| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * Setups the language and translations model based on WordPress taxonomies |
| 8 | 5 | * |
| @@ -8,11 +5,11 @@ | ||
| 8 | 5 | * |
| 9 | 6 | * @since 1.2 |
| 10 | 7 | */ |
| 11 | 8 | class PLL_Model { |
| 12 | - public $cache; // Our internal non persistent cache object | |
| 9 | + public $cache; // our internal non persistent cache object | |
| 13 | 10 | public $options; |
| 14 | - public $post, $term; // Translated objects models | |
| 11 | + public $post, $term; // translated objects models | |
| 15 | 12 | |
| 16 | 13 | /** |
| 17 | 14 | * Constructor |
| 18 | 15 | * setups translated objects sub models |
| @@ -28,17 +25,15 @@ | ||
| 28 | 25 | $this->cache = new PLL_Cache(); |
| 29 | 26 | $this->post = new PLL_Translated_Post( $this ); // translated post sub model |
| 30 | 27 | $this->term = new PLL_Translated_Term( $this ); // translated term sub model |
| 31 | 28 | |
| 32 | - // We need to clean languages cache when editing a language and when modifying the permalink structure | |
| 29 | + // we need to clean languages cache when editing a language and when modifying the permalink structure | |
| 33 | 30 | add_action( 'edited_term_taxonomy', array( $this, 'clean_languages_cache' ), 10, 2 ); |
| 34 | 31 | add_action( 'update_option_permalink_structure', array( $this, 'clean_languages_cache' ) ); |
| 35 | 32 | add_action( 'update_option_siteurl', array( $this, 'clean_languages_cache' ) ); |
| 36 | 33 | add_action( 'update_option_home', array( $this, 'clean_languages_cache' ) ); |
| 37 | 34 | |
| 38 | - add_filter( 'get_terms_args', array( $this, 'get_terms_args' ) ); | |
| 39 | - | |
| 40 | - // Just in case someone would like to display the language description ;- ) | |
| 35 | + // just in case someone would like to display the language description ;- ) | |
| 41 | 36 | add_filter( 'language_description', '__return_empty_string' ); |
| 42 | 37 | } |
| 43 | 38 | |
| 44 | 39 | /** |
| @@ -45,9 +40,9 @@ | ||
| 45 | 40 | * Returns the list of available languages |
| 46 | 41 | * caches the list in a db transient ( except flags ), unless PLL_CACHE_LANGUAGES is set to false |
| 47 | 42 | * caches the list ( with flags ) in the private property $languages |
| 48 | 43 | * |
| 49 | - * List of parameters accepted in $args: | |
| 44 | + * list of parameters accepted in $args: | |
| 50 | 45 | * |
| 51 | 46 | * hide_empty => hides languages with no posts if set to true ( defaults to false ) |
| 52 | 47 | * fields => return only that field if set ( see PLL_Language for a list of fields ) |
| 53 | 48 | * |
| @@ -58,9 +53,9 @@ | ||
| 58 | 53 | */ |
| 59 | 54 | public function get_languages_list( $args = array() ) { |
| 60 | 55 | if ( false === $languages = $this->cache->get( 'languages' ) ) { |
| 61 | 56 | |
| 62 | - // Create the languages from taxonomies | |
| 57 | + // create the languages from taxonomies | |
| 63 | 58 | if ( ( defined( 'PLL_CACHE_LANGUAGES' ) && ! PLL_CACHE_LANGUAGES ) || false === ( $languages = get_transient( 'pll_languages_list' ) ) ) { |
| 64 | 59 | $languages = get_terms( 'language', array( 'hide_empty' => false, 'orderby' => 'term_group' ) ); |
| 65 | 60 | $languages = empty( $languages ) || is_wp_error( $languages ) ? array() : $languages; |
| 66 | 61 | |
| @@ -68,14 +63,14 @@ | ||
| 68 | 63 | $term_languages = empty( $term_languages ) || is_wp_error( $term_languages ) ? |
| 69 | 64 | array() : array_combine( wp_list_pluck( $term_languages, 'slug' ), $term_languages ); |
| 70 | 65 | |
| 71 | 66 | if ( ! empty( $languages ) && ! empty( $term_languages ) ) { |
| 72 | - // Don't use array_map + create_function to instantiate an autoloaded class as it breaks badly in old versions of PHP | |
| 67 | + // don't use array_map + create_function to instantiate an autoloaded class as it breaks badly in old versions of PHP | |
| 73 | 68 | foreach ( $languages as $k => $v ) { |
| 74 | 69 | $languages[ $k ] = new PLL_Language( $v, $term_languages[ 'pll_' . $v->slug ] ); |
| 75 | 70 | } |
| 76 | 71 | |
| 77 | - // We will need the languages list to allow its access in the filter below | |
| 72 | + // we will need the languages list to allow its access in the filter below | |
| 78 | 73 | $this->cache->set( 'languages', $languages ); |
| 79 | 74 | |
| 80 | 75 | /** |
| 81 | 76 | * Filter the list of languages *before* it is stored in the persistent cache |
| @@ -87,19 +82,19 @@ | ||
| 87 | 82 | * @param object $model PLL_Model object |
| 88 | 83 | */ |
| 89 | 84 | $languages = apply_filters( 'pll_languages_list', $languages, $this ); |
| 90 | 85 | |
| 91 | - // Don't store directly objects as it badly break with some hosts ( GoDaddy ) due to race conditions when using object cache | |
| 92 | - // Thanks to captin411 for catching this! | |
| 93 | - // See https://wordpress.org/support/topic/fatal-error-pll_model_languages_list?replies=8#post-6782255; | |
| 86 | + // don't store directly objects as it badly break with some hosts ( GoDaddy ) due to race conditions when using object cache | |
| 87 | + // thanks to captin411 for catching this! | |
| 88 | + // see https://wordpress.org/support/topic/fatal-error-pll_model_languages_list?replies=8#post-6782255; | |
| 94 | 89 | set_transient( 'pll_languages_list', array_map( 'get_object_vars', $languages ) ); |
| 95 | 90 | } |
| 96 | 91 | else { |
| 97 | - $languages = array(); // In case something went wrong | |
| 92 | + $languages = array(); // in case something went wrong | |
| 98 | 93 | } |
| 99 | 94 | } |
| 100 | 95 | |
| 101 | - // Create the languages directly from arrays stored in transients | |
| 96 | + // create the languages directly from arrays stored in transients | |
| 102 | 97 | else { |
| 103 | 98 | foreach ( $languages as $k => $v ) { |
| 104 | 99 | $languages[ $k ] = new PLL_Language( $v ); |
| 105 | 100 | } |
| @@ -118,9 +113,9 @@ | ||
| 118 | 113 | } |
| 119 | 114 | |
| 120 | 115 | $args = wp_parse_args( $args, array( 'hide_empty' => false ) ); |
| 121 | 116 | |
| 122 | - // Remove empty languages if requested | |
| 117 | + // remove empty languages if requested | |
| 123 | 118 | if ( $args['hide_empty'] ) { |
| 124 | 119 | $languages = wp_list_filter( $languages, array( 'count' => 0 ), 'NOT' ); |
| 125 | 120 | } |
| 126 | 121 | |
| @@ -137,8 +132,14 @@ | ||
| 137 | 132 | * @param int $term not used |
| 138 | 133 | * @param string $taxonomy taxonomy name |
| 139 | 134 | */ |
| 140 | 135 | public function clean_languages_cache( $term = 0, $taxonomy = null ) { |
| 136 | + // depending on WP version, the action is passed an object or a string | |
| 137 | + // backward compatibility with WP < 4.2 | |
| 138 | + if ( ! empty( $taxonomy ) && is_object( $taxonomy ) ) { | |
| 139 | + $taxonomy = $taxonomy->name; | |
| 140 | + } | |
| 141 | + | |
| 141 | 142 | if ( empty( $taxonomy ) || 'language' == $taxonomy ) { |
| 142 | 143 | delete_transient( 'pll_languages_list' ); |
| 143 | 144 | $this->cache->clean(); |
| 144 | 145 | } |
| @@ -144,28 +145,13 @@ | ||
| 144 | 145 | } |
| 145 | 146 | } |
| 146 | 147 | |
| 147 | 148 | /** |
| 148 | - * Don't query term metas when only our taxonomies are queried | |
| 149 | - * | |
| 150 | - * @since 2.3 | |
| 151 | - * | |
| 152 | - * @param array $args WP_Term_Query arguments | |
| 153 | - * @return array | |
| 154 | - */ | |
| 155 | - public function get_terms_args( $args ) { | |
| 156 | - if ( isset( $args['taxonomy'] ) && ! array_diff( (array) $args['taxonomy'], array( 'language', 'term_language', 'post_translations', 'term_translations' ) ) ) { | |
| 157 | - $args['update_term_meta_cache'] = false; | |
| 158 | - } | |
| 159 | - return $args; | |
| 160 | - } | |
| 161 | - | |
| 162 | - /** | |
| 163 | 149 | * Returns the language by its term_id, tl_term_id, slug or locale |
| 164 | 150 | * |
| 165 | 151 | * @since 0.1 |
| 166 | 152 | * |
| 167 | - * @param int|string $value term_id, tl_term_id, slug or locale of the queried language | |
| 153 | + * @param int|string term_id, tl_term_id, slug or locale of the queried language | |
| 168 | 154 | * @return object|bool PLL_Language object, false if no language found |
| 169 | 155 | */ |
| 170 | 156 | public function get_language( $value ) { |
| 171 | 157 | if ( is_object( $value ) ) { |
| @@ -177,9 +163,8 @@ | ||
| 177 | 163 | $this->cache->set( 'language:' . $lang->term_id, $lang ); |
| 178 | 164 | $this->cache->set( 'language:' . $lang->tl_term_id, $lang ); |
| 179 | 165 | $this->cache->set( 'language:' . $lang->slug, $lang ); |
| 180 | 166 | $this->cache->set( 'language:' . $lang->locale, $lang ); |
| 181 | - $this->cache->set( 'language:' . $lang->w3c, $lang ); | |
| 182 | 167 | } |
| 183 | 168 | $return = $this->cache->get( 'language:' . $value ); |
| 184 | 169 | } |
| 185 | 170 | |
| @@ -192,9 +177,9 @@ | ||
| 192 | 177 | * @since 1.2 |
| 193 | 178 | * |
| 194 | 179 | * @param array $clauses the list of sql clauses in terms query |
| 195 | 180 | * @param object $lang PLL_Language object |
| 196 | - * @return array modified list of clauses | |
| 181 | + * @return array modifed list of clauses | |
| 197 | 182 | */ |
| 198 | 183 | public function terms_clauses( $clauses, $lang ) { |
| 199 | 184 | if ( ! empty( $lang ) && false === strpos( $clauses['join'], 'pll_tr' ) ) { |
| 200 | 185 | $clauses['join'] .= $this->term->join_clause(); |
| @@ -214,9 +199,9 @@ | ||
| 214 | 199 | * @return array post type names for which Polylang manages languages and translations |
| 215 | 200 | */ |
| 216 | 201 | public function get_translated_post_types( $filter = true ) { |
| 217 | 202 | if ( false === $post_types = $this->cache->get( 'post_types' ) ) { |
| 218 | - $post_types = array( 'post' => 'post', 'page' => 'page', 'wp_block' => 'wp_block' ); | |
| 203 | + $post_types = array( 'post' => 'post', 'page' => 'page' ); | |
| 219 | 204 | |
| 220 | 205 | if ( ! empty( $this->options['media_support'] ) ) { |
| 221 | 206 | $post_types['attachment'] = 'attachment'; |
| 222 | 207 | } |
| @@ -221,9 +206,9 @@ | ||
| 221 | 206 | $post_types['attachment'] = 'attachment'; |
| 222 | 207 | } |
| 223 | 208 | |
| 224 | 209 | if ( ! empty( $this->options['post_types'] ) && is_array( $this->options['post_types'] ) ) { |
| 225 | - $post_types = array_merge( $post_types, array_combine( $this->options['post_types'], $this->options['post_types'] ) ); | |
| 210 | + $post_types = array_merge( $post_types, array_combine( $this->options['post_types'], $this->options['post_types'] ) ); | |
| 226 | 211 | } |
| 227 | 212 | |
| 228 | 213 | /** |
| 229 | 214 | * Filter the list of post types available for translation. |
| @@ -255,9 +240,9 @@ | ||
| 255 | 240 | * @return bool |
| 256 | 241 | */ |
| 257 | 242 | public function is_translated_post_type( $post_type ) { |
| 258 | 243 | $post_types = $this->get_translated_post_types( false ); |
| 259 | - return ( is_array( $post_type ) && array_intersect( $post_type, $post_types ) || in_array( $post_type, $post_types ) || 'any' === $post_type && ! empty( $post_types ) ); | |
| 244 | + return ( is_array( $post_type ) && array_intersect( $post_type, $post_types ) || in_array( $post_type, $post_types ) ); | |
| 260 | 245 | } |
| 261 | 246 | |
| 262 | 247 | /** |
| 263 | 248 | * Return taxonomies that need to be translated |
| @@ -263,9 +248,9 @@ | ||
| 263 | 248 | * Return taxonomies that need to be translated |
| 264 | 249 | * |
| 265 | 250 | * @since 1.2 |
| 266 | 251 | * |
| 267 | - * @param bool $filter true if we should return only valid registered taxonomies | |
| 252 | + * @param bool $filter true if we should return only valid registered taxonmies | |
| 268 | 253 | * @return array array of registered taxonomy names for which Polylang manages languages and translations |
| 269 | 254 | */ |
| 270 | 255 | public function get_translated_taxonomies( $filter = true ) { |
| 271 | 256 | if ( false === $taxonomies = $this->cache->get( 'taxonomies' ) ) { |
| @@ -308,8 +293,33 @@ | ||
| 308 | 293 | return ( is_array( $tax ) && array_intersect( $tax, $taxonomies ) || in_array( $tax, $taxonomies ) ); |
| 309 | 294 | } |
| 310 | 295 | |
| 311 | 296 | /** |
| 297 | + * Check if translated taxonomy is queried | |
| 298 | + * Compatible with nested queries introduced in WP 4.1 | |
| 299 | + * @see https://wordpress.org/support/topic/tax_query-bug | |
| 300 | + * | |
| 301 | + * @since 1.7 | |
| 302 | + * | |
| 303 | + * @param array $tax_queries | |
| 304 | + * @return bool | |
| 305 | + */ | |
| 306 | + public function have_translated_taxonomy( $tax_queries ) { | |
| 307 | + foreach ( $tax_queries as $tax_query ) { | |
| 308 | + if ( isset( $tax_query['taxonomy'] ) && $this->is_translated_taxonomy( $tax_query['taxonomy'] ) && ! ( isset( $tax_query['operator'] ) && 'NOT IN' === $tax_query['operator'] ) ) { | |
| 309 | + return true; | |
| 310 | + } | |
| 311 | + | |
| 312 | + // Nested queries | |
| 313 | + elseif ( is_array( $tax_query ) && $this->have_translated_taxonomy( $tax_query ) ) { | |
| 314 | + return true; | |
| 315 | + } | |
| 316 | + } | |
| 317 | + | |
| 318 | + return false; | |
| 319 | + } | |
| 320 | + | |
| 321 | + /** | |
| 312 | 322 | * Return taxonomies that need to be filtered ( post_format like ) |
| 313 | 323 | * |
| 314 | 324 | * @since 1.7 |
| 315 | 325 | * |
| @@ -381,9 +391,9 @@ | ||
| 381 | 391 | $lang = $this->get_language( $lang ); |
| 382 | 392 | |
| 383 | 393 | // create a new category |
| 384 | 394 | // FIXME this is translated in admin language when we would like it in $lang |
| 385 | - $cat_name = __( 'Uncategorized', 'polylang' ); | |
| 395 | + $cat_name = __( 'Uncategorized' ); | |
| 386 | 396 | $cat_slug = sanitize_title( $cat_name . '-' . $lang->slug ); |
| 387 | 397 | $cat = wp_insert_term( $cat_name, 'category', array( 'slug' => $cat_slug ) ); |
| 388 | 398 | |
| 389 | 399 | // check that the category was not previously created ( in case the language was deleted and recreated ) |
| @@ -423,9 +433,8 @@ | ||
| 423 | 433 | public function term_exists( $term_name, $taxonomy, $parent, $language ) { |
| 424 | 434 | global $wpdb; |
| 425 | 435 | |
| 426 | 436 | $term_name = trim( wp_unslash( $term_name ) ); |
| 427 | - $term_name = _wp_specialchars( $term_name ); | |
| 428 | 437 | |
| 429 | 438 | $select = "SELECT t.term_id FROM $wpdb->terms AS t"; |
| 430 | 439 | $join = " INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id"; |
| 431 | 440 | $join .= $this->term->join_clause(); |
| @@ -435,59 +444,24 @@ | ||
| 435 | 444 | if ( $parent > 0 ) { |
| 436 | 445 | $where .= $wpdb->prepare( ' AND tt.parent = %d', $parent ); |
| 437 | 446 | } |
| 438 | 447 | |
| 439 | - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 440 | 448 | return $wpdb->get_var( $select . $join . $where ); |
| 441 | 449 | } |
| 442 | 450 | |
| 443 | 451 | /** |
| 444 | - * Checks if a term slug exists in a given language, taxonomy, hierarchy | |
| 452 | + * Gets the number of posts per language in a date, author or post type archive | |
| 445 | 453 | * |
| 446 | - * @since 1.9 | |
| 447 | - * @since 2.8 Moved from PLL_Share_Term_Slug::term_exists() to PLL_Model::term_exists_by_slug() | |
| 448 | - * | |
| 449 | - * @param string $slug The term slug to test. | |
| 450 | - * @param string|object $language The language slug or object. | |
| 451 | - * @param string $taxonomy Optional taxonomy name. | |
| 452 | - * @param int $parent Optional parent term id. | |
| 453 | - * @return null|int The term_id of the found term. | |
| 454 | - */ | |
| 455 | - public function term_exists_by_slug( $slug, $language, $taxonomy = '', $parent = 0 ) { | |
| 456 | - global $wpdb; | |
| 457 | - | |
| 458 | - $select = "SELECT t.term_id FROM {$wpdb->terms} AS t"; | |
| 459 | - $join = " INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id"; | |
| 460 | - $join .= $this->term->join_clause(); | |
| 461 | - $where = $wpdb->prepare( ' WHERE t.slug = %s', $slug ); | |
| 462 | - $where .= $this->term->where_clause( $this->get_language( $language ) ); | |
| 463 | - | |
| 464 | - if ( ! empty( $taxonomy ) ) { | |
| 465 | - $where .= $wpdb->prepare( ' AND tt.taxonomy = %s', $taxonomy ); | |
| 466 | - } | |
| 467 | - | |
| 468 | - if ( $parent > 0 ) { | |
| 469 | - $where .= $wpdb->prepare( ' AND tt.parent = %d', $parent ); | |
| 470 | - } | |
| 471 | - | |
| 472 | - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 473 | - return $wpdb->get_var( $select . $join . $where ); | |
| 474 | - } | |
| 475 | - | |
| 476 | - | |
| 477 | - /** | |
| 478 | - * Gets the number of posts per language in a date, author or post type archive. | |
| 479 | - * | |
| 480 | 454 | * @since 1.2 |
| 481 | 455 | * |
| 482 | - * @param object $lang PLL_Language instance. | |
| 483 | - * @param array $q WP_Query arguments ( accepted: post_type, m, year, monthnum, day, author, author_name, post_format, post_status ). | |
| 456 | + * @param object $lang | |
| 457 | + * @param array $q WP_Query arguments ( accepted: post_type, m, year, monthnum, day, author, author_name, post_format ) | |
| 484 | 458 | * @return int |
| 485 | 459 | */ |
| 486 | 460 | public function count_posts( $lang, $q = array() ) { |
| 487 | 461 | global $wpdb; |
| 488 | 462 | |
| 489 | - $q = wp_parse_args( $q, array( 'post_type' => 'post', 'post_status' => 'publish' ) ); | |
| 463 | + $q = wp_parse_args( $q, array( 'post_type' => 'post' ) ); | |
| 490 | 464 | |
| 491 | 465 | if ( ! is_array( $q['post_type'] ) ) { |
| 492 | 466 | $q['post_type'] = array( $q['post_type'] ); |
| 493 | 467 | } |
| @@ -498,19 +472,19 @@ | ||
| 498 | 472 | } |
| 499 | 473 | } |
| 500 | 474 | |
| 501 | 475 | if ( empty( $q['post_type'] ) ) { |
| 502 | - $q['post_type'] = array( 'post' ); // We *need* a post type. | |
| 476 | + $q['post_type'] = array( 'post' ); // we *need* a post type | |
| 503 | 477 | } |
| 504 | 478 | |
| 505 | - $cache_key = 'pll_count_posts_' . md5( maybe_serialize( $q ) ); | |
| 506 | - $counts = wp_cache_get( $cache_key, 'counts' ); | |
| 479 | + $cache_key = md5( serialize( $q ) ); | |
| 480 | + $counts = wp_cache_get( $cache_key, 'pll_count_posts' ); | |
| 507 | 481 | |
| 508 | 482 | if ( false === $counts ) { |
| 509 | 483 | $select = "SELECT pll_tr.term_taxonomy_id, COUNT( * ) AS num_posts FROM {$wpdb->posts}"; |
| 510 | 484 | $join = $this->post->join_clause(); |
| 511 | - $where = sprintf( " WHERE post_status = '%s'", esc_sql( $q['post_status'] ) ); | |
| 512 | - $where .= sprintf( " AND {$wpdb->posts}.post_type IN ( '%s' )", join( "', '", esc_sql( $q['post_type'] ) ) ); | |
| 485 | + $where = " WHERE post_status = 'publish'"; | |
| 486 | + $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_type IN ( '%s' )", join( "', '", $q['post_type'] ) ); | |
| 513 | 487 | $where .= $this->post->where_clause( $this->get_languages_list() ); |
| 514 | 488 | $groupby = ' GROUP BY pll_tr.term_taxonomy_id'; |
| 515 | 489 | |
| 516 | 490 | if ( ! empty( $q['m'] ) ) { |
| @@ -536,9 +510,9 @@ | ||
| 536 | 510 | $where .= $wpdb->prepare( " AND DAYOFMONTH( {$wpdb->posts}.post_date ) = %d", $q['day'] ); |
| 537 | 511 | } |
| 538 | 512 | |
| 539 | 513 | if ( ! empty( $q['author_name'] ) ) { |
| 540 | - $author = get_user_by( 'slug', sanitize_title_for_query( $q['author_name'] ) ); | |
| 514 | + $author = get_user_by( 'slug', sanitize_title_for_query( $q['author_name'] ) ); | |
| 541 | 515 | if ( $author ) { |
| 542 | 516 | $q['author'] = $author->ID; |
| 543 | 517 | } |
| 544 | 518 | } |
| @@ -546,9 +520,9 @@ | ||
| 546 | 520 | if ( ! empty( $q['author'] ) ) { |
| 547 | 521 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $q['author'] ); |
| 548 | 522 | } |
| 549 | 523 | |
| 550 | - // Filtered taxonomies ( post_format ). | |
| 524 | + // filtered taxonomies ( post_format ) | |
| 551 | 525 | foreach ( $this->get_filtered_taxonomies_query_vars() as $tax_qv ) { |
| 552 | 526 | |
| 553 | 527 | if ( ! empty( $q[ $tax_qv ] ) ) { |
| 554 | 528 | $join .= " INNER JOIN {$wpdb->term_relationships} AS tr ON tr.object_id = {$wpdb->posts}.ID"; |
| @@ -557,15 +531,14 @@ | ||
| 557 | 531 | $where .= $wpdb->prepare( ' AND t.slug = %s', $q[ $tax_qv ] ); |
| 558 | 532 | } |
| 559 | 533 | } |
| 560 | 534 | |
| 561 | - // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared | |
| 562 | 535 | $res = $wpdb->get_results( $select . $join . $where . $groupby, ARRAY_A ); |
| 563 | 536 | foreach ( (array) $res as $row ) { |
| 564 | 537 | $counts[ $row['term_taxonomy_id'] ] = $row['num_posts']; |
| 565 | 538 | } |
| 566 | 539 | |
| 567 | - wp_cache_set( $cache_key, $counts, 'counts' ); | |
| 540 | + wp_cache_set( $cache_key, $counts, 'pll_count_posts' ); | |
| 568 | 541 | } |
| 569 | 542 | |
| 570 | 543 | return empty( $counts[ $lang->term_taxonomy_id ] ) ? 0 : $counts[ $lang->term_taxonomy_id ]; |
| 571 | 544 | } |
| @@ -579,19 +552,8 @@ | ||
| 579 | 552 | */ |
| 580 | 553 | public function get_links_model() { |
| 581 | 554 | $c = array( 'Directory', 'Directory', 'Subdomain', 'Domain' ); |
| 582 | 555 | $class = get_option( 'permalink_structure' ) ? 'PLL_Links_' . $c[ $this->options['force_lang'] ] : 'PLL_Links_Default'; |
| 583 | - | |
| 584 | - /** | |
| 585 | - * Filter the links model class to use | |
| 586 | - * /!\ this filter is fired *before* the $polylang object is available | |
| 587 | - * | |
| 588 | - * @since 2.1.1 | |
| 589 | - * | |
| 590 | - * @param string $class A class name: PLL_Links_Default, PLL_Links_Directory, PLL_Links_Subdomain, PLL_Links_Domain | |
| 591 | - */ | |
| 592 | - $class = apply_filters( 'pll_links_model', $class ); | |
| 593 | - | |
| 594 | 556 | return new $class( $this ); |
| 595 | 557 | } |
| 596 | 558 | |
| 597 | 559 | /** |
| @@ -600,10 +562,10 @@ | ||
| 600 | 562 | * this works but should be slower than the direct call, thus an error is triggered in debug mode |
| 601 | 563 | * |
| 602 | 564 | * @since 1.8 |
| 603 | 565 | * |
| 604 | - * @param string $func Function name | |
| 605 | - * @param array $args Function arguments | |
| 566 | + * @param string $func function name | |
| 567 | + * @param array $args function arguments | |
| 606 | 568 | */ |
| 607 | 569 | public function __call( $func, $args ) { |
| 608 | 570 | $f = $func; |
| 609 | 571 | |
| @@ -608,10 +570,10 @@ | ||
| 608 | 570 | $f = $func; |
| 609 | 571 | |
| 610 | 572 | switch ( $func ) { |
| 611 | 573 | case 'get_object_term': |
| 612 | - $o = ( false === strpos( $args[1], 'term' ) ) ? 'post' : 'term'; | |
| 613 | - break; | |
| 574 | + $o = false === strpos( $args[1], 'term' ) ? 'post' : 'term'; | |
| 575 | + break; | |
| 614 | 576 | |
| 615 | 577 | case 'save_translations': |
| 616 | 578 | case 'delete_translation': |
| 617 | 579 | case 'get_translations': |
| @@ -618,9 +580,9 @@ | ||
| 618 | 580 | case 'get_translation': |
| 619 | 581 | case 'join_clause': |
| 620 | 582 | $o = ( 'post' == $args[0] || $this->is_translated_post_type( $args[0] ) ) ? 'post' : ( 'term' == $args[0] || $this->is_translated_taxonomy( $args[0] ) ? 'term' : false ); |
| 621 | 583 | unset( $args[0] ); |
| 622 | - break; | |
| 584 | + break; | |
| 623 | 585 | |
| 624 | 586 | case 'set_post_language': |
| 625 | 587 | case 'get_post_language': |
| 626 | 588 | case 'set_term_language': |
| @@ -630,44 +592,30 @@ | ||
| 630 | 592 | case 'get_term': |
| 631 | 593 | $str = explode( '_', $func ); |
| 632 | 594 | $f = empty( $str[2] ) ? $str[0] : $str[0] . '_' . $str[2]; |
| 633 | 595 | $o = $str[1]; |
| 634 | - break; | |
| 596 | + break; | |
| 635 | 597 | |
| 636 | 598 | case 'where_clause': |
| 637 | 599 | case 'get_objects_in_language': |
| 638 | 600 | $o = $args[1]; |
| 639 | 601 | unset( $args[1] ); |
| 640 | - break; | |
| 602 | + break; | |
| 641 | 603 | } |
| 642 | 604 | |
| 643 | 605 | if ( ! empty( $o ) && is_object( $this->$o ) && method_exists( $this->$o, $f ) ) { |
| 644 | 606 | if ( WP_DEBUG ) { |
| 645 | - $debug = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions | |
| 607 | + $debug = debug_backtrace(); | |
| 646 | 608 | $i = 1 + empty( $debug[1]['line'] ); // the file and line are in $debug[2] if the function was called using call_user_func |
| 647 | 609 | |
| 648 | - trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions | |
| 649 | - sprintf( | |
| 650 | - '%1$s was called incorrectly in %4$s on line %5$s: the call to $polylang->model->%1$s() has been deprecated in Polylang 1.8, use PLL()->model->%2$s->%3$s() instead.' . "\nError handler", | |
| 651 | - esc_html( $func ), | |
| 652 | - esc_html( $o ), | |
| 653 | - esc_html( $f ), | |
| 654 | - esc_html( $debug[ $i ]['file'] ), | |
| 655 | - absint( $debug[ $i ]['line'] ) | |
| 656 | - ) | |
| 657 | - ); | |
| 610 | + trigger_error( sprintf( | |
| 611 | + '%1$s was called incorrectly in %4$s on line %5$s: the call to $polylang->model->%1$s() has been deprecated in Polylang 1.8, use PLL()->model->%2$s->%3$s() instead.' . "\nError handler", | |
| 612 | + $func, $o, $f, $debug[ $i ]['file'], $debug[ $i ]['line'] | |
| 613 | + ) ); | |
| 658 | 614 | } |
| 659 | 615 | return call_user_func_array( array( $this->$o, $f ), $args ); |
| 660 | 616 | } |
| 661 | 617 | |
| 662 | - $debug = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions | |
| 663 | - trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions | |
| 664 | - sprintf( | |
| 665 | - 'Call to undefined function PLL()->model->%1$s() in %2$s on line %3$s' . "\nError handler", | |
| 666 | - esc_html( $func ), | |
| 667 | - esc_html( $debug[0]['file'] ), | |
| 668 | - absint( $debug[0]['line'] ) | |
| 669 | - ), | |
| 670 | - E_USER_ERROR | |
| 671 | - ); | |
| 618 | + $debug = debug_backtrace(); | |
| 619 | + trigger_error( sprintf( 'Call to undefined function PLL()->model->%1$s() in %2$s on line %3$s' . "\nError handler", $func, $debug[0]['file'], $debug[0]['line'] ), E_USER_ERROR ); | |
| 672 | 620 | } |
| 673 | 621 | } |