hello.php
これは私がしたことです-プラグインフォルダ内のファイルをコピーし、名前を。に変更しましたmyhello.php
。これが私のシステムで正常に動作するコードです-
<?php
/**
* @package myhello
* @version 1.6
*/
/*
Plugin Name: My Hello
Plugin URI: http://wordpress.org/extend/plugins/myhello/
Description: This is not just a plugin
Author: Swapnesh Sinha
Version: 1.6
Author URI: swapneshsinha.wordpress.com
*/
function myhello_get_lyric() {
/** These are the lyrics to Hello Dolly */
$lyrics = "Hello, Dolly
Well, hello, Dolly
It's so nice to have you back where you belong
You're lookin' swell, Dolly
Dolly'll never go away
Dolly'll never go away
Dolly'll never go away again";
// Here we split it into lines
$lyrics = explode( "\n", $lyrics );
// And then randomly choose a line
return wptexturize( $lyrics[ mt_rand( 0, count( $lyrics ) - 1 ) ] );
}
// This just echoes the chosen line, we'll position it later
function myhello() {
$chosen = myhello_get_lyric();
echo "<p id='dolly'>$chosen</p>";
}
// Now we set that function up to execute when the admin_notices action is called
add_action( 'admin_notices', 'myhello' );
// We need some CSS to position the paragraph
function dolly_css() {
// This makes sure that the positioning is also good for right-to-left languages
$x = is_rtl() ? 'left' : 'right';
echo "
<style type='text/css'>
#dolly {
float: $x;
padding-$x: 15px;
padding-top: 5px;
margin: 0;
font-size: 11px;
}
</style>
";
}
add_action( 'admin_head', 'dolly_css' );
?>