Articles of plugin development

wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated

So, I have a plugin that uses Ajax to dynamically build the post content piece by piece for a custom post type. Once the user has build their page, they hit Update/Publish and Ajax sends the entire built page to a the main plugin PHP file where I am attempting to call wp_insert_post(). Here is […]

Why this global array is returning NULL from a callback function

This drove me crazy for hours now… Please tell me why the $ppk_fields array is empty in the ppk_field_callback function? Note that it returns the correct values in the ppk_default_id function but that is not a callback function. Thank you! ppk.php class Ppk { public function ini() { add_action( ‘admin_menu’, array( $this, ‘add_ppk_p_menu’ ) ); […]

Only allow plugin to be activated on root site of multisite

I’m developing the wordpress file monitor plus plugin. Its purpose is to scan for altered files and it works fine for a single installation of WP. But when you look at multi-site it’s not something that wants to be enabled on all sub sites, as they all share the same files and (to be honest) […]

Demystifying and understanding shortcode nomenclature

A code snippet from the Tuts Plus → function link($atts, $content = null) { extract(shortcode_atts(array( “to” => ‘’ ), $atts)); return ‘<a href=”‘.$to.'”>’.$content.'</a>’; } Source Link → Question → How to reproduce “$to” in the shortcode? I tried this → [link $to= “”] But this didnt worked.

Plugin options table,is the data serialized

I am planning on building a plugin and i need to know if the data stored in the options table i will create for the plugin will be serialized or it will be in the ordinary sql format.

Where should I put “run once” plugin pages?

Where should I put an administration page that should only be used once? I am creating a plugin that will index all used HTML tags in your posts, so you can cleanup posts if you change themes and want to replace old incorrect <font> tags with headers or other semantic markup. When you install this […]

anything like add_meta_box for categories?

I want to add few custom fields to categories. So I am looking for something like add_meta_box but for categories. Is there any WP function like that for categories?

which action to hook to in order to perform post-publish action

I have some functionality I’ve written in order to post the title and link for the post to twitter whenever a post is published. I’m wondering which wp function to hook this to? save_post has no real reference documentation. Basically I just want to run an action when a post is successfully published. Thanks very […]

Can I leave out `if ( ! defined …)` when defining plugin constants?

I’m writing a WordPress plugin. At the top of the plugin file, I define some constants. Can I leave out the if ( ! defined( ‘THE_CONSTANT’ ) ) tests? Some other plugins that I’ve studied includes such if ( ! defined tests, some don’t. Personally, I don’t know why my plugin file would ever be […]

Unit testing wordpress plugins with plugin options

I’m new with unit testing in WordPress. I managed to setup the unit testing environment using PHP Unit and WordPress tests but I am having trouble accessing the plugin options that I’ve set in the plugin. class nrw_pg{ private $twitter_id; public function __construct(){ $options = get_option(‘nrw_pg_options’); $this->twitter_id = (!empty($options[‘nrw_pg_options_twitter_id’])) ? $options[‘nrw_pg_options_twitter_id’] : ”; } public […]