PluginProbe
Polylang / 2.5
Polylang v2.5
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | include/functions.php +41 -74 2.82.5 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Define wordpress.com VIP equivalent of uncached functions
8 5 * WordPress backward compatibility functions
@@ -20,54 +17,71 @@
20 17 * @param string|array $post_type Optional. Post type or array of post types. Default 'page'.
21 18 * @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
22 19 */
23 20 function wpcom_vip_get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
24 - return get_page_by_title( $page_title, $output, $post_type ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.get_page_by_title_get_page_by_title
21 + return get_page_by_title( $page_title, $output, $post_type );
25 22 }
26 23 }
27 24
28 -if ( ! function_exists( 'wp_doing_ajax' ) ) {
25 +if ( ! function_exists( 'wpcom_vip_get_category_by_slug' ) ) {
29 26 /**
30 - * Determines whether the current request is a WordPress Ajax request.
31 - * Backward compatibility function for WP < 4.7
27 + * Retrieve category object by category slug.
32 28 *
33 - * @since 2.2
29 + * @since 2.0
34 30 *
35 - * @return bool True if it's a WordPress Ajax request, false otherwise.
31 + * @param string $slug The category slug.
32 + * @return object Category data object
36 33 */
37 - function wp_doing_ajax() {
38 - /** This filter is documented in wp-includes/load.php */
39 - return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
34 + function wpcom_vip_get_category_by_slug( $slug ) {
35 + return get_category_by_slug( $slug );
40 36 }
41 37 }
42 38
43 -if ( ! function_exists( 'wp_doing_cron' ) ) {
39 +if ( ! function_exists( 'wpcom_vip_get_term_by' ) ) {
44 40 /**
45 - * Determines whether the current request is a WordPress cron request.
46 - * Backward compatibility function for WP < 4.8
41 + * Get all Term data from database by Term field and data.
47 42 *
48 - * @since 2.6
43 + * @since 2.0
49 44 *
50 - * @return bool True if it's a WordPress cron request, false otherwise.
45 + * @param string $field Either 'slug', 'name', 'id' (term_id), or 'term_taxonomy_id'
46 + * @param string|int $value Search for this term value
47 + * @param string $taxonomy Taxonomy name. Optional, if `$field` is 'term_taxonomy_id'.
48 + * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N. Default OBJECT.
49 + * @param string $filter Optional, default is raw or no WordPress defined filter will applied.
50 + * @return WP_Term|array|false WP_Term instance (or array) on success. Will return false if `$taxonomy` does not exist or `$term` was not found.
51 51 */
52 - function wp_doing_cron() {
53 - /** This filter is documented in wp-includes/load.php */
54 - return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON );
52 + function wpcom_vip_get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) {
53 + return get_term_by( $field, $value, $taxonomy, $output, $filter );
55 54 }
56 55 }
57 56
58 -if ( ! function_exists( 'wp_using_themes' ) ) {
57 +if ( ! function_exists( 'wpcom_vip_get_term_link' ) ) {
59 58 /**
60 - * Determines whether the current request should use themes.
61 - * Backward compatibility function for WP < 5.1
59 + * Generate a permalink for a taxonomy term archive.
62 60 *
63 - * @since 2.6
61 + * @since 2.0
64 62 *
65 - * @return bool True if themes should be used, false otherwise.
63 + * @param object|int|string $term The term object, ID, or slug whose link will be retrieved.
64 + * @param string $taxonomy Optional. Taxonomy. Default empty.
65 + * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist.
66 66 */
67 - function wp_using_themes() {
67 + function wpcom_vip_get_term_link( $term, $taxonomy = '' ) {
68 + return get_term_link( $term, $taxonomy );
69 + }
70 +}
71 +
72 +if ( ! function_exists( 'wp_doing_ajax' ) ) {
73 + /**
74 + * Determines whether the current request is a WordPress Ajax request.
75 + * Backward compatibility function for WP < 4.7
76 + *
77 + * @since 2.2
78 + *
79 + * @return bool True if it's a WordPress Ajax request, false otherwise.
80 + */
81 + function wp_doing_ajax() {
68 82 /** This filter is documented in wp-includes/load.php */
69 - return apply_filters( 'wp_using_themes', defined( 'WP_USE_THEMES' ) && WP_USE_THEMES );
83 + return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
70 84 }
71 85 }
72 86
73 87 /**
@@ -86,52 +100,5 @@
86 100 * @bool $is_cache True if a known cache plugin is active
87 101 * incl. WP Fastest Cache which doesn't use WP_CACHE
88 102 */
89 103 return apply_filters( 'pll_is_cache_active', ( defined( 'WP_CACHE' ) && WP_CACHE ) || defined( 'WPFC_MAIN_PATH' ) );
90 -}
91 -
92 -/**
93 - * Get the the current requested url
94 - *
95 - * @since 2.6
96 - *
97 - * @return string Requested url
98 - */
99 -function pll_get_requested_url() {
100 - if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
101 - return set_url_scheme( esc_url_raw( wp_unslash( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) ) );
102 - }
103 -
104 - /*
105 - * In WP CLI context, few developers define superglobals in wp-config.php
106 - * as proposed in https://make.wordpress.org/cli/handbook/common-issues/#php-notice-undefined-index-on-_server-superglobal
107 - * So let's return the unfiltered home url to avoid a bunch of notices.
108 - */
109 - if ( defined( 'WP_CLI' ) && WP_CLI ) {
110 - return get_option( 'home' );
111 - }
112 -
113 - if ( WP_DEBUG ) {
114 - // phpcs:ignore WordPress.PHP.DevelopmentFunctions
115 - trigger_error( '$_SERVER[\'HTTP_HOST\'] or $_SERVER[\'REQUEST_URI\'] are required but not set.' );
116 - }
117 -
118 - return '';
119 -}
120 -
121 -/**
122 - * Determines whether we should load the block editor plugin or the legacy languages metabox.
123 - *
124 - * @since 2.6.0
125 - *
126 - * return bool True to use the block editor plugin.
127 - */
128 -function pll_use_block_editor_plugin() {
129 - /**
130 - * Filters whether we should load the block editor plugin or the legacy languages metabox.
131 - *
132 - * @since 2.6.0
133 - *
134 - * @param bool $use_plugin True when loading the block editor plugin.
135 - */
136 - return class_exists( 'PLL_Block_Editor_Plugin' ) && apply_filters( 'pll_use_block_editor_plugin', ! defined( 'PLL_USE_BLOCK_EDITOR_PLUGIN' ) || PLL_USE_BLOCK_EDITOR_PLUGIN );
137 104 }