PluginProbe
My WP Customize Admin/Frontend / 1.5
My WP Customize Admin/Frontend v1.5
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.post.edit.php

mywp.controller.module.admin.post.edit.php in My WP Customize Admin/Frontend 1.5, at controller/modules/mywp.controller.module.admin.post.edit.php

893 lines 18.1 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( 'MywpControllerModuleAdminPostEdit' ) ) :
12
13 final class MywpControllerModuleAdminPostEdit extends MywpControllerAbstractModule {
14
15 static protected $id = 'admin_post_edit';
16
17 static private $post_type = '';
18
19 public static function mywp_controller_initial_data( $initial_data ) {
20
21 $initial_data['meta_boxes'] = array();
22
23 $initial_data['post_updated_messages'] = array();
24
25 $initial_data['hide_add_new'] = '';
26 $initial_data['hide_title'] = '';
27 $initial_data['change_title_placeholder'] = '';
28 $initial_data['auto_create_title'] = '';
29 $initial_data['hide_permalink'] = '';
30 $initial_data['hide_change_permalink'] = '';
31 $initial_data['hide_content'] = '';
32 $initial_data['prevent_meta_box'] = '';
33 $initial_data['forced_editor'] = '';
34
35 $initial_data['hide_publish_metabox_draft'] = '';
36 $initial_data['hide_publish_metabox_preview'] = '';
37 $initial_data['hide_publish_metabox_change_post_status'] = '';
38 $initial_data['hide_publish_metabox_change_publish_status'] = '';
39 $initial_data['hide_publish_metabox_change_publish_on'] = '';
40
41 return $initial_data;
42
43 }
44
45 public static function mywp_controller_default_data( $default_data ) {
46
47 $default_data['meta_boxes'] = array();
48
49 $default_data['post_updated_messages'] = array();
50
51 $default_data['hide_add_new'] = false;
52 $default_data['hide_title'] = false;
53 $default_data['change_title_placeholder'] = '';
54 $default_data['auto_create_title'] = false;
55 $default_data['hide_permalink'] = false;
56 $default_data['hide_change_permalink'] = false;
57 $default_data['hide_content'] = false;
58 $default_data['prevent_meta_box'] = false;
59 $default_data['forced_editor'] = false;
60
61 $default_data['hide_publish_metabox_draft'] = false;
62 $default_data['hide_publish_metabox_preview'] = false;
63 $default_data['hide_publish_metabox_change_post_status'] = false;
64 $default_data['hide_publish_metabox_change_publish_status'] = false;
65 $default_data['hide_publish_metabox_change_publish_on'] = false;
66
67 return $default_data;
68
69 }
70
71 public static function get_update_messages_default() {
72
73 $update_messages_default = array(
74 1 => array(
75 'title' => __( 'Post updated' , 'mywp' ),
76 'message' => __( 'Post updated.' ),
77 ),
78 2 => array(
79 'title' => __( 'Custom field updated' , 'mywp' ),
80 'message' => __( 'Custom field updated.' ),
81 ),
82 3 => array(
83 'title' => __( 'Custom field deleted' , 'mywp' ),
84 'message' => __( 'Custom field updated.' ),
85 ),
86 4 => array(
87 'title' => __( 'Post updated' , 'mywp' ),
88 'message' => __( 'Post updated.' ),
89 ),
90 5 => array(
91 'title' => __( 'Revision' ),
92 'message' => sprintf( __( 'Post restored to revision from %s.' ), __( 'Post Title' ) ),
93 ),
94 6 => array(
95 'title' => __( 'Post published' , 'mywp' ),
96 'message' => __( 'Post published.' ),
97 ),
98 7 => array(
99 'title' => __( 'Post saved' , 'mywp' ),
100 'message' => __( 'Post saved.' ),
101 ),
102 8 => array(
103 'title' => __( 'Post submitted' , 'mywp' ),
104 'message' => __( 'Post submitted.' ),
105 ),
106 9 => array(
107 'title' => __( 'Post Scheduled' , 'mywp' ),
108 'message' => sprintf( __( 'Post scheduled for: %s.' ), '<strong>' . __( 'Schedule Date' , 'mywp' ) . '</strong>' ) . __( 'Schedule Link' , 'mywp' ),
109 ),
110 10 => array(
111 'title' => __( 'Post draft updated' , 'mywp' ),
112 'message' => __( 'Post draft updated.' ) . __( 'Preview Post Link' ),
113 ),
114 );
115
116 return $update_messages_default;
117
118 }
119
120 public static function mywp_wp_loaded() {
121
122 if( ! is_admin() ) {
123
124 return false;
125
126 }
127
128 if( is_network_admin() ) {
129
130 return false;
131
132 }
133
134 if( ! self::is_do_controller() ) {
135
136 return false;
137
138 }
139
140 add_action( 'load-post.php' , array( __CLASS__ , 'load_post' ) , 1000 );
141 add_action( 'load-post-new.php' , array( __CLASS__ , 'load_post' ) , 1000 );
142
143 }
144
145 public static function mywp_get_option_key( $option_key ) {
146
147 if( empty( self::$post_type ) ) {
148
149 return $option_key;
150
151 }
152
153 $option_key .= '_' . self::$post_type;
154
155 return $option_key;
156
157 }
158
159 public static function load_post() {
160
161 global $typenow;
162
163 if( empty( $typenow ) ) {
164
165 return false;
166
167 }
168
169 self::$post_type = $typenow;
170
171 add_filter( 'mywp_get_option_key_mywp_admin_post_edit' , array( __CLASS__ , 'mywp_get_option_key' ) );
172
173 add_filter( 'post_updated_messages' , array( __CLASS__ , 'change_post_updated_messages' ) );
174
175 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_add_new' ) );
176
177 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_title' ) );
178
179 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_permalink' ) );
180
181 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_change_permalink' ) );
182
183 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_content' ) );
184
185 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_publish_metabox_draft' ) );
186
187 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_publish_metabox_preview' ) );
188
189 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_publish_metabox_change_post_status' ) );
190
191 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_publish_metabox_change_publish_status' ) );
192
193 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_publish_metabox_change_publish_on' ) );
194
195 add_action( 'admin_print_styles' , array( __CLASS__ , 'forced_editor_buttons' ) );
196
197 add_action( 'admin_head' , array( __CLASS__ , 'hide_meta_boxes' ) );
198
199 add_action( 'in_admin_header' , array( __CLASS__ , 'remove_meta_boxes' ) );
200
201 add_action( 'in_admin_header' , array( __CLASS__ , 'change_title_meta_boxes' ) );
202
203 add_filter( 'wp_default_editor' , array( __CLASS__ , 'forced_editor' ) );
204
205 add_filter( 'enter_title_here' , array( __CLASS__ , 'change_title_placeholder' ) );
206
207 add_action( 'admin_print_footer_scripts' , array( __CLASS__ , 'prevent_meta_boxes' ) );
208
209 add_action( 'admin_print_footer_scripts' , array( __CLASS__ , 'auto_create_title' ) );
210
211 }
212
213 public static function change_post_updated_messages( $post_updated_messages ) {
214
215 if( ! self::is_do_function( __FUNCTION__ ) ) {
216
217 return $post_updated_messages;
218
219 }
220
221 $setting_data = self::get_setting_data();
222
223 if( empty( $setting_data['post_updated_messages'] ) ) {
224
225 return $post_updated_messages;
226
227 }
228
229 $post_updated_messages_default = self::get_update_messages_default();
230
231 foreach( $post_updated_messages_default as $key => $v ) {
232
233 if( ! empty( $setting_data['post_updated_messages'][ $key ] ) ) {
234
235 $post_updated_messages[ self::$post_type ][ $key ] = $setting_data['post_updated_messages'][ $key ];
236
237 }
238
239 }
240
241 self::after_do_function( __FUNCTION__ );
242
243 return $post_updated_messages;
244
245 }
246
247 public static function hide_add_new() {
248
249 if( ! self::is_do_function( __FUNCTION__ ) ) {
250
251 return false;
252
253 }
254
255 $setting_data = self::get_setting_data();
256
257 if( empty( $setting_data['hide_add_new'] ) ) {
258
259 return false;
260
261 }
262
263 echo '<style>';
264
265 echo '.wrap h1 > a { display: none; }';
266 echo '.wrap > a.page-title-action { display: none; }';
267
268 echo '</style>';
269
270 self::after_do_function( __FUNCTION__ );
271
272 }
273
274 public static function hide_title() {
275
276 if( ! self::is_do_function( __FUNCTION__ ) ) {
277
278 return false;
279
280 }
281
282 $setting_data = self::get_setting_data();
283
284 if( empty( $setting_data['hide_title'] ) ) {
285
286 return false;
287
288 }
289
290 echo '<style>';
291
292 echo '#post-body-content #titlewrap { display: none; }';
293
294 echo '</style>';
295
296 self::after_do_function( __FUNCTION__ );
297
298 }
299
300 public static function hide_permalink() {
301
302 if( ! self::is_do_function( __FUNCTION__ ) ) {
303
304 return false;
305
306 }
307
308 $setting_data = self::get_setting_data();
309
310 if( empty( $setting_data['hide_permalink'] ) ) {
311
312 return false;
313
314 }
315
316 echo '<style>';
317
318 echo '#post-body-content #titlediv .inside { display: none; }';
319
320 echo '</style>';
321
322 self::after_do_function( __FUNCTION__ );
323
324 }
325
326 public static function hide_change_permalink() {
327
328 if( ! self::is_do_function( __FUNCTION__ ) ) {
329
330 return false;
331
332 }
333
334 $setting_data = self::get_setting_data();
335
336 if( empty( $setting_data['hide_change_permalink'] ) ) {
337
338 return false;
339
340 }
341
342 echo '<style>';
343
344 echo '#post-body-content #change-permalinks { display: none; }';
345
346 echo '</style>';
347
348 self::after_do_function( __FUNCTION__ );
349
350 }
351
352 public static function hide_content() {
353
354 if( ! self::is_do_function( __FUNCTION__ ) ) {
355
356 return false;
357
358 }
359
360 $setting_data = self::get_setting_data();
361
362 if( empty( $setting_data['hide_content'] ) ) {
363
364 return false;
365
366 }
367
368 echo '<style>';
369
370 echo '#post-body-content #postdivrich { display: none; }';
371
372 echo '</style>';
373
374 self::after_do_function( __FUNCTION__ );
375
376 }
377
378 public static function hide_publish_metabox_draft() {
379
380 if( ! self::is_do_function( __FUNCTION__ ) ) {
381
382 return false;
383
384 }
385
386 $setting_data = self::get_setting_data();
387
388 if( empty( $setting_data['hide_publish_metabox_draft'] ) ) {
389
390 return false;
391
392 }
393
394 echo '<style>';
395
396 echo '#minor-publishing-actions #save-action { display: none; }';
397
398 echo '</style>';
399
400 self::after_do_function( __FUNCTION__ );
401
402 }
403
404 public static function hide_publish_metabox_preview() {
405
406 if( ! self::is_do_function( __FUNCTION__ ) ) {
407
408 return false;
409
410 }
411
412 $setting_data = self::get_setting_data();
413
414 if( empty( $setting_data['hide_publish_metabox_preview'] ) ) {
415
416 return false;
417
418 }
419
420 echo '<style>';
421
422 echo '#minor-publishing-actions #preview-action { display: none; }';
423
424 echo '</style>';
425
426 self::after_do_function( __FUNCTION__ );
427
428 }
429
430 public static function hide_publish_metabox_change_post_status() {
431
432 if( ! self::is_do_function( __FUNCTION__ ) ) {
433
434 return false;
435
436 }
437
438 $setting_data = self::get_setting_data();
439
440 if( empty( $setting_data['hide_publish_metabox_change_post_status'] ) ) {
441
442 return false;
443
444 }
445
446 echo '<style>';
447
448 echo '#misc-publishing-actions .misc-pub-section.misc-pub-post-status { display: none; }';
449
450 echo '</style>';
451
452 self::after_do_function( __FUNCTION__ );
453
454 }
455
456 public static function hide_publish_metabox_change_publish_status() {
457
458 if( ! self::is_do_function( __FUNCTION__ ) ) {
459
460 return false;
461
462 }
463
464 $setting_data = self::get_setting_data();
465
466 if( empty( $setting_data['hide_publish_metabox_change_publish_status'] ) ) {
467
468 return false;
469
470 }
471
472 echo '<style>';
473
474 echo '#misc-publishing-actions .misc-pub-section.misc-pub-visibility { display: none; }';
475
476 echo '</style>';
477
478 self::after_do_function( __FUNCTION__ );
479
480 }
481
482 public static function hide_publish_metabox_change_publish_on() {
483
484 if( ! self::is_do_function( __FUNCTION__ ) ) {
485
486 return false;
487
488 }
489
490 $setting_data = self::get_setting_data();
491
492 if( empty( $setting_data['hide_publish_metabox_change_publish_on'] ) ) {
493
494 return false;
495
496 }
497
498 echo '<style>';
499
500 echo '#misc-publishing-actions .misc-pub-section.misc-pub-curtime { display: none; }';
501
502 echo '</style>';
503
504 self::after_do_function( __FUNCTION__ );
505
506 }
507
508 public static function forced_editor_buttons() {
509
510 if( ! self::is_do_function( __FUNCTION__ ) ) {
511
512 return false;
513
514 }
515
516 $setting_data = self::get_setting_data();
517
518 if( empty( $setting_data['forced_editor'] ) ) {
519
520 return false;
521
522 }
523
524 echo '<style>';
525
526 echo '#wp-content-editor-tools .wp-editor-tabs { display: none; }';
527
528 echo '</style>';
529
530 self::after_do_function( __FUNCTION__ );
531
532 }
533
534 public static function hide_meta_boxes() {
535
536 if( ! self::is_do_function( __FUNCTION__ ) ) {
537
538 return false;
539
540 }
541
542 $setting_data = self::get_setting_data();
543
544 if( empty( $setting_data['meta_boxes'] ) ) {
545
546 return false;
547
548 }
549
550 $hide_meta_boxes = array();
551
552 foreach( $setting_data['meta_boxes'] as $meta_box_id => $meta_box_setting ) {
553
554 if( $meta_box_setting['action'] != 'hide' ) {
555
556 continue;
557
558 }
559
560 $hide_meta_boxes[] = $meta_box_id;
561
562 }
563
564 if( empty( $hide_meta_boxes ) ) {
565
566 return false;
567
568 }
569
570 echo '<style>';
571
572 foreach( $hide_meta_boxes as $meta_box_id ) {
573
574 printf( '.postbox#%s { height: 0; overflow: hidden; margin: 0; box-shadow: none; border: 0 none; }' , $meta_box_id );
575
576 }
577
578 echo '</style>';
579
580 echo '<script>jQuery(document).ready(function($){';
581
582 foreach( $hide_meta_boxes as $meta_box_id ) {
583
584 printf( '$("#screen-options-wrap .metabox-prefs label[for=%s-hide]").css("display", "none");' , $meta_box_id );
585
586 }
587
588 echo '});</script>';
589
590 self::after_do_function( __FUNCTION__ );
591
592 }
593
594 public static function remove_meta_boxes() {
595
596 global $wp_meta_boxes;
597
598 if( ! self::is_do_function( __FUNCTION__ ) ) {
599
600 return false;
601
602 }
603
604 $setting_data = self::get_setting_data();
605
606 if( empty( $setting_data['meta_boxes'] ) ) {
607
608 return false;
609
610 }
611
612 $remove_meta_boxes = array();
613
614 foreach( $setting_data['meta_boxes'] as $meta_box_id => $meta_box_setting ) {
615
616 if( $meta_box_setting['action'] != 'remove' ) {
617
618 continue;
619
620 }
621
622 $remove_meta_boxes[] = $meta_box_id;
623
624 }
625
626 if( empty( $remove_meta_boxes ) ) {
627
628 return false;
629
630 }
631
632 if( empty( $wp_meta_boxes[ self::$post_type ] ) ) {
633
634 return false;
635
636 }
637
638 $current_meta_boxes = $wp_meta_boxes[ self::$post_type ];
639
640 foreach( $current_meta_boxes as $context => $priority_meta_boxes ) {
641
642 if( empty( $priority_meta_boxes ) or ! is_array( $priority_meta_boxes ) ) {
643
644 continue;
645
646 }
647
648 foreach( $priority_meta_boxes as $priority => $meta_boxes ) {
649
650 if( empty( $meta_boxes ) or ! is_array( $meta_boxes ) ) {
651
652 continue;
653
654 }
655
656 foreach( $meta_boxes as $meta_box_id => $meta_box ) {
657
658 if( empty( $meta_box ) or ! is_array( $meta_box ) ) {
659
660 continue;
661
662 }
663
664 if( ! in_array( $meta_box_id , $remove_meta_boxes ) ) {
665
666 continue;
667
668 }
669
670 remove_meta_box( $meta_box_id , self::$post_type , $context );
671
672 }
673
674 }
675
676 }
677
678 self::after_do_function( __FUNCTION__ );
679
680 }
681
682 public static function change_title_meta_boxes() {
683
684 global $wp_meta_boxes;
685
686 if( ! self::is_do_function( __FUNCTION__ ) ) {
687
688 return false;
689
690 }
691
692 $setting_data = self::get_setting_data();
693
694 if( empty( $setting_data['meta_boxes'] ) ) {
695
696 return false;
697
698 }
699
700 $change_title_meta_boxes = array();
701
702 foreach( $setting_data['meta_boxes'] as $meta_box_id => $meta_box_setting ) {
703
704 if( ! empty( $meta_box_setting['action'] ) ) {
705
706 continue;
707
708 }
709
710 if( empty( $meta_box_setting['title'] ) ) {
711
712 continue;
713
714 }
715
716 $change_title_meta_boxes[ $meta_box_id ] = $meta_box_setting['title'];
717
718 }
719
720 if( empty( $change_title_meta_boxes ) ) {
721
722 return false;
723
724 }
725
726 if( empty( $wp_meta_boxes[ self::$post_type ] ) ) {
727
728 return false;
729
730 }
731
732 $current_meta_boxes = $wp_meta_boxes[ self::$post_type ];
733
734 foreach( $current_meta_boxes as $context => $priority_meta_boxes ) {
735
736 if( empty( $priority_meta_boxes ) or ! is_array( $priority_meta_boxes ) ) {
737
738 continue;
739
740 }
741
742 foreach( $priority_meta_boxes as $priority => $meta_boxes ) {
743
744 if( empty( $meta_boxes ) or ! is_array( $meta_boxes ) ) {
745
746 continue;
747
748 }
749
750 foreach( $meta_boxes as $meta_box_id => $meta_box ) {
751
752 if( empty( $meta_box ) or ! is_array( $meta_box ) ) {
753
754 continue;
755
756 }
757
758 if( empty( $change_title_meta_boxes[ $meta_box_id ] ) ) {
759
760 continue;
761
762 }
763
764 $wp_meta_boxes[ self::$post_type ][ $context ][ $priority ][ $meta_box_id ]['title'] = do_shortcode( $change_title_meta_boxes[ $meta_box_id ] );
765
766 }
767
768 }
769
770 }
771
772 self::after_do_function( __FUNCTION__ );
773
774 }
775
776 public static function forced_editor( $wp_default_editor ) {
777
778 if( ! self::is_do_function( __FUNCTION__ ) ) {
779
780 return $wp_default_editor;
781
782 }
783
784 $setting_data = self::get_setting_data();
785
786 if( ! empty( $setting_data['forced_editor'] ) or in_array( $setting_data['forced_editor'] , array( 'text' , 'tinymce' ) ) ) {
787
788 $wp_default_editor = $setting_data['forced_editor'];
789
790 }
791
792 self::after_do_function( __FUNCTION__ );
793
794 return $wp_default_editor;
795
796 }
797
798 public static function change_title_placeholder( $title_placeholder ) {
799
800 if( ! self::is_do_function( __FUNCTION__ ) ) {
801
802 return $title_placeholder;
803
804 }
805
806 $setting_data = self::get_setting_data();
807
808 if( empty( $setting_data['change_title_placeholder'] ) ) {
809
810 return $title_placeholder;
811
812 }
813
814 $title_placeholder = $setting_data['change_title_placeholder'];
815
816 self::after_do_function( __FUNCTION__ );
817
818 return $title_placeholder;
819
820 }
821
822 public static function prevent_meta_boxes() {
823
824 if( ! self::is_do_function( __FUNCTION__ ) ) {
825
826 return false;
827
828 }
829
830 $setting_data = self::get_setting_data();
831
832 if( empty( $setting_data['prevent_meta_box'] ) ) {
833
834 return false;
835
836 }
837
838 echo '<script>jQuery(document).ready(function($){';
839
840 echo '$(".meta-box-sortables").sortable("disable");';
841
842 echo '});</script>';
843
844 echo '<style>';
845
846 echo '.js .postbox .hndle { cursor: pointer; }';
847
848 echo '</style>';
849
850 self::after_do_function( __FUNCTION__ );
851
852 }
853
854 public static function auto_create_title() {
855
856 global $post;
857
858 if( empty( $post ) or empty( $post->ID ) ) {
859
860 return false;
861
862 }
863
864 if( ! self::is_do_function( __FUNCTION__ ) ) {
865
866 return false;
867
868 }
869
870 $setting_data = self::get_setting_data();
871
872 if( empty( $setting_data['auto_create_title'] ) ) {
873
874 return false;
875
876 }
877
878 echo '<script>jQuery(document).ready(function($){';
879
880 echo '$("#titlediv #titlewrap #title").val( ' . $post->ID . ');';
881
882 echo '});</script>';
883
884 self::after_do_function( __FUNCTION__ );
885
886 }
887
888 }
889
890 MywpControllerModuleAdminPostEdit::init();
891
892 endif;
893