我提供了一个小插件来实现这一点。该插件基于WordPress Hello插件,其工作原理与WordPress Hello插件类似。只需将下面的脚本保存到一个文件(例如mynotes.php)中,并放在插件文件夹中即可。您还可以编辑插件名称和函数以满足您的需要。要更改注释,只需替换函数my\\u notes()中的内容$notes即可。
<?php
/**
* @file
* My Note WordPress plugin.
* Plugin name: My Note
* Author: Your Name
* Description: My custom plugin to create notes for admin
* Version: 1.0
*/
if (!defined(\'ABSPATH\')) die(\'Direct access is not allowed.\');
//
function my_notes() {
/** Put our notes here one per line */
$notes = "Hello, Admin, welcome to my notes. Notes will always show here.";
//split the notes into lines
$notes = explode( "\\n", $notes );
//return the lines randonmly
return wptexturize( $notes[ mt_rand( 0, count( $notes ) - 1 ) ] );
}
// This just echoes the chosen line
function show_notes() {
$note = my_notes();
echo "<div id=\'notes\'>
<h4>My Note</h4>
<em>$note</em>
</div>";
}
// Set the function up to execute when the admin_notices action is called
add_action( \'admin_notices\', \'show_notes\' );
// Create CSS to stylize and position the output
function notes_css() {
echo "
<style type=\'text/css\'>
#notes {position:fixed; right:calc(40% - 110px); top:0; line-height: 19px; padding: 12.5px; font-size: 12px; text-align: left; margin: 25px 20px 0 2px; background-color: #fff;
width:220px; height:auto; box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);}
#notes h4{display:block; margin:0 0 13px; font-size:14px; font-weight:600; color:#162E43; text-align:center;}
</style>
";
}
add_action( \'admin_head\', \'notes_css\' );
?>