PluginProbe
Polylang / 2.4
Polylang v2.4
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / include / functions.php

functions.php in Polylang 2.4, at include/functions.php

105 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 );
22 }
23 }
24
25 if ( ! function_exists( 'wpcom_vip_get_category_by_slug' ) ) {
26 /**
27 * Retrieve category object by category slug.
28 *
29 * @since 2.0
30 *
31 * @param string $slug The category slug.
32 * @return object Category data object
33 */
34 function wpcom_vip_get_category_by_slug( $slug ) {
35 return get_category_by_slug( $slug );
36 }
37 }
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 /**
88 * Determines whether we should load the cache compatibility
89 *
90 * @since 2.3.8
91 *
92 * return bool True if the cache compatibility must be loaded
93 */
94 function pll_is_cache_active() {
95 /**
96 * Filters whether we should load the cache compatibility
97 *
98 * @since 2.3.8
99 *
100 * @bool $is_cache True if a known cache plugin is active
101 * incl. WP Fastest Cache which doesn't use WP_CACHE
102 */
103 return apply_filters( 'pll_is_cache_active', ( defined( 'WP_CACHE' ) && WP_CACHE ) || defined( 'WPFC_MAIN_PATH' ) );
104 }
105