Last active
January 3, 2017 03:28
-
-
Save michaelcurry/8819401 to your computer and use it in GitHub Desktop.
This is an object-oriented sample Wordpress plugin. Blog Post: http://www.kernelcurry.com/blog/object-oriented-wordpress-plugin
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 | |
/** | |
* @package Hello_Dolly_OOP | |
* @version 0.1 | |
*/ | |
/* | |
Plugin Name: Hello Dolly OOP | |
Plugin URI: http://kernelcurry.com/blog/object-oriented-wordpress-plugin | |
Description: This plugin is an object oriented version of Matt Mullenweg's Hello Dolly plugin. | |
Version: 0.1 | |
Author: Michael Curry | |
Author URI: http://kernelcurry.com | |
*/ | |
Class HelloDolly | |
{ | |
public function __construct() | |
{ | |
add_action( 'admin_head', array( $this, 'dolly_css' ) ); | |
add_action( 'admin_notices', array( $this, 'hello_dolly' ) ); | |
} | |
public function hello_dolly() | |
{ | |
$chosen = $this->hello_dolly_get_lyric(); | |
echo "<p id='dolly'>$chosen</p>"; | |
} | |
public function dolly_css() | |
{ | |
$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> | |
"; | |
} | |
public function hello_dolly_get_lyric() | |
{ | |
$lyrics = array( | |
"Hello, Dolly", | |
"Well, hello, Dolly", | |
"It's so nice to have you back where you belong", | |
"You're lookin' swell, Dolly", | |
"I can tell, Dolly", | |
"You're still glowin', you're still crowin'", | |
"You're still goin' strong", | |
"We feel the room swayin'", | |
"While the band's playin'", | |
"One of your old favourite songs from way back when", | |
"So, take her wrap, fellas", | |
"Find her an empty lap, fellas", | |
"Dolly'll never go away again", | |
"Hello, Dolly", | |
"Well, hello, Dolly", | |
"It's so nice to have you back where you belong", | |
"You're lookin' swell, Dolly", | |
"I can tell, Dolly", | |
"You're still glowin', you're still crowin'", | |
"You're still goin' strong", | |
"We feel the room swayin'", | |
"While the band's playin'", | |
"One of your old favourite songs from way back when", | |
"Golly, gee, fellas", | |
"Find her a vacant knee, fellas", | |
"Dolly'll never go away", | |
"Dolly'll never go away", | |
"Dolly'll never go away again" | |
); | |
return wptexturize( $lyrics[ mt_rand( 0, count( $lyrics ) - 1 ) ] ); | |
} | |
} // End Class | |
$hello_dolly_oop = new HelloDolly; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, Thanks for sharing a simplified OOP plugin framework for wordpress.. It would be great if you add a simple option page (settings page) for this framework..
Thanks once again..
Cheers..