-
Notifications
You must be signed in to change notification settings - Fork 104
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] Option: prevent thrashing question if there are any answers #860
Conversation
includes/theme.php
Outdated
@@ -289,7 +289,16 @@ function ap_post_actions( $_post = null ) { | |||
$actions[] = array( 'header' => true ); | |||
} | |||
|
|||
if ( ap_user_can_delete_post( $_post->ID ) ) { | |||
$answers = get_posts( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mebishalnapit Why you need to load all posts here? Can't we simply get a count?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rahularyan wp_count_posts
will not work on this condition since it will count all of the available answers throughout the site while in this case, we'll only need the answers related to a specific question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try this: ap_count_published_answers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and also resolved conflicts.
includes/theme.php
Outdated
if ( ap_user_can_delete_post( $_post->ID ) ) { | ||
$answers = ap_count_published_answers( $_post->ID ); | ||
|
||
if ( ap_user_can_delete_post( $_post->ID ) && ( ! ap_opt( 'trashing_question_with_answer' ) || ( ap_opt( 'trashing_question_with_answer' ) && empty( $answers ) ) ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mebishalnapit Can this be simplified to this:
if (ap_user_can_delete_post($_post->ID) && (!ap_opt('trashing_question_with_answer') || empty($answers))) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rahularyan Modified the condition as requested.
This PR includes: