Created
September 25, 2012 07:45
-
-
Save hissy/3780493 to your computer and use it in GitHub Desktop.
[WordPress] fixes admin menu order conflict
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'admin_menu', 'admin_menu_order_hack', 9); // 9 is the priority contact form 7 applies. | |
function admin_menu_order_hack() { | |
global $_wp_last_object_menu; | |
$_wp_last_object_menu++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
プラグインがWordPressに追加するメニューなどで、priorityが重複することで片方のメニューが管理画面から消えてしまう問題の回避方法。
メモ: add_object_pageを使ってメニューを追加しているプラグインの場合は、$_wp_last_object_menuをインクリメントしてからメニューを追加するのでpriorityが重複することはないのだが、add_menu_pageを使ってpriorityを指定してメニューを追加するプラグインが共存している場合、偶然priority値が重複することがあり、片方が管理画面から消えてしまう。それを回避するため、add_object_pageを使ってメニューを追加するプラグインがadmin_menuフックを使ってメニューを追加する前に、$_wp_last_object_menuをインクリメントして重複を回避している。この方法では、両方がadd_menu_pageを使っている場合はどうしようもないです。