WordPress Add_filter Priority Issue On 2 Different Custom Plugins (Metaboxes)

I recently developed 2 seperate wordpress plugins for one of my projects

  1. Partners
  2. Resource Library

Both plugins create custom post types fsb_partners and fsb_resource_library. And in both plugins I have created different metaboxes (partners plugin metabox contains one file field i.e. Logo and resource library plugin creates metabox with two file fields i.e. Audio and PDF).

Read More

I used following code to create metabox in each plugin:

add_filter( 'cmb_meta_boxes', array($this, "fsb_partners_metaboxes"), 999); —> Partners Plugin

add_filter( 'cmb_meta_boxes', array($this, "fsb_resource_library_metaboxes"), 999); —> Resource Library Plugin

Now only metabox at resource library plugin is visible and other is not. If I change the priority of partner plugin metabox to 9999 then it shows up but at the same time resource library plugins goes off.

I know it’s wordpress’s add_filter hook’s priority issue, but am unable to get hands on it. Any help?

Related posts

1 comment

  1. Fixed it myself. Just created a separate (common) function in my theme’s functions.php as follows:

    add_filter('cmb_meta_boxes', function( array $metaboxes = array() ) {
    
        global $fsb_resource_library, $fsb_partner;
    
        if( class_exists('fsb_resource_library') && is_object($fsb_resource_library) ) {
            $metaboxes += $fsb_resource_library->fsb_resource_library_metaboxes();  
        }
    
        if( class_exists('fsb_partners') && is_object($fsb_partner) ) {
            $metaboxes += $fsb_partner->fsb_partners_metaboxes();   
        }
    
        return $metaboxes;
    
    });
    

Comments are closed.