Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories
Register::update_approved_directory
Updates an existing approved directory.
On success or if there is an existing entry for the same URL, returns true.
Method of the class: Register{}
No Hooks.
Returns
true|false.
Usage
$Register = new Register(); $Register->update_approved_directory( $id, $url, $enabled ): bool;
- $id(int) (required)
- The ID of the approved directory to be updated.
- $url(string) (required)
- The new URL for the specified option.
- $enabled(true|false)
- If the rule is enabled.
Default:true
Register::update_approved_directory() Register::update approved directory code WC 10.5.0
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;
}