PluginProbe
Polylang / 2.6.3
Polylang v2.6.3
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
polylang / include / functions.php

functions.php in Polylang 2.6.3, at include/functions.php

173 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Define wordpress.com VIP equivalent of uncached functions
5 * WordPress backward compatibility functions
6 * and miscellaneous utility functions
7 */
8
9 if ( ! function_exists( 'wpcom_vip_get_page_by_title' ) ) {
10 /**
11 * Retrieve a page given its title.
12 *
13 * @since 2.0
14 *
15 * @param string $page_title Page title
16 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N. Default OBJECT
17 * @param string|array $post_type Optional. Post type or array of post types. Default 'page'.
18 * @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
19 */
20 function wpcom_vip_get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
21 return get_page_by_title( $page_title, $output, $post_type );
22 }
23 }
24
25 if ( ! function_exists( 'wpcom_vip_get_category_by_slug' ) ) {
26 /**
27 * Retrieve category object by category slug.
28 *
29 * @since 2.0
30 *
31 * @param string $slug The category slug.
32 * @return object Category data object
33 */
34 function wpcom_vip_get_category_by_slug( $slug ) {
35 return get_category_by_slug( $slug );
36 }
37 }
38
39 if ( ! function_exists( 'wpcom_vip_get_term_by' ) ) {
40 /**
41 * Get all Term data from database by Term field and data.
42 *
43 * @since 2.0
44 *
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 */
52 function wpcom_vip_get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) {
53 return get_term_by( $field, $value, $taxonomy, $output, $filter );
54 }
55 }
56
57 if ( ! function_exists( 'wpcom_vip_get_term_link' ) ) {
58 /**
59 * Generate a permalink for a taxonomy term archive.
60 *
61 * @since 2.0
62 *
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 */
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() {
82 /** This filter is documented in wp-includes/load.php */
83 return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX );
84 }
85 }
86
87 if ( ! function_exists( 'wp_doing_cron' ) ) {
88 /**
89 * Determines whether the current request is a WordPress cron request.
90 * Backward compatibility function for WP < 4.8
91 *
92 * @since 2.6
93 *
94 * @return bool True if it's a WordPress cron request, false otherwise.
95 */
96 function wp_doing_cron() {
97 /** This filter is documented in wp-includes/load.php */
98 return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON );
99 }
100 }
101
102 if ( ! function_exists( 'wp_using_themes' ) ) {
103 /**
104 * Determines whether the current request should use themes.
105 * Backward compatibility function for WP < 5.1
106 *
107 * @since 2.6
108 *
109 * @return bool True if themes should be used, false otherwise.
110 */
111 function wp_using_themes() {
112 /** This filter is documented in wp-includes/load.php */
113 return apply_filters( 'wp_using_themes', defined( 'WP_USE_THEMES' ) && WP_USE_THEMES );
114 }
115 }
116
117 /**
118 * Determines whether we should load the cache compatibility
119 *
120 * @since 2.3.8
121 *
122 * return bool True if the cache compatibility must be loaded
123 */
124 function pll_is_cache_active() {
125 /**
126 * Filters whether we should load the cache compatibility
127 *
128 * @since 2.3.8
129 *
130 * @bool $is_cache True if a known cache plugin is active
131 * incl. WP Fastest Cache which doesn't use WP_CACHE
132 */
133 return apply_filters( 'pll_is_cache_active', ( defined( 'WP_CACHE' ) && WP_CACHE ) || defined( 'WPFC_MAIN_PATH' ) );
134 }
135
136 /**
137 * Get the the current requested url
138 *
139 * @since 2.6
140 *
141 * @return string Requested url
142 */
143 function pll_get_requested_url() {
144 if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
145 return set_url_scheme( esc_url_raw( wp_unslash( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) ) );
146 }
147
148 if ( WP_DEBUG ) {
149 // phpcs:ignore WordPress.PHP.DevelopmentFunctions
150 trigger_error( '$_SERVER[\'HTTP_HOST\'] or $_SERVER[\'REQUEST_URI\'] are required but not set.' );
151 }
152
153 return '';
154 }
155
156 /**
157 * Determines whether we should load the block editor plugin or the legacy languages metabox.
158 *
159 * @since 2.6.0
160 *
161 * return bool True to use the block editor plugin.
162 */
163 function pll_use_block_editor_plugin() {
164 /**
165 * Filters whether we should load the block editor plugin or the legacy languages metabox.
166 *
167 * @since 2.6.0
168 *
169 * @param bool $use_plugin True when loading the block editor plugin.
170 */
171 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 );
172 }
173