WP_Async_Task::__construct( int $auth_level = self::BOTH )

Description #

Constructor to wire up the necessary actions

Which hooks the asynchronous postback happens on can be set by the $auth_level parameter. There are essentially three options: logged in users only, logged out users only, or both. Set this when you instantiate an object by using one of the three class constants to do so:

  • LOGGED_IN
  • LOGGED_OUT
  • BOTH $auth_level defaults to BOTH

Parameters #

  • $auth_level
    int (Optional) The authentication level to use (see above) Default value: self::BOTH

Source #

File: lib/class-wp-async-task.php

		public function __construct( $auth_level = self::BOTH ) {
			if ( empty( $this->action ) ) {
				throw new Exception( 'Action not defined for class ' . __CLASS__ );
			}
			add_action( $this->action, array( $this, 'launch' ), (int) $this->priority, (int) $this->argument_count );
			if ( $auth_level & self::LOGGED_IN ) {
				add_action( "admin_post_wp_async_$this->action", array( $this, 'handle_postback' ) );
			}
			if ( $auth_level & self::LOGGED_OUT ) {
				add_action( "admin_post_nopriv_wp_async_$this->action", array( $this, 'handle_postback' ) );
			}
		}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment