Filters - rogerlos/cmb2-metatabs-options GitHub Wiki

CMO has two filters available for you to add HTML markup before or after the options page form (ie, above or below your metaboxes and tabs). CMO expects either filter to return HTML ready for insertion into the options page.

By default, there is no pre-existing text affected by these filters; your filter can simply return HTML. Turns out this is not a great idea, see next graph.

Version 1.1.2: Note that if you have multiple plugins using CMO, it would be best to pass back $content if you don't modify it--turns out it may not be empty if another plugin has had a go at it. See note at bottom of page.

The filters are

  • cmb2metatabs_before_form
  • cmb2metatabs_after_form

Use them like so:

add_filter( 'cmb2metatabs_before_form', 'my_before_form' );

function my_before_form( $content ) {
    return '<p>Lorem ipsum dolor...</p>';
}

As of version 1.1.0, the page slug (['menuargs']['menu_slug']) is passed as a second argument, allowing logic to be performed in your callback if you have multiple options pages:

add_filter( 'cmb2metatabs_before_form', 'my_before_form', 10, 2 );

function my_before_form( $content, $page_slug ) {
    $good_stuff = $content;
    if ( $page_slug == $my_indicator ) {
        $good_stuff = '<p>My stuff is better than the other content.</p>';
    }
    return $good_stuff;
}

Note CMO sends an empty string as the $content argument.

Version 1.1.2: CMO now sets a variable to an empty string and then passes that variable to the filter. This allows the filter to be processed multiple times without losing modifications, as long as your callback returns the $content var unmodified if it doesn't need to be altered.