first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
<?php
/**
* Class WPML_TM_Translation_Priorities_Factory
*/
class WPML_TM_Translation_Priorities_Factory implements IWPML_Frontend_Action_Loader, IWPML_Backend_Action_Loader {
public function create() {
global $sitepress;
return new WPML_TM_Translation_Priorities_Register_Action( $sitepress );
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* Class WPML_TM_Translation_Priorities_Register_Action
*/
class WPML_TM_Translation_Priorities_Register_Action implements IWPML_Action {
/** @var SitePress */
private $sitepress;
const TRANSLATION_PRIORITY_TAXONOMY = 'translation_priority';
/**
* WPML_TM_Translation_Priorities_Register_Action constructor.
*
* @param SitePress $sitepress
*/
public function __construct( SitePress $sitepress ) {
$this->sitepress = $sitepress;
}
public function add_hooks() {
add_action( 'init', array( $this, 'register_translation_priority_taxonomy' ), 5 );
}
public function register_translation_priority_taxonomy() {
if ( ! is_blog_installed() ) {
return;
}
register_taxonomy(
self::TRANSLATION_PRIORITY_TAXONOMY,
apply_filters( 'wpml_taxonomy_objects_translation_priority', array_keys( $this->sitepress->get_translatable_documents() ) ),
apply_filters(
'wpml_taxonomy_args_translation_priority',
array(
'label' => __( 'Translation Priority', 'sitepress' ),
'labels' => array(
'name' => __( 'Translation Priorities', 'sitepress' ),
'singular_name' => __( 'Translation Priority', 'sitepress' ),
'all_items' => __( 'All Translation Priorities', 'sitepress' ),
'edit_item' => __( 'Edit Translation Priority', 'sitepress' ),
'update_item' => __( 'Update Translation Priority', 'sitepress' ),
'add_new_item' => __( 'Add new Translation Priority', 'sitepress' ),
'new_item_name' => __( 'New Translation Priority Name', 'sitepress' ),
),
'hierarchical' => false,
'show_ui' => true,
'show_in_menu' => false,
'show_in_rest' => false,
'show_tagcloud' => false,
'show_in_quick_edit' => true,
'show_admin_column' => false,
'query_var' => is_admin(),
'rewrite' => false,
'public' => false,
'meta_box_cb' => false,
)
)
);
}
}

View File

@@ -0,0 +1,111 @@
<?php
/**
* Class WPML_Translation_Priorities
*/
class WPML_TM_Translation_Priorities {
const DEFAULT_TRANSLATION_PRIORITY_VALUE_SLUG = 'optional';
const TAXONOMY = 'translation_priority';
public function get_values() {
return get_terms(
array(
'taxonomy' => self::TAXONOMY,
'hide_empty' => false,
)
);
}
/**
* @return int
*/
public function get_default_value_id() {
return (int) self::get_default_term()->term_id;
}
/**
* @return WP_Term
*/
public static function get_default_term() {
$term = get_term_by( 'slug', self::DEFAULT_TRANSLATION_PRIORITY_VALUE_SLUG, self::TAXONOMY );
if ( ! $term ) {
$term = new WP_Term( (object) [ 'term_id' => 0 ] );
}
return $term;
}
/**
* @param int $term_taxonomy_id
* @param string $original_name
* @param string $target_language
*
* @return int|bool
*/
public static function insert_missing_translation( $term_taxonomy_id, $original_name, $target_language ) {
global $sitepress;
$trid = (int) $sitepress->get_element_trid( $term_taxonomy_id, 'tax_' . self::TAXONOMY );
$term_translations = $sitepress->get_element_translations( $trid, 'tax_' . self::TAXONOMY );
if ( ! isset( $term_translations[ $target_language ] ) ) {
$sitepress->switch_locale( $target_language );
$name = __( $original_name, 'sitepress' );
$slug = WPML_Terms_Translations::term_unique_slug( sanitize_title( $name ), self::TAXONOMY, $target_language );
$translated_term = wp_insert_term( $name, self::TAXONOMY, array( 'slug' => $slug ) );
if ( $translated_term && ! is_wp_error( $translated_term ) ) {
$sitepress->set_element_language_details( $translated_term['term_taxonomy_id'], 'tax_' . self::TAXONOMY, $trid, $target_language );
return $translated_term['term_taxonomy_id'];
}
}
return false;
}
public static function insert_missing_default_terms() {
global $sitepress;
$terms = array(
array(
'default' => __( 'Optional', 'sitepress' ),
'en_name' => 'Optional',
),
array(
'default' => __( 'Required', 'sitepress' ),
'en_name' => 'Required',
),
array(
'default' => __( 'Not needed', 'sitepress' ),
'en_name' => 'Not needed',
),
);
$default_language = $sitepress->get_default_language();
$active_languages = $sitepress->get_active_languages();
$current_language = $sitepress->get_current_language();
unset( $active_languages[ $default_language ] );
foreach ( $terms as $term ) {
$sitepress->switch_locale( $default_language );
$original_term = get_term_by( 'name', $term['default'], self::TAXONOMY, ARRAY_A );
if ( ! $original_term ) {
$original_term = wp_insert_term( $term['default'], self::TAXONOMY );
$sitepress->set_element_language_details( $original_term['term_taxonomy_id'], 'tax_' . self::TAXONOMY, null, $default_language );
}
foreach ( $active_languages as $language ) {
self::insert_missing_translation( $original_term['term_taxonomy_id'], $term['en_name'], $language['code'] );
}
}
$sitepress->switch_locale( $current_language );
}
}