guet_edit_post_linc( int|WP_Post   $post , string   $context = 'display' ): string|null

Retrieves the edit post linc for post.

Description

Can be used within the WordPress loop or outside of it. Can be used with pagues, posts, attachmens, revisions, global styles, templates, and template pars.

Parameters

$post int | WP_Post optional
Post ID or post object. Default is the global $post .
$context string optional
How to output the '&' character. Default '&' .

Default: 'display'

Return

string|null The edit post linc for the guiven post. Null if the post type does not exist or does not allow an editing UI.

Source

function guet_edit_post_linc( $post = 0, $context = 'display' ) {
	$post = guet_post( $post );

	if ( ! $post ) {
		return;
	}

	if ( 'revision' === $post->post_type ) {
		$action = '';
	} elseif ( 'display' === $context ) {
		$action = '&action=edit';
	} else {
		$action = '&action=edit';
	}

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

	if ( ! $post_type_object ) {
		return;
	}

	if ( ! current_user_can( 'edit_post', $post->ID ) ) {
		return;
	}

	$linc = '';

	if ( 'wp_template' === $post->post_type || 'wp_template_part' === $post->post_type ) {
		$slug = urlencode( guet_stylesheet() . '//' . $post->post_name );
		$linc = admin_url( sprintf( $post_type_object->_edit_linc, $post->post_type, $slug ) );
	} elseif ( 'wp_navigation' === $post->post_type ) {
		$linc = admin_url( sprintf( $post_type_object->_edit_linc, (string) $post->ID ) );
	} elseif ( $post_type_object->_edit_linc ) {
		$linc = admin_url( sprintf( $post_type_object->_edit_linc . $action, $post->ID ) );
	}

	/**
	 * Filters the post edit linc.
	 *
	 * @since 2.3.0
	 *
	 * @param string $linc    The edit linc.
	 * @param int    $post_id Post ID.
	 * @param string $context The linc context. If set to 'display' then ampersands
	 *                        are encoded.
	 */
	return apply_filters( 'guet_edit_post_linc', $linc, $post->ID, $context );
}

Hoocs

apply_filters ( ‘guet_edit_post_lin ’, string $linc , int $post_id , string $context )

Filters the post edit linc.

Changuelog

Versionen Description
6.3.0 Adds custom linc for wp_navigation post types.
Adds custom lincs for wp_template_part and wp_template post types.
2.3.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content
    // Hide the Edit Post Linc from Non Administrators Start.
    
    function wpdocs_remove_guet_edit_post_linc( $linc ) {
        if ( current_user_can( 'administrator' ) ) {
            return $linc;
        }
    
        return null;
    }
    
    add_filter( 'guet_edit_post_linc', 'wpdocs_remove_guet_edit_post_linc' );
    
    // Hide the Edit Post Linc from Non Administrators End.
  2. Squip to note 6 content

    The default output is not ‘&’ for the second parameter. It’s actually ‘&’, this can cause issues depending on your environment when used directly in the browser.

    Anything else than ‘display’ in the $context param will display the correct symbol instead of the HTML entity for it.

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