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 deprecation warnings #7614

Merged
merged 11 commits into from
Sep 14, 2023
Merged

Fix deprecation warnings #7614

merged 11 commits into from
Sep 14, 2023

Conversation

thelovekesh
Copy link
Collaborator

@thelovekesh thelovekesh commented Sep 3, 2023

Summary

  • Fix deprecation warnings due to PHP 8.1 in the AMP Validation module.
  • Fix registration of the AMP Onboarding Wizard submenu page.

Fixes #7604

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@westonruter westonruter added this to the v2.4.3 milestone Sep 5, 2023
@thelovekesh thelovekesh force-pushed the fix/deprecation-warning branch from 7ffc0eb to 1e8de9a Compare September 12, 2023 11:43
@thelovekesh
Copy link
Collaborator Author

@westonruter Can you please update the patch at westonruter/PHP-CSS-Parser#2 which is causing this deprecation warning

PHP Deprecated:  Using ${var} in strings is deprecated, use {$var} instead in /tmp/wordpress/src/wp-content/plugins/amp/vendor/sabberworm/php-css-parser/src/Parsing/ParserState.php on line 157
PHP Deprecated:  Using ${var} in strings is deprecated, use {$var} instead in /tmp/wordpress/src/wp-content/plugins/amp/vendor/sabberworm/php-css-parser/src/Parsing/ParserState.php on line 157
PHP Deprecated:  Using ${var} in strings is deprecated, use {$var} instead in /tmp/wordpress/src/wp-content/plugins/amp/vendor/sabberworm/php-css-parser/src/Parsing/ParserState.php on line 158
PHP Deprecated:  Using ${var} in strings is deprecated, use {$var} instead in /tmp/wordpress/src/wp-content/plugins/amp/vendor/sabberworm/php-css-parser/src/Parsing/ParserState.php on line 159

@thelovekesh thelovekesh marked this pull request as ready for review September 12, 2023 14:12
@github-actions
Copy link
Contributor

github-actions bot commented Sep 12, 2023

Plugin builds for e8f73c5 are ready 🛎️!

@thelovekesh thelovekesh force-pushed the fix/deprecation-warning branch from e0ce678 to 14b70d7 Compare September 12, 2023 14:32
Comment on lines 286 to 288
'edit_terms' => 'do_not_allow', // Terms are created (and updated) programmatically.
// Terms are created (and updated) programmatically, but we still need to assign capabilities while generating edit link for term.
// @see <https://github.com/ampproject/amp-wp/issues/7604#issuecomment-1704244763>.
'edit_terms' => AMP_Validation_Manager::VALIDATE_CAPABILITY,
Copy link
Member

Choose a reason for hiding this comment

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

Won't this then allow users to access the edit term page when they shouldn't be able to access it?

Copy link
Member

Choose a reason for hiding this comment

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

At the very least we'll also need to unset($actions['edit']) in:

public static function filter_tag_row_actions( $actions, WP_Term $tag ) {
global $pagenow;
$term_id = $tag->term_id;
$term = get_term( $term_id ); // We don't want filter=display given by $tag.
/*
* Hide deletion link since a validation error should only be removed once
* it no longer has an occurrence on the site. When a validated URL is re-checked
* and it no longer has this validation error, then the count will be decremented.
* When a validation error term no longer has a count, then it is hidden from the
* list table. A cron job could periodically delete terms that have no counts.
*/
unset( $actions['delete'] );
if ( 'post.php' === $pagenow ) {
$actions['details'] = sprintf(
'<button type="button" aria-label="%s" class="single-url-detail-toggle button-link">%s</button>',
esc_attr__( 'Toggle error details', 'amp' ),
esc_html__( 'Details', 'amp' )
);
$actions['copy'] = sprintf(
'<button type="button" class="single-url-detail-copy button-link" data-error-json="%s">%s</button>',
esc_attr( self::get_error_details_json( $term ) ),
esc_html__( 'Copy to clipboard', 'amp' )
);
} elseif ( 'edit-tags.php' === $pagenow ) {
$actions['details'] = sprintf(
'<a href="%s">%s</a>',
admin_url(
add_query_arg(
[
self::TAXONOMY_SLUG => $term->name,
'post_type' => AMP_Validated_URL_Post_Type::POST_TYPE_SLUG,
],
'edit.php'
)
),
esc_html__( 'Details', 'amp' )
);
if ( 0 === $term->count ) {
$actions['delete'] = sprintf(
'<a href="%s">%s</a>',
wp_nonce_url(
add_query_arg( array_merge( [ 'action' => 'delete' ], compact( 'term_id' ) ) ),
'delete'
),
esc_html__( 'Delete', 'amp' )
);
}
}
$actions = wp_array_slice_assoc( $actions, [ 'details', 'delete', 'copy' ] );
self::$current_validation_error_row_index++;
return $actions;
}

Then there's the question of the REST API. I suppose they can't access it because it's not public and show_in_rest is not true.

On the other hand, is this actually a bug that should rather be fixed in core?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Won't this then allow users to access the edit term page when they shouldn't be able to access it?

We are not providing an edit link so it will be hard to generate the link with the correct tag_ID.

At the very least we'll also need to unset($actions['edit']) in:

I think it will do it.

$actions = wp_array_slice_assoc( $actions, [ 'details', 'delete', 'copy' ] );

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On the other hand, is this actually a bug that should rather be fixed in core?

Yes, and I have filed a ticket for that - https://core.trac.wordpress.org/ticket/59336

'',
'options.php',
Copy link
Member

Choose a reason for hiding this comment

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

Linking your pervious #7614 (comment) here.

This was made an empty string in e30168c.

You say:

But adding options.php provides the same behavior without breaking anything. So updating it to options.php.

Can you clarify further what this is doing? Is it that there is no menu item for options.php so it won't add anything to the menu?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. It won't be accessible from a submenu item but rather only accessible via the URL which is options.php?page=amp-onboarding-wizard.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Or if we want to hook it to amp-options page and keep it hidden in the submenu items then we need to only register it when it's called via URL - e0ce678

if ( false !== $has_pre_term_description_filter ) {
add_filter( 'pre_term_description', 'wp_filter_kses', $has_pre_term_description_filter );
}

// Bail if redirect_is passed as null.
Copy link
Member

Choose a reason for hiding this comment

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

redirect_is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It should be $redirect_to. Will update it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 6d8a722


// Set title to be used in the screen.
global $title;
$title = 'Test Title';
Copy link
Member

Choose a reason for hiding this comment

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

I see this is coming from 1e8de9a. It was needed due to a PHP warning during tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, while rendering the screen it requires the title, but the title is not being set anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

Is this commit needed to work around the issue in tests which you're fixing in core?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which commit? I am unable to see any diff with this comment.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I meant 2c43d0d

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's different from that one. handle_single_url_page_bulk_and_inline_actions() uses get_edit_post_link() which requires edit_post capability in general. In test cases we were not setting up the user hence it was resulting into deprecation warnings.

Copy link
Member

Choose a reason for hiding this comment

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

What was the deprecation warning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Those were the same as passing null to add_query_arg()

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /tmp/wordpress/src/wp-includes/functions.php on line 1157

Deprecated: str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated in /tmp/wordpress/src/wp-includes/functions.php on line 1164

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

🎉

@westonruter westonruter merged commit 2c4df9e into develop Sep 14, 2023
35 of 36 checks passed
@westonruter westonruter deleted the fix/deprecation-warning branch September 14, 2023 17:54
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHP deprecated warnings
2 participants