ACF_Admin_Field_Groups::check_activate()publicACF 6.0

Checks for the custom "Activate" bulk action.

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

Хуков нет.

Возвращает

null. Ничего.

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

$ACF_Admin_Field_Groups = new ACF_Admin_Field_Groups();
$ACF_Admin_Field_Groups->check_activate();

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

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

Код ACF_Admin_Field_Groups::check_activate() ACF 6.0.4

public function check_activate() {

	// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Used for redirect notice.
	// Display notice on success redirect.
	if ( isset( $_GET['acfactivatecomplete'] ) ) {
		$ids = array_map( 'intval', explode( ',', $_GET['acfactivatecomplete'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized with intval().
		// phpcs:enable WordPress.Security.NonceVerification.Recommended
		// Generate text.
		$text = sprintf(
			_n( 'Field group activated.', '%s field groups activated.', count( $ids ), 'acf' ),
			count( $ids )
		);

		// Append links to text.
		$links = array();
		foreach ( $ids as $id ) {
			$links[] = '<a href="' . get_edit_post_link( $id ) . '">' . get_the_title( $id ) . '</a>';
		}
		$text .= ' ' . implode( ', ', $links );

		// Add notice.
		acf_add_admin_notice( $text, 'success' );
		return;
	}

	// Find items to activate.
	$ids = array();
	if ( isset( $_GET['acfactivate'] ) ) {
		$ids[] = intval( $_GET['acfactivate'] );
	} elseif ( isset( $_GET['post'], $_GET['action2'] ) && $_GET['action2'] === 'acfactivate' ) {
		$ids = array_map( 'intval', $_GET['post'] );
	}

	if ( $ids ) {
		check_admin_referer( 'bulk-posts' );

		// Activate the field groups and return an array of IDs that were activated.
		$new_ids = array();
		foreach ( $ids as $id ) {
			if ( acf_update_field_group_active_status( $id ) ) {
				$new_ids[] = $id;
			}
		}

		wp_redirect( $this->get_admin_url( '&acfactivatecomplete=' . implode( ',', $new_ids ) ) );
		exit;
	}
}