Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories

Register::update_approved_directory()publicWC 1.0

Updates an existing approved directory.

On success or if there is an existing entry for the same URL, returns true.

Метод класса: Register{}

Хуков нет.

Возвращает

true|false.

Использование

$Register = new Register();
$Register->update_approved_directory( $id, $url, $enabled ): bool;
$id(int) (обязательный)
The ID of the approved directory to be updated.
$url(строка) (обязательный)
The new URL for the specified option.
$enabled(true|false)
If the rule is enabled.
По умолчанию: true

Код Register::update_approved_directory() WC 9.3.3

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

	// No need to go any further if the URL is already listed and nothing has changed.
	if ( $existing_path && $existing_path->get_url() === $url && $enabled === $existing_path->is_enabled() ) {
		return true;
	}

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

	if ( false === $wpdb->update( $this->get_table(), $fields, array( 'url_id' => $id ) ) ) {
		throw new ApprovedDirectoriesException( __( 'URL could not be updated (probable database error).', 'woocommerce' ), ApprovedDirectoriesException::DB_ERROR );
	}

	return true;
}