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