Skip to content

Instantly share code, notes, and snippets.

@kovshenin
Created January 17, 2012 11:16
Show Gist options
  • Save kovshenin/1626284 to your computer and use it in GitHub Desktop.
Save kovshenin/1626284 to your computer and use it in GitHub Desktop.
WP_Plugin class concept
<?php
/*
Plugin Name: WP_Plugin class test
Description: Tosting things out, again.
Author: Konstantin Kovshenin
Version: 1.0
Author URI: http://kovshenin.com
*/
class WP_Plugin {
function __construct() {
add_filter( 'all', array( $this, 'a_method_name_somebody_would_never_guess' ) );
}
function a_method_name_somebody_would_never_guess() {
$args = func_get_args();
$tag = array_shift( $args );
$method = '__' . $tag;
if ( is_callable( array( $this, $method ) ) ) {
add_filter( $tag, array( $this, $method ), 10, count( $args ) );
}
}
}
// Here's an example of a plugin that would benefit from the above
class Some_Plugin extends WP_Plugin {
// Will filter the_title
function __the_title( $title ) {
return $title . '123';
}
// Will filter the_content
function __the_content( $content ) {
return $content . ' Add more content.';
}
// Will run during wp_footer
function __wp_footer() {
echo "I'm in the footer!";
}
}
$some_plugin = new Some_Plugin;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment