WordPress 4.5破坏了我的插件,没有明显的线索表明change log
该插件控制菜单项的可见性。用户选择一个或多个国家,以及是否显示或隐藏菜单项。
显示或隐藏的设置仍然有效:
add_action( \'wp_update_nav_menu_item\', array( $this, \'csmi_update_visibility\' ), 10, 3 );
...
<input
type="radio"
id="edit-menu-item-visibility-<?php echo $item_id;?>"
name="menu-item-show-hide[<?php echo $item_id; ?>]"
value="hide" <?php checked( get_post_meta( $item_id, \'hide_show\', true ), \'hide\', true ); ?>
/>Hide from these countries.</br>
<input
type="radio"
id="edit-menu-item-visibility-<?php echo $item_id; ?>"
name="menu-item-show-hide[<?php echo $item_id; ?>]"
value="show" <?php checked( get_post_meta( $item_id, \'hide_show\', true ), \'show\', true ); ?>
/>Only show to these countries.</br>
...
/* Put visibility settings in the database. */
function csmi_update_visibility( $menu_id, $menu_item_db_id, $args ) {
$meta_value = get_post_meta( $menu_item_db_id, \'hide_show\', true );
if ( isset( $_POST[ \'menu-item-show-hide\' ][ $menu_item_db_id ] ) ) {
$new_meta_value = $_POST[ \'menu-item-show-hide\' ][ $menu_item_db_id ];
}
if ( $meta_value !== $new_meta_value ) {
update_post_meta( $menu_item_db_id, \'hide_show\', $new_meta_value );
}
}
但未保存位置:
add_action( \'wp_update_nav_menu_item\', array( $this, \'csmi_update_locations\' ), 10, 3 );
...
<select name="menu-item-visibility[<?php echo $item_id; ?>][]" id="edit-menu-item-visibility-<?php echo $item_id; ?>" class="chzn-select" multiple="true">
<?php
$vals = get_post_meta( $item_id, \'locations\', true );
foreach( $countries as $key => $value ) {
?>
<option value="<?php echo $key;?>"<?php echo is_array( $vals ) && in_array( $key, $vals ) ? "selected=\'selected\'" : \'\'; ?>> <?php echo $value;?> </option>
<?php
}
?>
</select>
...
/* Put locations in the database. */
function csmi_update_locations( $menu_id, $menu_item_db_id, $args ) {
$meta_value = get_post_meta( $menu_item_db_id, \'locations\', true );
if ( isset( $_POST[ \'menu-item-visibility\' ][ $menu_item_db_id ] ) ) {
$new_meta_value = $_POST[ \'menu-item-visibility\' ][ $menu_item_db_id ];
}
if ( !isset($new_meta_value ) ) {
delete_post_meta( $menu_item_db_id, \'locations\', $meta_value );
}
elseif ( $meta_value !== $new_meta_value ) {
update_post_meta( $menu_item_db_id, \'locations\', $new_meta_value );
}
}
你知道WP 4.5是如何破坏它的吗?我快不知所措了。
此处提供的源代码:https://plugins.trac.wordpress.org/browser/location-specific-menu-items-by-country/tags/1.0.3