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