Copy_Recipe_Parts::modify_tokens( $content,  $post_parent,  $new_post_id )


Parameters Parameters

$content

(Required)


Top ↑

Return Return

(mixed)


Source Source

File: src/core/admin/class-copy-recipe-parts.php

	public function modify_tokens( $content, $post_parent = 0, $new_post_id = 0 ) {

		//Check if it's a webhook URL
		if ( 0 !== $new_post_id && ! is_array( $content ) && preg_match( '/\/wp-json\/uap\/v2\/uap-/', $content ) ) {
			// Only modify webhook URL of the trigger. We are leaving webhook URL of action alone.
			if ( 'uo-trigger' === get_post_type( $new_post_id ) ) {
				$new     = sprintf( 'uap/v2/uap-%d-%d', wp_get_post_parent_id( $new_post_id ), $new_post_id );
				$content = preg_replace( '/uap\/v2\/uap-.+/', $new, $content );
			}
		}

		if ( empty( $this->trigger_tokens ) ) {
			return $content;
		}

		// Loop thru multiple triggers and update token's trigger ID based on that.
		foreach ( $this->trigger_tokens as $prev_id => $new_id ) {
			$content = preg_replace( '/{{' . $prev_id . ':/', '{{' . $new_id . ':', $content );
		}

		return $content;
	}