public
Last active

Answering the question on Quora: "How do I specify the loading order of plugins?" by changing the question to "How do you ensure that you declare your child class after the plugin's class is declared?" - http://www.quora.com/WordPress-Plugin-Development/How-do-I-specify-the-loading-order-of-plugins. Note I've boiled this example down to its bare essentials so the reader can understand the technique without concern for the best plugin code architecture which is a much bigger question. If you'd like to learn more about plugin code architecture check out our blog at HardcoreWP.com.

  • Download Gist
child-class-plugin-loader.php
PHP
1 2 3 4 5 6 7 8 9 10 11
<?php
 
/**
* class_exists() is a fail-safe.
*/
if ( ! class_exists( 'Parent_Class_Plugin' ) )
return;
 
class Child_Class_Plugin extends Parent_Class_Plugin {
// Your plugin code goes here.
}
child-class-plugin.php
PHP
1 2 3 4 5 6 7 8 9 10
<?php
/**
* Plugin Name: @Child Plugin
*/
 
add_action( 'plugins_loaded', 'child_class_plugin_loader' );
 
function child_class_plugin_loader() {
include dirname( __FILE__ ) . '/child-class-plugin-loader.php';
}
parent-class-plugin.php
PHP
1 2 3 4 5 6 7 8 9
<?php
 
/**
* Plugin Name: @Parent Plugin
*/
 
class Parent_Class_Plugin {
// Their plugin code went here.
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.