PluginProbe
My WP Customize Admin/Frontend / trunk
My WP Customize Admin/Frontend vtrunk
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 / core / class.api.php

class.api.php in My WP Customize Admin/Frontend trunk, at core/class.api.php

1,896 lines 44.4 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( 'MywpApi' ) ) :
8
9 final class MywpApi {
10
11 public static function get_manager_capability() {
12
13 $capability = 'manage_options';
14
15 return apply_filters( 'mywp_manager_capability' , $capability );
16
17 }
18
19 public static function is_manager() {
20
21 $capability = self::get_manager_capability();
22
23 if( current_user_can( $capability ) ) {
24
25 return true;
26
27 }
28
29 return false;
30
31 }
32
33 public static function get_network_manager_capability() {
34
35 $capability = 'manage_network';
36
37 return apply_filters( 'mywp_network_manager_capability' , $capability );
38
39 }
40
41 public static function is_network_manager() {
42
43 $capability = self::get_network_manager_capability();
44
45 if( current_user_can( $capability ) ) {
46
47 return true;
48
49 }
50
51 return false;
52
53 }
54
55 public static function plugin_info() {
56
57 $plugin_info = array(
58 'forum_url' => 'https://wordpress.org/support/plugin/my-wp/',
59 'review_url' => 'https://wordpress.org/support/plugin/my-wp/reviews/',
60 'admin_url' => admin_url( 'admin.php?page=mywp' ),
61 'website_url' => 'https://mywpcustomize.com/',
62 'document_url' => 'https://mywpcustomize.com/documents/',
63 'document_category_url' => 'https://mywpcustomize.com/document_category/',
64 );
65
66 $plugin_info = apply_filters( 'mywp_plugin_info' , $plugin_info );
67
68 return $plugin_info;
69
70 }
71
72 public static function get_plugin_url( $path = 'assets' ) {
73
74 $path = strip_tags( $path );
75
76 if( $path === 'assets' ) {
77
78 return MYWP_PLUGIN_URL . 'assets/';
79
80 } elseif( $path === 'css' ) {
81
82 return MYWP_PLUGIN_URL . 'assets/css/';
83
84 } elseif( $path === 'js' ) {
85
86 return MYWP_PLUGIN_URL . 'assets/js/';
87
88 } elseif( $path === 'img' ) {
89
90 return MYWP_PLUGIN_URL . 'assets/img/';
91
92 } elseif( $path === 'font' ) {
93
94 return MYWP_PLUGIN_URL . 'assets/font/';
95
96 } else {
97
98 $called_text = sprintf( '%s::%s()' , __CLASS__ , __FUNCTION__ );
99
100 MywpHelper::error_not_found_message( $path , $called_text );
101
102 }
103
104 }
105
106 public static function include_files( $files = array() ) {
107
108 if( empty( $files ) ) {
109
110 return false;
111
112 }
113
114 foreach( $files as $file ) {
115
116 self::include_file( $file );
117
118 }
119
120 }
121
122 public static function include_file( $file = false ) {
123
124 if( $file === false ) {
125
126 return false;
127
128 }
129
130 if ( file_exists( $file ) ) {
131
132 $mywp_cache = new MywpCache( 'include_file' );
133
134 $mywp_cache->add_cache( $file );
135
136 include_once( $file );
137
138 } else {
139
140 $error_msg = sprintf( __( "There doesn't seem to be a %s file." , 'my-wp' ) , $file );
141
142 return self::add_error( $error_msg );
143
144 }
145
146 }
147
148 public static function require_files( $files = array() ) {
149
150 if( empty( $files ) ) {
151
152 return false;
153
154 }
155
156 foreach( $files as $file ) {
157
158 self::require_file( $file );
159
160 }
161
162 }
163
164 public static function require_file( $file = false ) {
165
166 if( $file === false ) {
167
168 return false;
169
170 }
171
172 if ( file_exists( $file ) ) {
173
174 $mywp_cache = new MywpCache( 'require_file' );
175
176 $mywp_cache->add_cache( $file );
177
178 require_once( $file );
179
180 } else {
181
182 $error_msg = sprintf( __( "There doesn't seem to be a %s file." , 'my-wp' ) , $file );
183
184 return self::add_error( $error_msg );
185
186 }
187
188 }
189
190 public static function add_error( $message = false ) {
191
192 $mywp_cache = new MywpCache( 'error' );
193
194 return $mywp_cache->add_cache( $message );
195
196 }
197
198 public static function get_error() {
199
200 $errors = self::get_errors();
201
202 if( empty( $errors ) ) {
203
204 return false;
205
206 }
207
208 return array_shift( $errors );
209
210 }
211
212 public static function get_errors() {
213
214 $mywp_cache = new MywpCache( 'error' );
215
216 return $mywp_cache->get_cache();
217
218 }
219
220 public static function get_all_user_roles() {
221
222 if( ! function_exists( 'get_editable_roles' ) ) {
223
224 require_once ABSPATH . 'wp-admin/includes/user.php';
225
226 }
227
228 if( ! function_exists( 'get_editable_roles' ) ) {
229
230 $called_text = sprintf( 'get_editable_roles()' , __FUNCTION__ );
231
232 MywpHelper::error_not_found_message( '$editable_roles' , $called_text );
233
234 return false;
235
236 }
237
238 $editable_roles = get_editable_roles();
239
240 if( empty( $editable_roles ) ) {
241
242 $called_text = sprintf( '%s::%s()' , __CLASS__ , __FUNCTION__ );
243
244 MywpHelper::error_not_found_message( '$editable_roles' , $called_text );
245
246 return false;
247
248 }
249
250 $all_user_roles = array();
251
252 foreach( $editable_roles as $role_group_name => $role_details ) {
253
254 $role_group = $role_details;
255 $role_group['label'] = translate_user_role( $role_details['name'] );
256
257 $all_user_roles[ $role_group_name ] = $role_group;
258
259 }
260
261 return apply_filters( 'mywp_all_user_roles' , $all_user_roles );
262 }
263
264 public static function get_all_post_types() {
265
266 global $wp_post_types;
267
268 return $wp_post_types;
269
270 }
271
272 public static function get_all_post_statuses() {
273
274 global $wp_post_statuses;
275
276 return $wp_post_statuses;
277
278 }
279
280 public static function get_all_taxonomies() {
281
282 global $wp_taxonomies;
283
284 return $wp_taxonomies;
285
286 }
287
288 public static function get_dashicons() {
289
290 $categories = array(
291 'admin_menu' => array( 'id' => 'admin_menu' , 'title' =>__( 'Admin Menu' ) ),
292 'welcome_screen' => array( 'id' => 'welcome_screen' , 'title' =>__( 'Welcome Screen' ) ),
293 'post_formats' => array( 'id' => 'post_formats' , 'title' =>__( 'Post Formats' ) ),
294 'media' => array( 'id' => 'media' , 'title' =>__( 'Media' ) ),
295 'image_editing' => array( 'id' => 'image_editing' , 'title' =>__( 'Image Editing' ) ),
296 'tinymce' => array( 'id' => 'tinymce' , 'title' =>__( 'TinyMCE' ) ),
297 'posts_screen' => array( 'id' => 'posts_screen' , 'title' =>__( 'Posts Screen' ) ),
298 'sorting' => array( 'id' => 'sorting' , 'title' =>__( 'Sorting' ) ),
299 'social' => array( 'id' => 'social' , 'title' =>__( 'Social' ) ),
300 'wp' => array( 'id' => 'wp' , 'title' =>__( 'WordPress.org Specific: Jobs, Profiles, WordCamps' ) ),
301 'products' => array( 'id' => 'products' , 'title' =>__( 'Products' ) ),
302 'taxonomies' => array( 'id' => 'taxonomies' , 'title' =>__( 'Taxonomies' ) ),
303 'widgets' => array( 'id' => 'widgets' , 'title' =>__( 'Widgets' ) ),
304 'notifications' => array( 'id' => 'notifications' , 'title' =>__( 'Notifications' ) ),
305 'misc' => array( 'id' => 'misc' , 'title' =>__( 'Misc' ) ),
306 );
307
308 $icons = array(
309
310 array(
311 'css_content' => '\f333',
312 'class' => 'dashicons-menu',
313 'cat' => 'admin_menu',
314 ),
315 array(
316 'css_content' => '\f319',
317 'class' => 'dashicons-admin-site',
318 'cat' => 'admin_menu',
319 ),
320 array(
321 'css_content' => '\f226',
322 'class' => 'dashicons-dashboard',
323 'cat' => 'admin_menu',
324 ),
325 array(
326 'css_content' => '\f109',
327 'class' => 'dashicons-admin-post',
328 'cat' => 'admin_menu',
329 ),
330 array(
331 'css_content' => '\f104',
332 'class' => 'dashicons-admin-media',
333 'cat' => 'admin_menu',
334 ),
335 array(
336 'css_content' => '\f103',
337 'class' => 'dashicons-admin-links',
338 'cat' => 'admin_menu',
339 ),
340 array(
341 'css_content' => '\f105',
342 'class' => 'dashicons-admin-page',
343 'cat' => 'admin_menu',
344 ),
345 array(
346 'css_content' => '\f101',
347 'class' => 'dashicons-admin-comments',
348 'cat' => 'admin_menu',
349 ),
350 array(
351 'css_content' => '\f100',
352 'class' => 'dashicons-admin-appearance',
353 'cat' => 'admin_menu',
354 ),
355 array(
356 'css_content' => '\f106',
357 'class' => 'dashicons-admin-plugins',
358 'cat' => 'admin_menu',
359 ),
360 array(
361 'css_content' => '\f110',
362 'class' => 'dashicons-admin-users',
363 'cat' => 'admin_menu',
364 ),
365 array(
366 'css_content' => '\f107',
367 'class' => 'dashicons-admin-tools',
368 'cat' => 'admin_menu',
369 ),
370 array(
371 'css_content' => '\f108',
372 'class' => 'dashicons-admin-settings',
373 'cat' => 'admin_menu',
374 ),
375 array(
376 'css_content' => '\f112',
377 'class' => 'dashicons-admin-network',
378 'cat' => 'admin_menu',
379 ),
380 array(
381 'css_content' => '\f102',
382 'class' => 'dashicons-admin-home',
383 'cat' => 'admin_menu',
384 ),
385 array(
386 'css_content' => '\f111',
387 'class' => 'dashicons-admin-generic',
388 'cat' => 'admin_menu',
389 ),
390 array(
391 'css_content' => '\f148',
392 'class' => 'dashicons-admin-collapse',
393 'cat' => 'admin_menu',
394 ),
395 array(
396 'css_content' => '\f536',
397 'class' => 'dashicons-filter',
398 'cat' => 'admin_menu',
399 ),
400 array(
401 'css_content' => '\f540',
402 'class' => 'dashicons-admin-customizer',
403 'cat' => 'admin_menu',
404 ),
405 array(
406 'css_content' => '\f541',
407 'class' => 'dashicons-admin-multisite',
408 'cat' => 'admin_menu',
409 ),
410
411 array(
412 'css_content' => '\f119',
413 'class' => 'dashicons-welcome-write-blog',
414 'cat' => 'welcome_screen',
415 ),
416 array(
417 'css_content' => '\f133',
418 'class' => 'dashicons-welcome-add-page',
419 'cat' => 'welcome_screen',
420 ),
421 array(
422 'css_content' => '\f115',
423 'class' => 'dashicons-welcome-view-site',
424 'cat' => 'welcome_screen',
425 ),
426 array(
427 'css_content' => '\f116',
428 'class' => 'dashicons-welcome-widgets-menus',
429 'cat' => 'welcome_screen',
430 ),
431 array(
432 'css_content' => '\f117',
433 'class' => 'dashicons-welcome-comments',
434 'cat' => 'welcome_screen',
435 ),
436 array(
437 'css_content' => '\f118',
438 'class' => 'dashicons-welcome-learn-more',
439 'cat' => 'welcome_screen',
440 ),
441
442 array(
443 'css_content' => '\f123',
444 'class' => 'dashicons-format-aside',
445 'cat' => 'post_formats',
446 ),
447 array(
448 'css_content' => '\f128',
449 'class' => 'dashicons-format-image',
450 'cat' => 'post_formats',
451 ),
452 array(
453 'css_content' => '\f161',
454 'class' => 'dashicons-format-gallery',
455 'cat' => 'post_formats',
456 ),
457 array(
458 'css_content' => '\f126',
459 'class' => 'dashicons-format-video',
460 'cat' => 'post_formats',
461 ),
462 array(
463 'css_content' => '\f130',
464 'class' => 'dashicons-format-status',
465 'cat' => 'post_formats',
466 ),
467 array(
468 'css_content' => '\f122',
469 'class' => 'dashicons-format-quote',
470 'cat' => 'post_formats',
471 ),
472 array(
473 'css_content' => '\f125',
474 'class' => 'dashicons-format-chat',
475 'cat' => 'post_formats',
476 ),
477 array(
478 'css_content' => '\f127',
479 'class' => 'dashicons-format-audio',
480 'cat' => 'post_formats',
481 ),
482 array(
483 'css_content' => '\f306',
484 'class' => 'dashicons-camera',
485 'cat' => 'post_formats',
486 ),
487 array(
488 'css_content' => '\f232',
489 'class' => 'dashicons-images-alt',
490 'cat' => 'post_formats',
491 ),
492 array(
493 'css_content' => '\f233',
494 'class' => 'dashicons-images-alt2',
495 'cat' => 'post_formats',
496 ),
497 array(
498 'css_content' => '\f234',
499 'class' => 'dashicons-video-alt',
500 'cat' => 'post_formats',
501 ),
502 array(
503 'css_content' => '\f235',
504 'class' => 'dashicons-video-alt2',
505 'cat' => 'post_formats',
506 ),
507 array(
508 'css_content' => '\f236',
509 'class' => 'dashicons-video-alt3',
510 'cat' => 'post_formats',
511 ),
512
513 array(
514 'css_content' => '\f501',
515 'class' => 'dashicons-media-archive',
516 'cat' => 'media',
517 ),
518 array(
519 'css_content' => '\f500',
520 'class' => 'dashicons-media-audio',
521 'cat' => 'media',
522 ),
523 array(
524 'css_content' => '\f499',
525 'class' => 'dashicons-media-code',
526 'cat' => 'media',
527 ),
528 array(
529 'css_content' => '\f498',
530 'class' => 'dashicons-media-default',
531 'cat' => 'media',
532 ),
533 array(
534 'css_content' => '\f497',
535 'class' => 'dashicons-media-document',
536 'cat' => 'media',
537 ),
538 array(
539 'css_content' => '\f496',
540 'class' => 'dashicons-media-interactive',
541 'cat' => 'media',
542 ),
543 array(
544 'css_content' => '\f495',
545 'class' => 'dashicons-media-spreadsheet',
546 'cat' => 'media',
547 ),
548 array(
549 'css_content' => '\f491',
550 'class' => 'dashicons-media-text',
551 'cat' => 'media',
552 ),
553 array(
554 'css_content' => '\f490',
555 'class' => 'dashicons-media-video',
556 'cat' => 'media',
557 ),
558 array(
559 'css_content' => '\f492',
560 'class' => 'dashicons-playlist-audio',
561 'cat' => 'media',
562 ),
563 array(
564 'css_content' => '\f493',
565 'class' => 'dashicons-playlist-video',
566 'cat' => 'media',
567 ),
568 array(
569 'css_content' => '\f522',
570 'class' => 'dashicons-controls-play',
571 'cat' => 'media',
572 ),
573 array(
574 'css_content' => '\f523',
575 'class' => 'dashicons-controls-pause',
576 'cat' => 'media',
577 ),
578 array(
579 'css_content' => '\f519',
580 'class' => 'dashicons-controls-forward',
581 'cat' => 'media',
582 ),
583 array(
584 'css_content' => '\f517',
585 'class' => 'dashicons-controls-skipforward',
586 'cat' => 'media',
587 ),
588 array(
589 'css_content' => '\f518',
590 'class' => 'dashicons-controls-back',
591 'cat' => 'media',
592 ),
593 array(
594 'css_content' => '\f516',
595 'class' => 'dashicons-controls-skipback',
596 'cat' => 'media',
597 ),
598 array(
599 'css_content' => '\f515',
600 'class' => 'dashicons-controls-repeat',
601 'cat' => 'media',
602 ),
603 array(
604 'css_content' => '\f521',
605 'class' => 'dashicons-controls-volumeon',
606 'cat' => 'media',
607 ),
608 array(
609 'css_content' => '\f520',
610 'class' => 'dashicons-controls-volumeoff',
611 'cat' => 'media',
612 ),
613
614 array(
615 'css_content' => '\f165',
616 'class' => 'dashicons-image-crop',
617 'cat' => 'image_editing',
618 ),
619 array(
620 'css_content' => '\f531',
621 'class' => 'dashicons-image-rotate',
622 'cat' => 'image_editing',
623 ),
624 array(
625 'css_content' => '\f166',
626 'class' => 'dashicons-image-rotate-left',
627 'cat' => 'image_editing',
628 ),
629 array(
630 'css_content' => '\f167',
631 'class' => 'dashicons-image-rotate-right',
632 'cat' => 'image_editing',
633 ),
634 array(
635 'css_content' => '\f168',
636 'class' => 'dashicons-image-flip-vertical',
637 'cat' => 'image_editing',
638 ),
639 array(
640 'css_content' => '\f169',
641 'class' => 'dashicons-image-flip-horizontal',
642 'cat' => 'image_editing',
643 ),
644 array(
645 'css_content' => '\f533',
646 'class' => 'dashicons-image-filter',
647 'cat' => 'image_editing',
648 ),
649 array(
650 'css_content' => '\f171',
651 'class' => 'dashicons-undo',
652 'cat' => 'image_editing',
653 ),
654 array(
655 'css_content' => '\f172',
656 'class' => 'dashicons-redo',
657 'cat' => 'image_editing',
658 ),
659
660 array(
661 'css_content' => '\f200',
662 'class' => 'dashicons-editor-bold',
663 'cat' => 'tinymce',
664 ),
665 array(
666 'css_content' => '\f201',
667 'class' => 'dashicons-editor-italic',
668 'cat' => 'tinymce',
669 ),
670 array(
671 'css_content' => '\f203',
672 'class' => 'dashicons-editor-ul',
673 'cat' => 'tinymce',
674 ),
675 array(
676 'css_content' => '\f204',
677 'class' => 'dashicons-editor-ol',
678 'cat' => 'tinymce',
679 ),
680 array(
681 'css_content' => '\f205',
682 'class' => 'dashicons-editor-quote',
683 'cat' => 'tinymce',
684 ),
685 array(
686 'css_content' => '\f206',
687 'class' => 'dashicons-editor-alignleft',
688 'cat' => 'tinymce',
689 ),
690 array(
691 'css_content' => '\f207',
692 'class' => 'dashicons-editor-aligncenter',
693 'cat' => 'tinymce',
694 ),
695 array(
696 'css_content' => '\f208',
697 'class' => 'dashicons-editor-alignright',
698 'cat' => 'tinymce',
699 ),
700 array(
701 'css_content' => '\f209',
702 'class' => 'dashicons-editor-insertmore',
703 'cat' => 'tinymce',
704 ),
705 array(
706 'css_content' => '\f210',
707 'class' => 'dashicons-editor-spellcheck',
708 'cat' => 'tinymce',
709 ),
710 array(
711 'css_content' => '\f211',
712 'class' => 'dashicons-editor-expand',
713 'cat' => 'tinymce',
714 ),
715 array(
716 'css_content' => '\f506',
717 'class' => 'dashicons-editor-contract',
718 'cat' => 'tinymce',
719 ),
720 array(
721 'css_content' => '\f212',
722 'class' => 'dashicons-editor-kitchensink',
723 'cat' => 'tinymce',
724 ),
725 array(
726 'css_content' => '\f213',
727 'class' => 'dashicons-editor-underline',
728 'cat' => 'tinymce',
729 ),
730 array(
731 'css_content' => '\f214',
732 'class' => 'dashicons-editor-justify',
733 'cat' => 'tinymce',
734 ),
735 array(
736 'css_content' => '\f215',
737 'class' => 'dashicons-editor-textcolor',
738 'cat' => 'tinymce',
739 ),
740 array(
741 'css_content' => '\f216',
742 'class' => 'dashicons-editor-paste-word',
743 'cat' => 'tinymce',
744 ),
745 array(
746 'css_content' => '\f217',
747 'class' => 'dashicons-editor-paste-text',
748 'cat' => 'tinymce',
749 ),
750 array(
751 'css_content' => '\f218',
752 'class' => 'dashicons-editor-removeformatting',
753 'cat' => 'tinymce',
754 ),
755 array(
756 'css_content' => '\f219',
757 'class' => 'dashicons-editor-video',
758 'cat' => 'tinymce',
759 ),
760 array(
761 'css_content' => '\f220',
762 'class' => 'dashicons-editor-customchar',
763 'cat' => 'tinymce',
764 ),
765 array(
766 'css_content' => '\f221',
767 'class' => 'dashicons-editor-outdent',
768 'cat' => 'tinymce',
769 ),
770 array(
771 'css_content' => '\f222',
772 'class' => 'dashicons-editor-indent',
773 'cat' => 'tinymce',
774 ),
775 array(
776 'css_content' => '\f223',
777 'class' => 'dashicons-editor-help',
778 'cat' => 'tinymce',
779 ),
780 array(
781 'css_content' => '\f224',
782 'class' => 'dashicons-editor-strikethrough',
783 'cat' => 'tinymce',
784 ),
785 array(
786 'css_content' => '\f225',
787 'class' => 'dashicons-editor-unlink',
788 'cat' => 'tinymce',
789 ),
790 array(
791 'css_content' => '\f320',
792 'class' => 'dashicons-editor-rtl',
793 'cat' => 'tinymce',
794 ),
795 array(
796 'css_content' => '\f474',
797 'class' => 'dashicons-editor-break',
798 'cat' => 'tinymce',
799 ),
800 array(
801 'css_content' => '\f475',
802 'class' => 'dashicons-editor-code',
803 'cat' => 'tinymce',
804 ),
805 array(
806 'css_content' => '\f476',
807 'class' => 'dashicons-editor-paragraph',
808 'cat' => 'tinymce',
809 ),
810 array(
811 'css_content' => '\f535',
812 'class' => 'dashicons-editor-table',
813 'cat' => 'tinymce',
814 ),
815
816 array(
817 'css_content' => '\f135',
818 'class' => 'dashicons-align-left',
819 'cat' => 'posts_screen',
820 ),
821 array(
822 'css_content' => '\f136',
823 'class' => 'dashicons-align-right',
824 'cat' => 'posts_screen',
825 ),
826 array(
827 'css_content' => '\f134',
828 'class' => 'dashicons-align-center',
829 'cat' => 'posts_screen',
830 ),
831 array(
832 'css_content' => '\f138',
833 'class' => 'dashicons-align-none',
834 'cat' => 'posts_screen',
835 ),
836 array(
837 'css_content' => '\f160',
838 'class' => 'dashicons-lock',
839 'cat' => 'posts_screen',
840 ),
841 array(
842 'css_content' => '\f528',
843 'class' => 'dashicons-unlock',
844 'cat' => 'posts_screen',
845 ),
846 array(
847 'css_content' => '\f145',
848 'class' => 'dashicons-calendar',
849 'cat' => 'posts_screen',
850 ),
851 array(
852 'css_content' => '\f508',
853 'class' => 'dashicons-calendar-alt',
854 'cat' => 'posts_screen',
855 ),
856 array(
857 'css_content' => '\f177',
858 'class' => 'dashicons-visibility',
859 'cat' => 'posts_screen',
860 ),
861 array(
862 'css_content' => '\f530',
863 'class' => 'dashicons-hidden',
864 'cat' => 'posts_screen',
865 ),
866 array(
867 'css_content' => '\f173',
868 'class' => 'dashicons-post-status',
869 'cat' => 'posts_screen',
870 ),
871 array(
872 'css_content' => '\f464',
873 'class' => 'dashicons-edit',
874 'cat' => 'posts_screen',
875 ),
876 array(
877 'css_content' => '\f182',
878 'class' => 'dashicons-trash',
879 'cat' => 'posts_screen',
880 ),
881 array(
882 'css_content' => '\f537',
883 'class' => 'dashicons-sticky',
884 'cat' => 'posts_screen',
885 ),
886
887 array(
888 'css_content' => '\f504',
889 'class' => 'dashicons-external',
890 'cat' => 'sorting',
891 ),
892 array(
893 'css_content' => '\f142',
894 'class' => 'dashicons-arrow-up',
895 'cat' => 'sorting',
896 ),
897 array(
898 'css_content' => '\f140',
899 'class' => 'dashicons-arrow-down',
900 'cat' => 'sorting',
901 ),
902 array(
903 'css_content' => '\f139',
904 'class' => 'dashicons-arrow-right',
905 'cat' => 'sorting',
906 ),
907 array(
908 'css_content' => '\f141',
909 'class' => 'dashicons-arrow-left',
910 'cat' => 'sorting',
911 ),
912 array(
913 'css_content' => '\f342"',
914 'class' => 'dashicons-arrow-up-alt',
915 'cat' => 'sorting',
916 ),
917 array(
918 'css_content' => '\f346',
919 'class' => 'dashicons-arrow-down-alt',
920 'cat' => 'sorting',
921 ),
922 array(
923 'css_content' => '\f344',
924 'class' => 'dashicons-arrow-right-alt',
925 'cat' => 'sorting',
926 ),
927 array(
928 'css_content' => '\f340',
929 'class' => 'dashicons-arrow-left-alt',
930 'cat' => 'sorting',
931 ),
932 array(
933 'css_content' => '\f343',
934 'class' => 'dashicons-arrow-up-alt2',
935 'cat' => 'sorting',
936 ),
937 array(
938 'css_content' => '\f347',
939 'class' => 'dashicons-arrow-down-alt2',
940 'cat' => 'sorting',
941 ),
942 array(
943 'css_content' => '\f345',
944 'class' => 'dashicons-arrow-right-alt2',
945 'cat' => 'sorting',
946 ),
947 array(
948 'css_content' => '\f341',
949 'class' => 'dashicons-arrow-left-alt2',
950 'cat' => 'sorting',
951 ),
952 array(
953 'css_content' => '\f156',
954 'class' => 'dashicons-sort',
955 'cat' => 'sorting',
956 ),
957 array(
958 'css_content' => '\f229',
959 'class' => 'dashicons-leftright',
960 'cat' => 'sorting',
961 ),
962 array(
963 'css_content' => '\f503',
964 'class' => 'dashicons-randomize',
965 'cat' => 'sorting',
966 ),
967 array(
968 'css_content' => '\f163',
969 'class' => 'dashicons-list-view',
970 'cat' => 'sorting',
971 ),
972 array(
973 'css_content' => '\f164',
974 'class' => 'dashicons-exerpt-view',
975 'cat' => 'sorting',
976 ),
977 array(
978 'css_content' => '\f509',
979 'class' => 'dashicons-grid-view',
980 'cat' => 'sorting',
981 ),
982 array(
983 'css_content' => '\f545',
984 'class' => 'dashicons-move',
985 'cat' => 'sorting',
986 ),
987
988 array(
989 'css_content' => '\f237',
990 'class' => 'dashicons-share',
991 'cat' => 'social',
992 ),
993 array(
994 'css_content' => '\f240',
995 'class' => 'dashicons-share-alt',
996 'cat' => 'social',
997 ),
998 array(
999 'css_content' => '\f242',
1000 'class' => 'dashicons-share-alt2',
1001 'cat' => 'social',
1002 ),
1003 array(
1004 'css_content' => '\f301',
1005 'class' => 'dashicons-twitter',
1006 'cat' => 'social',
1007 ),
1008 array(
1009 'css_content' => '\f303',
1010 'class' => 'dashicons-rss',
1011 'cat' => 'social',
1012 ),
1013 array(
1014 'css_content' => '\f465',
1015 'class' => 'dashicons-email',
1016 'cat' => 'social',
1017 ),
1018 array(
1019 'css_content' => '\f466',
1020 'class' => 'dashicons-email-alt',
1021 'cat' => 'social',
1022 ),
1023 array(
1024 'css_content' => 'f304',
1025 'class' => 'dashicons-facebook',
1026 'cat' => 'social',
1027 ),
1028 array(
1029 'css_content' => '\f305',
1030 'class' => 'dashicons-facebook-alt',
1031 'cat' => 'social',
1032 ),
1033 array(
1034 'css_content' => '\f462',
1035 'class' => 'dashicons-googleplus',
1036 'cat' => 'social',
1037 ),
1038 array(
1039 'css_content' => '\f325',
1040 'class' => 'dashicons-networking',
1041 'cat' => 'social',
1042 ),
1043
1044 array(
1045 'css_content' => '\f308',
1046 'class' => 'dashicons-hammer',
1047 'cat' => 'wp',
1048 ),
1049 array(
1050 'css_content' => '\f309',
1051 'class' => 'dashicons-art',
1052 'cat' => 'wp',
1053 ),
1054 array(
1055 'css_content' => '\f310',
1056 'class' => 'dashicons-migrate',
1057 'cat' => 'wp',
1058 ),
1059 array(
1060 'css_content' => '\f311',
1061 'class' => 'dashicons-performance',
1062 'cat' => 'wp',
1063 ),
1064 array(
1065 'css_content' => '\f483',
1066 'class' => 'dashicons-universal-access',
1067 'cat' => 'wp',
1068 ),
1069 array(
1070 'css_content' => '\f507',
1071 'class' => 'dashicons-universal-access-alt',
1072 'cat' => 'wp',
1073 ),
1074 array(
1075 'css_content' => '\f486',
1076 'class' => 'dashicons-tickets',
1077 'cat' => 'wp',
1078 ),
1079 array(
1080 'css_content' => '\f484',
1081 'class' => 'dashicons-nametag',
1082 'cat' => 'wp',
1083 ),
1084 array(
1085 'css_content' => '\f481',
1086 'class' => 'dashicons-clipboard',
1087 'cat' => 'wp',
1088 ),
1089 array(
1090 'css_content' => '\f487',
1091 'class' => 'dashicons-heart',
1092 'cat' => 'wp',
1093 ),
1094 array(
1095 'css_content' => '\f488',
1096 'class' => 'dashicons-megaphone',
1097 'cat' => 'wp',
1098 ),
1099 array(
1100 'css_content' => '\f489',
1101 'class' => 'dashicons-schedule',
1102 'cat' => 'wp',
1103 ),
1104
1105 array(
1106 'css_content' => '\f120',
1107 'class' => 'dashicons-wordpress',
1108 'cat' => 'products',
1109 ),
1110 array(
1111 'css_content' => '\f324',
1112 'class' => 'dashicons-wordpress-alt',
1113 'cat' => 'products',
1114 ),
1115 array(
1116 'css_content' => '\f157',
1117 'class' => 'dashicons-pressthis',
1118 'cat' => 'products',
1119 ),
1120 array(
1121 'css_content' => '\f463',
1122 'class' => 'dashicons-update',
1123 'cat' => 'products',
1124 ),
1125 array(
1126 'css_content' => '\f180',
1127 'class' => 'dashicons-screenoptions',
1128 'cat' => 'products',
1129 ),
1130 array(
1131 'css_content' => '\f348"',
1132 'class' => 'dashicons-info',
1133 'cat' => 'products',
1134 ),
1135 array(
1136 'css_content' => '\f174',
1137 'class' => 'dashicons-cart',
1138 'cat' => 'products',
1139 ),
1140 array(
1141 'css_content' => '\f175',
1142 'class' => 'dashicons-feedback',
1143 'cat' => 'products',
1144 ),
1145 array(
1146 'css_content' => '\f176',
1147 'class' => 'dashicons-cloud',
1148 'cat' => 'products',
1149 ),
1150 array(
1151 'css_content' => '\f326',
1152 'class' => 'dashicons-translation',
1153 'cat' => 'products',
1154 ),
1155
1156 array(
1157 'css_content' => '\f323',
1158 'class' => 'dashicons-tag',
1159 'cat' => 'taxonomies',
1160 ),
1161 array(
1162 'css_content' => '\f318',
1163 'class' => 'dashicons-category',
1164 'cat' => 'taxonomies',
1165 ),
1166
1167 array(
1168 'css_content' => '\f480',
1169 'class' => 'dashicons-archive',
1170 'cat' => 'widgets',
1171 ),
1172 array(
1173 'css_content' => '\f479',
1174 'class' => 'dashicons-tagcloud',
1175 'cat' => 'widgets',
1176 ),
1177 array(
1178 'css_content' => '\f478',
1179 'class' => 'dashicons-text',
1180 'cat' => 'widgets',
1181 ),
1182
1183 array(
1184 'css_content' => '\f147',
1185 'class' => 'dashicons-yes',
1186 'cat' => 'notifications',
1187 ),
1188 array(
1189 'css_content' => '\f158',
1190 'class' => 'dashicons-no',
1191 'cat' => 'notifications',
1192 ),
1193 array(
1194 'css_content' => '\f335',
1195 'class' => 'dashicons-no-alt',
1196 'cat' => 'notifications',
1197 ),
1198 array(
1199 'css_content' => '\f132',
1200 'class' => 'dashicons-plus',
1201 'cat' => 'notifications',
1202 ),
1203 array(
1204 'css_content' => '\f502',
1205 'class' => 'dashicons-plus-alt',
1206 'cat' => 'notifications',
1207 ),
1208 array(
1209 'css_content' => '\f460',
1210 'class' => 'dashicons-minus',
1211 'cat' => 'notifications',
1212 ),
1213 array(
1214 'css_content' => '\f153',
1215 'class' => 'dashicons-dismiss',
1216 'cat' => 'notifications',
1217 ),
1218 array(
1219 'css_content' => '\f159',
1220 'class' => 'dashicons-marker',
1221 'cat' => 'notifications',
1222 ),
1223 array(
1224 'css_content' => '\f155',
1225 'class' => 'dashicons-star-filled',
1226 'cat' => 'notifications',
1227 ),
1228 array(
1229 'css_content' => '\f459',
1230 'class' => 'dashicons-star-half',
1231 'cat' => 'notifications',
1232 ),
1233 array(
1234 'css_content' => '\f154',
1235 'class' => 'dashicons-star-empty',
1236 'cat' => 'notifications',
1237 ),
1238 array(
1239 'css_content' => '\f227',
1240 'class' => 'dashicons-flag',
1241 'cat' => 'notifications',
1242 ),
1243 array(
1244 'css_content' => '\f534',
1245 'class' => 'dashicons-warning',
1246 'cat' => 'notifications',
1247 ),
1248
1249 array(
1250 'css_content' => '\f230',
1251 'class' => 'dashicons-location',
1252 'cat' => 'misc',
1253 ),
1254 array(
1255 'css_content' => '\f231',
1256 'class' => 'dashicons-location-alt',
1257 'cat' => 'misc',
1258 ),
1259 array(
1260 'css_content' => '\f178',
1261 'class' => 'dashicons-vault',
1262 'cat' => 'misc',
1263 ),
1264 array(
1265 'css_content' => '\f332',
1266 'class' => 'dashicons-shield',
1267 'cat' => 'misc',
1268 ),
1269 array(
1270 'css_content' => '\f334',
1271 'class' => 'dashicons-shield-alt',
1272 'cat' => 'misc',
1273 ),
1274 array(
1275 'css_content' => '\f468',
1276 'class' => 'dashicons-sos',
1277 'cat' => 'misc',
1278 ),
1279 array(
1280 'css_content' => '\f179',
1281 'class' => 'dashicons-search',
1282 'cat' => 'misc',
1283 ),
1284 array(
1285 'css_content' => '\f181',
1286 'class' => 'dashicons-slides',
1287 'cat' => 'misc',
1288 ),
1289 array(
1290 'css_content' => '\f183',
1291 'class' => 'dashicons-analytics',
1292 'cat' => 'misc',
1293 ),
1294 array(
1295 'css_content' => '\f184',
1296 'class' => 'dashicons-chart-pie',
1297 'cat' => 'misc',
1298 ),
1299 array(
1300 'css_content' => '\f185',
1301 'class' => 'dashicons-chart-bar',
1302 'cat' => 'misc',
1303 ),
1304 array(
1305 'css_content' => '\f238',
1306 'class' => 'dashicons-chart-line',
1307 'cat' => 'misc',
1308 ),
1309 array(
1310 'css_content' => '\f239',
1311 'class' => 'dashicons-chart-area',
1312 'cat' => 'misc',
1313 ),
1314 array(
1315 'css_content' => '\f307',
1316 'class' => 'dashicons-groups',
1317 'cat' => 'misc',
1318 ),
1319 array(
1320 'css_content' => '\f338',
1321 'class' => 'dashicons-businessman',
1322 'cat' => 'misc',
1323 ),
1324 array(
1325 'css_content' => '\f336',
1326 'class' => 'dashicons-id',
1327 'cat' => 'misc',
1328 ),
1329 array(
1330 'css_content' => '\f337',
1331 'class' => 'dashicons-id-alt',
1332 'cat' => 'misc',
1333 ),
1334 array(
1335 'css_content' => '\f312',
1336 'class' => 'dashicons-products',
1337 'cat' => 'misc',
1338 ),
1339 array(
1340 'css_content' => '\f313',
1341 'class' => 'dashicons-awards',
1342 'cat' => 'misc',
1343 ),
1344 array(
1345 'css_content' => '\f314',
1346 'class' => 'dashicons-forms',
1347 'cat' => 'misc',
1348 ),
1349 array(
1350 'css_content' => '\f473',
1351 'class' => 'dashicons-testimonial',
1352 'cat' => 'misc',
1353 ),
1354 array(
1355 'css_content' => '\f322',
1356 'class' => 'dashicons-portfolio',
1357 'cat' => 'misc',
1358 ),
1359 array(
1360 'css_content' => '\f330',
1361 'class' => 'dashicons-book',
1362 'cat' => 'misc',
1363 ),
1364 array(
1365 'css_content' => '\f331',
1366 'class' => 'dashicons-book-alt',
1367 'cat' => 'misc',
1368 ),
1369 array(
1370 'css_content' => '\f316',
1371 'class' => 'dashicons-download',
1372 'cat' => 'misc',
1373 ),
1374 array(
1375 'css_content' => '\f317',
1376 'class' => 'dashicons-upload',
1377 'cat' => 'misc',
1378 ),
1379 array(
1380 'css_content' => '\f321',
1381 'class' => 'dashicons-backup',
1382 'cat' => 'misc',
1383 ),
1384 array(
1385 'css_content' => '\f469',
1386 'class' => 'dashicons-clock',
1387 'cat' => 'misc',
1388 ),
1389 array(
1390 'css_content' => '\f339',
1391 'class' => 'dashicons-lightbulb',
1392 'cat' => 'misc',
1393 ),
1394 array(
1395 'css_content' => '\f482',
1396 'class' => 'dashicons-microphone',
1397 'cat' => 'misc',
1398 ),
1399 array(
1400 'css_content' => '\f472',
1401 'class' => 'dashicons-desktop',
1402 'cat' => 'misc',
1403 ),
1404 array(
1405 'css_content' => '\f547',
1406 'class' => 'dashicons-laptop',
1407 'cat' => 'misc',
1408 ),
1409 array(
1410 'css_content' => '\f471',
1411 'class' => 'dashicons-tablet',
1412 'cat' => 'misc',
1413 ),
1414 array(
1415 'css_content' => '\f470',
1416 'class' => 'dashicons-smartphone',
1417 'cat' => 'misc',
1418 ),
1419 array(
1420 'css_content' => '\f525',
1421 'class' => 'dashicons-phone',
1422 'cat' => 'misc',
1423 ),
1424 array(
1425 'css_content' => '\f510',
1426 'class' => 'dashicons-index-card',
1427 'cat' => 'misc',
1428 ),
1429 array(
1430 'css_content' => '\f511',
1431 'class' => 'dashicons-carrot',
1432 'cat' => 'misc',
1433 ),
1434 array(
1435 'css_content' => '\f512',
1436 'class' => 'dashicons-building',
1437 'cat' => 'misc',
1438 ),
1439 array(
1440 'css_content' => '\f513',
1441 'class' => 'dashicons-store',
1442 'cat' => 'misc',
1443 ),
1444 array(
1445 'css_content' => '\f514',
1446 'class' => 'dashicons-album',
1447 'cat' => 'misc',
1448 ),
1449 array(
1450 'css_content' => '\f527',
1451 'class' => 'dashicons-palmtree',
1452 'cat' => 'misc',
1453 ),
1454 array(
1455 'css_content' => '\f524',
1456 'class' => 'dashicons-tickets-alt',
1457 'cat' => 'misc',
1458 ),
1459 array(
1460 'css_content' => '\f526',
1461 'class' => 'dashicons-money',
1462 'cat' => 'misc',
1463 ),
1464 array(
1465 'css_content' => '\f328',
1466 'class' => 'dashicons-smiley',
1467 'cat' => 'misc',
1468 ),
1469 array(
1470 'css_content' => '\f529',
1471 'class' => 'dashicons-thumbs-up',
1472 'cat' => 'misc',
1473 ),
1474 array(
1475 'css_content' => '\f542',
1476 'class' => 'dashicons-thumbs-down',
1477 'cat' => 'misc',
1478 ),
1479 array(
1480 'css_content' => '\f538',
1481 'class' => 'dashicons-layout',
1482 'cat' => 'misc',
1483 ),
1484 array(
1485 'css_content' => '\f546',
1486 'class' => 'dashicons-paperclip',
1487 'cat' => 'misc',
1488 ),
1489
1490 );
1491
1492 $dashicons = array( 'all' => $icons , 'categories' => $categories );
1493
1494 return $dashicons;
1495
1496 }
1497
1498 public static function get_theme_path( $parent = false ) {
1499
1500 if( $parent ) {
1501
1502 $theme_path = get_template_directory();
1503
1504 } else {
1505
1506 $theme_path = get_stylesheet_directory();
1507
1508 }
1509
1510 return $theme_path;
1511
1512 }
1513
1514 public static function get_theme_url( $parent = false ) {
1515
1516 if( $parent ) {
1517
1518 $theme_url = get_template_directory_uri();
1519
1520 } else {
1521
1522 $theme_url = get_stylesheet_directory_uri();
1523
1524 }
1525
1526 return $theme_url;
1527
1528 }
1529
1530 public static function duplicate_post_from_site_in_network( $from_site_id = false , $from_post_id = false , $args = array() ) {
1531
1532 $called_text = sprintf( '%s::%s()' , __CLASS__ , __FUNCTION__ );
1533
1534 $from_site_id = (int) $from_site_id;
1535
1536 if( empty( $from_site_id ) ) {
1537
1538 MywpHelper::error_require_message( '$from_site_id' , $called_text );
1539
1540 return false;
1541
1542 }
1543
1544 if( is_multisite() ) {
1545
1546 $blog_details = get_blog_details( array( 'blog_id' => $from_site_id ) );
1547
1548 if( empty( $blog_details ) ) {
1549
1550 MywpHelper::error_not_found_message( '$blog_details' , $called_text );
1551
1552 return false;
1553
1554 }
1555
1556 }
1557
1558 $from_post_id = (int) $from_post_id;
1559
1560 if( empty( $from_post_id ) ) {
1561
1562 MywpHelper::error_require_message( '$from_post_id' , $called_text );
1563
1564 return false;
1565
1566 }
1567
1568 $from_args = array(
1569 'site_id' => $from_site_id,
1570 'post_id' => $from_post_id,
1571 'args' => $args,
1572 );
1573
1574 $is_switch_blog = false;
1575
1576 if( is_multisite() ) {
1577
1578 if( $from_site_id !== (int) get_current_blog_id() ) {
1579
1580 $is_switch_blog = true;
1581
1582 switch_to_blog( $from_site_id );
1583
1584 }
1585
1586 }
1587
1588 $from_post = get_post( $from_post_id );
1589
1590 $from_post_metas = false;
1591
1592 $from_post_thumbnail_id = false;
1593
1594 $from_post_attached_file = false;
1595
1596 $from_post_taxonomy_terms = false;
1597
1598 if( ! empty( $from_post ) ) {
1599
1600 if( ! empty( $args['is_duplicate_custom_field'] ) ) {
1601
1602 $from_post_metas = get_post_meta( $from_post_id );
1603
1604 }
1605
1606 if( ! empty( $args['is_duplicate_featured_image'] ) ) {
1607
1608 $from_post_thumbnail_id = get_post_thumbnail_id( $from_post_id );
1609
1610 $from_post_attached_file = get_attached_file( $from_post_thumbnail_id );
1611
1612 }
1613
1614 if( ! empty( $args['is_duplicate_terms'] ) ) {
1615
1616 $taxonomies_args = array(
1617 'object_type' => array( $from_post->post_type ),
1618 );
1619
1620 $taxonomies = get_taxonomies( $taxonomies_args , 'objects' );
1621
1622 $from_post_taxonomy_terms = array();
1623
1624 if( ! empty( $taxonomies ) ) {
1625
1626 foreach( $taxonomies as $taxonomy ) {
1627
1628 $terms = wp_get_post_terms( $from_post_id , $taxonomy->name );
1629
1630 if( empty( $terms ) ) {
1631
1632 continue;
1633
1634 }
1635
1636 if( is_wp_error( $terms ) ) {
1637
1638 continue;
1639
1640 }
1641
1642 $from_post_taxonomy_terms[ $taxonomy->name ] = $terms;
1643
1644 }
1645
1646 }
1647
1648 }
1649
1650 }
1651
1652 if( $is_switch_blog ) {
1653
1654 restore_current_blog();
1655
1656 }
1657
1658 if( empty( $from_post ) ) {
1659
1660 MywpHelper::error_not_found_message( '$from_post' , $called_text );
1661
1662 return false;
1663
1664 }
1665
1666 $post_new_args = (array) $from_post;
1667
1668 foreach( array( 'ID' , 'guid' , 'post_date' , 'post_date_gmt' , 'post_modified' , 'post_modified_gmt' , 'post_content_filtered' , 'comment_count' , 'filter' ) as $key ) {
1669
1670 if( isset( $post_new_args[ $key ] ) ) {
1671
1672 unset( $post_new_args[ $key ] );
1673
1674 }
1675
1676 }
1677
1678 $post_new_args = apply_filters( 'mywp_api_duplicate_post_from_site_in_network_post_new_args' , $post_new_args , $from_post , $from_args );
1679
1680 if( empty( $post_new_args ) ) {
1681
1682 MywpHelper::error_not_found_message( '$post_new_args' , $called_text );
1683
1684 return false;
1685
1686 }
1687
1688 add_filter( 'wp_insert_post_empty_content' , '__return_false' , 1000 );
1689
1690 $new_post_id = wp_insert_post( $post_new_args , true );
1691
1692 remove_filter( 'wp_insert_post_empty_content' , '__return_false' , 1000 );
1693
1694 if( empty( $new_post_id ) ) {
1695
1696 MywpHelper::error_not_found_message( '$new_post_id' , $called_text );
1697
1698 return false;
1699
1700 }
1701
1702 if( is_wp_error( $new_post_id ) ) {
1703
1704 MywpHelper::error_returned_message( '$new_post_id' , sprintf( '[%s] %s' , $new_post_id->get_error_code() , $new_post_id->get_error_message() ) , $called_text );
1705
1706 return false;
1707
1708 }
1709
1710 $validate_new_post = apply_filters( 'mywp_api_duplicate_post_from_site_in_network_post_validate_new_post' , true , $new_post_id , $from_args );
1711
1712 if( ! $validate_new_post ) {
1713
1714 MywpHelper::error_returned_message( '$validate_new_post' , '' , $called_text );
1715
1716 wp_delete_post( $new_post_id , true );
1717
1718 return false;
1719
1720 }
1721
1722 if( ! empty( $args['is_duplicate_custom_field'] ) ) {
1723
1724 if( ! empty( $from_post_metas ) ) {
1725
1726 foreach( $from_post_metas as $meta_key => $from_post_meta_values ) {
1727
1728 foreach( $from_post_meta_values as $from_post_meta_value ) {
1729
1730 add_post_meta( $new_post_id , $meta_key , maybe_unserialize( $from_post_meta_value ) );
1731
1732 }
1733
1734 }
1735
1736 }
1737
1738 }
1739
1740 if( ! empty( $args['is_duplicate_featured_image'] ) ) {
1741
1742 if( ! empty( $from_post_attached_file ) ) {
1743
1744 $pathinfo = pathinfo( $from_post_attached_file );
1745
1746 $from_post_attached_file_data = file_get_contents( $from_post_attached_file );
1747
1748 $new_attachment_id = self::create_attachment_from_filedata( $from_post_attached_file_data , $pathinfo['basename'] );
1749
1750 if( empty( self::get_error() ) ) {
1751
1752 if( empty( $new_attachment_id ) ) {
1753
1754 MywpHelper::error_not_found_message( '$new_attachment_id' , $called_text );
1755
1756 } else {
1757
1758 wp_update_post( array( 'ID' => $new_attachment_id , 'post_parent' => $new_post_id ) );
1759
1760 set_post_thumbnail( $new_post_id , $new_attachment_id );
1761
1762 }
1763
1764 }
1765
1766 }
1767
1768 }
1769
1770 if( ! empty( $args['is_duplicate_terms'] ) ) {
1771
1772 if( ! empty( $from_post_taxonomy_terms ) ) {
1773
1774 foreach( $from_post_taxonomy_terms as $taxonomy_name => $from_post_terms ) {
1775
1776 $term_names = array();
1777
1778 foreach( $from_post_terms as $from_post_term ) {
1779
1780 $term_names[] = $from_post_term->name;
1781
1782 }
1783
1784 if( empty( $term_names ) ) {
1785
1786 continue;
1787
1788 }
1789
1790 $wp_set_object_terms = wp_set_object_terms( $new_post_id , $term_names , $taxonomy_name , false );
1791
1792 if( empty( $wp_set_object_terms ) ) {
1793
1794 MywpHelper::error_not_found_message( '$wp_set_object_terms' , $called_text );
1795
1796 continue;
1797
1798 }
1799
1800 if( is_wp_error( $wp_set_object_terms ) ) {
1801
1802 MywpHelper::error_returned_message( '$wp_set_object_terms' , sprintf( '[%s] %s' , $wp_set_object_terms->get_error_code() , $wp_set_object_terms->get_error_message() ) , $called_text );
1803
1804 continue;
1805
1806 }
1807
1808 }
1809
1810 }
1811
1812 }
1813
1814 do_action( 'mywp_api_duplicate_post_from_site_in_network' , $new_post_id , $from_args );
1815
1816 return $new_post_id;
1817
1818 }
1819
1820 public static function create_attachment_from_filedata( $filedata = false , $filename = false ) {
1821
1822 $called_text = sprintf( '%s::%s()' , __CLASS__ , __FUNCTION__ );
1823
1824 if( empty( $filedata ) ) {
1825
1826 MywpHelper::error_require_message( '$filedata' , $called_text );
1827
1828 return false;
1829
1830 }
1831
1832 $filename = strip_tags( $filename );
1833
1834 if( empty( $filename ) ) {
1835
1836 MywpHelper::error_require_message( '$filename' , $called_text );
1837
1838 return false;
1839
1840 }
1841
1842 $wp_upload_bits = wp_upload_bits( $filename , null , $filedata );
1843
1844 if( ! empty( $wp_upload_bits['error'] ) ) {
1845
1846 MywpHelper::error_returned_message( '$wp_upload_bits' , $wp_upload_bits['error'] , $called_text );
1847
1848 return false;
1849
1850 }
1851
1852 $wp_filetype = wp_check_filetype( $wp_upload_bits['file'] , null );
1853
1854 $attachment_args = array(
1855 'post_mime_type' => $wp_filetype['type'],
1856 'post_title' => sanitize_file_name( basename( $filename ) ),
1857 'post_content' => '',
1858 'post_status' => 'inherit',
1859 );
1860
1861 $attachment_id = wp_insert_attachment( $attachment_args , $wp_upload_bits['file'] );
1862
1863 if( empty( $attachment_id ) ) {
1864
1865 MywpHelper::error_not_found_message( '$attachment_id' , $called_text );
1866
1867 return false;
1868
1869 }
1870
1871 if( is_wp_error( $attachment_id ) ) {
1872
1873 MywpHelper::error_returned_message( '$attachment_id' , sprintf( '[%s] %s' , $attachment_id->get_error_code() , $attachment_id->get_error_message() ) , $called_text );
1874
1875 return false;
1876
1877 }
1878
1879 if( ! function_exists( 'wp_generate_attachment_metadata' ) ) {
1880
1881 require_once( ABSPATH . 'wp-admin/includes/image.php' );
1882
1883 }
1884
1885 $attachment_metadata = wp_generate_attachment_metadata( $attachment_id , $wp_upload_bits['file'] );
1886
1887 wp_update_attachment_metadata( $attachment_id , $attachment_metadata);
1888
1889 return $attachment_id;
1890
1891 }
1892
1893 }
1894
1895 endif;
1896