-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrbm-cpts.php
More file actions
289 lines (239 loc) · 7 KB
/
rbm-cpts.php
File metadata and controls
289 lines (239 loc) · 7 KB
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
/**
* Plugin Name: RBM Custom Post Types
* Description: Creates custom post types.
* Version: 1.2.2
* Author: Real Big Marketing
* Author URI: http://realbigmarketing.com
* GitHub Plugin URI: realbig/rbm-cpts
* GitHub Branch: master
*/
defined( 'ABSPATH' ) || die();
if ( ! class_exists( 'RBM_CPTS' ) ) {
// Define plugin constants
define( 'RBM_CPTS_VERSION', '1.2.2' );
define( 'RBM_CPTS_DIR', plugin_dir_path( __FILE__ ) );
define( 'RBM_CPTS_URL', plugins_url( '', __FILE__ ) );
/**
* Class RBM_CPTS
*
* Initiates the plugin.
*
* @since 0.1.0
*
* @package RBM_CPTS
*/
class RBM_CPTS {
/**
* Custom Post Types.
*
* @since 0.1.0
*
* @var array
*/
public $cpts;
/**
* Post to Post relationships.
*
* @since 0.1.0
*
* @var RBM_CPTS_P2P
*/
public $p2ps;
/**
* RBM Field Helpers instance.
*
* @since 1.1.0
*
* @var RBM_FieldHelpers
*/
public $fieldhelpers;
/**
* @var array $plugin_data Holds Plugin Header Info
* @since 1.2.1
*/
public $plugin_data;
/**
* @var array $admin_errors Stores all our Admin Errors to fire at once
* @since 1.2.1
*/
private $admin_errors;
public function __clone() {
}
public function __wakeup() {
}
/**
* Returns the *Singleton* instance of this class.
*
* @since 0.1.0
*
* @staticvar Singleton $instance The *Singleton* instances of this class.
*
* @return RBM_CPTS Outline The *Singleton* instance.
*/
public static function getInstance() {
static $instance = null;
if ( null === $instance ) {
$instance = new static();
}
return $instance;
}
/**
* Initializes the plugin.
*
* @since 0.1.0
*/
protected function __construct() {
$this->setup_constants();
$this->load_textdomain();
if ( ! class_exists( 'RBM_FieldHelpers' ) ) {
$this->admin_errors[] = sprintf( __( 'To use the %s Plugin, %s must be installed!', 'rbm-cpts' ), '<strong>' . $this->plugin_data['Name'] . '</strong>', '<a href="//github.com/realbig/rbm-field-helpers-wrapper/" target="_blank">' . __( 'RBM Field Helpers', 'rbm-cpts' ) . '</a>' );
if ( ! has_action( 'admin_notices', array( $this, 'admin_errors' ) ) ) {
add_action( 'admin_notices', array( $this, 'admin_errors' ) );
}
return false;
}
$this->setup_fieldhelpers();
$this->require_necessities();
}
/**
* Setup plugin constants
*
* @access private
* @since 1.2.1
* @return void
*/
private function setup_constants() {
// WP Loads things so weird. I really want this function.
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
// Only call this once, accessible always
$this->plugin_data = get_plugin_data( __FILE__ );
if ( ! defined( 'RBM_CPTS_VER' ) ) {
// Plugin version
define( 'RBM_CPTS_VER', $this->plugin_data['Version'] );
}
if ( ! defined( 'RBM_CPTS_DIR' ) ) {
// Plugin path
define( 'RBM_CPTS_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'RBM_CPTS_URL' ) ) {
// Plugin URL
define( 'RBM_CPTS_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'RBM_CPTS_FILE' ) ) {
// Plugin File
define( 'RBM_CPTS_FILE', __FILE__ );
}
}
/**
* Internationalization
*
* @access private
* @since 1.2.1
* @return void
*/
private function load_textdomain() {
// Set filter for language directory
$lang_dir = RBM_CPTS_DIR . '/languages/';
$lang_dir = apply_filters( 'rbm_cpts_languages_directory', $lang_dir );
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), 'rbm-cpts' );
$mofile = sprintf( '%1$s-%2$s.mo', 'rbm-cpts', $locale );
// Setup paths to current locale file
$mofile_local = $lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/rbm-cpts/' . $mofile;
if ( file_exists( $mofile_global ) ) {
// Look in global /wp-content/languages/rbm-cpts/ folder
// This way translations can be overridden via the Theme/Child Theme
load_textdomain( 'rbm-cpts', $mofile_global );
}
else if ( file_exists( $mofile_local ) ) {
// Look in local /wp-content/plugins/rbm-cpts/languages/ folder
load_textdomain( 'rbm-cpts', $mofile_local );
}
else {
// Load the default language files
load_plugin_textdomain( 'rbm-cpts', false, $lang_dir );
}
}
/**
* Requires necessary base files.
*
* @since 0.1.0
*/
public function require_necessities() {
require_once __DIR__ . '/core/class-rbm-cpt.php';
require_once __DIR__ . '/core/class-rbm-cpts-p2p.php';
$this->p2ps = new RBM_CPTS_P2P();
}
/**
* Initializes Field Helpers.
*
* @since 1.2.0
* @access private
*/
private function setup_fieldhelpers() {
$this->field_helpers = new RBM_FieldHelpers( array(
'ID' => 'rbm_cpts',
'l10n' => array(
'field_table' => array(
'delete_row' => __( 'Delete Row', 'rbm-cpts' ),
'delete_column' => __( 'Delete Column', 'rbm-cpts' ),
),
'field_select' => array(
'no_options' => __( 'No select options.', 'rbm-cpts' ),
'error_loading' => __( 'The results could not be loaded', 'rbm-cpts' ),
/* translators: %d is number of characters over input limit */
'input_too_long' => __( 'Please delete %d character(s)', 'rbm-cpts' ),
/* translators: %d is number of characters under input limit */
'input_too_short' => __( 'Please enter %d or more characters', 'rbm-cpts' ),
'loading_more' => __( 'Loading more results...', 'rbm-cpts' ),
/* translators: %d is maximum number items selectable */
'maximum_selected' => __( 'You can only select %d item(s)', 'rbm-cpts' ),
'no_results' => __( 'No results found', 'rbm-cpts' ),
'searching' => __( 'Searching...', 'rbm-cpts' ),
),
'field_repeater' => array(
'collapsable_title' => __( 'New Row', 'rbm-cpts' ),
'confirm_delete' => __( 'Are you sure you want to delete this element?', 'rbm-cpts' ),
'delete_item' => __( 'Delete', 'rbm-cpts' ),
'add_item' => __( 'Add', 'rbm-cpts' ),
),
'field_media' => array(
'button_text' => __( 'Upload / Choose Media', 'rbm-cpts' ),
'button_remove_text' => __( 'Remove Media', 'rbm-cpts' ),
'window_title' => __( 'Choose Media', 'rbm-cpts' ),
),
'field_checkbox' => array(
'no_options_text' => __( 'No options available.', 'rbm-cpts' ),
),
),
) );
}
/**
* Show admin errors.
*
* @access public
* @since 1.2.1
* @return void
*/
public function admin_errors() {
?>
<div class="error">
<?php foreach ( $this->admin_errors as $notice ) : ?>
<p>
<?php echo $notice; ?>
</p>
<?php endforeach; ?>
</div>
<?php
}
}
add_action( 'plugins_loaded', 'rbm_cpt_init' );
function rbm_cpt_init() {
require_once __DIR__ . '/core/rbm-cpts-functions.php';
RBM_CPTS();
}
}