Commit Graph

26 Commits

Author SHA1 Message Date
Sergey Biryukov 2ec23a82ed Code Modernization: Replace usage of `strpos()` with `str_starts_with()`.
`str_starts_with()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) begins with the given substring (needle).

WordPress core includes a polyfill for `str_starts_with()` on PHP < 8.0 as of WordPress 5.9.

This commit replaces `0 === strpos( ... )` with `str_starts_with()` in core files, making the code more readable and consistent, as well as improving performance.

While `strpos()` is slightly faster than the polyfill on PHP < 8.0, `str_starts_with()` is noticeably faster on PHP 8.0+, as it is optimized to avoid unnecessarily searching along the whole haystack if it does not find the needle.

Follow-up to [52039], [52040], [52326].

Props spacedmonkey, costdev, sabernhardt, mukesh27, desrosj, jorbin, TobiasBg, ayeshrajans, lgadzhev, SergeyBiryukov.
Fixes #58012.
Built from https://develop.svn.wordpress.org/trunk@55703


git-svn-id: http://core.svn.wordpress.org/trunk@55215 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-05-02 15:45:22 +00:00
Pascal Birchler 5edb22187d I18N: Introduce `switch_to_user_locale()`.
This new function makes it easier to switch to a specific user’s locale by reducing duplicate code and storing the user’s ID as additional context for plugins to consume. Existing usage of `switch_to_locale()` in core has been replaced with `switch_to_user_locale()` where appropriate.

Also, this change ensures `WP_Locale_Switcher` properly filters `determine_locale` so that anyyone using the `determine_locale()` function will get the correct locale information when switching is in effect.

Props costdev.
Fixes #57123.
See #26511.
Built from https://develop.svn.wordpress.org/trunk@55161


git-svn-id: http://core.svn.wordpress.org/trunk@54694 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-01-30 10:27:16 +00:00
Sergey Biryukov 92673e251e Site Health: Remove the WordPress 5.2 reference from the email sent on fatal errors.
The version reference was initially added to reduce confusion and make it clear that this is new WordPress functionality, with the website itself sending an automated notification of a fatal error, most likely in a plugin or theme.

Almost four years and several major releases later, it no longer adds any helpful information and can be removed.

Follow-up to [44973], [45181], [45268].

Props NekoJonez, jb510, peterwilsoncc, kebbet, mukesh27, mrwweb, johnbillion, SergeyBiryukov.
Fixes #57327. See #54961.
Built from https://develop.svn.wordpress.org/trunk@55001


git-svn-id: http://core.svn.wordpress.org/trunk@54534 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-17 15:31:17 +00:00
Sergey Biryukov c03305852e Code Modernization: Add `AllowDynamicProperties` attribute to all (parent) classes.
Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.

There are a number of ways to mitigate this:
* If it is an accidental typo for a declared property: fix the typo.
* For known properties: declare them on the class.
* For unknown properties: add the magic `__get()`, `__set()`, et al. methods to the class or let the class extend `stdClass` which has highly optimized versions of these magic methods built in.
* For unknown ''use'' of dynamic properties, the `#[AllowDynamicProperties]` attribute can be added to the class. The attribute will automatically be inherited by child classes.

Trac ticket #56034 is open to investigate and handle the third and fourth type of situations, however it has become clear this will need more time and will not be ready in time for WP 6.1.

To reduce “noise” in the meantime, both in the error logs of WP users moving onto PHP 8.2, in the test run logs of WP itself, in test runs of plugins and themes, as well as to prevent duplicate tickets from being opened for the same issue, this commit adds the `#[AllowDynamicProperties]` attribute to all “parent” classes in WP.

The logic used for this commit is as follows:
* If a class already has the attribute: no action needed.
* If a class does not `extend`: add the attribute.
* If a class does `extend`:
 - If it extends `stdClass`: no action needed (as `stdClass` supports dynamic properties).
 - If it extends a PHP native class: add the attribute.
 - If it extends a class from one of WP's external dependencies: add the attribute.
* In all other cases: no action — the attribute should not be needed as child classes inherit from the parent.

Whether or not a class contains magic methods has not been taken into account, as a review of the currently existing magic methods has shown that those are generally not sturdy enough and often even set dynamic properties (which they should not). See the [https://www.youtube.com/watch?v=vDZWepDQQVE live stream from August 16, 2022] for more details.

This commit only affects classes in the `src` directory of WordPress core.
* Tests should not get this attribute, but should be fixed to not use dynamic properties instead. Patches for this are already being committed under ticket #56033.
* While a number bundled themes (2014, 2019, 2020, 2021) contain classes, they are not a part of this commit and may be updated separately.

Reference: [https://wiki.php.net/rfc/deprecate_dynamic_properties PHP RFC: Deprecate dynamic properties].

Follow-up to [53922].

Props jrf, hellofromTonya, markjaquith, peterwilsoncc, costdev, knutsp, aristath.
See #56513, #56034.
Built from https://develop.svn.wordpress.org/trunk@54133


git-svn-id: http://core.svn.wordpress.org/trunk@53692 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-09-12 15:47:14 +00:00
John Blackbourn beac9601fa Docs: Corrections and improvements to docblocks for function and hooks relating to fatal error handling.
See #54729

Built from https://develop.svn.wordpress.org/trunk@53316


git-svn-id: http://core.svn.wordpress.org/trunk@52905 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-29 19:17:11 +00:00
audrasjb e05557e222 Administration: Replace "Current theme" with "Active theme" in user facing strings.
This change replaces "Current theme" with "Active theme" in user-facing strings. It brings better consistency across the Administration.

Props Presskopp, audrasjb, costdev.
Fixes #54770.

Built from https://develop.svn.wordpress.org/trunk@52580


git-svn-id: http://core.svn.wordpress.org/trunk@52170 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-01-15 08:44:03 +00:00
Sergey Biryukov 10a084a067 Coding Standards: Move some translator comments to the correct place.
Follow-up to [46273], [50060], [50117].

See #52627.
Built from https://develop.svn.wordpress.org/trunk@50654


git-svn-id: http://core.svn.wordpress.org/trunk@50266 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-04-04 18:30:05 +00:00
Sergey Biryukov 37662df05e Docs: In various `@return` tags, list the expected type first, instead of `false` or `WP_Error`.
Follow-up to [46696], [47060], [49926], [49927].

See #51800.
Built from https://develop.svn.wordpress.org/trunk@49929


git-svn-id: http://core.svn.wordpress.org/trunk@49628 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-01-04 17:18:04 +00:00
John Blackbourn dfe1f9b322 Docs: Promote many `bool` types to `true` or `false` where only that value is used.
See #51800

Built from https://develop.svn.wordpress.org/trunk@49927


git-svn-id: http://core.svn.wordpress.org/trunk@49626 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-01-03 22:04:04 +00:00
Sergey Biryukov 0cdab6e91d Docs: Add a `@since` note for the `recovery_mode_email` filter about the `$email` argument now including the `attachments` key.
Follow-up to [48964].

See #51276.
Built from https://develop.svn.wordpress.org/trunk@48994


git-svn-id: http://core.svn.wordpress.org/trunk@48756 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-09-18 11:03:02 +00:00
desrosj 8e9e942215 Site Health: Allow attachments to be added to recovery mode emails.
The `wp_mail()` function has the ability to add attachments to emails. There is currently no way to add attachments to the recovery mode email sent out to site admins when a PHP error is encountered on their site.

This change adds that ability through the use of the `recovery_mode_email` filter, allowing developers to use the full capabilities of `wp_mail()`.

Props desrosj, timothyblynjacobs.
Fixes #51276.
Built from https://develop.svn.wordpress.org/trunk@48964


git-svn-id: http://core.svn.wordpress.org/trunk@48726 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-09-09 16:21:06 +00:00
desrosj 5be5b975c3 Docs: Improve the `recovery_mode_email` inline docs.
See #51267, #50768.
Built from https://develop.svn.wordpress.org/trunk@48962


git-svn-id: http://core.svn.wordpress.org/trunk@48724 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-09-09 15:48:07 +00:00
Sergey Biryukov 1f85e7484f Docs: Consistently use third-person singular verbs for various filter descriptions, per the documentation standards.
See #50768.
Built from https://develop.svn.wordpress.org/trunk@48782


git-svn-id: http://core.svn.wordpress.org/trunk@48544 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-08-11 00:34:08 +00:00
Sergey Biryukov 350ad6141e Coding Standards: Use consistent formatting for translator comments in `wp-includes/rest-api.php`.
See #50767.
Built from https://develop.svn.wordpress.org/trunk@48765


git-svn-id: http://core.svn.wordpress.org/trunk@48527 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-08-09 01:46:07 +00:00
John Blackbourn 9bc7d0a776 Docs: Another pass at some inline docs fixes mostly made by PHPCBF.
See #49572, #50744
Built from https://develop.svn.wordpress.org/trunk@48590


git-svn-id: http://core.svn.wordpress.org/trunk@48352 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-23 21:11:05 +00:00
John Blackbourn c3f787b8ff Docs: Miscellaneous docblock corrections.
See #49572
Built from https://develop.svn.wordpress.org/trunk@48508


git-svn-id: http://core.svn.wordpress.org/trunk@48270 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-18 22:11:02 +00:00
Sergey Biryukov a576a13246 Docs: Remove an empty line between `@param` and `@return` tags, per the documentation standards.
See #49572.
Built from https://develop.svn.wordpress.org/trunk@48102


git-svn-id: http://core.svn.wordpress.org/trunk@47871 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-20 11:18:09 +00:00
Sergey Biryukov 001ffe81fb Docs: Improve inline comments per the documentation standards.
Includes minor code layout fixes for better readability.

See #48303.
Built from https://develop.svn.wordpress.org/trunk@47122


git-svn-id: http://core.svn.wordpress.org/trunk@46922 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-01-29 00:45:18 +00:00
John Blackbourn 9ac1d82f23 Docs: Further improve documentation of known return types, plus other docs fixes.
See #48303

Built from https://develop.svn.wordpress.org/trunk@46661


git-svn-id: http://core.svn.wordpress.org/trunk@46461 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-11-05 21:27:02 +00:00
Sergey Biryukov 406021dba8 Site Health: Include simple debug data in fatal error protection email.
Introduce `recovery_email_debug_info` filter for the debug information included in the email.

Props Clorith, TimothyBlynJacobs.
Fixes #48090.
Built from https://develop.svn.wordpress.org/trunk@46273


git-svn-id: http://core.svn.wordpress.org/trunk@46085 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-23 20:27:56 +00:00
Sergey Biryukov e199663322 I18N: Capitalize translator comments consistently, add trailing punctuation.
Includes minor code layout fixes.

See #44360.
Built from https://develop.svn.wordpress.org/trunk@45932


git-svn-id: http://core.svn.wordpress.org/trunk@45743 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-09-03 00:41:05 +00:00
Sergey Biryukov 67f944caa6 I18N: Remove PHP function name from translatable string in `WP_Recovery_Mode_Email_Service`.
Props ramiy.
Fixes #47255.
Built from https://develop.svn.wordpress.org/trunk@45447


git-svn-id: http://core.svn.wordpress.org/trunk@45258 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-05-26 20:44:52 +00:00
Gary Pendergast 3b5307339d Bootstrap/Load: Tweak the recovery mode email text and behaviour.
- Change the recovery mode link expiry to 1 day.
- Improve the email text.
- Add a new `recovery_email_support_info` filter, for hosts to be able to customise their support contact information.

Props pento, chanthaboune, michelleweber, matt.
Fixes #46898.


Built from https://develop.svn.wordpress.org/trunk@45268


git-svn-id: http://core.svn.wordpress.org/trunk@45077 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-25 00:47:52 +00:00
Sergey Biryukov 65da064055 Bootstrap/Load: Finalize recovery mode email language.
Props TimothyBlynJacobs, miss_jwo, desrosj.
Fixes #46898.
Built from https://develop.svn.wordpress.org/trunk@45181


git-svn-id: http://core.svn.wordpress.org/trunk@44990 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-12 20:49:51 +00:00
Sergey Biryukov 63d0abd5ff Administration: Fix typo in fatal error email notification.
Props kraftbj.
Fixes #46722.
Built from https://develop.svn.wordpress.org/trunk@45077


git-svn-id: http://core.svn.wordpress.org/trunk@44886 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-03-30 18:54:51 +00:00
Felix Arntz 3a77265148 Bootstrap/Load: Introduce a recovery mode for fixing fatal errors.
Using the new fatal handler introduced in [44962], an email is sent to the admin when a fatal error occurs. This email includes a secret link to enter recovery mode. When clicked, the link will be validated and on success a cookie will be placed on the client, enabling recovery mode for that user. This functionality is executed early before plugins and themes are loaded, in order to be unaffected by potential fatal errors these might be causing.

When in recovery mode, broken plugins and themes will be paused for that client, so that they are able to access the admin backend despite of these errors. They are notified about the broken extensions and the errors caused, and can then decide whether they would like to temporarily deactivate the extension or fix the problem and resume the extension.

A link in the admin bar allows the client to exit recovery mode.

Props timothyblynjacobs, afragen, flixos90, nerrad, miss_jwo, schlessera, spacedmonkey, swissspidy.
Fixes #46130, #44458.

Built from https://develop.svn.wordpress.org/trunk@44973


git-svn-id: http://core.svn.wordpress.org/trunk@44804 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-03-21 21:53:51 +00:00