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/classify post action #311

Merged
merged 2 commits into from
Oct 7, 2021

Conversation

mustafauysal
Copy link
Contributor

Description of the Change

These changes address 2 issues with CPT.

  1. Don't show the "Classify" action when the post_type is not supported. (post_row_actions, page_row_actions could allow to shown classify action on unregistered post type)
  2. Pass post_type for individual classify action. (eg: when you enable classify for the "page" and click on the row item, it doesn't work due to missing post_type on request.

Alternate Designs

Benefits

Making ClassifAI work better in admin UI.

Possible Drawbacks

Haven't seen any drawback, changes are relatively small.

Verification Process

  1. Register CPT:
function setup_test_post_type() {
	$args = array(
		'public' => true,
		'label'  => esc_html__( 'FooBar', 'foobar' ),
	);
	register_post_type( 'foobar', $args );
}

add_action( 'init', 'setup_test_post_type' );
  1. Enable ClassifAI for foobar only
  2. Click to "Classify" action on /wp-admin/edit.php?post_type=foobar for a post
  3. See "Classified 1 post." message.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

I couldn't add tests at this time, but it might be worth adding some testing 🤷🏻‍♂️

Changelog Entry

  • Fix individual classify action.

Post type necessary to make "handle_bulk_actions-edit-$post_type" work consistently.
@jeffpaul jeffpaul requested review from a team and cadic and removed request for a team October 4, 2021 14:22
@jeffpaul jeffpaul added this to the Future Release milestone Oct 4, 2021
Copy link

@cadic cadic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mustafauysal thank you for this update. Please fix the code regarding the post_type argument or explain the necessity of it.

$actions['classify'] = sprintf(
'<a href="%s">%s</a>',
esc_url( wp_nonce_url( admin_url( 'edit.php?action=classify&ids=' . $post->ID ), 'bulk-posts' ) ),
esc_url( wp_nonce_url( admin_url( sprintf( 'edit.php?action=classify&ids=%d&post_type=%s', $post->ID, $post->post_type ) ), 'bulk-posts' ) ),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks redundant, the hook handle_bulk_actions-edit-$post_type works regardless of post_type query argument presence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cadic It's not redundant but it can be a bit tricky to realize how it hooked on a single classification request at first glance.

In order to see reproduce the issue, please enable classify for "page" post type only, and click on the "Classify" row action for any given page. You will see nothing happens without passing the correct post_type.

wp-admin/edit.php needs to know $post_type to execute the dynamic hook ("handle_bulk_actions-edit-$post_type") accordingly.

I hope this makes sense.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mustafauysal thank you, I can confirm the action link doesn't work without post_type

@jeffpaul jeffpaul requested a review from cadic October 6, 2021 13:19
Copy link

@cadic cadic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mustafauysal thank you, looks good!

$actions['classify'] = sprintf(
'<a href="%s">%s</a>',
esc_url( wp_nonce_url( admin_url( 'edit.php?action=classify&ids=' . $post->ID ), 'bulk-posts' ) ),
esc_url( wp_nonce_url( admin_url( sprintf( 'edit.php?action=classify&ids=%d&post_type=%s', $post->ID, $post->post_type ) ), 'bulk-posts' ) ),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mustafauysal thank you, I can confirm the action link doesn't work without post_type

@jeffpaul jeffpaul modified the milestones: Future Release, 1.8.0 Oct 7, 2021
@jeffpaul jeffpaul merged commit 9203646 into 10up:develop Oct 7, 2021
@jeffpaul jeffpaul modified the milestones: 1.8.0, 1.7.1 Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants