Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is an object-oriented sample Wordpress plugin. Blog Post: http://www.kernelcurry.com/blog/object-oriented-wordpress-plugin
<?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;
@shrinitech

This comment has been minimized.

Copy link

shrinitech commented Dec 8, 2014

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..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.