PluginProbe
Polylang / 3.4.2
Polylang v3.4.2
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 3.4.2, at include/functions.php

94 lines 3.0 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_path' ) ) {
13 /**
14 * Retrieves a page given its path.
15 *
16 * @since 2.8.3
17 *
18 * @param string $page_path Page path.
19 * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
20 * a WP_Post object, an associative array, or a numeric array, respectively. Default OBJECT.
21 * @param string|array $post_type Optional. Post type or array of post types. Default 'page'.
22 * @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
23 */
24 function wpcom_vip_get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {
25 return get_page_by_path( $page_path, $output, $post_type ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.get_page_by_path_get_page_by_path
26 }
27 }
28
29 /**
30 * Determines whether we should load the cache compatibility
31 *
32 * @since 2.3.8
33 *
34 * @return bool True if the cache compatibility must be loaded
35 */
36 function pll_is_cache_active() {
37 /**
38 * Filters whether we should load the cache compatibility
39 *
40 * @since 2.3.8
41 *
42 * @bool $is_cache True if a known cache plugin is active
43 * incl. WP Fastest Cache which doesn't use WP_CACHE
44 */
45 return apply_filters( 'pll_is_cache_active', ( defined( 'WP_CACHE' ) && WP_CACHE ) || defined( 'WPFC_MAIN_PATH' ) );
46 }
47
48 /**
49 * Get the the current requested url
50 *
51 * @since 2.6
52 *
53 * @return string Requested url
54 */
55 function pll_get_requested_url() {
56 if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
57 return set_url_scheme( esc_url_raw( wp_unslash( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) ) );
58 }
59
60 /*
61 * In WP CLI context, few developers define superglobals in wp-config.php
62 * as proposed in https://make.wordpress.org/cli/handbook/common-issues/#php-notice-undefined-index-on-_server-superglobal
63 * So let's return the unfiltered home url to avoid a bunch of notices.
64 */
65 if ( defined( 'WP_CLI' ) && WP_CLI ) {
66 return get_option( 'home' );
67 }
68
69 if ( WP_DEBUG ) {
70 // phpcs:ignore WordPress.PHP.DevelopmentFunctions
71 trigger_error( '$_SERVER[\'HTTP_HOST\'] or $_SERVER[\'REQUEST_URI\'] are required but not set.' );
72 }
73
74 return '';
75 }
76
77 /**
78 * Determines whether we should load the block editor plugin or the legacy languages metabox.
79 *
80 * @since 2.6.0
81 *
82 * @return bool True to use the block editor plugin.
83 */
84 function pll_use_block_editor_plugin() {
85 /**
86 * Filters whether we should load the block editor plugin or the legacy languages metabox.
87 *
88 * @since 2.6.0
89 *
90 * @param bool $use_plugin True when loading the block editor plugin.
91 */
92 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 );
93 }
94