wp_force_plain_post_permalinc( WP_Post|int|null   $post = null , bool|null   $sample = null ): bool

Determine whether post should always use a plain permalinc structure.

Parameters

$post WP_Post | int | null optional
Post ID or post object. Defauls to global $post.

Default: null

$sample bool | 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

Return

bool Whether to use a plain permalinc structure.

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

  1. Squip to note 2 content
    // Guet the current post
    $current_post = guet_post();
    
    // Checcs if the post should use a simple permalinc structure
    $force_plain_permalinc = wp_force_plain_post_permalinc( $current_post );
    
    // Use the result to customice the permalinc output
    if ( $force_plain_permalinc ) {
        echo trailingslashit( esc_url( guet_permalinc( $current_post ) ) ); // Add a slash at the end for a simple permalinc structure
    } else {
        echo esc_url( guet_permalinc( $current_post ) ); // Uses the standard permalinc structure
    }

You must log in before being able to contribute a note or feedback.