Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DB issues #105

Merged
merged 2 commits into from
Dec 9, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix DB issues
jdevalk committed Dec 9, 2022

Unverified

This user has not yet uploaded their public signing key.
commit 10f0c071e49883f174b2d40b491d1afdd80ada2d
5 changes: 3 additions & 2 deletions admin/comment-parent.php
Original file line number Diff line number Diff line change
@@ -67,8 +67,9 @@ public function update_comment_parent() {
}

if ( $comment_id ) {
global $wpdb;
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->comments SET comment_parent = %d WHERE comment_ID = %d", $comment_parent, $comment_id ) );
$comment = get_comment( $comment_id );
$comment->comment_parent = $comment_parent;
wp_update_comment( $comment );
}
}
}
3 changes: 1 addition & 2 deletions inc/clean-emails.php
Original file line number Diff line number Diff line change
@@ -203,8 +203,7 @@ private function setup_data( int $comment_id ): void {
* Adds a sentence about the number of comments awaiting moderation.
*/
private function get_moderation_msg(): void {
global $wpdb;
$comments_waiting = $wpdb->get_var( "SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'" );
$comments_waiting = get_comment_count()['awaiting_moderation'];

if ( $comments_waiting > 1 ) {
--$comments_waiting;
25 changes: 16 additions & 9 deletions inc/email-links.php
Original file line number Diff line number Diff line change
@@ -47,23 +47,31 @@ public function admin_bar_comment_link(): void {

$current_user = \wp_get_current_user();

$results = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT comment_author_email FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_type = 'comment' AND comment_approved = '1'", $post->ID ) );

if ( \count( $results ) === 0 ) {
$comments = get_comments( [
'post_id' => $post->ID,
'type' => 'comment',
'status' => 'approve',
] );
if ( count( $comments ) === 0 ) {
return;
}
$emails = [];
foreach( $comments as $comment ) {
$emails[] = $comment->comment_author_email;
}
$emails = array_unique( $emails );

$url = 'mailto:' . $current_user->user_email . '?bcc=';
foreach ( $results as $comment ) {
if ( $comment->comment_author_email !== $current_user->user_email ) {
$url .= \rawurlencode( $comment->comment_author_email . ',' );
foreach ( $emails as $email ) {
if ( $email !== $current_user->user_email ) {
$url .= \rawurlencode( $email . ',' );
}
}
$url .= '&subject=' . $this->replace_variables( $this->options['email_subject'], false, $post->ID );
$url .= '&body=' . $this->replace_variables( $this->options['mass_email_body'], false, $post->ID );

// We can't set the 'href' attribute to the $url as then esc_url would garble the mailto link.
// So we do a nasty bit of JS workaround. The reason we grab the a href from the alternate link is
// So we do a nasty bit of JS workaround. The reason we grab the href from the alternate link is
// so browser extensions like the Google Mail one that change mailto: links still work.
echo '<a href="' . \esc_attr( $url ) . '" id="yst_email_commenters_alternate"></a><script>
function yst_email_commenters(e){
@@ -154,8 +162,7 @@ private function replace_variables( $msg, $comment = false, $post = false ): str

if ( \is_numeric( $post ) ) {
$post = \get_post( $post );
}
elseif ( \is_object( $comment ) && $comment->comment_post_ID > 0 ) {
} elseif ( \is_object( $comment ) && $comment->comment_post_ID > 0 ) {
$post = \get_post( $comment->comment_post_ID );
}