Information Technology Reference
In-Depth Information
15
The bulk of this script creates the followme class, with a series
of functions that define the badge and set up the administrative
settings that make the plug-in useful. The first function adds
FollowMe to the Settings menu:
Class followme {
function init() {
// attach the handler
add_action('wp_head',
array('followme', 'wp_head'));
add_action('wp_footer',
array('followme', 'wp_footer'));
// attach to admin menu
if (is_admin()) {
add_action('admin_menu',
array('followme', '_menu')
);
tip
When you look at the FollowMe
code, you will see that each
section is clearly marked with
dividers, so you can see what's
going on. There's no particular
standard for dividing things up,
so choose a character or other
method of clearly marking
your code, and stick with it so
others can always see what
you did.
}
This code hooks into the built-in WordPress plug-in upgrade system:
// attach to plugin installation
register_activation_hook(
__FILE__,
array('followme', 'install')
);
// plugin updated, upgrade it
//
if (version_compare(followme::version(), get_option('followme_version')) > 0)
{
followme::install();
}
}
This section puts a function called followmerize in the page footer—see, we told you some plug-ins
take advantage of the footer real estate! You'll see what 'snippets' are shortly.
function wp_head() {
return followme::followmerize(__FUNCTION__);
}
function wp_footer() {
return followme::followmerize(__FUNCTION__);
}
function followmerize($tag) {
$followme_settings = (array) get_option('followme_settings');
if (isset($followme_settings['snippets'][$tag])) {
echo $followme_settings['snippets'][$tag];
}
}
Search WWH ::




Custom Search