diff --git a/lib/WPMenu.py b/lib/WPMenu.py index 841a618..c3f92c9 100644 --- a/lib/WPMenu.py +++ b/lib/WPMenu.py @@ -262,7 +262,6 @@ class WPMenu: - exit(0) def _createItemMenu(self, idMenu, itemMenu, parent): idItemMenu = 0 @@ -285,10 +284,17 @@ class WPMenu: if objectt == "tag": objectt = "post_tag" 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)) + page = self._request_wordpress.post(url, auth=self._basic, headers=self._headers_json, data=json.dumps(data)) + if page.status_code == 201: + result = page.json() + idItemMenu = result["id"] self._logger.info("{0} : create item menu : {1}".format(self._name, itemMenu["title"])) elif page.status_code == 200: + result = page.json() + for i in result: + if result["title"]["rendered"] == itemMenu["title"]: + idItemMenu = i["id"] 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)) @@ -356,3 +362,8 @@ class WPMenu: exit(1) except Exception as err: self._logger.error("{0} : Exception error for get menu {1} : {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/menus".format(self._wordpress, self._protocol_wordpress), err)) + + + def addItemMenu(self, menu, idMenu): + self._logger.info("{0} : add item to menu : {1}".format(self._name, idMenu)) + \ No newline at end of file