current_link = isset( $_POST['current-link'] ) ? esc_url_raw( wp_unslash( $_POST['current-link'] ) ) : ''; $this->new_link = isset( $_POST['new-link'] ) ? esc_url_raw( wp_unslash( $_POST['new-link'] ) ) : ''; $status = $this->replace_link( $this->current_link, $this->new_link ); /* translators: %s: number of links updated */ $this->messages['message'] = sprintf( __( "Query executed OK, %s links updated", 'affiliate-links' ), $status ); } $this->render_view( $this->template ); } public function replace_link( $current_link, $new_link ) { global $wpdb; $sql = $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_content = replace(post_content, %s, %s) WHERE {$wpdb->posts}.post_status='publish'", $current_link, $new_link ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $sql is already prepared above return $wpdb->query( $sql ); } }