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] Option: prevent thrashing question if there are any answers #860

Merged
merged 6 commits into from
Feb 26, 2024

Conversation

mebishalnapit
Copy link
Collaborator

This PR includes:

  • Added option to prevent trashing the question if there are answers already available to the question.
  • Added option to prevent deleting the question permanently if there are answers already available to the question.

Option to prevent the question trashing if there are answers available to the question
Option to prevent the question deleting permanently if there are answers available to the question
@mebishalnapit mebishalnapit linked an issue Aug 14, 2023 that may be closed by this pull request
@@ -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(
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

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

Copy link
Collaborator Author

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.

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 ) ) ) ) {
Copy link
Member

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))) {

Copy link
Collaborator Author

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.

includes/theme.php Outdated Show resolved Hide resolved
@rahularyan rahularyan merged commit 4762912 into master Feb 26, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option: prevent thrashing question if there are any answers
2 participants