WP Plugin Coding Question
I wonder if someone can help me with a Wordpress plugin coding question.
I have the following boilerplate code:
<?php
/*
Plugin Name: Free eBooks Section
Plugin URI: Personal Development Resources - White Dove Books
Description: Free eBooks Section
Version: 0.1
Author: Will Edwards
*/
class FreeeBooksSection {
/*--------------------------------------------*
* Constants
*--------------------------------------------*/
const name = 'Free eBooks Section';
const slug = 'free_ebooks_section';
/**
* Constructor
*/
function __construct() {
//Hook up to the init action
add_action( 'init', array( &$this, 'init_free_ebooks_section' ) );
}
/**
* Runs when the plugin is activated
*/
function install_free_ebooks_section() {
// do not generate any output here
}
/**
* Runs when the plugin is initialized
*/
function init_free_ebooks_section() {
// Load JavaScript and stylesheets
$this->register_scripts_and_styles();
// Register the shortcode [free_books_section]
add_shortcode('free_books_section', 'render_shortcode');
if ( is_admin() ) {
//this will run when in the WordPress admin
} else {
//this will run when on the frontend
}
/*
* TODO: Define custom functionality for your plugin here
*
* For more information:
* Plugin API « WordPress Codex
*/
add_action( 'your_action_here', array( &$this, 'action_callback_method_name' ) );
add_filter( 'your_filter_here', array( &$this, 'filter_callback_method_name' ) );
}
function action_callback_method_name() {
// TODO define your action method here
}
function filter_callback_method_name() {
// TODO define your filter method here
}
function render_shortcode($atts) {
// Extract the attributes
extract(shortcode_atts(array(
'attr1' => 'foo', //foo is a default value
'attr2' => 'bar'
), $atts));
// you can now access the attribute values using $attr1 and $attr2
}
/**
* Registers and enqueues stylesheets for the administration panel and the
* public facing site.
*/
private function register_scripts_and_styles() {
if ( is_admin() ) {
} else {
} // end if/else
} // end register_scripts_and_styles
/**
* Helper function for registering and enqueueing scripts and styles.
*
* @name The ID to register with WordPress
* @file_path The path to the actual file
* @is_script Optional argument for if the incoming file_path is a JavaScript source file.
*/
private function load_file( $name, $file_path, $is_script = false ) {
$url = plugins_url($file_path, __FILE__);
$file = plugin_dir_path(__FILE__) . $file_path;
if( file_exists( $file ) ) {
if( $is_script ) {
wp_register_script( $name, $url, array('jquery') ); //depends on jquery
wp_enqueue_script( $name );
} else {
wp_register_style( $name, $url );
wp_enqueue_style( $name );
} // end if
} // end if
} // end load_file
} // end class
new FreeeBooksSection();
?>
And I want to include a single line of PHP that will only be executed when a page encounters the shortcode [free_books_section]
Can anyone tell me where in the above I should place that code.
Many thanks
Will
-
Wilco de Kreij -
[ 1 ] Thanks
{{ DiscussionBoard.errors[6356829].message }} -