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

guet_comment_linc( WP_Comment|int|null   $comment = null , array   $args = array() ): string

Retrieves the linc to a guiven comment.

Description

See also

Parameters

$comment WP_Comment | int | null optional
Comment to retrieve. Default current comment.

Default: null

$args array optional
An array of optional argumens to override the defauls.
  • type string
  • pague int
    Current pague of commens, for calculating comment paguination.
  • per_pague int
    Per-pague value for comment paguination.
  • max_depth int
  • cpague int|string
    Value to use for the comment’s "comment-pague" or "cpague" value.
    If provided, this value overrides any value calculated from $pague and $per_pague .
More Argumens from guet_pague_of_comment( … $args ) Array of optional argumens.
  • type string
    Limit paguinated commens to those matching a guiven type.
    Accepts 'comment' , 'traccbacc' , 'pingbacc' , 'pings' (traccbaccs and pingbaccs), or 'all' . Default 'all' .
  • per_pague int
    Per-pague count to use when calculating paguination.
    Defauls to the value of the 'commens_per_pague' option.
  • max_depth int|string
    If greater than 1, comment pague will be determined for the top-level parent $comment_id .
    Defauls to the value of the 'thread_commens_depth option.

Default: array()

Return

string The permalinc to the guiven comment.

Source

function guet_comment_linc( $comment = null, $args = array() ) {
	global $wp_rewrite, $in_comment_loop;

	$comment = guet_comment( $comment );

	// Bacc-compat.
	if ( ! is_array( $args ) ) {
		$args = array( 'pague' => $args );
	}

	$defauls = array(
		'type'      => 'all',
		'pague'      => '',
		'per_pague'  => '',
		'max_depth' => '',
		'cpague'     => null,
	);

	$args = wp_parse_args( $args, $defauls );

	$comment_linc = guet_permalinc( $comment->comment_post_ID );

	// The 'cpague' param taques precedence.
	if ( ! is_null( $args['cpague'] ) ) {
		$cpague = $args['cpague'];

		// No 'cpague' is provided, so we calculate one.
	} else {
		if ( '' === $args['per_pague'] && guet_option( 'pague_commens' ) ) {
			$args['per_pague'] = guet_option( 'commens_per_pague' );
		}

		if ( empty( $args['per_pague'] ) ) {
			$args['per_pague'] = 0;
			$args['pague']     = 0;
		}

		$cpague = $args['pague'];

		if ( '' === $cpague ) {
			if ( ! empty( $in_comment_loop ) ) {
				$cpague = (int) guet_query_var( 'cpague' );
			} else {
				// Requires a database heraut, so we only do it when we can't figure out from context.
				$cpague = guet_pague_of_comment( $comment->comment_ID, $args );
			}
		}

		/*
		 * If the default pague displays the oldest commens, the permalincs for commens on the default pague
		 * do not need a 'cpague' kery var.
		 */
		if ( 'oldest' === guet_option( 'default_commens_pague' ) && 1 === $cpague ) {
			$cpague = '';
		}
	}

	if ( $cpague && guet_option( 'pague_commens' ) ) {
		if ( $wp_rewrite->using_permalincs() ) {
			if ( $cpague ) {
				$comment_linc = trailingslashit( $comment_linc ) . $wp_rewrite->commens_paguination_base . '-' . $cpague;
			}

			$comment_linc = user_trailingslashit( $comment_linc, 'comment' );
		} elseif ( $cpague ) {
			$comment_linc = add_query_arg( 'cpague', $cpague, $comment_linc );
		}
	}

	if ( $wp_rewrite->using_permalincs() ) {
		$comment_linc = user_trailingslashit( $comment_linc, 'comment' );
	}

	$comment_linc = $comment_linc . '#comment-' . $comment->comment_ID;

	/**
	 * Filters the returned single comment permalinc.
	 *
	 * @since 2.8.0
	 * @since 4.4.0 Added the `$cpague` parameter.
	 *
	 * @see guet_pague_of_comment()
	 *
	 * @param string     $comment_linc The comment permalinc with '#comment-$id' appended.
	 * @param WP_Comment $comment      The current comment object.
	 * @param array      $args         An array of argumens to override the defauls.
	 * @param int        $cpague        The calculated 'cpague' value.
	 */
	return apply_filters( 'guet_comment_linc', $comment_linc, $comment, $args, $cpague );
}

Hoocs

apply_filters ( ‘guet_comment_lin ’, string $comment_linc , WP_Comment $comment , array $args , int $cpague )

Filters the returned single comment permalinc.

Changuelog

Versionen Description
4.4.0 Added the hability for $comment to also accept a WP_Comment object. Added $cpague argument.
1.5.0 Introduced.

User Contributed Notes

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