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

110 lines 3.7 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( 'wpcom_vip_get_page_by_path' ) ) {
29 /**
30 * Retrieves a page given its path.
31 *
32 * @since 2.8.3
33 *
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.
39 */
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
42 }
43 }
44
45 /**
46 * Determines whether we should load the cache compatibility
47 *
48 * @since 2.3.8
49 *
50 * @return bool True if the cache compatibility must be loaded
51 */
52 function pll_is_cache_active() {
53 /**
54 * Filters whether we should load the cache compatibility
55 *
56 * @since 2.3.8
57 *
58 * @bool $is_cache True if a known cache plugin is active
59 * incl. WP Fastest Cache which doesn't use WP_CACHE
60 */
61 return apply_filters( 'pll_is_cache_active', ( defined( 'WP_CACHE' ) && WP_CACHE ) || defined( 'WPFC_MAIN_PATH' ) );
62 }
63
64 /**
65 * Get the the current requested url
66 *
67 * @since 2.6
68 *
69 * @return string Requested url
70 */
71 function pll_get_requested_url() {
72 if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
73 return set_url_scheme( esc_url_raw( wp_unslash( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) ) );
74 }
75
76 /*
77 * In WP CLI context, few developers define superglobals in wp-config.php
78 * as proposed in https://make.wordpress.org/cli/handbook/common-issues/#php-notice-undefined-index-on-_server-superglobal
79 * So let's return the unfiltered home url to avoid a bunch of notices.
80 */
81 if ( defined( 'WP_CLI' ) && WP_CLI ) {
82 return get_option( 'home' );
83 }
84
85 if ( WP_DEBUG ) {
86 // phpcs:ignore WordPress.PHP.DevelopmentFunctions
87 trigger_error( '$_SERVER[\'HTTP_HOST\'] or $_SERVER[\'REQUEST_URI\'] are required but not set.' );
88 }
89
90 return '';
91 }
92
93 /**
94 * Determines whether we should load the block editor plugin or the legacy languages metabox.
95 *
96 * @since 2.6.0
97 *
98 * @return bool True to use the block editor plugin.
99 */
100 function pll_use_block_editor_plugin() {
101 /**
102 * Filters whether we should load the block editor plugin or the legacy languages metabox.
103 *
104 * @since 2.6.0
105 *
106 * @param bool $use_plugin True when loading the block editor plugin.
107 */
108 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 );
109 }
110