add item menu
This commit is contained in:
parent
e17cace820
commit
cf2c1aa617
@ -259,8 +259,42 @@ class WPMenu:
|
||||
menu[i] = {"id":idMenu["id"], "type": idMenu["type"], "title":menu[i]["title"], "link":idMenu["link"], "children": menu[i]["children"]}
|
||||
|
||||
self._createMenu(menu)
|
||||
|
||||
|
||||
|
||||
exit(0)
|
||||
|
||||
|
||||
def _createItemMenu(self, idMenu, itemMenu, parent):
|
||||
idItemMenu = 0
|
||||
self._logger.info("{0} : Create item menu from API Wordpress : {1}".format(self._name, self._wordpress))
|
||||
try:
|
||||
params = {"search": itemMenu["title"], "menus": idMenu}
|
||||
page = self._request_wordpress.get("{1}://{0}/wp-json/wp/v2/menu-items".format(self._wordpress, self._protocol_wordpress), auth=self._basic, params=params)
|
||||
if page.status_code == 200:
|
||||
result = page.json()
|
||||
for i in result:
|
||||
if i["title"]["rendered"] == itemMenu["title"]:
|
||||
idItemMenu = i["id"]
|
||||
self._logger.info("{0} : Length of result for item menus : {1}".format(self._name, len(result)))
|
||||
if idItemMenu == 0:
|
||||
try:
|
||||
data = {"title": itemMenu["title"], "status": "publish", "parent":parent}
|
||||
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:
|
||||
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:
|
||||
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))
|
||||
except ConnectionError as err:
|
||||
self._logger.error("{0} : Connection error for get item menus {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 menus {1} : {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/menu-items".format(self._wordpress, self._protocol_wordpress), err))
|
||||
return idItemMenu
|
||||
|
||||
def _createMenu(self, menu):
|
||||
title = "Menu {0}".format(self._wordpress)
|
||||
self._logger.info("{0} : Create menu from API Wordpress : {1}".format(self._name, title))
|
||||
|
Loading…
x
Reference in New Issue
Block a user