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