Initial Commit
This commit is contained in:
725
inc/api/class-register-endpoint.php
Normal file
725
inc/api/class-register-endpoint.php
Normal file
@ -0,0 +1,725 @@
|
||||
<?php
|
||||
/**
|
||||
* The Register API endpoint.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage API
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\API;
|
||||
|
||||
use \WP_Ultimo\Checkout\Cart;
|
||||
use \WP_Ultimo\Database\Sites\Site_Type;
|
||||
use \WP_Ultimo\Database\Payments\Payment_Status;
|
||||
use \WP_Ultimo\Database\Memberships\Membership_Status;
|
||||
use \WP_Ultimo\Objects\Billing_Address;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* The Register API endpoint.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Register_Endpoint {
|
||||
|
||||
use \WP_Ultimo\Traits\Singleton;
|
||||
|
||||
/**
|
||||
* Loads the initial register route hooks.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
add_action('wu_register_rest_routes', array($this, 'register_route'));
|
||||
|
||||
} // end init;
|
||||
|
||||
/**
|
||||
* Adds a new route to the wu namespace, for the register endpoint.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Ultimo\API $api The API main singleton.
|
||||
* @return void
|
||||
*/
|
||||
public function register_route($api) {
|
||||
|
||||
$namespace = $api->get_namespace();
|
||||
|
||||
register_rest_route($namespace, '/register', array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'handle_get'),
|
||||
'permission_callback' => \Closure::fromCallable([$api, 'check_authorization']),
|
||||
));
|
||||
|
||||
register_rest_route($namespace, '/register', array(
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'handle_endpoint'),
|
||||
'permission_callback' => \Closure::fromCallable([$api, 'check_authorization']),
|
||||
'args' => $this->get_rest_args(),
|
||||
));
|
||||
|
||||
} // end register_route;
|
||||
|
||||
/**
|
||||
* Handle the register endpoint get for zapier integration reasons.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_REST_Request $request WP Request Object.
|
||||
* @return array
|
||||
*/
|
||||
public function handle_get($request) {
|
||||
|
||||
return array(
|
||||
'registration_status' => wu_get_setting('enable_registration', true) ? 'open' : 'closed',
|
||||
);
|
||||
|
||||
} // end handle_get;
|
||||
|
||||
/**
|
||||
* Handle the register endpoint logic.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_REST_Request $request WP Request Object.
|
||||
* @return array
|
||||
*/
|
||||
public function handle_endpoint($request) {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$params = json_decode($request->get_body(), true);
|
||||
|
||||
if (\WP_Ultimo\API::get_instance()->should_log_api_calls()) {
|
||||
|
||||
wu_log_add('api-calls', json_encode($params, JSON_PRETTY_PRINT));
|
||||
|
||||
} // end if;
|
||||
|
||||
$validation_errors = $this->validate($params);
|
||||
|
||||
if (is_wp_error($validation_errors)) {
|
||||
|
||||
$validation_errors->add_data(array(
|
||||
'status' => 400,
|
||||
));
|
||||
|
||||
return $validation_errors;
|
||||
|
||||
} // end if;
|
||||
|
||||
$wpdb->query('START TRANSACTION');
|
||||
|
||||
try {
|
||||
|
||||
$customer = $this->maybe_create_customer($params);
|
||||
|
||||
if (is_wp_error($customer)) {
|
||||
|
||||
return $this->rollback_and_return($customer);
|
||||
|
||||
} // end if;
|
||||
|
||||
$customer->update_last_login(true, true);
|
||||
|
||||
$customer->add_note(array(
|
||||
'text' => __('Created via REST API', 'wp-ultimo'),
|
||||
'author_id' => $customer->get_user_id(),
|
||||
));
|
||||
|
||||
/*
|
||||
* Payment Method defaults
|
||||
*/
|
||||
$payment_method = wp_parse_args(wu_get_isset($params, 'payment_method'), array(
|
||||
'gateway' => '',
|
||||
'gateway_customer_id' => '',
|
||||
'gateway_subscription_id' => '',
|
||||
'gateway_payment_id' => '',
|
||||
));
|
||||
|
||||
/*
|
||||
* Cart params and creation
|
||||
*/
|
||||
$cart_params = $params;
|
||||
|
||||
$cart_params = wp_parse_args($cart_params, array(
|
||||
'type' => 'new',
|
||||
));
|
||||
|
||||
$cart = new Cart($cart_params);
|
||||
|
||||
/*
|
||||
* Validates if the cart is valid.
|
||||
*/
|
||||
if ($cart->is_valid() && count($cart->get_line_items()) === 0) {
|
||||
|
||||
return new \WP_Error('invalid_cart', __('Products are required.', 'wp-ultimo'), array_merge((array) $cart->done(), array(
|
||||
'status' => 400,
|
||||
)));
|
||||
|
||||
} // end if;
|
||||
|
||||
/*
|
||||
* Get Membership data
|
||||
*/
|
||||
$membership_data = $cart->to_membership_data();
|
||||
|
||||
$membership_data = array_merge($membership_data, wu_get_isset($params, 'membership', array(
|
||||
'status' => Membership_Status::PENDING,
|
||||
)));
|
||||
|
||||
$membership_data['customer_id'] = $customer->get_id();
|
||||
$membership_data['gateway'] = wu_get_isset($payment_method, 'gateway');
|
||||
$membership_data['gateway_subscription_id'] = wu_get_isset($payment_method, 'gateway_subscription_id');
|
||||
$membership_data['gateway_customer_id'] = wu_get_isset($payment_method, 'gateway_customer_id');
|
||||
$membership_data['auto_renew'] = wu_get_isset($params, 'auto_renew');
|
||||
|
||||
/*
|
||||
* Unset the status because we are going to transition it later.
|
||||
*/
|
||||
$membership_status = $membership_data['status'];
|
||||
|
||||
unset($membership_data['status']);
|
||||
|
||||
$membership = wu_create_membership($membership_data);
|
||||
|
||||
if (is_wp_error($membership)) {
|
||||
|
||||
return $this->rollback_and_return($membership);
|
||||
|
||||
} // end if;
|
||||
|
||||
$membership->add_note(array(
|
||||
'text' => __('Created via REST API', 'wp-ultimo'),
|
||||
'author_id' => $customer->get_user_id(),
|
||||
));
|
||||
|
||||
$payment_data = $cart->to_payment_data();
|
||||
|
||||
$payment_data = array_merge($payment_data, wu_get_isset($params, 'payment', array(
|
||||
'status' => Payment_Status::PENDING,
|
||||
)));
|
||||
|
||||
/*
|
||||
* Unset the status because we are going to transition it later.
|
||||
*/
|
||||
$payment_status = $payment_data['status'];
|
||||
|
||||
unset($payment_data['status']);
|
||||
|
||||
$payment_data['customer_id'] = $customer->get_id();
|
||||
$payment_data['membership_id'] = $membership->get_id();
|
||||
$payment_data['gateway'] = wu_get_isset($payment_method, 'gateway');
|
||||
$payment_data['gateway_payment_id'] = wu_get_isset($payment_method, 'gateway_payment_id');
|
||||
|
||||
$payment = wu_create_payment($payment_data);
|
||||
|
||||
if (is_wp_error($payment)) {
|
||||
|
||||
return $this->rollback_and_return($payment);
|
||||
|
||||
} // end if;
|
||||
|
||||
$payment->add_note(array(
|
||||
'text' => __('Created via REST API', 'wp-ultimo'),
|
||||
'author_id' => $customer->get_user_id(),
|
||||
));
|
||||
|
||||
$site = false;
|
||||
|
||||
/*
|
||||
* Site creation.
|
||||
*/
|
||||
if (wu_get_isset($params, 'site')) {
|
||||
|
||||
$site = $this->maybe_create_site($params, $membership);
|
||||
|
||||
if (is_wp_error($site)) {
|
||||
|
||||
return $this->rollback_and_return($site);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
/*
|
||||
* Deal with status changes.
|
||||
*/
|
||||
if ($membership_status !== $membership->get_status()) {
|
||||
|
||||
$membership->set_status($membership_status);
|
||||
|
||||
$membership->save();
|
||||
|
||||
/*
|
||||
* The above change might trigger a site publication
|
||||
* to take place, so we need to try to fetch the site
|
||||
* again, this time as a WU Site object.
|
||||
*/
|
||||
if ($site) {
|
||||
|
||||
$wp_site = get_site_by_path($site['domain'], $site['path']);
|
||||
|
||||
if ($wp_site) {
|
||||
|
||||
$site['id'] = $wp_site->blog_id;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
if ($payment_status !== $payment->get_status()) {
|
||||
|
||||
$payment->set_status($payment_status);
|
||||
|
||||
$payment->save();
|
||||
|
||||
} // end if;
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
$wpdb->query('ROLLBACK');
|
||||
|
||||
return new \WP_Error('registration_error', $e->getMessage(), array('status' => 500));
|
||||
|
||||
} // end try;
|
||||
|
||||
$wpdb->query('COMMIT');
|
||||
|
||||
/*
|
||||
* We have everything we need now.
|
||||
*/
|
||||
return array(
|
||||
'membership' => $membership->to_array(),
|
||||
'customer' => $customer->to_array(),
|
||||
'payment' => $payment->to_array(),
|
||||
'site' => $site ? $site : array('id' => 0),
|
||||
);
|
||||
|
||||
} // end handle_endpoint;
|
||||
|
||||
/**
|
||||
* Returns the list of arguments allowed on to the endpoint.
|
||||
*
|
||||
* This is also used to build the documentation page for the endpoint.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_rest_args() {
|
||||
/*
|
||||
* Billing Address Fields
|
||||
*/
|
||||
$billing_address_fields = Billing_Address::fields_for_rest(false);
|
||||
|
||||
$customer_args = array(
|
||||
'customer_id' => array(
|
||||
'description' => __('The customer ID, if the customer already exists. If you also need to create a customer/wp user, use the "customer" property.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
),
|
||||
'customer' => array(
|
||||
'description' => __('Customer data. Needs to be present when customer id is not.', 'wp-ultimo'),
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'user_id' => array(
|
||||
'description' => __('Existing WordPress user id to attach this customer to. If you also need to create a WordPress user, pass the properties "username", "password", and "email".', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
),
|
||||
'username' => array(
|
||||
'description' => __('The customer username. This is used to create the WordPress user.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'minLength' => 4,
|
||||
),
|
||||
'password' => array(
|
||||
'description' => __('The customer password. This is used to create the WordPress user. Note that no validation is performed here to enforce strength.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'minLength' => 6,
|
||||
),
|
||||
'email' => array(
|
||||
'description' => __('The customer email address. This is used to create the WordPress user.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'format' => 'email',
|
||||
),
|
||||
'billing_address' => array(
|
||||
'type' => 'object',
|
||||
'properties' => $billing_address_fields,
|
||||
)
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$membership_args = array(
|
||||
'membership' => array(
|
||||
'description' => __('The membership data is automatically generated based on the cart info passed (e.g. products) but can be overridden with this property.', 'wp-ultimo'),
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'status' => array(
|
||||
'description' => __('The membership status.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'enum' => array_values(Membership_Status::get_allowed_list()),
|
||||
'default' => Membership_Status::PENDING,
|
||||
),
|
||||
'date_expiration' => array(
|
||||
'description' => __('The membership expiration date. Must be a valid PHP date format.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
),
|
||||
'date_trial_end' => array(
|
||||
'description' => __('The membership trial end date. Must be a valid PHP date format.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
),
|
||||
'date_activated' => array(
|
||||
'description' => __('The membership activation date. Must be a valid PHP date format.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
),
|
||||
'date_renewed' => array(
|
||||
'description' => __('The membership last renewed date. Must be a valid PHP date format.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
),
|
||||
'date_cancellation' => array(
|
||||
'description' => __('The membership cancellation date. Must be a valid PHP date format.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
),
|
||||
'date_payment_plan_completed' => array(
|
||||
'description' => __('The membership completion date. Used when the membership is limited to a limited number of billing cycles. Must be a valid PHP date format.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$payment_args = array(
|
||||
'payment' => array(
|
||||
'description' => __('The payment data is automatically generated based on the cart info passed (e.g. products) but can be overridden with this property.', 'wp-ultimo'),
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'status' => array(
|
||||
'description' => __('The payment status.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'enum' => array_values(Payment_Status::get_allowed_list()),
|
||||
'default' => Payment_Status::PENDING,
|
||||
),
|
||||
),
|
||||
),
|
||||
'payment_method' => array(
|
||||
'description' => __('Payment method information. Useful when using the REST API to integrate other payment methods.', 'wp-ultimo'),
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'gateway' => array(
|
||||
'description' => __('The gateway name. E.g. stripe.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
),
|
||||
'gateway_customer_id' => array(
|
||||
'description' => __('The customer ID on the gateway system.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
),
|
||||
'gateway_subscription_id' => array(
|
||||
'description' => __('The subscription ID on the gateway system.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
),
|
||||
'gateway_payment_id' => array(
|
||||
'description' => __('The payment ID on the gateway system.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$site_args = array(
|
||||
'site' => array(
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'site_url' => array(
|
||||
'type' => 'string',
|
||||
'description' => __('The site subdomain or subdirectory (depending on your Multisite install). This would be "test" in "test.your-network.com".', 'wp-ultimo'),
|
||||
'minLength' => 4,
|
||||
'required' => true,
|
||||
),
|
||||
'site_title' => array(
|
||||
'type' => 'string',
|
||||
'description' => __('The site title. E.g. My Amazing Site', 'wp-ultimo'),
|
||||
'minLength' => 4,
|
||||
'required' => true,
|
||||
),
|
||||
'publish' => array(
|
||||
'description' => __('If we should publish this site regardless of membership/payment status. Sites are created as pending by default, and are only published when a payment is received or the status of the membership changes to "active". This flag allows you to bypass the pending state.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
),
|
||||
'template_id' => array(
|
||||
'description' => __('The template ID we should copy when creating this site. If left empty, the value dictated by the products will be used.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
),
|
||||
'site_meta' => array(
|
||||
'description' => __('An associative array of key values to be saved as site_meta.', 'wp-ultimo'),
|
||||
'type' => 'object',
|
||||
),
|
||||
'site_option' => array(
|
||||
'description' => __('An associative array of key values to be saved as site_options. Useful for changing plugin settings and other site configurations.', 'wp-ultimo'),
|
||||
'type' => 'object',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$cart_args = array(
|
||||
'products' => array(
|
||||
'description' => __('The products to be added to this membership. Takes an array of product ids or slugs.', 'wp-ultimo'),
|
||||
'uniqueItems' => true,
|
||||
'type' => 'array',
|
||||
),
|
||||
'duration' => array(
|
||||
'description' => __('The membership duration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'duration_unit' => array(
|
||||
'description' => __('The membership duration unit.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'default' => 'month',
|
||||
'enum' => array(
|
||||
'day',
|
||||
'week',
|
||||
'month',
|
||||
'year',
|
||||
),
|
||||
),
|
||||
'discount_code' => array(
|
||||
'description' => __('A discount code. E.g. PROMO10.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
),
|
||||
'auto_renew' => array(
|
||||
'description' => __('The membership auto-renew status. Useful when integrating with other payment options via this REST API.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'required' => true,
|
||||
),
|
||||
'country' => array(
|
||||
'description' => __('The customer country. Used to calculate taxes and check if registration is allowed for that country.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'default' => '',
|
||||
),
|
||||
'currency' => array(
|
||||
'description' => __('The currency to be used.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
),
|
||||
);
|
||||
|
||||
$args = array_merge($customer_args, $membership_args, $cart_args, $payment_args, $site_args);
|
||||
|
||||
return apply_filters('wu_rest_register_endpoint_args', $args, $this);
|
||||
|
||||
} // end get_rest_args;
|
||||
/**
|
||||
* Maybe create a customer, if needed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $p The request parameters.
|
||||
* @return \WP_Ultimo\Models\Customer|\WP_Error
|
||||
*/
|
||||
public function maybe_create_customer($p) {
|
||||
|
||||
$customer_id = wu_get_isset($p, 'customer_id');
|
||||
|
||||
if ($customer_id) {
|
||||
|
||||
$customer = wu_get_customer($customer_id);
|
||||
|
||||
if (!$customer) {
|
||||
|
||||
return new \WP_Error('customer_not_found', __('The customer id sent does not correspond to a valid customer.', 'wp-ultimo'));
|
||||
|
||||
} // end if;
|
||||
|
||||
} else {
|
||||
|
||||
$customer = wu_create_customer($p['customer']);
|
||||
|
||||
} // end if;
|
||||
|
||||
return $customer;
|
||||
|
||||
} // end maybe_create_customer;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $p The request parameters.
|
||||
* @param \WP_Ultimo\Models\Membership $membership The membership created.
|
||||
* @return array|\WP_Ultimo\Models\Site\|\WP_Error
|
||||
*/
|
||||
public function maybe_create_site($p, $membership) {
|
||||
|
||||
$site_data = $p['site'];
|
||||
|
||||
/*
|
||||
* Let's get a list of membership sites.
|
||||
* This list includes pending sites as well.
|
||||
*/
|
||||
$sites = $membership->get_sites();
|
||||
|
||||
/*
|
||||
* Decide if we should create a new site or not.
|
||||
*
|
||||
* When should we create a new pending site?
|
||||
* There are a couple of rules:
|
||||
* - The membership must not have a pending site;
|
||||
* - The membership must not have an existing site;
|
||||
*
|
||||
* The get_sites method already includes pending sites,
|
||||
* so we can safely rely on it.
|
||||
*/
|
||||
if (!empty($sites)) {
|
||||
/*
|
||||
* Returns the first site on that list.
|
||||
* This is not ideal, but since we'll usually only have
|
||||
* one site here, it's ok. for now.
|
||||
*/
|
||||
return current($sites);
|
||||
|
||||
} // end if;
|
||||
|
||||
$site_url = wu_get_isset($site_data, 'site_url');
|
||||
|
||||
$d = wu_get_site_domain_and_path($site_url);
|
||||
|
||||
/*
|
||||
* Validates the site url.
|
||||
*/
|
||||
$results = wpmu_validate_blog_signup($site_url, wu_get_isset($site_data, 'site_title'), $membership->get_customer()->get_user());
|
||||
|
||||
if ($results['errors']->has_errors()) {
|
||||
|
||||
return $results['errors'];
|
||||
|
||||
} // end if;
|
||||
|
||||
/*
|
||||
* Get the transient data to save with the site
|
||||
* that way we can use it when actually registering
|
||||
* the site on WordPress.
|
||||
*/
|
||||
$transient = array_merge(
|
||||
wu_get_isset($site_data, 'site_meta', array()),
|
||||
wu_get_isset($site_data, 'site_option', array())
|
||||
);
|
||||
|
||||
$template_id = apply_filters('wu_checkout_template_id', (int) wu_get_isset($site_data, 'template_id'), $membership, $this);
|
||||
|
||||
$site_data = array(
|
||||
'domain' => $d->domain,
|
||||
'path' => $d->path,
|
||||
'title' => wu_get_isset($site_data, 'site_title'),
|
||||
'template_id' => $template_id,
|
||||
'customer_id' => $membership->get_customer()->get_id(),
|
||||
'membership_id' => $membership->get_id(),
|
||||
'transient' => $transient,
|
||||
'signup_meta' => wu_get_isset($site_data, 'site_meta', array()),
|
||||
'signup_options' => wu_get_isset($site_data, 'site_option', array()),
|
||||
'type' => Site_Type::CUSTOMER_OWNED,
|
||||
);
|
||||
|
||||
$membership->create_pending_site($site_data);
|
||||
|
||||
$site_data['id'] = 0;
|
||||
|
||||
if (wu_get_isset($site_data, 'publish')) {
|
||||
|
||||
$membership->publish_pending_site();
|
||||
|
||||
$wp_site = get_site_by_path($site_data['domain'], $site_data['path']);
|
||||
|
||||
if ($wp_site) {
|
||||
|
||||
$site_data['id'] = $wp_site->blog_id;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
return $site_data;
|
||||
|
||||
} // end maybe_create_site;
|
||||
|
||||
/**
|
||||
* Set the validation rules for this particular model.
|
||||
*
|
||||
* To see how to setup rules, check the documentation of the
|
||||
* validation library we are using: https://github.com/rakit/validation
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @link https://github.com/rakit/validation
|
||||
* @return array
|
||||
*/
|
||||
public function validation_rules() {
|
||||
|
||||
return array(
|
||||
'customer_id' => 'required_without:customer',
|
||||
'customer' => 'required_without:customer_id',
|
||||
'customer.username' => 'required_without_all:customer_id,customer.user_id',
|
||||
'customer.password' => 'required_without_all:customer_id,customer.user_id',
|
||||
'customer.email' => 'required_without_all:customer_id,customer.user_id',
|
||||
'customer.user_id' => 'required_without_all:customer_id,customer.username,customer.password,customer.email',
|
||||
'site.site_url' => 'required_with:site|alpha_num|min:4|lowercase|unique_site',
|
||||
'site.site_title' => 'required_with:site|min:4',
|
||||
);
|
||||
|
||||
} // end validation_rules;
|
||||
/**
|
||||
* Validates the rules and make sure we only save models when necessary.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @param array $args The params to validate.
|
||||
* @return mixed[]|\WP_Error
|
||||
*/
|
||||
public function validate($args) {
|
||||
|
||||
$validator = new \WP_Ultimo\Helpers\Validator;
|
||||
|
||||
$validator->validate($args, $this->validation_rules());
|
||||
|
||||
if ($validator->fails()) {
|
||||
|
||||
return $validator->get_errors();
|
||||
|
||||
} // end if;
|
||||
|
||||
return true;
|
||||
|
||||
} // end validate;
|
||||
|
||||
/**
|
||||
* Rolls back database changes and returns the error passed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WP_Error $error The error to return.
|
||||
* @return \WP_Error
|
||||
*/
|
||||
protected function rollback_and_return($error) {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$wpdb->query('ROLLBACK');
|
||||
|
||||
return $error;
|
||||
|
||||
} // end rollback_and_return;
|
||||
|
||||
} // end class Register_Endpoint;
|
93
inc/api/schemas/broadcast-create.php
Normal file
93
inc/api/schemas/broadcast-create.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for broadcast@create.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for broadcast@create.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'notice_type' => array(
|
||||
'description' => __('Can be info, success, warning or error.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'info',
|
||||
'success',
|
||||
'warning',
|
||||
'error',
|
||||
),
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __('This broadcast name, which is used as broadcast title as well.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __('The type being set.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'status' => array(
|
||||
'description' => __('The status being set.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'author_id' => array(
|
||||
'description' => __('The author ID.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'title' => array(
|
||||
'description' => __('Post title.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'content' => array(
|
||||
'description' => __('Post content.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'excerpt' => array(
|
||||
'description' => __('Post excerpt.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Post creation date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Post last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'slug' => array(
|
||||
'description' => __('The slug.', 'wp-ultimo'),
|
||||
'type' => 'mixed',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
93
inc/api/schemas/broadcast-update.php
Normal file
93
inc/api/schemas/broadcast-update.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for broadcast@update.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for broadcast@update.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'notice_type' => array(
|
||||
'description' => __('Can be info, success, warning or error.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'info',
|
||||
'success',
|
||||
'warning',
|
||||
'error',
|
||||
),
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __('This broadcast name, which is used as broadcast title as well.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __('The type being set.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'status' => array(
|
||||
'description' => __('The status being set.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'author_id' => array(
|
||||
'description' => __('The author ID.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'title' => array(
|
||||
'description' => __('Post title.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'content' => array(
|
||||
'description' => __('Post content.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'excerpt' => array(
|
||||
'description' => __('Post excerpt.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Post creation date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Post last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'slug' => array(
|
||||
'description' => __('The slug.', 'wp-ultimo'),
|
||||
'type' => 'mixed',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
92
inc/api/schemas/checkout-form-create.php
Normal file
92
inc/api/schemas/checkout-form-create.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for checkout@form-create.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for checkout@form-create.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'slug' => array(
|
||||
'description' => __('The checkout form slug. It needs to be unique and preferably make it clear what it is about. E.g. my_checkout_form.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __('Your checkout form name, which is used as checkout form title as well.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Set this checkout form as active (true), which means available to be used, or inactive (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => true,
|
||||
),
|
||||
'custom_css' => array(
|
||||
'description' => __('Custom CSS code for the checkout form.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'settings' => array(
|
||||
'description' => __('The checkout form settings and configurations.', 'wp-ultimo'),
|
||||
'type' => 'object',
|
||||
'required' => false,
|
||||
),
|
||||
'allowed_countries' => array(
|
||||
'description' => __('The allowed countries that can access this checkout.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'thank_you_page_id' => array(
|
||||
'description' => __('The thank you page ID. This page is shown after a successful purchase.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'conversion_snippets' => array(
|
||||
'description' => __('Snippets to run on thank you page.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'template' => array(
|
||||
'description' => __("Template mode. Can be either 'blank', 'single-step' or 'multi-step'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'blank',
|
||||
'single-step',
|
||||
'multi-step',
|
||||
),
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Model creation date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
92
inc/api/schemas/checkout-form-update.php
Normal file
92
inc/api/schemas/checkout-form-update.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for checkout@form-update.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for checkout@form-update.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'slug' => array(
|
||||
'description' => __('The checkout form slug. It needs to be unique and preferably make it clear what it is about. E.g. my_checkout_form.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __('Your checkout form name, which is used as checkout form title as well.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Set this checkout form as active (true), which means available to be used, or inactive (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'custom_css' => array(
|
||||
'description' => __('Custom CSS code for the checkout form.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'settings' => array(
|
||||
'description' => __('The checkout form settings and configurations.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'allowed_countries' => array(
|
||||
'description' => __('The allowed countries that can access this checkout.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'thank_you_page_id' => array(
|
||||
'description' => __('The thank you page ID. This page is shown after a successful purchase.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'conversion_snippets' => array(
|
||||
'description' => __('Snippets to run on thank you page.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'template' => array(
|
||||
'description' => __("Template mode. Can be either 'blank', 'single-step' or 'multi-step'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'blank',
|
||||
'single-step',
|
||||
'multi-step',
|
||||
),
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Model creation date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
100
inc/api/schemas/customer-create.php
Normal file
100
inc/api/schemas/customer-create.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for customer@create.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for customer@create.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'user_id' => array(
|
||||
'description' => __('The WordPress user ID attached to this customer.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
),
|
||||
'date_registered' => array(
|
||||
'description' => __('Date when the customer was created.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'email_verification' => array(
|
||||
'description' => __('Email verification status - either `none`, `pending`, or `verified`.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'enum' => array(
|
||||
'verified',
|
||||
'pending',
|
||||
'none',
|
||||
),
|
||||
),
|
||||
'last_login' => array(
|
||||
'description' => __('Date this customer last logged in.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'has_trialed' => array(
|
||||
'description' => __('Whether or not the customer has trialed before.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'vip' => array(
|
||||
'description' => __('If this customer is a VIP customer or not.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'ips' => array(
|
||||
'description' => __('List of IP addresses used by this customer.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'extra_information' => array(
|
||||
'description' => __('Any extra information related to this customer.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __("The customer type. Can be 'customer'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'enum' => array(
|
||||
'customer',
|
||||
),
|
||||
),
|
||||
'signup_form' => array(
|
||||
'description' => __('The form used to signup.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Model creation date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
100
inc/api/schemas/customer-update.php
Normal file
100
inc/api/schemas/customer-update.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for customer@update.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for customer@update.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'user_id' => array(
|
||||
'description' => __('The WordPress user ID attached to this customer.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'date_registered' => array(
|
||||
'description' => __('Date when the customer was created.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'email_verification' => array(
|
||||
'description' => __('Email verification status - either `none`, `pending`, or `verified`.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'verified',
|
||||
'pending',
|
||||
'none',
|
||||
),
|
||||
),
|
||||
'last_login' => array(
|
||||
'description' => __('Date this customer last logged in.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'has_trialed' => array(
|
||||
'description' => __('Whether or not the customer has trialed before.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'vip' => array(
|
||||
'description' => __('If this customer is a VIP customer or not.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'ips' => array(
|
||||
'description' => __('List of IP addresses used by this customer.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'extra_information' => array(
|
||||
'description' => __('Any extra information related to this customer.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __("The customer type. Can be 'customer'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'customer',
|
||||
),
|
||||
),
|
||||
'signup_form' => array(
|
||||
'description' => __('The form used to signup.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Model creation date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
125
inc/api/schemas/discount-code-create.php
Normal file
125
inc/api/schemas/discount-code-create.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for discount@code-create.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for discount@code-create.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'name' => array(
|
||||
'description' => __('Your discount code name, which is used as discount code title as well.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'code' => array(
|
||||
'description' => __('A unique identification to redeem the discount code. E.g. PROMO10.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __('A description for the discount code, usually a short text.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'uses' => array(
|
||||
'description' => __('Number of times this discount was applied.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'max_uses' => array(
|
||||
'description' => __('The number of times this discount can be used before becoming inactive.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'apply_to_renewals' => array(
|
||||
'description' => __('Wether or not we should apply the discount to membership renewals.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __("The type of the discount code. Can be 'percentage' (e.g. 10%% OFF), 'absolute' (e.g. $10 OFF).", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'percentage',
|
||||
'absolute',
|
||||
),
|
||||
),
|
||||
'value' => array(
|
||||
'description' => __('Amount discounted in cents.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
),
|
||||
'setup_fee_type' => array(
|
||||
'description' => __('Type of the discount for the setup fee value. Can be a percentage or absolute.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'percentage',
|
||||
'absolute',
|
||||
),
|
||||
),
|
||||
'setup_fee_value' => array(
|
||||
'description' => __('Amount discounted for setup fees in cents.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Set this discount code as active (true), which means available to be used, or inactive (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'date_start' => array(
|
||||
'description' => __('Start date for the coupon code to be considered valid.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_expiration' => array(
|
||||
'description' => __('Expiration date for the coupon code.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Date when this discount code was created.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'allowed_products' => array(
|
||||
'description' => __('The list of products that allows this discount code to be used. If empty, all products will accept this code.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'limit_products' => array(
|
||||
'description' => __('This discount code will be limited to be used in certain products? If set to true, you must define a list of allowed products.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
125
inc/api/schemas/discount-code-update.php
Normal file
125
inc/api/schemas/discount-code-update.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for discount@code-update.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for discount@code-update.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'name' => array(
|
||||
'description' => __('Your discount code name, which is used as discount code title as well.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'code' => array(
|
||||
'description' => __('A unique identification to redeem the discount code. E.g. PROMO10.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __('A description for the discount code, usually a short text.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'uses' => array(
|
||||
'description' => __('Number of times this discount was applied.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'max_uses' => array(
|
||||
'description' => __('The number of times this discount can be used before becoming inactive.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'apply_to_renewals' => array(
|
||||
'description' => __('Wether or not we should apply the discount to membership renewals.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __("The type of the discount code. Can be 'percentage' (e.g. 10%% OFF), 'absolute' (e.g. $10 OFF).", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'percentage',
|
||||
'absolute',
|
||||
),
|
||||
),
|
||||
'value' => array(
|
||||
'description' => __('Amount discounted in cents.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'setup_fee_type' => array(
|
||||
'description' => __('Type of the discount for the setup fee value. Can be a percentage or absolute.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'percentage',
|
||||
'absolute',
|
||||
),
|
||||
),
|
||||
'setup_fee_value' => array(
|
||||
'description' => __('Amount discounted for setup fees in cents.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Set this discount code as active (true), which means available to be used, or inactive (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'date_start' => array(
|
||||
'description' => __('Start date for the coupon code to be considered valid.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_expiration' => array(
|
||||
'description' => __('Expiration date for the coupon code.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Date when this discount code was created.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'allowed_products' => array(
|
||||
'description' => __('The list of products that allows this discount code to be used. If empty, all products will accept this code.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'limit_products' => array(
|
||||
'description' => __('This discount code will be limited to be used in certain products? If set to true, you must define a list of allowed products.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
79
inc/api/schemas/domain-create.php
Normal file
79
inc/api/schemas/domain-create.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for domain@create.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for domain@create.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'domain' => array(
|
||||
'description' => __("Your Domain name. You don't need to put http or https in front of your domain in this field. e.g: example.com.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'blog_id' => array(
|
||||
'description' => __('The blog ID attached to this domain.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Set this domain as active (true), which means available to be used, or inactive (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'primary_domain' => array(
|
||||
'description' => __("Define true to set this as primary domain of a site, meaning it's the main url, or set false.", 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'secure' => array(
|
||||
'description' => __('If this domain has some SSL security or not.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'stage' => array(
|
||||
'description' => __('The state of the domain model object. Can be one of this options: checking-dns, checking-ssl-cert, done-without-ssl, done and failed.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'enum' => array(
|
||||
'checking-dns',
|
||||
'checking-ssl-cert',
|
||||
'done-without-ssl',
|
||||
'done',
|
||||
'failed',
|
||||
),
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Date when the domain was created. If no date is set, the current date and time will be used.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
79
inc/api/schemas/domain-update.php
Normal file
79
inc/api/schemas/domain-update.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for domain@update.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for domain@update.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'domain' => array(
|
||||
'description' => __("Your Domain name. You don't need to put http or https in front of your domain in this field. e.g: example.com.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'blog_id' => array(
|
||||
'description' => __('The blog ID attached to this domain.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Set this domain as active (true), which means available to be used, or inactive (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'primary_domain' => array(
|
||||
'description' => __("Define true to set this as primary domain of a site, meaning it's the main url, or set false.", 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'secure' => array(
|
||||
'description' => __('If this domain has some SSL security or not.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'stage' => array(
|
||||
'description' => __('The state of the domain model object. Can be one of this options: checking-dns, checking-ssl-cert, done-without-ssl, done and failed.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'checking-dns',
|
||||
'checking-ssl-cert',
|
||||
'done-without-ssl',
|
||||
'done',
|
||||
'failed',
|
||||
),
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Date when the domain was created. If no date is set, the current date and time will be used.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
144
inc/api/schemas/email-create.php
Normal file
144
inc/api/schemas/email-create.php
Normal file
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for email@create.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for email@create.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'style' => array(
|
||||
'description' => __("The email style. Can be 'html' or 'plain-text'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'html',
|
||||
'plain-text',
|
||||
),
|
||||
),
|
||||
'schedule' => array(
|
||||
'description' => __('Whether or not this is a scheduled email.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __('The type being set.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'event' => array(
|
||||
'description' => __('The event that needs to be fired for this email to be sent.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'send_hours' => array(
|
||||
'description' => __('The amount of hours that the email will wait before is sent.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'send_days' => array(
|
||||
'description' => __('The amount of days that the email will wait before is sent.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'schedule_type' => array(
|
||||
'description' => __("The type of schedule. Can be 'days' or 'hours'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'days',
|
||||
'hours',
|
||||
),
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __('The name being set as title.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'custom_sender' => array(
|
||||
'description' => __('If has a custom sender.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'custom_sender_name' => array(
|
||||
'description' => __('The name of the custom sender. E.g. From: John Doe.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'custom_sender_email' => array(
|
||||
'description' => __('The email of the custom sender. E.g. From: johndoe@gmail.com.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'target' => array(
|
||||
'description' => __("If we should send this to a customer or to the network admin. Can be 'customer' or 'admin'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'enum' => array(
|
||||
'customer',
|
||||
'admin',
|
||||
),
|
||||
),
|
||||
'send_copy_to_admin' => array(
|
||||
'description' => __('Checks if we should send a copy of the email to the admin.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Set this email as active (true), which means available will fire when the event occur, or inactive (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'legacy' => array(
|
||||
'description' => __('Whether or not this is a legacy email.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'title' => array(
|
||||
'description' => __('Post title.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'content' => array(
|
||||
'description' => __('Post content.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'excerpt' => array(
|
||||
'description' => __('Post excerpt.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Post creation date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Post last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
144
inc/api/schemas/email-update.php
Normal file
144
inc/api/schemas/email-update.php
Normal file
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for email@update.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for email@update.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'style' => array(
|
||||
'description' => __("The email style. Can be 'html' or 'plain-text'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'html',
|
||||
'plain-text',
|
||||
),
|
||||
),
|
||||
'schedule' => array(
|
||||
'description' => __('Whether or not this is a scheduled email.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __('The type being set.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'event' => array(
|
||||
'description' => __('The event that needs to be fired for this email to be sent.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'send_hours' => array(
|
||||
'description' => __('The amount of hours that the email will wait before is sent.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'send_days' => array(
|
||||
'description' => __('The amount of days that the email will wait before is sent.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'schedule_type' => array(
|
||||
'description' => __("The type of schedule. Can be 'days' or 'hours'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'days',
|
||||
'hours',
|
||||
),
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __('The name being set as title.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'custom_sender' => array(
|
||||
'description' => __('If has a custom sender.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'custom_sender_name' => array(
|
||||
'description' => __('The name of the custom sender. E.g. From: John Doe.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'custom_sender_email' => array(
|
||||
'description' => __('The email of the custom sender. E.g. From: johndoe@gmail.com.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'target' => array(
|
||||
'description' => __("If we should send this to a customer or to the network admin. Can be 'customer' or 'admin'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'customer',
|
||||
'admin',
|
||||
),
|
||||
),
|
||||
'send_copy_to_admin' => array(
|
||||
'description' => __('Checks if we should send a copy of the email to the admin.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Set this email as active (true), which means available will fire when the event occur, or inactive (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'legacy' => array(
|
||||
'description' => __('Whether or not this is a legacy email.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'title' => array(
|
||||
'description' => __('Post title.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'content' => array(
|
||||
'description' => __('Post content.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'excerpt' => array(
|
||||
'description' => __('Post excerpt.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Post creation date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Post last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
76
inc/api/schemas/event-create.php
Normal file
76
inc/api/schemas/event-create.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for event@create.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for event@create.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'severity' => array(
|
||||
'description' => __('Severity of the problem.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Date when the event was created.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'payload' => array(
|
||||
'description' => __('Payload of the event.', 'wp-ultimo'),
|
||||
'type' => 'object',
|
||||
'required' => true,
|
||||
),
|
||||
'initiator' => array(
|
||||
'description' => __('The type of user responsible for initiating the event. There are two options: Manual and System. By default, the event is saved as manual.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'enum' => array(
|
||||
'system',
|
||||
'manual',
|
||||
),
|
||||
),
|
||||
'object_type' => array(
|
||||
'description' => __("The type of object related to this event. It's usually the model name.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'slug' => array(
|
||||
'description' => __('The event slug. It needs to be unique and preferably make it clear what it is about. Example: account_created is about creating an account.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'object_id' => array(
|
||||
'description' => __('The ID of the related objects.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
76
inc/api/schemas/event-update.php
Normal file
76
inc/api/schemas/event-update.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for event@update.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for event@update.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'severity' => array(
|
||||
'description' => __('Severity of the problem.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Date when the event was created.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'payload' => array(
|
||||
'description' => __('Payload of the event.', 'wp-ultimo'),
|
||||
'type' => 'object',
|
||||
'required' => false,
|
||||
),
|
||||
'initiator' => array(
|
||||
'description' => __('The type of user responsible for initiating the event. There are two options: Manual and System. By default, the event is saved as manual.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'system',
|
||||
'manual',
|
||||
),
|
||||
),
|
||||
'object_type' => array(
|
||||
'description' => __("The type of object related to this event. It's usually the model name.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'slug' => array(
|
||||
'description' => __('The event slug. It needs to be unique and preferably make it clear what it is about. Example: account_created is about creating an account.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'object_id' => array(
|
||||
'description' => __('The ID of the related objects.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
181
inc/api/schemas/membership-create.php
Normal file
181
inc/api/schemas/membership-create.php
Normal file
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for membership@create.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use WP_Ultimo\Database\Memberships\Membership_Status;
|
||||
|
||||
/**
|
||||
* Schema for membership@create.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'customer_id' => array(
|
||||
'description' => __('The ID of the customer attached to this membership.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
),
|
||||
'user_id' => array(
|
||||
'description' => __('The user ID attached to this membership.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'plan_id' => array(
|
||||
'description' => __('The plan ID associated with the membership.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
),
|
||||
'addon_products' => array(
|
||||
'description' => __('Additional products related to this membership. Services, Packages or other types of products.', 'wp-ultimo'),
|
||||
'type' => 'mixed',
|
||||
'required' => false,
|
||||
),
|
||||
'currency' => array(
|
||||
'description' => __("The currency that this membership. It's a 3-letter code. E.g. 'USD'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'duration' => array(
|
||||
'description' => __('The interval period between a charge. Only the interval amount, the unit will be defined in another property.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'duration_unit' => array(
|
||||
'description' => __("The duration amount type. Can be 'day', 'week', 'month' or 'year'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'day',
|
||||
'month',
|
||||
'week',
|
||||
'year',
|
||||
),
|
||||
),
|
||||
'amount' => array(
|
||||
'description' => __('The product amount.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'initial_amount' => array(
|
||||
'description' => __('The initial amount charged for this membership, including the setup fee.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Date of creation of this membership.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_activated' => array(
|
||||
'description' => __('Date when this membership was activated.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_trial_end' => array(
|
||||
'description' => __('Date when the trial period ends, if this membership has or had a trial period.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_renewed' => array(
|
||||
'description' => __('Date when the membership was cancelled.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_cancellation' => array(
|
||||
'description' => __('Date when the membership was cancelled.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_expiration' => array(
|
||||
'description' => __('Date when the membership will expiry.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_payment_plan_completed' => array(
|
||||
'description' => __('Change of the payment completion for the plan value.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'auto_renew' => array(
|
||||
'description' => __('If this membership should auto-renewal.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'times_billed' => array(
|
||||
'description' => __('Amount of times this membership got billed.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'billing_cycles' => array(
|
||||
'description' => __('Maximum times we should charge this membership.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'status' => array(
|
||||
'description' => __("The membership status. Can be 'pending', 'active', 'on-hold', 'expired', 'cancelled' or other values added by third-party add-ons.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => Membership_Status::get_allowed_list(),
|
||||
),
|
||||
'gateway_customer_id' => array(
|
||||
'description' => __('The ID of the customer on the payment gateway database.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'gateway_subscription_id' => array(
|
||||
'description' => __('The ID of the subscription on the payment gateway database.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'gateway' => array(
|
||||
'description' => __('ID of the gateway being used on this subscription.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'signup_method' => array(
|
||||
'description' => __('Signup method used to create this membership.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'upgraded_from' => array(
|
||||
'description' => __('Plan that this membership upgraded from.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Date this membership was last modified.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'disabled' => array(
|
||||
'description' => __('If this membership is a disabled one.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'recurring' => array(
|
||||
'description' => __('If this membership is recurring (true), which means the customer paid a defined amount each period of time, or not recurring (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
181
inc/api/schemas/membership-update.php
Normal file
181
inc/api/schemas/membership-update.php
Normal file
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for membership@update.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use WP_Ultimo\Database\Memberships\Membership_Status;
|
||||
|
||||
/**
|
||||
* Schema for membership@update.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'customer_id' => array(
|
||||
'description' => __('The ID of the customer attached to this membership.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'user_id' => array(
|
||||
'description' => __('The user ID attached to this membership.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'plan_id' => array(
|
||||
'description' => __('The plan ID associated with the membership.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'addon_products' => array(
|
||||
'description' => __('Additional products related to this membership. Services, Packages or other types of products.', 'wp-ultimo'),
|
||||
'type' => 'mixed',
|
||||
'required' => false,
|
||||
),
|
||||
'currency' => array(
|
||||
'description' => __("The currency that this membership. It's a 3-letter code. E.g. 'USD'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'duration' => array(
|
||||
'description' => __('The interval period between a charge. Only the interval amount, the unit will be defined in another property.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'duration_unit' => array(
|
||||
'description' => __("The duration amount type. Can be 'day', 'week', 'month' or 'year'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'day',
|
||||
'month',
|
||||
'week',
|
||||
'year',
|
||||
),
|
||||
),
|
||||
'amount' => array(
|
||||
'description' => __('The product amount.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'initial_amount' => array(
|
||||
'description' => __('The initial amount charged for this membership, including the setup fee.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Date of creation of this membership.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_activated' => array(
|
||||
'description' => __('Date when this membership was activated.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_trial_end' => array(
|
||||
'description' => __('Date when the trial period ends, if this membership has or had a trial period.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_renewed' => array(
|
||||
'description' => __('Date when the membership was cancelled.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_cancellation' => array(
|
||||
'description' => __('Date when the membership was cancelled.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_expiration' => array(
|
||||
'description' => __('Date when the membership will expiry.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_payment_plan_completed' => array(
|
||||
'description' => __('Change of the payment completion for the plan value.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'auto_renew' => array(
|
||||
'description' => __('If this membership should auto-renewal.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'times_billed' => array(
|
||||
'description' => __('Amount of times this membership got billed.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'billing_cycles' => array(
|
||||
'description' => __('Maximum times we should charge this membership.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'status' => array(
|
||||
'description' => __("The membership status. Can be 'pending', 'active', 'on-hold', 'expired', 'cancelled' or other values added by third-party add-ons.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => Membership_Status::get_allowed_list(),
|
||||
),
|
||||
'gateway_customer_id' => array(
|
||||
'description' => __('The ID of the customer on the payment gateway database.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'gateway_subscription_id' => array(
|
||||
'description' => __('The ID of the subscription on the payment gateway database.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'gateway' => array(
|
||||
'description' => __('ID of the gateway being used on this subscription.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'signup_method' => array(
|
||||
'description' => __('Signup method used to create this membership.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'upgraded_from' => array(
|
||||
'description' => __('Plan that this membership upgraded from.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Date this membership was last modified.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'disabled' => array(
|
||||
'description' => __('If this membership is a disabled one.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'recurring' => array(
|
||||
'description' => __('If this membership is recurring (true), which means the customer paid a defined amount each period of time, or not recurring (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
125
inc/api/schemas/payment-create.php
Normal file
125
inc/api/schemas/payment-create.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for payment@create.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use WP_Ultimo\Database\Payments\Payment_Status;
|
||||
|
||||
/**
|
||||
* Schema for payment@create.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'customer_id' => array(
|
||||
'description' => __('The ID of the customer attached to this payment.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
),
|
||||
'membership_id' => array(
|
||||
'description' => __('The ID of the membership attached to this payment.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
),
|
||||
'parent_id' => array(
|
||||
'description' => __('The ID from another payment that this payment is related to.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'currency' => array(
|
||||
'description' => __("The currency of this payment. It's a 3-letter code. E.g. 'USD'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'subtotal' => array(
|
||||
'description' => __('Value before taxes, discounts, fees and other changes.', 'wp-ultimo'),
|
||||
'type' => 'number',
|
||||
'required' => true,
|
||||
),
|
||||
'refund_total' => array(
|
||||
'description' => __('Total amount refunded.', 'wp-ultimo'),
|
||||
'type' => 'number',
|
||||
'required' => false,
|
||||
),
|
||||
'tax_total' => array(
|
||||
'description' => __('The amount, in currency, of the tax.', 'wp-ultimo'),
|
||||
'type' => 'number',
|
||||
'required' => false,
|
||||
),
|
||||
'discount_code' => array(
|
||||
'description' => __('Discount code used.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'total' => array(
|
||||
'description' => __('This takes into account fees, discounts and credits.', 'wp-ultimo'),
|
||||
'type' => 'number',
|
||||
'required' => true,
|
||||
),
|
||||
'status' => array(
|
||||
'description' => __("The payment status: Can be 'pending', 'completed', 'refunded', 'partially-refunded', 'partially-paid', 'failed', 'cancelled' or other values added by third-party add-ons.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'enum' => Payment_Status::get_allowed_list(),
|
||||
),
|
||||
'gateway' => array(
|
||||
'description' => __('ID of the gateway being used on this payment.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'product_id' => array(
|
||||
'description' => __('The ID of the product of this payment.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'gateway_payment_id' => array(
|
||||
'description' => __('The ID of the payment on the gateway, if it exists.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'discount_total' => array(
|
||||
'description' => __('The total value of the discounts applied to this payment.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'invoice_number' => array(
|
||||
'description' => __('Sequential invoice number assigned to this payment.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'cancel_membership_on_refund' => array(
|
||||
'description' => __('Holds if we need to cancel the membership on refund.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Model creation date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
125
inc/api/schemas/payment-update.php
Normal file
125
inc/api/schemas/payment-update.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for payment@update.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use WP_Ultimo\Database\Payments\Payment_Status;
|
||||
|
||||
/**
|
||||
* Schema for payment@update.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'customer_id' => array(
|
||||
'description' => __('The ID of the customer attached to this payment.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'membership_id' => array(
|
||||
'description' => __('The ID of the membership attached to this payment.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'parent_id' => array(
|
||||
'description' => __('The ID from another payment that this payment is related to.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'currency' => array(
|
||||
'description' => __("The currency of this payment. It's a 3-letter code. E.g. 'USD'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'subtotal' => array(
|
||||
'description' => __('Value before taxes, discounts, fees and other changes.', 'wp-ultimo'),
|
||||
'type' => 'number',
|
||||
'required' => false,
|
||||
),
|
||||
'refund_total' => array(
|
||||
'description' => __('Total amount refunded.', 'wp-ultimo'),
|
||||
'type' => 'number',
|
||||
'required' => false,
|
||||
),
|
||||
'tax_total' => array(
|
||||
'description' => __('The amount, in currency, of the tax.', 'wp-ultimo'),
|
||||
'type' => 'number',
|
||||
'required' => false,
|
||||
),
|
||||
'discount_code' => array(
|
||||
'description' => __('Discount code used.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'total' => array(
|
||||
'description' => __('This takes into account fees, discounts and credits.', 'wp-ultimo'),
|
||||
'type' => 'number',
|
||||
'required' => false,
|
||||
),
|
||||
'status' => array(
|
||||
'description' => __("The payment status: Can be 'pending', 'completed', 'refunded', 'partially-refunded', 'partially-paid', 'failed', 'cancelled' or other values added by third-party add-ons.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => Payment_Status::get_allowed_list(),
|
||||
),
|
||||
'gateway' => array(
|
||||
'description' => __('ID of the gateway being used on this payment.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'product_id' => array(
|
||||
'description' => __('The ID of the product of this payment.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'gateway_payment_id' => array(
|
||||
'description' => __('The ID of the payment on the gateway, if it exists.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'discount_total' => array(
|
||||
'description' => __('The total value of the discounts applied to this payment.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'invoice_number' => array(
|
||||
'description' => __('Sequential invoice number assigned to this payment.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'cancel_membership_on_refund' => array(
|
||||
'description' => __('Holds if we need to cancel the membership on refund.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Model creation date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
199
inc/api/schemas/product-create.php
Normal file
199
inc/api/schemas/product-create.php
Normal file
@ -0,0 +1,199 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for product@create.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for product@create.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'featured_image_id' => array(
|
||||
'description' => __('The ID of the feature image of the product.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'slug' => array(
|
||||
'description' => __('The product slug. It needs to be unique and preferably make it clear what it is about. Example: my_new_product.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __('Your product name, which is used as product title as well.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __('A description for the product, usually a short text.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'currency' => array(
|
||||
'description' => __("The currency that this product accepts. It's a 3-letter code. E.g. 'USD'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'pricing_type' => array(
|
||||
'description' => __("The pricing type can be 'free', 'paid' or 'contact_us'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'enum' => array(
|
||||
'free',
|
||||
'paid',
|
||||
'contact_us',
|
||||
),
|
||||
),
|
||||
'trial_duration' => array(
|
||||
'description' => __('The duration of the trial period of this product, if the product has one.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'trial_duration_unit' => array(
|
||||
'description' => __('The unit of the trial duration amount. Can be day, week, month or year.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'day',
|
||||
'week',
|
||||
'month',
|
||||
'year',
|
||||
),
|
||||
),
|
||||
'duration' => array(
|
||||
'description' => __('Time interval between charges.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'duration_unit' => array(
|
||||
'description' => __('Time interval unit between charges.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'day',
|
||||
'month',
|
||||
'week',
|
||||
'year',
|
||||
),
|
||||
),
|
||||
'amount' => array(
|
||||
'description' => __('The value of this product. E.g. 19.99.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'setup_fee' => array(
|
||||
'description' => __('The setup fee value, if the product has one. E.g. 159.99.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Set this product as active (true), which means available to be used, or inactive (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __("The default product types are 'product', 'service' and 'package'. More types can be add using the product type filter.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'enum' => array(
|
||||
'plan',
|
||||
'service',
|
||||
'package',
|
||||
),
|
||||
),
|
||||
'parent_id' => array(
|
||||
'description' => __('The ID from another Product that this product is related to.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'recurring' => array(
|
||||
'description' => __('Set this product as a recurring one (true), which means the customer paid a defined amount each period of time, or not recurring (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'billing_cycles' => array(
|
||||
'description' => __('The number of times we should charge this product.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Date when this was created.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Date when this was last modified.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'taxable' => array(
|
||||
'description' => __('Set this product as a taxable one (true), which means tax rules are applied to, or not taxable (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'tax_category' => array(
|
||||
'description' => __('Category of taxes applied to this product. You need to set this if taxable is set to true.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'contact_us_label' => array(
|
||||
'description' => __("If the product is the 'contact_us' type, it will need a label for the contact us button.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'contact_us_link' => array(
|
||||
'description' => __('The url where the contact us button will lead to.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'feature_list' => array(
|
||||
'description' => __('A list (array) of features of the product.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'customer_role' => array(
|
||||
'description' => __('The customer role of this product.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'available_addons' => array(
|
||||
'description' => __('The available addons of this product.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'group' => array(
|
||||
'description' => __('The group of this product, if has any.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'legacy_options' => array(
|
||||
'description' => __('If the legacy options are enabled.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'featured_plan' => array(
|
||||
'description' => __('Feature list for pricing tables.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
199
inc/api/schemas/product-update.php
Normal file
199
inc/api/schemas/product-update.php
Normal file
@ -0,0 +1,199 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for product@update.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for product@update.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'featured_image_id' => array(
|
||||
'description' => __('The ID of the feature image of the product.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'slug' => array(
|
||||
'description' => __('The product slug. It needs to be unique and preferably make it clear what it is about. Example: my_new_product.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __('Your product name, which is used as product title as well.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __('A description for the product, usually a short text.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'currency' => array(
|
||||
'description' => __("The currency that this product accepts. It's a 3-letter code. E.g. 'USD'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'pricing_type' => array(
|
||||
'description' => __("The pricing type can be 'free', 'paid' or 'contact_us'.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'free',
|
||||
'paid',
|
||||
'contact_us',
|
||||
),
|
||||
),
|
||||
'trial_duration' => array(
|
||||
'description' => __('The duration of the trial period of this product, if the product has one.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'trial_duration_unit' => array(
|
||||
'description' => __('The unit of the trial duration amount. Can be day, week, month or year.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'day',
|
||||
'week',
|
||||
'month',
|
||||
'year',
|
||||
),
|
||||
),
|
||||
'duration' => array(
|
||||
'description' => __('Time interval between charges.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'duration_unit' => array(
|
||||
'description' => __('Time interval unit between charges.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'day',
|
||||
'month',
|
||||
'week',
|
||||
'year',
|
||||
),
|
||||
),
|
||||
'amount' => array(
|
||||
'description' => __('The value of this product. E.g. 19.99.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'setup_fee' => array(
|
||||
'description' => __('The setup fee value, if the product has one. E.g. 159.99.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Set this product as active (true), which means available to be used, or inactive (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __("The default product types are 'product', 'service' and 'package'. More types can be add using the product type filter.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'plan',
|
||||
'service',
|
||||
'package',
|
||||
),
|
||||
),
|
||||
'parent_id' => array(
|
||||
'description' => __('The ID from another Product that this product is related to.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'recurring' => array(
|
||||
'description' => __('Set this product as a recurring one (true), which means the customer paid a defined amount each period of time, or not recurring (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'billing_cycles' => array(
|
||||
'description' => __('The number of times we should charge this product.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Date when this was created.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Date when this was last modified.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'taxable' => array(
|
||||
'description' => __('Set this product as a taxable one (true), which means tax rules are applied to, or not taxable (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'tax_category' => array(
|
||||
'description' => __('Category of taxes applied to this product. You need to set this if taxable is set to true.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'contact_us_label' => array(
|
||||
'description' => __("If the product is the 'contact_us' type, it will need a label for the contact us button.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'contact_us_link' => array(
|
||||
'description' => __('The url where the contact us button will lead to.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'feature_list' => array(
|
||||
'description' => __('A list (array) of features of the product.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'customer_role' => array(
|
||||
'description' => __('The customer role of this product.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'available_addons' => array(
|
||||
'description' => __('The available addons of this product.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'group' => array(
|
||||
'description' => __('The group of this product, if has any.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'legacy_options' => array(
|
||||
'description' => __('If the legacy options are enabled.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'featured_plan' => array(
|
||||
'description' => __('Feature list for pricing tables.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
165
inc/api/schemas/site-create.php
Normal file
165
inc/api/schemas/site-create.php
Normal file
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for site@create.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for site@create.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'categories' => array(
|
||||
'description' => __('The categories this site belongs to.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'featured_image_id' => array(
|
||||
'description' => __('The ID of the feature image of the site.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'site_id' => array(
|
||||
'description' => __('The network ID for this site.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
),
|
||||
'title' => array(
|
||||
'description' => __('The site title.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __('The site name.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __('A description for the site, usually a short text.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'domain' => array(
|
||||
'description' => __("The site domain. You don't need to put http or https in front of your domain in this field. e.g: example.com.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'path' => array(
|
||||
'description' => __('Path of the site. Used when in sub-directory mode.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'registered' => array(
|
||||
'description' => __('Date when the site was registered.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'last_updated' => array(
|
||||
'description' => __('Date of the last update on this site.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Holds the ID of the customer that owns this site.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'public' => array(
|
||||
'description' => __('Set true if this site is a public one, false if not.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'archived' => array(
|
||||
'description' => __('Is this an archived site.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'mature' => array(
|
||||
'description' => __('Is this a site with mature content.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'spam' => array(
|
||||
'description' => __('Is this an spam site.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'deleted' => array(
|
||||
'description' => __('Is this site deleted.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'lang_id' => array(
|
||||
'description' => __('The ID of the language being used on this site.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'customer_id' => array(
|
||||
'description' => __('The ID of the customer that owns this site.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
),
|
||||
'membership_id' => array(
|
||||
'description' => __('The ID of the membership associated with this site, if any.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
),
|
||||
'template_id' => array(
|
||||
'description' => __('The ID of the templated used to create this site.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __('The type of this particular site. Can be default, site_template, customer_owned, pending, external, main or other values added by third-party add-ons.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'enum' => array(
|
||||
'default',
|
||||
'site_template',
|
||||
'customer_owned',
|
||||
'pending',
|
||||
'external',
|
||||
'main',
|
||||
),
|
||||
),
|
||||
'signup_options' => array(
|
||||
'description' => __('Keeps signup options for the site.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'signup_meta' => array(
|
||||
'description' => __('Keeps signup meta for the site.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Model creation date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
165
inc/api/schemas/site-update.php
Normal file
165
inc/api/schemas/site-update.php
Normal file
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for site@update.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for site@update.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'categories' => array(
|
||||
'description' => __('The categories this site belongs to.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'featured_image_id' => array(
|
||||
'description' => __('The ID of the feature image of the site.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'site_id' => array(
|
||||
'description' => __('The network ID for this site.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'title' => array(
|
||||
'description' => __('The site title.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __('The site name.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __('A description for the site, usually a short text.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'domain' => array(
|
||||
'description' => __("The site domain. You don't need to put http or https in front of your domain in this field. e.g: example.com.", 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'path' => array(
|
||||
'description' => __('Path of the site. Used when in sub-directory mode.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'registered' => array(
|
||||
'description' => __('Date when the site was registered.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'last_updated' => array(
|
||||
'description' => __('Date of the last update on this site.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Holds the ID of the customer that owns this site.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'public' => array(
|
||||
'description' => __('Set true if this site is a public one, false if not.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'archived' => array(
|
||||
'description' => __('Is this an archived site.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'mature' => array(
|
||||
'description' => __('Is this a site with mature content.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'spam' => array(
|
||||
'description' => __('Is this an spam site.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'deleted' => array(
|
||||
'description' => __('Is this site deleted.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'lang_id' => array(
|
||||
'description' => __('The ID of the language being used on this site.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'customer_id' => array(
|
||||
'description' => __('The ID of the customer that owns this site.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'membership_id' => array(
|
||||
'description' => __('The ID of the membership associated with this site, if any.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'template_id' => array(
|
||||
'description' => __('The ID of the templated used to create this site.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __('The type of this particular site. Can be default, site_template, customer_owned, pending, external, main or other values added by third-party add-ons.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
'enum' => array(
|
||||
'default',
|
||||
'site_template',
|
||||
'customer_owned',
|
||||
'pending',
|
||||
'external',
|
||||
'main',
|
||||
),
|
||||
),
|
||||
'signup_options' => array(
|
||||
'description' => __('Keeps signup options for the site.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'signup_meta' => array(
|
||||
'description' => __('Keeps signup meta for the site.', 'wp-ultimo'),
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Model creation date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
82
inc/api/schemas/webhook-create.php
Normal file
82
inc/api/schemas/webhook-create.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for webhook@create.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for webhook@create.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'name' => array(
|
||||
'description' => __('Webhook name, which is used as product title as well.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'webhook_url' => array(
|
||||
'description' => __('The URL used for the webhook call.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'event' => array(
|
||||
'description' => __('The event that needs to be fired for this webhook to be sent.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'event_count' => array(
|
||||
'description' => __('How many times this webhook was sent.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Set this webhook as active (true), which means available will fire when the event occur, or inactive (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'hidden' => array(
|
||||
'description' => __('Is this webhook hidden.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Date when this was created.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'integration' => array(
|
||||
'description' => __('The integration that created this webhook.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
),
|
||||
'date_last_failed' => array(
|
||||
'description' => __('The date when this webhook last fail.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
82
inc/api/schemas/webhook-update.php
Normal file
82
inc/api/schemas/webhook-update.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Schema for webhook@update.
|
||||
*
|
||||
* @package WP_Ultimo\API\Schemas
|
||||
* @since 2.0.11
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Schema for webhook@update.
|
||||
*
|
||||
* @since 2.0.11
|
||||
* @internal last-generated in 2022-12
|
||||
* @generated class generated by our build scripts, do not change!
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
return array(
|
||||
'name' => array(
|
||||
'description' => __('Webhook name, which is used as product title as well.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'webhook_url' => array(
|
||||
'description' => __('The URL used for the webhook call.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'event' => array(
|
||||
'description' => __('The event that needs to be fired for this webhook to be sent.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'event_count' => array(
|
||||
'description' => __('How many times this webhook was sent.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'active' => array(
|
||||
'description' => __('Set this webhook as active (true), which means available will fire when the event occur, or inactive (false).', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'hidden' => array(
|
||||
'description' => __('Is this webhook hidden.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
'date_created' => array(
|
||||
'description' => __('Date when this was created.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'integration' => array(
|
||||
'description' => __('The integration that created this webhook.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_last_failed' => array(
|
||||
'description' => __('The date when this webhook last fail.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'description' => __('Model last modification date.', 'wp-ultimo'),
|
||||
'type' => 'string',
|
||||
'required' => false,
|
||||
),
|
||||
'migrated_from_id' => array(
|
||||
'description' => __('The ID of the original 1.X model that was used to generate this item on migration.', 'wp-ultimo'),
|
||||
'type' => 'integer',
|
||||
'required' => false,
|
||||
),
|
||||
'skip_validation' => array(
|
||||
'description' => __('Set true to have field information validation bypassed when saving this event.', 'wp-ultimo'),
|
||||
'type' => 'boolean',
|
||||
'required' => false,
|
||||
),
|
||||
);
|
697
inc/api/trait-rest-api.php
Normal file
697
inc/api/trait-rest-api.php
Normal file
@ -0,0 +1,697 @@
|
||||
<?php
|
||||
/**
|
||||
* A trait to be included in entities to enable REST API endpoints.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Apis
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Apis;
|
||||
|
||||
/**
|
||||
* REST API trait.
|
||||
*/
|
||||
trait Rest_Api {
|
||||
|
||||
/**
|
||||
* The base used in the route right after the namespace: <namespace>/<rest_base>.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = '';
|
||||
|
||||
/**
|
||||
* REST endpoints enabled for this entity.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $enabled_rest_endpoints = array(
|
||||
'get_item',
|
||||
'get_items',
|
||||
'create_item',
|
||||
'update_item',
|
||||
'delete_item',
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns the base used right after the namespace.
|
||||
* Uses the `rest_base` attribute if set, `slug` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_rest_base() {
|
||||
|
||||
return (!empty($this->rest_base)) ? $this->rest_base : $this->slug;
|
||||
|
||||
} // end get_rest_base;
|
||||
|
||||
/**
|
||||
* Registers the routes. Should be called by the entity
|
||||
* to actually enable the REST API.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function enable_rest_api() {
|
||||
|
||||
$is_enabled = \WP_Ultimo\API::get_instance()->is_api_enabled();
|
||||
|
||||
if ($is_enabled) {
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes_general'));
|
||||
|
||||
add_action('rest_api_init', array($this, 'register_routes_with_id'));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end enable_rest_api;
|
||||
|
||||
/**
|
||||
* Register the endpoints that don't need an ID,
|
||||
* like creation and lists.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function register_routes_general() {
|
||||
|
||||
$routes = array();
|
||||
|
||||
if (in_array('get_items', $this->enabled_rest_endpoints, true)) {
|
||||
|
||||
$routes = array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_items_rest'),
|
||||
'permission_callback' => array($this, 'get_items_permissions_check'),
|
||||
),
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
if (in_array('create_item', $this->enabled_rest_endpoints, true)) {
|
||||
|
||||
$routes[] = array(
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item_rest'),
|
||||
'permission_callback' => array($this, 'create_item_permissions_check'),
|
||||
'args' => $this->get_arguments_schema()
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
if (!empty($routes)) {
|
||||
|
||||
register_rest_route(
|
||||
\WP_Ultimo\API::get_instance()->get_namespace(),
|
||||
'/' . $this->get_rest_base(),
|
||||
$routes,
|
||||
true
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
do_action('wu_rest_register_routes_general', $routes, $this->get_rest_base(), 'create', $this);
|
||||
|
||||
} // end register_routes_general;
|
||||
|
||||
/**
|
||||
* Register the endpoints that need an ID,
|
||||
* like get, update and delete of a single element.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function register_routes_with_id() {
|
||||
|
||||
$routes = array();
|
||||
|
||||
if (in_array('get_item', $this->enabled_rest_endpoints, true)) {
|
||||
|
||||
$routes[] = array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item_rest'),
|
||||
'permission_callback' => array($this, 'get_item_permissions_check'),
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
if (in_array('update_item', $this->enabled_rest_endpoints, true)) {
|
||||
|
||||
$routes[] = array(
|
||||
'methods' => \WP_REST_Server::EDITABLE,
|
||||
'callback' => array($this, 'update_item_rest'),
|
||||
'permission_callback' => array($this, 'update_item_permissions_check'),
|
||||
'args' => $this->get_arguments_schema(true)
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
if (in_array('delete_item', $this->enabled_rest_endpoints, true)) {
|
||||
|
||||
$routes[] = array(
|
||||
'methods' => \WP_REST_Server::DELETABLE,
|
||||
'callback' => array($this, 'delete_item_rest'),
|
||||
'permission_callback' => array($this, 'delete_item_permissions_check'),
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
if (!empty($routes)) {
|
||||
|
||||
register_rest_route(
|
||||
\WP_Ultimo\API::get_instance()->get_namespace(),
|
||||
'/' . $this->get_rest_base() . '/(?P<id>[\d]+)',
|
||||
$routes,
|
||||
true
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
do_action('wu_rest_register_routes_with_id', $routes, $this->get_rest_base(), 'update', $this);
|
||||
|
||||
} // end register_routes_with_id;
|
||||
/**
|
||||
* Returns a specific item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request sent.
|
||||
* @return \WP_REST_Response|\WP_Error
|
||||
*/
|
||||
public function get_item_rest($request) {
|
||||
|
||||
$item = $this->model_class::get_by_id($request['id']);
|
||||
|
||||
if (empty($item)) {
|
||||
|
||||
return new \WP_Error("wu_rest_{$this->slug}_invalid_id", __('Item not found.', 'wp-ultimo'), array('status' => 404));
|
||||
|
||||
} // end if;
|
||||
|
||||
return rest_ensure_response($item);
|
||||
|
||||
} // end get_item_rest;
|
||||
/**
|
||||
* Returns a list of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request sent.
|
||||
* @return \WP_REST_Response|\WP_Error
|
||||
*/
|
||||
public function get_items_rest($request) {
|
||||
|
||||
$items = $this->model_class::query($request->get_params());
|
||||
|
||||
return rest_ensure_response($items);
|
||||
|
||||
} // end get_items_rest;
|
||||
/**
|
||||
* Creates an item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request sent.
|
||||
* @return \WP_REST_Response|\WP_Error
|
||||
*/
|
||||
public function create_item_rest($request) {
|
||||
|
||||
$body = json_decode($request->get_body(), true);
|
||||
|
||||
$model_name = (new $this->model_class(array()))->model;
|
||||
|
||||
$saver_function = "wu_create_{$model_name}";
|
||||
|
||||
if (function_exists($saver_function)) {
|
||||
|
||||
$item = call_user_func($saver_function, $body);
|
||||
|
||||
$saved = is_wp_error($item) ? $item : true;
|
||||
|
||||
} else {
|
||||
|
||||
$item = new $this->model_class($body);
|
||||
|
||||
$saved = $item->save();
|
||||
|
||||
} // end if;
|
||||
|
||||
if (is_wp_error($saved)) {
|
||||
|
||||
return rest_ensure_response($saved);
|
||||
|
||||
} // end if;
|
||||
|
||||
if (!$saved) {
|
||||
|
||||
return new \WP_Error("wu_rest_{$this->slug}", __('Something went wrong (Code 1).', 'wp-ultimo'), array('status' => 400));
|
||||
|
||||
} // end if;
|
||||
|
||||
return rest_ensure_response($item);
|
||||
|
||||
} // end create_item_rest;
|
||||
/**
|
||||
* Updates an item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request sent.
|
||||
* @return \WP_REST_Response|\WP_Error
|
||||
*/
|
||||
public function update_item_rest($request) {
|
||||
|
||||
$id = wu_get_isset($request->get_url_params(), 'id');
|
||||
|
||||
$item = $this->model_class::get_by_id($id);
|
||||
|
||||
if (empty($item)) {
|
||||
|
||||
return new \WP_Error("wu_rest_{$this->slug}_invalid_id", __('Item not found.', 'wp-ultimo'), array('status' => 404));
|
||||
|
||||
} // end if;
|
||||
|
||||
$params = array_filter(
|
||||
json_decode($request->get_body(), true),
|
||||
array($this, 'is_not_credential_key'),
|
||||
ARRAY_FILTER_USE_KEY
|
||||
);
|
||||
|
||||
foreach ($params as $param => $value) {
|
||||
|
||||
$set_method = "set_{$param}";
|
||||
|
||||
if ($param === 'meta') {
|
||||
|
||||
$item->update_meta_batch($value);
|
||||
|
||||
} elseif (method_exists($item, $set_method)) {
|
||||
|
||||
call_user_func(array($item, $set_method), $value);
|
||||
|
||||
} else {
|
||||
|
||||
$error_message = sprintf(
|
||||
/* translators: 1. Object class name; 2. Set method name */
|
||||
__('The %1$s object does not have a %2$s method', 'wp-ultimo'),
|
||||
get_class($item),
|
||||
$set_method
|
||||
);
|
||||
|
||||
return new \WP_Error(
|
||||
"wu_rest_{$this->slug}_invalid_set_method",
|
||||
$error_message,
|
||||
array('status' => 400)
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
$saved = $item->save();
|
||||
|
||||
if (is_wp_error($saved)) {
|
||||
|
||||
return rest_ensure_response($saved);
|
||||
|
||||
} // end if;
|
||||
|
||||
if (!$saved) {
|
||||
|
||||
return new \WP_Error("wu_rest_{$this->slug}", __('Something went wrong (Code 2).', 'wp-ultimo'));
|
||||
|
||||
} // end if;
|
||||
|
||||
return rest_ensure_response($item);
|
||||
|
||||
} // end update_item_rest;
|
||||
/**
|
||||
* Deletes an item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request sent.
|
||||
* @return \WP_REST_Response|\WP_Error
|
||||
*/
|
||||
public function delete_item_rest($request) {
|
||||
|
||||
$item = $this->model_class::get_by_id($request['id']);
|
||||
|
||||
if (empty($item)) {
|
||||
|
||||
return new \WP_Error("wu_rest_{$this->slug}_invalid_id", __('Item not found.', 'wp-ultimo'), array('status' => 404));
|
||||
|
||||
} // end if;
|
||||
|
||||
$result = $item->delete();
|
||||
|
||||
return rest_ensure_response($result);
|
||||
|
||||
} // end delete_item_rest;
|
||||
|
||||
/**
|
||||
* Check permissions to list items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request sent.
|
||||
* @return bool
|
||||
*/
|
||||
public function get_items_permissions_check($request) {
|
||||
|
||||
if (!\WP_Ultimo\API::get_instance()->check_authorization($request)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
/**
|
||||
* Filters if it is allowed to proceed with the request or not.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param bool $allowed Initial return value.
|
||||
* @param array $rest_base Entity slug.
|
||||
* @param Base_Manager $this The object instance.
|
||||
*/
|
||||
return apply_filters('wu_rest_get_items', true, $this->get_rest_base(), $this);
|
||||
|
||||
} // end get_items_permissions_check;
|
||||
|
||||
/**
|
||||
* Check permissions to create an item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request sent.
|
||||
* @return bool
|
||||
*/
|
||||
public function create_item_permissions_check($request) {
|
||||
|
||||
if (!\WP_Ultimo\API::get_instance()->check_authorization($request)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
/**
|
||||
* Filters if it is allowed to proceed with the request or not.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param bool $allowed Initial return value.
|
||||
* @param array $rest_base Entity slug.
|
||||
* @param Base_Manager $this The object instance.
|
||||
*/
|
||||
return apply_filters('wu_rest_create_item', true, $this->get_rest_base(), $this);
|
||||
|
||||
} // end create_item_permissions_check;
|
||||
|
||||
/**
|
||||
* Check permissions to get an item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request sent.
|
||||
* @return bool
|
||||
*/
|
||||
public function get_item_permissions_check($request) {
|
||||
|
||||
if (!\WP_Ultimo\API::get_instance()->check_authorization($request)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
/**
|
||||
* Filters if it is allowed to proceed with the request or not.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param bool $allowed Initial return value.
|
||||
* @param array $rest_base Entity slug.
|
||||
* @param Base_Manager $this The object instance.
|
||||
*/
|
||||
return apply_filters('wu_rest_get_item', true, $this->get_rest_base(), $this);
|
||||
|
||||
} // end get_item_permissions_check;
|
||||
|
||||
/**
|
||||
* Check permissions to update an item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request sent.
|
||||
* @return bool
|
||||
*/
|
||||
public function update_item_permissions_check($request) {
|
||||
|
||||
if (!\WP_Ultimo\API::get_instance()->check_authorization($request)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
/**
|
||||
* Filters if it is allowed to proceed with the request or not.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param bool $allowed Initial return value.
|
||||
* @param array $rest_base Entity slug.
|
||||
* @param Base_Manager $this The object instance.
|
||||
*/
|
||||
return apply_filters('wu_rest_update_item', true, $this->get_rest_base(), $this);
|
||||
|
||||
} // end update_item_permissions_check;
|
||||
|
||||
/**
|
||||
* Check permissions to delete an item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param WP_REST_Request $request The request sent.
|
||||
* @return bool
|
||||
*/
|
||||
public function delete_item_permissions_check($request) {
|
||||
|
||||
if (!\WP_Ultimo\API::get_instance()->check_authorization($request)) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
/**
|
||||
* Filters if it is allowed to proceed with the request or not.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param bool $allowed Initial return value.
|
||||
* @param array $rest_base Entity slug.
|
||||
* @param Base_Manager $this The object instance.
|
||||
*/
|
||||
return apply_filters('wu_rest_delete_item', true, $this->get_rest_base(), $this);
|
||||
|
||||
} // end delete_item_permissions_check;
|
||||
|
||||
/**
|
||||
* Checks if a value is not a credential key.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $value The value that will be checked.
|
||||
* @return bool
|
||||
*/
|
||||
private function is_not_credential_key($value) {
|
||||
|
||||
$credentials_keys = array(
|
||||
'api_key',
|
||||
'api_secret',
|
||||
'api-key',
|
||||
'api-secret',
|
||||
);
|
||||
|
||||
return !in_array($value, $credentials_keys, true);
|
||||
|
||||
} // end is_not_credential_key;
|
||||
|
||||
/**
|
||||
* Checks if a value is not equal to "id".
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $value The value that will be checked.
|
||||
* @return bool
|
||||
*/
|
||||
private function is_not_id_key($value) {
|
||||
|
||||
$arr = array(
|
||||
'id',
|
||||
);
|
||||
|
||||
if ($this->slug === 'site') {
|
||||
|
||||
$arr = array(
|
||||
'id',
|
||||
'blog_id',
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
return !in_array($value, $arr, true);
|
||||
|
||||
} // end is_not_id_key;
|
||||
|
||||
/**
|
||||
* Get the arguments for an endpoint
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param bool $edit Context. In edit, some fields, like ids, are not mandatory.
|
||||
* @return array
|
||||
*/
|
||||
public function get_arguments_schema($edit = false) {
|
||||
|
||||
$schema = wu_rest_get_endpoint_schema($this->model_class, $edit ? 'update' : 'create', true);
|
||||
|
||||
$args = array_filter($schema, array($this, 'is_not_id_key'), ARRAY_FILTER_USE_KEY);
|
||||
|
||||
return $this->filter_schema_arguments($args);
|
||||
|
||||
} // end get_arguments_schema;
|
||||
|
||||
/**
|
||||
* Remove some properties from the API schema.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $args Schema array.
|
||||
* @return array
|
||||
*/
|
||||
public function filter_schema_arguments($args) {
|
||||
|
||||
/**
|
||||
* Filter the original api arguments.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $args API Arguments for this manager.
|
||||
* @param object $this This manager.
|
||||
*/
|
||||
apply_filters('wu_before_' . $this->slug . '_api_arguments', $args, $this);
|
||||
|
||||
if ($this->slug !== 'broadcast' && isset($args['author_id'])) {
|
||||
|
||||
unset($args['author_id']);
|
||||
|
||||
} // end if;
|
||||
|
||||
if (isset($args['list_order'])) {
|
||||
|
||||
unset($args['list_order']);
|
||||
|
||||
} // end if;
|
||||
|
||||
$remove_status = apply_filters("wu_api_{$this->slug}_remove_status", array(
|
||||
'broadcast',
|
||||
'membership',
|
||||
'product',
|
||||
'payment',
|
||||
));
|
||||
|
||||
if (!in_array($this->slug, $remove_status, true) && isset($args['status'])) {
|
||||
|
||||
unset($args['status']);
|
||||
|
||||
} // end if;
|
||||
|
||||
$remove_slug = apply_filters("wu_api_{$this->slug}_remove_slug", array(
|
||||
'broadcast',
|
||||
'product',
|
||||
'checkout_form',
|
||||
'event',
|
||||
));
|
||||
|
||||
if (!in_array($this->slug, $remove_slug, true) && isset($args['slug'])) {
|
||||
|
||||
unset($args['slug']);
|
||||
|
||||
} // end if;
|
||||
|
||||
if ($this->slug === 'product' && isset($args['price_variations'])) {
|
||||
|
||||
unset($args['price_variations']);
|
||||
|
||||
} // end if;
|
||||
|
||||
if ($this->slug === 'payment' && isset($args['line_items'])) {
|
||||
|
||||
unset($args['line_items']);
|
||||
|
||||
} // end if;
|
||||
|
||||
if ($this->slug === 'site') {
|
||||
|
||||
if (isset($args['duplication_arguments'])) {
|
||||
|
||||
unset($args['duplication_arguments']);
|
||||
|
||||
} // end if;
|
||||
|
||||
if (isset($args['transient'])) {
|
||||
|
||||
unset($args['transient']);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
if ($this->slug === 'email') {
|
||||
|
||||
if (isset($args['status'])) {
|
||||
|
||||
unset($args['status']);
|
||||
|
||||
} // end if;
|
||||
|
||||
if (isset($args['email_schedule'])) {
|
||||
|
||||
unset($args['email_schedule']);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
if ($this->slug === 'broadcast') {
|
||||
|
||||
if (isset($args['message_targets'])) {
|
||||
|
||||
unset($args['message_targets']);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
if (isset($args['billing_address'])) {
|
||||
|
||||
unset($args['billing_address']);
|
||||
|
||||
} // end if;
|
||||
|
||||
/**
|
||||
* Filter after being changed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $args API Arguments for this manager.
|
||||
* @param object $this This manager.
|
||||
*/
|
||||
apply_filters('wu_after_' . $this->slug . '_api_arguments', $args, $this);
|
||||
|
||||
return $args;
|
||||
|
||||
} // end filter_schema_arguments;
|
||||
|
||||
} // end trait Rest_Api;
|
448
inc/api/trait-wp-cli.php
Normal file
448
inc/api/trait-wp-cli.php
Normal file
@ -0,0 +1,448 @@
|
||||
<?php
|
||||
/**
|
||||
* A trait to be included in entities to enable WP CLI commands.
|
||||
*
|
||||
* @package WP_Ultimo
|
||||
* @subpackage Apis
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
namespace WP_Ultimo\Apis;
|
||||
|
||||
/**
|
||||
* WP CLI trait.
|
||||
*/
|
||||
trait WP_CLI {
|
||||
|
||||
/**
|
||||
* The base used in the command right after the root: `wp <root> <command_base> <sub_command>`.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $wp_cli_command_base = '';
|
||||
|
||||
/**
|
||||
* WP-CLI Sub_command enabled for this entity.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $wp_cli_enabled_sub_commands = array();
|
||||
|
||||
/**
|
||||
* Returns the base used right after the root.
|
||||
* Uses the `wp_cli_command_base` attribute if set, `slug` otherwise.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string
|
||||
*/
|
||||
public function get_wp_cli_command_base() {
|
||||
|
||||
return (!empty($this->wp_cli_command_base)) ? $this->wp_cli_command_base : $this->slug;
|
||||
|
||||
} // end get_wp_cli_command_base;
|
||||
|
||||
/**
|
||||
* Registers the routes. Should be called by the entity
|
||||
* to actually enable the REST API.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function enable_wp_cli() {
|
||||
|
||||
if (!defined('WP_CLI')) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
$wp_cli_root = 'wu';
|
||||
|
||||
$this->set_wp_cli_enabled_sub_commands();
|
||||
|
||||
foreach ($this->wp_cli_enabled_sub_commands as $sub_command => $sub_command_data) {
|
||||
|
||||
\WP_CLI::add_command(
|
||||
"{$wp_cli_root} {$this->get_wp_cli_command_base()} {$sub_command}",
|
||||
$sub_command_data['callback'],
|
||||
array(
|
||||
'synopsis' => $sub_command_data['synopsis'],
|
||||
)
|
||||
);
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end enable_wp_cli;
|
||||
|
||||
/**
|
||||
* Set wP-CLI Sub-command enabled for this entity.
|
||||
*/
|
||||
public function set_wp_cli_enabled_sub_commands() {
|
||||
|
||||
$sub_commands = array(
|
||||
'get' => array(
|
||||
'callback' => array($this, 'wp_cli_get_item'),
|
||||
),
|
||||
'list' => array(
|
||||
'callback' => array($this, 'wp_cli_get_items'),
|
||||
),
|
||||
'create' => array(
|
||||
'callback' => array($this, 'wp_cli_create_item'),
|
||||
),
|
||||
'update' => array(
|
||||
'callback' => array($this, 'wp_cli_update_item'),
|
||||
),
|
||||
'delete' => array(
|
||||
'callback' => array($this, 'wp_cli_delete_item'),
|
||||
),
|
||||
);
|
||||
|
||||
$params = array_merge($this->wp_cli_get_fields(), $this->wp_cli_extra_parameters());
|
||||
|
||||
$params = array_unique($params);
|
||||
|
||||
/**
|
||||
* Unset undesired Params.
|
||||
*/
|
||||
$params_to_remove = apply_filters('wu_cli_params_to_remove', array(
|
||||
'id',
|
||||
'model',
|
||||
));
|
||||
|
||||
$params = array_filter($params, fn($param) => !in_array($param, $params_to_remove, true));
|
||||
|
||||
foreach ($sub_commands as $sub_command => &$sub_command_data) {
|
||||
|
||||
$sub_command_data['synopsis'] = array();
|
||||
|
||||
if (in_array($sub_command, array('get', 'update', 'delete'), true)) {
|
||||
|
||||
$sub_command_data['synopsis'][] = array(
|
||||
'name' => 'id',
|
||||
'type' => 'positional',
|
||||
'description' => __('The id for the resource.', 'wp-ultimo'),
|
||||
'optional' => false,
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
if (in_array($sub_command, array('list', 'update', 'create'), true)) {
|
||||
|
||||
$explanation_list = wu_rest_get_endpoint_schema($this->model_class, 'update');
|
||||
|
||||
foreach ($params as $name) {
|
||||
|
||||
$explanation = wu_get_isset($explanation_list, $name, array());
|
||||
|
||||
$type = wu_get_isset($explanation, 'type', 'assoc');
|
||||
|
||||
$field = array(
|
||||
'name' => $name,
|
||||
'description' => wu_get_isset($explanation, 'description', __('No description found.', 'wp-ultimo')),
|
||||
'optional' => !wu_get_isset($explanation, 'required'),
|
||||
'type' => 'assoc',
|
||||
);
|
||||
|
||||
$options = wu_get_isset($explanation, 'options', array());
|
||||
|
||||
if ($options) {
|
||||
|
||||
$field['options'] = $options;
|
||||
|
||||
} // end if;
|
||||
|
||||
$sub_command_data['synopsis'][] = $field;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end if;
|
||||
|
||||
if (in_array($sub_command, array('create', 'update'), true)) {
|
||||
|
||||
$sub_command_data['synopsis'][] = array(
|
||||
'name' => 'porcelain',
|
||||
'type' => 'flag',
|
||||
'description' => __('Output just the id when the operation is successful.', 'wp-ultimo'),
|
||||
'optional' => true,
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
if (in_array($sub_command, array('list', 'get'), true)) {
|
||||
|
||||
$sub_command_data['synopsis'][] = array(
|
||||
'name' => 'format',
|
||||
'type' => 'assoc',
|
||||
'description' => __('Render response in a particular format.', 'wp-ultimo'),
|
||||
'optional' => true,
|
||||
'default' => 'table',
|
||||
'options' => array(
|
||||
'table',
|
||||
'json',
|
||||
'csv',
|
||||
'ids',
|
||||
'yaml',
|
||||
'count',
|
||||
),
|
||||
);
|
||||
|
||||
$sub_command_data['synopsis'][] = array(
|
||||
'name' => 'fields',
|
||||
'type' => 'assoc',
|
||||
'description' => __('Limit response to specific fields. Defaults to id, name', 'wp-ultimo'),
|
||||
'optional' => true,
|
||||
'options' => array_merge(array('id'), $params),
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
$this->wp_cli_enabled_sub_commands = $sub_commands;
|
||||
|
||||
/**
|
||||
* Filters which sub_commands are enabled for this entity.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $sub_commands Default sub_commands.
|
||||
* @param string $command_base The base used in the command right after the root.
|
||||
* @param Base_Manager $this The object instance.
|
||||
*/
|
||||
$this->wp_cli_enabled_sub_commands = apply_filters(
|
||||
'wu_wp_cli_enabled_sub_commands',
|
||||
$this->wp_cli_enabled_sub_commands,
|
||||
$this->get_wp_cli_command_base(),
|
||||
$this
|
||||
);
|
||||
|
||||
} // end set_wp_cli_enabled_sub_commands;
|
||||
/**
|
||||
* Allows the additional of additional parameters.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function wp_cli_extra_parameters(): array {
|
||||
|
||||
$model = new $this->model_class();
|
||||
|
||||
return array_keys($model->to_array());
|
||||
|
||||
} // end wp_cli_extra_parameters;
|
||||
|
||||
/**
|
||||
* Returns the list of default fields, based on the table schema.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array List of the schema columns.
|
||||
*/
|
||||
public function wp_cli_get_fields(): array {
|
||||
|
||||
$schema = $this->model_class::get_schema();
|
||||
|
||||
return array_column($schema, 'name');
|
||||
|
||||
} // end wp_cli_get_fields;
|
||||
|
||||
/**
|
||||
* Returns a specific item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $args Positional arguments passed. ID expected.
|
||||
* @param array $array_assoc Assoc arguments passed.
|
||||
*/
|
||||
public function wp_cli_get_item($args, $array_assoc) {
|
||||
|
||||
$item = $this->model_class::get_by_id($args[0]);
|
||||
|
||||
if (empty($item)) {
|
||||
|
||||
\WP_CLI::error('Invalid ID.');
|
||||
|
||||
} // end if;
|
||||
|
||||
$fields = (!empty($array_assoc['fields'])) ? $array_assoc['fields'] : $this->wp_cli_get_fields();
|
||||
|
||||
$formatter = new \WP_CLI\Formatter($array_assoc, $fields);
|
||||
|
||||
$formatter->display_item($item->to_array());
|
||||
|
||||
} // end wp_cli_get_item;
|
||||
|
||||
/**
|
||||
* Returns a list of items.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $args Positional arguments passed. ID expected.
|
||||
* @param array $array_assoc Assoc arguments passed.
|
||||
*/
|
||||
public function wp_cli_get_items($args, $array_assoc) {
|
||||
|
||||
$fields = (!empty($array_assoc['fields'])) ? $array_assoc['fields'] : $this->wp_cli_get_fields();
|
||||
|
||||
unset($array_assoc['fields']);
|
||||
|
||||
$items = $this->model_class::query($array_assoc);
|
||||
|
||||
$items = array_map(fn($item) => $item->to_array(), $items);
|
||||
|
||||
\WP_CLI\Utils\format_items($array_assoc['format'], $items, $fields);
|
||||
|
||||
} // end wp_cli_get_items;
|
||||
|
||||
/**
|
||||
* Creates an item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $args Positional arguments passed. ID expected.
|
||||
* @param array $array_assoc Assoc arguments passed.
|
||||
*/
|
||||
public function wp_cli_create_item($args, $array_assoc) {
|
||||
|
||||
$item = new $this->model_class($array_assoc);
|
||||
|
||||
$success = $item->save();
|
||||
|
||||
if ($success === true) {
|
||||
|
||||
$item_id = $item->get_id();
|
||||
|
||||
if (!empty($array_assoc['porcelain'])) {
|
||||
|
||||
\WP_CLI::line($item_id);
|
||||
|
||||
} else {
|
||||
|
||||
$message = sprintf('Item created with ID %d', $item_id);
|
||||
|
||||
\WP_CLI::success($message);
|
||||
|
||||
} // end if;
|
||||
|
||||
} else {
|
||||
|
||||
\WP_CLI::error($success);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end wp_cli_create_item;
|
||||
|
||||
/**
|
||||
* Updates an item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $args Positional arguments passed. ID expected.
|
||||
* @param array $array_assoc Assoc arguments passed.
|
||||
*/
|
||||
public function wp_cli_update_item($args, $array_assoc) {
|
||||
|
||||
$item = $this->model_class::get_by_id($args[0]);
|
||||
|
||||
if (empty($item)) {
|
||||
|
||||
\WP_CLI::error('Invalid ID.');
|
||||
|
||||
} // end if;
|
||||
|
||||
$porcelain = false;
|
||||
|
||||
if (!empty($array_assoc['porcelain'])) {
|
||||
|
||||
$porcelain = true;
|
||||
|
||||
unset($array_assoc['porcelain']);
|
||||
|
||||
} // end if;
|
||||
|
||||
$params = $array_assoc;
|
||||
|
||||
foreach ($params as $param => $value) {
|
||||
|
||||
$set_method = "set_{$param}";
|
||||
|
||||
if ($param === 'meta') {
|
||||
|
||||
$item->update_meta_batch($value);
|
||||
|
||||
} elseif (method_exists($item, $set_method)) {
|
||||
|
||||
call_user_func(array($item, $set_method), $value);
|
||||
|
||||
} else {
|
||||
|
||||
$error_message = sprintf(
|
||||
/* translators: 1. Object class name; 2. Set method name */
|
||||
__('The %1$s object does not have a %2$s method', 'wp-ultimo'),
|
||||
get_class($item),
|
||||
$set_method
|
||||
);
|
||||
|
||||
\WP_CLI::error($error_message);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
$success = $item->save();
|
||||
|
||||
if ($success) {
|
||||
|
||||
$item_id = $item->get_id();
|
||||
|
||||
if ($porcelain) {
|
||||
|
||||
\WP_CLI::line($item_id);
|
||||
|
||||
} else {
|
||||
|
||||
$message = sprintf('Item updated with ID %d', $item_id);
|
||||
|
||||
\WP_CLI::success($message);
|
||||
|
||||
} // end if;
|
||||
|
||||
} else {
|
||||
|
||||
\WP_CLI::error('Unexpected error. The item was not updated.');
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end wp_cli_update_item;
|
||||
|
||||
/**
|
||||
* Deletes an item.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $args Positional arguments passed. ID expected.
|
||||
*/
|
||||
public function wp_cli_delete_item($args) {
|
||||
|
||||
$item = $this->model_class::get_by_id($args[0]);
|
||||
|
||||
if (empty($item)) {
|
||||
|
||||
\WP_CLI::error('Invalid ID.');
|
||||
|
||||
} // end if;
|
||||
|
||||
$success = $item->delete();
|
||||
|
||||
if (is_wp_error($success) || !$success) {
|
||||
|
||||
\WP_CLI::error('Unexpected error. The item was not deleted.');
|
||||
|
||||
} else {
|
||||
|
||||
\WP_CLI::success('Item deleted.');
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end wp_cli_delete_item;
|
||||
|
||||
} // end trait WP_CLI;
|
Reference in New Issue
Block a user