|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CMB2 Admin Extension - a WordPress plugin. |
|
4
|
|
|
* |
|
5
|
|
|
* @category WordPress_Plugin |
|
6
|
|
|
* @package CMB2-Admin-Extension |
|
7
|
|
|
* @author twoelevenjay |
|
8
|
|
|
* @license GPL-2.0+ |
|
9
|
|
|
* @link http://211j.com |
|
10
|
|
|
* |
|
11
|
|
|
* @wordpress-plugin |
|
12
|
|
|
* Plugin Name: CMB2 Admin Extension |
|
13
|
|
|
* Plugin URI: https://github.com/twoelevenjay/CMB2-Admin-Extension |
|
14
|
|
|
* Description: CMB2 Admin Extension add a user interface for admins to create CMB2 meta boxes from the WordPress admin. |
|
15
|
|
|
* Author: twoelevenjay |
|
16
|
|
|
* Author URI: http://211j.com |
|
17
|
|
|
* Contributors: |
|
18
|
|
|
* Version: 0.1.6 |
|
19
|
|
|
* Text Domain: cmb2-admin-extension |
|
20
|
|
|
* Domain Path: /languages |
|
21
|
|
|
* |
|
22
|
|
|
* |
|
23
|
|
|
* Released under the GPL license |
|
24
|
|
|
* http://www.opensource.org/licenses/gpl-license.php |
|
25
|
|
|
* |
|
26
|
|
|
* This is an add-on for WordPress |
|
27
|
|
|
* http://wordpress.org/ |
|
28
|
|
|
* |
|
29
|
|
|
* ********************************************************************** |
|
30
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
31
|
|
|
* it under the terms of the GNU General Public License as published by |
|
32
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
|
33
|
|
|
* (at your option) any later version. |
|
34
|
|
|
* |
|
35
|
|
|
* This program is distributed in the hope that it will be useful, |
|
36
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
37
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
38
|
|
|
* GNU General Public License for more details. |
|
39
|
|
|
* ********************************************************************** |
|
40
|
|
|
*/ |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Silence is golden; exit if accessed directly. |
|
44
|
|
|
*/ |
|
45
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
46
|
|
|
exit; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Define plugin constant. |
|
52
|
|
|
*/ |
|
53
|
|
|
if ( ! defined( 'CMB2AE_CMB2_PLUGIN_FILE' ) ) { |
|
54
|
|
|
define( 'CMB2AE_CMB2_PLUGIN_FILE', 'cmb2/init.php' ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if ( ! defined( 'CMB2AE_URI' ) ) { |
|
58
|
|
|
define( 'CMB2AE_URI', plugins_url( '', __FILE__ ) ); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if ( ! defined( 'CMB2AE_PATH' ) ) { |
|
62
|
|
|
define( 'CMB2AE_PATH', plugin_dir_path( __FILE__ ) ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* CMB2 Admin Extension main class. |
|
68
|
|
|
*/ |
|
69
|
|
|
class CMB2_Admin_Extension_Class { |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Plugin version. |
|
73
|
|
|
* |
|
74
|
|
|
* @var string |
|
75
|
|
|
*/ |
|
76
|
|
|
const VERSION = '0.1.6'; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Instance of this class. |
|
80
|
|
|
* |
|
81
|
|
|
* @var object |
|
82
|
|
|
*/ |
|
83
|
|
|
protected static $instance; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Initiate CMB2 Admin Extension. |
|
87
|
|
|
* |
|
88
|
|
|
* @since 0.0.1 |
|
89
|
|
|
*/ |
|
90
|
|
|
public function __construct() { |
|
91
|
|
|
|
|
92
|
|
|
$this->check_for_cmb2(); |
|
93
|
|
|
|
|
94
|
|
|
add_action( 'init', array( $this, 'load_textdomain' ), 9 ); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Return an instance of this class. |
|
99
|
|
|
* |
|
100
|
|
|
* @return object A single instance of this class. |
|
101
|
|
|
*/ |
|
102
|
|
|
public static function get_instance() { |
|
103
|
|
|
// If the single instance hasn't been set, set it now. |
|
104
|
|
|
if ( null === self::$instance ) { |
|
105
|
|
|
self::$instance = new self; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
return self::$instance; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Check for the CMB2 plugin. |
|
113
|
|
|
* |
|
114
|
|
|
* @since 0.0.1 |
|
115
|
|
|
*/ |
|
116
|
|
|
private function check_for_cmb2() { |
|
117
|
|
|
|
|
118
|
|
|
if ( defined( 'CMB2_LOADED' ) && CMB2_LOADED !== false ) { |
|
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
require_once dirname( __FILE__ ) . '/includes/class-meta-box.php'; |
|
121
|
|
|
require_once dirname( __FILE__ ) . '/includes/class-meta-box-post-type.php'; |
|
122
|
|
|
require_once dirname( __FILE__ ) . '/includes/class-meta-box-settings.php'; |
|
123
|
|
|
cmb2ae_metabox(); |
|
124
|
|
|
return; |
|
125
|
|
|
} elseif ( file_exists( WP_PLUGIN_DIR . '/' . CMB2AE_CMB2_PLUGIN_FILE ) ) { |
|
126
|
|
|
|
|
127
|
|
|
add_action( 'admin_notices', array( $this, 'cmb2_not_activated' ) ); |
|
128
|
|
|
return; |
|
129
|
|
|
} |
|
130
|
|
|
add_action( 'admin_notices', array( $this, 'missing_cmb2' ) ); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Load plugin textdomain. |
|
135
|
|
|
* |
|
136
|
|
|
* @return void |
|
137
|
|
|
*/ |
|
138
|
|
|
public function load_textdomain() { |
|
139
|
|
|
|
|
140
|
|
|
$lang_path = plugin_basename( dirname( __FILE__ ) ) . '/languages'; |
|
141
|
|
|
$loaded = load_muplugin_textdomain( 'cmb2-admin-extension', $lang_path ); |
|
142
|
|
|
if ( strpos( __FILE__, basename( WPMU_PLUGIN_DIR ) ) === false ) { |
|
|
|
|
|
|
143
|
|
|
$loaded = load_plugin_textdomain( 'cmb2-admin-extension', false, $lang_path ); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
if ( ! $loaded ) { |
|
147
|
|
|
$loaded = load_theme_textdomain( 'cmb2-admin-extension', get_stylesheet_directory() . '/languages' ); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
if ( ! $loaded ) { |
|
151
|
|
|
$locale = apply_filters( 'plugin_locale', get_locale(), 'cmb2-admin-extension' ); |
|
152
|
|
|
$mofile = dirname( __FILE__ ) . '/languages/cmb2-admin-extension-' . $locale . '.mo'; |
|
153
|
|
|
load_textdomain( 'cmb2-admin-extension', $mofile ); |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Add an error notice if the CMB2 plugin is missing. |
|
159
|
|
|
* |
|
160
|
|
|
* @return void |
|
161
|
|
|
*/ |
|
162
|
|
|
public function missing_cmb2() { |
|
163
|
|
|
|
|
164
|
|
|
?> |
|
165
|
|
|
<div class="error"> |
|
166
|
|
|
<p><?php printf( esc_html__( 'CMB2 Admin Extension depends on the last version of %1$s the CMB2 plugin %2$s to work!', 'cmb2-admin-extension' ), '<a href="https://wordpress.org/plugins/cmb2/">', '</a>' ); ?></p> |
|
167
|
|
|
</div> |
|
168
|
|
|
<?php |
|
169
|
|
|
|
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Add an error notice if the CMB2 plugin isn't activated. |
|
174
|
|
|
* |
|
175
|
|
|
* @return void |
|
176
|
|
|
*/ |
|
177
|
|
|
public function cmb2_not_activated() { |
|
178
|
|
|
|
|
179
|
|
|
?> |
|
180
|
|
|
<div class="error"> |
|
181
|
|
|
<p><?php printf( esc_html__( 'The CMB2 plugin is installed but has not been activated. Please %1$s activate %2$s it to use the CMB2 Admin Extension', 'cmb2-admin-extension' ), '<a href="' . esc_url( admin_url( 'plugins.php' ) ) . '">', '</a>' ); ?></p> |
|
182
|
|
|
</div> |
|
183
|
|
|
<?php |
|
184
|
|
|
|
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
add_action( 'plugins_loaded', array( 'CMB2_Admin_Extension_Class', 'get_instance' ), 20 ); |
|
189
|
|
|
|
|
190
|
|
|
if ( ! function_exists( 'cmbf' ) ) { |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* This function needs documentation. |
|
194
|
|
|
* |
|
195
|
|
|
* @todo |
|
|
|
|
|
|
196
|
|
|
* |
|
197
|
|
|
* @param int $id Post ID. |
|
198
|
|
|
* @param string $field The meta key to retrieve. |
|
199
|
|
|
*/ |
|
200
|
|
|
function cmbf( $id, $field ) { |
|
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
return get_post_meta( $id, $field, true ); |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|