WP_MS_Sites_List_Table::handle_row_actions( array $item, string $column_name, string $primary ): string

In this article

Generates and displays row action links.

Parameters

$itemarrayrequired
Site being acted upon.
$column_namestringrequired
Current column name.
$primarystringrequired
Primary column name.

Return

string Row actions output for sites in Multisite, or an empty string if the current column is not the primary column.

Source

protected function handle_row_actions( $item, $column_name, $primary ) {
	if ( $primary !== $column_name ) {
		return '';
	}

	// Restores the more descriptive, specific name for use within this method.
	$blog = $item;

	$blogname = untrailingslashit( $blog['domain'] . $blog['path'] );

	// Preordered.
	$actions = array(
		'edit'       => '',
		'backend'    => '',
		'activate'   => '',
		'deactivate' => '',
		'archive'    => '',
		'unarchive'  => '',
		'spam'       => '',
		'unspam'     => '',
		'delete'     => '',
		'visit'      => '',
	);

	$actions['edit'] = sprintf(
		'<a href="%1$s">%2$s</a>',
		esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ),
		__( 'Edit' )
	);

	$actions['backend'] = sprintf(
		'<a href="%1$s" class="edit">%2$s</a>',
		esc_url( get_admin_url( $blog['blog_id'] ) ),
		__( 'Dashboard' )
	);

	if ( ! is_main_site( $blog['blog_id'] ) ) {
		if ( '1' === $blog['deleted'] ) {
			$actions['activate'] = sprintf(
				'<a href="%1$s">%2$s</a>',
				esc_url(
					wp_nonce_url(
						network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] ),
						'activateblog_' . $blog['blog_id']
					)
				),
				__( 'Activate' )
			);
		} else {
			$actions['deactivate'] = sprintf(
				'<a href="%1$s">%2$s</a>',
				esc_url(
					wp_nonce_url(
						network_admin_url( 'sites.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] ),
						'deactivateblog_' . $blog['blog_id']
					)
				),
				__( 'Deactivate' )
			);
		}

		if ( '1' === $blog['archived'] ) {
			$actions['unarchive'] = sprintf(
				'<a href="%1$s">%2$s</a>',
				esc_url(
					wp_nonce_url(
						network_admin_url( 'sites.php?action=confirm&amp;action2=unarchiveblog&amp;id=' . $blog['blog_id'] ),
						'unarchiveblog_' . $blog['blog_id']
					)
				),
				__( 'Unarchive' )
			);
		} else {
			$actions['archive'] = sprintf(
				'<a href="%1$s">%2$s</a>',
				esc_url(
					wp_nonce_url(
						network_admin_url( 'sites.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] ),
						'archiveblog_' . $blog['blog_id']
					)
				),
				_x( 'Archive', 'verb; site' )
			);
		}

		if ( '1' === $blog['spam'] ) {
			$actions['unspam'] = sprintf(
				'<a href="%1$s">%2$s</a>',
				esc_url(
					wp_nonce_url(
						network_admin_url( 'sites.php?action=confirm&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] ),
						'unspamblog_' . $blog['blog_id']
					)
				),
				_x( 'Not Spam', 'site' )
			);
		} else {
			$actions['spam'] = sprintf(
				'<a href="%1$s">%2$s</a>',
				esc_url(
					wp_nonce_url(
						network_admin_url( 'sites.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] ),
						'spamblog_' . $blog['blog_id']
					)
				),
				_x( 'Spam', 'site' )
			);
		}

		if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) {
			$actions['delete'] = sprintf(
				'<a href="%1$s">%2$s</a>',
				esc_url(
					wp_nonce_url(
						network_admin_url( 'sites.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] ),
						'deleteblog_' . $blog['blog_id']
					)
				),
				__( 'Delete' )
			);
		}
	}

	$actions['visit'] = sprintf(
		'<a href="%1$s" rel="bookmark">%2$s</a>',
		esc_url( get_home_url( $blog['blog_id'], '/' ) ),
		__( 'Visit' )
	);

	/**
	 * Filters the action links displayed for each site in the Sites list table.
	 *
	 * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by
	 * default for each site. The site's status determines whether to show the
	 * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and
	 * 'Not Spam' or 'Spam' link for each site.
	 *
	 * @since 3.1.0
	 *
	 * @param string[] $actions  An array of action links to be displayed.
	 * @param int      $blog_id  The site ID.
	 * @param string   $blogname Site path, formatted depending on whether it is a sub-domain
	 *                           or subdirectory multisite installation.
	 */
	$actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname );

	return $this->row_actions( $actions );
}

Hooks

apply_filters( ‘manage_sites_action_links’, string[] $actions, int $blog_id, string $blogname )

Filters the action links displayed for each site in the Sites list table.

Changelog

VersionDescription
5.9.0Renamed $blog to $item to match parent class for PHP 8 named parameter support.
4.3.0Introduced.

User Contributed Notes

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