Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories

Register::add_approved_directory()publicWC 1.0

Adds a new URL path.

On success (or if the URL was already added) returns the URL ID, or else returns boolean false.

Method of the class: Register{}

No Hooks.

Return

Int.

Usage

$Register = new Register();
$Register->add_approved_directory( $url, $enabled ): int;
$url(string) (required)
The URL of the approved directory.
$enabled(true|false)
If the rule is enabled.
Default: true

Register::add_approved_directory() code WC 7.1.0

public function add_approved_directory( string $url, bool $enabled = true ): int {
	$url      = $this->prepare_url_for_upsert( $url );
	$existing = $this->get_by_url( $url );

	if ( $existing ) {
		return $existing->get_id();
	}

	global $wpdb;
	$insert_fields = array(
		'url'     => $url,
		'enabled' => (int) $enabled,
	);

	if ( false !== $wpdb->insert( $this->get_table(), $insert_fields ) ) {
		return $wpdb->insert_id;
	}

	throw new ApprovedDirectoriesException( __( 'URL could not be added (probable database error).', 'woocommerce' ), ApprovedDirectoriesException::DB_ERROR );
}