sortable.php
5.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
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'CAC_SC_URL', plugin_dir_url( __FILE__ ) );
define( 'CAC_SC_DIR', plugin_dir_path( __FILE__ ) );
// only run plugin in the admin interface
if ( ! is_admin() ) {
return false;
}
/**
* Addon class
*
* @since 1.0
*/
class CAC_Addon_Sortable {
/**
* @since 1.0
*/
function __construct() {
// styling & scripts
add_action( "admin_print_styles-settings_page_codepress-admin-columns", array( $this, 'scripts' ) );
// add column properties
add_filter( 'cac/column/properties', array( $this, 'set_column_default_properties' ) );
// add column options
add_filter( 'cac/column/default_options', array( $this, 'set_column_default_options' ) );
// add setting field
add_action( 'cac/column/settings_after', array( $this, 'add_settings_field' ), 9 );
// add setting sort indicator
add_action( 'cac/column/settings_meta', array( $this, 'add_label_sort_indicator' ), 9 );
// init addon
add_action( 'cac/loaded', array( $this, 'init_addon_sortables' ) );
// add general settings
add_action( 'cac/settings/general', array( $this, 'add_settings' ) );
}
/**
* @since 1.0
*/
public function add_settings( $options ) {
?>
<p>
<label for="show_all_results">
<input name="cpac_general_options[show_all_results]" id="show_all_results" type="checkbox" value="1" <?php checked( isset( $options['show_all_results'] ) ? $options['show_all_results'] : '', '1' ); ?>>
<?php _e( 'Show all results when sorting. Default is <code>off</code>.', 'codepress-admin-columns' ); ?>
</label>
</p>
<?php
}
/**
* Add Addon to Admin Columns list
*
* @since 1.0
*/
public function add_addon( $addons ) {
$addons['cac-sortable'] = __( 'Sortable add-on', 'codepress-admin-columns' );
return $addons;
}
/**
* @since 1.0
*/
public function scripts() {
if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'cpac-settings', 'codepress-admin-columns' ) ) ) {
wp_enqueue_style( 'cac-addon-sortable-columns-css', CAC_SC_URL . 'assets/css/sortable.css', array(), CAC_PRO_VERSION, 'all' );
}
}
/**
* @since 1.0
*/
function set_column_default_properties( $properties ) {
if ( ! isset( $properties['is_sortable'] ) ) {
$properties['is_sortable'] = false;
}
return $properties;
}
/**
* @since 1.0
*/
function set_column_default_options( $options ) {
if ( ! isset( $options['sort'] ) ) {
$options['sort'] = 'off';
}
return $options;
}
/**
* @since 1.0
*/
function add_settings_field( $column ) {
if ( ! $column->properties->is_sortable ) {
return false;
}
$sort = isset( $column->options->sort ) ? $column->options->sort : '';
?>
<tr class="column_sorting">
<?php $column->label_view( __( 'Enable sorting?', 'codepress-admin-columns' ), __( 'This will make the column support sorting.', 'codepress-admin-columns' ), 'sorting' ); ?>
<td class="input" data-toggle-id="<?php $column->attr_id( 'sort' ); ?>">
<label for="<?php $column->attr_id( 'sort' ); ?>-on">
<input type="radio" value="on" name="<?php $column->attr_name( 'sort' ); ?>" id="<?php $column->attr_id( 'sort' ); ?>-on"<?php checked( $column->options->sort, 'on' ); ?> />
<?php _e( 'Yes'); ?>
</label>
<label for="<?php $column->attr_id( 'sort' ); ?>-off">
<input type="radio" value="off" name="<?php $column->attr_name( 'sort' ); ?>" id="<?php $column->attr_id( 'sort' ); ?>-off"<?php checked( $column->options->sort, '' ); ?><?php checked( $column->options->sort, 'off' ); ?> />
<?php _e( 'No'); ?>
</label>
</td>
</tr>
<?php
}
/**
* Meta Label in the column header
*
* @since 1.0
*/
function add_label_sort_indicator( $column ) {
if ( ! $column->properties->is_sortable ) {
return false;
}
?>
<span title="<?php echo esc_attr( __( 'sort', 'codepress-admin-columns' ) ); ?>" class="sorting <?php echo $column->options->sort; ?>" data-indicator-id="<?php $column->attr_id( 'sort' ); ?>"></span>
<?php
}
/**
* Init Addons
*
* @since 1.0
*/
function init_addon_sortables( $cpac ) {
// Abstract
include_once 'classes/model.php';
// Childs
include_once 'classes/post.php';
include_once 'classes/media.php';
include_once 'classes/user.php';
include_once 'classes/comment.php';
include_once 'classes/link.php';
// Posts
foreach ( $cpac->get_post_types() as $post_type ) {
if ( $storage_model = $cpac->get_storage_model( $post_type ) ) {
new CAC_Sortable_Model_Post( $storage_model );
}
}
// Media
if ( $storage_model = $cpac->get_storage_model( 'wp-media' ) ) {
new CAC_Sortable_Model_Media( $storage_model );
}
// User
if ( $storage_model = $cpac->get_storage_model( 'wp-users' ) ) {
new CAC_Sortable_Model_User( $storage_model );
}
// Comment
if ( $storage_model = $cpac->get_storage_model( 'wp-comments' ) ) {
new CAC_Sortable_Model_Comment( $storage_model );
}
// Link
if ( $storage_model = $cpac->get_storage_model( 'wp-links' ) ) {
new CAC_Sortable_Model_Link( $storage_model );
}
}
}
new CAC_Addon_Sortable();