| @@ -17,54 +17,71 @@ | ||
| 17 | 17 | * @param string|array $post_type Optional. Post type or array of post types. Default 'page'. |
| 18 | 18 | * @return WP_Post|array|null WP_Post (or array) on success, or null on failure. |
| 19 | 19 | */ |
| 20 | 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 | |
| 21 | + return get_page_by_title( $page_title, $output, $post_type ); | |
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -if ( ! function_exists( 'wp_doing_ajax' ) ) { | |
| 25 | +if ( ! function_exists( 'wpcom_vip_get_category_by_slug' ) ) { | |
| 26 | 26 | /** |
| 27 | - * Determines whether the current request is a WordPress Ajax request. | |
| 28 | - * Backward compatibility function for WP < 4.7 | |
| 27 | + * Retrieve category object by category slug. | |
| 29 | 28 | * |
| 30 | - * @since 2.2 | |
| 29 | + * @since 2.0 | |
| 31 | 30 | * |
| 32 | - * @return bool True if it's a WordPress Ajax request, false otherwise. | |
| 31 | + * @param string $slug The category slug. | |
| 32 | + * @return object Category data object | |
| 33 | 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 ); | |
| 34 | + function wpcom_vip_get_category_by_slug( $slug ) { | |
| 35 | + return get_category_by_slug( $slug ); | |
| 37 | 36 | } |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | -if ( ! function_exists( 'wp_doing_cron' ) ) { | |
| 39 | +if ( ! function_exists( 'wpcom_vip_get_term_by' ) ) { | |
| 41 | 40 | /** |
| 42 | - * Determines whether the current request is a WordPress cron request. | |
| 43 | - * Backward compatibility function for WP < 4.8 | |
| 41 | + * Get all Term data from database by Term field and data. | |
| 44 | 42 | * |
| 45 | - * @since 2.6 | |
| 43 | + * @since 2.0 | |
| 46 | 44 | * |
| 47 | - * @return bool True if it's a WordPress cron request, false otherwise. | |
| 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. | |
| 48 | 51 | */ |
| 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 | + function wpcom_vip_get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) { | |
| 53 | + return get_term_by( $field, $value, $taxonomy, $output, $filter ); | |
| 52 | 54 | } |
| 53 | 55 | } |
| 54 | 56 | |
| 55 | -if ( ! function_exists( 'wp_using_themes' ) ) { | |
| 57 | +if ( ! function_exists( 'wpcom_vip_get_term_link' ) ) { | |
| 56 | 58 | /** |
| 57 | - * Determines whether the current request should use themes. | |
| 58 | - * Backward compatibility function for WP < 5.1 | |
| 59 | + * Generate a permalink for a taxonomy term archive. | |
| 59 | 60 | * |
| 60 | - * @since 2.6 | |
| 61 | + * @since 2.0 | |
| 61 | 62 | * |
| 62 | - * @return bool True if themes should be used, false otherwise. | |
| 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. | |
| 63 | 66 | */ |
| 64 | - function wp_using_themes() { | |
| 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() { | |
| 65 | 82 | /** This filter is documented in wp-includes/load.php */ |
| 66 | - return apply_filters( 'wp_using_themes', defined( 'WP_USE_THEMES' ) && WP_USE_THEMES ); | |
| 83 | + return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ); | |
| 67 | 84 | } |
| 68 | 85 | } |
| 69 | 86 | |
| 70 | 87 | /** |
| @@ -83,52 +100,5 @@ | ||
| 83 | 100 | * @bool $is_cache True if a known cache plugin is active |
| 84 | 101 | * incl. WP Fastest Cache which doesn't use WP_CACHE |
| 85 | 102 | */ |
| 86 | 103 | 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 | 104 | } |