PUM_Admin_Ajax::save_popup_enabled_state()

Sets the enabled meta field to on or off


Description Description


Source Source

File: classes/Admin/Ajax.php

	public static function save_popup_enabled_state() {
		$args = wp_parse_args(
			$_REQUEST,
			array(
				'popupID' => 0,
				'active'  => 1,
			)
		);

		// Ensures Popup ID is an int and not 0.
		$popup_id = intval( $args['popupID'] );
		if ( 0 === $popup_id ) {
			wp_send_json_error( 'Invalid popup ID provided.' );
		}

		// Ensures active state is 0 or 1.
		$enabled = intval( $args['enabled'] );
		if ( ! in_array( $enabled, array( 0, 1 ), true ) ) {
			wp_send_json_error( 'Invalid enabled state provided.' );
		}

		// Verify the nonce.
		if ( ! wp_verify_nonce( $_REQUEST['nonce'], "pum_save_enabled_state_$popup_id" ) ) {
			wp_send_json_error();
		}

		// Get our popup and previous value.
		$popup    = pum_get_popup( $popup_id );
		$previous = $popup->get_meta( 'enabled' );

		// If value is the same, bail now.
		if ( $previous === $enabled ) {
			wp_send_json_success();
		}

		// Update our value.
		$results = $popup->update_meta( 'enabled', $enabled );

		if ( false === $results ) {
			wp_send_json_error( 'Error updating enabled state.' );
			PUM_Utils_Logging::instance()->log( "Error updating enabled state on $popup_id. Previous value: $previous. New value: $enabled" );
		} else {
			wp_send_json_success();
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.12.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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