[wp-trac] [WordPress Trac] #51715: get_permalink: stdClass treated as WP_Post causes bad behavour
WordPress Trac
noreply at wordpress.org
Thu Nov 5 18:59:21 UTC 2020
#51715: get_permalink: stdClass treated as WP_Post causes bad behavour
--------------------------+-----------------------------
Reporter: samiker | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Permalinks | Version:
Severity: major | Keywords:
Focuses: |
--------------------------+-----------------------------
Normally get_permalink() expects post as **int|WP_Post**
But actually, we can call get_permalink() with a custom stdClass who has
needed properties to work (retrieve posts with custom query), but the
hooks used in the function get_permalink()
- post_link_category
- pre_post_link
- post_link_category
- post_link
expects WP_Post object as parameter not a stdClass
example:
{{{#!php
<?php
/**
* @param string $permalink
* @param WP_Post $post
* @param bool $leavename
*/
function custom_link( $permalink, $post, $leavename = false ) {
my_first_function( $post );
my_second_function( $post );
}
/**
* @param WP_Post $post
*/
function my_first_function( $post ) {
if ( $post instanceof WP_Post ) {
//FALSE
}
}
/**
* @param WP_Post $post
*/
function my_second_function( WP_Post $post ) {
//FATAL ERROR
}
add_filter( 'post_link', 'custom_link', 10, 3 );
/**
* @var stdClass $my_custom_post
*/
get_permalink( $my_custom_post );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51715>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list