Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hi Dave. I can think of two pretty easy ways to check on such a thing.

    The first one would be checking if “CMB2_LOADED” is defined. Looks like Justin recommends this one as well from his comment in the code:

    /**
      * A constant you can use to check if CMB2 is loaded
      * for your plugins/themes with CMB2 dependency
      */
     if ( ! defined( 'CMB2_LOADED' ) ) {
             define( 'CMB2_LOADED', true );
     }

    The second one would be doing a class_exists() check for “CMB2”

    Hope that helps.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    class_exists check is not recommended, because the CMB2 class is loaded much later. the best way is to use if ( defined( 'CMB2_LOADED' ) ) { /* your stuff */ }.

    Thread Starter Dave Navarro, Jr.

    (@dnavarrojr)

    That is awesome, thanks so much!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Check for CMB2 in a plugin’ is closed to new replies.