本文整理汇总了PHP中wp_update_nav_menu_object函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_update_nav_menu_object函数的具体用法?PHP wp_update_nav_menu_object怎么用?PHP wp_update_nav_menu_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_update_nav_menu_object函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sync_menu_translations
function sync_menu_translations($menu_trans_data, $menus)
{
global $wpdb;
foreach ($menu_trans_data as $menu_id => $translations) {
foreach ($translations as $language => $name) {
$_POST['icl_translation_of'] = $wpdb->get_var($wpdb->prepare("\tSELECT term_taxonomy_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->term_taxonomy}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE term_id=%d\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND taxonomy='nav_menu'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT 1", $menu_id));
$_POST['icl_nav_menu_language'] = $language;
$menu_indentation = '';
$menu_increment = 0;
do {
$new_menu_id = wp_update_nav_menu_object(0, array('menu-name' => $name . $menu_indentation . ($menu_increment ? $menu_increment : '')));
$menu_increment = $menu_increment != '' ? $menu_increment + 1 : 2;
$menu_indentation = '-';
} while (is_wp_error($new_menu_id) && $menu_increment < 10);
$menus[$menu_id]['translations'][$language] = array('id' => $new_menu_id);
}
}
return $menus;
}
示例2: menu_customizer_update_menu_name
/**
* Save the Menu Name when it's changed.
*
* Menu Name is not previewed because it's designed primarily for admin uses.
*
* @since Menu Customizer 0.0
*
* @param mixed $value Value of the setting.
* @param WP_Customize_Setting $setting WP_Customize_Setting instance.
*/
function menu_customizer_update_menu_name($value, $setting)
{
if (!$value || !$setting) {
return;
}
// Get the menu id from the setting id.
$id = str_replace('nav_menus[', '', $setting->id);
$id = str_replace('][name]', '', $id);
if (0 == $id) {
return;
// Avoid creating a new, empty menu.
}
// Update the menu name with the new $value.
wp_update_nav_menu_object($id, array('menu-name' => trim(esc_html($value))));
}
示例3: update
/**
* Create/update the nav_menu term for this setting.
*
* Any created menus will have their assigned term IDs exported to the client
* via the customize_save_response filter. Likewise, any errors will be exported
* to the client via the customize_save_response() filter.
*
* To delete a menu, the client can send false as the value.
*
* @since 4.3.0
* @access protected
*
* @see wp_update_nav_menu_object()
*
* @param array|false $value {
* The value to update. Note that slug cannot be updated via wp_update_nav_menu_object().
* If false, then the menu will be deleted entirely.
*
* @type string $name The name of the menu to save.
* @type string $description The term description. Default empty string.
* @type int $parent The id of the parent term. Default 0.
* @type bool $auto_add Whether pages will auto_add to this menu. Default false.
* }
* @return null|void
*/
protected function update($value)
{
if ($this->is_updated) {
return;
}
$this->is_updated = true;
$is_placeholder = $this->term_id < 0;
$is_delete = false === $value;
add_filter('customize_save_response', array($this, 'amend_customize_save_response'));
$auto_add = null;
if ($is_delete) {
// If the current setting term is a placeholder, a delete request is a no-op.
if ($is_placeholder) {
$this->update_status = 'deleted';
} else {
$r = wp_delete_nav_menu($this->term_id);
if (is_wp_error($r)) {
$this->update_status = 'error';
$this->update_error = $r;
} else {
$this->update_status = 'deleted';
$auto_add = false;
}
}
} else {
// Insert or update menu.
$menu_data = wp_array_slice_assoc($value, array('description', 'parent'));
$menu_data['menu-name'] = $value['name'];
$menu_id = $is_placeholder ? 0 : $this->term_id;
$r = wp_update_nav_menu_object($menu_id, wp_slash($menu_data));
$original_name = $menu_data['menu-name'];
$name_conflict_suffix = 1;
while (is_wp_error($r) && 'menu_exists' === $r->get_error_code()) {
$name_conflict_suffix += 1;
/* translators: 1: original menu name, 2: duplicate count */
$menu_data['menu-name'] = sprintf(__('%1$s (%2$d)'), $original_name, $name_conflict_suffix);
$r = wp_update_nav_menu_object($menu_id, wp_slash($menu_data));
}
if (is_wp_error($r)) {
$this->update_status = 'error';
$this->update_error = $r;
} else {
if ($is_placeholder) {
$this->previous_term_id = $this->term_id;
$this->term_id = $r;
$this->update_status = 'inserted';
} else {
$this->update_status = 'updated';
}
$auto_add = $value['auto_add'];
}
}
if (null !== $auto_add) {
$nav_menu_options = $this->filter_nav_menu_options_value((array) get_option('nav_menu_options', array()), $this->term_id, $auto_add);
update_option('nav_menu_options', $nav_menu_options);
}
if ('inserted' === $this->update_status) {
// Make sure that new menus assigned to nav menu locations use their new IDs.
foreach ($this->manager->settings() as $setting) {
if (!preg_match('/^nav_menu_locations\\[/', $setting->id)) {
continue;
}
$post_value = $setting->post_value(null);
if (!is_null($post_value) && $this->previous_term_id === intval($post_value)) {
$this->manager->set_post_value($setting->id, $this->term_id);
$setting->save();
}
}
// Make sure that any nav_menu widgets referencing the placeholder nav menu get updated and sent back to client.
foreach (array_keys($this->manager->unsanitized_post_values()) as $setting_id) {
$nav_menu_widget_setting = $this->manager->get_setting($setting_id);
if (!$nav_menu_widget_setting || !preg_match('/^widget_nav_menu\\[/', $nav_menu_widget_setting->id)) {
continue;
}
$widget_instance = $nav_menu_widget_setting->post_value();
//.........这里部分代码省略.........
示例4: test_nav_menu_term_should_retain_menu_items_on_split
/**
* @ticket 33187
* @group navmenus
*/
public function test_nav_menu_term_should_retain_menu_items_on_split()
{
global $wpdb;
$cat_term = wp_insert_term('Foo Menu', 'category');
$shared_term_id = $cat_term['term_id'];
$nav_term_id = wp_create_nav_menu('Foo Menu');
$nav_term = get_term($nav_term_id, 'nav_menu');
// Manually modify because shared terms shouldn't naturally occur.
$wpdb->update($wpdb->term_taxonomy, array('term_id' => $shared_term_id), array('term_taxonomy_id' => $nav_term->term_taxonomy_id));
$t1 = wp_insert_term('Random term', 'category');
$cat_menu_item = wp_update_nav_menu_item($shared_term_id, 0, array('menu-item-type' => 'taxonomy', 'menu-item-object' => 'category', 'menu-item-object-id' => $t1['term_id'], 'menu-item-status' => 'publish'));
// Updating the menu will split the shared term.
$new_nav_menu_id = wp_update_nav_menu_object($shared_term_id, array('description' => 'Updated Foo Menu', 'menu-name' => 'Updated Foo Menu'));
$menu = wp_get_nav_menu_object($new_nav_menu_id);
$this->assertSame('Updated Foo Menu', $menu->name);
$this->assertSame('Updated Foo Menu', $menu->description);
$menu_items = wp_get_nav_menu_items($new_nav_menu_id);
$this->assertEquals(array($cat_menu_item), wp_list_pluck($menu_items, 'ID'));
}
示例5: create_menu
private function create_menu($type)
{
$menu_name = $type == 'vmenu' ? 'Sample VMenu' : 'Sample HMenu';
for ($i = 0;; $i++) {
$_possible_existing = get_term_by('name', $menu_name . ($i ? ' #' . $i : ''), 'nav_menu');
if (!$_possible_existing || is_wp_error($_possible_existing) || !isset($_possible_existing->term_id)) {
break;
}
}
$page_to_menu_ids = array();
$nav_menu_selected_id = wp_update_nav_menu_object(0, array('menu-name' => $menu_name . ($i ? ' #' . $i : '')));
if (!is_wp_error($nav_menu_selected_id)) {
$this->sample_data['menu'][] = $nav_menu_selected_id;
foreach ($this->menu[$type] as $menu_item_data) {
if (0 != $menu_item_data['menu-item-parent-id']) {
if (isset($page_to_menu_ids[$menu_item_data['menu-item-parent-id']])) {
$menu_item_data['menu-item-parent-id'] = $page_to_menu_ids[$menu_item_data['menu-item-parent-id']];
} else {
$menu_item_data['menu-item-parent-id'] = 0;
}
}
$menu_item_id = wp_update_nav_menu_item($nav_menu_selected_id, 0, $menu_item_data);
$page_to_menu_ids[$menu_item_data['menu-item-object-id']] = $menu_item_id;
}
$this->{$type . '_id'} = $nav_menu_selected_id;
}
if ('hmenu' == $type) {
$nav_menu_locations = get_theme_mod('nav_menu_locations');
$nav_menu_locations['primary-menu'] = $nav_menu_selected_id;
set_theme_mod('nav_menu_locations', $nav_menu_locations);
}
}
示例6: _do_the_sync
function _do_the_sync($data)
{
global $sitepress, $wpdb;
if (isset($data['menu_translation']) && is_array($data['menu_translation'])) {
foreach ($data['menu_translation'] as $menuinfo) {
list($original_menu_id, $language, $menu_name) = explode('#', $menuinfo);
$menu_name = urldecode($menu_name);
$_POST['icl_translation_of'] = $original_menu_id;
$_POST['icl_nav_menu_language'] = $language;
$new_menu_id = wp_update_nav_menu_object(0, array('menu-name' => $menu_name));
$new_menus[$original_menu_id][$language] = $new_menu_id;
}
}
if (isset($data['del']) && is_array($data['del'])) {
foreach ($data['del'] as $iteminfo) {
list($menu_id, $item_id) = explode('#', $iteminfo);
wp_delete_post($item_id, true);
}
}
if (isset($data['add']) && is_array($data['add'])) {
foreach ($data['add'] as $iteminfo) {
list($menu_id, $object_id, $ob_type, $parent_id) = explode('#', $iteminfo);
if (!is_numeric($menu_id)) {
$exp = explode('-', $menu_id);
$menu_id = $new_menus[$exp[1]][$exp[2]];
}
global $wp_post_types;
if (taxonomy_exists($ob_type)) {
$menu_obj = get_term($object_id, $ob_type);
$menu_item_type = 'taxonomy';
} elseif (in_array($ob_type, array_keys($wp_post_types))) {
$menu_obj = get_post($object_id);
$menu_item_type = 'post_type';
}
$menu_tax_id = $wpdb->get_var($wpdb->prepare("\r\r\n SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=%d AND taxonomy='nav_menu'", $new_menu_id));
$_ldetails = $sitepress->get_element_language_details($menu_tax_id, 'tax_nav_menu');
$language = $_ldetails->language_code;
$menudata = array('menu-item-db-id' => 0, 'menu-item-object-id' => $object_id, 'menu-item-object' => $ob_type, 'menu-item-parent-id' => 0, 'menu-item-position' => 0, 'menu-item-type' => $menu_item_type, 'menu-item-title' => '', 'menu-item-url' => '', 'menu-item-description' => '', 'menu-item-attr-title' => '', 'menu-item-target' => '', 'menu-item-classes' => '', 'menu-item-xfn' => '', 'menu-item-status' => 'publish');
$nav_item_id = wp_update_nav_menu_item($menu_id, 0, $menudata);
// set language explicitly since the 'wp_update_nav_menu_item' is still TBD
$sitepress->set_element_language_details($nav_item_id, 'post_nav_menu_item', null, $language);
}
// check and set hierarchy
foreach ($data['add'] as $iteminfo) {
list($menu_id, $object_id, $ob_type, $original_item_parent) = explode('#', $iteminfo);
if (!is_numeric($menu_id)) {
$exp = explode('-', $menu_id);
$menu_id = $new_menus[$exp[1]][$exp[2]];
}
global $wp_post_types;
if (taxonomy_exists($ob_type)) {
$menu_obj = get_term($object_id, $ob_type);
$menu_item_type = 'taxonomy';
} elseif (in_array($ob_type, array_keys($wp_post_types))) {
$menu_obj = get_post($object_id);
$menu_item_type = 'post_type';
}
if (!$original_item_parent) {
//get original object
$original_object = icl_object_id($object_id, $ob_type, false, $sitepress->get_default_language());
// get item id of original object in original menu
$original_menu_id = icl_object_id($menu_id, 'nav_menu', false, $sitepress->get_default_language());
$original_item_id = $wpdb->get_var($wpdb->prepare("\r\r\n SELECT p.post_id FROM {$wpdb->postmeta} p\r\r\n JOIN {$wpdb->term_relationships} r ON r.object_id = p.post_id\r\r\n JOIN {$wpdb->term_taxonomy} x ON r.term_taxonomy_id = x.term_taxonomy_id AND taxonomy = 'nav_menu'\r\r\n JOIN {$wpdb->terms} m ON m.term_id = x.term_id\r\r\n WHERE meta_key='_menu_item_object_id' AND meta_value=%d AND m.term_id=%d", $original_object, $original_menu_id));
$original_item_parent = get_post_meta($original_item_id, '_menu_item_menu_item_parent', true);
}
if ($original_item_parent) {
$original_item_parent_object_id = get_post_meta($original_item_parent, '_menu_item_object_id', true);
$parent_ob_type = $wpdb->get_var($wpdb->prepare("SELECT post_type FROM {$wpdb->posts} WHERE ID=%d", $original_item_parent_object_id));
$item_parent_object_id = icl_object_id($original_item_parent_object_id, $parent_ob_type, false, $language);
$item_parent = $wpdb->get_var($wpdb->prepare("\r\r\n SELECT p.post_id FROM {$wpdb->postmeta} p\r\r\n JOIN {$wpdb->term_relationships} r ON r.object_id = p.post_id\r\r\n JOIN {$wpdb->term_taxonomy} x ON r.term_taxonomy_id = x.term_taxonomy_id AND taxonomy = 'nav_menu'\r\r\n JOIN {$wpdb->terms} m ON m.term_id = x.term_id\r\r\n WHERE meta_key='_menu_item_object_id' AND meta_value=%d AND m.term_id=%d\r\r\n ", $item_parent_object_id, $menu_id));
$item_id = $wpdb->get_var($wpdb->prepare("\r\r\n SELECT p.post_id FROM {$wpdb->postmeta} p\r\r\n JOIN {$wpdb->term_relationships} r ON r.object_id = p.post_id\r\r\n JOIN {$wpdb->term_taxonomy} x ON r.term_taxonomy_id = x.term_taxonomy_id AND taxonomy = 'nav_menu'\r\r\n JOIN {$wpdb->terms} m ON m.term_id = x.term_id\r\r\n WHERE meta_key='_menu_item_object_id' AND meta_value=%d AND m.term_id=%d\r\r\n ", $object_id, $menu_id));
update_post_meta($item_id, '_menu_item_menu_item_parent', $item_parent);
}
}
}
}
示例7: blog_creation
function blog_creation($blog_id)
{
// Muda para o tema pensando direito caso já não esteja nesse tema
switch_to_blog(ID_BLOG_PENSANDO_DIREITO);
// Pega os dados dos menus do tema anterior
$menus = wp_get_nav_menus();
foreach ($menus as $menu) {
$menu->items = wp_get_nav_menu_items($menu->term_id);
foreach ($menu->items as $item) {
// Se for uma página ou post type pega o post original
if ($item->type == 'post_type') {
$item->orginal_post = get_post((int) $item->object_id);
}
}
}
// Troca a conexão para salvar o menu no novo blog
switch_to_blog($blog_id);
foreach ($menus as $menu) {
//$menu_id = wp_create_nav_menu($menu->name);
$menu_id = wp_update_nav_menu_object(0, array('menu-name' => $menu->name, 'menu-parent' => $menu->parent, 'menu-description' => $menu->description));
if (isset($menu->items)) {
foreach ($menu->items as $item) {
// Se for um menu para um post cria o post no novo blog
if ($item->type == 'post_type') {
$data = array('post_title' => $item->orginal_post->post_title, 'post_content' => $item->orginal_post->post_content, 'post_status' => $item->orginal_post->post_status, 'post_type' => $item->orginal_post->post_type);
$new_post_id = wp_insert_post($data);
$item->object_id = is_int($new_post_id) ? $new_post_id : 0;
}
// Insere o item no menu
wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => $item->title, 'menu-item-classes' => implode(" ", $item->classes), 'menu-item-url' => $item->url, 'menu-item-status' => $item->post_status, 'menu-item-object-id' => (int) $item->object_id, 'menu-item-object' => $item->object, 'menu-item-type' => $item->type));
}
}
}
restore_current_blog();
}
示例8: wp_create_nav_menu
/**
* Creates a navigation menu.
*
* Note that `$menu_name` is expected to be pre-slashed.
*
* @since 3.0.0
*
* @param string $menu_name Menu name.
* @return int|WP_Error Menu ID on success, WP_Error object on failure.
*/
function wp_create_nav_menu($menu_name)
{
// expected_slashed ($menu_name)
return wp_update_nav_menu_object(0, array('menu-name' => $menu_name));
}
示例9: import_menu
protected function import_menu($menu)
{
$_menu = $menu['menu'];
if (is_nav_menu($menu['menu']['slug'])) {
$local_menu = wp_get_nav_menu_object($menu['menu']['slug']);
$menu_id = $local_menu->term_id;
$update = true;
if (!empty($local_menu)) {
$local_menu = new cfd_menu($menu['menu']['slug']);
}
} else {
$menu_id = 0;
$update = false;
}
$insert_menu_id = wp_update_nav_menu_object($menu_id, array('menu-name' => $menu['menu']['name'], 'description' => $menu['menu']['description'], 'slug' => $menu['menu']['slug']));
if (is_wp_error($insert_menu_id)) {
$this->add_import_message('menus', '__error__', sprintf(__('Menu import failed for menu "%s". Error: ', 'cf-deploy'), $menu['menu']['name']) . $insert_menu_id->get_error_message());
return false;
}
// nuke existing menu items, trust me, its easier this way
if ($update) {
// Taken directly from wp_delete_nav_menu, wp-includes/nav-menu.php
$menu_objects = get_objects_in_term($insert_menu_id, 'nav_menu');
if (!empty($menu_objects)) {
foreach ($menu_objects as $item) {
wp_delete_post($item);
}
}
}
// handle menu items
if (!empty($menu['items'])) {
$this->menu_item_parent_map = array();
$processed_items = 0;
foreach ($menu['items'] as $item) {
if ($this->import_menu_item($item, $insert_menu_id)) {
$processed_items++;
}
}
}
// log rollback state
$item_change['menus'][$menu['menu']['slug']] = 'new';
if (!empty($local_menu)) {
$item_change['menus'][$menu['menu']['slug']] = $local_menu->get_data_for_transit();
}
$this->log_item_change($item_change);
return $processed_items == count($menu['items']);
}
示例10: importMenu
public function importMenu($menu)
{
wp_delete_nav_menu($menu['menu-name']);
$newMenu = wp_update_nav_menu_object(0, $menu);
if (is_wp_error($newTerm)) {
return $newTerm;
}
$this->registry->set('term', $menu['id'], (int) $newMenu);
foreach ($menu['items'] as $menuItem) {
$existing = $this->registry->get('post', $menuItem['id']);
if (is_nav_menu_item($existing)) {
wp_delete_post($existing, true);
}
if ('taxonomy' == $menuItem['menu-item-type']) {
$menuItem['menu-item-object-id'] = $this->registry->get('term', $menuItem['menu-item-object-id']);
} elseif ('post_type' == $menuItem['menu-item-type']) {
$menuItem['menu-item-object-id'] = $this->registry->get('post', $menuItem['menu-item-object-id']);
}
if (0 != (int) $menuItem['menu-item-parent-id']) {
$menuItem['menu-item-parent-id'] = $this->registry->get('post', $menuItem['menu-item-parent-id']);
if (is_null($menuItem['menu-item-parent-id'])) {
continue;
}
}
$newMenuItem = wp_update_nav_menu_item($newMenu, 0, $menuItem);
if (is_wp_error($newMenuItem)) {
return $newMenuItem;
}
$this->registry->set('post', $menuItem['id'], (int) $newMenuItem);
}
$this->message = sprintf(__('Creating menus...', '__x__'), $menu['menu-name']);
return true;
}
示例11: sn_scoutnet_api_group_html_page
function sn_scoutnet_api_group_html_page()
{
$zeestr = '';
$zee = 'n';
$akabestr = '';
$akabe = 'n';
$verhuurstr = '';
$verhuurstrY = '';
$verhuurstrN = '';
$verhuur = '-';
$hasaddressstr = '';
$hasaddress = 'n';
$streetstr = '';
$latstr = '';
$lngstr = '';
$verhuurstr2 = '';
$str_urllist = '';
$str_oldurllist = '';
$devkey = "jorisp@scoutnet.be";
$options = get_option('sn_scoutnet_api');
$secret = $options['apigroupkey'];
$accountid = $options['accountid'];
$appkey = substr($secret, 0, 6);
$dir = plugin_dir_path(__FILE__);
//print_r($_POST);
?>
<script type="text/javascript">
var templateDir = "<?php
echo SN_API_PLUGIN_URL;
?>
";
</script>
<?php
if (isset($_POST['sn3_submit_old'])) {
try {
$apicall = new Scoutnet_API_Call('group', $devkey, $appkey, $secret, false);
$method = 'GET';
$endpoint = 'sections/' . get_option('sn_accountid') . '/?filter=name:name_url';
$call = $apicall->run($endpoint, $method, null);
//echo "ANSWER:<br />";
//var_dump($call);
if ($call['decoded']['head']['status'] == 1) {
$sections = $call['decoded']['body']['data'];
foreach ($sections as $section) {
echo $section['name'];
}
} else {
echo "<div class=\"error\">{$call['decoded']['head']['error_message']}<br /><br />Is de secret key correct? Contacteer info@scoutnet.be</div>";
}
} catch (Exception $e) {
echo '<div class="error">' . $e->getMessage() . '</div>';
}
function my_register_navs()
{
register_nav_menus(array('takken-menu' => __('Takken Menu')));
}
add_action('init', 'my_register_navs');
/*
$locations = get_nav_menu_locations();
var_dump($locations);
$menu_name = 'Hoofdmenu';
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menu_items = wp_get_nav_menu_items($menu->term_id);
$menu_list = '<ul id="menu-' . $menu_name . '">';
foreach ( (array) $menu_items as $key => $menu_item ) {
$title = $menu_item->title;
$url = $menu_item->url;
$menu_list .= '<li><a href="' . $url . '">' . $title . '</a></li>';
}
$menu_list .= '</ul>';
} else {
$menu_list = '<ul><li>Menu "' . $menu_name . '" not defined.</li></ul>';
}
// $menu_list now ready to output
if ( !is_nav_menu( 'Takken Menu' )) {
$menu_id = wp_create_nav_menu( 'Takken Menu' );
$menu = array( 'menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'),'menu-item-title' => 'Home', 'menu-item-status' => 'publish' );
wp_update_nav_menu_item( $menu_id, 0, $menu );
}
*/
// Create the menus
$tak_menu = array('menu-name' => 'Takken Menu', 'description' => 'A navigation menu for this website');
$takken_menu = wp_update_nav_menu_object($menu_id, $tak_menu);
//var_dump($takken_menu);
// Set the menus to appear in the proper theme locations ???
$locations = get_theme_mod('nav_menu_locations');
//var_dump($locations);
$locations['header-menu'] = $takken_menu;
//.........这里部分代码省略.........
示例12: add_action
add_action('wp_ajax_nopriv_get_new_google_fonts', array('TMM_HelperFonts', 'get_new_google_fonts'));
add_action('wp_ajax_nopriv_folio_get_by_folio_id', array('TMM_Portfolio', 'get_by_folio_id'));
add_action('wp_ajax_folio_get_masonry_piece', array('TMM_Portfolio', 'get_masonry_piece'));
add_action('wp_ajax_nopriv_folio_get_masonry_piece', array('TMM_Portfolio', 'get_masonry_piece'));
//--------------------------------------------------------------------------
add_action('admin_menu', 'tmm_theme_add_admin');
add_action('admin_enqueue_scripts', 'tmm_theme_admin_head');
add_action('admin_bar_menu', 'tmm_theme_admin_bar_menu', 89);
//*****
global $pagenow;
if (is_admin() and 'themes.php' == $pagenow and isset($_GET['activated'])) {
//***** set default options
$theme_was_activated = TMM::get_option('theme_was_activated');
if (!$theme_was_activated) {
//*****
$menu_id = wp_update_nav_menu_object(0, array('menu-name' => 'Primary Menu'));
$theme_mods = get_option('theme_mods_' . 'almera');
$theme_mods['nav_menu_locations']['primary'] = $menu_id;
update_option('theme_mods_' . 'almera', $theme_mods);
if (class_exists('TMM_Ext_Shortcodes')) {
$shortcodes = TMM_Ext_Shortcodes::get_shortcodes_array();
if (!empty($shortcodes)) {
foreach ($shortcodes as $shortcode) {
TMM::update_option('show_shortcode_' . $shortcode, 1);
}
}
}
TMM::update_option('theme_was_activated', 1);
//*****
TMM::update_option('saved_google_fonts', 'a:1:{i:0;s:83:"Open Sans:300,300italic,400regular,italic,600,600italic,700,700italic,800,800italic";}');
TMM::update_option('sidebar_position', 'sbr');
示例13: rename_existing_menus
function rename_existing_menus()
{
$menus = wp_get_nav_menus();
if (!empty($menus)) {
//wp_delete_nav_menu($menu->slug);
foreach ($menus as $menu) {
$updated = false;
$i = 0;
while (!is_numeric($updated)) {
$i++;
$args['menu-name'] = __("Previously used menu", 'avia_framework') . " " . $i;
$args['description'] = $menu->description;
$args['parent'] = $menu->parent;
$updated = wp_update_nav_menu_object($menu->term_id, $args);
//return a number on success or wp_error object if menu name exists
//fallback, prevents infinite loop if something weird happens
if ($i > 100) {
$updated = 1;
}
}
}
}
}
示例14: wp_ajax_oxy_save_menu
/**
* Saves wordpress menu using ajax calls
*
* @return json messages from nav-menus.php
* @author
**/
public function wp_ajax_oxy_save_menu()
{
@error_reporting(0);
// Don't break the JSON result
// parse variables sent from $.serialize into an array
$oxy_menu_to_save = json_decode(stripslashes($_POST['menu']), true);
// set request and post to parsed menu data to fake the request
$_REQUEST = $oxy_menu_to_save;
$_POST = $oxy_menu_to_save;
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
// Container for any messages displayed to the user
$messages = array();
// Container that stores the name of the active menu
$nav_menu_selected_title = '';
// The menu id of the current menu being edited
$nav_menu_selected_id = isset($_REQUEST['menu']) ? (int) $_REQUEST['menu'] : 0;
// Get existing menu locations assignments
$locations = get_registered_nav_menus();
$menu_locations = get_nav_menu_locations();
$num_locations = count(array_keys($locations));
check_admin_referer('update-nav_menu', 'update-nav-menu-nonce');
// Remove menu locations that have been unchecked
foreach ($locations as $location => $description) {
if ((empty($_POST['menu-locations']) || empty($_POST['menu-locations'][$location])) && isset($menu_locations[$location]) && $menu_locations[$location] == $nav_menu_selected_id) {
unset($menu_locations[$location]);
}
}
// Merge new and existing menu locations if any new ones are set
if (isset($_POST['menu-locations'])) {
$new_menu_locations = array_map('absint', $_POST['menu-locations']);
$menu_locations = array_merge($menu_locations, $new_menu_locations);
}
// Set menu locations
set_theme_mod('nav_menu_locations', $menu_locations);
// Add Menu
if (0 == $nav_menu_selected_id) {
$new_menu_title = trim(esc_html($_POST['menu-name']));
if ($new_menu_title) {
$_nav_menu_selected_id = wp_update_nav_menu_object(0, array('menu-name' => $new_menu_title));
if (is_wp_error($_nav_menu_selected_id)) {
$messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
} else {
$_menu_object = wp_get_nav_menu_object($_nav_menu_selected_id);
$nav_menu_selected_id = $_nav_menu_selected_id;
$nav_menu_selected_title = $_menu_object->name;
if (isset($_REQUEST['menu-item'])) {
wp_save_nav_menu_items($nav_menu_selected_id, absint($_REQUEST['menu-item']));
}
if (isset($_REQUEST['zero-menu-state'])) {
// If there are menu items, add them
wp_nav_menu_update_menu_items($nav_menu_selected_id, $nav_menu_selected_title);
// Auto-save nav_menu_locations
$locations = get_nav_menu_locations();
foreach ($locations as $location => $menu_id) {
$locations[$location] = $nav_menu_selected_id;
break;
// There should only be 1
}
set_theme_mod('nav_menu_locations', $locations);
}
if (isset($_REQUEST['use-location'])) {
$locations = get_registered_nav_menus();
$menu_locations = get_nav_menu_locations();
if (isset($locations[$_REQUEST['use-location']])) {
$menu_locations[$_REQUEST['use-location']] = $nav_menu_selected_id;
}
set_theme_mod('nav_menu_locations', $menu_locations);
}
// $messages[] = '<div id="message" class="updated"><p>' . sprintf(__('<strong>%s</strong> has been created.'), $nav_menu_selected_title) . '</p></div>';
wp_redirect(admin_url('nav-menus.php?menu=' . $_nav_menu_selected_id));
exit;
}
} else {
$messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.', 'lambda-admin-td') . '</p></div>';
}
// Update existing menu
} else {
$_menu_object = wp_get_nav_menu_object($nav_menu_selected_id);
$menu_title = trim(esc_html($_POST['menu-name']));
if (!$menu_title) {
$messages[] = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.', 'lambda-admin-td') . '</p></div>';
$menu_title = $_menu_object->name;
}
if (!is_wp_error($_menu_object)) {
$_nav_menu_selected_id = wp_update_nav_menu_object($nav_menu_selected_id, array('menu-name' => $menu_title));
if (is_wp_error($_nav_menu_selected_id)) {
$_menu_object = $_nav_menu_selected_id;
$messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
} else {
$_menu_object = wp_get_nav_menu_object($_nav_menu_selected_id);
$nav_menu_selected_title = $_menu_object->name;
}
}
// Update menu items
//.........这里部分代码省略.........
示例15: callback
function callback($path = '', $site = 0, $menu_id = 0)
{
$site_id = $this->switch_to_blog_and_validate_user($this->api->get_blog_id($site));
if (is_wp_error($site_id)) {
return $site_id;
}
if ($menu_id <= 0) {
return new WP_Error('menu-id', 'Menu ID must be greater than 0.', 400);
}
$data = $this->input(true, false);
$data['id'] = $menu_id;
$data = $this->complexify(array($data));
if (is_wp_error($data)) {
return $data;
}
$data = $data[0];
// Avoid special-case handling of an unset 'items' field in empty menus
$data['items'] = isset($data['items']) ? $data['items'] : array();
$data = $this->create_new_items($data, $menu_id);
$result = wp_update_nav_menu_object($menu_id, array('menu-name' => $data['menu-name']));
if (is_wp_error($result)) {
return $result;
}
$delete_status = $this->delete_items_not_present($menu_id, $data['items']);
if (is_wp_error($delete_status)) {
return $delete_status;
}
foreach ($data['items'] as $item) {
$item_id = isset($item['menu-item-db-id']) ? $item['menu-item-db-id'] : 0;
$result = wp_update_nav_menu_item($menu_id, $item_id, $item);
if (is_wp_error($result)) {
return $result;
}
}
$items = wp_get_nav_menu_items($menu_id, array('update_post_term_cache' => false));
if (is_wp_error($items)) {
return $items;
}
$menu = wp_get_nav_menu_object($menu_id);
$menu->items = $items;
return array('menu' => $this->simplify($menu));
}