Skip to content

Instantly share code, notes, and snippets.

@jbubriski
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbubriski/9530018 to your computer and use it in GitHub Desktop.
Save jbubriski/9530018 to your computer and use it in GitHub Desktop.
WordPress Plugins 101 Agenda

Agenda

Intro

  • Dial people in
  • Does anyone have any issues with WAMP or WordPress running locally?
  • Any other important things to discuss?

Main Event

  • The anatomy of a plugin.
  • Creating a barebones plugin that does one thing, like insert a banner, or CSS or JS ref into the page, or something like that
  • Creating an admin form for your plugin.
  • A look at a more complex example.
<?php
/*
Plugin Name: Jbubriski Add jQuery
Plugin URI: http://johnnycode.com
Description: Adds jQuery
Author: John Bubriski
Version: 0.1
Author URI: http://johnnycode.com
Text Domain: jbubriski-add-jquery
Domain Path: /lang
*/
function jbubriski_add_jQuery()
{
if (!is_admin())
{
wp_enqueue_script('jQuery-2.0.3', '//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js', array(), '3', true);
}
}
add_action('wp_head', 'jbubriski_add_jQuery');
<?php
/*
Plugin Name: Jbubriski Add Caption Shortcode
Plugin URI: http://johnnycode.com
Description: Adds a caption shortcode
Author: John Bubriski
Version: 0.1
Author URI: http://johnnycode.com
Text Domain: jbubriski-add-shortcode
Domain Path: /lang
*/
function caption_shortcode($atts, $content = null)
{
return '<span class="caption">' . $content . '</span>';
}
add_shortcode('caption', 'caption_shortcode');
<?php
/*
Plugin Name: Johnny Code's head code
Plugin URI: http://johnnycode.com
Description: Adds code to the &lt;head&gt; section of the page.
Author: John Bubriski
Version: 0.1
Author URI: http://johnnycode.com
Text Domain: johnny-code-head-code
Domain Path: /lang
*/
function register_head_setting()
{
register_setting('general', 'jc_head-code');
add_settings_section('jc_head-code-section', 'Johnny Code Head Code', '__return_false', 'general');
add_settings_field('jc_head-code', 'Head Code HTML', 'jc_setting_callback_function', 'general', 'jc_head-code-section');
}
function jc_head_code()
{
if (!is_admin())
{
$head_code = get_option('jc_head-code');
echo $head_code;
}
}
function jc_setting_callback_function($args)
{
$head_code = html_entity_decode(get_option( 'jc_head-code'));
echo "<textarea name='jc_head-code' rows='12' cols='80'>$head_code</textarea>";
}
add_action('admin_init', 'register_head_setting');
add_action('wp_head', 'jc_head_code');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment