PluginProbe
My WP Customize Admin/Frontend / 1.6
My WP Customize Admin/Frontend v1.6
1.27.4 1.27.3 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.10 1.10.1 1.10.2 1.11 1.12 1.12.1 1.12.2 1.13 1.13.1 1.13.2 1.14 1.15.0 1.16 1.17.0 All 76 releases
my-wp / controller / modules / mywp.controller.module.admin.posts.php

mywp.controller.module.admin.posts.php in My WP Customize Admin/Frontend 1.6, at controller/modules/mywp.controller.module.admin.posts.php

263 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if( ! class_exists( 'MywpControllerAbstractModule' ) ) {
8 return false;
9 }
10
11 if ( ! class_exists( 'MywpControllerModuleAdminPosts' ) ) :
12
13 final class MywpControllerModuleAdminPosts extends MywpControllerAbstractModule {
14
15 static protected $id = 'admin_posts';
16
17 static private $post_type = '';
18
19 public static function mywp_controller_initial_data( $initial_data ) {
20
21 $initial_data['bulk_post_updated_messages'] = array();
22
23 $initial_data['per_page_num'] = '';
24 $initial_data['hide_add_new'] = '';
25 $initial_data['hide_search_box'] = '';
26
27 return $initial_data;
28
29 }
30
31 public static function mywp_controller_default_data( $default_data ) {
32
33 $default_data['bulk_post_updated_messages'] = array();
34
35 $default_data['per_page_num'] = 20;
36 $default_data['hide_add_new'] = false;
37 $default_data['hide_search_box'] = false;
38
39 return $default_data;
40
41 }
42
43 public static function get_bulk_update_messages_default() {
44
45 $bulk_update_messages_default = array(
46 'updated' => _n( '%s post updated.', '%s posts updated.', 0 ),
47 'locked' => _n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', 0 ),
48 'deleted' => _n( '%s post permanently deleted.', '%s posts permanently deleted.', 0 ),
49 'trashed' => _n( '%s post moved to the Trash.', '%s posts moved to the Trash.', 0 ),
50 'untrashed' => _n( '%s post restored from the Trash.', '%s posts restored from the Trash.', 0 ),
51 );
52
53 return $bulk_update_messages_default;
54
55 }
56
57 public static function mywp_wp_loaded() {
58
59 if( ! is_admin() ) {
60
61 return false;
62
63 }
64
65 if( is_network_admin() ) {
66
67 return false;
68
69 }
70
71 if( ! self::is_do_controller() ) {
72
73 return false;
74
75 }
76
77 add_action( 'mywp_ajax' , array( __CLASS__ , 'mywp_ajax' ) , 1000 );
78
79 add_action( 'load-edit.php' , array( __CLASS__ , 'load_edit' ) , 1000 );
80
81 }
82
83 public static function mywp_get_option_key( $option_key ) {
84
85 if( empty( self::$post_type ) ) {
86
87 return $option_key;
88
89 }
90
91 $option_key .= '_' . self::$post_type;
92
93 return $option_key;
94
95 }
96
97 public static function mywp_ajax() {
98
99 if( empty( $_POST['action'] ) or $_POST['action'] != 'inline-save' ) {
100
101 return false;
102
103 }
104
105 if( empty( $_POST['screen'] ) or $_POST['screen'] != 'edit-post' ) {
106
107 return false;
108
109 }
110
111 if( empty( $_POST['post_type'] ) ) {
112
113 return false;
114
115 }
116
117 self::$post_type = strip_tags( $_POST['post_type'] );
118
119 add_filter( 'mywp_get_option_key_mywp_admin_posts' , array( __CLASS__ , 'mywp_get_option_key' ) );
120
121 }
122
123 public static function load_edit() {
124
125 global $typenow;
126
127 if( empty( $typenow ) ) {
128
129 return false;
130
131 }
132
133 self::$post_type = $typenow;
134
135 add_filter( 'mywp_get_option_key_mywp_admin_posts' , array( __CLASS__ , 'mywp_get_option_key' ) );
136
137 add_filter( 'bulk_post_updated_messages' , array( __CLASS__ , 'change_bulk_post_updated_messages' ) );
138
139 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_add_new' ) );
140
141 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_search_box' ) );
142
143 add_filter( "edit_{$typenow}_per_page" , array( __CLASS__ , 'edit_per_page' ) );
144
145 }
146
147 public static function change_bulk_post_updated_messages( $bulk_post_updated_messages ) {
148
149 if( ! self::is_do_function( __FUNCTION__ ) ) {
150
151 return $bulk_post_updated_messages;
152
153 }
154
155 $setting_data = self::get_setting_data();
156
157 if( empty( $setting_data['bulk_post_updated_messages'] ) ) {
158
159 return $bulk_post_updated_messages;
160
161 }
162
163 $bulk_post_updated_messages_default = self::get_bulk_update_messages_default();
164
165 foreach( $bulk_post_updated_messages_default as $key => $v ) {
166
167 if( ! empty( $setting_data['bulk_post_updated_messages'][ $key ] ) ) {
168
169 $bulk_post_updated_messages[ self::$post_type ][ $key ] = $setting_data['bulk_post_updated_messages'][ $key ];
170
171 }
172
173 }
174
175 self::after_do_function( __FUNCTION__ );
176
177 return $bulk_post_updated_messages;
178
179 }
180
181 public static function hide_add_new() {
182
183 if( ! self::is_do_function( __FUNCTION__ ) ) {
184
185 return false;
186
187 }
188
189 $setting_data = self::get_setting_data();
190
191 if( empty( $setting_data['hide_add_new'] ) ) {
192
193 return false;
194
195 }
196
197 echo '<style>';
198
199 echo 'body.wp-admin .wrap h1 a { display: none; }';
200 echo 'body.wp-admin .wrap .page-title-action { display: none; }';
201
202 echo '</style>';
203
204 self::after_do_function( __FUNCTION__ );
205
206 }
207
208 public static function hide_search_box() {
209
210 if( ! self::is_do_function( __FUNCTION__ ) ) {
211
212 return false;
213
214 }
215
216 $setting_data = self::get_setting_data();
217
218 if( empty( $setting_data['hide_search_box'] ) ) {
219
220 return false;
221
222 }
223
224 echo '<style>';
225
226 echo 'body.wp-admin #posts-filter .search-box { display: none; }';
227
228 echo '</style>';
229
230 self::after_do_function( __FUNCTION__ );
231
232 }
233
234 public static function edit_per_page( $per_page ) {
235
236 if( ! self::is_do_function( __FUNCTION__ ) ) {
237
238 return $per_page;
239
240 }
241
242 $setting_data = self::get_setting_data();
243
244 if( empty( $setting_data['per_page_num'] ) ) {
245
246 return $per_page;
247
248 }
249
250 $per_page = $setting_data['per_page_num'];
251
252 self::after_do_function( __FUNCTION__ );
253
254 return $per_page;
255
256 }
257
258 }
259
260 MywpControllerModuleAdminPosts::init();
261
262 endif;
263