| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Define wordpress.com VIP equivalent of uncached functions |
| 5 |
* and WordPress backward compatibility functions |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! function_exists( 'wpcom_vip_get_page_by_title' ) ) { |
| 9 |
/** |
| 10 |
* Retrieve a page given its title. |
| 11 |
* |
| 12 |
* @since 2.0 |
| 13 |
* |
| 14 |
* @param string $page_title Page title |
| 15 |
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N. Default OBJECT |
| 16 |
* @param string|array $post_type Optional. Post type or array of post types. Default 'page'. |
| 17 |
* @return WP_Post|array|null WP_Post (or array) on success, or null on failure. |
| 18 |
*/ |
| 19 |
function wpcom_vip_get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) { |
| 20 |
return get_page_by_title( $page_title, $output, $post_type ); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
if ( ! function_exists( 'wpcom_vip_get_category_by_slug' ) ) { |
| 25 |
/** |
| 26 |
* Retrieve category object by category slug. |
| 27 |
* |
| 28 |
* @since 2.0 |
| 29 |
* |
| 30 |
* @param string $slug The category slug. |
| 31 |
* @return object Category data object |
| 32 |
*/ |
| 33 |
function wpcom_vip_get_category_by_slug( $slug ) { |
| 34 |
return get_category_by_slug( $slug ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
if ( ! function_exists( 'wpcom_vip_get_term_by' ) ) { |
| 39 |
/** |
| 40 |
* Get all Term data from database by Term field and data. |
| 41 |
* |
| 42 |
* @since 2.0 |
| 43 |
* |
| 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. |
| 50 |
*/ |
| 51 |
function wpcom_vip_get_term_by( $field, $value, $taxonomy = '', $output = OBJECT, $filter = 'raw' ) { |
| 52 |
return get_term_by( $field, $value, $taxonomy, $output, $filter ); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
if ( ! function_exists( 'wpcom_vip_get_term_link' ) ) { |
| 57 |
/** |
| 58 |
* Generate a permalink for a taxonomy term archive. |
| 59 |
* |
| 60 |
* @since 2.0 |
| 61 |
* |
| 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. |
| 65 |
*/ |
| 66 |
function wpcom_vip_get_term_link( $term, $taxonomy = '' ) { |
| 67 |
return get_term_link( $term, $taxonomy ); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
if ( ! function_exists( 'wp_doing_ajax' ) ) { |
| 72 |
/** |
| 73 |
* Determines whether the current request is a WordPress Ajax request. |
| 74 |
* Backward compatibility function for WP < 4.7 |
| 75 |
* |
| 76 |
* @since 2.2 |
| 77 |
* |
| 78 |
* @return bool True if it's a WordPress Ajax request, false otherwise. |
| 79 |
*/ |
| 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 ); |
| 83 |
} |
| 84 |
} |
| 85 |
|