Skip to main content
Tweeted twitter.com/#!/StackWordPress/status/487697185434505216
edited body
Source Link
Philipp Kühn
  • 367
  • 1
  • 3
  • 15

i'm writing a plugin which requires another plugin. So i have to check first if the other plugin exists in a correct version.

If yes i want to add a submenu page to the plugin page but here my code doesn't seem to work.

I think the problem is, that i only can check the existence of other plugins with a late hook (admin_init). But to add submenus i have to use an earlier hook (admin_menu). How to solve that?

class acf_multisite_sync {
    
    function __construct() {

        add_action('admin_init', array($this, 'acf_sync_init'));
        
    }
    
    function acf_sync_init() {
        
        $plugins = get_plugins();
        
        if (isset($plugins['advanced-custom-fields-pro/acf.php'])) {
            
            if ($plugins['advanced-custom-fields-pro/acf.php']['Version'] >= 5 
                && is_plugin_active('advanced-custom-fields-pro/acf.php')
                && is_main_site())) {
                    
                add_action('admin_menu', array($this, 'acf_sync_submenu'));
                
            }
            
        }
    
    }
    
    function acf_sync_submenu() {
        
        add_submenu_page(
            'edit.php?post_type=acf-field-group', 
            'Multisite', 
            'Multisite', 
            'manage_options', 
            'acf-sync', 
            array($this, 'acf_sync_callback')
        );
        
    }
    
    function acf_sync_callback() {
        
        echo 'My Submenu Content';
    
    }

}

new acf_multisite_sync();

i'm writing a plugin which requires another plugin. So i have to check first if the other plugin exists in a correct version.

If yes i want to add a submenu page to the plugin page but here my code doesn't seem to work.

I think the problem is, that i only can check the existence of other plugins with a late hook (admin_init). But to add submenus i have to use an earlier hook (admin_menu). How to solve that?

class acf_multisite_sync {
    
    function __construct() {

        add_action('admin_init', array($this, 'acf_sync_init'));
        
    }
    
    function acf_sync_init() {
        
        $plugins = get_plugins();
        
        if (isset($plugins['advanced-custom-fields-pro/acf.php'])) {
            
            if ($plugins['advanced-custom-fields-pro/acf.php']['Version'] >= 5 
                && is_plugin_active('advanced-custom-fields-pro/acf.php'
                && is_main_site())) {
                    
                add_action('admin_menu', array($this, 'acf_sync_submenu'));
                
            }
            
        }
    
    }
    
    function acf_sync_submenu() {
        
        add_submenu_page(
            'edit.php?post_type=acf-field-group', 
            'Multisite', 
            'Multisite', 
            'manage_options', 
            'acf-sync', 
            array($this, 'acf_sync_callback')
        );
        
    }
    
    function acf_sync_callback() {
        
        echo 'My Submenu Content';
    
    }

}

new acf_multisite_sync();

i'm writing a plugin which requires another plugin. So i have to check first if the other plugin exists in a correct version.

If yes i want to add a submenu page to the plugin page but here my code doesn't seem to work.

I think the problem is, that i only can check the existence of other plugins with a late hook (admin_init). But to add submenus i have to use an earlier hook (admin_menu). How to solve that?

class acf_multisite_sync {
    
    function __construct() {

        add_action('admin_init', array($this, 'acf_sync_init'));
        
    }
    
    function acf_sync_init() {
        
        $plugins = get_plugins();
        
        if (isset($plugins['advanced-custom-fields-pro/acf.php'])) {
            
            if ($plugins['advanced-custom-fields-pro/acf.php']['Version'] >= 5 
                && is_plugin_active('advanced-custom-fields-pro/acf.php')
                && is_main_site()) {
                    
                add_action('admin_menu', array($this, 'acf_sync_submenu'));
                
            }
            
        }
    
    }
    
    function acf_sync_submenu() {
        
        add_submenu_page(
            'edit.php?post_type=acf-field-group', 
            'Multisite', 
            'Multisite', 
            'manage_options', 
            'acf-sync', 
            array($this, 'acf_sync_callback')
        );
        
    }
    
    function acf_sync_callback() {
        
        echo 'My Submenu Content';
    
    }

}

new acf_multisite_sync();
Source Link
Philipp Kühn
  • 367
  • 1
  • 3
  • 15

Howto check version of another plugin and then add a submenu page to it

i'm writing a plugin which requires another plugin. So i have to check first if the other plugin exists in a correct version.

If yes i want to add a submenu page to the plugin page but here my code doesn't seem to work.

I think the problem is, that i only can check the existence of other plugins with a late hook (admin_init). But to add submenus i have to use an earlier hook (admin_menu). How to solve that?

class acf_multisite_sync {
    
    function __construct() {

        add_action('admin_init', array($this, 'acf_sync_init'));
        
    }
    
    function acf_sync_init() {
        
        $plugins = get_plugins();
        
        if (isset($plugins['advanced-custom-fields-pro/acf.php'])) {
            
            if ($plugins['advanced-custom-fields-pro/acf.php']['Version'] >= 5 
                && is_plugin_active('advanced-custom-fields-pro/acf.php'
                && is_main_site())) {
                    
                add_action('admin_menu', array($this, 'acf_sync_submenu'));
                
            }
            
        }
    
    }
    
    function acf_sync_submenu() {
        
        add_submenu_page(
            'edit.php?post_type=acf-field-group', 
            'Multisite', 
            'Multisite', 
            'manage_options', 
            'acf-sync', 
            array($this, 'acf_sync_callback')
        );
        
    }
    
    function acf_sync_callback() {
        
        echo 'My Submenu Content';
    
    }

}

new acf_multisite_sync();