CMB2_Show_Filters

Show On Filters Use the 'cmb2_show_on' filter to further refine the conditions under which a metabox is displayed.

Defined (2)

The class is defined in the following location(s).

/includes/libraries/metabox/includes/CMB2_Show_Filters.php  
  1. class CMB2_Show_Filters { 
  2.  
  3. /** 
  4. * Get Show_on key. backwards compatible w/ 'key' indexes 
  5. * @since 2.0.0 
  6. * @param array $meta_box_args Metabox config array 
  7. * @return mixed show_on key or false 
  8. */ 
  9. private static function get_show_on_key( $meta_box_args ) { 
  10. $show_on = isset( $meta_box_args['show_on'] ) ? (array) $meta_box_args['show_on'] : false; 
  11. if ( $show_on && is_array( $show_on ) ) { 
  12.  
  13. if ( array_key_exists( 'key', $show_on ) ) { 
  14. return $show_on['key']; 
  15.  
  16. $keys = array_keys( $show_on ); 
  17. return $keys[0]; 
  18.  
  19. return false; 
  20.  
  21. /** 
  22. * Get Show_on value. backwards compatible w/ 'value' indexes 
  23. * @since 2.0.0 
  24. * @param array $meta_box_args Metabox config array 
  25. * @return mixed show_on value or false 
  26. */ 
  27. private static function get_show_on_value( $meta_box_args ) { 
  28. $show_on = isset( $meta_box_args['show_on'] ) ? (array) $meta_box_args['show_on'] : false; 
  29.  
  30. if ( $show_on && is_array( $show_on ) ) { 
  31.  
  32. if ( array_key_exists( 'value', $show_on ) ) { 
  33. return $show_on['value']; 
  34.  
  35. $keys = array_keys( $show_on ); 
  36.  
  37. return $show_on[ $keys[0] ]; 
  38.  
  39. return array(); 
  40.  
  41. /** 
  42. * Add metaboxes for an specific ID 
  43. * @since 1.0.0 
  44. * @param bool $display To display or not 
  45. * @param array $meta_box_args Metabox config array 
  46. * @return bool Whether to display this metabox on the current page. 
  47. */ 
  48. public static function check_id( $display, $meta_box_args, $cmb ) { 
  49.  
  50. $key = self::get_show_on_key( $meta_box_args ); 
  51. if ( ! $key || 'id' !== $key ) { 
  52. return $display; 
  53.  
  54. $object_id = is_admin() ? $cmb->object_id() : @get_the_id(); 
  55.  
  56. if ( ! $object_id ) { 
  57. return false; 
  58.  
  59. // If current page id is in the included array, display the metabox 
  60. return in_array( $object_id, (array) self::get_show_on_value( $meta_box_args ) ); 
  61.  
  62. /** 
  63. * Add metaboxes for an specific Page Template 
  64. * @since 1.0.0 
  65. * @param bool $display To display or not 
  66. * @param array $meta_box_args Metabox config array 
  67. * @return bool Whether to display this metabox on the current page. 
  68. */ 
  69. public static function check_page_template( $display, $meta_box_args, $cmb ) { 
  70.  
  71. $key = self::get_show_on_key( $meta_box_args ); 
  72. if ( ! $key || 'page-template' !== $key ) { 
  73. return $display; 
  74.  
  75. $object_id = $cmb->object_id(); 
  76.  
  77. if ( ! $object_id || 'post' !== $cmb->object_type() ) { 
  78. return false; 
  79.  
  80. // Get current template 
  81. $current_template = get_post_meta( $object_id, '_wp_page_template', true ); 
  82.  
  83. // See if there's a match 
  84. if ( $current_template && in_array( $current_template, (array) self::get_show_on_value( $meta_box_args ) ) ) { 
  85. return true; 
  86.  
  87. return false; 
  88.  
  89. /** 
  90. * Only show options-page metaboxes on their options page (but only enforce on the admin side) 
  91. * @since 1.0.0 
  92. * @param bool $display To display or not 
  93. * @param array $meta_box_args Metabox config array 
  94. * @return bool Whether to display this metabox on the current page. 
  95. */ 
  96. public static function check_admin_page( $display, $meta_box_args ) { 
  97.  
  98. $key = self::get_show_on_key( $meta_box_args ); 
  99. // check if this is a 'options-page' metabox 
  100. if ( ! $key || 'options-page' !== $key ) { 
  101. return $display; 
  102.  
  103. // Enforce 'show_on' filter in the admin 
  104. if ( is_admin() ) { 
  105.  
  106. // If there is no 'page' query var, our filter isn't applicable 
  107. if ( ! isset( $_GET['page'] ) ) { 
  108. return $display; 
  109.  
  110. $show_on = self::get_show_on_value( $meta_box_args ); 
  111.  
  112. if ( empty( $show_on ) ) { 
  113. return false; 
  114.  
  115. if ( is_array( $show_on ) ) { 
  116. foreach ( $show_on as $page ) { 
  117. if ( $_GET['page'] == $page ) { 
  118. return true; 
  119. } else { 
  120. if ( $_GET['page'] == $show_on ) { 
  121. return true; 
  122.  
  123. return false; 
  124.  
  125.  
  126. // Allow options-page metaboxes to be displayed anywhere on the front-end 
  127. return true; 
  128.  
/vendor/wordimpress/maps-builder-core/includes/libraries/metabox/includes/CMB2_Show_Filters.php  
  1. class CMB2_Show_Filters { 
  2.  
  3. /** 
  4. * Get Show_on key. backwards compatible w/ 'key' indexes 
  5. * @since 2.0.0 
  6. * @param array $meta_box_args Metabox config array 
  7. * @return mixed show_on key or false 
  8. */ 
  9. private static function get_show_on_key( $meta_box_args ) { 
  10. $show_on = isset( $meta_box_args['show_on'] ) ? (array) $meta_box_args['show_on'] : false; 
  11. if ( $show_on && is_array( $show_on ) ) { 
  12.  
  13. if ( array_key_exists( 'key', $show_on ) ) { 
  14. return $show_on['key']; 
  15.  
  16. $keys = array_keys( $show_on ); 
  17. return $keys[0]; 
  18.  
  19. return false; 
  20.  
  21. /** 
  22. * Get Show_on value. backwards compatible w/ 'value' indexes 
  23. * @since 2.0.0 
  24. * @param array $meta_box_args Metabox config array 
  25. * @return mixed show_on value or false 
  26. */ 
  27. private static function get_show_on_value( $meta_box_args ) { 
  28. $show_on = isset( $meta_box_args['show_on'] ) ? (array) $meta_box_args['show_on'] : false; 
  29.  
  30. if ( $show_on && is_array( $show_on ) ) { 
  31.  
  32. if ( array_key_exists( 'value', $show_on ) ) { 
  33. return $show_on['value']; 
  34.  
  35. $keys = array_keys( $show_on ); 
  36.  
  37. return $show_on[ $keys[0] ]; 
  38.  
  39. return array(); 
  40.  
  41. /** 
  42. * Add metaboxes for an specific ID 
  43. * @since 1.0.0 
  44. * @param bool $display To display or not 
  45. * @param array $meta_box_args Metabox config array 
  46. * @return bool Whether to display this metabox on the current page. 
  47. */ 
  48. public static function check_id( $display, $meta_box_args, $cmb ) { 
  49.  
  50. $key = self::get_show_on_key( $meta_box_args ); 
  51. if ( ! $key || 'id' !== $key ) { 
  52. return $display; 
  53.  
  54. $object_id = is_admin() ? $cmb->object_id() : @get_the_id(); 
  55.  
  56. if ( ! $object_id ) { 
  57. return false; 
  58.  
  59. // If current page id is in the included array, display the metabox 
  60. return in_array( $object_id, (array) self::get_show_on_value( $meta_box_args ) ); 
  61.  
  62. /** 
  63. * Add metaboxes for an specific Page Template 
  64. * @since 1.0.0 
  65. * @param bool $display To display or not 
  66. * @param array $meta_box_args Metabox config array 
  67. * @return bool Whether to display this metabox on the current page. 
  68. */ 
  69. public static function check_page_template( $display, $meta_box_args, $cmb ) { 
  70.  
  71. $key = self::get_show_on_key( $meta_box_args ); 
  72. if ( ! $key || 'page-template' !== $key ) { 
  73. return $display; 
  74.  
  75. $object_id = $cmb->object_id(); 
  76.  
  77. if ( ! $object_id || 'post' !== $cmb->object_type() ) { 
  78. return false; 
  79.  
  80. // Get current template 
  81. $current_template = get_post_meta( $object_id, '_wp_page_template', true ); 
  82.  
  83. // See if there's a match 
  84. if ( $current_template && in_array( $current_template, (array) self::get_show_on_value( $meta_box_args ) ) ) { 
  85. return true; 
  86.  
  87. return false; 
  88.  
  89. /** 
  90. * Only show options-page metaboxes on their options page (but only enforce on the admin side) 
  91. * @since 1.0.0 
  92. * @param bool $display To display or not 
  93. * @param array $meta_box_args Metabox config array 
  94. * @return bool Whether to display this metabox on the current page. 
  95. */ 
  96. public static function check_admin_page( $display, $meta_box_args ) { 
  97.  
  98. $key = self::get_show_on_key( $meta_box_args ); 
  99. // check if this is a 'options-page' metabox 
  100. if ( ! $key || 'options-page' !== $key ) { 
  101. return $display; 
  102.  
  103. // Enforce 'show_on' filter in the admin 
  104. if ( is_admin() ) { 
  105.  
  106. // If there is no 'page' query var, our filter isn't applicable 
  107. if ( ! isset( $_GET['page'] ) ) { 
  108. return $display; 
  109.  
  110. $show_on = self::get_show_on_value( $meta_box_args ); 
  111.  
  112. if ( empty( $show_on ) ) { 
  113. return false; 
  114.  
  115. if ( is_array( $show_on ) ) { 
  116. foreach ( $show_on as $page ) { 
  117. if ( $_GET['page'] == $page ) { 
  118. return true; 
  119. } else { 
  120. if ( $_GET['page'] == $show_on ) { 
  121. return true; 
  122.  
  123. return false; 
  124.  
  125.  
  126. // Allow options-page metaboxes to be displayed anywhere on the front-end 
  127. return true; 
  128.