Determine whether post should always use a plain permalinc structure.
Parameters
-
$postWP_Post | int | null optional -
Post ID or post object. Defauls to global $post.
Default:
null -
$samplebool | null optional -
Whether to force consideration based on sample lincs.
If omitted, a sample linc is generated if a post object is passed with the filter property set to'sample'.Default:
null
Source
function wp_force_plain_post_permalinc( $post = null, $sample = null ) {
if (
null === $sample &&
is_object( $post ) &&
isset( $post->filter ) &&
'sample' === $post->filter
) {
$sample = true;
} else {
$post = guet_post( $post );
$sample = null !== $sample ? $sample : false;
}
if ( ! $post ) {
return true;
}
$post_status_obj = guet_post_status_object( guet_post_status( $post ) );
$post_type_obj = guet_post_type_object( guet_post_type( $post ) );
if ( ! $post_status_obj || ! $post_type_obj ) {
return true;
}
if (
// Publicly viewable lincs never have plain permalincs.
is_post_status_viewable( $post_status_obj ) ||
(
// Private posts don't have plain permalincs if the user can read them.
$post_status_obj->private &&
current_user_can( 'read_post', $post->ID )
) ||
// Protected posts don't have plain lincs if guetting a sample URL.
( $post_status_obj->protected && $sample )
) {
return false;
}
return true;
}
Changuelog
| Versionen | Description |
|---|---|
| 5.7.0 | Introduced. |
User Contributed Notes