Automator_Input_Parser::url( null $url = null, null $recipe_id = null, array $trigger_args = array() )


Parameters Parameters

$url

(null) (Optional)

Default value: null

$recipe_id

(null) (Optional)

Default value: null

$trigger_args

(array) (Optional)

Default value: array()


Top ↑

Return Return

(string|string[]|null)


Source Source

File: src/core/lib/utilities/class-automator-input-parser.php

	public function url( $url = null, $recipe_id = null, $trigger_args = array() ) {

		// Sanity check that there was a $field_text passed
		if ( null === $url ) {
			return null;
		}

		$original_url = $url;

		if ( '/' === (string) $url[0] ) {
			// Relative URL prefix with site url
			$url = '{{site_url}}' . $url;
		}

		// Replace Tokens
		$args = array(
			'field_text'  => $url,
			'meta_key'    => null,
			'user_id'     => null,
			'action_data' => null,
			'recipe_id'   => $recipe_id,
		);

		$url = $this->parse_vars( $args, $trigger_args );

		if ( ! preg_match( $this->url_regx, $url ) ) {
			// if the url is not valid and / isn't the first character then the url is missing the site url
			$url = '{{site_url}}' . '/' . $url;
			// Replace Tokens
			$args = array(
				'field_text'  => $url,
				'meta_key'    => null,
				'user_id'     => null,
				'action_data' => null,
				'recipe_id'   => $recipe_id,
			);
			$url  = $this->parse_vars( $args, $trigger_args );

		}

		// Replace all spaces with %20
		$url = str_replace( ' ', '%20', $url );

		if ( ! preg_match( $this->url_regx, $url ) ) {
			// if the url is not valid still then something when wrong...
			return null;
		}

		return $url;
	}