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/post-tra...
File: wpml-post-translation.class.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Class WPML_Post_Translation
[3] Fix | Delete
*
[4] Fix | Delete
* @package wpml-core
[5] Fix | Delete
* @subpackage post-translation
[6] Fix | Delete
*/
[7] Fix | Delete
abstract class WPML_Post_Translation extends WPML_Element_Translation {
[8] Fix | Delete
[9] Fix | Delete
protected $settings;
[10] Fix | Delete
protected $post_translation_sync;
[11] Fix | Delete
public static $defer_term_counting = false;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* @var WPML_Debug_BackTrace
[15] Fix | Delete
*/
[16] Fix | Delete
private $debug_backtrace;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* @param array $settings
[20] Fix | Delete
* @param wpdb $wpdb
[21] Fix | Delete
*/
[22] Fix | Delete
public function __construct( &$settings, &$wpdb ) {
[23] Fix | Delete
parent::__construct( $wpdb );
[24] Fix | Delete
$this->settings = $settings;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
protected function is_setup_complete( ) {
[28] Fix | Delete
return isset( $this->settings[ 'setup_complete' ]) && $this->settings[ 'setup_complete' ];
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
public function init() {
[32] Fix | Delete
if ( $this->is_setup_complete() ) {
[33] Fix | Delete
add_action( 'save_post', array( $this, 'save_post_actions' ), 100, 2 );
[34] Fix | Delete
add_action( 'shutdown', array( $this, 'shutdown_action' ), PHP_INT_MAX );
[35] Fix | Delete
}
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
public function get_original_post_status( $trid, $source_lang_code = null ) {
[39] Fix | Delete
[40] Fix | Delete
return $this->get_original_post_attr ( $trid, 'post_status', $source_lang_code );
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
public function get_original_post_ID( $trid, $source_lang_code = null ) {
[44] Fix | Delete
[45] Fix | Delete
return $this->get_original_post_attr ( $trid, 'ID', $source_lang_code );
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
public function get_original_menu_order
[49] Fix | Delete
( $trid, $source_lang_code = null ) {
[50] Fix | Delete
[51] Fix | Delete
return $this->get_original_post_attr ( $trid, 'menu_order', $source_lang_code );
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
public function get_original_comment_status( $trid, $source_lang_code = null ) {
[55] Fix | Delete
[56] Fix | Delete
return $this->get_original_post_attr ( $trid, 'comment_status', $source_lang_code );
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
public function get_original_ping_status( $trid, $source_lang_code = null ) {
[60] Fix | Delete
[61] Fix | Delete
return $this->get_original_post_attr ( $trid, 'ping_status', $source_lang_code );
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
public function get_original_post_format( $trid, $source_lang_code = null ) {
[65] Fix | Delete
[66] Fix | Delete
return get_post_format ( $this->get_original_post_ID ( $trid, $source_lang_code ) );
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* @param int $pidd
[71] Fix | Delete
* @param WP_Post $post
[72] Fix | Delete
*
[73] Fix | Delete
* @return void
[74] Fix | Delete
*/
[75] Fix | Delete
public abstract function save_post_actions( $pidd, $post );
[76] Fix | Delete
[77] Fix | Delete
public function shutdown_action() {
[78] Fix | Delete
if ( self::$defer_term_counting ) {
[79] Fix | Delete
self::$defer_term_counting = false;
[80] Fix | Delete
wp_defer_term_counting( false );
[81] Fix | Delete
}
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
public function trash_translation ( $trans_id ) {
[85] Fix | Delete
if ( !WPML_WordPress_Actions::is_bulk_trash( $trans_id ) ) {
[86] Fix | Delete
wp_trash_post( $trans_id );
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
public function untrash_translation( $trans_id ) {
[91] Fix | Delete
if ( ! WPML_WordPress_Actions::is_bulk_untrash( $trans_id ) ) {
[92] Fix | Delete
wp_untrash_post( $trans_id );
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
function untrashed_post_actions( $post_id ) {
[97] Fix | Delete
$translation_sync = $this->get_sync_helper ();
[98] Fix | Delete
$translation_sync->untrashed_post_actions ( $post_id );
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
public function delete_post_translation_entry( $post_id ) {
[102] Fix | Delete
[103] Fix | Delete
$update_args = array( 'context' => 'post', 'element_id' => $post_id );
[104] Fix | Delete
do_action( 'wpml_translation_update', array_merge( $update_args, array( 'type' => 'before_delete' ) ) );
[105] Fix | Delete
[106] Fix | Delete
$sql = $this->wpdb->prepare( "DELETE FROM {$this->wpdb->prefix}icl_translations
[107] Fix | Delete
WHERE element_id = %d
[108] Fix | Delete
AND element_type LIKE 'post%%'
[109] Fix | Delete
LIMIT 1",
[110] Fix | Delete
$post_id );
[111] Fix | Delete
$res = $this->wpdb->query( $sql );
[112] Fix | Delete
[113] Fix | Delete
do_action( 'wpml_translation_update', array_merge( $update_args, array( 'type' => 'after_delete' ) ) );
[114] Fix | Delete
[115] Fix | Delete
return $res;
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
public function trashed_post_actions( $post_id ) {
[119] Fix | Delete
$this->delete_post_actions( $post_id, true );
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* This function holds all actions to be run after deleting a post.
[124] Fix | Delete
* 1. Delete the posts entry in icl_translations.
[125] Fix | Delete
* 2. Set one of the posts translations or delete all translations of the post, depending on sitepress settings.
[126] Fix | Delete
*
[127] Fix | Delete
* @param Integer $post_id
[128] Fix | Delete
* @param bool $keep_db_entries Sets whether icl_translations entries are to be deleted or kept, when hooking this to
[129] Fix | Delete
* post trashing we want them to be kept.
[130] Fix | Delete
*/
[131] Fix | Delete
public function delete_post_actions( $post_id, $keep_db_entries = false ) {
[132] Fix | Delete
$translation_sync = $this->get_sync_helper ();
[133] Fix | Delete
$translation_sync->delete_post_actions ( $post_id, $keep_db_entries );
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* @param int $post_id
[138] Fix | Delete
* @param string $post_status
[139] Fix | Delete
*
[140] Fix | Delete
* @return null|int
[141] Fix | Delete
*/
[142] Fix | Delete
abstract function get_save_post_trid( $post_id, $post_status );
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* @param integer $post_id
[146] Fix | Delete
* @param SitePress $sitepress
[147] Fix | Delete
* @return bool|mixed|null|string|void
[148] Fix | Delete
*/
[149] Fix | Delete
public function get_save_post_lang( $post_id, $sitepress ) {
[150] Fix | Delete
$language_code = $this->get_element_lang_code ( $post_id );
[151] Fix | Delete
$language_code = $language_code ? $language_code : $sitepress->get_current_language ();
[152] Fix | Delete
$language_code = $sitepress->is_active_language ( $language_code ) ? $language_code
[153] Fix | Delete
: $sitepress->get_default_language ();
[154] Fix | Delete
[155] Fix | Delete
return apply_filters ( 'wpml_save_post_lang', $language_code );
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
/**
[159] Fix | Delete
* @param int $trid
[160] Fix | Delete
* @param string $language_code
[161] Fix | Delete
* @param string $default_language
[162] Fix | Delete
*
[163] Fix | Delete
* @return string|null
[164] Fix | Delete
*/
[165] Fix | Delete
protected abstract function get_save_post_source_lang( $trid, $language_code, $default_language );
[166] Fix | Delete
[167] Fix | Delete
/**
[168] Fix | Delete
* Sets a posts language details, invalidates caches relating to the post and triggers
[169] Fix | Delete
* synchronisation actions across translations of the just saved post.
[170] Fix | Delete
*
[171] Fix | Delete
* @param int $trid
[172] Fix | Delete
* @param array $post_vars
[173] Fix | Delete
* @param string $language_code
[174] Fix | Delete
* @param string $source_language
[175] Fix | Delete
*
[176] Fix | Delete
* @used-by \WPML_Post_Translation::save_post_actions as final step of the WPML Core save_post actions
[177] Fix | Delete
*/
[178] Fix | Delete
protected function after_save_post( $trid, $post_vars, $language_code, $source_language ) {
[179] Fix | Delete
$this->maybe_set_elid( $trid, $post_vars['post_type'], $language_code, $post_vars['ID'], $source_language );
[180] Fix | Delete
$translation_sync = $this->get_sync_helper();
[181] Fix | Delete
$original_id = $this->get_original_element( $post_vars['ID'] );
[182] Fix | Delete
$translation_sync->sync_with_translations( $original_id ? $original_id : $post_vars['ID'], $post_vars );
[183] Fix | Delete
$translation_sync->sync_with_duplicates( $post_vars['ID'] );
[184] Fix | Delete
if ( ! function_exists( 'icl_cache_clear' ) ) {
[185] Fix | Delete
require_once WPML_PLUGIN_PATH . '/inc/cache.php';
[186] Fix | Delete
}
[187] Fix | Delete
icl_cache_clear( $post_vars['post_type'] . 's_per_language', true );
[188] Fix | Delete
if ( ! in_array( $post_vars['post_type'], array( 'nav_menu_item', 'attachment' ), true ) ) {
[189] Fix | Delete
do_action( 'wpml_tm_save_post', $post_vars['ID'], get_post( $post_vars['ID'] ), false );
[190] Fix | Delete
}
[191] Fix | Delete
// Flush object cache.
[192] Fix | Delete
$this->flush_object_cache_for_groups( array( 'ls_languages', 'element_translations' ) );
[193] Fix | Delete
[194] Fix | Delete
do_action( 'wpml_after_save_post', $post_vars['ID'], $trid, $language_code, $source_language );
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* Create new instance of WPML_WP_Cache for each group and flush cache for group.
[199] Fix | Delete
* @param array $groups
[200] Fix | Delete
*/
[201] Fix | Delete
private function flush_object_cache_for_groups( $groups = array() ) {
[202] Fix | Delete
if ( ! empty( $groups ) ) {
[203] Fix | Delete
foreach ( $groups as $group ) {
[204] Fix | Delete
$cache = new WPML_WP_Cache( $group );
[205] Fix | Delete
$cache->flush_group_cache();
[206] Fix | Delete
}
[207] Fix | Delete
}
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
private function get_original_post_attr( $trid, $attribute, $source_lang_code ) {
[211] Fix | Delete
$legal_attributes = array(
[212] Fix | Delete
'post_status',
[213] Fix | Delete
'post_date',
[214] Fix | Delete
'menu_order',
[215] Fix | Delete
'comment_status',
[216] Fix | Delete
'ping_status',
[217] Fix | Delete
'ID'
[218] Fix | Delete
);
[219] Fix | Delete
$res = false;
[220] Fix | Delete
if ( in_array ( $attribute, $legal_attributes, true ) ) {
[221] Fix | Delete
$attribute = 'p.' . $attribute;
[222] Fix | Delete
$source_snippet = $source_lang_code === null
[223] Fix | Delete
? " AND wpml_translations.source_language_code IS NULL "
[224] Fix | Delete
: $this->wpdb->prepare ( " AND wpml_translations.language_code = %s ", $source_lang_code );
[225] Fix | Delete
$res = $this->wpdb->get_var (
[226] Fix | Delete
$this->wpdb->prepare (
[227] Fix | Delete
"SELECT {$attribute}
[228] Fix | Delete
" . $this->get_element_join() . "
[229] Fix | Delete
WHERE wpml_translations.trid=%d
[230] Fix | Delete
{$source_snippet}
[231] Fix | Delete
LIMIT 1",
[232] Fix | Delete
$trid
[233] Fix | Delete
)
[234] Fix | Delete
);
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
return $res;
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
public function has_save_post_action( $post ) {
[241] Fix | Delete
if ( ! $post ) {
[242] Fix | Delete
return false;
[243] Fix | Delete
}
[244] Fix | Delete
$is_auto_draft = isset( $post->post_status ) && $post->post_status === 'auto-draft';
[245] Fix | Delete
$is_editing_different_post = $this->is_editing_different_post( $post->ID );
[246] Fix | Delete
$is_saving_a_revision = array_key_exists( 'post_type', $_POST ) && 'revision' === $_POST['post_type'];
[247] Fix | Delete
$is_untrashing = array_key_exists( 'action', $_GET ) && 'untrash' === $_GET['action'];
[248] Fix | Delete
$is_auto_save = array_key_exists( 'autosave', $_POST );
[249] Fix | Delete
$skip_sitepress_actions = array_key_exists( 'skip_sitepress_actions', $_POST );
[250] Fix | Delete
$is_post_a_revision = 'revision' === $post->post_type;
[251] Fix | Delete
$is_scheduled_to_be_trashed = get_post_meta( $post->ID, '_wp_trash_meta_status', true );
[252] Fix | Delete
$is_add_meta_action = isset( $_POST['action'] ) && 'add-meta' === $_POST['action'];
[253] Fix | Delete
$is_inner_post_insertion = $this->is_inner_post_insertion();
[254] Fix | Delete
[255] Fix | Delete
return $this->is_translated_type( $post->post_type )
[256] Fix | Delete
&& ! ( $is_auto_draft
[257] Fix | Delete
|| $is_auto_save
[258] Fix | Delete
|| $skip_sitepress_actions
[259] Fix | Delete
|| ( $is_editing_different_post && ! $is_inner_post_insertion )
[260] Fix | Delete
|| $is_saving_a_revision
[261] Fix | Delete
|| $is_post_a_revision
[262] Fix | Delete
|| $is_scheduled_to_be_trashed
[263] Fix | Delete
|| $is_add_meta_action
[264] Fix | Delete
|| $is_untrashing );
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
/**
[268] Fix | Delete
* @param int $post_id
[269] Fix | Delete
*
[270] Fix | Delete
* @return bool
[271] Fix | Delete
*/
[272] Fix | Delete
protected function is_editing_different_post( $post_id ) {
[273] Fix | Delete
return array_key_exists( 'post_ID', $_POST ) && (int) $_POST['post_ID'] && $post_id != $_POST['post_ID'];
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
protected function get_element_join() {
[277] Fix | Delete
[278] Fix | Delete
return "FROM {$this->wpdb->prefix}icl_translations wpml_translations
[279] Fix | Delete
JOIN {$this->wpdb->posts} p
[280] Fix | Delete
ON wpml_translations.element_id = p.ID
[281] Fix | Delete
AND wpml_translations.element_type = CONCAT('post_', p.post_type)";
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
protected function get_type_prefix() {
[285] Fix | Delete
return 'post_';
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
[289] Fix | Delete
public function is_translated_type( $post_type ) {
[290] Fix | Delete
global $sitepress;
[291] Fix | Delete
[292] Fix | Delete
return $sitepress->is_translated_post_type ( $post_type );
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
/**
[296] Fix | Delete
* @param WP_Post $post
[297] Fix | Delete
*
[298] Fix | Delete
* @return string[] all language codes the post can be translated into
[299] Fix | Delete
*/
[300] Fix | Delete
public function get_allowed_target_langs( $post ) {
[301] Fix | Delete
global $sitepress;
[302] Fix | Delete
[303] Fix | Delete
$active_languages = $sitepress->get_active_languages ();
[304] Fix | Delete
$can_translate = array_keys ( $active_languages );
[305] Fix | Delete
$can_translate = array_diff (
[306] Fix | Delete
$can_translate,
[307] Fix | Delete
array( $this->get_element_lang_code ( $post->ID ) )
[308] Fix | Delete
);
[309] Fix | Delete
[310] Fix | Delete
return apply_filters ( 'wpml_allowed_target_langs', $can_translate, $post->ID, 'post' );
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
/**
[314] Fix | Delete
* Before setting the language of the post to be saved, check if a translation in this language already exists
[315] Fix | Delete
* This check is necessary, so that synchronization actions like thrashing or un-trashing of posts, do not lead to
[316] Fix | Delete
* database corruption, due to erroneously changing a posts language into a state,
[317] Fix | Delete
* where it collides with an existing translation. While the UI prevents this sort of action for the most part,
[318] Fix | Delete
* this is not necessarily the case for other plugins like TM.
[319] Fix | Delete
* The logic here first of all checks if an existing translation id is present in the desired language_code.
[320] Fix | Delete
* If so but this translation is actually not the currently to be saved post,
[321] Fix | Delete
* then this post will be saved to its current language. If the translation already exists,
[322] Fix | Delete
* the existing translation id will be used. In all other cases a new entry in icl_translations will be created.
[323] Fix | Delete
*
[324] Fix | Delete
* @param Integer $trid
[325] Fix | Delete
* @param String $post_type
[326] Fix | Delete
* @param String $language_code
[327] Fix | Delete
* @param Integer $post_id
[328] Fix | Delete
* @param String $source_language
[329] Fix | Delete
*/
[330] Fix | Delete
private function maybe_set_elid( $trid, $post_type, $language_code, $post_id, $source_language ) {
[331] Fix | Delete
global $sitepress;
[332] Fix | Delete
[333] Fix | Delete
$element_type = 'post_' . $post_type;
[334] Fix | Delete
$sitepress->set_element_language_details (
[335] Fix | Delete
$post_id,
[336] Fix | Delete
$element_type,
[337] Fix | Delete
$trid,
[338] Fix | Delete
$language_code,
[339] Fix | Delete
$source_language
[340] Fix | Delete
);
[341] Fix | Delete
}
[342] Fix | Delete
[343] Fix | Delete
/**
[344] Fix | Delete
* @return WPML_Post_Synchronization
[345] Fix | Delete
*/
[346] Fix | Delete
private function get_sync_helper() {
[347] Fix | Delete
global $sitepress;
[348] Fix | Delete
[349] Fix | Delete
$this->post_translation_sync = $this->post_translation_sync
[350] Fix | Delete
? $this->post_translation_sync : new WPML_Post_Synchronization( $this->settings, $this, $sitepress );
[351] Fix | Delete
[352] Fix | Delete
return $this->post_translation_sync;
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
/**
[356] Fix | Delete
* @return WPML_Debug_BackTrace
[357] Fix | Delete
*/
[358] Fix | Delete
private function get_debug_backtrace() {
[359] Fix | Delete
if ( ! $this->debug_backtrace ) {
[360] Fix | Delete
$this->debug_backtrace = new WPML\Utils\DebugBackTrace( 20 );
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
return $this->debug_backtrace;
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
public function set_debug_backtrace( WPML_Debug_BackTrace $debug_backtrace ) {
[367] Fix | Delete
$this->debug_backtrace = $debug_backtrace;
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
/**
[371] Fix | Delete
* @return bool
[372] Fix | Delete
*/
[373] Fix | Delete
protected function is_inner_post_insertion() {
[374] Fix | Delete
$debug_backtrace = $this->get_debug_backtrace();
[375] Fix | Delete
return 1 < $debug_backtrace->count_function_in_call_stack( 'wp_insert_post' );
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
/**
[379] Fix | Delete
* @param WP_Post $post
[380] Fix | Delete
*
[381] Fix | Delete
* @return array
[382] Fix | Delete
*/
[383] Fix | Delete
protected function get_post_vars( $post ) {
[384] Fix | Delete
$post_vars = array();
[385] Fix | Delete
[386] Fix | Delete
if ( ! $this->is_inner_post_insertion() ) {
[387] Fix | Delete
$post_vars = (array) $_POST;
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
foreach ( (array) $post as $k => $v ) {
[391] Fix | Delete
$post_vars[ $k ] = $v;
[392] Fix | Delete
}
[393] Fix | Delete
[394] Fix | Delete
$post_vars['post_type'] = isset( $post_vars['post_type'] ) ? $post_vars['post_type'] : $post->post_type;
[395] Fix | Delete
[396] Fix | Delete
return $post_vars;
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
/**
[400] Fix | Delete
* @param bool $defer
[401] Fix | Delete
*/
[402] Fix | Delete
protected function defer_term_counting() {
[403] Fix | Delete
if ( ! self::$defer_term_counting ) {
[404] Fix | Delete
self::$defer_term_counting = true;
[405] Fix | Delete
wp_defer_term_counting( true );
[406] Fix | Delete
}
[407] Fix | Delete
}
[408] Fix | Delete
[409] Fix | Delete
/**
[410] Fix | Delete
* @return self|WPML_Frontend_Post_Actions|WPML_Admin_Post_Actions
[411] Fix | Delete
*/
[412] Fix | Delete
public static function getGlobalInstance() {
[413] Fix | Delete
global $wpml_post_translations, $sitepress;
[414] Fix | Delete
[415] Fix | Delete
if ( ! isset( $wpml_post_translations ) ) {
[416] Fix | Delete
wpml_load_post_translation( is_admin(), $sitepress->get_settings() );
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
return $wpml_post_translations;
[420] Fix | Delete
}
[421] Fix | Delete
}
[422] Fix | Delete
[423] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function