??????????????
??????????????
??????????????
??????????????
Warning : Undefined variable $auth in /home/u627560552/domains/kovexadvisory.com/public_html/666.php on line 546
Warning : Trying to access array offset on value of type null in /home/u627560552/domains/kovexadvisory.com/public_html/666.php on line 546
??????????????
??????????????
??????????????
??????????????
File Manager
✏️ Edit File: /home/mklsvubc/pgtankstorage.sg/wp-content/plugins/polylang/src/default-term.php
⬅ Kembali
<?php
/**
* @package Polylang
*/
/**
* Manages filters and actions related to default terms.
*
* @since 3.7
*/
class PLL_Default_Term {
/**
* A reference to the PLL_Model instance.
*
* @var PLL_Model
*/
protected $model;
/**
* Preferred language to assign to new contents.
*
* @var PLL_Language|null
*/
protected $curlang;
/**
* Array of registered taxonomy names for which Polylang manages languages and translations.
*
* @var string[]
*/
protected $taxonomies;
/**
* Constructor: setups properties.
*
* @since 3.1
*
* @param object $polylang The Polylang object.
*/
public function __construct( &$polylang ) {
$this->model = &$polylang->model;
$this->curlang = &$polylang->curlang;
$this->taxonomies = $this->model->get_translated_taxonomies();
}
/**
* Setups filters and actions needed.
*
* @since 3.1
*
* @return void
*/
public function add_hooks() {
foreach ( $this->taxonomies as $taxonomy ) {
if ( 'category' === $taxonomy ) {
// Allows to get the default terms in all languages.
add_filter( 'option_default_' . $taxonomy, array( $this, 'option_default_term' ) );
add_action( 'update_option_default_' . $taxonomy, array( $this, 'update_option_default_term' ), 10, 2 );
}
}
add_action( 'pll_add_language', array( $this, 'handle_default_term_on_create_language' ) );
// The default term should be in the default language.
add_action( 'pll_update_default_lang', array( $this, 'update_default_term_language' ) );
// Prevents deleting all the translations of the default term.
add_filter( 'map_meta_cap', array( $this, 'fix_delete_default_term' ), 10, 4 );
}
/**
* Filters the default term to return the one in the right language.
*
* @since 1.2
*
* @param int $taxonomy_term_id The taxonomy term id.
* @return int A taxonomy term id.
*/
public function option_default_term( $taxonomy_term_id ) {
if ( isset( $this->curlang ) && $tr = $this->model->term->get( $taxonomy_term_id, $this->curlang ) ) {
$taxonomy_term_id = $tr;
}
return $taxonomy_term_id;
}
/**
* Checks if the new default term is translated in all languages.
* If not, create the translations.
*
* @since 1.7
*
* @param int $old_value The old option value.
* @param int $value The new option value.
* @return void
*/
public function update_option_default_term( $old_value, $value ) {
$default_cat_lang = $this->model->term->get_language( $value );
// Assign a default language to default term.
if ( ! $default_cat_lang ) {
$default_cat_lang = $this->model->get_default_language();
$this->model->term->set_language( (int) $value, $default_cat_lang );
}
if ( empty( $default_cat_lang ) ) {
return;
}
$current_filter = current_filter();
if ( ! $current_filter ) {
return;
}
$taxonomy = substr( $current_filter, 22 );
foreach ( $this->model->get_languages_list() as $language ) {
if ( $language->slug != $default_cat_lang->slug && ! $this->model->term->get_translation( $value, $language ) ) {
$this->create_default_term( $language, $taxonomy );
}
}
}
/**
* Creates a default term for a language.
*
* @since 1.2
*
* @param PLL_Language|string|int $lang Language.
* @param string $taxonomy The current taxonomy.
* @return void
*/
public function create_default_term( $lang, $taxonomy ) {
$lang = $this->model->get_language( $lang );
// Create a new term.
// FIXME this is translated in admin language when we would like it in $lang
$cat_name = __( 'Uncategorized', 'polylang' );
$cat_slug = sanitize_title( $cat_name . '-' . $lang->slug );
$cat = wp_insert_term( $cat_name, $taxonomy, array( 'slug' => $cat_slug ) );
// Check that the term was not previously created (in case the language was deleted and recreated).
$cat = $cat->error_data['term_exists'] ?? $cat['term_id'];
// Set language.
$this->model->term->set_language( (int) $cat, $lang );
// This is a translation of the default term.
$default = (int) get_option( 'default_' . $taxonomy );
$translations = $this->model->term->get_translations( $default );
$this->model->term->save_translations( (int) $cat, $translations );
}
/**
* Manages the default term when new languages are created.
*
* @since 3.1
*
* @param array $args Argument used to create the language. @see `Model\Languages::add()`.
* @return void
*/
public function handle_default_term_on_create_language( $args ) {
foreach ( $this->taxonomies as $taxonomy ) {
if ( 'category' === $taxonomy ) {
$default = (int) get_option( 'default_' . $taxonomy );
// Assign default language to default term.
if ( ! $this->model->term->get_language( $default ) ) {
$this->model->term->set_language( $default, $args['slug'] );
} elseif ( empty( $args['no_default_cat'] ) && ! $this->model->term->get( $default, $args['slug'] ) ) {
$this->create_default_term( $args['slug'], $taxonomy );
}
}
}
}
/**
* Prevents deleting all the translations of the default term.
*
* @since 2.1
*
* @param array $caps The user's actual capabilities.
* @param string $cap Capability name.
* @param int $user_id The user ID.
* @param array $args Adds the context to the cap. The term id.
* @return array
*/
public function fix_delete_default_term( $caps, $cap, $user_id, $args ) {
if ( 'delete_term' === $cap && $this->is_default_term( reset( $args ) ) ) {
$caps[] = 'do_not_allow';
}
return $caps;
}
/**
* Checks if the term is the default term.
*
* @since 3.1
*
* @param int $term_id The term ID.
* @return bool True if the term is the default term, false otherwise.
*/
public function is_default_term( $term_id ) {
$term = get_term( $term_id );
if ( $term instanceof WP_Term ) {
$default_term_id = get_option( 'default_' . $term->taxonomy );
return $default_term_id && in_array( $default_term_id, $this->model->term->get_translations( $term_id ) );
}
return false;
}
/**
* Updates the default term language.
*
* @since 3.1
*
* @param string $slug Language slug.
* @return void
*/
public function update_default_term_language( $slug ) {
foreach ( $this->taxonomies as $taxonomy ) {
if ( 'category' === $taxonomy ) {
$default_cats = $this->model->term->get_translations( get_option( 'default_' . $taxonomy ) );
if ( isset( $default_cats[ $slug ] ) ) {
update_option( 'default_' . $taxonomy, $default_cats[ $slug ] );
}
}
}
}
}
Nama
Tipe
Ukuran
Diubah
Aksi
📁 Capabilities
dir
—
2026-06-17 21:10
📁 Model
dir
—
2026-06-17 21:10
📁 Options
dir
—
2026-06-17 21:10
📁 admin
dir
—
2026-06-17 21:10
📁 frontend
dir
—
2026-06-17 21:10
📁 install
dir
—
2026-06-17 21:10
📁 integrations
dir
—
2026-06-17 21:10
📁 modules
dir
—
2026-06-17 21:10
📁 settings
dir
—
2026-06-17 21:10
🐘 api.php
php
21.8 KB
2026-06-17 21:10
🐘 base.php
php
6.1 KB
2026-06-17 21:10
🐘 cache.php
php
2.4 KB
2026-06-17 21:10
🐘 class-polylang.php
php
8.3 KB
2026-06-17 21:10
🐘 constant-functions.php
php
1.8 KB
2026-06-17 21:10
🐘 cookie.php
php
3 KB
2026-06-17 21:10
🐘 crud-posts.php
php
14.7 KB
2026-06-17 21:10
🐘 crud-terms.php
php
8.8 KB
2026-06-17 21:10
🐘 default-term.php
php
6.4 KB
2026-06-17 21:10
🐘 filter-rest-routes.php
php
5 KB
2026-06-17 21:10
🐘 filters-links.php
php
5.6 KB
2026-06-17 21:10
🐘 filters-sanitization.php
php
3.2 KB
2026-06-17 21:10
🐘 filters-widgets-options.php
php
2.6 KB
2026-06-17 21:10
🐘 filters.php
php
12.9 KB
2026-06-17 21:10
🐘 format-util.php
php
3 KB
2026-06-17 21:10
🐘 functions.php
php
5.1 KB
2026-06-17 21:10
🐘 language-deprecated.php
php
7.1 KB
2026-06-17 21:10
🐘 language-factory.php
php
9.4 KB
2026-06-17 21:10
🐘 language.php
php
18.1 KB
2026-06-17 21:10
🐘 license.php
php
9.4 KB
2026-06-17 21:10
🐘 links-abstract-domain.php
php
3.2 KB
2026-06-17 21:10
🐘 links-default.php
php
3 KB
2026-06-17 21:10
🐘 links-directory.php
php
9.5 KB
2026-06-17 21:10
🐘 links-domain.php
php
2.9 KB
2026-06-17 21:10
🐘 links-model.php
php
6.5 KB
2026-06-17 21:10
🐘 links-permalinks.php
php
5.6 KB
2026-06-17 21:10
🐘 links-subdomain.php
php
2.2 KB
2026-06-17 21:10
🐘 links.php
php
1.4 KB
2026-06-17 21:10
🐘 mo.php
php
3.4 KB
2026-06-17 21:10
🐘 model.php
php
23 KB
2026-06-17 21:10
🐘 nav-menu.php
php
4.5 KB
2026-06-17 21:10
🐘 olt-manager.php
php
3 KB
2026-06-17 21:10
🐘 query.php
php
7.7 KB
2026-06-17 21:10
🐘 rest-request.php
php
4.2 KB
2026-06-17 21:10
🐘 static-pages.php
php
6.3 KB
2026-06-17 21:10
🐘 switcher.php
php
11 KB
2026-06-17 21:10
🐘 term-slug.php
php
4.9 KB
2026-06-17 21:10
🐘 translatable-object-with-types-interface.php
php
1 KB
2026-06-17 21:10
🐘 translatable-object-with-types-trait.php
php
2 KB
2026-06-17 21:10
🐘 translatable-object.php
php
17.6 KB
2026-06-17 21:10
🐘 translatable-objects.php
php
3.7 KB
2026-06-17 21:10
🐘 translate-option.php
php
13.1 KB
2026-06-17 21:10
🐘 translated-object.php
php
18.9 KB
2026-06-17 21:10
🐘 translated-post.php
php
17.2 KB
2026-06-17 21:10
🐘 translated-term.php
php
14.8 KB
2026-06-17 21:10
🐘 walker-dropdown.php
php
3.8 KB
2026-06-17 21:10
🐘 walker-list.php
php
2.5 KB
2026-06-17 21:10
🐘 walker.php
php
2.4 KB
2026-06-17 21:10
🐘 widget-calendar.php
php
11.6 KB
2026-06-17 21:10
🐘 widget-languages.php
php
5.3 KB
2026-06-17 21:10