Single_Product_Sync::handle_request()

Summary

No summary available.

Return

(void)


Source

File: src/BigCommerce/Post_Types/Product/Single_Product_Sync.php

	public function handle_request() {
		$post_id = filter_input( INPUT_GET, 'post_id', FILTER_SANITIZE_NUMBER_INT );
		$nonce   = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_STRING );
		if ( empty( $post_id ) || ! wp_verify_nonce( $nonce, self::ACTION . $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
			wp_die( esc_html( __( 'Invalid request', 'bigcommerce' ) ), esc_html( __( 'Invalid request', 'bigcommerce' ) ), 401 );
			exit;
		}

		$error = $this->sync_product( $post_id );
		if ( $error->has_errors() ) {
			add_settings_error( self::ACTION, $error->get_error_code(), $error->get_error_message() );
		} else {
			add_settings_error( self::ACTION, 'success', sprintf( __( 'Imported product: %s', 'bigcommerce' ), esc_html( get_the_title( $post_id ) ) ), 'updated' );
		}
		set_transient( 'settings_errors', get_settings_errors(), 30 );
		$redirect = filter_input( INPUT_GET, 'redirect_to', FILTER_SANITIZE_URL ) ?: admin_url( 'edit.php?post_type=' . Product::NAME );
		$redirect = add_query_arg( [ 'settings-updated' => 1 ], $redirect );
		wp_safe_redirect( esc_url_raw( $redirect ), 303 );
		exit();
	}

User Contributed Notes

You must log in before being able to contribute a note or feedback.