bp_core_optouts_admin_load()

Set up the Opt-outs admin page.


Description Description

Loaded before the page is rendered, this function does all initial setup, including: processing form requests, registering contextual help, and setting up screen options.


Source Source

File: bp-core/admin/bp-core-admin-optouts.php

function bp_core_optouts_admin_load() {
	global $bp_optouts_list_table;

	// Build redirection URL.
	$redirect_to = remove_query_arg( array( 'action', 'error', 'updated', 'activated', 'notactivated', 'deleted', 'notdeleted', 'resent', 'notresent', 'do_delete', 'do_resend', 'do_activate', '_wpnonce', 'signup_ids' ), $_SERVER['REQUEST_URI'] );
	$doaction    = bp_admin_list_table_current_bulk_action();

	/**
	 * Fires at the start of the nonmember opt-outs admin load.
	 *
	 * @since 8.0.0
	 *
	 * @param string $doaction Current bulk action being processed.
	 * @param array  $_REQUEST Current $_REQUEST global.
	 */
	do_action( 'bp_optouts_admin_load', $doaction, $_REQUEST );

	/**
	 * Filters the allowed actions for use in the nonmember opt-outs admin page.
	 *
	 * @since 8.0.0
	 *
	 * @param array $value Array of allowed actions to use.
	 */
	$allowed_actions = apply_filters( 'bp_optouts_admin_allowed_actions', array( 'do_delete',  'do_resend' ) );

	if ( ! in_array( $doaction, $allowed_actions ) || ( -1 == $doaction ) ) {

		require_once( ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php' );
		$bp_optouts_list_table = new BP_Optouts_List_Table();

		// The per_page screen option.
		add_screen_option( 'per_page', array( 'label' => _x( 'Nonmember opt-outs', 'Nonmember opt-outs per page (screen options)', 'buddypress' ) ) );

		// Current screen.
		$current_screen = get_current_screen();

		$current_screen->add_help_tab(
			array(
				'id'      => 'bp-optouts-overview',
				'title'   => __( 'Overview', 'buddypress' ),
				'content' =>
					'<p>' . __( 'This is the administration screen for nonmember opt-outs on your site.', 'buddypress' ) . '</p>' .
					'<p>' . __( 'From the screen options, you can customize the displayed columns and the pagination of this screen.', 'buddypress' ) . '</p>' .
					'<p>' . __( 'You can reorder the list of opt-outs by clicking on the Email Sender, Email Type or Date Modified column headers.', 'buddypress' ) . '</p>' .
					'<p>' . __( 'Using the search form, you can search for an opt-out to a specific email address.', 'buddypress' ) . '</p>',
			)
		);

		$current_screen->add_help_tab(
			array(
				'id'      => 'bp-optouts-actions',
				'title'   => __( 'Actions', 'buddypress' ),
				'content' =>
					'<p>' . __( 'Hovering over a row in the opt-outs list will display action links that allow you to manage the opt-out. You can perform the following actions:', 'buddypress' ) . '</p>' .
					'<ul><li>' . __( '"Delete" allows you to delete the record of an opt-out. You will be asked to confirm this deletion.', 'buddypress' ) . '</li></ul>' .
					'<p>' . __( 'Bulk actions allow you to perform these actions for the selected rows.', 'buddypress' ) . '</p>',
			)
		);

		// Help panel - sidebar links.
		$current_screen->set_help_sidebar(
			'<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
			'<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
		);

		// Add accessible hidden headings and text for the Pending Users screen.
		$current_screen->set_screen_reader_content(
			array(
				/* translators: accessibility text */
				'heading_views'      => __( 'Filter opt-outs list', 'buddypress' ),
				/* translators: accessibility text */
				'heading_pagination' => __( 'Opt-out list navigation', 'buddypress' ),
				/* translators: accessibility text */
				'heading_list'       => __( 'Opt-outs list', 'buddypress' ),
			)
		);

	} else {
		if ( empty( $_REQUEST['optout_ids' ] ) ) {
			return;
		}
		$optout_ids = wp_parse_id_list( $_REQUEST['optout_ids' ] );

		// Handle optout deletion.
		if ( 'do_delete' == $doaction ) {

			// Nonce check.
			check_admin_referer( 'optouts_delete' );

			$success = 0;
			foreach ( $optout_ids as $optout_id ) {
				if ( bp_delete_optout_by_id( $optout_id ) ) {
					$success++;
				}
			}

			$query_arg = array( 'updated' => 'deleted' );

			if ( ! empty( $success ) ) {
				$query_arg['deleted'] = $success;
			}

			$notdeleted = count( $optout_ids ) - $success;
			if ( $notdeleted > 0 ) {
				$query_arg['notdeleted'] = $notdeleted;
			}

			$redirect_to = add_query_arg( $query_arg, $redirect_to );

			bp_core_redirect( $redirect_to );

		// Plugins can update other stuff from here.
		} else {

			/**
			 * Fires at end of opt-outs admin load
			 * if doaction does not match any actions.
			 *
			 * @since 2.0.0
			 *
			 * @param string $doaction Current bulk action being processed.
			 * @param array  $_REQUEST Current $_REQUEST global.
			 * @param string $redirect Determined redirect url to send user to.
			 */
			do_action( 'bp_core_admin_update_optouts', $doaction, $_REQUEST, $redirect_to );

			bp_core_redirect( $redirect_to );
		}
	}
}


Top ↑

Changelog Changelog

Changelog
Version Description
8.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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