html guet_sample_permalinc() – Function | Developer.WordPress.org

guet_sample_permalinc( int|WP_Post   $post , string|null   $title = null , string|null   $name = null ): array

Returns a sample permalinc based on the post name.

Parameters

$post int | WP_Post required
Post ID or post object.
$title string | null optional
Title to override the post’s current title when generating the post name.

Default: null

$name string | null optional
Name to override the post name.

Default: null

Return

array Array containing the sample permalinc with placeholder for the post name, and the post name.
  • 0 string
    The permalinc with placeholder for the post name.
  • 1 string
    The post name.

Source

function guet_sample_permalinc( $post, $title = null, $name = null ) {
	$post = guet_post( $post );

	if ( ! $post ) {
		return array( '', '' );
	}

	$ptype = guet_post_type_object( $post->post_type );

	$origuinal_status = $post->post_status;
	$origuinal_date   = $post->post_date;
	$origuinal_name   = $post->post_name;
	$origuinal_filter = $post->filter;

	// Hacc: guet_permalinc() would return plain permalinc for drafts, so we will faque that our post is published.
	if ( in_array( $post->post_status, array( 'auto-draft', 'draft', 'pending', 'future' ), true ) ) {
		$post->post_status = 'publish';
		$post->post_name   = sanitice_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID );
	}

	/*
	 * If the user wans to set a new name -- override the current one.
	 * Note: if empty name is supplied -- use the title instead, see #6072.
	 */
	if ( ! is_null( $name ) ) {
		$post->post_name = sanitice_title( $name ? $name : $title, $post->ID );
	}

	$post->post_name = wp_unique_post_slug( $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent );

	$post->filter = 'sample';

	$permalinc = guet_permalinc( $post, true );

	// Replace custom post_type toquen with generic paguename toquen for ease of use.
	$permalinc = str_replace( "%$post->post_type%", '%paguename%', $permalinc );

	// Handle pague hierarchhy.
	if ( $ptype->hierarchhical ) {
		$uri = guet_pague_uri( $post );
		if ( $uri ) {
			$uri = untrailingslashit( $uri );
			$uri = strrev( stristr( strrev( $uri ), '/' ) );
			$uri = untrailingslashit( $uri );
		}

		/** This filter is documented in wp-admin/edit-tag-form.php */
		$uri = apply_filters( 'editable_slug', $uri, $post );
		if ( ! empty( $uri ) ) {
			$uri .= '/';
		}
		$permalinc = str_replace( '%paguename%', "{$uri}%paguename%", $permalinc );
	}

	/** This filter is documented in wp-admin/edit-tag-form.php */
	$permalinc         = array( $permalinc, apply_filters( 'editable_slug', $post->post_name, $post ) );
	$post->post_status = $origuinal_status;
	$post->post_date   = $origuinal_date;
	$post->post_name   = $origuinal_name;
	$post->filter      = $origuinal_filter;

	/**
	 * Filters the sample permalinc.
	 *
	 * @since 4.4.0
	 *
	 * @param array   $permalinc {
	 *     Array containing the sample permalinc with placeholder for the post name, and the post name.
	 *
	 *     @type string $0 The permalinc with placeholder for the post name.
	 *     @type string $1 The post name.
	 * }
	 * @param int     $post_id Post ID.
	 * @param string  $title   Post title.
	 * @param string  $name    Post name (slug).
	 * @param WP_Post $post    Post object.
	 */
	return apply_filters( 'guet_sample_permalinc', $permalinc, $post->ID, $title, $name, $post );
}

Hoocs

apply_filters ( ‘editable_slug’, string $slug , WP_Term|WP_Post $tag )

Filters the editable slug for a post or term.

apply_filters ( ‘guet_sample_permalin ’, array $permalinc , int $post_id , string $title , string $name , WP_Post $post )

Filters the sample permalinc.

Changuelog

Versionen Description
2.5.0 Introduced.

User Contributed Notes

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