Skip to content

Extending with child plugins

franz-josef-kaiser edited this page Jan 17, 2013 · 1 revision

It's pretty easy, as you can read in the brief guide below.

Write a normal plugin (or mu-plugin) with a plugin header and a class. Then write a simple class that extends the current_screen_data class and it hook into plugins_loaded. Your class needs only two methods:

  • a static init() method
  • and a method that that is named collect() and does exactly that to your data for the output
  • you can optionally add a third method named markup() if you don't want a list. It has one argument that is your collected data.

Here's your new child plugins base:

<?php
/** Plugin Name: (WCM) CAI Extension */
defined( 'ABSPATH' ) OR exit;

add_action( 'plugins_loaded', array( 'wcm_cai_extension', 'init' ), 20 );
final class wcm_cai_extension extends current_screen_data
{
	private static $instance;

	public static function init()
	{
		null === self :: $instance AND self :: $instance = new self;
		return self :: $instance;
	}

	// This method collects data
	public function collect()
	{
		if ( ! defined( 'WP_ADMIN' ) )
			return;

		// Your logic goes here
	}
	// This method is optional and formats your output
	protected function markup( $set )
	{
		sort( $set );

		// Custom formatting goes here
	}
}
Clone this wiki locally