LLMS_Abstract_Processor::get_edit_post_link( int|WP_Post $id, string $context = 'display' )

Returns the edit post link for a post.


Description Description

This is based on the WordPress get_edit_post_link() function, but does not check if the user can edit the post or if the post’s post type has an edit link defined.

When the background processor is running, the current user ID is 0. This prevents current_user_can() from ever returning true and also causes the post’s post type edit link to be set to an empty string in WP_Post_Type::set_props().

This method is useful when the processor has completed and creates an admin notice that contains an edit post link.


Top ↑

Parameters Parameters

$id

(int|WP_Post) (Optional) Post ID or post object. Default is the global $post.

$context

(string) (Optional) How to output the '&' character. Default '&'.

Default value: 'display'


Top ↑

Return Return

(string|null) The edit post link for the given post. Null if the post type does not exist or does not allow an editing UI.


Top ↑

Source Source

File: includes/abstracts/llms.abstract.processor.php

	protected function get_edit_post_link( $id = 0, $context = 'display' ) {

		$post = get_post( $id );
		if ( ! $post ) {
			return null;
		}

		$post_type_object = get_post_type_object( $post->post_type );
		if ( ! $post_type_object ) {
			return null;
		}

		if ( 'revision' === $post->post_type ) {
			$action = '';
		} elseif ( 'display' === $context ) {
			$action = '&action=edit';
		} else {
			$action = '&action=edit';
		}
		$link = admin_url( sprintf( 'post.php?post=%d%s', $post->ID, $action ) );

		/**
		 * Filters the post edit link.
		 *
		 * This is identical to the `get_edit_post_link` filter hook in {@see get_edit_post_link()}.
		 *
		 * @since 6.0.0
		 *
		 * @param string $link    The edit link.
		 * @param int    $post_id Post ID.
		 * @param string $context The link context. If set to 'display' then ampersands are encoded.
		 */
		return apply_filters( 'get_edit_post_link', $link, $post->ID, $context );
	}


Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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