class-wpml-wp-api.php
28.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
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
<?php
use WPML\API\Sanitize;
use WPML\Core\Twig_Environment;
use WPML\Core\Twig_Loader_Filesystem;
use WPML\Core\Twig_Loader_String;
use WPML\Core\Twig_LoaderInterface;
use function WPML\Container\make;
class WPML_WP_API extends WPML_PHP_Functions {
/**
* @param string $file
* @param string $filename
*
* @return false | string
*/
public function get_file_mime_type( $file, $filename ) {
$mime_type = false;
if ( file_exists( $file ) ) {
$file_info = wp_check_filetype_and_ext( $file, $filename );
$mime_type = $file_info['type'];
}
return $mime_type;
}
/**
* Wrapper for \get_option
*
* @param string $option
* @param bool|false $default
*
* @return mixed
*/
public function get_option( $option, $default = false ) {
return get_option( $option, $default );
}
public function is_url( $value ) {
$regex = '((https?|ftp)\:\/\/)?'; // SCHEME
$regex .= '([a-z0-9+!*(),;?&=$_.-]+(\:[a-z0-9+!*(),;?&=$_.-]+)?@)?'; // User and Pass
$regex .= '([a-z0-9-.]*)\.([a-z]{2,3})'; // Host or IP
$regex .= '(\:[0-9]{2,5})?'; // Port
$regex .= '(\/([a-z0-9+$_-]\.?)+)*\/?'; // Path
$regex .= '(\?[a-z+&$_.-][a-z0-9;:@&%=+\/$_.-]*)?'; // GET Query
$regex .= '(#[a-z_.-][a-z0-9+$_.-]*)?'; // Anchor
return preg_match( "/^$regex$/", $value );
}
public function get_transient( $transient ) {
return get_transient( $transient );
}
public function set_transient( $transient, $value, $expiration = 0 ) {
set_transient( $transient, $value, $expiration );
}
/**
* @param string $option
* @param mixed $value
* @param string|bool $autoload
*
* @return bool False if value was not updated and true if value was updated.
*/
public function update_option( $option, $value, $autoload = null ) {
return update_option( $option, $value, $autoload );
}
/**
* @param string|int|WP_Post $ID Optional. Post ID or post object. Default empty.
*
* @return false|string
*/
public function get_post_status( $ID = '' ) {
$ID = is_string( $ID ) ? (int) $ID : $ID;
return get_post_status( $ID );
}
/**
* Wrapper for \get_term_link
*
* @param WP_Term|int|string $term
* @param string $taxonomy
*
* @return string|WP_Error
*/
public function get_term_link( $term, $taxonomy = '' ) {
return get_term_link( $term, $taxonomy );
}
/**
* Wrapper for \get_term_by
*
* @param string $field
* @param string|int $value
* @param string $taxonomy
* @param string $output
* @param string $filter
*
* @return bool|WP_Term
*/
public function get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) {
return get_term_by( $field, $value, $taxonomy, $output, $filter );
}
/**
* Wrapper for \add_submenu_page
*
* @param string $parent_slug
* @param string $page_title
* @param string $menu_title
* @param string $capability
* @param string $menu_slug
* @param array|string $function
*
* @return false|string
*/
public function add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
/** @phpstan-ignore-next-line WP doc issue. */
return add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
}
/**
* @param string $page_title
* @param string $menu_title
* @param string $capability
* @param string $menu_slug
* @param array|string $function
* @param string $icon_url
* @param null $position
*
* @return string
*/
public function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = null ) {
/** @phpstan-ignore-next-line WP doc issue. */
return add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
}
/**
* Wrapper for \get_post_type_archive_link
*
* @param string $post_type
*
* @return string
*/
public function get_post_type_archive_link( $post_type ) {
return get_post_type_archive_link( $post_type );
}
/**
* Wrapper for \get_edit_post_link
*
* @param int $id
* @param string $context
*
* @return null|string|void
*/
public function get_edit_post_link( $id = 0, $context = 'display' ) {
return get_edit_post_link( $id, $context );
}
/**
* Wrapper for get_the_title
*
* @param int|WP_Post $post
*
* @return string
*/
public function get_the_title( $post ) {
return get_the_title( $post );
}
/**
* Wrapper for \get_day_link
*
* @param int $year
* @param int $month
* @param int $day
*
* @return string
*/
public function get_day_link( $year, $month, $day ) {
return get_day_link( $year, $month, $day );
}
/**
* Wrapper for \get_month_link
*
* @param int $year
* @param int $month
*
* @return string
*/
public function get_month_link( $year, $month ) {
return get_month_link( $year, $month );
}
/**
* Wrapper for \get_year_link
*
* @param int $year
*
* @return string
*/
public function get_year_link( $year ) {
return get_year_link( $year );
}
/**
* Wrapper for \get_author_posts_url
*
* @param int $author_id
* @param string $author_nicename
*
* @return string
*/
public function get_author_posts_url( $author_id, $author_nicename = '' ) {
return get_author_posts_url( $author_id, $author_nicename );
}
/**
* Wrapper for \current_user_can
*
* @param string $capability
*
* @return bool
*/
public function current_user_can( $capability ) {
return WPML\LIB\WP\User::currentUserCan( $capability );
}
/**
* @param int $user_id
* @param string $key
* @param bool $single
*
* @return mixed
*/
public function get_user_meta( $user_id, $key = '', $single = false ) {
return get_user_meta( $user_id, $key, $single );
}
/**
* Wrapper for \get_post_type
*
* @param null|int|WP_Post $post
*
* @return false|string
*/
public function get_post_type( $post = null ) {
return get_post_type( $post );
}
public function is_archive() {
return is_archive();
}
public function is_front_page() {
return is_front_page();
}
public function is_home() {
return is_home();
}
/**
* @param int|string|array $page Optional. Page ID, title, slug, or array of such. Default empty.
*
* @return bool
*/
public function is_page( $page = '' ) {
return is_page( $page );
}
public function is_paged() {
return is_paged();
}
/**
* @param string $post
*
* @return int|string|array $post Optional. Post ID, title, slug, or array of such. Default empty.
*/
public function is_single( $post = '' ) {
return is_single( $post );
}
/**
* @param string|array $post_types
*
* @return bool
*/
public function is_singular( $post_types = '' ) {
return is_singular( $post_types );
}
/**
* @param int|WP_User $user
* @param string $capability
*
* @return bool
*/
public function user_can( $user, $capability ) {
return WPML\LIB\WP\User::userCan( $user, $capability );
}
/**
* Wrapper for add_filter
*
* @param string $tag
* @param callable $function_to_add
* @param int $priority
* @param int $accepted_args
*
* @return bool|mixed|true|void
*/
public function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
return add_filter( $tag, $function_to_add, $priority, $accepted_args );
}
/**
* Wrapper for remove_filter
*
* @param string $tag
* @param callable $function_to_remove
* @param int $priority
*
* @return bool
*/
public function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
return remove_filter( $tag, $function_to_remove, $priority );
}
/**
* Wrapper for current_filter
*/
public function current_filter() {
return current_filter();
}
/**
* @param null|string $tab
* @param null|string $hash
*
* @return string
*/
public function get_tm_url( $tab = null, $hash = null ) {
$tm_url = menu_page_url( $this->constant( 'WPML_TM_FOLDER' ) . '/menu/main.php', false );
$query_vars = array();
if ( $tab ) {
$query_vars['sm'] = $tab;
}
$tm_url = add_query_arg( $query_vars, $tm_url );
if ( $hash ) {
if ( strpos( $hash, '#' ) !== 0 ) {
$hash = '#' . $hash;
}
$tm_url .= $hash;
}
return $tm_url;
}
/**
* Wrapper for \is_admin()
*
* @return bool
*/
public function is_admin() {
return is_admin();
}
public function is_jobs_tab() {
return $this->is_tm_page( 'jobs' );
}
/**
* @param string|null $tab
* @param string|null $page_type
*
* @return bool
*/
public function is_tm_page( $tab = null, $page_type = 'management' ) {
if ( 'settings' === $page_type ) {
$page_suffix = '/menu/settings';
$default_tab = 'mcsetup';
} else {
$page_suffix = '/menu/main.php';
$default_tab = 'dashboard';
}
$result = is_admin()
&& isset( $_GET['page'] )
&& $_GET['page'] == $this->constant( 'WPML_TM_FOLDER' ) . $page_suffix;
if ( $tab ) {
if ( $tab == $default_tab && ! isset( $_GET['sm'] ) ) {
$result = $result && true;
} else {
$result = $result && isset( $_GET['sm'] ) && $_GET['sm'] == $tab;
}
}
return $result;
}
public function is_translation_queue_page() {
return is_admin() && isset( $_GET['page'] ) && $this->constant( 'WPML_TM_FOLDER' ) . '/menu/translations-queue.php' == $_GET['page'];
}
public function is_string_translation_page() {
return is_admin() && isset( $_GET['page'] ) && $this->constant( 'WPML_ST_FOLDER' ) . '/menu/string-translation.php' == $_GET['page'];
}
public function is_support_page() {
return $this->is_core_page( 'support.php' );
}
public function is_troubleshooting_page() {
return $this->is_core_page( 'troubleshooting.php' );
}
/**
* @param string $page
*
* @return bool
*/
public function is_core_page( $page = '' ) {
$result = is_admin()
&& isset( $_GET['page'] )
&& stripos( $_GET['page'], $this->constant( 'ICL_PLUGIN_FOLDER' ) . '/menu/' . $page ) !== false;
return $result;
}
public function is_back_end() {
return is_admin() && ! $this->is_ajax() && ! $this->is_cron_job();
}
public function is_front_end() {
return ! is_admin() &&
! $this->is_ajax() &&
! $this->is_cron_job() &&
! wpml_is_rest_request();
}
public function is_ajax() {
$result = defined( 'DOING_AJAX' ) && DOING_AJAX;
if ( $this->function_exists( 'wpml_is_ajax' ) ) {
/** @noinspection PhpUndefinedFunctionInspection */
$result = $result || wpml_is_ajax();
}
return $result;
}
public function is_cron_job() {
return defined( 'DOING_CRON' ) && DOING_CRON;
}
public function is_heartbeat() {
$action = Sanitize::stringProp( 'action', $_POST );
return 'heartbeat' === $action;
}
public function is_post_edit_page() {
global $pagenow;
return 'post.php' === $pagenow && isset( $_GET['action'], $_GET['post'] )
&& 'edit' === Sanitize::stringProp( 'action', $_GET );
}
public function is_new_post_page() {
global $pagenow;
return 'post-new.php' === $pagenow;
}
public function is_term_edit_page() {
global $pagenow;
return 'term.php' === $pagenow || ( 'edit-tags.php' === $pagenow && isset( $_GET['action'] ) && 'edit' === filter_var( $_GET['action'] ) );
}
public function is_customize_page() {
global $pagenow;
return 'customize.php' === $pagenow;
}
public function is_comments_post_page() {
global $pagenow;
return 'wp-comments-post.php' === $pagenow;
}
public function is_plugins_page() {
global $pagenow;
return 'plugins.php' === $pagenow;
}
public function is_themes_page() {
global $pagenow;
return 'themes.php' === $pagenow;
}
/**
* Wrapper for \is_feed that returns false if called before the loop
*
* @param string $feeds
*
* @return bool
*/
public function is_feed( $feeds = '' ) {
global $wp_query;
return isset( $wp_query ) && is_feed( $feeds );
}
/**
* Wrapper for \wp_update_term_count
*
* @param int[] $terms given by their term_taxonomy_ids
* @param string $taxonomy
* @param bool|false $do_deferred
*
* @return bool
*/
public function wp_update_term_count( $terms, $taxonomy, $do_deferred = false ) {
return wp_update_term_count( $terms, $taxonomy, $do_deferred );
}
/**
* Wrapper for \get_taxonomy
*
* @param string $taxonomy
*
* @return bool|object
*/
public function get_taxonomy( $taxonomy ) {
return get_taxonomy( $taxonomy );
}
/**
* Wrapper for \wp_set_object_terms
*
* @param int $object_id The object to relate to.
* @param array|int|string $terms A single term slug, single term id, or array of either term slugs or ids.
* Will replace all existing related terms in this taxonomy.
* @param string $taxonomy The context in which to relate the term to the object.
* @param bool $append Optional. If false will delete difference of terms. Default false.
*
* @return array|WP_Error Affected Term IDs.
*/
public function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) {
return wp_set_object_terms( $object_id, $terms, $taxonomy, $append );
}
/**
* Wrapper for \get_post_types
*
* @param array $args
* @param string $output
* @param string $operator
*
* @return array
*/
public function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) {
return get_post_types( $args, $output, $operator );
}
public function wp_send_json( $response ) {
wp_send_json( $response );
return $response;
}
public function wp_send_json_success( $data = null ) {
wp_send_json_success( $data );
return $data;
}
public function wp_send_json_error( $data = null ) {
wp_send_json_error( $data );
return $data;
}
/**
* Wrapper for \get_current_user_id
*
* @return int
*/
public function get_current_user_id() {
return get_current_user_id();
}
/**
* Wrapper for \get_post
*
* @param null|int|WP_Post $post
* @param string $output
* @param string $filter
*
* @return array|null|WP_Post
*/
public function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) {
return get_post( $post, $output, $filter );
}
/**
* Wrapper for \get_post_meta
*
* @param int $post_id Post ID.
* @param string $key Optional. The meta key to retrieve. By default, returns
* data for all keys. Default empty.
* @param bool $single Optional. Whether to return a single value. Default false.
*
* @return mixed Will be an array if $single is false. Will be value of meta data
* field if $single is true.
*/
public function get_post_meta( $post_id, $key = '', $single = false ) {
return get_post_meta( $post_id, $key, $single );
}
/**
* Wrapper for \update_post_meta
*
* @param int $post_id Post ID.
* @param string $key
* @param mixed $value
* @param mixed $prev_value
*
* @return int|bool
*/
public function update_post_meta(
$post_id,
$key,
$value,
$prev_value = ''
) {
return update_post_meta( $post_id, $key, $value, $prev_value );
}
/**
* Wrapper for add_post_meta
*
* @param int $post_id Post ID.
* @param string $meta_key Metadata name.
* @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
* @param bool $unique Optional. Whether the same key should not be added.
* Default false.
* @return int|false Meta ID on success, false on failure.
*/
public function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
return add_post_meta( $post_id, $meta_key, $meta_value, $unique );
}
/**
* Wrapper for delete_post_meta
*
* @param int $post_id Post ID.
* @param string $meta_key Metadata name.
* @param mixed $meta_value Optional. Metadata value. Must be serializable if
* non-scalar. Default empty.
* @return bool True on success, false on failure.
*/
public function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
return delete_post_meta( $post_id, $meta_key, $meta_value );
}
/**
* Wrapper for \get_term_meta
*
* @param int $term_id
* @param string $key
* @param bool $single
*
* @return mixed
*/
public function get_term_meta( $term_id, $key = '', $single = false ) {
return get_term_meta( $term_id, $key, $single );
}
/**
* Wrapper for \get_permalink
*
* @param int $id
* @param bool|false $leavename
*
* @return bool|string
*/
public function get_permalink( $id = 0, $leavename = false ) {
return get_permalink( $id, $leavename );
}
/**
* Wrapper for \wp_mail
*
* @param string $to
* @param string $subject
* @param string $message
* @param string|array $headers
* @param array|array $attachments
*
* @return bool
*/
public function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
return wp_mail( $to, $subject, $message, $headers, $attachments );
}
/**
* Wrapper for \get_post_custom
*
* @param int $post_id
*
* @return array
*/
public function get_post_custom( $post_id = 0 ) {
return get_post_custom( $post_id );
}
public function is_dashboard_tab() {
return $this->is_tm_page( 'dashboard' );
}
public function wp_safe_redirect( $redir_target, $status = 302 ) {
if ( wp_safe_redirect( $redir_target, $status, 'WPML' ) ) {
exit;
}
}
/**
* Wrapper for \load_textdomain
*
* @param string $domain
* @param string $mofile
*
* @return bool
*/
public function load_textdomain( $domain, $mofile ) {
return load_textdomain( $domain, $mofile );
}
/**
* Wrapper for \get_home_url
*
* @param null|int $blog_id
* @param string $path
* @param null|string $scheme
*
* @return string
*/
public function get_home_url(
$blog_id = null,
$path = '',
$scheme = null
) {
return get_home_url( $blog_id, $path, $scheme );
}
/**
* Wrapper for \get_site_url
*
* @param null|int $blog_id
* @param string $path
* @param null|string $scheme
*
* @return string
*/
public function get_site_url(
$blog_id = null,
$path = '',
$scheme = null
) {
return get_site_url( $blog_id, $path, $scheme );
}
/**
* Wrapper for \is_multisite
*
* @return bool
*/
public function is_multisite() {
return is_multisite();
}
/**
* Wrapper for \is_main_site
*
* @param null|int $site_id
*
* @return bool
*/
public function is_main_site( $site_id = null ) {
return is_main_site( $site_id );
}
/**
* Wrapper for \ms_is_switched
*
* @return bool
*/
public function ms_is_switched() {
return ms_is_switched();
}
/**
* Wrapper for \get_current_blog_id
*
* @return int
*/
public function get_current_blog_id() {
return get_current_blog_id();
}
/**
* Wrapper for wp_get_post_terms
*
* @param int $post_id
* @param string $taxonomy
* @param array $args
*
* @return array|WP_Error
*/
public function wp_get_post_terms(
$post_id = 0,
$taxonomy = 'post_tag',
$args = array()
) {
return wp_get_post_terms( $post_id, $taxonomy, $args );
}
/**
* Wrapper for get_taxonomies
*
* @param array $args
* @param string $output
* @param string $operator
*
* @return array
*/
public function get_taxonomies(
$args = array(),
$output = 'names',
$operator = 'and'
) {
return get_taxonomies( $args, $output, $operator );
}
/**
* Wrapper for \wp_get_theme
*
* @param string $stylesheet
* @param string $theme_root
*
* @return WP_Theme
*/
public function wp_get_theme( $stylesheet = null, $theme_root = null ) {
return wp_get_theme( $stylesheet, $theme_root );
}
/**
* Wrapper for \wp_get_theme->get('Name')
*
* @return string
*/
public function get_theme_name() {
return wp_get_theme()->get( 'Name' );
}
/**
* Wrapper for \wp_get_theme->parent_theme
*
* @return string
*/
public function get_theme_parent_name() {
return wp_get_theme()->parent_theme;
}
/**
* Wrapper for \wp_get_theme->get('URI')
*
* @return string
*/
public function get_theme_URI() {
return wp_get_theme()->get( 'URI' );
}
/**
* Wrapper for \wp_get_theme->get('Author')
*
* @return string
*/
public function get_theme_author() {
return wp_get_theme()->get( 'Author' );
}
/**
* Wrapper for \wp_get_theme->get('AuthorURI')
*
* @return string
*/
public function get_theme_authorURI() {
return wp_get_theme()->get( 'AuthorURI' );
}
/**
* Wrapper for \wp_get_theme->get('Template')
*
* @return string
*/
public function get_theme_template() {
return wp_get_theme()->get( 'Template' );
}
/**
* Wrapper for \wp_get_theme->get('Version')
*
* @return string
*/
public function get_theme_version() {
return wp_get_theme()->get( 'Version' );
}
/**
* Wrapper for \wp_get_theme->get('TextDomain')
*
* @return string
*/
public function get_theme_textdomain() {
return wp_get_theme()->get( 'TextDomain' );
}
/**
* Wrapper for \wp_get_theme->get('DomainPath')
*
* @return string
*/
public function get_theme_domainpath() {
return wp_get_theme()->get( 'DomainPath' );
}
/**
* Wrapper for \get_plugins()
*
* @return array
*/
public function get_plugins() {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
return get_plugins();
}
/**
* Wrapper for \get_post_custom_keys
*
* @param int $post_id
*
* @return array|void
*/
public function get_post_custom_keys( $post_id ) {
return get_post_custom_keys( $post_id );
}
/**
* Wrapper for \get_bloginfo
*
* @param string $show (optional)
* @param string $filter (optional)
*
* @return string
*/
public function get_bloginfo( $show = '', $filter = 'raw' ) {
return get_bloginfo( $show, $filter );
}
/**
* Compare version in their "naked" form
*
* @see \WPML_WP_API::get_naked_version
* @see \WPML_WP_API::version_compare
* @see \version_compare
*
* @param string $version1
* @param string $version2
* @param null $operator
*
* @return mixed
*/
public function version_compare_naked( $version1, $version2, $operator = null ) {
return $this->version_compare( $this->get_naked_version( $version1 ), $this->get_naked_version( $version2 ), $operator );
}
/**
* Returns only the first 3 numeric elements of a version (assuming to use MAJOR.MINOR.PATCH
*
* @param string $version
*
* @return string
*/
public function get_naked_version( $version ) {
$elements = explode( '.', str_replace( '..', '.', preg_replace( '/([^0-9\.]+)/', '.$1.', str_replace( array( '-', '_', '+' ), '.', trim( $version ) ) ) ) );
$naked_elements = array( '0', '0', '0' );
$elements_count = 0;
foreach ( $elements as $element ) {
if ( $elements_count === 3 || ! is_numeric( $element ) ) {
break;
}
$naked_elements[ $elements_count ] = $element;
$elements_count ++;
}
return implode( $naked_elements );
}
public function has_filter( $tag, $function_to_check = false ) {
return has_filter( $tag, $function_to_check );
}
public function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
return add_action( $tag, $function_to_add, $priority, $accepted_args );
}
public function get_current_screen() {
return get_current_screen();
}
/**
* Wrapper for \get_query_var
*
* @param string $var
* @param mixed $default
*
* @return mixed
*/
public function get_query_var( $var, $default = '' ) {
return get_query_var( $var, $default );
}
/**
* Wrapper for \get_queried_object
*/
public function get_queried_object() {
return get_queried_object();
}
public function get_raw_post_data() {
$raw_post_data = @file_get_contents( 'php://input' );
if ( ! $raw_post_data && array_key_exists( 'HTTP_RAW_POST_DATA', $GLOBALS ) ) {
$raw_post_data = $GLOBALS['HTTP_RAW_POST_DATA'];
}
return $raw_post_data;
}
public function wp_verify_nonce( $nonce, $action = -1 ) {
return wp_verify_nonce( $nonce, $action );
}
/**
* @param string $action
*
* @return int The number of times action hook $tag is fired.
*/
public function did_action( $action ) {
return did_action( $action );
}
/**
* @return string
*/
public function current_action() {
return current_action();
}
public function get_wp_post_types_global() {
global $wp_post_types;
return $wp_post_types;
}
/**
* @return wp_xmlrpc_server
*/
public function get_wp_xmlrpc_server() {
global $wp_xmlrpc_server;
return $wp_xmlrpc_server;
}
/**
* Wrapper for $wp_taxonomies global variable
*/
public function get_wp_taxonomies() {
global $wp_taxonomies;
return $wp_taxonomies;
}
/**
* Wrapper for get_category_link function
*
* @param int $category_id
*
* @return string
*/
public function get_category_link( $category_id ) {
return get_category_link( $category_id );
}
/**
* Wrapper for is_wp_error function
*
* @param mixed $thing
*
* @return bool
*/
public function is_wp_error( $thing ) {
return is_wp_error( $thing );
}
/**
* @param int $limit
* @param bool $provide_object
* @param bool $ignore_args
*
* @return array
*/
public function get_backtrace( $limit = 0, $provide_object = false, $ignore_args = true ) {
$options = false;
if ( version_compare( $this->phpversion(), '5.3.6' ) < 0 ) {
// Before 5.3.6, the only values recognized are TRUE or FALSE,
// which are the same as setting or not setting the DEBUG_BACKTRACE_PROVIDE_OBJECT option respectively.
$options = $provide_object;
} else {
// As of 5.3.6, 'options' parameter is a bitmask for the following options:
if ( $provide_object ) {
$options |= DEBUG_BACKTRACE_PROVIDE_OBJECT;
}
if ( $ignore_args ) {
// phpcs:disable PHPCompatibility.Constants.NewConstants.debug_backtrace_ignore_argsFound -- It has a version check
$options |= DEBUG_BACKTRACE_IGNORE_ARGS;
// phpcs:enable PHPCompatibility.Constants.NewConstants.debug_backtrace_ignore_argsFound
}
}
// phpcs:disable PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection -- It has a version check
// phpcs:disable PHPCompatibility.FunctionUse.NewFunctionParameters.debug_backtrace_limitFound -- It has a version check
if ( version_compare( $this->phpversion(), '5.4.0' ) >= 0 ) {
$debug_backtrace = debug_backtrace( $options, $limit ); // add one item to include the current frame
} elseif ( version_compare( $this->phpversion(), '5.2.4' ) >= 0 ) {
// @link https://core.trac.wordpress.org/ticket/20953
$debug_backtrace = debug_backtrace();
} else {
$debug_backtrace = debug_backtrace( $options );
}
// phpcs:enable PHPCompatibility.FunctionUse.NewFunctionParameters.debug_backtrace_limitFound
// phpcs:enable PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
// Remove the current frame
if ( $debug_backtrace ) {
array_shift( $debug_backtrace );
}
return $debug_backtrace;
}
/**
* @return WP_Filesystem_Direct
*/
public function get_wp_filesystem_direct() {
global $wp_filesystem;
require_once ABSPATH . 'wp-admin/includes/file.php';
/**
* We need to make sure that `WP_Filesystem` has been called
* at least once so that some constants are defined with
* default values.
*/
if ( ! $wp_filesystem ) {
WP_Filesystem();
}
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
return new WP_Filesystem_Direct( null );
}
/**
* @return WPML_Notices
*/
public function get_admin_notices() {
global $wpml_admin_notices;
if ( ! $wpml_admin_notices ) {
$wpml_admin_notices = new WPML_Notices( new WPML_Notice_Render() );
$wpml_admin_notices->init_hooks();
}
return $wpml_admin_notices;
}
/**
* @param Twig_LoaderInterface $loader
* @param array $environment_args
*
* @return Twig_Environment
*/
public function get_twig_environment( $loader, $environment_args ) {
return new Twig_Environment( $loader, $environment_args );
}
/**
* @param array $template_paths
*
* @return Twig_Loader_Filesystem|\WPML\Core\Twig_LoaderInterface
*/
public function get_twig_loader_filesystem( $template_paths ) {
return new Twig_Loader_Filesystem( $template_paths );
}
/**
* @return \WPML\Core\Twig_Loader_String|\WPML\Core\Twig_LoaderInterface
*/
public function get_twig_loader_string() {
return new Twig_Loader_String();
}
public function is_a_REST_request() {
return defined( 'REST_REQUEST' ) && REST_REQUEST;
}
}