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
File: wpml-post-comments.class.php
<?php
[0] Fix | Delete
[1] Fix | Delete
class WPML_Post_Comments extends WPML_WPDB_User {
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* @param wpdb $wpdb
[5] Fix | Delete
*/
[6] Fix | Delete
public function __construct( &$wpdb ) {
[7] Fix | Delete
parent::__construct( $wpdb );
[8] Fix | Delete
$this->hooks();
[9] Fix | Delete
}
[10] Fix | Delete
[11] Fix | Delete
private function hooks() {
[12] Fix | Delete
add_action( 'wpml_troubleshooting_after_setup_complete_cleanup_end', array( $this, 'troubleshooting_action' ) );
[13] Fix | Delete
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
[14] Fix | Delete
add_action( 'wp_ajax_wpml_count_orphans', array( $this, 'count_orphans_action' ) );
[15] Fix | Delete
add_action( 'wp_ajax_wpml_delete_orphans', array( $this, 'delete_orphans_action' ) );
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
public function count_orphans_action() {
[19] Fix | Delete
if ( wpml_is_action_authenticated( 'wpml_orphan_comment' ) ) {
[20] Fix | Delete
wp_send_json_success( $this->get_orphan_comments( true ) );
[21] Fix | Delete
} else {
[22] Fix | Delete
wp_send_json_error( 'Wrong Nonce' );
[23] Fix | Delete
}
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
public function get_orphan_comments( $return_count = false, $limit = 10 ) {
[27] Fix | Delete
if ( $return_count ) {
[28] Fix | Delete
$columns = 'count(c.comment_id)';
[29] Fix | Delete
} else {
[30] Fix | Delete
$columns = 'DISTINCT c.comment_id';
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
$sql = "
[34] Fix | Delete
SELECT {$columns}
[35] Fix | Delete
FROM {$this->wpdb->prefix}comments c
[36] Fix | Delete
INNER JOIN {$this->wpdb->prefix}icl_translations tc
[37] Fix | Delete
ON c.comment_id = tc.element_id
[38] Fix | Delete
INNER JOIN {$this->wpdb->posts} p
[39] Fix | Delete
ON c.comment_post_ID = p.ID
[40] Fix | Delete
INNER JOIN {$this->wpdb->prefix}icl_translations tp
[41] Fix | Delete
ON p.ID = tp.element_id
[42] Fix | Delete
AND CONCAT('post_', p.post_type) = tp.element_type
[43] Fix | Delete
WHERE tc.element_type = 'comment'
[44] Fix | Delete
AND tp.language_code <> tc.language_code
[45] Fix | Delete
LIMIT 0, %d
[46] Fix | Delete
";
[47] Fix | Delete
$sql_prepared = $this->wpdb->prepare( $sql, $limit );
[48] Fix | Delete
if ( $return_count ) {
[49] Fix | Delete
$results = $this->wpdb->get_var( $sql_prepared );
[50] Fix | Delete
} else {
[51] Fix | Delete
$comments = $this->wpdb->get_col( $sql_prepared );
[52] Fix | Delete
$num_rows = $this->wpdb->num_rows;
[53] Fix | Delete
$results = array( $comments, $num_rows );
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
return $results;
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
public function delete_orphans_action() {
[60] Fix | Delete
if ( wpml_is_action_authenticated( 'wpml_orphan_comment' ) ) {
[61] Fix | Delete
$result = false;
[62] Fix | Delete
$data = isset( $_POST['data'] ) ? $_POST['data'] : array();
[63] Fix | Delete
$how_many = null;
[64] Fix | Delete
if ( isset( $data['how_many'] ) && is_numeric( $data['how_many'] ) ) {
[65] Fix | Delete
$how_many = (int) $data['how_many'];
[66] Fix | Delete
}
[67] Fix | Delete
if ( $how_many ) {
[68] Fix | Delete
$result = $this->delete_orphans( $how_many );
[69] Fix | Delete
}
[70] Fix | Delete
wp_send_json_success( $result );
[71] Fix | Delete
} else {
[72] Fix | Delete
wp_send_json_error( 'Wrong Nonce' );
[73] Fix | Delete
}
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* @param $hook
[78] Fix | Delete
*/
[79] Fix | Delete
public function enqueue_scripts( $hook ) {
[80] Fix | Delete
wp_register_script( 'wpml-orphan-comments', ICL_PLUGIN_URL . '/res/js/orphan-comments.js', array( 'jquery' ), ICL_SITEPRESS_VERSION, true );
[81] Fix | Delete
if ( WPML_PLUGIN_FOLDER . '/menu/troubleshooting.php' === $hook ) {
[82] Fix | Delete
wp_enqueue_script( 'wpml-orphan-comments' );
[83] Fix | Delete
}
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
public function troubleshooting_action() {
[87] Fix | Delete
?>
[88] Fix | Delete
<div id="wpml_orphans">
[89] Fix | Delete
<h4><?php esc_html_e( "Remove comments that don't match the content's language", 'sitepress' ); ?></h4>
[90] Fix | Delete
<div id="wpml_orphans_count" style="display:none;">
[91] Fix | Delete
<p>
[92] Fix | Delete
<?php esc_html_e( "This will check for comments that have a language different than the content they belong to. If found, we can delete these comments for you. We call these 'orphan comments'.", 'sitepress' ); ?>
[93] Fix | Delete
</p>
[94] Fix | Delete
<p>
[95] Fix | Delete
<button type="button" class="button-secondary check-orphans">
[96] Fix | Delete
<?php esc_html_e( 'Check for orphan comments', 'sitepress' ); ?>
[97] Fix | Delete
</button>
[98] Fix | Delete
</p>
[99] Fix | Delete
<div class="count-in-progress">
[100] Fix | Delete
<span class="spinner is-active" style="float:none;"></span>
[101] Fix | Delete
<?php esc_html_e( 'Checking...', 'sitepress' ); ?>
[102] Fix | Delete
</div>
[103] Fix | Delete
<div class="no_orphans">
[104] Fix | Delete
<br>
[105] Fix | Delete
<?php esc_html_e( 'Good news! Your site has no orphan comments.', 'sitepress' ); ?>
[106] Fix | Delete
</div>
[107] Fix | Delete
<div class="orphans-check-results">
[108] Fix | Delete
<p>
[109] Fix | Delete
<br>
[110] Fix | Delete
<?php echo sprintf( esc_html__( '%s orphan comments found.', 'sitepress' ), '<span class="count">0</span>' ); ?>
[111] Fix | Delete
</p>
[112] Fix | Delete
<p>
[113] Fix | Delete
<button type="button" class="button-secondary clean-orphans">
[114] Fix | Delete
<?php esc_html_e( 'Clean orphan comments', 'sitepress' ); ?>
[115] Fix | Delete
</button>
[116] Fix | Delete
</p>
[117] Fix | Delete
<p>
[118] Fix | Delete
<?php esc_html_e( '* The clean task may take several minutes to complete.', 'sitepress' ); ?>
[119] Fix | Delete
</p>
[120] Fix | Delete
<div class="delete-in-progress">
[121] Fix | Delete
<span class="spinner is-active" style="float:none;"></span>&nbsp;<?php esc_html_e( 'Deleted comments:', 'sitepress' ); ?>&nbsp;<span class="deleted">0</span>
[122] Fix | Delete
</div>
[123] Fix | Delete
</div>
[124] Fix | Delete
<?php wp_nonce_field( 'wpml_orphan_comment_nonce', 'wpml_orphan_comment_nonce' ); ?>
[125] Fix | Delete
</div>
[126] Fix | Delete
</div>
[127] Fix | Delete
<?php
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
/**
[131] Fix | Delete
* @param $how_many
[132] Fix | Delete
*
[133] Fix | Delete
* @return false|int
[134] Fix | Delete
*/
[135] Fix | Delete
public function delete_orphans( $how_many ) {
[136] Fix | Delete
$results = $this->get_orphan_comments( false, $how_many );
[137] Fix | Delete
$comment_ids = $results[0];
[138] Fix | Delete
$deleted_comments = 0;
[139] Fix | Delete
if ( $comment_ids ) {
[140] Fix | Delete
$comment_ids_flat = implode( ',', $comment_ids );
[141] Fix | Delete
$post_ids = $this->get_post_ids_from_comments_ids( $comment_ids_flat );
[142] Fix | Delete
$deleted_comments += $this->wpdb->query( "DELETE FROM {$this->wpdb->comments} WHERE comment_ID IN( {$comment_ids_flat} )" );
[143] Fix | Delete
$this->wpdb->query( "DELETE FROM {$this->wpdb->commentmeta} WHERE comment_ID IN( {$comment_ids_flat} )" );
[144] Fix | Delete
[145] Fix | Delete
$update_arg_set = array();
[146] Fix | Delete
foreach ( $comment_ids as $comment_id ) {
[147] Fix | Delete
$update_args = array(
[148] Fix | Delete
'element_id' => $comment_id,
[149] Fix | Delete
'element_type' => 'comment',
[150] Fix | Delete
'context' => 'comment',
[151] Fix | Delete
);
[152] Fix | Delete
[153] Fix | Delete
$update_arg_set[] = $update_args;
[154] Fix | Delete
[155] Fix | Delete
do_action( 'wpml_translation_update', array_merge( $update_args, array( 'type' => 'before_delete' ) ) );
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
$this->wpdb->query( "DELETE FROM {$this->wpdb->prefix}icl_translations WHERE element_id IN( {$comment_ids_flat} ) AND element_type = 'comment'" );
[159] Fix | Delete
[160] Fix | Delete
foreach ( $update_arg_set as $update_args ) {
[161] Fix | Delete
do_action( 'wpml_translation_update', array_merge( $update_args, array( 'type' => 'after_delete' ) ) );
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
$this->update_comments_count( $post_ids );
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
return $deleted_comments;
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* @param $post_ids
[172] Fix | Delete
*/
[173] Fix | Delete
private function update_comments_count( $post_ids ) {
[174] Fix | Delete
foreach ( $post_ids as $post_id ) {
[175] Fix | Delete
wp_update_comment_count( $post_id );
[176] Fix | Delete
}
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* @param string|array|int $comment_ids
[181] Fix | Delete
*
[182] Fix | Delete
* @return mixed
[183] Fix | Delete
*/
[184] Fix | Delete
private function get_post_ids_from_comments_ids( $comment_ids ) {
[185] Fix | Delete
if ( is_numeric( $comment_ids ) ) {
[186] Fix | Delete
$comment_ids = array( $comment_ids );
[187] Fix | Delete
}
[188] Fix | Delete
if ( is_array( $comment_ids ) ) {
[189] Fix | Delete
$comment_ids = implode( ',', $comment_ids );
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
return $this->wpdb->get_col( "SELECT DISTINCT comment_post_ID FROM {$this->wpdb->comments} WHERE comment_ID IN( {$comment_ids} )" );
[193] Fix | Delete
}
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
global $wpdb;
[197] Fix | Delete
new WPML_Post_Comments( $wpdb );
[198] Fix | Delete
[199] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function