| @@ -1,10 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | 4 | * Define wordpress.com VIP equivalent of uncached functions |
| 5 | - * WordPress backward compatibility functions | |
| 6 | - * and miscellaneous utility functions | |
| 5 | + * and WordPress backward compatibility functions | |
| 7 | 6 | */ |
| 8 | 7 | |
| 9 | 8 | if ( ! function_exists( 'wpcom_vip_get_page_by_title' ) ) { |
| 10 | 9 | /** |
| @@ -17,118 +16,69 @@ | ||
| 17 | 16 | * @param string|array $post_type Optional. Post type or array of post types. Default 'page'. |
| 18 | 17 | * @return WP_Post|array|null WP_Post (or array) on success, or null on failure. |
| 19 | 18 | */ |
| 20 | 19 | 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 | |
| 20 | + return get_page_by_title( $page_title, $output, $post_type ); | |
| 22 | 21 | } |
| 23 | 22 | } |
| 24 | 23 | |
| 25 | -if ( ! function_exists( 'wp_doing_ajax' ) ) { | |
| 24 | +if ( ! function_exists( 'wpcom_vip_get_category_by_slug' ) ) { | |
| 26 | 25 | /** |
| 27 | - * Determines whether the current request is a WordPress Ajax request. | |
| 28 | - * Backward compatibility function for WP < 4.7 | |
| 26 | + * Retrieve category object by category slug. | |
| 29 | 27 | * |
| 30 | - * @since 2.2 | |
| 28 | + * @since 2.0 | |
| 31 | 29 | * |
| 32 | - * @return bool True if it's a WordPress Ajax request, false otherwise. | |
| 30 | + * @param string $slug The category slug. | |
| 31 | + * @return object Category data object | |
| 33 | 32 | */ |
| 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 ); | |
| 33 | + function wpcom_vip_get_category_by_slug( $slug ) { | |
| 34 | + return get_category_by_slug( $slug ); | |
| 37 | 35 | } |
| 38 | 36 | } |
| 39 | 37 | |
| 40 | -if ( ! function_exists( 'wp_doing_cron' ) ) { | |
| 38 | +if ( ! function_exists( 'wpcom_vip_get_term_by' ) ) { | |
| 41 | 39 | /** |
| 42 | - * Determines whether the current request is a WordPress cron request. | |
| 43 | - * Backward compatibility function for WP < 4.8 | |
| 40 | + * Get all Term data from database by Term field and data. | |
| 44 | 41 | * |
| 45 | - * @since 2.6 | |
| 42 | + * @since 2.0 | |
| 46 | 43 | * |
| 47 | - * @return bool True if it's a WordPress cron request, false otherwise. | |
| 44 | + * @param string $field Either 'slug', 'name', 'id' (term_id), or 'term_taxonomy_id' | |
| 45 | + * @param string|int $value Search for this term value | |
| 46 | + * @param string $taxonomy Taxonomy name. Optional, if `$field` is 'term_taxonomy_id'. | |
| 47 | + * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N. Default OBJECT. | |
| 48 | + * @param string $filter Optional, default is raw or no WordPress defined filter will applied. | |
| 49 | + * @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. | |
| 48 | 50 | */ |
| 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 ); | |
| 51 | + function wpcom_vip_get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) { | |
| 52 | + return get_term_by( $field, $value, $taxonomy, $output, $filter ); | |
| 52 | 53 | } |
| 53 | 54 | } |
| 54 | 55 | |
| 55 | -if ( ! function_exists( 'wp_using_themes' ) ) { | |
| 56 | +if ( ! function_exists( 'wpcom_vip_get_term_link' ) ) { | |
| 56 | 57 | /** |
| 57 | - * Determines whether the current request should use themes. | |
| 58 | - * Backward compatibility function for WP < 5.1 | |
| 58 | + * Generate a permalink for a taxonomy term archive. | |
| 59 | 59 | * |
| 60 | - * @since 2.6 | |
| 60 | + * @since 2.0 | |
| 61 | 61 | * |
| 62 | - * @return bool True if themes should be used, false otherwise. | |
| 62 | + * @param object|int|string $term The term object, ID, or slug whose link will be retrieved. | |
| 63 | + * @param string $taxonomy Optional. Taxonomy. Default empty. | |
| 64 | + * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist. | |
| 63 | 65 | */ |
| 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 ); | |
| 66 | + function wpcom_vip_get_term_link( $term, $taxonomy = '' ) { | |
| 67 | + return get_term_link( $term, $taxonomy ); | |
| 67 | 68 | } |
| 68 | 69 | } |
| 69 | 70 | |
| 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() { | |
| 71 | +if ( ! function_exists( 'wp_doing_ajax' ) ) { | |
| 78 | 72 | /** |
| 79 | - * Filters whether we should load the cache compatibility | |
| 73 | + * Determines whether the current request is a WordPress Ajax request. | |
| 74 | + * Backward compatibility function for WP < 4.7 | |
| 80 | 75 | * |
| 81 | - * @since 2.3.8 | |
| 76 | + * @since 2.2 | |
| 82 | 77 | * |
| 83 | - * @bool $is_cache True if a known cache plugin is active | |
| 84 | - * incl. WP Fastest Cache which doesn't use WP_CACHE | |
| 78 | + * @return bool True if it's a WordPress Ajax request, false otherwise. | |
| 85 | 79 | */ |
| 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'] ) ) ); | |
| 80 | + function wp_doing_ajax() { | |
| 81 | + /** This filter is documented in wp-includes/load.php */ | |
| 82 | + return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ); | |
| 99 | 83 | } |
| 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 | 84 | } |