storage_model.php
24.2 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
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
<?php
/**
* Storage Model
*
* @since 2.0
*/
abstract class CPAC_Storage_Model {
/**
* @since 2.0
*/
public $label;
/**
* @since 2.3.5
*/
public $singular_label;
/**
* Identifier for Storage Model; Posttype etc.
*
* @since 2.0
*/
public $key;
/**
* Type of storage model; Post, Media, User or Comments
*
* @since 2.0
*/
public $type;
/**
* Meta type of storage model; post, user, comment. Mostly used for custom field data.
*
* @since 3.0
*/
public $meta_type;
/**
* Groups the storage model in the menu.
*
* @since 2.0
*/
public $menu_type;
/**
* @since NEWVERSIOM
*/
private $column_headings;
/**
* @since 2.0
* @var string
*/
public $page;
/**
* Uses PHP export to display settings
*
* @since 2.0
* @var string
*/
private $php_export = false;
/**
* @since 2.0.1
* @var array
*/
protected $columns_filepath;
/**
* @since 2.0.1
* @var array
*/
public $columns = array();
/**
* @since 2.1.0
* @var array
*/
public $custom_columns = array();
/**
* @since 2.1.0
* @var array
*/
public $default_columns = array();
/**
* @since 2.2
* @var array
*/
public $stored_columns = NULL;
/**
* @since 2.2
* @var array
*/
public $column_types = array();
/**
* @since 2.4.4
*/
abstract function get_default_column_names();
/**
* @since 2.0
* @return array Column Name | Column Label
*/
abstract function get_default_columns();
/**
* @since 2.2
*/
function __construct() {
// set columns paths
$this->set_columns_filepath();
// Populate columns for this screen.
add_action( 'admin_init', array( $this, 'set_columns_on_current_screen' ) );
}
/**
* Set menutype
*
* @since 2.4.1
*/
public function set_menu_type( $menu_type ) {
$this->menu_type = $menu_type;
return $this;
}
/**
* Checks if menu type is currently viewed
*
* @since 1.0
* @param string $key
* @return bool
*/
public function is_menu_type_current( $first_posttype ) {
// display the page that was being viewed before saving
if ( ! empty( $_REQUEST['cpac_key'] ) ) {
if ( $_REQUEST['cpac_key'] == $this->key ) {
return true;
}
}
// settings page has not yet been saved
elseif ( $first_posttype == $this->key ) {
return true;
}
return false;
}
/**
* @since 2.4.7
*/
public function format_meta_keys( $keys ) {
$add_hidden_meta = true; // always true @todo
$formatted_keys = array();
foreach ( $keys as $key ) {
// give hidden keys a prefix for identifaction
if ( $add_hidden_meta && "_" == substr( $key[0], 0, 1 ) ) {
$formatted_keys[] = 'cpachidden' . $key[0];
}
// non hidden keys are saved as is
elseif ( "_" != substr( $key[0], 0, 1 ) ) {
$formatted_keys[] = $key[0];
}
}
return $formatted_keys;
}
/**
* @since 2.0
* @return array
*/
public function get_meta_keys() {
if ( $cache = wp_cache_get( $this->key, 'cac_columns' ) ) {
$keys = $cache;
}
else {
$keys = $this->get_meta();
wp_cache_add( $this->key, $keys, 'cac_columns', 10 ); // 10 sec.
}
if ( is_wp_error( $keys ) || empty( $keys ) ) {
$keys = false;
}
else {
$keys = $this->format_meta_keys( $keys );
}
/**
* Filter the available custom field meta keys
* If showing hidden fields is enabled, they are prefixed with "cpachidden" in the list
*
* @since 2.0
*
* @param array $keys Available custom field keys
* @param CPAC_Storage_Model $storage_model Storage model class instance
*/
$keys = apply_filters( 'cac/storage_model/meta_keys', $keys, $this );
/**
* Filter the available custom field meta keys for this storage model type
*
* @since 2.0
* @see Filter cac/storage_model/meta_keys
*/
return apply_filters( "cac/storage_model/meta_keys/storage_key={$this->key}", $keys, $this );
}
/**
* @since 2.0
* @param array $fields Custom fields.
* @return array Custom fields.
*/
protected function add_hidden_meta( $fields ) {
if ( ! $fields ) {
return false;
}
$combined_fields = array();
// filter out hidden meta fields
foreach ( $fields as $field ) {
// give hidden fields a prefix for identifaction
if ( "_" == substr( $field[0], 0, 1 ) ) {
$combined_fields[] = 'cpachidden'.$field[0];
}
// non hidden fields are saved as is
elseif ( "_" != substr( $field[0], 0, 1 ) ) {
$combined_fields[] = $field[0];
}
}
if ( empty( $combined_fields ) )
return false;
return $combined_fields;
}
/**
* @since 2.0
*/
public function restore() {
delete_option( "cpac_options_{$this->key}" );
cpac_admin_message( "<strong>{$this->label}</strong> " . __( 'settings succesfully restored.', 'codepress-admin-columns' ), 'updated' );
// refresh columns otherwise the removed columns will still display
$this->set_columns_on_current_screen();
}
/**
* @since 2.0
*/
public function store( $columns = '' ) {
if ( ! empty( $_POST[ $this->key ] ) ) {
$columns = array_filter( $_POST[ $this->key ] );
}
if ( ! $columns ) {
cpac_admin_message( __( 'No columns settings available.', 'codepress-admin-columns' ), 'error' );
return false;
}
// sanitize user inputs
foreach ( $columns as $name => $options ) {
if ( $_column = $this->get_column_by_name( $name ) ) {
$columns[ $name ] = $_column->sanitize_storage( $options );
}
// Santize Label: Need to replace the url for images etc, so we do not have url problem on exports
// this can not be done by CPAC_Column::sanitize_storage() because 3rd party plugins are not available there
$columns[ $name ]['label'] = stripslashes( str_replace( site_url(), '[cpac_site_url]', trim( $columns[ $name ]['label'] ) ) );
}
// store columns
$result = update_option( "cpac_options_{$this->key}", $columns );
$result_default = update_option( "cpac_options_{$this->key}_default", array_keys( $this->get_default_columns() ) );
// error
if ( ! $result && ! $result_default ) {
cpac_admin_message( sprintf( __( 'You are trying to store the same settings for %s.', 'codepress-admin-columns' ), "<strong>{$this->label}</strong>" ), 'error' );
return false;
}
cpac_admin_message( sprintf( __( 'Settings for %s updated successfully.', 'codepress-admin-columns' ), "<strong>{$this->label}</strong>" ), 'updated' );
// refresh columns otherwise the newly added columns will not be displayed
$this->set_columns_on_current_screen();
/**
* Fires after a new column setup is stored in the database
* Primarily used when columns are saved through the Admin Columns settings screen
*
* @since 2.2.9
*
* @param array $columns List of columns ([columnid] => (array) [column properties])
* @param CPAC_Storage_Model $storage_model_instance Storage model instance
*/
do_action( 'cac/storage_model/columns_stored', $columns, $this );
return true;
}
/**
* Goes through all files in 'classes/column' and includes each file.
*
* @since 2.0.1
* @return array Column Classnames | Filepaths
*/
public function set_columns_filepath() {
$columns = array(
'CPAC_Column_Custom_Field' => CPAC_DIR . 'classes/column/custom-field.php',
'CPAC_Column_Taxonomy' => CPAC_DIR . 'classes/column/taxonomy.php',
'CPAC_Column_Used_By_Menu' => CPAC_DIR . 'classes/column/used-by-menu.php'
);
// Add-on placeholders
if ( ! cpac_is_pro_active() ) {
// Display ACF placeholder
if ( cpac_is_acf_active() ) {
$columns[ 'CPAC_Column_ACF_Placeholder' ] = CPAC_DIR . 'classes/column/acf-placeholder.php';
}
// Display WooCommerce placeholder
if ( cpac_is_woocommerce_active() ) {
$columns[ 'CPAC_Column_WC_Placeholder' ] = CPAC_DIR . 'classes/column/wc-placeholder.php';
}
}
// Directory to iterate
$columns_dir = CPAC_DIR . 'classes/column/' . $this->type;
if ( is_dir( $columns_dir ) ) {
$iterator = new DirectoryIterator( $columns_dir );
foreach( $iterator as $leaf ) {
if ( $leaf->isDot() || $leaf->isDir() ) {
continue;
}
// only allow php files, exclude .SVN .DS_STORE and such
if ( substr( $leaf->getFilename(), -4 ) !== '.php' ) {
continue;
}
// build classname from filename
$class_name = 'CPAC_Column_' . ucfirst( $this->type ) . '_' . implode( '_', array_map( 'ucfirst', explode( '-', basename( $leaf->getFilename(), '.php' ) ) ) );
// classname | filepath
$columns[ $class_name ] = $leaf->getPathname();
}
}
/**
* Filter the available custom column types
* Use this to register a custom column type
*
* @since 2.0
* @param array $columns Available custom columns ([class_name] => [class file path])
* @param CPAC_Storage_Model $storage_model Storage model class instance
*/
$columns = apply_filters( 'cac/columns/custom', $columns, $this );
/**
* Filter the available custom column types for a specific type
*
* @since 2.0
* @see Filter cac/columns/custom
*/
$columns = apply_filters( 'cac/columns/custom/type=' . $this->type, $columns, $this );
/**
* Filter the available custom column types for a specific type
*
* @since 2.0
* @see Filter cac/columns/custom
*/
$columns = apply_filters( 'cac/columns/custom/post_type=' . $this->key, $columns, $this );
$this->columns_filepath = $columns;
}
/**
* @since 2.0
* @param $column_name
* @param $label
* @return object CPAC_Column
*/
public function create_column_instance( $column_name, $label ) {
// create column instance
$column = new CPAC_Column( $this );
$column
->set_properties( 'type', $column_name )
->set_properties( 'name', $column_name )
->set_properties( 'label', $label )
->set_properties( 'is_cloneable', false )
->set_properties( 'default', true )
->set_properties( 'group', 'plugin' )
->set_options( 'label', $label )
->set_options( 'state', 'on' );
// Hide Label when it contains HTML elements
if( strlen( $label ) != strlen( strip_tags( $label ) ) ) {
$column->set_properties( 'hide_label', true );
}
// Label empty? Use it's column_name
if ( ! $label ) {
$column->set_properties( 'label', ucfirst( $column_name ) );
}
/**
* Filter the default column names
*
* @since 2.4.4
*
* @param array $default_column_names Default column names
* @param object $column Column object
* @param object $this Storage_Model object
*/
$default_column_names = apply_filters( 'cac/columns/defaults', $this->get_default_column_names(), $column, $this );
$default_column_names = apply_filters( 'cac/columns/defaults/type=' . $this->get_type(), $default_column_names, $column, $this );
$default_column_names = apply_filters( 'cac/columns/defaults/post_type=' . $this->get_post_type(), $default_column_names, $column, $this );
// set group for WP Default
if ( $default_column_names && in_array( $column_name, $default_column_names ) ) {
$column->set_properties( 'group', 'default' );
}
return $column;
}
/**
* @since 2.0
* @return array Column Type | Column Instance
*/
public function get_default_registered_columns() {
$columns = array();
// Default columns
foreach ( $this->get_default_columns() as $column_name => $label ) {
// checkboxes are mandatory
if ( 'cb' == $column_name ) {
continue;
}
$column = $this->create_column_instance( $column_name, $label );
$columns[ $column->properties->name ] = $column;
}
do_action( "cac/columns/registered/default", $columns, $this );
do_action( "cac/columns/registered/default/storage_key={$this->key}", $columns, $this );
return $columns;
}
/**
* @since 2.0
* @return array Column Type | Column Instance
*/
public function get_custom_registered_columns() {
$columns = array();
foreach ( $this->columns_filepath as $classname => $path ) {
include_once $path;
if ( ! class_exists( $classname ) ) {
continue;
}
$column = new $classname( $this );
// exlude columns that are not registered based on conditional logic within the child column
if ( ! $column->properties->is_registered ) {
continue;
}
$columns[ $column->properties->type ] = $column;
}
do_action( "cac/columns/registered/custom", $columns, $this );
do_action( "cac/columns/registered/custom/storage_key={$this->key}", $columns, $this );
return $columns;
}
/**
* @since 1.0
* @param string $key
* @return array Column options
*/
public function get_default_stored_columns() {
if ( ! $columns = get_option( "cpac_options_{$this->key}_default" ) ) {
return array();
}
return $columns;
}
/**
* @since 1.0
* @return array Column options
*/
public function get_stored_columns() {
$columns = $this->stored_columns;
if ( $this->stored_columns === NULL ) {
$columns = $this->get_database_columns();
}
$columns = apply_filters( 'cpac/storage_model/stored_columns', $columns, $this );
$columns = apply_filters( 'cpac/storage_model/stored_columns/storage_key=' . $this->key, $columns, $this );
if ( ! $columns ) {
return array();
}
return $columns;
}
public function get_database_columns() {
return get_option( "cpac_options_{$this->key}" );
}
/**
* Set stopred column by 3rd party plugins
*
* @since 2.3
*/
public function set_stored_columns( $columns ) {
$this->stored_columns = $columns;
// columns settings are set by external plugin
$this->php_export = true;
}
/**
* Are column set by third party plugin
*
* @since 2.3.4
*/
public function is_using_php_export() {
return $this->php_export;
}
/**
* @since 2.1.1
*/
public function get_post_type() {
return isset( $this->post_type ) ? $this->post_type : false;
}
/**
* @since 2.3.4
*/
public function get_type() {
return $this->type;
}
/**
* @since 2.3.4
*/
public function get_meta_type() {
return $this->meta_type;
}
/**
* Only set columns on current screens
*
* @since 2.2.6
*/
public function set_columns_on_current_screen() {
if ( ! $this->is_doing_ajax() && ! $this->is_columns_screen() && ! $this->is_settings_page() ) {
return;
}
$this->set_columns();
}
/**
* @since 2.0.2
*/
public function set_columns() {
do_action( 'cac/set_columns', $this );
$this->custom_columns = $this->get_custom_registered_columns();
$this->default_columns = $this->get_default_registered_columns();
$this->column_types = $this->get_grouped_column_types();
$this->columns = $this->get_columns();
do_action( 'cac/set_columns/after', $this );
}
public function get_grouped_column_types() {
$types = array();
$groups = array_keys( $this->get_column_type_groups() );
$columns = array_merge( $this->default_columns, $this->custom_columns );
foreach ( $groups as $group ) {
$grouptypes = array();
foreach ( $columns as $index => $column ) {
if ( $column->properties->group == $group ) {
$grouptypes[ $index ] = $column;
unset( $columns[ $index ] );
}
}
$types[ $group ] = $grouptypes;
}
return $types;
}
public function get_column_type_groups() {
$groups = array(
'default' => __( 'Default', 'codepress-admin-columns' ),
'custom-field' => __( 'Custom Field', 'codepress-admin-columns' ),
'custom' => __( 'Custom', 'codepress-admin-columns' ),
'plugin' => __( 'Columns by Plugins', 'codepress-admin-columns' ),
'acf' => __( 'Advanced Custom Fields', 'codepress-admin-columns' ),
'woocommerce' => __( 'WooCommerce', 'codepress-admin-columns' )
);
/**
* Filter the available column type groups
*
* @since 2.2
*
* @param array $groups Available groups ([groupid] => [label])
* @param CPAC_Storage_Model $storage_model_instance Storage model class instance
*/
$groups = apply_filters( "cac/storage_model/column_type_groups", $groups, $this );
$groups = apply_filters( "cac/storage_model/column_type_groups/storage_key={$this->key}", $groups, $this );
return $groups;
}
/**
* @since 2.0.2
*/
public function get_registered_columns() {
$types = array();
foreach ( $this->column_types as $grouptypes ) {
$types = array_merge( $types, $grouptypes );
}
return $types;
}
/**
* @since 2.3.4
* @param string Column Type
*/
public function get_registered_column( $column_type ) {
$columns = $this->get_registered_columns();
return isset( $columns[ $column_type ] ) ? $columns[ $column_type ] : false;
}
/**
* @since 2.0
*/
public function get_columns() {
do_action( 'cac/get_columns', $this );
$columns = array();
// get columns
$default_columns = $this->get_default_columns();
// @todo check if this solves the issue with not displaying value when using "manage_{$post_type}_posts_columns" at CPAC_Storage_Model_Post
$registered_columns = $this->get_registered_columns();
if ( $stored_columns = $this->get_stored_columns() ) {
$stored_names = array();
foreach ( $stored_columns as $name => $options ) {
if ( ! isset( $options['type'] ) ) {
continue;
}
$stored_names[] = $name;
// In case of a disabled plugin, we will skip column.
// This means the stored column type is not available anymore.
if ( ! in_array( $options['type'], array_keys( $registered_columns ) ) ) {
continue;
}
// add an clone number which defines the instance
$column = clone $registered_columns[ $options['type'] ];
$column->set_clone( $options['clone'] );
// preload options when php export is being used
$preload = $this->is_using_php_export() ? $options : false;
// repopulate the options, so they contains the right stored options
$column->populate_options( $preload );
$column->sanitize_label();
$columns[ $name ] = $column;
}
// In case of an enabled plugin, we will add that column.
// When $diff contains items, it means a default column has not been stored.
if ( $diff = array_diff( array_keys( $default_columns ), $this->get_default_stored_columns() ) ) {
foreach ( $diff as $name ) {
// because of the filter "manage_{$post_type}_posts_columns" the columns
// that are being added by CPAC will also appear in the $default_columns.
// this will filter out those columns.
if ( isset( $columns[ $name ] ) ) {
continue;
}
// is the column registered?
if ( ! isset( $registered_columns[ $name ] ) ) {
continue;
}
$columns[ $name ] = clone $registered_columns[ $name ];
}
}
}
// When nothing has been saved yet, we return the default WP columns.
else {
foreach ( array_keys( $default_columns ) as $name ) {
if ( isset( $registered_columns[ $name ] ) ) {
$columns[ $name ] = clone $registered_columns[ $name ];
}
}
/**
* Filter the columns that should be loaded if there were no stored columns
*
* @since 2.2.4
*
* @param array $columns List of columns ([column name] => [column instance])
* @param CPAC_Storage_Model $storage_model_instance Storage model class instance
*/
$columns = apply_filters( 'cpac/storage_model/columns_default', $columns, $this );
}
do_action( "cac/columns", $columns );
do_action( "cac/columns/storage_key={$this->key}", $columns );
return $columns;
}
/**
* @since 2.0
*/
public function get_column_by_name( $name ) {
if ( ! isset( $this->columns[ $name ] ) ) {
return false;
}
return $this->columns[ $name ];
}
/**
* @since 2.0
*/
public function add_headings( $columns ) {
// make sure we run this only once
if ( $this->column_headings ) {
return $this->column_headings;
}
// only add headings on overview screens, to prevent deactivating columns on the column settings screen
if ( ! $this->is_columns_screen() ) {
return $columns;
}
if ( ! ( $stored_columns = $this->get_stored_columns() ) ) {
return $columns;
}
if ( ! $this->default_columns ) {
return $columns;
}
$this->column_headings = array();
// add mandatory checkbox
if ( isset( $columns['cb'] ) ) {
$this->column_headings['cb'] = $columns['cb'];
}
// add active stored headings
foreach ( $stored_columns as $column_name => $options ) {
// Label needs stripslashes() for HTML tagged labels, like icons and checkboxes
$label = stripslashes( $options['label'] );
/**
* Filter the stored column headers label for use in a WP_List_Table
* Label needs stripslashes() for HTML tagged labels, like icons and checkboxes
*
* @since 2.0
* @param string $label Label
* @param string $column_name Column name
* @param array $options Column options
* @param CPAC_Storage_Model $storage_model Storage model class instance
*/
$label = apply_filters( 'cac/headings/label', $label, $column_name, $options, $this );
$label = str_replace( '[cpac_site_url]', site_url(), $label );
$this->column_headings[ $column_name ] = $label;
}
// Add 3rd party columns that have ( or could ) not been stored.
// For example when a plugin has been activated after storing column settings.
// When $diff contains items, it means an available column has not been stored.
if ( ! $this->is_using_php_export() && ( $diff = array_diff( array_keys( $columns ), $this->get_default_stored_columns() ) ) ) {
foreach ( $diff as $column_name ) {
$this->column_headings[ $column_name ] = $columns[ $column_name ];
}
}
return $this->column_headings;
}
/**
* @since 2.0
* @return string Link
*/
protected function get_screen_link() {
return is_network_admin() ? network_admin_url( $this->page . '.php' ) : admin_url( $this->page . '.php' );
}
/**
* @since 2.0
*/
public function screen_link() {
if ( $link = $this->get_screen_link() ) {
echo '<a href="' . $link . '" class="add-new-h2">' . __('View', 'codepress-admin-columns') . '</a>';
}
}
/**
* @since 2.0
*/
public function get_edit_link() {
return add_query_arg( array( 'page' => 'codepress-admin-columns', 'cpac_key' => $this->key ), admin_url( 'options-general.php' ) );
}
/**
* Whether this request is an AJAX request and marked as admin-column-ajax request.
* Mark your admin columns ajax request with plugin_id : 'cpac'.
*
* @since 2.0.5
* @return boolean
*/
public function is_doing_ajax() {
return cac_is_doing_ajax();
}
/**
* @since 2.0.3
* @global string $pagenow
* @global object $current_screen
* @return boolean
*/
public function is_columns_screen() {
global $pagenow;
if ( $this->page . '.php' != $pagenow ) {
return false;
}
// posttypes
if ( 'post' == $this->type ) {
$post_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : $this->type;
if ( $this->key != $post_type ) {
return false;
}
}
// taxonomy
if ( 'taxonomy' == $this->type ) {
$taxonomy = isset( $_GET['taxonomy'] ) ? $_GET['taxonomy'] : '';
if ( $this->taxonomy != $taxonomy ) {
return false;
}
}
// users
if ( 'wp-users' == $this->key && is_network_admin() ) {
return false;
}
return true;
}
/**
* Checks if the current page is the settings page
*
* @since 2.0.2
* @global string $pagenow
* @global string $plugin_page
* @return boolean
*/
public function is_settings_page() {
global $pagenow, $plugin_page;
return 'options-general.php' == $pagenow && ! empty( $plugin_page ) && 'codepress-admin-columns' == $plugin_page;
}
/**
* @since 2.3.2
*/
public function delete_general_option() {
delete_option( 'cpac_general_options' );
}
/**
* @since 2.1.1
*/
public function get_general_option( $option ) {
$options = get_option( 'cpac_general_options' );
if ( ! isset( $options[ $option ] ) )
return false;
return $options[ $option ];
}
}