| @@ -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 | * |
| @@ -104,8 +101,15 @@ | ||
| 104 | 101 | $languages[ $k ] = new PLL_Language( $v ); |
| 105 | 102 | } |
| 106 | 103 | } |
| 107 | 104 | |
| 105 | + // Custom flags | |
| 106 | + if ( ! PLL_ADMIN ) { | |
| 107 | + foreach ( $languages as $language ) { | |
| 108 | + $language->set_custom_flag(); | |
| 109 | + } | |
| 110 | + } | |
| 111 | + | |
| 108 | 112 | /** |
| 109 | 113 | * Filter the list of languages *after* it is stored in the persistent cache |
| 110 | 114 | * /!\ this filter is fired *before* the $polylang object is available |
| 111 | 115 | * |
| @@ -177,9 +181,8 @@ | ||
| 177 | 181 | $this->cache->set( 'language:' . $lang->term_id, $lang ); |
| 178 | 182 | $this->cache->set( 'language:' . $lang->tl_term_id, $lang ); |
| 179 | 183 | $this->cache->set( 'language:' . $lang->slug, $lang ); |
| 180 | 184 | $this->cache->set( 'language:' . $lang->locale, $lang ); |
| 181 | - $this->cache->set( 'language:' . $lang->w3c, $lang ); | |
| 182 | 185 | } |
| 183 | 186 | $return = $this->cache->get( 'language:' . $value ); |
| 184 | 187 | } |
| 185 | 188 | |
| @@ -214,9 +217,9 @@ | ||
| 214 | 217 | * @return array post type names for which Polylang manages languages and translations |
| 215 | 218 | */ |
| 216 | 219 | public function get_translated_post_types( $filter = true ) { |
| 217 | 220 | if ( false === $post_types = $this->cache->get( 'post_types' ) ) { |
| 218 | - $post_types = array( 'post' => 'post', 'page' => 'page', 'wp_block' => 'wp_block' ); | |
| 221 | + $post_types = array( 'post' => 'post', 'page' => 'page' ); | |
| 219 | 222 | |
| 220 | 223 | if ( ! empty( $this->options['media_support'] ) ) { |
| 221 | 224 | $post_types['attachment'] = 'attachment'; |
| 222 | 225 | } |
| @@ -381,9 +384,9 @@ | ||
| 381 | 384 | $lang = $this->get_language( $lang ); |
| 382 | 385 | |
| 383 | 386 | // create a new category |
| 384 | 387 | // FIXME this is translated in admin language when we would like it in $lang |
| 385 | - $cat_name = __( 'Uncategorized', 'polylang' ); | |
| 388 | + $cat_name = __( 'Uncategorized' ); | |
| 386 | 389 | $cat_slug = sanitize_title( $cat_name . '-' . $lang->slug ); |
| 387 | 390 | $cat = wp_insert_term( $cat_name, 'category', array( 'slug' => $cat_slug ) ); |
| 388 | 391 | |
| 389 | 392 | // check that the category was not previously created ( in case the language was deleted and recreated ) |
| @@ -423,9 +426,8 @@ | ||
| 423 | 426 | public function term_exists( $term_name, $taxonomy, $parent, $language ) { |
| 424 | 427 | global $wpdb; |
| 425 | 428 | |
| 426 | 429 | $term_name = trim( wp_unslash( $term_name ) ); |
| 427 | - $term_name = _wp_specialchars( $term_name ); | |
| 428 | 430 | |
| 429 | 431 | $select = "SELECT t.term_id FROM $wpdb->terms AS t"; |
| 430 | 432 | $join = " INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id"; |
| 431 | 433 | $join .= $this->term->join_clause(); |
| @@ -440,54 +442,20 @@ | ||
| 440 | 442 | return $wpdb->get_var( $select . $join . $where ); |
| 441 | 443 | } |
| 442 | 444 | |
| 443 | 445 | /** |
| 444 | - * Checks if a term slug exists in a given language, taxonomy, hierarchy | |
| 446 | + * Gets the number of posts per language in a date, author or post type archive | |
| 445 | 447 | * |
| 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 | 448 | * @since 1.2 |
| 481 | 449 | * |
| 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 ). | |
| 450 | + * @param object $lang | |
| 451 | + * @param array $q WP_Query arguments ( accepted: post_type, m, year, monthnum, day, author, author_name, post_format ) | |
| 484 | 452 | * @return int |
| 485 | 453 | */ |
| 486 | 454 | public function count_posts( $lang, $q = array() ) { |
| 487 | 455 | global $wpdb; |
| 488 | 456 | |
| 489 | - $q = wp_parse_args( $q, array( 'post_type' => 'post', 'post_status' => 'publish' ) ); | |
| 457 | + $q = wp_parse_args( $q, array( 'post_type' => 'post' ) ); | |
| 490 | 458 | |
| 491 | 459 | if ( ! is_array( $q['post_type'] ) ) { |
| 492 | 460 | $q['post_type'] = array( $q['post_type'] ); |
| 493 | 461 | } |
| @@ -498,18 +466,18 @@ | ||
| 498 | 466 | } |
| 499 | 467 | } |
| 500 | 468 | |
| 501 | 469 | if ( empty( $q['post_type'] ) ) { |
| 502 | - $q['post_type'] = array( 'post' ); // We *need* a post type. | |
| 470 | + $q['post_type'] = array( 'post' ); // we *need* a post type | |
| 503 | 471 | } |
| 504 | 472 | |
| 505 | - $cache_key = 'pll_count_posts_' . md5( maybe_serialize( $q ) ); | |
| 506 | - $counts = wp_cache_get( $cache_key, 'counts' ); | |
| 473 | + $cache_key = md5( serialize( $q ) ); | |
| 474 | + $counts = wp_cache_get( $cache_key, 'pll_count_posts' ); | |
| 507 | 475 | |
| 508 | 476 | if ( false === $counts ) { |
| 509 | 477 | $select = "SELECT pll_tr.term_taxonomy_id, COUNT( * ) AS num_posts FROM {$wpdb->posts}"; |
| 510 | 478 | $join = $this->post->join_clause(); |
| 511 | - $where = sprintf( " WHERE post_status = '%s'", esc_sql( $q['post_status'] ) ); | |
| 479 | + $where = " WHERE post_status = 'publish'"; | |
| 512 | 480 | $where .= sprintf( " AND {$wpdb->posts}.post_type IN ( '%s' )", join( "', '", esc_sql( $q['post_type'] ) ) ); |
| 513 | 481 | $where .= $this->post->where_clause( $this->get_languages_list() ); |
| 514 | 482 | $groupby = ' GROUP BY pll_tr.term_taxonomy_id'; |
| 515 | 483 | |
| @@ -546,9 +514,9 @@ | ||
| 546 | 514 | if ( ! empty( $q['author'] ) ) { |
| 547 | 515 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $q['author'] ); |
| 548 | 516 | } |
| 549 | 517 | |
| 550 | - // Filtered taxonomies ( post_format ). | |
| 518 | + // filtered taxonomies ( post_format ) | |
| 551 | 519 | foreach ( $this->get_filtered_taxonomies_query_vars() as $tax_qv ) { |
| 552 | 520 | |
| 553 | 521 | if ( ! empty( $q[ $tax_qv ] ) ) { |
| 554 | 522 | $join .= " INNER JOIN {$wpdb->term_relationships} AS tr ON tr.object_id = {$wpdb->posts}.ID"; |
| @@ -563,9 +531,9 @@ | ||
| 563 | 531 | foreach ( (array) $res as $row ) { |
| 564 | 532 | $counts[ $row['term_taxonomy_id'] ] = $row['num_posts']; |
| 565 | 533 | } |
| 566 | 534 | |
| 567 | - wp_cache_set( $cache_key, $counts, 'counts' ); | |
| 535 | + wp_cache_set( $cache_key, $counts, 'pll_count_posts' ); | |
| 568 | 536 | } |
| 569 | 537 | |
| 570 | 538 | return empty( $counts[ $lang->term_taxonomy_id ] ) ? 0 : $counts[ $lang->term_taxonomy_id ]; |
| 571 | 539 | } |
| @@ -641,19 +609,19 @@ | ||
| 641 | 609 | } |
| 642 | 610 | |
| 643 | 611 | if ( ! empty( $o ) && is_object( $this->$o ) && method_exists( $this->$o, $f ) ) { |
| 644 | 612 | if ( WP_DEBUG ) { |
| 645 | - $debug = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions | |
| 613 | + $debug = debug_backtrace(); | |
| 646 | 614 | $i = 1 + empty( $debug[1]['line'] ); // the file and line are in $debug[2] if the function was called using call_user_func |
| 647 | 615 | |
| 648 | - trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions | |
| 616 | + trigger_error( | |
| 649 | 617 | sprintf( |
| 650 | 618 | '%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'] ) | |
| 619 | + $func, | |
| 620 | + $o, | |
| 621 | + $f, | |
| 622 | + $debug[ $i ]['file'], | |
| 623 | + $debug[ $i ]['line'] | |
| 656 | 624 | ) |
| 657 | 625 | ); |
| 658 | 626 | } |
| 659 | 627 | return call_user_func_array( array( $this->$o, $f ), $args ); |
| @@ -658,16 +626,8 @@ | ||
| 658 | 626 | } |
| 659 | 627 | return call_user_func_array( array( $this->$o, $f ), $args ); |
| 660 | 628 | } |
| 661 | 629 | |
| 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 | - ); | |
| 630 | + $debug = debug_backtrace(); | |
| 631 | + 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 | 632 | } |
| 673 | 633 | } |