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.2.1 |
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.2.1'; |
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> |
167
|
|
|
<?php |
168
|
|
|
printf( |
169
|
|
|
/* translators: 1: link opener; 2: link closer. */ |
170
|
|
|
esc_html__( 'CMB2 Admin Extension depends on the last version of %1$s the CMB2 plugin %2$s to work!', 'cmb2-admin-extension' ), |
171
|
|
|
'<a href="https://wordpress.org/plugins/cmb2/">', |
172
|
|
|
'</a>' |
173
|
|
|
); |
174
|
|
|
?> |
175
|
|
|
</p> |
176
|
|
|
</div> |
177
|
|
|
<?php |
178
|
|
|
|
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Add an error notice if the CMB2 plugin isn't activated. |
183
|
|
|
* |
184
|
|
|
* @return void |
185
|
|
|
*/ |
186
|
|
|
public function cmb2_not_activated() { |
187
|
|
|
|
188
|
|
|
?> |
189
|
|
|
<div class="error"> |
190
|
|
|
<p> |
191
|
|
|
<?php |
192
|
|
|
printf( |
193
|
|
|
/* translators: 1: link opener; 2: link closer. */ |
194
|
|
|
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' ), |
195
|
|
|
'<a href="' . esc_url( admin_url( 'plugins.php' ) ) . '">', |
196
|
|
|
'</a>' |
197
|
|
|
); |
198
|
|
|
?> |
199
|
|
|
</p> |
200
|
|
|
</div> |
201
|
|
|
<?php |
202
|
|
|
|
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
add_action( 'plugins_loaded', array( 'CMB2_Admin_Extension_Class', 'get_instance' ), 20 ); |
207
|
|
|
|
208
|
|
|
if ( ! function_exists( 'cmbf' ) ) { |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* This function needs documentation. |
212
|
|
|
* |
213
|
|
|
* @todo |
|
|
|
|
214
|
|
|
* |
215
|
|
|
* @param int $id Post ID. |
216
|
|
|
* @param string $field The meta key to retrieve. |
217
|
|
|
*/ |
218
|
|
|
function cmbf( $id, $field ) { |
|
|
|
|
219
|
|
|
|
220
|
|
|
return get_post_meta( $id, $field, true ); |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|