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/clone/wp-conte.../plugins/popup-ma.../includes/integrat...
File: class-pum-wpml.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Integrations for wpml
[2] Fix | Delete
*
[3] Fix | Delete
* @package PUM
[4] Fix | Delete
* @copyright Copyright (c) 2023, Code Atlantic LLC
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
// Exit if accessed directly
[8] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[9] Fix | Delete
exit;
[10] Fix | Delete
}
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Class PUM_WPML_Integration
[14] Fix | Delete
*/
[15] Fix | Delete
class PUM_WPML_Integration {
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
*
[19] Fix | Delete
*/
[20] Fix | Delete
public static function init() {
[21] Fix | Delete
add_action( 'icl_make_duplicate', [ __CLASS__, 'duplicate_post' ], 10, 4 );
[22] Fix | Delete
/*
[23] Fix | Delete
add_filter( 'pum_popup', array( __CLASS__, 'pum_popup' ), 10, 2 );
[24] Fix | Delete
TODO Further testing of this filter may prove 80+% of the following unneeded.
[25] Fix | Delete
*/
[26] Fix | Delete
add_filter( 'pum_popup_get_display', [ __CLASS__, 'popup_get_display' ], 10, 2 );
[27] Fix | Delete
add_filter( 'pum_popup_get_close', [ __CLASS__, 'popup_get_close' ], 10, 2 );
[28] Fix | Delete
add_filter( 'pum_popup_get_triggers', [ __CLASS__, 'popup_get_triggers' ], 10, 2 );
[29] Fix | Delete
add_filter( 'pum_popup_get_cookies', [ __CLASS__, 'popup_get_cookies' ], 10, 2 );
[30] Fix | Delete
add_filter( 'pum_popup_get_conditions', [ __CLASS__, 'popup_get_conditions' ], 10, 2 );
[31] Fix | Delete
add_filter( 'pum_popup_get_theme_id', [ __CLASS__, 'popup_get_theme_id' ], 10, 2 );
[32] Fix | Delete
add_filter( 'pum_popup_mobile_disabled', [ __CLASS__, 'popup_mobile_disabled' ], 10, 2 );
[33] Fix | Delete
add_filter( 'pum_popup_tablet_disabled', [ __CLASS__, 'popup_tablet_disabled' ], 10, 2 );
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* @param $popup
[38] Fix | Delete
* @param null $popup_id
[39] Fix | Delete
*
[40] Fix | Delete
* @return \PUM_Model_Popup
[41] Fix | Delete
*/
[42] Fix | Delete
public static function pum_popup( $popup, $popup_id = null ) {
[43] Fix | Delete
if ( self::is_new_popup_translation( $popup_id ) ) {
[44] Fix | Delete
remove_filter( 'pum_popup', [ __CLASS__, 'pum_popup' ], 10 );
[45] Fix | Delete
$popup = pum_get_popup( self::source_id( $popup_id ) );
[46] Fix | Delete
add_filter( 'pum_popup', [ __CLASS__, 'pum_popup' ], 10, 2 );
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
return $popup;
[50] Fix | Delete
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* @param int $post_id
[55] Fix | Delete
*
[56] Fix | Delete
* @return bool
[57] Fix | Delete
*/
[58] Fix | Delete
public static function is_new_popup_translation( $post_id = 0 ) {
[59] Fix | Delete
global $pagenow, $sitepress;
[60] Fix | Delete
[61] Fix | Delete
return is_admin() && 'post-new.php' === $pagenow && ! empty( $_GET['post_type'] ) && 'popup' === $_GET['post_type'] && self::source_id( $post_id ) > 0;
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* @param int $post_id
[66] Fix | Delete
*
[67] Fix | Delete
* @return int
[68] Fix | Delete
*/
[69] Fix | Delete
public static function source_id( $post_id = 0 ) {
[70] Fix | Delete
global $sitepress;
[71] Fix | Delete
[72] Fix | Delete
static $source_id;
[73] Fix | Delete
[74] Fix | Delete
if ( ! isset( $source_id ) && ! empty( $sitepress ) && method_exists( $sitepress, 'get_new_post_source_id' ) ) {
[75] Fix | Delete
$source_id = absint( $sitepress->get_new_post_source_id( $post_id ) );
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
return $source_id;
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* @param int $post_id
[83] Fix | Delete
*/
[84] Fix | Delete
public static function source_lang( $post_id = 0 ) {
[85] Fix | Delete
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* @param int $post_id
[90] Fix | Delete
*
[91] Fix | Delete
* @return int
[92] Fix | Delete
*/
[93] Fix | Delete
public static function trid( $post_id = 0 ) {
[94] Fix | Delete
global $sitepress;
[95] Fix | Delete
[96] Fix | Delete
static $trid;
[97] Fix | Delete
[98] Fix | Delete
if ( ! isset( $trid ) && ! empty( $sitepress ) && method_exists( $sitepress, 'get_element_trid' ) ) {
[99] Fix | Delete
$trid = absint( $sitepress->get_element_trid( $post_id, 'post_popup' ) );
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
return $trid;
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
/**
[106] Fix | Delete
* @param $disabled
[107] Fix | Delete
* @param $post_id
[108] Fix | Delete
*
[109] Fix | Delete
* @return bool
[110] Fix | Delete
*/
[111] Fix | Delete
public static function popup_mobile_disabled( $disabled, $post_id ) {
[112] Fix | Delete
if ( self::is_new_popup_translation( $post_id ) ) {
[113] Fix | Delete
remove_filter( 'pum_popup_mobile_disabled', [ __CLASS__, 'popup_mobile_disabled' ], 10 );
[114] Fix | Delete
$disabled = pum_get_popup( self::source_id( $post_id ) )->mobile_disabled();
[115] Fix | Delete
add_filter( 'pum_popup_mobile_disabled', [ __CLASS__, 'popup_mobile_disabled' ], 10, 2 );
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
return $disabled;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* @param $disabled
[123] Fix | Delete
* @param $post_id
[124] Fix | Delete
*
[125] Fix | Delete
* @return bool
[126] Fix | Delete
*/
[127] Fix | Delete
public static function popup_tablet_disabled( $disabled, $post_id ) {
[128] Fix | Delete
if ( self::is_new_popup_translation( $post_id ) ) {
[129] Fix | Delete
remove_filter( 'pum_popup_tablet_disabled', [ __CLASS__, 'popup_tablet_disabled' ], 10 );
[130] Fix | Delete
$disabled = pum_get_popup( self::source_id( $post_id ) )->tablet_disabled();
[131] Fix | Delete
add_filter( 'pum_popup_tablet_disabled', [ __CLASS__, 'popup_tablet_disabled' ], 10, 2 );
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
return $disabled;
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* @param $triggers
[139] Fix | Delete
* @param $post_id
[140] Fix | Delete
*
[141] Fix | Delete
* @return array
[142] Fix | Delete
*/
[143] Fix | Delete
public static function popup_get_triggers( $triggers, $post_id ) {
[144] Fix | Delete
if ( self::is_new_popup_translation( $post_id ) ) {
[145] Fix | Delete
remove_filter( 'pum_popup_get_triggers', [ __CLASS__, 'popup_get_triggers' ], 10 );
[146] Fix | Delete
$triggers = pum_get_popup( self::source_id( $post_id ) )->get_triggers();
[147] Fix | Delete
add_filter( 'pum_popup_get_triggers', [ __CLASS__, 'popup_get_triggers' ], 10, 2 );
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
return $triggers;
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* @param $display
[155] Fix | Delete
* @param $post_id
[156] Fix | Delete
*
[157] Fix | Delete
* @return mixed
[158] Fix | Delete
*/
[159] Fix | Delete
public static function popup_get_display( $display, $post_id ) {
[160] Fix | Delete
if ( self::is_new_popup_translation( $post_id ) ) {
[161] Fix | Delete
remove_filter( 'pum_popup_get_display', [ __CLASS__, 'popup_get_display' ], 10 );
[162] Fix | Delete
$display = pum_get_popup( self::source_id( $post_id ) )->get_display();
[163] Fix | Delete
add_filter( 'pum_popup_get_display', [ __CLASS__, 'popup_get_display' ], 10, 2 );
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
return $display;
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* @param $close
[171] Fix | Delete
* @param $post_id
[172] Fix | Delete
*
[173] Fix | Delete
* @return mixed
[174] Fix | Delete
*/
[175] Fix | Delete
public static function popup_get_close( $close, $post_id ) {
[176] Fix | Delete
if ( self::is_new_popup_translation( $post_id ) ) {
[177] Fix | Delete
remove_filter( 'pum_popup_get_close', [ __CLASS__, 'popup_get_close' ], 10 );
[178] Fix | Delete
$close = pum_get_popup( self::source_id( $post_id ) )->get_close();
[179] Fix | Delete
add_filter( 'pum_popup_get_close', [ __CLASS__, 'popup_get_close' ], 10, 2 );
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
return $close;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* @param $cookies
[187] Fix | Delete
* @param $post_id
[188] Fix | Delete
*
[189] Fix | Delete
* @return array
[190] Fix | Delete
*/
[191] Fix | Delete
public static function popup_get_cookies( $cookies, $post_id ) {
[192] Fix | Delete
if ( self::is_new_popup_translation( $post_id ) ) {
[193] Fix | Delete
remove_filter( 'pum_popup_get_cookies', [ __CLASS__, 'popup_get_cookies' ], 10 );
[194] Fix | Delete
$cookies = pum_get_popup( self::source_id( $post_id ) )->get_cookies();
[195] Fix | Delete
add_filter( 'pum_popup_get_cookies', [ __CLASS__, 'popup_get_cookies' ], 10, 2 );
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
return $cookies;
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
/**
[202] Fix | Delete
* @param $theme_id
[203] Fix | Delete
* @param $post_id
[204] Fix | Delete
*
[205] Fix | Delete
* @return int
[206] Fix | Delete
*/
[207] Fix | Delete
public static function popup_get_theme_id( $theme_id, $post_id ) {
[208] Fix | Delete
if ( self::is_new_popup_translation( $post_id ) ) {
[209] Fix | Delete
remove_filter( 'pum_popup_get_theme_id', [ __CLASS__, 'popup_get_theme_id' ], 10 );
[210] Fix | Delete
$theme_id = pum_get_popup( self::source_id( $post_id ) )->get_theme_id();
[211] Fix | Delete
add_filter( 'pum_popup_get_theme_id', [ __CLASS__, 'popup_get_theme_id' ], 10, 2 );
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
return $theme_id;
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
/**
[218] Fix | Delete
* @param $conditions
[219] Fix | Delete
* @param null $new_lang
[220] Fix | Delete
*
[221] Fix | Delete
* @return mixed
[222] Fix | Delete
*/
[223] Fix | Delete
public static function remap_conditions( $conditions, $new_lang = null ) {
[224] Fix | Delete
if ( ! isset( $new_lang ) && empty( $_GET['lang'] ) ) {
[225] Fix | Delete
return $conditions;
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
if ( ! isset( $new_lang ) ) {
[229] Fix | Delete
$new_lang = $_GET['lang'];
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
foreach ( $conditions as $group_key => $group ) {
[233] Fix | Delete
[234] Fix | Delete
foreach ( $group as $key => $condition ) {
[235] Fix | Delete
[236] Fix | Delete
$target = $condition['target'];
[237] Fix | Delete
[238] Fix | Delete
$tests = [
[239] Fix | Delete
strpos( $target, '_selected' ) !== false,
[240] Fix | Delete
strpos( $target, '_ID' ) !== false,
[241] Fix | Delete
strpos( $target, '_children' ) !== false,
[242] Fix | Delete
strpos( $target, '_ancestors' ) !== false,
[243] Fix | Delete
strpos( $target, '_w_' ) !== false,
[244] Fix | Delete
];
[245] Fix | Delete
[246] Fix | Delete
if ( ! in_array( true, $tests ) ) {
[247] Fix | Delete
continue;
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
// Taxonomy
[251] Fix | Delete
if ( strpos( $target, 'tax_' ) === 0 ) {
[252] Fix | Delete
$t = explode( '_', $target );
[253] Fix | Delete
// Remove the tax_ prefix.
[254] Fix | Delete
array_shift( $t );
[255] Fix | Delete
// Assign the last key as the modifier _all, _selected
[256] Fix | Delete
$modifier = array_pop( $t );
[257] Fix | Delete
// Whatever is left is the taxonomy.
[258] Fix | Delete
$type = implode( '_', $t );
[259] Fix | Delete
} // Post by Tax
[260] Fix | Delete
elseif ( strpos( $target, '_w_' ) !== false ) {
[261] Fix | Delete
$t = explode( '_w_', $target );
[262] Fix | Delete
// First key is the post type.
[263] Fix | Delete
$post_type = array_shift( $t );
[264] Fix | Delete
// Last Key is the taxonomy
[265] Fix | Delete
$type = array_pop( $t );
[266] Fix | Delete
} // Post Type
[267] Fix | Delete
else {
[268] Fix | Delete
$t = explode( '_', $target );
[269] Fix | Delete
// Modifier should be the last key.
[270] Fix | Delete
$modifier = array_pop( $t );
[271] Fix | Delete
// Post type is the remaining keys combined.
[272] Fix | Delete
$type = implode( '_', $t );
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
// To hold the newly remapped selection.
[276] Fix | Delete
$selected = [];
[277] Fix | Delete
[278] Fix | Delete
foreach ( wp_parse_id_list( $condition['selected'] ) as $object_id ) {
[279] Fix | Delete
// Insert the translated post_id or the original if no translation exists.
[280] Fix | Delete
$selected[] = wpml_object_id_filter( $object_id, $type, true, $new_lang );
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
// Replace the original conditions with the new remapped ones.
[284] Fix | Delete
$conditions[ $group_key ][ $key ]['selected'] = $selected;
[285] Fix | Delete
}
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
return $conditions;
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
/**
[292] Fix | Delete
* @param $conditions
[293] Fix | Delete
* @param $post_id
[294] Fix | Delete
*
[295] Fix | Delete
* @return array|mixed
[296] Fix | Delete
*/
[297] Fix | Delete
public static function popup_get_conditions( $conditions, $post_id ) {
[298] Fix | Delete
if ( self::is_new_popup_translation( $post_id ) ) {
[299] Fix | Delete
remove_filter( 'pum_popup_get_conditions', [ __CLASS__, 'popup_get_conditions' ], 10 );
[300] Fix | Delete
[301] Fix | Delete
$popup = pum_get_popup( self::source_id( $post_id ) );
[302] Fix | Delete
$conditions = $popup->get_conditions();
[303] Fix | Delete
[304] Fix | Delete
$conditions = self::remap_conditions( $conditions, $post_id );
[305] Fix | Delete
[306] Fix | Delete
add_filter( 'pum_popup_get_conditions', [ __CLASS__, 'popup_get_conditions' ], 10, 2 );
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
return $conditions;
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
/**
[313] Fix | Delete
* @return mixed|void
[314] Fix | Delete
*/
[315] Fix | Delete
public static function untranslatable_meta_keys() {
[316] Fix | Delete
return apply_filters(
[317] Fix | Delete
'pum_wpml_untranslatable_meta_keys',
[318] Fix | Delete
[
[319] Fix | Delete
'popup_display',
[320] Fix | Delete
'popup_theme',
[321] Fix | Delete
'popup_triggers',
[322] Fix | Delete
'popup_cookies',
[323] Fix | Delete
'popup_conditions',
[324] Fix | Delete
'popup_mobile_disabled',
[325] Fix | Delete
'popup_tablet_disabled',
[326] Fix | Delete
]
[327] Fix | Delete
);
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
[331] Fix | Delete
/**
[332] Fix | Delete
* @return mixed|void
[333] Fix | Delete
*/
[334] Fix | Delete
public static function translatable_meta_keys() {
[335] Fix | Delete
return apply_filters(
[336] Fix | Delete
'pum_wpml_translatable_meta_keys',
[337] Fix | Delete
[
[338] Fix | Delete
'popup_close',
[339] Fix | Delete
'popup_title',
[340] Fix | Delete
]
[341] Fix | Delete
);
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
[345] Fix | Delete
/**
[346] Fix | Delete
* Copies post_meta for popups on duplication.
[347] Fix | Delete
*
[348] Fix | Delete
* Only copies untranslatable data.
[349] Fix | Delete
*
[350] Fix | Delete
* @param $master_post_id int Original post_ID.
[351] Fix | Delete
* @param $lang string The new language.
[352] Fix | Delete
* @param post_array array The $post array for the new/duplicate post.
[353] Fix | Delete
* @param $id int The post_ID for the new/duplicate post.
[354] Fix | Delete
*/
[355] Fix | Delete
public static function duplicate_post( $master_post_id, $lang, $post_array, $id ) {
[356] Fix | Delete
// Only do this for popups.
[357] Fix | Delete
if ( get_post_type( $master_post_id ) !== 'popup' ) {
[358] Fix | Delete
return;
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
foreach ( self::untranslatable_meta_keys() as $key ) {
[362] Fix | Delete
$value = get_post_meta( $master_post_id, $key, true );
[363] Fix | Delete
if ( ! $value ) {
[364] Fix | Delete
continue;
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
if ( 'popup_conditions' === $key ) {
[368] Fix | Delete
$value = self::remap_conditions( $value, $lang );
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
update_post_meta( $id, $key, $value );
[372] Fix | Delete
}
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
}
[376] Fix | Delete
[377] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function