Automattic\WooCommerce\Internal\Admin\Notes

MerchantEmailNotifications::trigger_notification_action()public staticWC 1.0

Trigger the note action.

Method of the class: MerchantEmailNotifications{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = MerchantEmailNotifications::trigger_notification_action();

MerchantEmailNotifications::trigger_notification_action() code WC 8.7.0

public static function trigger_notification_action() {
	/* phpcs:disable WordPress.Security.NonceVerification */
	if (
		! isset( $_GET['external_redirect'] ) ||
		1 !== intval( $_GET['external_redirect'] ) ||
		! isset( $_GET['user'] ) ||
		! isset( $_GET['note'] ) ||
		! isset( $_GET['action'] )
	) {
		return;
	}
	$note_id   = intval( $_GET['note'] );
	$action_id = intval( $_GET['action'] );
	$user_id   = intval( $_GET['user'] );
	/* phpcs:enable */

	$note = Notes::get_note( $note_id );

	if ( ! $note || Note::E_WC_ADMIN_NOTE_EMAIL !== $note->get_type() ) {
		return;
	}

	$triggered_action = Notes::get_action_by_id( $note, $action_id );

	if ( ! $triggered_action ) {
		return;
	}

	Notes::trigger_note_action( $note, $triggered_action );
	$url = $triggered_action->query;

	// We will use "wp_safe_redirect" when it's an internal redirect.
	if ( strpos( $url, 'http' ) === false ) {
		wp_safe_redirect( $url );
	} else {
		header( 'Location: ' . $url );
	}
	exit();
}