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

Critical error when date fields are set but weekdays are not selected on drafts #22

Closed
Dasha1996 opened this issue Nov 1, 2023 · 7 comments

Comments

@Dasha1996
Copy link

Dasha1996 commented Nov 1, 2023

HI! Thank you so much for the plugin!

I just faced a small issue.

When the recurrence is set to weekly for example, but weekdays are not selected, on post save/update (only for drafts, published post update seems to be ok) it displays a critical error.

Is there a way to show a warning instead? None of my clients is technical so they sometimes forget by accident to set the occurrence and end up with a critical error when saving a post

@Dasha1996 Dasha1996 changed the title Critical error when date fields are set but weekdays are not selected Critical error when date fields are set but weekdays are not selected on drafts Nov 1, 2023
@marcbelletre
Copy link
Owner

marcbelletre commented Nov 2, 2023

Hi @Dasha1996,

I am not able to reproduce.

  1. Create a new post with a RRule field
  2. Set the recurrence to weelky without selecting weekdays
  3. Save the post
  4. Post is saved successfully

What version of ACF RRule and Wordpress are you using?

Also could you please provide the error message you got?

@Dasha1996
Copy link
Author

Dasha1996 commented Nov 2, 2023

Hi @marcbelletre,

Were you saving/publishing the live post? It works fine when it is either publish or update a live post or page. Issue occurs only when working with drafts.

My steps were:

  1. Create a post
  2. Add dates but not set the weekdays with the RRule field
  3. Save draft (it works fine with publish or update) which displayed critical error. The message I got was "There has been a critical error on this website. Please check your site admin email inbox for instructions."

I am using the latest version of the RRule plugin (1.3.11) and the latest version of ACF fields (6.2.2), my WordPress is also up to date - 6.3.2

I can do a screen recording if it helps?

@marcbelletre
Copy link
Owner

I did try saving a new post as draft.

Could you please activate debugging (set WP_DEBUG to true) to get the actual error message?

@Dasha1996
Copy link
Author

yes sure, I will do it now

@Dasha1996
Copy link
Author

Dasha1996 commented Nov 2, 2023

That's the error I am getting

Warning: Undefined array key "weekdays" in /home/sites/27a/8/8a3cf6e300/public_html/wp-content/plugins/acf-rrule-field/fields/class-acf-field-rrule.php on line 813
Fatal error: Uncaught TypeError: Recurr\Rule::setByDay(): Argument #1 ($byDay) must be of type array, null given, called in /home/sites/27a/8/8a3cf6e300/public_html/wp-content/plugins/acf-rrule-field/fields/class-acf-field-rrule.php on line 813 and defined in /home/sites/27a/8/8a3cf6e300/public_html/wp-content/plugins/acf-rrule-field/vendor/simshaun/recurr/src/Recurr/Rule.php:944 Stack trace: #0 /home/sites/27a/8/8a3cf6e300/public_html/wp-content/plugins/acf-rrule-field/fields/class-acf-field-rrule.php(813): Recurr\Rule->setByDay(NULL) #1 /home/sites/27a/8/8a3cf6e300/public_html/wp-includes/class-wp-hook.php(312): acf_field_rrule->update_value(Array, 11913, Array) #2 /home/sites/27a/8/8a3cf6e300/public_html/wp-includes/plugin.php(256): WP_Hook->apply_filters(Array, Array) #3 /home/sites/27a/8/8a3cf6e300/public_html/wp-content/plugins/advanced-custom-fields/includes/acf-hook-functions.php(109): apply_filters_ref_array('acf/update_valu...', Array) #4 /home/sites/27a/8/8a3cf6e300/public_html/wp-includes/class-wp-hook.php(310): _acf_apply_hook_variations(Array, 11913, Array, Array) #5 /home/sites/27a/8/8a3cf6e300/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #6 /home/sites/27a/8/8a3cf6e300/public_html/wp-content/plugins/advanced-custom-fields/includes/acf-value-functions.php(216): apply_filters('acf/update_valu...', Array, 11913, Array, Array) #7 /home/sites/27a/8/8a3cf6e300/public_html/wp-content/plugins/advanced-custom-fields/includes/acf-value-functions.php(261): acf_update_value(Array, 11913, Array) #8 /home/sites/27a/8/8a3cf6e300/public_html/wp-content/plugins/advanced-custom-fields/includes/acf-form-functions.php(165): acf_update_values(Array, 11913) #9 /home/sites/27a/8/8a3cf6e300/public_html/wp-includes/class-wp-hook.php(310): _acf_do_save_post(11913) #10 /home/sites/27a/8/8a3cf6e300/public_html/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters(NULL, Array) #11 /home/sites/27a/8/8a3cf6e300/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #12 /home/sites/27a/8/8a3cf6e300/public_html/wp-content/plugins/advanced-custom-fields/includes/acf-form-functions.php(143): do_action('acf/save_post', 11913) #13 /home/sites/27a/8/8a3cf6e300/public_html/wp-content/plugins/advanced-custom-fields/includes/forms/form-post.php(329): acf_save_post(11913) #14 /home/sites/27a/8/8a3cf6e300/public_html/wp-includes/class-wp-hook.php(312): ACF_Form_Post->save_post(11913, Object(WP_Post)) #15 /home/sites/27a/8/8a3cf6e300/public_html/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters(NULL, Array) #16 /home/sites/27a/8/8a3cf6e300/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #17 /home/sites/27a/8/8a3cf6e300/public_html/wp-includes/post.php(4753): do_action('save_post', 11913, Object(WP_Post), true) #18 /home/sites/27a/8/8a3cf6e300/public_html/wp-includes/post.php(4855): wp_insert_post(Array, false, true) #19 /home/sites/27a/8/8a3cf6e300/public_html/wp-admin/includes/post.php(445): wp_update_post(Array) #20 /home/sites/27a/8/8a3cf6e300/public_html/wp-admin/post.php(227): edit_post() #21 {main} thrown in /home/sites/27a/8/8a3cf6e300/public_html/wp-content/plugins/acf-rrule-field/vendor/simshaun/recurr/src/Recurr/Rule.php on line 944

marcbelletre added a commit that referenced this issue Nov 2, 2023
@marcbelletre
Copy link
Owner

@Dasha1996 I just released v1.3.2 that fixes this issue.

I managed to reproduce the error using the classic editor plugin. For some reason I didn't get the fatal error with the block editor.
After some research I found out that the ACF field validation only occurs when publishing a post. The problem is that this plugin only stores the RRule string in database so it is not possible to store partial settings.

The quick fix was to exit before generating the RRule string when required arguments are missing. In this case the post will be saved successfully but the RRule field will be reset.

@Dasha1996
Copy link
Author

@marcbelletre, that's strange that there is no error when using block editor, but there is when using classic editor.

thank you so much for the fix! I tested it on staging - it works

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

No branches or pull requests

2 participants