Saturday, 25 May 2013

very simple oop issue with wordpress plugin

very simple oop issue with wordpress plugin

I'm using Tom Mc'Farlins Plugin Boilerplate, and I'm facing this huge problem. I can't update an option when the publish_post action is fired.
I have a function that hooks into the publish post action and all it does is update an option . This wasn't even my original task. What i wanted to do, was call a private function from within the function mentioned above, that would update the option. That didn't work out so i got down to updating the option from within the public function itself.
Here's the code--> and if someone can help me out with not just this, but also how to use the private function it would really bail me out. Thanks in advance,
P.S: the content filter, works, but the publish post action does not work. I've left the line which calls the private function commented out, so that you can test my two issues seperately.
Richard Madson.
<?php
/*
Plugin Name: winkadoka on caffeine
Plugin URI: zilch
Description: blah blah blah
Version: 1.1.1
Author: richard madson


License:GPL v.2

/*--------------------------------------------*
 * Constructor
 *--------------------------------------------*/

/**
 * Initializes the plugin by setting localization, filters, and administration functions.
 */
function __construct()
{

    // Load plugin text domain
    add_action( 'init', array( $this, 'plugin_textdomain' ) );

    // Register admin styles and scripts
    add_action( 'admin_print_styles', array( $this, 'register_admin_styles' ) );
    add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_scripts' ) );

    // Register site styles and scripts
    add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_styles' ) );
    add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_scripts' ) );

    // Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively.
    register_activation_hook( __FILE__, array( $this, 'activate' ) );
    register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
    register_uninstall_hook( __FILE__, array( $this, 'uninstall' ) );

    /*
     * TODO:
     * Define the custom functionality for your plugin. The first parameter of the
     * add_action/add_filter calls are the hooks into which your code should fire.
     *
     * The second parameter is the function name located within this class. See the stubs
     * later in the file.
     *
     * For more information:
     * http://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters
     */
    add_action( 'publish_post', array( $this, 'on_publish_post' ) );
    add_filter( 'the_content', array( $this, 'on_content_load' ) );

} // end constructor

/**
 * Fired when the plugin is activated.
 *
 * @param   boolean $network_wide   True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog
 */
public function activate( $network_wide ) {
    // TODO:    Define activation functionality here
    //on activation --->see what akismet does.

} // end activate

/**
 * Fired when the plugin is deactivated.
 *
 * @param   boolean $network_wide   True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin

No comments:

Post a Comment