Skip to content

Instantly share code, notes, and snippets.

@coolamit
Created January 23, 2014 10:21
Show Gist options
  • Save coolamit/8576204 to your computer and use it in GitHub Desktop.
Save coolamit/8576204 to your computer and use it in GitHub Desktop.
A sample WordPress plugin - for evaluation of code refactoring
<?php
/*
Plugin Name: iG: Sample Plugin
Plugin URI: http://igeek.info/
Description: This is a sample plugin for code evaluation only
Version: 1.0
Author: Amit Gupta
License: GPL v2
*/
add_action( 'init', 'initialize_plugin' );
function initialize_plugin() {
//check if plugin's first run
if ( get_option( 'ig-sample-plugin', false ) == false ) {
//yes, install options
add_option( 'ig-sample-plugin', 1 );
}
add_action( 'wp_head', 'enqueue_stuff' );
add_filter( 'the_content', 'filter_post' );
add_filter( 'wp_footer', 'add_footer' );
}
//queue up JS & CSS to load on front-end
function enqueue_stuff() {
//load stylesheet
wp_enqueue_style( 'ig-sample-css', plugins_url( 'css/sample-styles.css', __FILE__ ) );
//load script
wp_enqueue_script( 'ig-sample-css', plugins_url( 'js/sample-script.js', __FILE__ ), array( 'jquery' ) );
}
//filter only posts and inject our code
function filter_post( $content ) {
//iG::filter_post() is loaded outside this plugin & is available
//globally on the current site, so assume its availability
$content = iG::filter_post( $content )->get();
return $content;
}
//add markup in footer
function add_footer() {
//iG::sample_generator() is loaded outside this plugin & is available
//globally on the current site, so assume its availability
?>
<div class="sample-footer">
<div class="logo"><img src="<?php echo iG::sample_generator()->get_image(); ?>"></div>
<div class="copy"><?php echo iG::sample_generator()->get_footer(); ?></div>
</div>
<?php
}
//EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment