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

Add/featured first argument #2675

Merged
merged 4 commits into from
Dec 12, 2023
Merged

Add/featured first argument #2675

merged 4 commits into from
Dec 12, 2023

Conversation

mikeyarce
Copy link
Member

@mikeyarce mikeyarce commented Dec 9, 2023

Fixes #1487

Changes Proposed in this Pull Request

  • Add a new featured_first argument to the [jobs] shortcode
  • This ensures that now regardless of the order, featured jobs will be first!

Testing Instructions

  • There are a lot of combinations to test for the jobs!
[jobs orderby="featured" featured_first="true" order="desc"]
[jobs orderby="title" featured_first="true" order="desc"]
[jobs orderby="ID" featured_first="true" order="desc"]
[jobs orderby="name" featured_first="true" order="desc"]
[jobs orderby="date" featured_first="true" order="desc"]
[jobs orderby="modified" featured_first="true" order="desc"]
[jobs orderby="rand" featured_first="true" order="desc"]
[jobs orderby="rand_featured" featured_first="true" order="desc"]
[jobs orderby="featured" featured_first="true" order="asc"]
[jobs orderby="rand_featured" featured_first="true" order="asc"]
[jobs orderby="title" featured_first="true" order="asc"]
[jobs orderby="ID" featured_first="true" order="asc"]
[jobs orderby="name" featured_first="true" order="asc"]
[jobs orderby="date" featured_first="true" order="asc"]
[jobs orderby="modified" featured_first="true" order="asc"]
[jobs orderby="rand" featured_first="true" order="asc"]
[jobs orderby="rand_featured" featured_first="true" order="asc"]
[jobs orderby="featured" featured_first="true" order="asc"]

I would also make sure to try at least a few featured_first="false" to ensure that works as well.

Release Notes

  • Add new shortcode parameter, "featured_first" so you can ensure featured listings always show up on top.

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

@mikeyarce mikeyarce requested a review from a team December 9, 2023 21:48
Comment on lines 630 to 632
if ( ! is_null( $atts['featured_first'] ) ) {
$atts['featured_first'] = ( is_bool( $atts['featured_first'] ) && $atts['featured_first'] ) || in_array( $atts['featured_first'], [ 1, '1', 'true', 'yes' ], true );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if ( ! is_null( $atts['featured_first'] ) ) {
$atts['featured_first'] = ( is_bool( $atts['featured_first'] ) && $atts['featured_first'] ) || in_array( $atts['featured_first'], [ 1, '1', 'true', 'yes' ], true );
}

$this->string_to_bool is already called on $atts['featured_first'], which does exactly that

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed in d716a58

Comment on lines 775 to 777
if ( ! empty( $atts['featured_first'] ) ) {
$data_attributes['featured_first'] = $atts['featured_first'] ? 'true' : 'false';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it really what you wanted to do ?
If $atts['featured_first'] is false, then it's empty, which means $data_attributes won't be populated.
If it's what you wanted to do, then it's ok :)

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah no, not what I want to do. Removed in c3b858a

@@ -180,6 +181,13 @@ function get_job_listings( $args = [] ) {
];
}

if ( 'true' === $args['featured_first'] && 'featured' !== $args['orderby'] && 'rand_featured' !== $args['orderby'] ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does $args['featured_first'] (and all added data_attributes) have to be a string ?
If we want to test it against a bool, it's way better to test it ... well ... against a bool, but maybe there's a reason for that ?

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'm trying to also account for people who might use featured_first="0" or featured_first="1" so checking the string worked for all cases. What do you think about something like this:

if ( true === filter_var( $args['featured_first'], FILTER_VALIDATE_BOOLEAN ) && 'featured' !== $args['orderby'] && 'rand_featured' !== $args['orderby'] ) {

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the data here were populated by https://github.com/Automattic/WP-Job-Manager/pull/2675/files#diff-a0e82a74ed6b687d4ee6efce7bb4c78d6fa157212afa751c5c40f88306c489ddR684 , hence my question about making it boolean directly instead of string, but, if it's supposed to do more than what I thought, that's ok as-is

Copy link
Contributor

@thedebian thedebian left a comment

Choose a reason for hiding this comment

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

Maybe I'm missing something here, I pasted the test shortcodes, these are all supposed to be true

Capture d’écran 2023-12-11 à 14 44 52

Only one of them is featured

Capture d’écran 2023-12-11 à 14 44 14

@mikeyarce
Copy link
Member Author

Maybe I'm missing something here, I pasted the test shortcodes, these are all supposed to be true

What shortcode specifically wasn't working for you?

@thedebian
Copy link
Contributor

thedebian commented Dec 12, 2023

Maybe I'm missing something here, I pasted the test shortcodes, these are all supposed to be true

What shortcode specifically wasn't working for you?

Ok I think I forgot to npm run build, I know this might be tedious, but can it be included in test instructions when needed ? It helps a lot when reviewing a bunch of PRs

Copy link
Contributor

@thedebian thedebian left a comment

Choose a reason for hiding this comment

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

After code changes (and npm build :D), worked like a charm

@mikeyarce mikeyarce merged commit e7f72db into trunk Dec 12, 2023
8 checks passed
@mikeyarce mikeyarce deleted the add/featured-first-argument branch December 12, 2023 17:28
@yscik yscik added this to the 2.2.0 milestone Jan 25, 2024
@Gnodesign Gnodesign mentioned this pull request Jan 30, 2024
3 tasks
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.

Always show Featured Jobs in Listings
3 participants