| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * Define wordpress.com VIP equivalent of uncached functions |
| 8 | 5 | * WordPress backward compatibility functions |
| @@ -20,29 +17,104 @@ | ||
| 20 | 17 | * @param string|array $post_type Optional. Post type or array of post types. Default 'page'. |
| 21 | 18 | * @return WP_Post|array|null WP_Post (or array) on success, or null on failure. |
| 22 | 19 | */ |
| 23 | 20 | 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 | |
| 21 | + return get_page_by_title( $page_title, $output, $post_type ); | |
| 25 | 22 | } |
| 26 | 23 | } |
| 27 | 24 | |
| 28 | -if ( ! function_exists( 'wpcom_vip_get_page_by_path' ) ) { | |
| 25 | +if ( ! function_exists( 'wpcom_vip_get_category_by_slug' ) ) { | |
| 29 | 26 | /** |
| 30 | - * Retrieves a page given its path. | |
| 27 | + * Retrieve category object by category slug. | |
| 31 | 28 | * |
| 32 | - * @since 2.8.3 | |
| 29 | + * @since 2.0 | |
| 33 | 30 | * |
| 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. | |
| 31 | + * @param string $slug The category slug. | |
| 32 | + * @return object Category data object | |
| 39 | 33 | */ |
| 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 | |
| 34 | + function wpcom_vip_get_category_by_slug( $slug ) { | |
| 35 | + return get_category_by_slug( $slug ); | |
| 42 | 36 | } |
| 43 | 37 | } |
| 44 | 38 | |
| 39 | +if ( ! function_exists( 'wpcom_vip_get_term_by' ) ) { | |
| 40 | + /** | |
| 41 | + * Get all Term data from database by Term field and data. | |
| 42 | + * | |
| 43 | + * @since 2.0 | |
| 44 | + * | |
| 45 | + * @param string $field Either 'slug', 'name', 'id' (term_id), or 'term_taxonomy_id' | |
| 46 | + * @param string|int $value Search for this term value | |
| 47 | + * @param string $taxonomy Taxonomy name. Optional, if `$field` is 'term_taxonomy_id'. | |
| 48 | + * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N. Default OBJECT. | |
| 49 | + * @param string $filter Optional, default is raw or no WordPress defined filter will applied. | |
| 50 | + * @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. | |
| 51 | + */ | |
| 52 | + function wpcom_vip_get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) { | |
| 53 | + return get_term_by( $field, $value, $taxonomy, $output, $filter ); | |
| 54 | + } | |
| 55 | +} | |
| 56 | + | |
| 57 | +if ( ! function_exists( 'wpcom_vip_get_term_link' ) ) { | |
| 58 | + /** | |
| 59 | + * Generate a permalink for a taxonomy term archive. | |
| 60 | + * | |
| 61 | + * @since 2.0 | |
| 62 | + * | |
| 63 | + * @param object|int|string $term The term object, ID, or slug whose link will be retrieved. | |
| 64 | + * @param string $taxonomy Optional. Taxonomy. Default empty. | |
| 65 | + * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist. | |
| 66 | + */ | |
| 67 | + function wpcom_vip_get_term_link( $term, $taxonomy = '' ) { | |
| 68 | + return get_term_link( $term, $taxonomy ); | |
| 69 | + } | |
| 70 | +} | |
| 71 | + | |
| 72 | +if ( ! function_exists( 'wp_doing_ajax' ) ) { | |
| 73 | + /** | |
| 74 | + * Determines whether the current request is a WordPress Ajax request. | |
| 75 | + * Backward compatibility function for WP < 4.7 | |
| 76 | + * | |
| 77 | + * @since 2.2 | |
| 78 | + * | |
| 79 | + * @return bool True if it's a WordPress Ajax request, false otherwise. | |
| 80 | + */ | |
| 81 | + function wp_doing_ajax() { | |
| 82 | + /** This filter is documented in wp-includes/load.php */ | |
| 83 | + return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ); | |
| 84 | + } | |
| 85 | +} | |
| 86 | + | |
| 87 | +if ( ! function_exists( 'wp_doing_cron' ) ) { | |
| 88 | + /** | |
| 89 | + * Determines whether the current request is a WordPress cron request. | |
| 90 | + * Backward compatibility function for WP < 4.8 | |
| 91 | + * | |
| 92 | + * @since 2.6 | |
| 93 | + * | |
| 94 | + * @return bool True if it's a WordPress cron request, false otherwise. | |
| 95 | + */ | |
| 96 | + function wp_doing_cron() { | |
| 97 | + /** This filter is documented in wp-includes/load.php */ | |
| 98 | + return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON ); | |
| 99 | + } | |
| 100 | +} | |
| 101 | + | |
| 102 | +if ( ! function_exists( 'wp_using_themes' ) ) { | |
| 103 | + /** | |
| 104 | + * Determines whether the current request should use themes. | |
| 105 | + * Backward compatibility function for WP < 5.1 | |
| 106 | + * | |
| 107 | + * @since 2.6 | |
| 108 | + * | |
| 109 | + * @return bool True if themes should be used, false otherwise. | |
| 110 | + */ | |
| 111 | + function wp_using_themes() { | |
| 112 | + /** This filter is documented in wp-includes/load.php */ | |
| 113 | + return apply_filters( 'wp_using_themes', defined( 'WP_USE_THEMES' ) && WP_USE_THEMES ); | |
| 114 | + } | |
| 115 | +} | |
| 116 | + | |
| 45 | 117 | /** |
| 46 | 118 | * Determines whether we should load the cache compatibility |
| 47 | 119 | * |
| 48 | 120 | * @since 2.3.8 |
| @@ -70,17 +142,8 @@ | ||
| 70 | 142 | */ |
| 71 | 143 | function pll_get_requested_url() { |
| 72 | 144 | if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) { |
| 73 | 145 | 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 | 146 | } |
| 84 | 147 | |
| 85 | 148 | if ( WP_DEBUG ) { |
| 86 | 149 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions |