add update menu item
This commit is contained in:
parent
cf2c1aa617
commit
eee14e08f1
@ -276,15 +276,29 @@ class WPMenu:
|
|||||||
if i["title"]["rendered"] == itemMenu["title"]:
|
if i["title"]["rendered"] == itemMenu["title"]:
|
||||||
idItemMenu = i["id"]
|
idItemMenu = i["id"]
|
||||||
self._logger.info("{0} : Length of result for item menus : {1}".format(self._name, len(result)))
|
self._logger.info("{0} : Length of result for item menus : {1}".format(self._name, len(result)))
|
||||||
if idItemMenu == 0:
|
url = "{1}://{0}/wp-json/wp/v2/menu-items".format(self._wordpress, self._protocol_wordpress)
|
||||||
try:
|
if idItemMenu != 0:
|
||||||
data = {"title": itemMenu["title"], "status": "publish", "parent":parent}
|
url = "{1}://{0}/wp-json/wp/v2/menu-items/{2}".format(self._wordpress, self._protocol_wordpress, idItemMenu)
|
||||||
page = self._request_wordpress.post("{1}://{0}/wp-json/wp/v2/menu-items".format(self._wordpress, self._protocol_wordpress), auth=self._basic, headers=self._headers_json, data=json.dumps(data))
|
|
||||||
except ConnectionError as err:
|
try:
|
||||||
self._logger.error("{0} : Connection error for create item menu {1} : {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/menu-items".format(self._wordpress, self._protocol_wordpress), err))
|
objectt = itemMenu["type"]
|
||||||
exit(1)
|
if objectt == "tag":
|
||||||
except Exception as err:
|
objectt = "post_tag"
|
||||||
self._logger.error("{0} : Exception error for get item menu {1} : {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/menu-items".format(self._wordpress, self._protocol_wordpress), err))
|
data = {"title": itemMenu["title"], "status": "publish", "parent":parent, "menus":idMenu, "object":objectt, "object_id":itemMenu["id"]}
|
||||||
|
page = self._request_wordpress.post(url, auth=self._basic, headers=self._headers_json, data=json.dumps(data))
|
||||||
|
if page.status_code == 201:
|
||||||
|
self._logger.info("{0} : create item menu : {1}".format(self._name, itemMenu["title"]))
|
||||||
|
elif page.status_code == 200:
|
||||||
|
self._logger.info("{0} : update item menu : {1}".format(self._name, itemMenu["title"]))
|
||||||
|
else:
|
||||||
|
self._logger.error("{0} : Create menu items didn't get due status code : {1}".format(self._name, page.status_code))
|
||||||
|
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
||||||
|
|
||||||
|
except ConnectionError as err:
|
||||||
|
self._logger.error("{0} : Connection error for create item menu {1} : {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/menu-items".format(self._wordpress, self._protocol_wordpress), err))
|
||||||
|
exit(1)
|
||||||
|
except Exception as err:
|
||||||
|
self._logger.error("{0} : Exception error for get item menu {1} : {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/menu-items".format(self._wordpress, self._protocol_wordpress), err))
|
||||||
else:
|
else:
|
||||||
self._logger.error("{0} : Get menu items didn't get due status code : {1}".format(self._name, page.status_code))
|
self._logger.error("{0} : Get menu items didn't get due status code : {1}".format(self._name, page.status_code))
|
||||||
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
self._logger.debug("{0} : {1}".format(self._name, page.content))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user