PluginProbe
Polylang / 2.8
Polylang v2.8
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.8, at include/functions.php

138 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Polylang
4 */
5
6 /**
7 * Define wordpress.com VIP equivalent of uncached functions
8 * WordPress backward compatibility functions
9 * and miscellaneous utility functions
10 */
11
12 if ( ! function_exists( 'wpcom_vip_get_page_by_title' ) ) {
13 /**
14 * Retrieve a page given its title.
15 *
16 * @since 2.0
17 *
18 * @param string $page_title Page title
19 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N. Default OBJECT
20 * @param string|array $post_type Optional. Post type or array of post types. Default 'page'.
21 * @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
22 */
23 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
25 }
26 }
27
28 if ( ! function_exists( 'wp_doing_ajax' ) ) {
29 /**
30 * Determines whether the current request is a WordPress Ajax request.
31 * Backward compatibility function for WP < 4.7
32 *
33 * @since 2.2
34 *
35 * @return bool True if it's a WordPress Ajax request, false otherwise.
36 */
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 );
40 }
41 }
42
43 if ( ! function_exists( 'wp_doing_cron' ) ) {
44 /**
45 * Determines whether the current request is a WordPress cron request.
46 * Backward compatibility function for WP < 4.8
47 *
48 * @since 2.6
49 *
50 * @return bool True if it's a WordPress cron request, false otherwise.
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 );
55 }
56 }
57
58 if ( ! function_exists( 'wp_using_themes' ) ) {
59 /**
60 * Determines whether the current request should use themes.
61 * Backward compatibility function for WP < 5.1
62 *
63 * @since 2.6
64 *
65 * @return bool True if themes should be used, false otherwise.
66 */
67 function wp_using_themes() {
68 /** This filter is documented in wp-includes/load.php */
69 return apply_filters( 'wp_using_themes', defined( 'WP_USE_THEMES' ) && WP_USE_THEMES );
70 }
71 }
72
73 /**
74 * Determines whether we should load the cache compatibility
75 *
76 * @since 2.3.8
77 *
78 * return bool True if the cache compatibility must be loaded
79 */
80 function pll_is_cache_active() {
81 /**
82 * Filters whether we should load the cache compatibility
83 *
84 * @since 2.3.8
85 *
86 * @bool $is_cache True if a known cache plugin is active
87 * incl. WP Fastest Cache which doesn't use WP_CACHE
88 */
89 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 }
138