wp admin notices
1.0.0
一種建立可永久關閉的 WordPress 管理員通知的簡單便捷的方法。除此之外,它還有一些很酷的功能:
add_action ( ' admin_notices ' , function () {
$ notices_manager = ThanksToIT WPAN get_notices_manager ();
$ notices_manager -> create_notice ( array (
' id ' => ' my-notice ' ,
' content ' => ' <p>My Notice</p> ' ,
) );
} );
注意:預設情況下,該庫將使通知持續存在,這表示用戶關閉通知後不會再次顯示通知,除非通知過期
為了使其完美工作,您需要像這樣初始化它:
add_action ( ' wp_ajax_ ' . ' tttwpan_dismiss_persist ' , array ( ' ThanksToITWPANNotices_Manager ' , ' ajax_dismiss ' ) );
add_action ( ' activated_plugin ' , array ( ' ThanksToITWPANNotices_Manager ' , ' set_activated_plugin ' ) );
add_action ( ' upgrader_process_complete ' , array ( ' ThanksToITWPANNotices_Manager ' , ' set_upgrader_process ' ), 10 , 2 );
在外掛程式/主題上的任何其他掛鉤之前進行這些呼叫非常重要。但不用擔心,只有在必要時才會載入該函式庫,因為它是在正確的掛鉤上呼叫的
'notice-info'
、 'notice-warning'
、 'notice-success'
、 'notice-error'
、 'notice-info'
。預設值為'notice-info'
。true
。MONTH_IN_SECONDS
。'screen_id' => array( 'plugins' )
。'activated_plugin' => array('akismet/akismet.php')
。'updated_plugin' => array('akismet/akismet.php')
。'key'
和'value'
參數的數組數組。範例: 'request' => array( array( 'key' => 'show_notice', 'value' => '1' ), )
。array( 'activated_plugin', 'updated_plugin' )
, add_action ( ' admin_notices ' , function () {
$ notices_manager = ThanksToIT WPAN get_notices_manager ();
$ notices_manager -> create_notice ( array (
' id ' => ' 1-week-notice ' ,
' content ' => ' <p>1 week notice</p> ' ,
' dismissal_expiration ' => WEEK_IN_SECONDS ,
) );
} );
add_action ( ' admin_notices ' , function () {
$ notices_manager = ThanksToIT WPAN get_notices_manager ();
$ notices_manager -> create_notice ( array (
' id ' => ' plugins-page-notice ' ,
' content ' => ' <p>plugins page notice</p> ' ,
' display_on ' => array (
' screen_id ' => array ( ' plugins ' ),
)
) );
} );
add_action ( ' admin_notices ' , function () {
$ notices_manager = ThanksToIT WPAN get_notices_manager ();
$ notices_manager -> create_notice ( array (
' id ' => ' akismet-notice ' ,
' content ' => ' <p>Akismet notice</p> ' ,
' display_on ' => array (
' activated_plugin ' => array ( ' akismet/akismet.php ' )
)
) );
} );
要安裝此軟體包,請編輯您的composer.json
檔案:
{
"require" : {
"thanks-to-it/wp-admin-notices" : "dev-master"
}
}
現在運行:
$ composer install