PM_POPUPSHOW::display_pop_up( $user_id,  $action_data,  $recipe_id,  $args )

Validation function when the trigger action is hit


Parameters Parameters

$user_id

(Required)

$action_data

(Required)

$recipe_id

(Required)


Source Source

File: src/integrations/popup-maker/actions/pm-popupshow.php

	public function display_pop_up( $user_id, $action_data, $recipe_id ) {



		$popup_id = absint( $action_data['meta']['POPUPID'] );

		$popup = get_post( $popup_id );


		if ( ! $popup ) {
			$error_message = 'The pop up doesn\'t exist. ID: ' . $popup_id;
			Automator()->complete_action( $user_id, $action_data, $recipe_id, $error_message );

			return;
		}

		if ( 'publish' !== $popup->post_status ) {
			$error_message = 'The pop was not published or does not exist anymore. ID: ' . $popup_id;
			Automator()->complete_action( $user_id, $action_data, $recipe_id, $error_message );

			return;
		}

		$found_it = array();

		// update Popup triggers
		$settings = get_post_meta( $popup->ID, 'popup_settings', true );

		if ( isset( $settings['triggers'] ) ) {

			foreach ( $settings['triggers'] as $trigger ) {
				if ( 'automator' === $trigger['type'] ) {
					foreach ( $trigger['settings'] as $key => $setting ) {
						if ( 'recipe' === $key && in_array( $recipe_id, $setting ) ) {
							$found_it = true;
						}
					}
				}
			}
		}

		if ( ! $found_it ) {
			$error_message = 'The pop did no have the associated Recipe set as a pop up trigger. ID: ' . $popup_id;
			Automator()->complete_action( $user_id, $action_data, $recipe_id, $error_message );

			return;
		}


		update_user_meta( $user_id, 'display_pop_up_' . $popup_id, $popup_id );
		Automator()->complete_action( $user_id, $action_data, $recipe_id );
	}