Skip to content

Wrong parameter in get_permalink - class WPSEO_Post_Type_Sitemap_Provider #16308

@asadowski10

Description

@asadowski10

Please give us a description of what happened.

Hey team,

In this file https://plugins.trac.wordpress.org/browser/wordpress-seo/trunk/inc/sitemaps/class-post-type-sitemap-provider.php#L615 when you call get_permalink($post);

$post is not a WP_Post or and ID but your Stdclass.
In the function get_permalink() the final return has a filter :

/**
* @param string $permalink The post’s permalink.
* @param WP_Post $post The post in question.
* @param bool $leavename Whether to keep the post name.
*/
apply_filters( 'post_link', $permalink, $post, $leavename );

If any plugins or custom code hook ‘post_link’ after WordPress SEO it can generate a fatal error.
Could you modify your code to put an ID or an WP_Post instance ?
Best,

Please describe what you expected to happen and why.

In https://plugins.trac.wordpress.org/browser/wordpress-seo/trunk/inc/sitemaps/class-post-type-sitemap-provider.php#L615, on your hook : apply_filters( 'wpseo_xml_sitemap_post_url', get_permalink( $post ), $post );
In get_permalink() $post must be an ID or au WP_Post. In your code you put an StdClass

How can we reproduce this behavior?

  1. Activate Yoast SEO
  2. Add the code:
add_filter( 'post_link', function( string $permalink, WP_Post $post, bool $leavename ){ 
    /* my custom code */
    return $permalink;
} 10, 3  );
  1. Visit post-sitemap.xml. Fatal Error is triggered because $post is an StdClass

Technical info

  • If relevant, which editor is affected (or editors):
  • Classic Editor
  • Gutenberg
  • Classic Editor plugin
  • Which browser is affected (or browsers):
  • Chrome
  • Firefox
  • Safari
  • Other

Used versions

  • WordPress version: 5.5.3
  • Yoast SEO version: 15.2.1
  • Tested with theme: Twenty Seventeen

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions