Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Admin

UI::process_edits()privateWC 1.0

Handles updating or adding a new URL to the list of approved directories.

Method of the class: UI{}

No Hooks.

Return

null. Nothing.

Usage

// private - for code of main (parent) class only
$result = $this->process_edits( $url_id );
$url_id(int) (required)
The ID of the rule to be edited/created. Zero if we are creating a new entry.

UI::process_edits() code WC 7.1.1

private function process_edits( int $url_id ) {
	// phpcs:disable WordPress.Security.NonceVerification.Missing
	$url     = esc_url_raw( wp_unslash( $_POST['approved_directory_url'] ?? '' ) );
	$enabled = (bool) sanitize_text_field( wp_unslash( $_POST['approved_directory_enabled'] ?? '' ) );

	if ( empty( $url ) ) {
		return;
	}

	$redirect_url = add_query_arg( 'id', $url_id, $this->table->get_action_url( 'edit', $url_id ) );

	try {
		$upserted = 0 === $url_id
			? $this->register->add_approved_directory( $url, $enabled )
			: $this->register->update_approved_directory( $url_id, $url, $enabled );

		if ( is_integer( $upserted ) ) {
			$redirect_url = add_query_arg( 'url', $upserted, $redirect_url );
		}

		$redirect_url = add_query_arg( 'edit-status', 0 === $url_id ? 'added' : 'updated', $redirect_url );
	} catch ( Exception $e ) {
		$redirect_url = add_query_arg(
			array(
				'edit-status'   => 'failure',
				'submitted-url' => $url,
			),
			$redirect_url
		);
	}

	wp_safe_redirect( $redirect_url );
	exit;
	// phpcs:enable WordPress.Security.NonceVerification.Missing
}