-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathac-addon-genesis.php
319 lines (266 loc) · 8.3 KB
/
ac-addon-genesis.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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
/**
* Plugin Name: Admin Columns - Genesis Framework add-on
* Plugin URI: https://github.com/JoryHogeveen/ac-addon-genesis
* Version: 1.3
* Description: Show Genesis Framework fields in your admin post overviews and edit them inline! Genesis Framework integration Add-on for Admin Columns.
* Author: Jory Hogeveen
* Author URI: http://www.keraweb.nl
* Text Domain: ac-addon-genesis
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'ACA_GENESIS_FILE', __FILE__ );
class ACA_Genesis {
const CLASS_PREFIX = 'ACA_Genesis_';
/**
* @var ACA_Genesis
*/
protected static $_instance = null;
/**
* @return ACA_Genesis
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* ACA_Genesis constructor.
*/
private function __construct() {
add_action( 'after_setup_theme', array( $this, 'init' ) );
}
/**
* Check dependencies and register actions.
*/
public function init() {
if ( ! is_admin() ) {
return;
}
if ( $this->has_missing_dependencies() ) {
return;
}
require_once 'classes/Autoloader.php';
ACA_Genesis_Autoloader::instance()->register_prefix( 'ACA\Genesis', plugin_dir_path( ACA_GENESIS_FILE ) . 'classes/' );
add_action( 'ac/column_groups', array( $this, 'register_column_groups' ) );
// Prio 9 to make sure PRO is loaded after FREE.
add_action( 'ac/column_types', array( $this, 'add_columns' ), 9 );
add_action( 'acp/column_types', array( $this, 'add_pro_columns' ) );
// Scripts
add_action( 'ac/table_scripts', array( $this, 'table_scripts' ) );
add_action( 'ac/table_scripts/editing', array( $this, 'table_scripts_editing' ) );
}
/**
* @param AC\Groups $groups
*/
public function register_column_groups( $groups ) {
$groups->register_group( 'genesis', __( 'Genesis', 'genesis' ), 11 );
}
/**
* @return bool True when there are missing dependencies
*/
private function has_missing_dependencies() {
require_once 'classes/Dependencies.php';
$dependencies = new ACA_Genesis_Dependencies( plugin_basename( ACA_GENESIS_FILE ) );
$dependencies->check_php_version( '5.3.6' );
if ( $this->is_pro_active() ) {
$dependencies->check_acp( '4.4-dev' );
} else {
$dependencies->check_ac( '3.2' );
}
// Pro not required.
//$dependencies->is_acp_active( '4.0.3' );
if ( ! $this->is_genesis_active() ) {
$dependencies->add_missing_plugin( 'Genesis Framework', 'https://my.studiopress.com/themes/genesis/' );
}
return $dependencies->has_missing();
}
/**
* @return string
*/
public function get_plugin_basename() {
static $basename = null;
if ( $basename ) {
return $basename;
}
$basename = plugin_basename( __FILE__ );
return $basename;
}
/**
* @return string
*/
public function get_plugin_dir() {
static $dir = null;
if ( $dir ) {
return $dir;
}
$dir = plugin_dir_path( __FILE__ );
return $dir;
}
/**
* @return string
*/
public function get_plugin_url() {
static $url = null;
if ( $url ) {
return $url;
}
$url = plugin_dir_url( __FILE__ );
return $url;
}
/**
* @return int|float|string
*/
public function get_version() {
static $version = null;
if ( $version ) {
return $version;
}
$plugins = get_plugins();
$version = $plugins[ $this->get_plugin_basename() ]['Version'];
return $version;
}
/**
* Whether Admin Columns Pro is active
*
* @return bool
*/
private function is_pro_active() {
return function_exists( 'ac_is_pro_active' ) && ac_is_pro_active();
}
/**
* Whether Genesis is active
*
* @return bool Returns true if Genesis is active, false otherwise
*/
public function is_genesis_active() {
return 'genesis' === get_template();
}
/**
* @param AC_ListScreen $list_screen
*/
public function table_scripts_editing( $list_screen ) {
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
$url = $this->get_plugin_url();
wp_register_script(
'aca-genesis-xeditable-input-genesis_layout',
$url . 'assets/js/xeditable/input/genesis-layout' . $suffix . '.js',
array(
'jquery',
'acp-editing-table',
),
$this->get_version()
);
wp_register_script(
'aca-genesis-xeditable-input-select2_classes',
$url . 'assets/js/xeditable/input/select2-classes' . $suffix . '.js',
array(
'jquery',
'acp-editing-table',
),
$this->get_version()
);
// Translations
//wp_localize_script( 'aca-genesis-xeditable-input-genesis_layout', 'acp_genesis_i18n', array() );
}
/**
* @since 1.3
*
* @param AC_ListScreen $list_screen
*/
public function table_scripts( $list_screen ) {
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
$url = $this->get_plugin_url();
wp_register_style( 'aca-genesis-column', $url . 'assets/css/column' . $suffix . '.css', array(), $this->get_version() );
//wp_enqueue_script( 'aca-genesis-table', $url . 'assets/js/table.js', array( 'jquery' ), $this->get_version() );
}
/**
* Add custom columns
*
* @param AC_ListScreen $list_screen
*
*/
public function add_columns( $list_screen ) {
$has_multiple_layouts = genesis_has_multiple_layouts();
switch ( true ) {
case $list_screen instanceof AC\ListScreen\Post:
$post_type = $list_screen->get_post_type();
if ( current_theme_supports( 'genesis-inpost-layouts' ) && post_type_supports( $post_type, 'genesis-layouts' ) ) {
if ( $has_multiple_layouts ) {
$list_screen->register_column_type( new \ACA\Genesis\Column\Post\Layout() );
}
$list_screen->register_column_type( new \ACA\Genesis\Column\Post\BodyClass() );
$list_screen->register_column_type( new \ACA\Genesis\Column\Post\PostClass() );
}
break;
case $list_screen instanceof AC\ListScreen\User:
// Users also use archives.
if ( current_theme_supports( 'genesis-archive-layouts' ) ) {
if ( $has_multiple_layouts ) {
$list_screen->register_column_type( new \ACA\Genesis\Column\User\Layout() );
}
$list_screen->register_column_type( new \ACA\Genesis\Column\User\Headline() );
$list_screen->register_column_type( new \ACA\Genesis\Column\User\IntroText() );
}
break;
case $list_screen instanceof ACP\ListScreen\Taxonomy:
if ( current_theme_supports( 'genesis-archive-layouts' ) ) {
if ( $has_multiple_layouts ) {
$list_screen->register_column_type( new \ACA\Genesis\Column\Term\Layout() );
}
$list_screen->register_column_type( new \ACA\Genesis\Column\Term\Headline() );
$list_screen->register_column_type( new \ACA\Genesis\Column\Term\IntroText() );
}
break;
}
}
/**
* Add custom columns
*
* @param AC_ListScreen $list_screen
*/
public function add_pro_columns( $list_screen ) {
$has_multiple_layouts = genesis_has_multiple_layouts();
switch ( true ) {
case $list_screen instanceof AC\ListScreen\Post:
$post_type = $list_screen->get_post_type();
if ( current_theme_supports( 'genesis-inpost-layouts' ) && post_type_supports( $post_type, 'genesis-layouts' ) ) {
if ( $has_multiple_layouts ) {
$list_screen->register_column_type( new \ACA\Genesis\Pro\Column\Post\Layout() );
}
$list_screen->register_column_type( new \ACA\Genesis\Pro\Column\Post\BodyClass() );
$list_screen->register_column_type( new \ACA\Genesis\Pro\Column\Post\PostClass() );
}
break;
case $list_screen instanceof AC\ListScreen\User:
// Users also use archives.
if ( current_theme_supports( 'genesis-archive-layouts' ) ) {
if ( $has_multiple_layouts ) {
$list_screen->register_column_type( new \ACA\Genesis\Pro\Column\User\Layout() );
}
}
$list_screen->register_column_type( new \ACA\Genesis\Pro\Column\User\Headline() );
$list_screen->register_column_type( new \ACA\Genesis\Pro\Column\User\IntroText() );
break;
case $list_screen instanceof ACP\ListScreen\Taxonomy:
if ( current_theme_supports( 'genesis-archive-layouts' ) ) {
if ( $has_multiple_layouts ) {
$list_screen->register_column_type( new \ACA\Genesis\Pro\Column\Term\Layout() );
}
}
$list_screen->register_column_type( new \ACA\Genesis\Pro\Column\Term\Headline() );
$list_screen->register_column_type( new \ACA\Genesis\Pro\Column\Term\IntroText() );
break;
}
}
}
/**
* @return ACA_Genesis
*/
function ac_addon_genesis() {
return ACA_Genesis::instance();
}
ac_addon_genesis();