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

Fix wp core deprecation messages for strpos and str_replace #7028

Merged
merged 6 commits into from
Jul 18, 2023

Conversation

Imran92
Copy link
Contributor

@Imran92 Imran92 commented Jul 15, 2023

Resolves #7016

Proposed Changes

  • Multiple deprecation messages are appearing in PHP 8.1 and 8.2. Among those messages, 6 were related to strpos and str_replace. This PR fixes those.

Though the error message shows that it's being thrown from the core (wp-includes/functions.php), these are actually due to some calls to the function add_submenu_page in Sensei core.

Among the parameters we use for calling add_submenu_page, the first one for the parent. If it's not set, the page is added but it's not listed under the visible menu. So use use empty string or null as the first parameter for some pages, like the course and lesson ordering pages.

Sending empty strings is alright, but sending null actually makes core wp throw a deprecation message because sending null to the haystack for strpos is no longer allowed, which is called internally by the add_submenu_page function. So we are changing the nulls to empty strings here. And in the future, we should not use null anymore in similar use case.

Testing Instructions

  • Use PHP 8.1 or 8.2 at least
  • Set WP_DEBUG, WP_DEBUG_DISPLAY, WP_DEBUG_LOG to true
  • Load the dashboard
  • Make sure you see no deprecation messages visible in the rendered page or the log

Note

For PHP 8.2, you'll still see some deprecation messages regarding dynamically created variables. Those will be fixed separately under this issue, because it's more specific to that deprecation message.

Pre-Merge Checklist

  • PR title and description contain sufficient detail and accurately describe the changes
  • Acceptance criteria is met
  • Decisions are publicly documented
  • Adheres to coding standards (PHP, JavaScript, CSS, HTML)
  • All strings are translatable (without concatenation, handles plurals)
  • Follows our naming conventions (P6rkRX-4oA-p2)
  • Hooks (p6rkRX-1uS-p2) and functions are documented
  • New UIs are responsive and use a mobile-first approach
  • New UIs match the designs
  • Different user privileges (admin, teacher, subscriber) are tested as appropriate
  • Code is tested on the minimum supported PHP and WordPress versions
  • User interface changes have been tested on the latest versions of Chrome, Firefox and Safari
  • "Needs Documentation" label is added if this change requires updates to documentation
  • Known issues are created as new GitHub issues

@Imran92 Imran92 requested a review from a team July 15, 2023 01:05
@Imran92 Imran92 self-assigned this Jul 15, 2023
@Imran92 Imran92 added this to the 4.16.1 milestone Jul 15, 2023
@codecov
Copy link

codecov bot commented Jul 15, 2023

Codecov Report

Merging #7028 (fa0899a) into trunk (689f545) will not change coverage.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              trunk    #7028   +/-   ##
=========================================
  Coverage     48.03%   48.03%           
  Complexity    10458    10458           
=========================================
  Files           573      573           
  Lines         44141    44141           
  Branches        402      402           
=========================================
  Hits          21201    21201           
  Misses        22613    22613           
  Partials        327      327           
Impacted Files Coverage Δ
includes/class-sensei-admin.php 19.08% <0.00%> (ø)
includes/class-sensei-course.php 38.49% <0.00%> (ø)
includes/class-sensei-modules.php 36.62% <0.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da8a4c1...fa0899a. Read the comment docs.

donnapep
donnapep previously approved these changes Jul 17, 2023
Copy link
Collaborator

@donnapep donnapep left a comment

Choose a reason for hiding this comment

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

Small mistake in the change log entry

changelog/fix-wp-core-deprecation-messages Outdated Show resolved Hide resolved
Co-authored-by: Donna Peplinskie <donnapep@gmail.com>
@donnapep donnapep merged commit fd21749 into trunk Jul 18, 2023
19 of 20 checks passed
@donnapep donnapep deleted the fix/wp-core-deprecation-messages branch July 18, 2023 13:36
@donnapep donnapep mentioned this pull request Jul 20, 2023
14 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.

PHP 8.2: Fix multiple deprecation message issues
2 participants