I want to do something like: want to display one plugin's page on other plugin's page.

I have read Including file or library from other plugin but its not working for me or either am doing something wrong

let say I want to use plugin-1 into plugin-2

here whats the meaning of

do_action( 'my_library_loaded', plugin_dir_path( __FILE__ ) );

plugin_dir_path( FILE ) path of which plugin (plugin-1 or plugin-2 ?) and where I have to put this? (in plugin-1 or plugin-2 ?)

same question for add_action( 'my_library_loaded', 'other_plugin_init_handler' );

any suggestion please

  • If your having a problem with the answer on that question your better off commenting on it then making a duplicate question. Also could do with a little more info than its not working. Aug 29, 2013 at 9:52
  • My suggestion is to add your code to the question. :)
    – fuxia
    Aug 29, 2013 at 9:55
  • I have updated but how to link my question with other question in stackexchange
    – anytime
    Aug 29, 2013 at 10:28

1 Answer 1

  1. The first plugin, the base, calls do_action() or apply_filters().
  2. The second plugin, the one relying on the the first, uses add_action() or add_filter().

Basic example

Base plugin

<?php # -*- coding: utf-8 -*-
 * Plugin Name: Base
 * Plugin URI:  http://wordpress.stackexchange.com/q/112075

class Plugin_Base {

    public function __construct()
        add_action( 'wp_loaded', array ( $this, 'plugin_setup' ) );

    public function plugin_setup()
        $headers = get_file_data(
                'name' => 'Plugin Name',
                'uri'  => 'Plugin URI'
        $data    = new stdClass;
        $data->plugin_name = $headers[ 'name' ];
        $data->plugin_uri  = $headers[ 'uri' ];
        $data->plugin_file = __FILE__;

        do_action( 'plugin_base_loaded', $data );

new Plugin_Base;

Note the custom action plugin_base_loaded. This will be the anchor for all depending plugins.

Now let’s create a second plugin that should run after the base has been loaded.

Addon plugin

<?php # -*- coding: utf-8 -*-
 * Plugin Name: Base Addon
class Plugin_Base_Addon {

    protected $data;

    public function __construct()
        add_action( 'plugin_base_loaded', array ( $this, 'setup' ) );

    public function setup( $data )
        $this->data = $data;

        add_action( 'wp_footer', array( $this, 'wp_footer' ) );

    public function wp_footer()
            '<p>I am an addon for <a href="%1$s">%2$s</a> which lives in <code>%3$s</code>.</p>',
            esc_url( $this->data->plugin_uri ),
            esc_html( $this->data->plugin_name ),
            esc_html( $this->data->plugin_file )

new Plugin_Base_Addon;

This second plugin will not do anything if the base is not active. And if it is active, it will wait until the base has been loaded. Then it will print information about the base into the front-end footer.

You can see a broader example in my article Initialize a plugin with a configuration object, code examples, including an additional plugin, are on GiHub.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.