PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.1.36
Gallery : FooGallery v3.1.36
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / foopluginbase / classes / class-foo-plugin-metabox-sanity.php
foogallery / includes / foopluginbase / classes Last commit date
class-foo-friendly-dates.php 2 months ago class-foo-plugin-base.php 2 months ago class-foo-plugin-file-locator.php 2 months ago class-foo-plugin-metabox-sanity.php 2 months ago class-foo-plugin-options.php 2 months ago class-foo-plugin-settings.php 2 months ago class-foo-plugin-textdomain.php 2 months ago index.php 2 months ago
class-foo-plugin-metabox-sanity.php
102 lines
1 <?php
2 /**
3 * Foo Metabox Sanity allows plugin authors to whitelist metaboxes for your custom post types
4 * Original code and idea by Thomas Griffin - https://github.com/thomasgriffin/metabox-sanity
5 *
6 * @package Foo_Plugin_Base
7 * @version 1.0.0
8 * @author Brad Vincent
9 * @copyright Copyright (c) 2014, Brad Vincent
10 * @license http://opensource.org/licenses/gpl-2.0.php GPL v2 or later
11 * @link https://github.com/fooplugins/Foo_Plugin_Base
12 */
13
14 /*
15 Copyright 2014 Brad Vincent (fooplugins.com)
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License, version 2, as
19 published by the Free Software Foundation.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30
31 if ( !class_exists( 'Foo_Plugin_Metabox_Sanity_v1' ) ) {
32 /**
33 * Provides an intuitive way for plugins to whitelist
34 * metaboxes on their custom post type interfaces.
35 *
36 * @since 2.1.0
37 *
38 * @package Foo_Plugin_Base
39 * @author Brad Vincent
40 */
41 class Foo_Plugin_Metabox_Sanity_v1 {
42
43 protected $plugin_slug;
44
45 public function __construct($plugin_slug) {
46 $this->plugin_slug = $plugin_slug;
47
48 add_action( 'add_meta_boxes', array($this, 'maintain_sanity'), 999 );
49 }
50
51 /**
52 * TODO
53 */
54 function maintain_sanity() {
55
56 $metabox_sanity_config = apply_filters( $this->plugin_slug . '_metabox_sanity', false );
57
58 // If there is no data, return.
59 if ( empty($metabox_sanity_config) ) {
60 return;
61 }
62
63 // Bring the global metaboxes array into scope.
64 global $wp_meta_boxes;
65
66 // Loop through each post type and start whitelisting metaboxes!
67 foreach ( $metabox_sanity_config as $post_type => $data ) {
68 // If no contexts or priorities have been specified, do nothing.
69 if ( empty($data['contexts']) || empty($data['priorities']) ) {
70 continue;
71 }
72
73 // Now loop through each context that has been assigned to the post type.
74 foreach ( (array) $data['contexts'] as $context ) {
75 // Now loop through each priority within the context.
76 foreach ( (array) $data['priorities'] as $priority ) {
77 if ( isset($wp_meta_boxes[$post_type][$context][$priority]) ) {
78 // Loop through each priority and check the data to determine whether the metabox will stay or go.
79 foreach ( (array) $wp_meta_boxes[$post_type][$context][$priority] as $id => $metabox_data ) {
80 // If the metabox ID matches one to pass over, whitelist it and allow it to be registered.
81 if ( in_array( $id, (array) $data['whitelist'] ) ) {
82 unset($data['whitelist'][$id]);
83 continue;
84 }
85
86 // Otherwise, loop over the IDs to skip and see if there is a relevant match to whitelist.
87 foreach ( (array) $data['whitelist'] as $skip ) {
88 if ( preg_match( '#^' . $id . '#i', $skip ) ) {
89 continue;
90 }
91 }
92
93 // The metabox is not allowed on this screen. Prevent it from being registered.
94 unset($wp_meta_boxes[$post_type][$context][$priority][$id]);
95 }
96 }
97 }
98 }
99 }
100 }
101 }
102 }