| 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 ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.get_page_by_title_get_page_by_title |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
if ( ! function_exists( 'wp_doing_ajax' ) ) { |
| 26 |
/** |
| 27 |
* Determines whether the current request is a WordPress Ajax request. |
| 28 |
* Backward compatibility function for WP < 4.7 |
| 29 |
* |
| 30 |
* @since 2.2 |
| 31 |
* |
| 32 |
* @return bool True if it's a WordPress Ajax request, false otherwise. |
| 33 |
*/ |
| 34 |
function wp_doing_ajax() { |
| 35 |
/** This filter is documented in wp-includes/load.php */ |
| 36 |
return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
if ( ! function_exists( 'wp_doing_cron' ) ) { |
| 41 |
/** |
| 42 |
* Determines whether the current request is a WordPress cron request. |
| 43 |
* Backward compatibility function for WP < 4.8 |
| 44 |
* |
| 45 |
* @since 2.6 |
| 46 |
* |
| 47 |
* @return bool True if it's a WordPress cron request, false otherwise. |
| 48 |
*/ |
| 49 |
function wp_doing_cron() { |
| 50 |
/** This filter is documented in wp-includes/load.php */ |
| 51 |
return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON ); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
if ( ! function_exists( 'wp_using_themes' ) ) { |
| 56 |
/** |
| 57 |
* Determines whether the current request should use themes. |
| 58 |
* Backward compatibility function for WP < 5.1 |
| 59 |
* |
| 60 |
* @since 2.6 |
| 61 |
* |
| 62 |
* @return bool True if themes should be used, false otherwise. |
| 63 |
*/ |
| 64 |
function wp_using_themes() { |
| 65 |
/** This filter is documented in wp-includes/load.php */ |
| 66 |
return apply_filters( 'wp_using_themes', defined( 'WP_USE_THEMES' ) && WP_USE_THEMES ); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Determines whether we should load the cache compatibility |
| 72 |
* |
| 73 |
* @since 2.3.8 |
| 74 |
* |
| 75 |
* return bool True if the cache compatibility must be loaded |
| 76 |
*/ |
| 77 |
function pll_is_cache_active() { |
| 78 |
/** |
| 79 |
* Filters whether we should load the cache compatibility |
| 80 |
* |
| 81 |
* @since 2.3.8 |
| 82 |
* |
| 83 |
* @bool $is_cache True if a known cache plugin is active |
| 84 |
* incl. WP Fastest Cache which doesn't use WP_CACHE |
| 85 |
*/ |
| 86 |
return apply_filters( 'pll_is_cache_active', ( defined( 'WP_CACHE' ) && WP_CACHE ) || defined( 'WPFC_MAIN_PATH' ) ); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Get the the current requested url |
| 91 |
* |
| 92 |
* @since 2.6 |
| 93 |
* |
| 94 |
* @return string Requested url |
| 95 |
*/ |
| 96 |
function pll_get_requested_url() { |
| 97 |
if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) { |
| 98 |
return set_url_scheme( esc_url_raw( wp_unslash( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) ) ); |
| 99 |
} |
| 100 |
|
| 101 |
/* |
| 102 |
* In WP CLI context, few developers define superglobals in wp-config.php |
| 103 |
* as proposed in https://make.wordpress.org/cli/handbook/common-issues/#php-notice-undefined-index-on-_server-superglobal |
| 104 |
* So let's return the unfiltered home url to avoid a bunch of notices. |
| 105 |
*/ |
| 106 |
if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 107 |
return get_option( 'home' ); |
| 108 |
} |
| 109 |
|
| 110 |
if ( WP_DEBUG ) { |
| 111 |
// phpcs:ignore WordPress.PHP.DevelopmentFunctions |
| 112 |
trigger_error( '$_SERVER[\'HTTP_HOST\'] or $_SERVER[\'REQUEST_URI\'] are required but not set.' ); |
| 113 |
} |
| 114 |
|
| 115 |
return ''; |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Determines whether we should load the block editor plugin or the legacy languages metabox. |
| 120 |
* |
| 121 |
* @since 2.6.0 |
| 122 |
* |
| 123 |
* return bool True to use the block editor plugin. |
| 124 |
*/ |
| 125 |
function pll_use_block_editor_plugin() { |
| 126 |
/** |
| 127 |
* Filters whether we should load the block editor plugin or the legacy languages metabox. |
| 128 |
* |
| 129 |
* @since 2.6.0 |
| 130 |
* |
| 131 |
* @param bool $use_plugin True when loading the block editor plugin. |
| 132 |
*/ |
| 133 |
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 ); |
| 134 |
} |
| 135 |
|