WP_List_Table::bulk_actions()protectedWP 3.1.0

Displays the bulk actions dropdown.

Метод класса: WP_List_Table{}

Хуки из метода

Возвращает

null. Ничего (null).

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->bulk_actions( $which );
$which(строка)
The location of the bulk actions: 'top' or 'bottom'. This is designated as optional for backward compatibility.
По умолчанию: ''

Список изменений

С версии 3.1.0 Введена.

Код WP_List_Table::bulk_actions() WP 6.4.3

protected function bulk_actions( $which = '' ) {
	if ( is_null( $this->_actions ) ) {
		$this->_actions = $this->get_bulk_actions();

		/**
		 * Filters the items in the bulk actions menu of the list table.
		 *
		 * The dynamic portion of the hook name, `$this->screen->id`, refers
		 * to the ID of the current screen.
		 *
		 * @since 3.1.0
		 * @since 5.6.0 A bulk action can now contain an array of options in order to create an optgroup.
		 *
		 * @param array $actions An array of the available bulk actions.
		 */
		$this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores

		$two = '';
	} else {
		$two = '2';
	}

	if ( empty( $this->_actions ) ) {
		return;
	}

	echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' .
		/* translators: Hidden accessibility text. */
		__( 'Select bulk action' ) .
	'</label>';
	echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">\n";
	echo '<option value="-1">' . __( 'Bulk actions' ) . "</option>\n";

	foreach ( $this->_actions as $key => $value ) {
		if ( is_array( $value ) ) {
			echo "\t" . '<optgroup label="' . esc_attr( $key ) . '">' . "\n";

			foreach ( $value as $name => $title ) {
				$class = ( 'edit' === $name ) ? ' class="hide-if-no-js"' : '';

				echo "\t\t" . '<option value="' . esc_attr( $name ) . '"' . $class . '>' . $title . "</option>\n";
			}
			echo "\t" . "</optgroup>\n";
		} else {
			$class = ( 'edit' === $key ) ? ' class="hide-if-no-js"' : '';

			echo "\t" . '<option value="' . esc_attr( $key ) . '"' . $class . '>' . $value . "</option>\n";
		}
	}

	echo "</select>\n";

	submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
	echo "\n";
}