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-synchronization.class.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Class WPML_Post_Synchronization
[3] Fix | Delete
*
[4] Fix | Delete
* @package wpml-core
[5] Fix | Delete
* @subpackage post-translation
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
class WPML_Post_Synchronization extends WPML_SP_And_PT_User {
[9] Fix | Delete
[10] Fix | Delete
/** @var bool[] */
[11] Fix | Delete
private $sync_parent_cpt = array();
[12] Fix | Delete
/** @var $sync_parent bool */
[13] Fix | Delete
private $sync_parent;
[14] Fix | Delete
/** @var $sync_delete bool */
[15] Fix | Delete
private $sync_delete;
[16] Fix | Delete
/** @var $sync_ping_status bool */
[17] Fix | Delete
private $sync_ping_status;
[18] Fix | Delete
/** @var $sync_post_date bool */
[19] Fix | Delete
private $sync_post_date;
[20] Fix | Delete
/** @var $sync_post_format bool */
[21] Fix | Delete
private $sync_post_format;
[22] Fix | Delete
/** @var $sync_comment_status bool */
[23] Fix | Delete
private $sync_comment_status;
[24] Fix | Delete
/** @var $sync_page_template bool */
[25] Fix | Delete
private $sync_page_template;
[26] Fix | Delete
/** @var bool $sync_menu_order */
[27] Fix | Delete
private $sync_menu_order;
[28] Fix | Delete
/** @var $sync_password bool */
[29] Fix | Delete
private $sync_password;
[30] Fix | Delete
/** @var $sync_private_flag bool */
[31] Fix | Delete
private $sync_private_flag;
[32] Fix | Delete
/** @var bool $is_deleting_all_translations */
[33] Fix | Delete
private $is_deleting_all_translations = false;
[34] Fix | Delete
/** @var array $deleted_post_types */
[35] Fix | Delete
private $deleted_post_types = array();
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* @param array $settings
[39] Fix | Delete
* @param WPML_Post_Translation $post_translations
[40] Fix | Delete
* @param SitePress $sitepress
[41] Fix | Delete
*/
[42] Fix | Delete
public function __construct( &$settings, &$post_translations, &$sitepress ) {
[43] Fix | Delete
parent::__construct( $post_translations, $sitepress );
[44] Fix | Delete
$this->sync_delete = isset( $settings[ 'sync_delete' ] ) ? $settings[ 'sync_delete' ] : false;
[45] Fix | Delete
$this->sync_parent = isset( $settings[ 'sync_page_parent' ] ) ? $settings[ 'sync_page_parent' ] : false;
[46] Fix | Delete
$this->sync_ping_status = isset( $settings[ 'sync_ping_status' ] ) ? $settings[ 'sync_ping_status' ] : false;
[47] Fix | Delete
$this->sync_post_date = isset( $settings[ 'sync_post_date' ] ) ? $settings[ 'sync_post_date' ] : false;
[48] Fix | Delete
$this->sync_post_format = isset( $settings[ 'sync_post_format' ] ) ? $settings[ 'sync_post_format' ] : false;
[49] Fix | Delete
$this->sync_comment_status = isset( $settings[ 'sync_comment_status' ] ) ? $settings[ 'sync_comment_status' ] : false;
[50] Fix | Delete
$this->sync_page_template = isset( $settings[ 'sync_page_template' ] ) ? $settings[ 'sync_page_template' ] : false;
[51] Fix | Delete
$this->sync_password = isset( $settings[ 'sync_password' ] ) ? $settings[ 'sync_password' ] : false;
[52] Fix | Delete
$this->sync_private_flag = isset( $settings[ 'sync_private_flag' ] ) ? $settings[ 'sync_private_flag' ] : false;
[53] Fix | Delete
$this->sync_document_status = isset( $settings[ 'translated_document_status' ] ) ? $settings[ 'translated_document_status' ] : 1;
[54] Fix | Delete
$this->sync_menu_order = isset( $settings[ 'sync_page_ordering' ] ) ? $settings[ 'sync_page_ordering' ] : array();
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
private function must_sync_parents( $post_type ) {
[58] Fix | Delete
if ( ! array_key_exists( $post_type, $this->sync_parent_cpt ) ) {
[59] Fix | Delete
$this->sync_parent_cpt[ $post_type ] = apply_filters( 'wpml_sync_parent_for_post_type', $this->sync_parent, $post_type );
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
return $this->sync_parent_cpt[ $post_type ];
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* Fixes parents of translations for hierarchical post types
[67] Fix | Delete
*
[68] Fix | Delete
* User changed parent for a post in $post_type and we are setting proper parent for $translation_id in
[69] Fix | Delete
* $language_code_translated language
[70] Fix | Delete
*
[71] Fix | Delete
* @param string $post_type - post_type that should have the translated parents fixed
[72] Fix | Delete
*/
[73] Fix | Delete
private function maybe_fix_translated_parent( $post_type ) {
[74] Fix | Delete
if ( $this->must_sync_parents( $post_type ) ) {
[75] Fix | Delete
$sync_helper = wpml_get_hierarchy_sync_helper();
[76] Fix | Delete
$sync_helper->sync_element_hierarchy( $post_type );
[77] Fix | Delete
}
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
public function sync_with_duplicates( $post_id ) {
[81] Fix | Delete
$duplicates = $this->sitepress->get_duplicates( $post_id );
[82] Fix | Delete
foreach ( array_keys( $duplicates ) as $lang_code ) {
[83] Fix | Delete
$this->sitepress->make_duplicate( $post_id, $lang_code );
[84] Fix | Delete
}
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* @param int $post_id
[89] Fix | Delete
* @param bool $keep_db_entries
[90] Fix | Delete
*/
[91] Fix | Delete
public function delete_post_actions( $post_id, $keep_db_entries = false ) {
[92] Fix | Delete
$post_type = get_post_type( $post_id );
[93] Fix | Delete
$post_type_exceptions = array( 'nav_menu_item' );
[94] Fix | Delete
if ( in_array( $post_type, $post_type_exceptions ) ) {
[95] Fix | Delete
return;
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
if ( ! $this->is_deleting_all_translations ) {
[99] Fix | Delete
$this->is_deleting_all_translations = ! $this->post_translation->get_original_element( $post_id, true );
[100] Fix | Delete
$trid = $this->post_translation->get_element_trid( $post_id );
[101] Fix | Delete
$translated_ids = $this->get_translations_without_source( $post_id, $trid );
[102] Fix | Delete
$this->delete_translations( $translated_ids, $keep_db_entries );
[103] Fix | Delete
$this->is_deleting_all_translations = false;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
if ( ! $keep_db_entries ) {
[107] Fix | Delete
$this->post_translation->delete_post_translation_entry( $post_id );
[108] Fix | Delete
[109] Fix | Delete
if ( ! $this->is_deleting_all_translations ) {
[110] Fix | Delete
$lang_code = $this->post_translation->get_element_lang_code( $post_id );
[111] Fix | Delete
$this->set_new_original( $trid, $lang_code );
[112] Fix | Delete
}
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
if ( ! $this->is_deleting_all_translations ) {
[116] Fix | Delete
$this->run_final_actions_for_delete_post( $post_type );
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* @param int $post_id
[122] Fix | Delete
* @param int $trid
[123] Fix | Delete
*
[124] Fix | Delete
* @return array
[125] Fix | Delete
*/
[126] Fix | Delete
private function get_translations_without_source( $post_id, $trid ) {
[127] Fix | Delete
$actual_translations_only = ! $this->is_deleting_all_translations;
[128] Fix | Delete
$translated_ids = $this->post_translation->get_element_translations( $post_id, $trid, $actual_translations_only );
[129] Fix | Delete
unset( $translated_ids[ array_search( $post_id, $translated_ids ) ] );
[130] Fix | Delete
return $translated_ids;
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
private function is_bulk_delete() {
[134] Fix | Delete
return ( isset( $_REQUEST['action'] ) && 'delete' === $_REQUEST['action']
[135] Fix | Delete
|| isset( $_REQUEST['action2'] ) && 'delete' === $_REQUEST['action2']
[136] Fix | Delete
) && ( isset( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] )
[137] Fix | Delete
|| isset( $_REQUEST['media'] ) && is_array( $_REQUEST['media'] )
[138] Fix | Delete
);
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
/** @param string $post_type */
[142] Fix | Delete
private function reset_cache( $post_type ) {
[143] Fix | Delete
require_once WPML_PLUGIN_PATH . '/inc/cache.php';
[144] Fix | Delete
icl_cache_clear( $post_type . 's_per_language', true );
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
/** @param string $post_type */
[148] Fix | Delete
private function defer_delete_actions( $post_type ) {
[149] Fix | Delete
if ( ! in_array( $post_type, $this->deleted_post_types, true ) ) {
[150] Fix | Delete
$this->deleted_post_types[] = $post_type;
[151] Fix | Delete
if ( ! has_action( 'shutdown', array( $this, 'shutdown_action' ) ) ) {
[152] Fix | Delete
add_action( 'shutdown', array( $this, 'shutdown_action' ) );
[153] Fix | Delete
}
[154] Fix | Delete
}
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
public function shutdown_action() {
[158] Fix | Delete
$this->post_translation->reload();
[159] Fix | Delete
[160] Fix | Delete
foreach ( $this->deleted_post_types as $post_type ) {
[161] Fix | Delete
$this->reset_cache( $post_type );
[162] Fix | Delete
$this->maybe_fix_translated_parent( $post_type );
[163] Fix | Delete
}
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* @param array $translated_ids
[168] Fix | Delete
* @param bool $keep_db_entries
[169] Fix | Delete
*/
[170] Fix | Delete
private function delete_translations( array $translated_ids, $keep_db_entries ) {
[171] Fix | Delete
if ( $this->sync_delete && ! empty( $translated_ids ) ) {
[172] Fix | Delete
foreach ( $translated_ids as $trans_id ) {
[173] Fix | Delete
if ( ! $this->is_bulk_prevented( $trans_id ) ) {
[174] Fix | Delete
if ( $keep_db_entries ) {
[175] Fix | Delete
$this->post_translation->trash_translation( $trans_id );
[176] Fix | Delete
} else {
[177] Fix | Delete
wp_delete_post( $trans_id, true );
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
}
[181] Fix | Delete
}
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
/** @param string $post_type */
[185] Fix | Delete
private function run_final_actions_for_delete_post( $post_type ) {
[186] Fix | Delete
if ( $this->is_bulk_delete() ) {
[187] Fix | Delete
$this->defer_delete_actions( $post_type );
[188] Fix | Delete
} else {
[189] Fix | Delete
$this->post_translation->reload();
[190] Fix | Delete
$this->reset_cache( $post_type );
[191] Fix | Delete
$this->maybe_fix_translated_parent( $post_type );
[192] Fix | Delete
}
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
private function is_bulk_prevented( $post_id ) {
[196] Fix | Delete
[197] Fix | Delete
return ( isset( $_GET[ 'delete_all' ] ) && $_GET[ 'delete_all' ] === 'Empty Trash' )
[198] Fix | Delete
|| in_array( $post_id, ( isset( $_GET[ 'ids' ] ) ? $_GET[ 'ids' ] : array() ) );
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
function untrashed_post_actions( $post_id ) {
[202] Fix | Delete
if ( $this->sync_delete ) {
[203] Fix | Delete
$translations = $this->post_translation->get_element_translations( $post_id, false, true );
[204] Fix | Delete
foreach ( $translations as $t_id ) {
[205] Fix | Delete
$this->post_translation->untrash_translation( $t_id );
[206] Fix | Delete
}
[207] Fix | Delete
}
[208] Fix | Delete
$post_type = get_post_type( $post_id );
[209] Fix | Delete
require_once WPML_PLUGIN_PATH . '/inc/cache.php';
[210] Fix | Delete
icl_cache_clear( $post_type . 's_per_language', true );
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
public function sync_with_translations( $post_id, $post_vars = false ) {
[214] Fix | Delete
global $wpdb;
[215] Fix | Delete
[216] Fix | Delete
$wp_api = $this->sitepress->get_wp_api();
[217] Fix | Delete
$term_count_update = new WPML_Update_Term_Count( $wp_api );
[218] Fix | Delete
[219] Fix | Delete
$post = get_post ( $post_id );
[220] Fix | Delete
$source_post_status = get_post_status( $post_id );
[221] Fix | Delete
$translated_ids = $this->post_translation->get_element_translations( $post_id, false, true );
[222] Fix | Delete
$post_format = $this->sync_post_format ? get_post_format( $post_id ) : null;
[223] Fix | Delete
$ping_status = $this->sync_ping_status ? ( pings_open( $post_id ) ? 'open' : 'closed' ) : null;
[224] Fix | Delete
$comment_status = $this->sync_comment_status ? ( comments_open( $post_id ) ? 'open' : 'closed' ) : null;
[225] Fix | Delete
$post_password = $this->sync_password ? $post->post_password : null;
[226] Fix | Delete
$menu_order = $this->sync_menu_order && ! empty( $post->menu_order ) ? $post->menu_order : null;
[227] Fix | Delete
$page_template = $this->sync_page_template && get_post_type( $post_id ) === 'page' ? get_post_meta( $post_id, '_wp_page_template', true ) : null;
[228] Fix | Delete
$post_date = $this->sync_post_date ? $wpdb->get_var( $wpdb->prepare( "SELECT post_date FROM {$wpdb->posts} WHERE ID=%d LIMIT 1", $post_id ) ) : null;
[229] Fix | Delete
[230] Fix | Delete
foreach ( $translated_ids as $lang_code => $translated_pid ) {
[231] Fix | Delete
$post_status = get_post_status( $translated_pid );
[232] Fix | Delete
[233] Fix | Delete
$post_status_differs = ( 'private' === $source_post_status && 'publish' === $post_status )
[234] Fix | Delete
|| ( 'publish' === $source_post_status && 'private' === $post_status );
[235] Fix | Delete
if ( $this->sync_private_flag && $post_status_differs ) {
[236] Fix | Delete
$post_status = $source_post_status;
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
$this->sync_custom_fields ( $post_id, $translated_pid );
[240] Fix | Delete
if ( $post_format ) {
[241] Fix | Delete
set_post_format ( $translated_pid, $post_format );
[242] Fix | Delete
}
[243] Fix | Delete
if ( $post_date !== null ) {
[244] Fix | Delete
$post_date_gmt = get_gmt_from_date ( $post_date );
[245] Fix | Delete
$data = array( 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt );
[246] Fix | Delete
$now = gmdate('Y-m-d H:i:59');
[247] Fix | Delete
$allow_post_statuses = array( 'private', 'pending', 'draft' );
[248] Fix | Delete
if ( mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false) ) {
[249] Fix | Delete
if ( ! in_array( $post_status, $allow_post_statuses, true ) ) {
[250] Fix | Delete
$post_status = 'future';
[251] Fix | Delete
}
[252] Fix | Delete
}
[253] Fix | Delete
$data[ 'post_status' ] = $post_status;
[254] Fix | Delete
$wpdb->update ( $wpdb->posts, $data, array( 'ID' => $translated_pid ) );
[255] Fix | Delete
wp_schedule_single_event( strtotime( $post_date_gmt . '+1 second' ), 'publish_future_post', array( $translated_pid ) );
[256] Fix | Delete
}
[257] Fix | Delete
if ( $post_password !== null ) {
[258] Fix | Delete
$wpdb->update ( $wpdb->posts, array( 'post_password' => $post_password ), array( 'ID' => $translated_pid ) );
[259] Fix | Delete
}
[260] Fix | Delete
if ( $post_status !== null && ! in_array( get_post_status( $translated_pid ), array( 'auto-draft', 'draft', 'inherit', 'trash' ) ) ) {
[261] Fix | Delete
$wpdb->update ( $wpdb->posts, array( 'post_status' => $post_status ), array( 'ID' => $translated_pid ) );
[262] Fix | Delete
$term_count_update->update_for_post( $translated_pid );
[263] Fix | Delete
} elseif ( $post_status == null && $this->sync_private_flag && get_post_status( $translated_pid ) === 'private' ) {
[264] Fix | Delete
$wpdb->update ( $wpdb->posts, array( 'post_status' => get_post_status( $post_id ) ), array( 'ID' => $translated_pid ) );
[265] Fix | Delete
$term_count_update->update_for_post( $translated_pid );
[266] Fix | Delete
}
[267] Fix | Delete
if ( $ping_status !== null ) {
[268] Fix | Delete
$wpdb->update ( $wpdb->posts, array( 'ping_status' => $ping_status ), array( 'ID' => $translated_pid ) );
[269] Fix | Delete
}
[270] Fix | Delete
if ( $comment_status !== null ) {
[271] Fix | Delete
$wpdb->update ( $wpdb->posts, array( 'comment_status' => $comment_status ), array( 'ID' => $translated_pid ) );
[272] Fix | Delete
}
[273] Fix | Delete
if ( $page_template !== null ) {
[274] Fix | Delete
update_post_meta ( $translated_pid, '_wp_page_template', $page_template );
[275] Fix | Delete
}
[276] Fix | Delete
$this->sync_with_translations ( $translated_pid );
[277] Fix | Delete
}
[278] Fix | Delete
$this->maybe_fix_translated_parent( get_post_type( $post_id ) );
[279] Fix | Delete
[280] Fix | Delete
if ( $menu_order !== null && (bool) $translated_ids !== false ) {
[281] Fix | Delete
$query = $wpdb->prepare(
[282] Fix | Delete
"UPDATE {$wpdb->posts}
[283] Fix | Delete
SET menu_order=%s
[284] Fix | Delete
WHERE ID IN (" . wpml_prepare_in( $translated_ids, '%d' ) . ')',
[285] Fix | Delete
$menu_order
[286] Fix | Delete
);
[287] Fix | Delete
$wpdb->query( $query );
[288] Fix | Delete
}
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
private function sync_custom_fields( $original_id, $post_id ) {
[292] Fix | Delete
if ( $original_id && $original_id != $post_id ) {
[293] Fix | Delete
$this->sitepress->copy_custom_fields ( $original_id, $post_id );
[294] Fix | Delete
} else {
[295] Fix | Delete
$translations = $this->post_translation->get_element_translations ( $post_id, false, true );
[296] Fix | Delete
foreach ( $translations as $t_id ) {
[297] Fix | Delete
$this->sitepress->copy_custom_fields ( $post_id, $t_id );
[298] Fix | Delete
}
[299] Fix | Delete
}
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
private function set_new_original( $trid, $removed_lang_code ) {
[303] Fix | Delete
if ( $trid && $removed_lang_code ) {
[304] Fix | Delete
$priorities = $this->sitepress->get_setting( 'languages_order' );
[305] Fix | Delete
$this->post_translation->reload();
[306] Fix | Delete
$translations = $this->post_translation->get_element_translations( false, $trid );
[307] Fix | Delete
$new_source_lang_code = false;
[308] Fix | Delete
foreach ( $priorities as $lang_code ) {
[309] Fix | Delete
if ( isset( $translations[ $lang_code ] ) ) {
[310] Fix | Delete
$new_source_lang_code = $lang_code;
[311] Fix | Delete
break;
[312] Fix | Delete
}
[313] Fix | Delete
}
[314] Fix | Delete
if ( $new_source_lang_code ) {
[315] Fix | Delete
global $wpdb;
[316] Fix | Delete
[317] Fix | Delete
$rows_updated = $wpdb->update( $wpdb->prefix . 'icl_translations',
[318] Fix | Delete
array( 'source_language_code' => $new_source_lang_code ),
[319] Fix | Delete
array( 'trid' => $trid, 'source_language_code' => $removed_lang_code )
[320] Fix | Delete
);
[321] Fix | Delete
[322] Fix | Delete
if( 0 < $rows_updated ) {
[323] Fix | Delete
do_action( 'wpml_translation_update', array( 'trid' => $trid ) );
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
$wpdb->query( " UPDATE {$wpdb->prefix}icl_translations
[327] Fix | Delete
SET source_language_code = NULL
[328] Fix | Delete
WHERE language_code = source_language_code" );
[329] Fix | Delete
}
[330] Fix | Delete
}
[331] Fix | Delete
}
[332] Fix | Delete
}
[333] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function