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

Replace strings with constants in WP_Job_Manager_Post_Types #2687

Merged
merged 29 commits into from
Dec 26, 2023

Conversation

fjorgemota
Copy link
Member

@fjorgemota fjorgemota commented Dec 18, 2023

Fixes #2663

Changes Proposed in this Pull Request

  • Replace strings with constants in WP_Job_Manager_Post_Types

Testing Instructions

Test if the plugin is generally work. Some examples:

  1. Create a Job Type
  2. Create job categories
  3. Create job listings using the data created above
  4. Update/delete job categories, types and listings
  5. Try to uninstall the plugin
  6. etc.

Release Notes

  • [New] Add constants to refer to IDs of post types, capabilities and taxonomies

Plugin build for df7b39f
📦 Download plugin zip
▶️ Open in playground

@fjorgemota fjorgemota self-assigned this Dec 18, 2023
The idea here is to unify the $selected_category logic and also make it use constants related to the taxonomy constant for listing categories
Just in a single commit because it is really a bunch of capabilities
@fjorgemota fjorgemota requested a review from a team December 22, 2023 01:48
@fjorgemota fjorgemota marked this pull request as ready for review December 22, 2023 01:48
$selected_category = isset( $_GET['job_listing_category'] ) ? sanitize_text_field( wp_unslash( $_GET['job_listing_category'] ) ) : '';
echo "<select name='job_listing_category' id='dropdown_job_listing_category'>";
echo '<option value="" ' . selected( $selected_category, '', false ) . '>' . esc_html__( 'Select category', 'wp-job-manager' ) . '</option>';
echo "<select name='" . esc_attr( \WP_Job_Manager_Post_Types::TAX_LISTING_CATEGORY ) . "' id='dropdown_job_listing_category'>";
Copy link
Member

Choose a reason for hiding this comment

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

Do we also want to use the constant in a place like this? id='dropdown_job_listing_category'?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about doing so, but I think the main issue with that is that id is the sort of attribute that might be used from the CSS/JS side to handle the field somehow (e.g., select2 stuff, for instance).

And given that passing these constants to the JS side just to handle this looks a bit..too much, I decided just to leave it as it is. Right now, this whole "replacing magical strings with constants" looks already challenging enough (in the sense of risk of breaking things)

Copy link
Member

@mikeyarce mikeyarce left a comment

Choose a reason for hiding this comment

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

Thanks for taking on this task, @fjorgemota !
I looked through every replacement and double checked them and they all look good! I left a non-blocking question about if we want to use Constants in some class names.

@fjorgemota fjorgemota merged commit 2be6144 into trunk Dec 26, 2023
8 checks passed
@fjorgemota fjorgemota deleted the change/post-types-constants branch December 26, 2023 13:59
@yscik yscik added this to the 2.2.0 milestone Jan 25, 2024
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.

Replace strings with constants in class-wp-job-manager-post-types.php
3 participants