Automattic\WooCommerce\Internal\Admin\ProductReviews

ReviewsListTable::handle_row_actions()protectedWC 1.0

Generate and display row actions links.

{} It's a method of the class: ReviewsListTable{}

No Hooks.

Return

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->handle_row_actions( $item, $column_name, $primary ) : string;
$item(WP_Comment|mixed) (required)
The product review or reply in context.
$column_name(string|mixed) (required)
Current column name.
$primary(string|mixed) (required)
Primary column name.

Notes

Code of ReviewsListTable::handle_row_actions() WC 7.1.0

protected function handle_row_actions( $item, $column_name, $primary ) : string {
	global $comment_status;

	if ( $primary !== $column_name || ! $this->current_user_can_edit_review ) {
		return '';
	}

	$review_status = wp_get_comment_status( $item );

	$url = add_query_arg(
		[
			'c' => urlencode( $item->comment_ID ),
		],
		admin_url( 'comment.php' )
	);

	$approve_url   = wp_nonce_url( add_query_arg( 'action', 'approvecomment', $url ), "approve-comment_$item->comment_ID" );
	$unapprove_url = wp_nonce_url( add_query_arg( 'action', 'unapprovecomment', $url ), "approve-comment_$item->comment_ID" );
	$spam_url      = wp_nonce_url( add_query_arg( 'action', 'spamcomment', $url ), "delete-comment_$item->comment_ID" );
	$unspam_url    = wp_nonce_url( add_query_arg( 'action', 'unspamcomment', $url ), "delete-comment_$item->comment_ID" );
	$trash_url     = wp_nonce_url( add_query_arg( 'action', 'trashcomment', $url ), "delete-comment_$item->comment_ID" );
	$untrash_url   = wp_nonce_url( add_query_arg( 'action', 'untrashcomment', $url ), "delete-comment_$item->comment_ID" );
	$delete_url    = wp_nonce_url( add_query_arg( 'action', 'deletecomment', $url ), "delete-comment_$item->comment_ID" );

	$actions = [
		'approve'   => '',
		'unapprove' => '',
		'reply'     => '',
		'quickedit' => '',
		'edit'      => '',
		'spam'      => '',
		'unspam'    => '',
		'trash'     => '',
		'untrash'   => '',
		'delete'    => '',
	];

	if ( $comment_status && 'all' !== $comment_status ) {
		if ( 'approved' === $review_status ) {
			$actions['unapprove'] = sprintf(
				'<a href="%s" data-wp-lists="%s" class="vim-u vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
				esc_url( $unapprove_url ),
				esc_attr( "delete:the-comment-list:comment-{$item->comment_ID}:e7e7d3:action=dim-comment&amp;new=unapproved" ),
				esc_attr__( 'Unapprove this review', 'woocommerce' ),
				esc_html__( 'Unapprove', 'woocommerce' )
			);
		} elseif ( 'unapproved' === $review_status ) {
			$actions['approve'] = sprintf(
				'<a href="%s" data-wp-lists="%s" class="vim-a vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
				esc_url( $approve_url ),
				esc_attr( "delete:the-comment-list:comment-{$item->comment_ID}:e7e7d3:action=dim-comment&amp;new=approved" ),
				esc_attr__( 'Approve this review', 'woocommerce' ),
				esc_html__( 'Approve', 'woocommerce' )
			);
		}
	} else {
		$actions['approve'] = sprintf(
			'<a href="%s" data-wp-lists="%s" class="vim-a aria-button-if-js" aria-label="%s">%s</a>',
			esc_url( $approve_url ),
			esc_attr( "dim:the-comment-list:comment-{$item->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved" ),
			esc_attr__( 'Approve this review', 'woocommerce' ),
			esc_html__( 'Approve', 'woocommerce' )
		);

		$actions['unapprove'] = sprintf(
			'<a href="%s" data-wp-lists="%s" class="vim-u aria-button-if-js" aria-label="%s">%s</a>',
			esc_url( $unapprove_url ),
			esc_attr( "dim:the-comment-list:comment-{$item->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved" ),
			esc_attr__( 'Unapprove this review', 'woocommerce' ),
			esc_html__( 'Unapprove', 'woocommerce' )
		);
	}

	if ( 'spam' !== $review_status ) {
		$actions['spam'] = sprintf(
			'<a href="%s" data-wp-lists="%s" class="vim-s vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
			esc_url( $spam_url ),
			esc_attr( "delete:the-comment-list:comment-{$item->comment_ID}::spam=1" ),
			esc_attr__( 'Mark this review as spam', 'woocommerce' ),
			/* translators: "Mark as spam" link. */
			esc_html_x( 'Spam', 'verb', 'woocommerce' )
		);
	} else {
		$actions['unspam'] = sprintf(
			'<a href="%s" data-wp-lists="%s" class="vim-z vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
			esc_url( $unspam_url ),
			esc_attr( "delete:the-comment-list:comment-{$item->comment_ID}:66cc66:unspam=1" ),
			esc_attr__( 'Restore this review from the spam', 'woocommerce' ),
			esc_html_x( 'Not Spam', 'review', 'woocommerce' )
		);
	}

	if ( 'trash' === $review_status ) {
		$actions['untrash'] = sprintf(
			'<a href="%s" data-wp-lists="%s" class="vim-z vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
			esc_url( $untrash_url ),
			esc_attr( "delete:the-comment-list:comment-{$item->comment_ID}:66cc66:untrash=1" ),
			esc_attr__( 'Restore this review from the Trash', 'woocommerce' ),
			esc_html__( 'Restore', 'woocommerce' )
		);
	}

	if ( 'spam' === $review_status || 'trash' === $review_status || ! EMPTY_TRASH_DAYS ) {
		$actions['delete'] = sprintf(
			'<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
			esc_url( $delete_url ),
			esc_attr( "delete:the-comment-list:comment-{$item->comment_ID}::delete=1" ),
			esc_attr__( 'Delete this review permanently', 'woocommerce' ),
			esc_html__( 'Delete Permanently', 'woocommerce' )
		);
	} else {
		$actions['trash'] = sprintf(
			'<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
			esc_url( $trash_url ),
			esc_attr( "delete:the-comment-list:comment-{$item->comment_ID}::trash=1" ),
			esc_attr__( 'Move this review to the Trash', 'woocommerce' ),
			esc_html_x( 'Trash', 'verb', 'woocommerce' )
		);
	}

	if ( 'spam' !== $review_status && 'trash' !== $review_status ) {
		$actions['edit'] = sprintf(
			'<a href="%s" aria-label="%s">%s</a>',
			esc_url(
				add_query_arg(
					[
						'action' => 'editcomment',
						'c'      => urlencode( $item->comment_ID ),
					],
					admin_url( 'comment.php' )
				)
			),
			esc_attr__( 'Edit this review', 'woocommerce' ),
			esc_html__( 'Edit', 'woocommerce' )
		);

		$format = '<button type="button" data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s button-link" aria-expanded="false" aria-label="%s">%s</button>';

		$actions['quickedit'] = sprintf(
			$format,
			esc_attr( $item->comment_ID ),
			esc_attr( $item->comment_post_ID ),
			'edit',
			'vim-q comment-inline',
			esc_attr__( 'Quick edit this review inline', 'woocommerce' ),
			esc_html__( 'Quick Edit', 'woocommerce' )
		);

		$actions['reply'] = sprintf(
			$format,
			esc_attr( $item->comment_ID ),
			esc_attr( $item->comment_post_ID ),
			'replyto',
			'vim-r comment-inline',
			esc_attr__( 'Reply to this review', 'woocommerce' ),
			esc_html__( 'Reply', 'woocommerce' )
		);
	}

	$always_visible = 'excerpt' === get_user_setting( 'posts_list_mode', 'list' );

	$output = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';

	$i = 0;

	foreach ( array_filter( $actions ) as $action => $link ) {
		++$i;

		if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) {
			$sep = '';
		} else {
			$sep = ' | ';
		}

		if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) {
			$action .= ' hide-if-no-js';
		} elseif ( ( 'untrash' === $action && 'trash' === $review_status ) || ( 'unspam' === $action && 'spam' === $review_status ) ) {
			if ( '1' === get_comment_meta( $item->comment_ID, '_wp_trash_meta_status', true ) ) {
				$action .= ' approve';
			} else {
				$action .= ' unapprove';
			}
		}

		$output .= "<span class='$action'>$sep$link</span>";
	}

	$output .= '</div>';
	$output .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . esc_html__( 'Show more details', 'woocommerce' ) . '</span></button>';

	return $output;
}