Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/sitepres.../inc/setup
File: wpml-settings-helper.class.php
<?php
[0] Fix | Delete
[1] Fix | Delete
class WPML_Settings_Helper {
[2] Fix | Delete
[3] Fix | Delete
const KEY_CPT_UNLOCK_OPTION = 'custom_posts_unlocked_option';
[4] Fix | Delete
const KEY_TAXONOMY_UNLOCK_OPTION = 'taxonomies_unlocked_option';
[5] Fix | Delete
[6] Fix | Delete
/** @var SitePress */
[7] Fix | Delete
protected $sitepress;
[8] Fix | Delete
[9] Fix | Delete
/** @var WPML_Post_Translation */
[10] Fix | Delete
protected $post_translation;
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* @var WPML_Settings_Filters
[14] Fix | Delete
*/
[15] Fix | Delete
private $filters;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* @param WPML_Post_Translation $post_translation
[19] Fix | Delete
* @param SitePress $sitepress
[20] Fix | Delete
*/
[21] Fix | Delete
public function __construct( WPML_Post_Translation $post_translation, SitePress $sitepress ) {
[22] Fix | Delete
$this->sitepress = $sitepress;
[23] Fix | Delete
$this->post_translation = $post_translation;
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* @return WPML_Settings_Filters
[28] Fix | Delete
*/
[29] Fix | Delete
private function get_filters() {
[30] Fix | Delete
if ( ! $this->filters ) {
[31] Fix | Delete
$this->filters = new WPML_Settings_Filters();
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
return $this->filters;
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
function set_post_type_translatable( $post_type ) {
[38] Fix | Delete
$this->set_post_type_translate_mode( $post_type, WPML_CONTENT_TYPE_TRANSLATE );
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
function set_post_type_display_as_translated( $post_type ) {
[42] Fix | Delete
$this->set_post_type_translate_mode( $post_type, WPML_CONTENT_TYPE_DISPLAY_AS_IF_TRANSLATED );
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
function set_post_type_not_translatable( $post_type ) {
[46] Fix | Delete
$sync_settings = $this->sitepress->get_setting( 'custom_posts_sync_option', array() );
[47] Fix | Delete
if ( isset( $sync_settings[ $post_type ] ) ) {
[48] Fix | Delete
unset( $sync_settings[ $post_type ] );
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
$this->clear_ls_languages_cache();
[52] Fix | Delete
$this->sitepress->set_setting( 'custom_posts_sync_option', $sync_settings, true );
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
private function set_post_type_translate_mode( $post_type, $mode ) {
[56] Fix | Delete
$sync_settings = $this->sitepress->get_setting( 'custom_posts_sync_option', array() );
[57] Fix | Delete
$sync_settings[ $post_type ] = $mode;
[58] Fix | Delete
$this->clear_ls_languages_cache();
[59] Fix | Delete
$this->sitepress->set_setting( 'custom_posts_sync_option', $sync_settings, true );
[60] Fix | Delete
$this->sitepress->verify_post_translations( $post_type );
[61] Fix | Delete
$this->post_translation->reload();
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
function set_taxonomy_translatable( $taxonomy ) {
[65] Fix | Delete
$this->set_taxonomy_translatable_mode( $taxonomy, WPML_CONTENT_TYPE_TRANSLATE );
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
function set_taxonomy_display_as_translated( $taxonomy ) {
[69] Fix | Delete
$this->set_taxonomy_translatable_mode( $taxonomy, WPML_CONTENT_TYPE_DISPLAY_AS_IF_TRANSLATED );
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
function set_taxonomy_translatable_mode( $taxonomy, $mode ) {
[73] Fix | Delete
$sync_settings = $this->sitepress->get_setting( 'taxonomies_sync_option', array() );
[74] Fix | Delete
$sync_settings[ $taxonomy ] = $mode;
[75] Fix | Delete
$this->clear_ls_languages_cache();
[76] Fix | Delete
$this->sitepress->set_setting( 'taxonomies_sync_option', $sync_settings, true );
[77] Fix | Delete
$this->sitepress->verify_taxonomy_translations( $taxonomy );
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
function set_taxonomy_not_translatable( $taxonomy ) {
[81] Fix | Delete
$sync_settings = $this->sitepress->get_setting( 'taxonomies_sync_option', array() );
[82] Fix | Delete
if ( isset( $sync_settings[ $taxonomy ] ) ) {
[83] Fix | Delete
unset( $sync_settings[ $taxonomy ] );
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
$this->clear_ls_languages_cache();
[87] Fix | Delete
$this->sitepress->set_setting( 'taxonomies_sync_option', $sync_settings, true );
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
function set_post_type_translation_unlocked_option( $post_type, $unlocked = true ) {
[91] Fix | Delete
[92] Fix | Delete
$unlocked_settings = $this->sitepress->get_setting( 'custom_posts_unlocked_option', array() );
[93] Fix | Delete
[94] Fix | Delete
$unlocked_settings[ $post_type ] = $unlocked ? 1 : 0;
[95] Fix | Delete
[96] Fix | Delete
$this->sitepress->set_setting( 'custom_posts_unlocked_option', $unlocked_settings, true );
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
function set_taxonomy_translation_unlocked_option( $taxonomy, $unlocked = true ) {
[100] Fix | Delete
[101] Fix | Delete
$unlocked_settings = $this->sitepress->get_setting( 'taxonomies_unlocked_option', array() );
[102] Fix | Delete
[103] Fix | Delete
$unlocked_settings[ $taxonomy ] = $unlocked ? 1 : 0;
[104] Fix | Delete
[105] Fix | Delete
$this->sitepress->set_setting( 'taxonomies_unlocked_option', $unlocked_settings, true );
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
/**
[109] Fix | Delete
* @deprecated use the action `wpml_activate_slug_translation` instead
[110] Fix | Delete
* or `WPML_ST_Post_Slug_Translation_Settings` instead (on ST side)
[111] Fix | Delete
*
[112] Fix | Delete
* @param string $post_type
[113] Fix | Delete
*/
[114] Fix | Delete
function activate_slug_translation( $post_type ) {
[115] Fix | Delete
$slug_settings = $this->sitepress->get_setting( 'posts_slug_translation', array() );
[116] Fix | Delete
$slug_settings[ 'types' ] = isset( $slug_settings[ 'types' ] )
[117] Fix | Delete
? $slug_settings[ 'types' ] : array();
[118] Fix | Delete
$slug_settings[ 'types' ][ $post_type ] = 1;
[119] Fix | Delete
/** @deprected key `on`, use option `wpml_base_slug_translation` instead */
[120] Fix | Delete
$slug_settings[ 'on' ] = 1;
[121] Fix | Delete
[122] Fix | Delete
$this->clear_ls_languages_cache();
[123] Fix | Delete
$this->sitepress->set_setting( 'posts_slug_translation', $slug_settings, true );
[124] Fix | Delete
update_option( 'wpml_base_slug_translation', 1 );
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* @deprecated use `WPML_ST_Post_Slug_Translation_Settings` instead (on ST side)
[129] Fix | Delete
*
[130] Fix | Delete
* @param string $post_type
[131] Fix | Delete
*/
[132] Fix | Delete
function deactivate_slug_translation( $post_type ) {
[133] Fix | Delete
$slug_settings = $this->sitepress->get_setting( 'posts_slug_translation', array() );
[134] Fix | Delete
if ( isset( $slug_settings[ 'types' ][ $post_type ] ) ) {
[135] Fix | Delete
unset( $slug_settings[ 'types' ][ $post_type ] );
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
$this->clear_ls_languages_cache();
[139] Fix | Delete
$this->sitepress->set_setting( 'posts_slug_translation', $slug_settings, true );
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
/**
[143] Fix | Delete
* @param array[] $taxs_obj_type
[144] Fix | Delete
*
[145] Fix | Delete
* @see \WPML_Config::maybe_add_filter
[146] Fix | Delete
*
[147] Fix | Delete
* @return array
[148] Fix | Delete
*/
[149] Fix | Delete
function _override_get_translatable_taxonomies( $taxs_obj_type ) {
[150] Fix | Delete
global $wp_taxonomies;
[151] Fix | Delete
[152] Fix | Delete
$taxs = $taxs_obj_type['taxs'];
[153] Fix | Delete
$object_type = $taxs_obj_type['object_type'];
[154] Fix | Delete
foreach ( $taxs as $k => $tax ) {
[155] Fix | Delete
if ( ! $this->sitepress->is_translated_taxonomy( $tax ) ) {
[156] Fix | Delete
unset( $taxs[ $k ] );
[157] Fix | Delete
}
[158] Fix | Delete
}
[159] Fix | Delete
$tm_settings = $this->sitepress->get_setting( 'translation-management', array() );
[160] Fix | Delete
foreach ( $tm_settings['taxonomies_readonly_config'] as $tx => $translate ) {
[161] Fix | Delete
if ( $translate
[162] Fix | Delete
&& ! in_array( $tx, $taxs )
[163] Fix | Delete
&& isset( $wp_taxonomies[ $tx ] )
[164] Fix | Delete
&& in_array( $object_type, $wp_taxonomies[ $tx ]->object_type )
[165] Fix | Delete
) {
[166] Fix | Delete
$taxs[] = $tx;
[167] Fix | Delete
}
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
$ret = array( 'taxs' => $taxs, 'object_type' => $taxs_obj_type['object_type'] );
[171] Fix | Delete
[172] Fix | Delete
return $ret;
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* @param array[] $types
[177] Fix | Delete
*
[178] Fix | Delete
* @see \WPML_Config::maybe_add_filter
[179] Fix | Delete
*
[180] Fix | Delete
* @return array
[181] Fix | Delete
*/
[182] Fix | Delete
function _override_get_translatable_documents( $types ) {
[183] Fix | Delete
$tm_settings = $this->sitepress->get_setting( 'translation-management', array() );
[184] Fix | Delete
$cpt_unlocked_options = $this->sitepress->get_setting( 'custom_posts_unlocked_option', array() );
[185] Fix | Delete
foreach ( $types as $k => $type ) {
[186] Fix | Delete
if ( isset( $tm_settings[ 'custom-types_readonly_config' ][ $k ] )
[187] Fix | Delete
&& ! $tm_settings[ 'custom-types_readonly_config' ][ $k ]
[188] Fix | Delete
) {
[189] Fix | Delete
unset( $types[ $k ] );
[190] Fix | Delete
}
[191] Fix | Delete
}
[192] Fix | Delete
$types = $this->get_filters()->get_translatable_documents( $types, $tm_settings['custom-types_readonly_config'], $cpt_unlocked_options );
[193] Fix | Delete
[194] Fix | Delete
return $types;
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* Updates the custom post type translation settings with new settings.
[199] Fix | Delete
*
[200] Fix | Delete
* @param array $new_options
[201] Fix | Delete
*
[202] Fix | Delete
* @uses \SitePress::get_setting
[203] Fix | Delete
* @uses \SitePress::save_settings
[204] Fix | Delete
*
[205] Fix | Delete
* @return array new custom post type settings after the update
[206] Fix | Delete
*/
[207] Fix | Delete
function update_cpt_sync_settings( array $new_options ) {
[208] Fix | Delete
$cpt_sync_options = $this->sitepress->get_setting( WPML_Element_Sync_Settings_Factory::KEY_POST_SYNC_OPTION, array() );
[209] Fix | Delete
$cpt_sync_options = array_merge( $cpt_sync_options, $new_options );
[210] Fix | Delete
$new_options = array_filter( $new_options );
[211] Fix | Delete
[212] Fix | Delete
$this->clear_ls_languages_cache();
[213] Fix | Delete
[214] Fix | Delete
do_action( 'wpml_verify_post_translations', $new_options );
[215] Fix | Delete
do_action( 'wpml_save_cpt_sync_settings' );
[216] Fix | Delete
$this->sitepress->set_setting( WPML_Element_Sync_Settings_Factory::KEY_POST_SYNC_OPTION, $cpt_sync_options, true );
[217] Fix | Delete
[218] Fix | Delete
return $cpt_sync_options;
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
/**
[222] Fix | Delete
* Updates the taxonomy type translation settings with new settings.
[223] Fix | Delete
*
[224] Fix | Delete
* @param array $new_options
[225] Fix | Delete
*
[226] Fix | Delete
* @uses \SitePress::get_setting
[227] Fix | Delete
* @uses \SitePress::save_settings
[228] Fix | Delete
*
[229] Fix | Delete
* @return array new taxonomy type settings after the update
[230] Fix | Delete
*/
[231] Fix | Delete
function update_taxonomy_sync_settings( array $new_options ) {
[232] Fix | Delete
$taxonomy_sync_options = $this->sitepress->get_setting( WPML_Element_Sync_Settings_Factory::KEY_TAX_SYNC_OPTION, [] );
[233] Fix | Delete
$changed_sync_options = array_diff_assoc( $new_options, $taxonomy_sync_options );
[234] Fix | Delete
$taxonomy_sync_options = array_merge( $taxonomy_sync_options, $new_options );
[235] Fix | Delete
[236] Fix | Delete
foreach ( $changed_sync_options as $taxonomy_name => $taxonomy_sync_option ) {
[237] Fix | Delete
$this->sitepress->verify_taxonomy_translations( $taxonomy_name );
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
$this->clear_ls_languages_cache();
[241] Fix | Delete
[242] Fix | Delete
do_action( 'wpml_save_taxonomy_sync_settings' );
[243] Fix | Delete
$this->sitepress->set_setting( WPML_Element_Sync_Settings_Factory::KEY_TAX_SYNC_OPTION, $taxonomy_sync_options, true );
[244] Fix | Delete
[245] Fix | Delete
return $taxonomy_sync_options;
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
/**
[249] Fix | Delete
* Updates the custom post type unlocked settings with new settings.
[250] Fix | Delete
*
[251] Fix | Delete
* @param array $unlock_options
[252] Fix | Delete
*
[253] Fix | Delete
* @uses \SitePress::get_setting
[254] Fix | Delete
* @uses \SitePress::save_settings
[255] Fix | Delete
*
[256] Fix | Delete
* @return array new custom post type unlocked settings after the update
[257] Fix | Delete
*/
[258] Fix | Delete
function update_cpt_unlocked_settings( array $unlock_options ) {
[259] Fix | Delete
return $this->update_unlocked_settings( $unlock_options, self::KEY_CPT_UNLOCK_OPTION );
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
/**
[263] Fix | Delete
* Updates the taxonomy type unlocked settings with new settings.
[264] Fix | Delete
*
[265] Fix | Delete
* @param array $unlock_options
[266] Fix | Delete
*
[267] Fix | Delete
* @uses \SitePress::get_setting
[268] Fix | Delete
* @uses \SitePress::save_settings
[269] Fix | Delete
*
[270] Fix | Delete
* @return array new taxonomy type unlocked settings after the update
[271] Fix | Delete
*/
[272] Fix | Delete
function update_taxonomy_unlocked_settings( array $unlock_options ) {
[273] Fix | Delete
return $this->update_unlocked_settings( $unlock_options, self::KEY_TAXONOMY_UNLOCK_OPTION );
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
/**
[277] Fix | Delete
* @param array $unlock_options
[278] Fix | Delete
* @param string $setting_key
[279] Fix | Delete
*
[280] Fix | Delete
* @return array
[281] Fix | Delete
*/
[282] Fix | Delete
private function update_unlocked_settings( array $unlock_options, $setting_key ) {
[283] Fix | Delete
$cpt_unlock_options = $this->sitepress->get_setting( $setting_key, array() );
[284] Fix | Delete
$cpt_unlock_options = array_merge( $cpt_unlock_options, $unlock_options );
[285] Fix | Delete
$this->sitepress->set_setting( $setting_key, $cpt_unlock_options, true );
[286] Fix | Delete
return $cpt_unlock_options ;
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
/**
[290] Fix | Delete
* @param string $config_type
[291] Fix | Delete
*/
[292] Fix | Delete
function maybe_add_filter( $config_type ) {
[293] Fix | Delete
if ( $config_type === 'taxonomies' ) {
[294] Fix | Delete
add_filter( 'get_translatable_taxonomies',
[295] Fix | Delete
array( $this, '_override_get_translatable_taxonomies' ) );
[296] Fix | Delete
} elseif ( $config_type === 'custom-types' ) {
[297] Fix | Delete
add_filter( 'get_translatable_documents',
[298] Fix | Delete
array( $this, '_override_get_translatable_documents' ) );
[299] Fix | Delete
}
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
private function clear_ls_languages_cache() {
[303] Fix | Delete
$cache = new WPML_WP_Cache( 'ls_languages' );
[304] Fix | Delete
$cache->flush_group_cache();
[305] Fix | Delete
}
[306] Fix | Delete
}
[307] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function