Use new code style
This commit is contained in:
@ -79,8 +79,7 @@ abstract class Base_Host_Provider {
|
||||
add_filter('wu_domain_manager_get_integrations', array($this, 'self_register'));
|
||||
|
||||
add_action('init', array($this, 'add_to_integration_list'));
|
||||
|
||||
} // end init;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the hooks and dependencies, but only if the hosting is enabled via is_enabled().
|
||||
@ -89,13 +88,12 @@ abstract class Base_Host_Provider {
|
||||
*/
|
||||
final public function __construct() {
|
||||
|
||||
if ($this->detect() && !$this->is_enabled()) {
|
||||
if ($this->detect() && ! $this->is_enabled()) {
|
||||
/*
|
||||
* Adds an admin notice telling the admin that they should probably enable this integration.
|
||||
*/
|
||||
return $this->alert_provider_detected();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* Only add hooks if the integration is enabled and correctly setup.
|
||||
@ -104,13 +102,12 @@ abstract class Base_Host_Provider {
|
||||
/*
|
||||
* Checks if everything was correctly setup.
|
||||
*/
|
||||
if (!$this->is_setup()) {
|
||||
if ( ! $this->is_setup()) {
|
||||
/*
|
||||
* Adds an admin notice telling the admin that the provider is not correctly setup.
|
||||
*/
|
||||
return $this->alert_provider_not_setup();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load the dependencies.
|
||||
@ -121,10 +118,8 @@ abstract class Base_Host_Provider {
|
||||
* Initialize the hooks.
|
||||
*/
|
||||
$this->register_hooks();
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end __construct;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Let the class register itself on the manager, allowing us to access the integrations later via the slug.
|
||||
@ -136,11 +131,10 @@ abstract class Base_Host_Provider {
|
||||
*/
|
||||
final public function self_register($integrations) {
|
||||
|
||||
$integrations[$this->get_id()] = get_called_class();
|
||||
$integrations[ $this->get_id() ] = get_called_class();
|
||||
|
||||
return $integrations;
|
||||
|
||||
} // end self_register;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of enabled host integrations.
|
||||
@ -151,8 +145,7 @@ abstract class Base_Host_Provider {
|
||||
protected function get_enabled_list() {
|
||||
|
||||
return get_network_option(null, 'wu_host_integrations_enabled', array());
|
||||
|
||||
} // end get_enabled_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this integration is enabled.
|
||||
@ -165,8 +158,7 @@ abstract class Base_Host_Provider {
|
||||
$list = $this->get_enabled_list();
|
||||
|
||||
return wu_get_isset($list, $this->get_id(), false);
|
||||
|
||||
} // end is_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables this integration.
|
||||
@ -178,11 +170,10 @@ abstract class Base_Host_Provider {
|
||||
|
||||
$list = $this->get_enabled_list();
|
||||
|
||||
$list[$this->get_id()] = true;
|
||||
$list[ $this->get_id() ] = true;
|
||||
|
||||
return update_network_option(null, 'wu_host_integrations_enabled', $list);
|
||||
|
||||
} // end enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables this integration.
|
||||
@ -194,11 +185,10 @@ abstract class Base_Host_Provider {
|
||||
|
||||
$list = $this->get_enabled_list();
|
||||
|
||||
$list[$this->get_id()] = false;
|
||||
$list[ $this->get_id() ] = false;
|
||||
|
||||
return update_network_option(null, 'wu_host_integrations_enabled', $list);
|
||||
|
||||
} // end disable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the host to the list of integrations.
|
||||
@ -212,9 +202,12 @@ abstract class Base_Host_Provider {
|
||||
|
||||
$html = $this->is_enabled() ? sprintf('<span class="wu-self-center wu-text-green-800 wu-mr-4"><span class="dashicons-wu-check"></span> %s</span>', __('Activated', 'wp-ultimo')) : '';
|
||||
|
||||
$url = wu_network_admin_url('wp-ultimo-hosting-integration-wizard', array(
|
||||
'integration' => $slug,
|
||||
));
|
||||
$url = wu_network_admin_url(
|
||||
'wp-ultimo-hosting-integration-wizard',
|
||||
array(
|
||||
'integration' => $slug,
|
||||
)
|
||||
);
|
||||
|
||||
$html .= sprintf('<a href="%s" class="button-primary">%s</a>', $url, __('Configuration', 'wp-ultimo'));
|
||||
|
||||
@ -226,13 +219,16 @@ abstract class Base_Host_Provider {
|
||||
__('Go to the setup wizard to setup this integration.', 'wp-ultimo')
|
||||
);
|
||||
|
||||
wu_register_settings_field('integrations', "integration_{$slug}", array(
|
||||
'type' => 'note',
|
||||
'title' => $title,
|
||||
'desc' => $html,
|
||||
));
|
||||
|
||||
} // end add_to_integration_list;
|
||||
wu_register_settings_field(
|
||||
'integrations',
|
||||
"integration_{$slug}",
|
||||
array(
|
||||
'type' => 'note',
|
||||
'title' => $title,
|
||||
'desc' => $html,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an admin notice telling the admin that they should probably enable this integration.
|
||||
@ -243,10 +239,8 @@ abstract class Base_Host_Provider {
|
||||
public function alert_provider_detected() {
|
||||
|
||||
if (WP_Ultimo()->is_loaded() === false) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
// translators: %1$s will be replaced with the integration title. E.g. RunCloud
|
||||
$message = sprintf(__('It looks like you are using %1$s as your hosting provider, yet the %1$s integration module is not active. In order for the domain mapping integration to work with %1$s, you might want to activate that module.', 'wp-ultimo'), $this->get_title());
|
||||
@ -257,15 +251,17 @@ abstract class Base_Host_Provider {
|
||||
'activate' => array(
|
||||
// translators: %s is the integration name.
|
||||
'title' => sprintf(__('Activate %s', 'wp-ultimo'), $this->get_title()),
|
||||
'url' => wu_network_admin_url('wp-ultimo-hosting-integration-wizard', array(
|
||||
'integration' => $slug,
|
||||
)),
|
||||
)
|
||||
'url' => wu_network_admin_url(
|
||||
'wp-ultimo-hosting-integration-wizard',
|
||||
array(
|
||||
'integration' => $slug,
|
||||
)
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
WP_Ultimo()->notices->add($message, 'info', 'network-admin', "should-enable-{$slug}-integration", $actions);
|
||||
|
||||
} // end alert_provider_detected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an admin notice telling the admin that the provider is not correctly setup.
|
||||
@ -276,10 +272,8 @@ abstract class Base_Host_Provider {
|
||||
public function alert_provider_not_setup() {
|
||||
|
||||
if (WP_Ultimo()->is_loaded() === false) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
// translators: %1$s will be replaced with the integration title. E.g. RunCloud.
|
||||
$message = sprintf(__('It looks like you are using %1$s as your hosting provider, yet the %1$s integration module was not properly setup. In order for the domain mapping integration to work with %1$s, you need to configure that module.', 'wp-ultimo'), $this->get_title());
|
||||
@ -290,16 +284,18 @@ abstract class Base_Host_Provider {
|
||||
'activate' => array(
|
||||
// translators: %s is the integration name
|
||||
'title' => sprintf(__('Setup %s', 'wp-ultimo'), $this->get_title()),
|
||||
'url' => wu_network_admin_url('wp-ultimo-hosting-integration-wizard', array(
|
||||
'integration' => $slug,
|
||||
'tab' => 'config',
|
||||
)),
|
||||
)
|
||||
'url' => wu_network_admin_url(
|
||||
'wp-ultimo-hosting-integration-wizard',
|
||||
array(
|
||||
'integration' => $slug,
|
||||
'tab' => 'config',
|
||||
)
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
WP_Ultimo()->notices->add($message, 'warning', 'network-admin', "should-setup-{$slug}-integration", $actions);
|
||||
|
||||
} // end alert_provider_not_setup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Fields for the integration.
|
||||
@ -310,8 +306,7 @@ abstract class Base_Host_Provider {
|
||||
public function get_fields() {
|
||||
|
||||
return array();
|
||||
|
||||
} // end get_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integration id.
|
||||
@ -322,8 +317,7 @@ abstract class Base_Host_Provider {
|
||||
public function get_id() {
|
||||
|
||||
return $this->id;
|
||||
|
||||
} // end get_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integration title.
|
||||
@ -334,8 +328,7 @@ abstract class Base_Host_Provider {
|
||||
public function get_title() {
|
||||
|
||||
return $this->title;
|
||||
|
||||
} // end get_title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a feature is supported, like auto-ssl for example.
|
||||
@ -347,8 +340,7 @@ abstract class Base_Host_Provider {
|
||||
public function supports($feature) {
|
||||
|
||||
return apply_filters('wu_hosting_support_supports', in_array($feature, $this->supports, true), $this);
|
||||
|
||||
} // end supports;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the hooks.
|
||||
@ -381,8 +373,7 @@ abstract class Base_Host_Provider {
|
||||
* Add additional hooks.
|
||||
*/
|
||||
$this->additional_hooks();
|
||||
|
||||
} // end register_hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets integrations add additional hooks.
|
||||
@ -390,7 +381,7 @@ abstract class Base_Host_Provider {
|
||||
* @since 2.0.7
|
||||
* @return void
|
||||
*/
|
||||
public function additional_hooks() {} // end additional_hooks;
|
||||
public function additional_hooks() {}
|
||||
|
||||
/**
|
||||
* Can be used to load dependencies.
|
||||
@ -398,7 +389,7 @@ abstract class Base_Host_Provider {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function load_dependencies() {} // end load_dependencies;
|
||||
public function load_dependencies() {}
|
||||
|
||||
/**
|
||||
* Picks up on tips that a given host provider is being used.
|
||||
@ -421,22 +412,17 @@ abstract class Base_Host_Provider {
|
||||
$all_set = true;
|
||||
|
||||
foreach ($this->constants as $constant) {
|
||||
|
||||
$constants = is_array($constant) ? $constant : array($constant);
|
||||
|
||||
$current = false;
|
||||
|
||||
foreach ($constants as $constant) {
|
||||
|
||||
if (defined($constant) && constant($constant)) {
|
||||
|
||||
$current = true;
|
||||
|
||||
break;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
}
|
||||
|
||||
$all_set = $all_set && $current;
|
||||
|
||||
@ -444,16 +430,12 @@ abstract class Base_Host_Provider {
|
||||
* If any constant fail, bail.
|
||||
*/
|
||||
if ($all_set === false) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
}
|
||||
|
||||
return $all_set;
|
||||
|
||||
} // end is_setup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of missing constants configured on wp-config.php
|
||||
@ -466,30 +448,23 @@ abstract class Base_Host_Provider {
|
||||
$missing_constants = array();
|
||||
|
||||
foreach ($this->constants as $constant) {
|
||||
|
||||
$constants = is_array($constant) ? $constant : array($constant);
|
||||
|
||||
$current = false;
|
||||
|
||||
foreach ($constants as $constant) {
|
||||
|
||||
if (defined($constant) && constant($constant)) {
|
||||
|
||||
$current = true;
|
||||
|
||||
break;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
}
|
||||
|
||||
$missing_constants = $current ? $missing_constants : array_merge($missing_constants, $constants);
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
|
||||
return $missing_constants;
|
||||
|
||||
} // end get_missing_constants;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all constants, optional or not.
|
||||
@ -502,16 +477,13 @@ abstract class Base_Host_Provider {
|
||||
$constants = array();
|
||||
|
||||
foreach ($this->constants as $constant) {
|
||||
|
||||
$current = is_array($constant) ? $constant : array($constant);
|
||||
|
||||
$constants = array_merge($constants, $current);
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
|
||||
return array_merge($constants, $this->optional_constants);
|
||||
|
||||
} // end get_all_constants;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the constants with their respective values into the wp-config.php.
|
||||
@ -532,12 +504,9 @@ abstract class Base_Host_Provider {
|
||||
$values = shortcode_atts(array_flip($this->get_all_constants()), $constant_values);
|
||||
|
||||
foreach ($values as $constant => $value) {
|
||||
|
||||
WP_Config::get_instance()->inject_wp_config_constant($constant, $value);
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end setup_constants;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a define string for manual insertion on-to wp-config.php.
|
||||
@ -569,10 +538,8 @@ abstract class Base_Host_Provider {
|
||||
* Adds the constants, one by one.
|
||||
*/
|
||||
foreach ($constant_values as $constant => $value) {
|
||||
|
||||
$content[] = sprintf("define( '%s', '%s' );", $constant, $value);
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds the final line.
|
||||
@ -580,8 +547,7 @@ abstract class Base_Host_Provider {
|
||||
$content[] = sprintf('// WP Multisite WaaS - Domain Mapping - %s - End', $this->get_title());
|
||||
|
||||
return implode(PHP_EOL, $content);
|
||||
|
||||
} // end get_constants_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the explainer lines for the integration.
|
||||
@ -603,17 +569,14 @@ abstract class Base_Host_Provider {
|
||||
|
||||
// translators: %s is the name of the integration e.g. RunCloud
|
||||
$explainer_lines['will'][] = sprintf(__('Fetch and install a SSL certificate on %s platform after the domain is added.', 'wp-ultimo'), $this->get_title());
|
||||
|
||||
} else {
|
||||
|
||||
// translators: %s is the name of the integration e.g. RunCloud
|
||||
$explainer_lines['will_not'][] = sprintf(__('Fetch and install a SSL certificate on %s platform after the domain is added. This needs to be done manually.', 'wp-ultimo'), $this->get_title());
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $explainer_lines;
|
||||
|
||||
} // end get_explainer_lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new domain is mapped.
|
||||
@ -670,8 +633,7 @@ abstract class Base_Host_Provider {
|
||||
public function test_connection() {
|
||||
|
||||
wp_send_json_success(array());
|
||||
|
||||
} // end test_connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of this integration.
|
||||
@ -682,8 +644,7 @@ abstract class Base_Host_Provider {
|
||||
public function get_description() {
|
||||
|
||||
return __('No description provided.', 'wp-ultimo');
|
||||
|
||||
} // end get_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logo for the integration.
|
||||
@ -694,7 +655,5 @@ abstract class Base_Host_Provider {
|
||||
public function get_logo() {
|
||||
|
||||
return '';
|
||||
|
||||
} // end get_logo;
|
||||
|
||||
} // end class Base_Host_Provider;
|
||||
}
|
||||
}
|
||||
|
@ -78,8 +78,7 @@ class Closte_Host_Provider extends Base_Host_Provider {
|
||||
public function detect() {
|
||||
|
||||
return defined('CLOSTE_CLIENT_API_KEY') && CLOSTE_CLIENT_API_KEY;
|
||||
|
||||
} // end detect;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new domain is mapped.
|
||||
@ -91,12 +90,14 @@ class Closte_Host_Provider extends Base_Host_Provider {
|
||||
*/
|
||||
public function on_add_domain($domain, $site_id) {
|
||||
|
||||
$this->send_closte_api_request('/adddomainalias', array(
|
||||
'domain' => $domain,
|
||||
'wildcard' => strncmp($domain, '*.', strlen('*.')) === 0
|
||||
));
|
||||
|
||||
} // end on_add_domain;
|
||||
$this->send_closte_api_request(
|
||||
'/adddomainalias',
|
||||
array(
|
||||
'domain' => $domain,
|
||||
'wildcard' => strncmp($domain, '*.', strlen('*.')) === 0,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a mapped domain is removed.
|
||||
@ -108,12 +109,14 @@ class Closte_Host_Provider extends Base_Host_Provider {
|
||||
*/
|
||||
public function on_remove_domain($domain, $site_id) {
|
||||
|
||||
$this->send_closte_api_request('/deletedomainalias', array(
|
||||
'domain' => $domain,
|
||||
'wildcard' => strncmp($domain, '*.', strlen('*.')) === 0
|
||||
));
|
||||
|
||||
} // end on_remove_domain;
|
||||
$this->send_closte_api_request(
|
||||
'/deletedomainalias',
|
||||
array(
|
||||
'domain' => $domain,
|
||||
'wildcard' => strncmp($domain, '*.', strlen('*.')) === 0,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being added.
|
||||
@ -125,7 +128,7 @@ class Closte_Host_Provider extends Base_Host_Provider {
|
||||
* @param int $site_id ID of the site that is receiving that mapping.
|
||||
* @return void
|
||||
*/
|
||||
public function on_add_subdomain($subdomain, $site_id) {} // end on_add_subdomain;
|
||||
public function on_add_subdomain($subdomain, $site_id) {}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being removed.
|
||||
@ -137,7 +140,7 @@ class Closte_Host_Provider extends Base_Host_Provider {
|
||||
* @param int $site_id ID of the site that is receiving that mapping.
|
||||
* @return void
|
||||
*/
|
||||
public function on_remove_subdomain($subdomain, $site_id) {} // end on_remove_subdomain;
|
||||
public function on_remove_subdomain($subdomain, $site_id) {}
|
||||
|
||||
/**
|
||||
* Tests the connection with the API.
|
||||
@ -152,18 +155,17 @@ class Closte_Host_Provider extends Base_Host_Provider {
|
||||
$response = $this->send_closte_api_request('/adddomainalias', array());
|
||||
|
||||
if (wu_get_isset($response, 'error') === 'Invalid or empty domain: ') {
|
||||
|
||||
wp_send_json_success(array(
|
||||
'message' => __('Access Authorized'),
|
||||
));
|
||||
|
||||
} // end if;
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => __('Access Authorized'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$error = new \WP_Error('not-auth', __('Something went wrong', 'wp-ultimo'));
|
||||
|
||||
wp_send_json_error($error);
|
||||
|
||||
} // end test_connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to Closte, with the right API key.
|
||||
@ -176,47 +178,43 @@ class Closte_Host_Provider extends Base_Host_Provider {
|
||||
public function send_closte_api_request($endpoint, $data) {
|
||||
|
||||
if (defined('CLOSTE_CLIENT_API_KEY') === false) {
|
||||
|
||||
return (object) array(
|
||||
'success' => false,
|
||||
'error' => 'Closte API Key not found.',
|
||||
);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$post_fields = array(
|
||||
'blocking' => true,
|
||||
'timeout' => 45,
|
||||
'method' => 'POST',
|
||||
'body' => array_merge(array(
|
||||
'apikey' => CLOSTE_CLIENT_API_KEY,
|
||||
), $data)
|
||||
'body' => array_merge(
|
||||
array(
|
||||
'apikey' => CLOSTE_CLIENT_API_KEY,
|
||||
),
|
||||
$data
|
||||
),
|
||||
);
|
||||
|
||||
$response = wp_remote_post('https://app.closte.com/api/client' . $endpoint, $post_fields);
|
||||
|
||||
wu_log_add('integration-closte', wp_remote_retrieve_body($response));
|
||||
|
||||
if (!is_wp_error($response)) {
|
||||
|
||||
if ( ! is_wp_error($response)) {
|
||||
$body = json_decode(wp_remote_retrieve_body($response), true);
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
|
||||
return $body;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return (object) array(
|
||||
'success' => false,
|
||||
'error' => 'unknown'
|
||||
'error' => 'unknown',
|
||||
);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
} // end send_closte_api_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of this integration.
|
||||
@ -227,8 +225,7 @@ class Closte_Host_Provider extends Base_Host_Provider {
|
||||
public function get_description() {
|
||||
|
||||
return __('Closte is not just another web hosting who advertise their services as a cloud hosting while still provides fixed plans like in 1995.', 'wp-ultimo');
|
||||
|
||||
} // end get_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logo for the integration.
|
||||
@ -239,7 +236,5 @@ class Closte_Host_Provider extends Base_Host_Provider {
|
||||
public function get_logo() {
|
||||
|
||||
return wu_get_asset('closte.svg', 'img/hosts');
|
||||
|
||||
} // end get_logo;
|
||||
|
||||
} // end class Closte_Host_Provider;
|
||||
}
|
||||
}
|
||||
|
@ -83,21 +83,21 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
$default_zone_id = defined('WU_CLOUDFLARE_ZONE_ID') && WU_CLOUDFLARE_ZONE_ID ? WU_CLOUDFLARE_ZONE_ID : false;
|
||||
|
||||
if ($default_zone_id) {
|
||||
|
||||
$zone_ids[] = $default_zone_id;
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
$cloudflare_zones = $this->cloudflare_api_call('client/v4/zones', 'GET', array(
|
||||
'name' => $domain,
|
||||
'status' => 'active',
|
||||
));
|
||||
$cloudflare_zones = $this->cloudflare_api_call(
|
||||
'client/v4/zones',
|
||||
'GET',
|
||||
array(
|
||||
'name' => $domain,
|
||||
'status' => 'active',
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($cloudflare_zones->result as $zone) {
|
||||
|
||||
$zone_ids[] = $zone->id;
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
|
||||
foreach ($zone_ids as $zone_id) {
|
||||
|
||||
@ -105,20 +105,22 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
* First, try to detect the domain as a proxied on the current zone,
|
||||
* if applicable
|
||||
*/
|
||||
$dns_entries = $this->cloudflare_api_call("client/v4/zones/$zone_id/dns_records/", 'GET', array(
|
||||
'name' => $domain,
|
||||
'match' => 'any',
|
||||
'type' => 'A,AAAA,CNAME',
|
||||
));
|
||||
|
||||
if (!empty($dns_entries->result)) {
|
||||
$dns_entries = $this->cloudflare_api_call(
|
||||
"client/v4/zones/$zone_id/dns_records/",
|
||||
'GET',
|
||||
array(
|
||||
'name' => $domain,
|
||||
'match' => 'any',
|
||||
'type' => 'A,AAAA,CNAME',
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! empty($dns_entries->result)) {
|
||||
$proxied_tag = sprintf('<span class="wu-bg-orange-500 wu-text-white wu-p-1 wu-rounded wu-text-3xs wu-uppercase wu-ml-2 wu-font-bold" %s>%s</span>', wu_tooltip_text(__('Proxied', 'wp-ultimo')), __('Cloudflare', 'wp-ultimo'));
|
||||
|
||||
$not_proxied_tag = sprintf('<span class="wu-bg-gray-700 wu-text-white wu-p-1 wu-rounded wu-text-3xs wu-uppercase wu-ml-2 wu-font-bold" %s>%s</span>', wu_tooltip_text(__('Not Proxied', 'wp-ultimo')), __('Cloudflare', 'wp-ultimo'));
|
||||
|
||||
foreach ($dns_entries->result as $entry) {
|
||||
|
||||
$dns_records[] = array(
|
||||
'ttl' => $entry->ttl,
|
||||
'data' => $entry->content,
|
||||
@ -126,16 +128,12 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
'host' => $entry->name,
|
||||
'tag' => $entry->proxied ? $proxied_tag : $not_proxied_tag,
|
||||
);
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $dns_records;
|
||||
|
||||
} // end add_cloudflare_dns_entries;
|
||||
}
|
||||
/**
|
||||
* Picks up on tips that a given host provider is being used.
|
||||
*
|
||||
@ -152,8 +150,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
* @since 2.1
|
||||
*/
|
||||
return false;
|
||||
|
||||
} // end detect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of installation fields.
|
||||
@ -173,8 +170,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
'placeholder' => __('e.g. xKGbxxVDpdcUv9dUzRf4i4ngv0QNf1wCtbehiec_o', 'wp-ultimo'),
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the connection with the Cloudflare API.
|
||||
@ -187,14 +183,11 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
$results = $this->cloudflare_api_call('client/v4/user/tokens/verify');
|
||||
|
||||
if (is_wp_error($results)) {
|
||||
|
||||
wp_send_json_error($results);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
wp_send_json_success($results);
|
||||
|
||||
} // end test_connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lets integrations add additional hooks.
|
||||
@ -205,8 +198,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
public function additional_hooks() {
|
||||
|
||||
add_filter('wu_domain_dns_get_record', array($this, 'add_cloudflare_dns_entries'), 10, 2);
|
||||
|
||||
} // end additional_hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new domain is mapped.
|
||||
@ -216,7 +208,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
* @param int $site_id ID of the site that is receiving that mapping.
|
||||
* @return void
|
||||
*/
|
||||
public function on_add_domain($domain, $site_id) {} // end on_add_domain;
|
||||
public function on_add_domain($domain, $site_id) {}
|
||||
|
||||
/**
|
||||
* This method gets called when a mapped domain is removed.
|
||||
@ -226,7 +218,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
* @param int $site_id ID of the site that is receiving that mapping.
|
||||
* @return void
|
||||
*/
|
||||
public function on_remove_domain($domain, $site_id) {} // end on_remove_domain;
|
||||
public function on_remove_domain($domain, $site_id) {}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being added.
|
||||
@ -244,25 +236,20 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$zone_id = defined('WU_CLOUDFLARE_ZONE_ID') && WU_CLOUDFLARE_ZONE_ID ? WU_CLOUDFLARE_ZONE_ID : '';
|
||||
|
||||
if (!$zone_id) {
|
||||
|
||||
if ( ! $zone_id) {
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
if (strpos($subdomain, (string) $current_site->domain) === false) {
|
||||
|
||||
return; // Not a sub-domain of the main domain.
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$subdomain = rtrim(str_replace($current_site->domain, '', $subdomain), '.');
|
||||
|
||||
if (!$subdomain) {
|
||||
|
||||
if ( ! $subdomain) {
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$should_add_www = apply_filters('wu_cloudflare_should_add_www', true, $subdomain, $site_id);
|
||||
|
||||
@ -272,38 +259,36 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
* Adds the www version, if necessary.
|
||||
*/
|
||||
if (strncmp($subdomain, 'www.', strlen('www.')) !== 0 && $should_add_www) {
|
||||
|
||||
$domains_to_send[] = 'www.' . $subdomain;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
foreach ($domains_to_send as $subdomain) {
|
||||
|
||||
$should_proxy = apply_filters('wu_cloudflare_should_proxy', true, $subdomain, $site_id);
|
||||
|
||||
$data = apply_filters('wu_cloudflare_on_add_domain_data', array(
|
||||
'type' => 'CNAME',
|
||||
'name' => $subdomain,
|
||||
'content' => '@',
|
||||
'proxied' => $should_proxy,
|
||||
'ttl' => 1,
|
||||
), $subdomain, $site_id);
|
||||
$data = apply_filters(
|
||||
'wu_cloudflare_on_add_domain_data',
|
||||
array(
|
||||
'type' => 'CNAME',
|
||||
'name' => $subdomain,
|
||||
'content' => '@',
|
||||
'proxied' => $should_proxy,
|
||||
'ttl' => 1,
|
||||
),
|
||||
$subdomain,
|
||||
$site_id
|
||||
);
|
||||
|
||||
$results = $this->cloudflare_api_call("client/v4/zones/$zone_id/dns_records/", 'POST', $data);
|
||||
|
||||
if (is_wp_error($results)) {
|
||||
|
||||
wu_log_add('integration-cloudflare', sprintf('Failed to add subdomain "%s" to Cloudflare. Reason: %s', $subdomain, $results->get_error_message()), LogLevel::ERROR);
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
wu_log_add('integration-cloudflare', sprintf('Added sub-domain "%s" to Cloudflare.', $subdomain));
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end on_add_subdomain;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being removed.
|
||||
@ -321,27 +306,22 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$zone_id = defined('WU_CLOUDFLARE_ZONE_ID') && WU_CLOUDFLARE_ZONE_ID ? WU_CLOUDFLARE_ZONE_ID : '';
|
||||
|
||||
if (!$zone_id) {
|
||||
|
||||
if ( ! $zone_id) {
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
if (strpos($subdomain, (string) $current_site->domain) === false) {
|
||||
|
||||
return; // Not a sub-domain of the main domain.
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$original_subdomain = $subdomain;
|
||||
|
||||
$subdomain = rtrim(str_replace($current_site->domain, '', $subdomain), '.');
|
||||
|
||||
if (!$subdomain) {
|
||||
|
||||
if ( ! $subdomain) {
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/**
|
||||
* Created the list that we should remove.
|
||||
@ -352,35 +332,32 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
);
|
||||
|
||||
foreach ($domains_to_remove as $original_subdomain) {
|
||||
$dns_entries = $this->cloudflare_api_call(
|
||||
"client/v4/zones/$zone_id/dns_records/",
|
||||
'GET',
|
||||
array(
|
||||
'name' => $original_subdomain,
|
||||
'type' => 'CNAME',
|
||||
)
|
||||
);
|
||||
|
||||
$dns_entries = $this->cloudflare_api_call("client/v4/zones/$zone_id/dns_records/", 'GET', array(
|
||||
'name' => $original_subdomain,
|
||||
'type' => 'CNAME',
|
||||
));
|
||||
|
||||
if (!$dns_entries->result) {
|
||||
|
||||
if ( ! $dns_entries->result) {
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$dns_entry_to_remove = $dns_entries->result[0];
|
||||
|
||||
$results = $this->cloudflare_api_call("client/v4/zones/$zone_id/dns_records/$dns_entry_to_remove->id", 'DELETE');
|
||||
|
||||
if (is_wp_error($results)) {
|
||||
|
||||
wu_log_add('integration-cloudflare', sprintf('Failed to remove subdomain "%s" to Cloudflare. Reason: %s', $subdomain, $results->get_error_message()), LogLevel::ERROR);
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
wu_log_add('integration-cloudflare', sprintf('Removed sub-domain "%s" to Cloudflare.', $subdomain));
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end on_remove_subdomain;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sends an API call to Cloudflare.
|
||||
*
|
||||
@ -389,7 +366,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
* @param string $endpoint The endpoint to call.
|
||||
* @param string $method The HTTP verb. Defaults to GET.
|
||||
* @param array $data The date to send.
|
||||
* @return object|\WP_Error
|
||||
* @return object|\WP_Error
|
||||
*/
|
||||
protected function cloudflare_api_call($endpoint = 'client/v4/user/tokens/verify', $method = 'GET', $data = array()): object {
|
||||
|
||||
@ -397,37 +374,33 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$endpoint_url = $api_url . $endpoint;
|
||||
|
||||
$response = wp_remote_request($endpoint_url, array(
|
||||
'method' => $method,
|
||||
'body' => $method === 'GET' ? $data : wp_json_encode($data),
|
||||
'data_format' => 'body',
|
||||
'headers' => array(
|
||||
'Authorization' => sprintf('Bearer %s', defined('WU_CLOUDFLARE_API_KEY') ? WU_CLOUDFLARE_API_KEY : ''),
|
||||
'Content-Type' => 'application/json',
|
||||
),
|
||||
));
|
||||
|
||||
if (!is_wp_error($response)) {
|
||||
$response = wp_remote_request(
|
||||
$endpoint_url,
|
||||
array(
|
||||
'method' => $method,
|
||||
'body' => $method === 'GET' ? $data : wp_json_encode($data),
|
||||
'data_format' => 'body',
|
||||
'headers' => array(
|
||||
'Authorization' => sprintf('Bearer %s', defined('WU_CLOUDFLARE_API_KEY') ? WU_CLOUDFLARE_API_KEY : ''),
|
||||
'Content-Type' => 'application/json',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! is_wp_error($response)) {
|
||||
$body = wp_remote_retrieve_body($response);
|
||||
|
||||
if (wp_remote_retrieve_response_code($response) === 200) {
|
||||
|
||||
return json_decode($body);
|
||||
|
||||
} else {
|
||||
|
||||
$error_message = wp_remote_retrieve_response_message($response);
|
||||
|
||||
$response = new \WP_Error('cloudflare-error', sprintf('%s: %s', $error_message, $body));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
} // end cloudflare_api_call;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the instructions content.
|
||||
@ -438,8 +411,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
public function get_instructions() {
|
||||
|
||||
wu_get_template('wizards/host-integrations/cloudflare-instructions');
|
||||
|
||||
} // end get_instructions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of this integration.
|
||||
@ -450,8 +422,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
public function get_description() {
|
||||
|
||||
return __('Cloudflare secures and ensures the reliability of your external-facing resources such as websites, APIs, and applications. It protects your internal resources such as behind-the-firewall applications, teams, and devices. And it is your platform for developing globally-scalable applications.', 'wp-ultimo');
|
||||
|
||||
} // end get_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logo for the integration.
|
||||
@ -462,8 +433,7 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
public function get_logo() {
|
||||
|
||||
return wu_get_asset('cloudflare.svg', 'img/hosts');
|
||||
|
||||
} // end get_logo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the explainer lines for the integration.
|
||||
@ -479,19 +449,13 @@ class Cloudflare_Host_Provider extends Base_Host_Provider {
|
||||
);
|
||||
|
||||
if (is_subdomain_install()) {
|
||||
|
||||
$explainer_lines['will']['send_sub_domains'] = __('Add a new proxied subdomain to the configured CloudFlare zone whenever a new site gets created', 'wp-ultimo');
|
||||
|
||||
} else {
|
||||
|
||||
$explainer_lines['will']['subdirectory'] = __('Do nothing! The CloudFlare integration has no effect in subdirectory multisite installs such as this one', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$explainer_lines['will_not']['send_domain'] = __('Add domain mappings as new CloudFlare zones', 'wp-ultimo');
|
||||
|
||||
return $explainer_lines;
|
||||
|
||||
} // end get_explainer_lines;
|
||||
|
||||
} // end class Cloudflare_Host_Provider;
|
||||
}
|
||||
}
|
||||
|
@ -92,8 +92,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
// Add the action to sync domains SSL.
|
||||
add_action('wu_domain_manager_dns_propagation_finished', array($this, 'request_ssl'), 10, 0);
|
||||
|
||||
} // end init;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a request to Cloudways API to install SSL, after ensuring that the domain is already mapped.
|
||||
@ -105,29 +104,25 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
/**
|
||||
* If the integration is not active, bail.
|
||||
*/
|
||||
if (!$this->is_enabled()) {
|
||||
|
||||
if ( ! $this->is_enabled()) {
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$all_domains = $this->get_domains();
|
||||
|
||||
$ssl_response = $this->send_cloudways_request('/security/lets_encrypt_install', array(
|
||||
'ssl_domains' => $this->get_valid_ssl_domains($all_domains),
|
||||
));
|
||||
$ssl_response = $this->send_cloudways_request(
|
||||
'/security/lets_encrypt_install',
|
||||
array(
|
||||
'ssl_domains' => $this->get_valid_ssl_domains($all_domains),
|
||||
)
|
||||
);
|
||||
|
||||
if (is_wp_error($ssl_response)) {
|
||||
|
||||
wu_log_add('integration-cloudways', '[SSL]' . $ssl_response->get_error_message(), LogLevel::ERROR);
|
||||
|
||||
} else {
|
||||
|
||||
wu_log_add('integration-cloudways', '[SSL]' . print_r($ssl_response, true));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end request_ssl;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Picks up on tips that a given host provider is being used.
|
||||
*
|
||||
@ -138,8 +133,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
public function detect(): bool {
|
||||
|
||||
return strpos(ABSPATH, 'cloudways') !== false;
|
||||
|
||||
} // end detect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of installation fields.
|
||||
@ -177,8 +171,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
'placeholder' => __('e.g. *.test.com, test.com', 'wp-ultimo'),
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new domain is mapped.
|
||||
@ -191,8 +184,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
public function on_add_domain($domain, $site_id) {
|
||||
|
||||
$this->sync_domains();
|
||||
|
||||
} // end on_add_domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a mapped domain is removed.
|
||||
@ -205,8 +197,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
public function on_remove_domain($domain, $site_id) {
|
||||
|
||||
$this->sync_domains();
|
||||
|
||||
} // end on_remove_domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being added.
|
||||
@ -219,8 +210,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
* @return void
|
||||
*/
|
||||
public function on_add_subdomain($subdomain, $site_id) {
|
||||
|
||||
} // end on_add_subdomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being removed.
|
||||
@ -233,8 +223,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
* @return void
|
||||
*/
|
||||
public function on_remove_subdomain($subdomain, $site_id) {
|
||||
|
||||
} // end on_remove_subdomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs the domains with the Cloudways API.
|
||||
@ -246,21 +235,19 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$all_domains = $this->get_domains();
|
||||
|
||||
$alias_response = $this->send_cloudways_request('/app/manage/aliases', array(
|
||||
'aliases' => $all_domains,
|
||||
));
|
||||
$alias_response = $this->send_cloudways_request(
|
||||
'/app/manage/aliases',
|
||||
array(
|
||||
'aliases' => $all_domains,
|
||||
)
|
||||
);
|
||||
|
||||
if (is_wp_error($alias_response)) {
|
||||
|
||||
wu_log_add('integration-cloudways', '[Alias]' . $alias_response->get_error_message(), LogLevel::ERROR);
|
||||
|
||||
} else {
|
||||
|
||||
wu_log_add('integration-cloudways', '[Alias]' . print_r($alias_response, true));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end sync_domains;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns an array of valid SSL domains to be used with the Cloudways API based on a list of domains.
|
||||
*
|
||||
@ -269,17 +256,19 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
*/
|
||||
private function get_valid_ssl_domains($domains): array {
|
||||
|
||||
$ssl_domains = array_unique(array_map(function($domain) {
|
||||
$ssl_domains = array_unique(
|
||||
array_map(
|
||||
function ($domain) {
|
||||
|
||||
if (strncmp($domain, '*.', strlen('*.')) === 0) {
|
||||
if (strncmp($domain, '*.', strlen('*.')) === 0) {
|
||||
$domain = str_replace('*.', '', $domain);
|
||||
}
|
||||
|
||||
$domain = str_replace('*.', '', $domain);
|
||||
|
||||
}
|
||||
|
||||
return $domain;
|
||||
|
||||
}, $domains));
|
||||
return $domain;
|
||||
},
|
||||
$domains
|
||||
)
|
||||
);
|
||||
|
||||
$ssl_valid_domains = $this->check_domain_dns($ssl_domains, Helper::get_network_public_ip());
|
||||
|
||||
@ -289,8 +278,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
$ssl_valid_domains[] = $main_domain;
|
||||
|
||||
return array_values(array_unique(array_filter($ssl_valid_domains)));
|
||||
|
||||
} // end get_valid_ssl_domains;
|
||||
}
|
||||
/**
|
||||
* Returns an array of all domains that should be added to Cloudways.
|
||||
*
|
||||
@ -302,20 +290,15 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
$domain_list = $this->get_domain_list();
|
||||
|
||||
foreach ($domain_list as $naked_domain) {
|
||||
|
||||
if (strncmp((string) $naked_domain, 'www.', strlen('www.')) !== 0 && strncmp((string) $naked_domain, '*.', strlen('*.')) !== 0) {
|
||||
|
||||
$domain_list[] = 'www.' . $naked_domain;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
}
|
||||
|
||||
sort($domain_list);
|
||||
|
||||
return array_values(array_unique(array_filter($domain_list)));
|
||||
|
||||
} // end get_domains;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the DNS records for the domains.
|
||||
@ -334,35 +317,25 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
$response = wp_remote_get('https://dns.google/resolve?name=' . $domain_name);
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
|
||||
wu_log_add('integration-cloudways', $response->get_error_message(), LogLevel::ERROR);
|
||||
|
||||
continue;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$data = json_decode(wp_remote_retrieve_body($response), true);
|
||||
|
||||
if (isset($data['Answer'])) {
|
||||
|
||||
foreach ($data['Answer'] as $answer) {
|
||||
|
||||
if ($answer['data'] === $network_ip) {
|
||||
|
||||
$valid_domains[] = $domain_name;
|
||||
break;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $valid_domains;
|
||||
|
||||
} // end check_domain_dns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the connection with the Cloudways API.
|
||||
@ -375,14 +348,11 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
$response = $this->send_cloudways_request('/app/manage/fpm_setting', array(), 'GET');
|
||||
|
||||
if (is_wp_error($response) || wu_get_isset($response, 'error')) {
|
||||
|
||||
wp_send_json_error($response);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
wp_send_json_success($response);
|
||||
|
||||
} // end test_connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the mapped domains currently on the network
|
||||
@ -396,7 +366,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$final_domain_list = array();
|
||||
|
||||
// Prepare the query
|
||||
// Prepare the query
|
||||
$query = "SELECT domain FROM {$wpdb->base_prefix}wu_domain_mappings";
|
||||
|
||||
// Suppress errors in case the table doesn't exist.
|
||||
@ -405,22 +375,17 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
$mappings = $wpdb->get_col($query, 0); // phpcs:ignore
|
||||
|
||||
foreach ($mappings as $domain) {
|
||||
|
||||
$final_domain_list[] = $domain;
|
||||
|
||||
if (strncmp((string) $domain, 'www.', strlen('www.')) !== 0) {
|
||||
|
||||
$final_domain_list[] = "www.$domain";
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
}
|
||||
|
||||
$wpdb->suppress_errors($suppress);
|
||||
|
||||
return $final_domain_list;
|
||||
|
||||
} // end get_all_mapped_domains;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extra domains for Cloudways
|
||||
@ -435,16 +400,13 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
$extra_domains = defined('WU_CLOUDWAYS_EXTRA_DOMAINS') && WU_CLOUDWAYS_EXTRA_DOMAINS;
|
||||
|
||||
if ($extra_domains) {
|
||||
|
||||
$extra_domains_list = array_filter(array_map('trim', explode(',', (string) WU_CLOUDWAYS_EXTRA_DOMAINS)));
|
||||
|
||||
$domain_list = array_merge($domain_list, $extra_domains_list);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $domain_list;
|
||||
|
||||
} // end get_domain_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches and saves a Cloudways access token.
|
||||
@ -456,42 +418,38 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$token = get_site_transient('wu_cloudways_token');
|
||||
|
||||
if (!$token) {
|
||||
|
||||
$response = wp_remote_post('https://api.cloudways.com/api/v1/oauth/access_token', array(
|
||||
'blocking' => true,
|
||||
'method' => 'POST',
|
||||
'headers' => array(
|
||||
'cache-control' => 'no-cache',
|
||||
'content-type' => 'application/x-www-form-urlencoded',
|
||||
),
|
||||
'body' => array(
|
||||
'email' => defined('WU_CLOUDWAYS_EMAIL') ? WU_CLOUDWAYS_EMAIL : '',
|
||||
'api_key' => defined('WU_CLOUDWAYS_API_KEY') ? WU_CLOUDWAYS_API_KEY : '',
|
||||
),
|
||||
));
|
||||
|
||||
if (!is_wp_error($response)) {
|
||||
if ( ! $token) {
|
||||
$response = wp_remote_post(
|
||||
'https://api.cloudways.com/api/v1/oauth/access_token',
|
||||
array(
|
||||
'blocking' => true,
|
||||
'method' => 'POST',
|
||||
'headers' => array(
|
||||
'cache-control' => 'no-cache',
|
||||
'content-type' => 'application/x-www-form-urlencoded',
|
||||
),
|
||||
'body' => array(
|
||||
'email' => defined('WU_CLOUDWAYS_EMAIL') ? WU_CLOUDWAYS_EMAIL : '',
|
||||
'api_key' => defined('WU_CLOUDWAYS_API_KEY') ? WU_CLOUDWAYS_API_KEY : '',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! is_wp_error($response)) {
|
||||
$body = json_decode(wp_remote_retrieve_body($response), true);
|
||||
|
||||
if (isset($body['access_token'])) {
|
||||
|
||||
$expires_in = isset($body['expires_in']) ? $body['expires_in'] : 50 * MINUTE_IN_SECONDS;
|
||||
|
||||
set_site_transient('wu_cloudways_token', $body['access_token'], $expires_in);
|
||||
|
||||
$token = $body['access_token'];
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $token;
|
||||
|
||||
} // end get_cloudways_access_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the Cloudways API.
|
||||
@ -501,7 +459,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
* @param string $endpoint The API endpoint.
|
||||
* @param array $data The data to send.
|
||||
* @param string $method The HTTP verb.
|
||||
* @return object|\WP_Error
|
||||
* @return object|\WP_Error
|
||||
*/
|
||||
protected function send_cloudways_request($endpoint, $data = array(), $method = 'POST'): object {
|
||||
|
||||
@ -512,44 +470,43 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
$endpoint_url = "https://api.cloudways.com/api/v1$endpoint";
|
||||
|
||||
if ($method === 'GET') {
|
||||
|
||||
$endpoint_url = add_query_arg(array(
|
||||
'server_id' => defined('WU_CLOUDWAYS_SERVER_ID') ? WU_CLOUDWAYS_SERVER_ID : '',
|
||||
'app_id' => defined('WU_CLOUDWAYS_APP_ID') ? WU_CLOUDWAYS_APP_ID : '',
|
||||
), $endpoint_url);
|
||||
|
||||
$endpoint_url = add_query_arg(
|
||||
array(
|
||||
'server_id' => defined('WU_CLOUDWAYS_SERVER_ID') ? WU_CLOUDWAYS_SERVER_ID : '',
|
||||
'app_id' => defined('WU_CLOUDWAYS_APP_ID') ? WU_CLOUDWAYS_APP_ID : '',
|
||||
),
|
||||
$endpoint_url
|
||||
);
|
||||
} else {
|
||||
|
||||
$data['server_id'] = defined('WU_CLOUDWAYS_SERVER_ID') ? WU_CLOUDWAYS_SERVER_ID : '';
|
||||
$data['app_id'] = defined('WU_CLOUDWAYS_APP_ID') ? WU_CLOUDWAYS_APP_ID : '';
|
||||
$data['ssl_email'] = defined('WU_CLOUDWAYS_EMAIL') ? WU_CLOUDWAYS_EMAIL : '';
|
||||
$data['wild_card'] = false;
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
$response = wp_remote_post($endpoint_url, array(
|
||||
'blocking' => true,
|
||||
'method' => $method,
|
||||
'timeout' => 45,
|
||||
'body' => $data,
|
||||
'headers' => array(
|
||||
'cache-control' => 'no-cache',
|
||||
'content-type' => 'application/x-www-form-urlencoded',
|
||||
'authorization' => "Bearer $token",
|
||||
),
|
||||
));
|
||||
$response = wp_remote_post(
|
||||
$endpoint_url,
|
||||
array(
|
||||
'blocking' => true,
|
||||
'method' => $method,
|
||||
'timeout' => 45,
|
||||
'body' => $data,
|
||||
'headers' => array(
|
||||
'cache-control' => 'no-cache',
|
||||
'content-type' => 'application/x-www-form-urlencoded',
|
||||
'authorization' => "Bearer $token",
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
|
||||
return $response;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$response_data = wp_remote_retrieve_body($response);
|
||||
|
||||
return json_decode($response_data);
|
||||
|
||||
} // end send_cloudways_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the instructions content.
|
||||
@ -560,8 +517,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
public function get_instructions() {
|
||||
|
||||
wu_get_template('wizards/host-integrations/cloudways-instructions');
|
||||
|
||||
} // end get_instructions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of this integration.
|
||||
@ -572,8 +528,7 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
public function get_description() {
|
||||
|
||||
return __('Focus on your business and avoid all the web hosting hassles. Our managed hosting guarantees unmatched performance, reliability and choice with 24/7 support that acts as your extended team, making Cloudways an ultimate choice for growing agencies and e-commerce businesses.', 'wp-ultimo');
|
||||
|
||||
} // end get_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logo for the integration.
|
||||
@ -584,7 +539,5 @@ class Cloudways_Host_Provider extends Base_Host_Provider {
|
||||
public function get_logo() {
|
||||
|
||||
return wu_get_asset('cloudways.png', 'img/hosts');
|
||||
|
||||
} // end get_logo;
|
||||
|
||||
} // end class Cloudways_Host_Provider;
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
*/
|
||||
protected $optional_constants = array(
|
||||
'WU_CPANEL_PORT',
|
||||
'WU_CPANEL_ROOT_DIR'
|
||||
'WU_CPANEL_ROOT_DIR',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -90,18 +90,17 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
protected $api = null;
|
||||
|
||||
/**
|
||||
* Picks up on tips that a given host provider is being used.
|
||||
*
|
||||
* We use this to suggest that the user should activate an integration module.
|
||||
* Unfortunately, we don't have a good method of detecting if someone is running from cPanel.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
* Picks up on tips that a given host provider is being used.
|
||||
*
|
||||
* We use this to suggest that the user should activate an integration module.
|
||||
* Unfortunately, we don't have a good method of detecting if someone is running from cPanel.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function detect(): bool {
|
||||
|
||||
return false;
|
||||
|
||||
} // end detect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of installation fields.
|
||||
@ -136,8 +135,7 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
'value' => '/public_html',
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new domain is mapped.
|
||||
@ -153,15 +151,18 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
$root_dir = defined('WU_CPANEL_ROOT_DIR') && WU_CPANEL_ROOT_DIR ? WU_CPANEL_ROOT_DIR : '/public_html';
|
||||
|
||||
// Send Request
|
||||
$results = $this->load_api()->api2('AddonDomain', 'addaddondomain', array(
|
||||
'dir' => $root_dir,
|
||||
'newdomain' => $domain,
|
||||
'subdomain' => $this->get_subdomain($domain),
|
||||
));
|
||||
$results = $this->load_api()->api2(
|
||||
'AddonDomain',
|
||||
'addaddondomain',
|
||||
array(
|
||||
'dir' => $root_dir,
|
||||
'newdomain' => $domain,
|
||||
'subdomain' => $this->get_subdomain($domain),
|
||||
)
|
||||
);
|
||||
|
||||
$this->log_calls($results);
|
||||
|
||||
} // end on_add_domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a mapped domain is removed.
|
||||
@ -174,14 +175,17 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
public function on_remove_domain($domain, $site_id) {
|
||||
|
||||
// Send Request
|
||||
$results = $this->load_api()->api2('AddonDomain', 'deladdondomain', array(
|
||||
'domain' => $domain,
|
||||
'subdomain' => $this->get_subdomain($domain) . '_' . $this->get_site_url(),
|
||||
));
|
||||
$results = $this->load_api()->api2(
|
||||
'AddonDomain',
|
||||
'deladdondomain',
|
||||
array(
|
||||
'domain' => $domain,
|
||||
'subdomain' => $this->get_subdomain($domain) . '_' . $this->get_site_url(),
|
||||
)
|
||||
);
|
||||
|
||||
$this->log_calls($results);
|
||||
|
||||
} // end on_remove_domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being added.
|
||||
@ -203,16 +207,19 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
$rootdomain = str_replace($subdomain . '.', '', $this->get_site_url($site_id));
|
||||
|
||||
// Send Request
|
||||
$results = $this->load_api()->api2('SubDomain', 'addsubdomain', array(
|
||||
'dir' => $root_dir,
|
||||
'domain' => $subdomain,
|
||||
'rootdomain' => $rootdomain,
|
||||
));
|
||||
$results = $this->load_api()->api2(
|
||||
'SubDomain',
|
||||
'addsubdomain',
|
||||
array(
|
||||
'dir' => $root_dir,
|
||||
'domain' => $subdomain,
|
||||
'rootdomain' => $rootdomain,
|
||||
)
|
||||
);
|
||||
|
||||
// Check the results
|
||||
$this->log_calls($results);
|
||||
|
||||
} // end on_add_subdomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being removed.
|
||||
@ -224,7 +231,7 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
* @param int $site_id ID of the site that is receiving that mapping.
|
||||
* @return void
|
||||
*/
|
||||
public function on_remove_subdomain($subdomain, $site_id) {} // end on_remove_subdomain;
|
||||
public function on_remove_subdomain($subdomain, $site_id) {}
|
||||
|
||||
/**
|
||||
* Load the CPanel API.
|
||||
@ -235,7 +242,6 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
public function load_api() {
|
||||
|
||||
if ($this->api === null) {
|
||||
|
||||
$username = defined('WU_CPANEL_USERNAME') ? WU_CPANEL_USERNAME : '';
|
||||
$password = defined('WU_CPANEL_PASSWORD') ? WU_CPANEL_PASSWORD : '';
|
||||
$host = defined('WU_CPANEL_HOST') ? WU_CPANEL_HOST : '';
|
||||
@ -245,12 +251,10 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
* Set up the API.
|
||||
*/
|
||||
$this->api = new CPanel_API($username, $password, preg_replace('#^https?://#', '', (string) $host), $port);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $this->api;
|
||||
|
||||
} // end load_api;
|
||||
}
|
||||
/**
|
||||
* Returns the Site URL.
|
||||
*
|
||||
@ -260,8 +264,7 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
public function get_site_url($site_id = null): string {
|
||||
|
||||
return trim(preg_replace('#^https?://#', '', get_site_url($site_id)), '/');
|
||||
|
||||
} // end get_site_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sub-domain version of the domain.
|
||||
@ -274,18 +277,15 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
public function get_subdomain($domain, $mapped_domain = true) {
|
||||
|
||||
if ($mapped_domain === false) {
|
||||
|
||||
$domain_parts = explode('.', $domain);
|
||||
|
||||
return array_shift($domain_parts);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$subdomain = str_replace(array('.', '/'), '', $domain);
|
||||
|
||||
return $subdomain;
|
||||
|
||||
} // end get_subdomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the results of the calls for debugging purposes
|
||||
@ -297,18 +297,13 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
public function log_calls($results) {
|
||||
|
||||
if (is_object($results->cpanelresult->data)) {
|
||||
|
||||
return wu_log_add('integration-cpanel', $results->cpanelresult->data->reason);
|
||||
|
||||
} elseif (!isset($results->cpanelresult->data[0])) {
|
||||
|
||||
} elseif ( ! isset($results->cpanelresult->data[0])) {
|
||||
return wu_log_add('integration-cpanel', __('Unexpected error ocurred trying to sync domains with CPanel', 'wp-ultimo'), LogLevel::ERROR);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return wu_log_add('integration-cpanel', $results->cpanelresult->data[0]->reason);
|
||||
|
||||
} // end log_calls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of this integration.
|
||||
@ -319,8 +314,7 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
public function get_description() {
|
||||
|
||||
return __('cPanel is the management panel being used on a large number of shared and dedicated hosts across the globe.', 'wp-ultimo');
|
||||
|
||||
} // end get_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logo for the integration.
|
||||
@ -331,8 +325,7 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
public function get_logo() {
|
||||
|
||||
return wu_get_asset('cpanel.svg', 'img/hosts');
|
||||
|
||||
} // end get_logo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the connection with the Cloudflare API.
|
||||
@ -346,17 +339,14 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$this->log_calls($results);
|
||||
|
||||
if (isset($results->cpanelresult->data) && !isset($results->cpanelresult->error)) {
|
||||
|
||||
if (isset($results->cpanelresult->data) && ! isset($results->cpanelresult->error)) {
|
||||
wp_send_json_success($results);
|
||||
|
||||
exit;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
wp_send_json_error($results);
|
||||
|
||||
} // end test_connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the explainer lines for the integration.
|
||||
@ -374,13 +364,9 @@ class CPanel_Host_Provider extends Base_Host_Provider {
|
||||
);
|
||||
|
||||
if (is_subdomain_install()) {
|
||||
|
||||
$explainer_lines['will']['send_sub_domains'] = __('Add a new SubDomain on cPanel whenever a new site gets created on your network', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $explainer_lines;
|
||||
|
||||
} // end get_explainer_lines;
|
||||
|
||||
} // end class CPanel_Host_Provider;
|
||||
}
|
||||
}
|
||||
|
@ -77,8 +77,7 @@ class Gridpane_Host_Provider extends Base_Host_Provider {
|
||||
public function detect() {
|
||||
|
||||
return defined('GRIDPANE') && GRIDPANE;
|
||||
|
||||
} // end detect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables this integration.
|
||||
@ -93,8 +92,7 @@ class Gridpane_Host_Provider extends Base_Host_Provider {
|
||||
$success = \WP_Ultimo\Helpers\WP_Config::get_instance()->revert('SUNRISE');
|
||||
|
||||
parent::enable();
|
||||
|
||||
} // end enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the GridPane API.
|
||||
@ -112,28 +110,26 @@ class Gridpane_Host_Provider extends Base_Host_Provider {
|
||||
'timeout' => 45,
|
||||
'blocking' => true,
|
||||
'method' => $method,
|
||||
'body' => array_merge(array(
|
||||
'api_token' => WU_GRIDPANE_API_KEY,
|
||||
), $data)
|
||||
'body' => array_merge(
|
||||
array(
|
||||
'api_token' => WU_GRIDPANE_API_KEY,
|
||||
),
|
||||
$data
|
||||
),
|
||||
);
|
||||
|
||||
$response = wp_remote_request("https://my.gridpane.com/api/{$endpoint}", $post_fields);
|
||||
|
||||
if (!is_wp_error($response)) {
|
||||
|
||||
if ( ! is_wp_error($response)) {
|
||||
$body = json_decode(wp_remote_retrieve_body($response), true);
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
|
||||
return $body;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
} // end send_gridpane_api_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new domain is mapped.
|
||||
@ -145,13 +141,15 @@ class Gridpane_Host_Provider extends Base_Host_Provider {
|
||||
*/
|
||||
public function on_add_domain($domain, $site_id) {
|
||||
|
||||
return $this->send_gridpane_api_request('application/add-domain', array(
|
||||
'server_ip' => WU_GRIDPANE_SERVER_ID,
|
||||
'site_url' => WU_GRIDPANE_APP_ID,
|
||||
'domain_url' => $domain
|
||||
));
|
||||
|
||||
} // end on_add_domain;
|
||||
return $this->send_gridpane_api_request(
|
||||
'application/add-domain',
|
||||
array(
|
||||
'server_ip' => WU_GRIDPANE_SERVER_ID,
|
||||
'site_url' => WU_GRIDPANE_APP_ID,
|
||||
'domain_url' => $domain,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a mapped domain is removed.
|
||||
@ -163,13 +161,15 @@ class Gridpane_Host_Provider extends Base_Host_Provider {
|
||||
*/
|
||||
public function on_remove_domain($domain, $site_id) {
|
||||
|
||||
return $this->send_gridpane_api_request('application/delete-domain', array(
|
||||
'server_ip' => WU_GRIDPANE_SERVER_ID,
|
||||
'site_url' => WU_GRIDPANE_APP_ID,
|
||||
'domain_url' => $domain
|
||||
));
|
||||
|
||||
} // end on_remove_domain;
|
||||
return $this->send_gridpane_api_request(
|
||||
'application/delete-domain',
|
||||
array(
|
||||
'server_ip' => WU_GRIDPANE_SERVER_ID,
|
||||
'site_url' => WU_GRIDPANE_APP_ID,
|
||||
'domain_url' => $domain,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being added.
|
||||
@ -181,7 +181,7 @@ class Gridpane_Host_Provider extends Base_Host_Provider {
|
||||
* @param int $site_id ID of the site that is receiving that mapping.
|
||||
* @return void
|
||||
*/
|
||||
public function on_add_subdomain($subdomain, $site_id) {} // end on_add_subdomain;
|
||||
public function on_add_subdomain($subdomain, $site_id) {}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being removed.
|
||||
@ -193,7 +193,7 @@ class Gridpane_Host_Provider extends Base_Host_Provider {
|
||||
* @param int $site_id ID of the site that is receiving that mapping.
|
||||
* @return void
|
||||
*/
|
||||
public function on_remove_subdomain($subdomain, $site_id) {} // end on_remove_subdomain;
|
||||
public function on_remove_subdomain($subdomain, $site_id) {}
|
||||
|
||||
/**
|
||||
* Tests the connection with the Gridpane API.
|
||||
@ -206,26 +206,27 @@ class Gridpane_Host_Provider extends Base_Host_Provider {
|
||||
$results = $this->on_remove_domain('test.com', false);
|
||||
|
||||
if (wu_get_isset($results, 'message') === 'This action is unauthorized.') {
|
||||
|
||||
wp_send_json_error(array(
|
||||
'error' => __('We were not able to successfully establish a connection.', 'wp-ultimo'),
|
||||
));
|
||||
|
||||
} // end if;
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'error' => __('We were not able to successfully establish a connection.', 'wp-ultimo'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (is_wp_error($results)) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'error' => __('We were not able to successfully establish a connection.', 'wp-ultimo'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
wp_send_json_error(array(
|
||||
'error' => __('We were not able to successfully establish a connection.', 'wp-ultimo'),
|
||||
));
|
||||
|
||||
} // end if;
|
||||
|
||||
wp_send_json_success(array(
|
||||
'success' => __('Connection successfully established.', 'wp-ultimo'),
|
||||
));
|
||||
|
||||
} // end test_connection;
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'success' => __('Connection successfully established.', 'wp-ultimo'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the instructions content.
|
||||
@ -236,8 +237,7 @@ class Gridpane_Host_Provider extends Base_Host_Provider {
|
||||
public function get_instructions() {
|
||||
|
||||
wu_get_template('wizards/host-integrations/gridpane-instructions');
|
||||
|
||||
} // end get_instructions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of this integration.
|
||||
@ -248,8 +248,7 @@ class Gridpane_Host_Provider extends Base_Host_Provider {
|
||||
public function get_description() {
|
||||
|
||||
return __("GridPane is the world's first hosting control panel built exclusively for serious WordPress professionals.", 'wp-ultimo');
|
||||
|
||||
} // end get_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logo for the integration.
|
||||
@ -260,7 +259,5 @@ class Gridpane_Host_Provider extends Base_Host_Provider {
|
||||
public function get_logo() {
|
||||
|
||||
return wu_get_asset('gridpane.png', 'img/hosts');
|
||||
|
||||
} // end get_logo;
|
||||
|
||||
} // end class Gridpane_Host_Provider;
|
||||
}
|
||||
}
|
||||
|
@ -70,17 +70,16 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
);
|
||||
|
||||
/**
|
||||
* Picks up on tips that a given host provider is being used.
|
||||
*
|
||||
* We use this to suggest that the user should activate an integration module.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
* Picks up on tips that a given host provider is being used.
|
||||
*
|
||||
* We use this to suggest that the user should activate an integration module.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function detect(): bool {
|
||||
|
||||
return strpos(ABSPATH, 'runcloud') !== false;
|
||||
|
||||
} // end detect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of installation fields.
|
||||
@ -112,8 +111,7 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
'placeholder' => __('e.g. 940288', 'wp-ultimo'),
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new domain is mapped.
|
||||
@ -127,40 +125,35 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$success = false;
|
||||
|
||||
$response = $this->send_runcloud_request($this->get_runcloud_base_url('domains'), array(
|
||||
'name' => $domain,
|
||||
'www' => true,
|
||||
'redirection' => 'non-www'
|
||||
), 'POST');
|
||||
$response = $this->send_runcloud_request(
|
||||
$this->get_runcloud_base_url('domains'),
|
||||
array(
|
||||
'name' => $domain,
|
||||
'www' => true,
|
||||
'redirection' => 'non-www',
|
||||
),
|
||||
'POST'
|
||||
);
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
|
||||
wu_log_add('integration-runcloud', $response->get_error_message(), LogLevel::ERROR);
|
||||
|
||||
} else {
|
||||
|
||||
$success = true; // At least one of the calls was successful;
|
||||
|
||||
wu_log_add('integration-runcloud', wp_remote_retrieve_body($response));
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only redeploy SSL if at least one of the domains were successfully added
|
||||
*/
|
||||
if ($success) {
|
||||
|
||||
$ssl_id = $this->get_runcloud_ssl_id();
|
||||
|
||||
if ($ssl_id) {
|
||||
|
||||
$this->redeploy_runcloud_ssl($ssl_id);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end on_add_domain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a mapped domain is removed.
|
||||
@ -174,25 +167,18 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$domain_id = $this->get_runcloud_domain_id($domain);
|
||||
|
||||
if (!$domain_id) {
|
||||
|
||||
if ( ! $domain_id) {
|
||||
wu_log_add('integration-runcloud', __('Domain name not found on runcloud', 'wp-ultimo'));
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$response = $this->send_runcloud_request($this->get_runcloud_base_url("domains/$domain_id"), array(), 'DELETE');
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
|
||||
wu_log_add('integration-runcloud', $response->get_error_message(), LogLevel::ERROR);
|
||||
|
||||
} else {
|
||||
|
||||
wu_log_add('integration-runcloud', wp_remote_retrieve_body($response));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end on_remove_domain;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being added.
|
||||
@ -204,7 +190,7 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
* @param int $site_id ID of the site that is receiving that mapping.
|
||||
* @return void
|
||||
*/
|
||||
public function on_add_subdomain($subdomain, $site_id) {} // end on_add_subdomain;
|
||||
public function on_add_subdomain($subdomain, $site_id) {}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being removed.
|
||||
@ -216,7 +202,7 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
* @param int $site_id ID of the site that is receiving that mapping.
|
||||
* @return void
|
||||
*/
|
||||
public function on_remove_subdomain($subdomain, $site_id) {} // end on_remove_subdomain;
|
||||
public function on_remove_subdomain($subdomain, $site_id) {}
|
||||
|
||||
/**
|
||||
* Tests the connection with the RunCloud API.
|
||||
@ -229,16 +215,11 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
$response = $this->send_runcloud_request($this->get_runcloud_base_url('domains'), array(), 'GET');
|
||||
|
||||
if (is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 200) {
|
||||
|
||||
wp_send_json_error($response);
|
||||
|
||||
} else {
|
||||
|
||||
wp_send_json_success($this->maybe_return_runcloud_body($response));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end test_connection;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base domain API url to our calls.
|
||||
@ -254,8 +235,7 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
$appid = defined('WU_RUNCLOUD_APP_ID') ? WU_RUNCLOUD_APP_ID : '';
|
||||
|
||||
return "https://manage.runcloud.io/api/v2/servers/{$serverid}/webapps/{$appid}/{$path}";
|
||||
|
||||
} // end get_runcloud_base_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the request to a given runcloud URL with a given body.
|
||||
@ -272,19 +252,21 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$password = defined('WU_RUNCLOUD_API_SECRET') ? WU_RUNCLOUD_API_SECRET : '';
|
||||
|
||||
$response = wp_remote_request($url, array(
|
||||
'timeout' => 100,
|
||||
'redirection' => 5,
|
||||
'body' => $data,
|
||||
'method' => $method,
|
||||
'headers' => array(
|
||||
'Authorization' => 'Basic ' . base64_encode($username . ':' . $password),
|
||||
),
|
||||
));
|
||||
$response = wp_remote_request(
|
||||
$url,
|
||||
array(
|
||||
'timeout' => 100,
|
||||
'redirection' => 5,
|
||||
'body' => $data,
|
||||
'method' => $method,
|
||||
'headers' => array(
|
||||
'Authorization' => 'Basic ' . base64_encode($username . ':' . $password),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
return $response;
|
||||
|
||||
} // end send_runcloud_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Treats the response, maybe returning the json decoded version
|
||||
@ -296,16 +278,11 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
public function maybe_return_runcloud_body($response) {
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
|
||||
return $response->get_error_message();
|
||||
|
||||
} else {
|
||||
|
||||
return json_decode(wp_remote_retrieve_body($response));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end maybe_return_runcloud_body;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the RunCloud.io domain id to remove.
|
||||
@ -320,56 +297,42 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$list = $this->maybe_return_runcloud_body($domains_list);
|
||||
|
||||
if (is_object($list) && !empty($list->data)) {
|
||||
|
||||
if (is_object($list) && ! empty($list->data)) {
|
||||
foreach ($list->data as $remote_domain) {
|
||||
|
||||
if ($remote_domain->name === $domain) {
|
||||
|
||||
return $remote_domain->id;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
} // end get_runcloud_domain_id;
|
||||
/**
|
||||
* Checks if RunCloud has a SSL cert installed or not, and returns the ID.
|
||||
*
|
||||
* @since 1.10.4
|
||||
* @return bool|int
|
||||
*/
|
||||
public function get_runcloud_ssl_id() {
|
||||
}
|
||||
/**
|
||||
* Checks if RunCloud has a SSL cert installed or not, and returns the ID.
|
||||
*
|
||||
* @since 1.10.4
|
||||
* @return bool|int
|
||||
*/
|
||||
public function get_runcloud_ssl_id() {
|
||||
|
||||
$ssl_id = false;
|
||||
|
||||
$response = $this->send_runcloud_request($this->get_runcloud_base_url('ssl'), array(), 'GET');
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
|
||||
wu_log_add('integration-runcloud', $response->get_error_message(), LogLevel::ERROR);
|
||||
|
||||
} else {
|
||||
|
||||
$data = $this->maybe_return_runcloud_body($response);
|
||||
|
||||
wu_log_add('integration-runcloud', json_encode($data));
|
||||
|
||||
if (property_exists($data, 'id')) {
|
||||
|
||||
$ssl_id = $data->id;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
|
||||
return $ssl_id;
|
||||
|
||||
} // end get_runcloud_ssl_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redeploys the SSL cert when a new domain is added.
|
||||
@ -383,16 +346,11 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
$response = $this->send_runcloud_request($this->get_runcloud_base_url("ssl/$ssl_id"), array(), 'PUT');
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
|
||||
wu_log_add('integration-runcloud', $response->get_error_message(), LogLevel::ERROR);
|
||||
|
||||
} else {
|
||||
|
||||
wu_log_add('integration-runcloud', wp_remote_retrieve_body($response));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end redeploy_runcloud_ssl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the instructions content.
|
||||
@ -403,8 +361,7 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
public function get_instructions() {
|
||||
|
||||
wu_get_template('wizards/host-integrations/runcloud-instructions');
|
||||
|
||||
} // end get_instructions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of this integration.
|
||||
@ -415,8 +372,7 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
public function get_description() {
|
||||
|
||||
return __('With RunCloud, you don’t need to be a Linux expert to build a website powered by DigitalOcean, AWS, or Google Cloud. Use our graphical interface and build a business on the cloud affordably.', 'wp-ultimo');
|
||||
|
||||
} // end get_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logo for the integration.
|
||||
@ -427,7 +383,5 @@ class Runcloud_Host_Provider extends Base_Host_Provider {
|
||||
public function get_logo() {
|
||||
|
||||
return wu_get_asset('runcloud.svg', 'img/hosts');
|
||||
|
||||
} // end get_logo;
|
||||
|
||||
} // end class Runcloud_Host_Provider;
|
||||
}
|
||||
}
|
||||
|
@ -79,8 +79,7 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
public function detect() {
|
||||
|
||||
return defined('WP_PLUGIN_DIR') && preg_match('/\/srv\/users\/(.+)\/apps\/(.+)/', (string) WP_PLUGIN_DIR);
|
||||
|
||||
} // end detect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of installation fields.
|
||||
@ -107,8 +106,7 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
'placeholder' => __('e.g. 940288', 'wp-ultimo'),
|
||||
),
|
||||
);
|
||||
|
||||
} // end get_fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new domain is mapped.
|
||||
@ -123,19 +121,19 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
$current_domain_list = $this->get_server_pilot_domains();
|
||||
|
||||
if ($current_domain_list && is_array($current_domain_list)) {
|
||||
|
||||
$this->send_server_pilot_api_request('', array(
|
||||
'domains' => array_merge($current_domain_list, array($domain, 'www.' . $domain)),
|
||||
));
|
||||
$this->send_server_pilot_api_request(
|
||||
'',
|
||||
array(
|
||||
'domains' => array_merge($current_domain_list, array($domain, 'www.' . $domain)),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Makes sure autoSSL is always on
|
||||
*/
|
||||
$this->turn_server_pilot_auto_ssl_on();
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end on_add_domain;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a mapped domain is removed.
|
||||
@ -156,13 +154,14 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
*/
|
||||
$current_domain_list = array_filter($current_domain_list, fn($remote_domain) => $remote_domain !== $domain && $remote_domain !== 'www.' . $domain);
|
||||
|
||||
$this->send_server_pilot_api_request('', array(
|
||||
'domains' => $current_domain_list
|
||||
));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end on_remove_domain;
|
||||
$this->send_server_pilot_api_request(
|
||||
'',
|
||||
array(
|
||||
'domains' => $current_domain_list,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being added.
|
||||
@ -179,19 +178,19 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
$current_domain_list = $this->get_server_pilot_domains();
|
||||
|
||||
if ($current_domain_list && is_array($current_domain_list)) {
|
||||
|
||||
$this->send_server_pilot_api_request('', array(
|
||||
'domains' => array_merge($current_domain_list, array($subdomain)),
|
||||
));
|
||||
$this->send_server_pilot_api_request(
|
||||
'',
|
||||
array(
|
||||
'domains' => array_merge($current_domain_list, array($subdomain)),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Makes sure autoSSL is always on
|
||||
*/
|
||||
$this->turn_server_pilot_auto_ssl_on();
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end on_add_subdomain;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being removed.
|
||||
@ -203,7 +202,7 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
* @param int $site_id ID of the site that is receiving that mapping.
|
||||
* @return void
|
||||
*/
|
||||
public function on_remove_subdomain($subdomain, $site_id) {} // end on_remove_subdomain;
|
||||
public function on_remove_subdomain($subdomain, $site_id) {}
|
||||
|
||||
/**
|
||||
* Sends a request to ServerPilot, with the right API key.
|
||||
@ -229,19 +228,16 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$response = wp_remote_request('https://api.serverpilot.io/v1/apps/' . WU_SERVER_PILOT_APP_ID . $endpoint, $post_fields);
|
||||
|
||||
if (!is_wp_error($response)) {
|
||||
|
||||
if ( ! is_wp_error($response)) {
|
||||
$body = json_decode(wp_remote_retrieve_body($response), true);
|
||||
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
return $body;
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
} // end send_server_pilot_api_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure ServerPilot autoSSL is always on, when possible.
|
||||
@ -251,11 +247,13 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
*/
|
||||
public function turn_server_pilot_auto_ssl_on() {
|
||||
|
||||
return $this->send_server_pilot_api_request('/ssl', array(
|
||||
'auto' => true,
|
||||
));
|
||||
|
||||
} // end turn_server_pilot_auto_ssl_on;
|
||||
return $this->send_server_pilot_api_request(
|
||||
'/ssl',
|
||||
array(
|
||||
'auto' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current list of domains added on Server Pilot.
|
||||
@ -268,10 +266,8 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
$app_info = $this->send_server_pilot_api_request('', array(), 'GET');
|
||||
|
||||
if (isset($app_info['data']['domains'])) {
|
||||
|
||||
return $app_info['data']['domains'];
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* Log response so we can see what went wrong
|
||||
@ -281,8 +277,7 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
wu_log_add('integration-serverpilot', sprintf(__('An error occurred while trying to get the current list of domains: %s', 'wp-ultimo'), json_encode($app_info)), LogLevel::ERROR);
|
||||
|
||||
return false;
|
||||
|
||||
} // end get_server_pilot_domains;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the connection with the ServerPilot API.
|
||||
@ -295,14 +290,11 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
$response = $this->send_server_pilot_api_request('', array(), 'GET');
|
||||
|
||||
if (is_wp_error($response) || wu_get_isset($response, 'error')) {
|
||||
|
||||
wp_send_json_error($response);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
wp_send_json_success($response);
|
||||
|
||||
} // end test_connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the instructions content.
|
||||
@ -313,8 +305,7 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
public function get_instructions() {
|
||||
|
||||
wu_get_template('wizards/host-integrations/serverpilot-instructions');
|
||||
|
||||
} // end get_instructions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of this integration.
|
||||
@ -325,8 +316,7 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
public function get_description() {
|
||||
|
||||
return __('ServerPilot is a cloud service for hosting WordPress and other PHP websites on servers at DigitalOcean, Amazon, Google, or any other server provider. You can think of ServerPilot as a modern, centralized hosting control panel.', 'wp-ultimo');
|
||||
|
||||
} // end get_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logo for the integration.
|
||||
@ -337,7 +327,5 @@ class ServerPilot_Host_Provider extends Base_Host_Provider {
|
||||
public function get_logo() {
|
||||
|
||||
return wu_get_asset('serverpilot.svg', 'img/hosts');
|
||||
|
||||
} // end get_logo;
|
||||
|
||||
} // end class ServerPilot_Host_Provider;
|
||||
}
|
||||
}
|
||||
|
@ -78,8 +78,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider {
|
||||
public function detect() {
|
||||
|
||||
return (defined('WPE_APIKEY') && WPE_APIKEY) || (defined('WPE_API') && WPE_API);
|
||||
|
||||
} // end detect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to load dependencies.
|
||||
@ -90,15 +89,12 @@ class WPEngine_Host_Provider extends Base_Host_Provider {
|
||||
public function load_dependencies() {
|
||||
|
||||
// if WP Engine is not defined, then return
|
||||
if (!defined('WPE_PLUGIN_DIR') || !is_readable(WPE_PLUGIN_DIR . '/class-wpeapi.php')) {
|
||||
|
||||
if ( ! defined('WPE_PLUGIN_DIR') || ! is_readable(WPE_PLUGIN_DIR . '/class-wpeapi.php')) {
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
include_once WPE_PLUGIN_DIR . '/class-wpeapi.php';
|
||||
|
||||
} // end load_dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new domain is mapped.
|
||||
@ -117,8 +113,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider {
|
||||
$api->set_arg('domain', $domain);
|
||||
|
||||
$api->get();
|
||||
|
||||
} // end on_add_domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a mapped domain is removed.
|
||||
@ -137,8 +132,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider {
|
||||
$api->set_arg('domain', $domain);
|
||||
|
||||
$api->get();
|
||||
|
||||
} // end on_remove_domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being added.
|
||||
@ -153,8 +147,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider {
|
||||
public function on_add_subdomain($subdomain, $site_id) {
|
||||
|
||||
$this->on_add_domain($subdomain, $site_id);
|
||||
|
||||
} // end on_add_subdomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being removed.
|
||||
@ -169,8 +162,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider {
|
||||
public function on_remove_subdomain($subdomain, $site_id) {
|
||||
|
||||
$this->on_remove_domain($subdomain, $site_id);
|
||||
|
||||
} // end on_remove_subdomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of this integration.
|
||||
@ -185,8 +177,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider {
|
||||
$description .= '<br><br><b>' . __('We recommend to enter in contact with WP Engine support to ask for a Wildcard domain if you are using a subdomain install.', 'wp-ultimo') . '</b>';
|
||||
|
||||
return $description;
|
||||
|
||||
} // end get_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logo for the integration.
|
||||
@ -197,8 +188,7 @@ class WPEngine_Host_Provider extends Base_Host_Provider {
|
||||
public function get_logo() {
|
||||
|
||||
return wu_get_asset('wpengine.svg', 'img/hosts');
|
||||
|
||||
} // end get_logo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the connection with the WP Engine API.
|
||||
@ -215,15 +205,9 @@ class WPEngine_Host_Provider extends Base_Host_Provider {
|
||||
$results = $api->get();
|
||||
|
||||
if (is_wp_error($results)) {
|
||||
|
||||
wp_send_json_error($results->get_error_message());
|
||||
|
||||
} else {
|
||||
|
||||
wp_send_json_success($results);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end test_connection;
|
||||
|
||||
} // end class WPEngine_Host_Provider;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,8 +83,7 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider {
|
||||
* This is needed because, from our tests, WPMU DEV hosting takes a while to get the SSL certificate.
|
||||
*/
|
||||
add_filter('wu_async_process_domain_stage_max_tries', array($this, 'ssl_tries'), 10, 2);
|
||||
|
||||
} // end init;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the number of tries to get the SSL certificate.
|
||||
@ -96,21 +95,16 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider {
|
||||
*/
|
||||
public function ssl_tries($max_tries, $domain) {
|
||||
|
||||
if (!$this->is_enabled()) {
|
||||
|
||||
if ( ! $this->is_enabled()) {
|
||||
return $max_tries;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
if ('checking-ssl-cert' === $domain->get_stage()) {
|
||||
|
||||
$max_tries = 10;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $max_tries;
|
||||
|
||||
} // end ssl_tries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Picks up on tips that a given host provider is being used.
|
||||
@ -123,8 +117,7 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider {
|
||||
public function detect() {
|
||||
|
||||
return defined('WPMUDEV_HOSTING_SITE_ID') && WPMUDEV_HOSTING_SITE_ID;
|
||||
|
||||
} // end detect;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new domain is mapped.
|
||||
@ -143,30 +136,29 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider {
|
||||
$domains = array($domain);
|
||||
|
||||
if (strncmp($domain, 'www.', strlen('www.')) !== 0) {
|
||||
|
||||
$domains[] = "www.$domain";
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
foreach ($domains as $_domain) {
|
||||
|
||||
$response = wp_remote_post("https://premium.wpmudev.org/api/hosting/v1/$site_id/domains", array(
|
||||
'timeout' => 50,
|
||||
'body' => array(
|
||||
'domain' => $_domain,
|
||||
'site_id' => $site_id,
|
||||
),
|
||||
'headers' => array(
|
||||
'Authorization' => $api_key,
|
||||
),
|
||||
));
|
||||
$response = wp_remote_post(
|
||||
"https://premium.wpmudev.org/api/hosting/v1/$site_id/domains",
|
||||
array(
|
||||
'timeout' => 50,
|
||||
'body' => array(
|
||||
'domain' => $_domain,
|
||||
'site_id' => $site_id,
|
||||
),
|
||||
'headers' => array(
|
||||
'Authorization' => $api_key,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
|
||||
// translators: The %s placeholder will be replaced with the domain name.
|
||||
wu_log_add('integration-wpmudev', sprintf(__('An error occurred while trying to add the custom domain %s to WPMU Dev hosting.', 'wp-ultimo'), $_domain), LogLevel::ERROR);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$body = json_decode(wp_remote_retrieve_body($response));
|
||||
|
||||
@ -174,17 +166,13 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
// translators: The %1$s will be replaced with the domain name and %2$s is the error message.
|
||||
wu_log_add('integration-wpmudev', sprintf(__('An error occurred while trying to add the custom domain %1$s to WPMU Dev hosting: %2$s', 'wp-ultimo'), $_domain, $body->message->message), LogLevel::ERROR);
|
||||
|
||||
} else {
|
||||
|
||||
// translators: The %s placeholder will be replaced with the domain name.
|
||||
wu_log_add('integration-wpmudev', sprintf(__('Domain %s added to WPMU Dev hosting successfully.', 'wp-ultimo'), $_domain));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end on_add_domain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a mapped domain is removed.
|
||||
@ -202,8 +190,7 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider {
|
||||
*
|
||||
* @todo Implement support to removing domains when a mapping is removed.
|
||||
*/
|
||||
|
||||
} // end on_remove_domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being added.
|
||||
@ -215,7 +202,7 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider {
|
||||
* @param int $site_id ID of the site that is receiving that mapping.
|
||||
* @return void
|
||||
*/
|
||||
public function on_add_subdomain($subdomain, $site_id) {} // end on_add_subdomain;
|
||||
public function on_add_subdomain($subdomain, $site_id) {}
|
||||
|
||||
/**
|
||||
* This method gets called when a new subdomain is being removed.
|
||||
@ -227,7 +214,7 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider {
|
||||
* @param int $site_id ID of the site that is receiving that mapping.
|
||||
* @return void
|
||||
*/
|
||||
public function on_remove_subdomain($subdomain, $site_id) {} // end on_remove_subdomain;
|
||||
public function on_remove_subdomain($subdomain, $site_id) {}
|
||||
|
||||
/**
|
||||
* Tests the connection with the WPMUDEV API.
|
||||
@ -241,24 +228,22 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider {
|
||||
|
||||
$api_key = get_site_option('wpmudev_apikey');
|
||||
|
||||
$response = wp_remote_get("https://premium.wpmudev.org/api/hosting/v1/{$site_id}/domains", array(
|
||||
'timeout' => 50,
|
||||
'headers' => array(
|
||||
'Authorization' => $api_key,
|
||||
),
|
||||
));
|
||||
$response = wp_remote_get(
|
||||
"https://premium.wpmudev.org/api/hosting/v1/{$site_id}/domains",
|
||||
array(
|
||||
'timeout' => 50,
|
||||
'headers' => array(
|
||||
'Authorization' => $api_key,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if (is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 200) {
|
||||
|
||||
wp_send_json_error($response);
|
||||
|
||||
} else {
|
||||
|
||||
wp_send_json_success(wp_remote_retrieve_body($response));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end test_connection;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of this integration.
|
||||
@ -269,8 +254,7 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider {
|
||||
public function get_description() {
|
||||
|
||||
return __('WPMU DEV is one of the largest companies in the WordPress space. Founded in 2004, it was one of the first companies to scale the Website as a Service model with products such as Edublogs and CampusPress.', 'wp-ultimo');
|
||||
|
||||
} // end get_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the logo for the integration.
|
||||
@ -281,7 +265,5 @@ class WPMUDEV_Host_Provider extends Base_Host_Provider {
|
||||
public function get_logo() {
|
||||
|
||||
return wu_get_asset('wpmudev.jpg', 'img/hosts');
|
||||
|
||||
} // end get_logo;
|
||||
|
||||
} // end class WPMUDEV_Host_Provider;
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ use WP_Ultimo\Logger;
|
||||
class CPanel_API {
|
||||
|
||||
/**
|
||||
* Holds the name of the cookis file.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
* Holds the name of the cookis file.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
private $cookie_file;
|
||||
|
||||
/**
|
||||
@ -41,40 +41,40 @@ class CPanel_API {
|
||||
private $cpsess;
|
||||
|
||||
/**
|
||||
* Holds the cPanel url.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string|null
|
||||
*/
|
||||
* Holds the cPanel url.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string|null
|
||||
*/
|
||||
private ?string $homepage = null;
|
||||
|
||||
/**
|
||||
* Holds the execution url.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string|null
|
||||
*/
|
||||
* Holds the execution url.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string|null
|
||||
*/
|
||||
private ?string $ex_page = null;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $username;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $password;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $host;
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
private $port = 2083;
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $log = false;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $username;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $password;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $host;
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
private $port = 2083;
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $log = false;
|
||||
|
||||
/**
|
||||
* Creates the CPanel_API Object.
|
||||
@ -95,18 +95,17 @@ class CPanel_API {
|
||||
) {
|
||||
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
$this->log = $log;
|
||||
// Generates the cookie file
|
||||
$this->password = $password;
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
$this->log = $log;
|
||||
// Generates the cookie file
|
||||
$this->generate_cookie();
|
||||
$this->cookie_file = Logger::get_logs_folder() . 'integration-cpanel-cookie.log';
|
||||
|
||||
// Signs up
|
||||
$this->sign_in();
|
||||
|
||||
} // end __construct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the Cookie File, that is used to make API requests to CPanel.
|
||||
@ -117,8 +116,7 @@ class CPanel_API {
|
||||
public function generate_cookie() {
|
||||
|
||||
wu_log_add('integration-cpanel-cookie', '');
|
||||
|
||||
} // end generate_cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs error or success messages.
|
||||
@ -130,8 +128,7 @@ class CPanel_API {
|
||||
public function log($message) {
|
||||
|
||||
return wu_log_add('integration-cpanel', $message);
|
||||
|
||||
} // end log;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the request to the CPanel API.
|
||||
@ -144,36 +141,24 @@ class CPanel_API {
|
||||
private function request($url, $params = array()) {
|
||||
|
||||
if ($this->log) {
|
||||
|
||||
$curl_log = fopen($this->curlfile, 'a+');
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
if (!file_exists($this->cookie_file)) {
|
||||
|
||||
if ( ! file_exists($this->cookie_file)) {
|
||||
try {
|
||||
|
||||
fopen($this->cookie_file, 'w');
|
||||
|
||||
} catch (Exception $ex) {
|
||||
|
||||
if (!file_exists($this->cookie_file)) {
|
||||
|
||||
if ( ! file_exists($this->cookie_file)) {
|
||||
$this->log($ex . __('Cookie file missing.', 'wp-ultimo'));
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end try;
|
||||
|
||||
} elseif (!is_writable($this->cookie_file)) {
|
||||
|
||||
}
|
||||
}
|
||||
} elseif ( ! is_writable($this->cookie_file)) {
|
||||
$this->log(__('Cookie file not writable', 'wp-ultimo'));
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
@ -192,24 +177,20 @@ class CPanel_API {
|
||||
'Accept-Language: en-US,en;q=0.5',
|
||||
'Accept-Encoding: gzip, deflate',
|
||||
'Connection: keep-alive',
|
||||
'Content-Type: application/x-www-form-urlencoded'
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
),
|
||||
);
|
||||
|
||||
if (!empty($params)) {
|
||||
|
||||
$curl_opts[CURLOPT_POST] = true;
|
||||
$curl_opts[CURLOPT_POSTFIELDS] = $params;
|
||||
|
||||
} // end if;
|
||||
if ( ! empty($params)) {
|
||||
$curl_opts[ CURLOPT_POST ] = true;
|
||||
$curl_opts[ CURLOPT_POSTFIELDS ] = $params;
|
||||
}
|
||||
|
||||
if ($this->log) {
|
||||
|
||||
$curl_opts[CURLOPT_STDERR] = $curl_log;
|
||||
$curl_opts[CURLOPT_FAILONERROR] = false;
|
||||
$curl_opts[CURLOPT_VERBOSE] = true;
|
||||
|
||||
} // end if;
|
||||
$curl_opts[ CURLOPT_STDERR ] = $curl_log;
|
||||
$curl_opts[ CURLOPT_FAILONERROR ] = false;
|
||||
$curl_opts[ CURLOPT_VERBOSE ] = true;
|
||||
}
|
||||
|
||||
curl_setopt_array($ch, $curl_opts);
|
||||
|
||||
@ -221,20 +202,16 @@ class CPanel_API {
|
||||
$this->log(sprintf(__('cPanel API Error: %s', 'wp-ultimo'), curl_error($ch)));
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
if ($this->log) {
|
||||
|
||||
fclose($curl_log);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return (@gzdecode($answer)) ? gzdecode($answer) : $answer; // phpcs:ignore
|
||||
|
||||
} // end request;
|
||||
}
|
||||
/**
|
||||
* Get the base URL to make the calls.
|
||||
*
|
||||
@ -243,8 +220,7 @@ class CPanel_API {
|
||||
private function get_base_url(): string {
|
||||
|
||||
return sprintf('https://%s:%s', $this->host, $this->port);
|
||||
|
||||
} // end get_base_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signs in on the cPanel.
|
||||
@ -266,14 +242,10 @@ class CPanel_API {
|
||||
$this->cpsess = $reply['security_token'];
|
||||
$this->homepage = $this->get_base_url() . $reply['redirect'];
|
||||
$this->ex_page = $this->get_base_url() . "/{$this->cpsess}/execute/";
|
||||
|
||||
} else {
|
||||
|
||||
return $this->log(__('Cannot connect to your cPanel server : Invalid Credentials', 'wp-ultimo'));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end sign_in;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes API calls, taking the request to the right API version
|
||||
@ -289,15 +261,14 @@ class CPanel_API {
|
||||
public function execute($api, $module, $function, array $parameters = array()) {
|
||||
|
||||
switch ($api) {
|
||||
case 'api2':
|
||||
return $this->api2($module, $function, $parameters);
|
||||
case 'uapi':
|
||||
return $this->uapi($module, $function, $parameters);
|
||||
default:
|
||||
throw new Exception('Invalid API type : api2 and uapi are accepted', 1);
|
||||
} // end switch;
|
||||
|
||||
} // end execute;
|
||||
case 'api2':
|
||||
return $this->api2($module, $function, $parameters);
|
||||
case 'uapi':
|
||||
return $this->uapi($module, $function, $parameters);
|
||||
default:
|
||||
throw new Exception('Invalid API type : api2 and uapi are accepted', 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the request if the API being used is the UAPI (newer version)
|
||||
@ -311,18 +282,13 @@ class CPanel_API {
|
||||
public function uapi($module, $function, array $parameters = array()) {
|
||||
|
||||
if (count($parameters) < 1) {
|
||||
|
||||
$parameters = '';
|
||||
|
||||
} else {
|
||||
|
||||
$parameters = (http_build_query($parameters));
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return json_decode((string) $this->request($this->ex_page . $module . '/' . $function . '?' . $parameters));
|
||||
|
||||
} // end uapi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the request if the API being used is the API2 (older version)
|
||||
@ -336,14 +302,10 @@ class CPanel_API {
|
||||
public function api2($module, $function, array $parameters = array()) {
|
||||
|
||||
if (count($parameters) < 1) {
|
||||
|
||||
$parameters = '';
|
||||
|
||||
} else {
|
||||
|
||||
$parameters = (http_build_query($parameters));
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$url = $this->get_base_url() . $this->cpsess . '/json-api/cpanel' .
|
||||
'?cpanel_jsonapi_version=2' .
|
||||
@ -351,7 +313,5 @@ class CPanel_API {
|
||||
"&cpanel_jsonapi_module={$module}&" . $parameters;
|
||||
|
||||
return json_decode((string) $this->request($url, $parameters));
|
||||
|
||||
} // end api2;
|
||||
|
||||
} // end class CPanel_API;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user