Skip to content

Add a new filter to prevent new user notifications. Also prevents some possible errors that can happen when plugin options haven't been set. Thanks to @federicojacobi for the pull request.#536

Merged
jonathanstegall merged 7 commits intoMinnPost:masterfrom
federicojacobi:master
Jun 19, 2024
Merged

Conversation

@federicojacobi
Copy link
Copy Markdown

What does this Pull Request do?

  • When some options aren't selected, options return non-array values and in_array calls fatal out. Let's cast them into arrays to be sure. In some cases, maybe_unserialize is not returning the default array values.
  • Updated some of the variable domdocs.
  • Added filter to prevent user creation from sending a notification (see inline note).

Comment on lines +97 to +98
$this->statuses_to_log = maybe_unserialize( get_option( $this->option_prefix . 'statuses_to_log', array() ) );
$this->statuses_to_log = empty( $this->statuses_to_log ) ? [] : $this->statuses_to_log;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There are multiple flavors of this issue, but they all come down to this: when the option doesn't exist or is empty then returned value from get_option is an empty string. Then maybe_unserialize thinks this is an ok value and doesn't return the array set as the default.

Then array functions throw fatals. Ex: in_array

Comment on lines +1001 to +1003
if ( apply_filters( $this->option_prefix . 'send_new_user_notification', true, $user_id, $params ) ) {
wp_new_user_notification( $user_id, null, 'both' );
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It is possible to user the default WP hooks wp_send_new_user_notification_to_admin and wp_send_new_user_notification_to_user but the problem with this is that by the time those hooks run, the developer cannot know where the user came from.

This is particularly bad when doing an "import" of existing contacts into wp ... perhaps you want to import users but not let them know about it.

just for wp code standards, use long declaration for array
I think these are always arrays
empty line doesn't seem necessary here
for wp code style, use longhand to declare arrays
@jonathanstegall jonathanstegall changed the title Add notification filter. Prevent fatals. Add a new filter to prevent new user notifications. Also prevents some possible errors that can happen when plugin options haven't been set. Jun 19, 2024
@jonathanstegall jonathanstegall changed the title Add a new filter to prevent new user notifications. Also prevents some possible errors that can happen when plugin options haven't been set. Add a new filter to prevent new user notifications. Also prevents some possible errors that can happen when plugin options haven't been set. Thanks to @federicojacobi for the pull request. Jun 19, 2024
@jonathanstegall jonathanstegall merged commit ad7cf7d into MinnPost:master Jun 19, 2024
@jonathanstegall jonathanstegall added the patch pull request that requires a patch release, ex v2.1.2. This is the default for new releases. label Jun 19, 2024
@jonathanstegall jonathanstegall added this to the v2.2.10 milestone Jun 19, 2024
@jonathanstegall jonathanstegall added chore Pull request that does maintenance tasks for developers Pull request for developer functionality and removed for developers Pull request for developer functionality labels Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Pull request that does maintenance tasks patch pull request that requires a patch release, ex v2.1.2. This is the default for new releases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants