cmb_Meta_Box_Show_Filters

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

Defined (1)

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

/admin/includes/CMBF/helpers/cmb_Meta_Box_Show_Filters.php  
  1. class cmb_Meta_Box_Show_Filters { 
  2.  
  3. /** 
  4. * Add metaboxes for an specific ID 
  5. * @since 1.0.0 
  6. * @param bool $display To display or not 
  7. * @param array $meta_box Metabox config array 
  8. * @return bool Whether to display this metabox on the current page. 
  9. */ 
  10. public static function check_id( $display, $meta_box ) { 
  11.  
  12. if ( ! isset( $meta_box['show_on']['key'] ) || 'id' !== $meta_box['show_on']['key'] ) 
  13. return $display; 
  14.  
  15. $object_id = is_admin() ? cmb_Meta_Box::get_object_id() : @get_the_id(); 
  16.  
  17. if ( ! $object_id ) 
  18. return false; 
  19.  
  20. // If current page id is in the included array, display the metabox 
  21. return in_array( $object_id, (array) $meta_box['show_on']['value'] ); 
  22.  
  23. /** 
  24. * Add metaboxes for an specific Page Template 
  25. * @since 1.0.0 
  26. * @param bool $display To display or not 
  27. * @param array $meta_box Metabox config array 
  28. * @return bool Whether to display this metabox on the current page. 
  29. */ 
  30. public static function check_page_template( $display, $meta_box ) { 
  31.  
  32. if ( ! isset( $meta_box['show_on']['key'] ) || 'page-template' !== $meta_box['show_on']['key'] ) 
  33. return $display; 
  34.  
  35. $object_id = cmb_Meta_Box::get_object_id(); 
  36.  
  37. if ( ! $object_id || cmb_Meta_Box::get_object_type() !== 'post' ) 
  38. return false; 
  39.  
  40. // Get current template 
  41. $current_template = get_post_meta( $object_id, '_wp_page_template', true ); 
  42.  
  43. // See if there's a match 
  44. if ( $current_template && in_array( $current_template, (array) $meta_box['show_on']['value'] ) ) 
  45. return true; 
  46.  
  47. return false; 
  48.  
  49. /** 
  50. * Only show options-page metaboxes on their options page (but only enforce on the admin side) 
  51. * @since 1.0.0 
  52. * @param bool $display To display or not 
  53. * @param array $meta_box Metabox config array 
  54. * @return bool Whether to display this metabox on the current page. 
  55. */ 
  56. public static function check_admin_page( $display, $meta_box ) { 
  57.  
  58. // check if this is a 'options-page' metabox 
  59. if ( ! isset( $meta_box['show_on']['key'] ) || 'options-page' !== $meta_box['show_on']['key'] ) 
  60. return $display; 
  61.  
  62. // Enforce 'show_on' filter in the admin 
  63. if ( is_admin() ) { 
  64.  
  65. // If there is no 'page' query var, our filter isn't applicable 
  66. if ( ! isset( $_GET['page'] ) ) 
  67. return $display; 
  68.  
  69. if ( ! isset( $meta_box['show_on']['value'] ) ) 
  70. return false; 
  71.  
  72. $pages = $meta_box['show_on']['value']; 
  73.  
  74. if ( is_array( $pages ) ) { 
  75. foreach ( $pages as $page ) { 
  76. if ( $_GET['page'] == $page ) 
  77. return true; 
  78. } else { 
  79. if ( $_GET['page'] == $pages ) 
  80. return true; 
  81.  
  82. return false; 
  83.  
  84.  
  85. // Allow options-page metaboxes to be displayed anywhere on the front-end 
  86. return true; 
  87.