Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/cubewp-framework/cube.php
+++ b/cubewp-framework/cube.php
@@ -3,7 +3,7 @@
* Plugin Name: CubeWP Framework
* Plugin URI: https://cubewp.com/
* Description: CubeWP is an end-to-end dynamic content framework for WordPress to help you save up to 90% of your coding time.
-* Version: 1.1.30
+* Version: 1.1.31
* Author: CubeWP
* Author URI: https://cubewp.com
* Text Domain: cubewp-framework
--- a/cubewp-framework/cube/classes/class-cubewp-add-ons.php
+++ b/cubewp-framework/cube/classes/class-cubewp-add-ons.php
@@ -35,7 +35,6 @@
//license system
add_action('admin_init', array($this, 'check_license'));
add_action('admin_init', array($this, 'updates_enable_for_free_addon'));
- add_action('admin_init', array($this, 'check_for_plugin_update'), 0);
add_action(self::CUBEWP . '/' . self::ADDON . '/' . self::ACTI . self::VATION, array($this, '_plugins'), 9, 1);
}
@@ -162,59 +161,6 @@
}
}
}
-
- /**
- * Plugin Update Check
- * @since 1.0
- * @version 1.1
- */
- public function check_for_plugin_update()
- {
- $add_ons = CWP()->cubewp_get_modules();
- foreach ($add_ons as $key => $add_on) {
- $item_name = $add_on['item_name'];
- $author = $add_on['author'];
- $slug = $add_on['slug'];
- $base = $add_on['base'];
- $Lkey = CWP()->cubewp_options($slug . '_key');
- $Lstatus = CWP()->cubewp_options($slug . '-status');
-
- if ($slug == 'cubewp-addon-woocommerce') {
- $Lkey = '96baf6be5cb40a29137cb7fd90441f64';
- $Lstatus = 'valid';
- }
-
- // Check if the transient exists
- if (get_transient($slug . '_update_check')) {
- continue; // Skip if transient exists
- }
- if ($Lkey && is_plugin_active($base)) {
- $plugin = get_plugin_data(plugin_dir_path(dirname(dirname(__DIR__))) . $base, false, false);
- // Set up the updater
- new CubeWp_Plugin_Updater(
- $this->route,
- $base,
- array(
- 'version' => $plugin['Version'],
- 'license' => $Lkey,
- 'item_name' => $item_name,
- 'author' => $author,
- ),
- array(
- 'license_status' => $Lstatus,
- 'admin_page_url' => admin_url('admin.php?page=cube_wp_dashboard'),
- 'purchase_url' => $this->purchase_url,
- 'plugin_title' => 'Dashboard',
- )
- );
- set_transient(
- $slug . '_update_check',
- true,
- 24 * HOUR_IN_SECONDS
- );
- }
- }
- }
public function check_license()
{
--- a/cubewp-framework/cube/classes/class-cubewp-addons-admin.php
+++ b/cubewp-framework/cube/classes/class-cubewp-addons-admin.php
@@ -65,6 +65,65 @@
return 'https://cubewp.com';
}
+ /**
+ * Site URL for EDD SL (activate / check / deactivate / get_version). Matches {@see CubeWp_Add_Ons::add_on_management()}.
+ *
+ * @return string
+ */
+ private function edd_license_client_site_url() {
+ return home_url();
+ }
+
+ /**
+ * Product fields for EDD API: same shape as CubeWp_Add_Ons (item_name sent with urlencode when set; else item_id).
+ *
+ * @param array<string, mixed> $addon Row with item_name / item_id.
+ * @return array<string, string>
+ */
+ private function edd_sl_addon_product_params( array $addon ) {
+ $params = array();
+ $item_name = isset( $addon['item_name'] ) ? trim( (string) $addon['item_name'] ) : '';
+ $item_id = isset( $addon['item_id'] ) ? trim( (string) $addon['item_id'] ) : '';
+
+ if ( '' !== $item_name ) {
+ $params['item_name'] = urlencode( $item_name );
+ } elseif ( '' !== $item_id ) {
+ $params['item_id'] = $item_id;
+ }
+
+ return $params;
+ }
+
+ /**
+ * Resolve EDD license post ID from the hub catalog for a slug + key (multi-license products).
+ *
+ * @param string $slug Sanitized product slug.
+ * @param string $license_key License key.
+ * @return int 0 if unknown.
+ */
+ private function hub_license_id_for_slug_and_license_key( $slug, $license_key ) {
+ $slug = sanitize_key( (string) $slug );
+ $license_key = trim( (string) $license_key );
+ if ( '' === $slug || '' === $license_key ) {
+ return 0;
+ }
+ $item = $this->hub_item_for_slug( $slug );
+ if ( ! is_array( $item ) ) {
+ return 0;
+ }
+ if ( ! empty( $item['licenses'] ) && is_array( $item['licenses'] ) ) {
+ foreach ( $item['licenses'] as $row ) {
+ if ( is_array( $row ) && ! empty( $row['license_key'] ) && (string) $row['license_key'] === $license_key && ! empty( $row['license_id'] ) ) {
+ return (int) $row['license_id'];
+ }
+ }
+ }
+ if ( ! empty( $item['license_key'] ) && (string) $item['license_key'] === $license_key && ! empty( $item['license_id'] ) ) {
+ return (int) $item['license_id'];
+ }
+ return 0;
+ }
+
private function hub_base_url() {
$base = self::DEFAULT_HUB_BASE_URL;
@@ -181,6 +240,87 @@
return null;
}
+ /**
+ * All license keys from the hub snapshot for a slug (flat + `licenses` list).
+ *
+ * @return array<int, string>
+ */
+ private function hub_license_keys_for_slug( $slug ) {
+ $item = $this->hub_item_for_slug( $slug );
+ if ( ! is_array( $item ) ) {
+ return array();
+ }
+ $keys = array();
+ if ( ! empty( $item['licenses'] ) && is_array( $item['licenses'] ) ) {
+ foreach ( $item['licenses'] as $row ) {
+ if ( is_array( $row ) && ! empty( $row['license_key'] ) ) {
+ $keys[] = (string) $row['license_key'];
+ }
+ }
+ }
+ if ( ! empty( $item['license_key'] ) ) {
+ $keys[] = (string) $item['license_key'];
+ }
+ $keys = array_values( array_unique( array_filter( $keys ) ) );
+ return $keys;
+ }
+
+ /**
+ * @param int $license_id EDD SL license post ID.
+ */
+ private function hub_license_id_is_allowed( $license_id ) {
+ $license_id = (int) $license_id;
+ if ( $license_id <= 0 ) {
+ return false;
+ }
+ foreach ( $this->hub_get_items() as $item ) {
+ if ( ! is_array( $item ) ) {
+ continue;
+ }
+ if ( ! empty( $item['licenses'] ) && is_array( $item['licenses'] ) ) {
+ foreach ( $item['licenses'] as $row ) {
+ if ( is_array( $row ) && (int) ( $row['license_id'] ?? 0 ) === $license_id ) {
+ return true;
+ }
+ }
+ }
+ if ( (int) ( $item['license_id'] ?? 0 ) === $license_id ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Posted `license_key` (optional) must match a hub snapshot key for this slug.
+ *
+ * @param string $slug
+ * @param array<string, mixed> $addon Catalog row.
+ * @return string|WP_Error
+ */
+ private function resolve_license_key_for_slug_or_fail( $slug, $addon ) {
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce and capability are verified by the calling handler (verify_post()/handle_ajax()) before this helper runs.
+ $posted = isset( $_POST['license_key'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['license_key'] ) ) : '';
+ if ( $posted !== '' ) {
+ $allowed = $this->hub_license_keys_for_slug( $slug );
+ if ( ! in_array( $posted, $allowed, true ) ) {
+ return new WP_Error(
+ 'cubewp_invalid_license_choice',
+ __( 'That license key is not in your hub purchase list for this product.', 'cubewp-framework' )
+ );
+ }
+ return $posted;
+ }
+ $key = $this->get_effective_license_key( $slug, $addon );
+ if ( $key === '' ) {
+ return new WP_Error(
+ 'cubewp_missing_license',
+ __( 'Connect to CubeWP.com to sync a license first.', 'cubewp-framework' )
+ );
+ }
+ return $key;
+ }
+
private function license_option_key( $slug ) {
return sanitize_key( (string) $slug ).'_key';
}
@@ -200,14 +340,55 @@
}
/**
- * Hub items first, then option populated by hub sync (no manual UI).
+ * Save `{slug}_key` only after install/activate — not when syncing the hub catalog.
+ * When connected to the hub, the key must exist in the current snapshot for that slug.
+ *
+ * @param string $slug Addon/theme slug.
+ * @param string $license_key License key that was used for EDD on this site.
+ */
+ private function persist_addon_license_key_for_slug( $slug, $license_key ) {
+ $slug = sanitize_key( (string) $slug );
+ $license_key = trim( (string) $license_key );
+ if ( '' === $slug || '' === $license_key ) {
+ return;
+ }
+ if ( $this->hub_is_connected() ) {
+ $allowed = $this->hub_license_keys_for_slug( $slug );
+ if ( ! empty( $allowed ) && ! in_array( $license_key, $allowed, true ) ) {
+ return;
+ }
+ }
+ update_option( $this->license_option_key( $slug ), $license_key, false );
+ }
+
+ /**
+ * Hub snapshot first, then optional `{slug}_key` saved when the user installs/activates (see persist_addon_license_key_for_slug).
+ * When the hub lists multiple keys for one product, prefer the key already saved locally if it matches.
*/
private function get_effective_license_key( $slug, $addon ) {
$item = $this->hub_item_for_slug( $slug );
- if ( is_array( $item ) && ! empty( $item['license_key'] ) ) {
+ if ( ! is_array( $item ) ) {
+ return $this->get_license_key( $slug );
+ }
+ $saved = $this->get_license_key( $slug );
+ if ( ! empty( $item['licenses'] ) && is_array( $item['licenses'] ) ) {
+ if ( $saved !== '' ) {
+ foreach ( $item['licenses'] as $row ) {
+ if ( is_array( $row ) && ! empty( $row['license_key'] ) && (string) $row['license_key'] === $saved ) {
+ return (string) $row['license_key'];
+ }
+ }
+ }
+ $list = $item['licenses'];
+ $last = end( $list );
+ if ( is_array( $last ) && ! empty( $last['license_key'] ) ) {
+ return (string) $last['license_key'];
+ }
+ }
+ if ( ! empty( $item['license_key'] ) ) {
return (string) $item['license_key'];
}
- return $this->get_license_key( $slug );
+ return $saved;
}
/**
@@ -368,7 +549,7 @@
trailingslashit( $this->hub_base_url() ) . 'my-account/'
);
- wp_redirect( esc_url_raw( $url ) );
+ wp_safe_redirect( esc_url_raw( $url ) );
exit;
}
@@ -408,14 +589,6 @@
$items = isset( $data['items'] ) && is_array( $data['items'] ) ? $data['items'] : array();
update_option( self::OPT_HUB_ITEMS, $items, false );
- // Also populate per-addon license options for existing installer logic/config.txt writer.
- foreach ( $items as $item ) {
- if ( ! is_array( $item ) || empty( $item['slug'] ) || empty( $item['license_key'] ) ) {
- continue;
- }
- update_option( $this->license_option_key( $item['slug'] ), (string) $item['license_key'], false );
- }
-
return true;
}
@@ -423,14 +596,18 @@
if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) {
return;
}
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- OAuth callback from CubeWP.com; CSRF is enforced by the user-bound state transient validated below.
if ( empty( $_GET['cubewp_hub_callback'] ) ) {
return;
}
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- OAuth callback from CubeWP.com; CSRF is enforced by the user-bound state transient validated below.
if ( empty( $_GET['code'] ) || empty( $_GET['state'] ) ) {
return;
}
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- OAuth callback from CubeWP.com; CSRF is enforced by the user-bound state transient validated below.
$code = sanitize_text_field( wp_unslash( $_GET['code'] ) );
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- OAuth callback from CubeWP.com; CSRF is enforced by the user-bound state transient validated below.
$state = sanitize_text_field( wp_unslash( $_GET['state'] ) );
$t = get_transient( self::STATE_PREFIX . md5( $state ) );
@@ -653,17 +830,9 @@
}
if ( ! empty( $license_key ) && ( empty( $addon['license_type'] ) || 'free' !== $addon['license_type'] ) ) {
- $act = $this->activate_license_for_site( $this->addon_for_edd_api( $addon ), $license_key );
- if ( is_wp_error( $act ) ) {
- wp_send_json_error( array( 'message' => $act->get_error_message() ), 400 );
- }
- $status = isset( $act['license'] ) ? (string) $act['license'] : '';
- if ( '' !== $status && ! in_array( $status, array( 'valid', 'active' ), true ) ) {
- $msg = __( 'License activation failed for this site.', 'cubewp-framework' ) . ' License: ' . $status;
- if ( ! empty( $act['error'] ) ) {
- $msg .= ' Error: ' . (string) $act['error'];
- }
- wp_send_json_error( array( 'message' => $msg ), 400 );
+ $ensured = $this->ensure_edd_license_for_package_download( $this->addon_for_edd_api( $addon ), $license_key );
+ if ( is_wp_error( $ensured ) ) {
+ wp_send_json_error( array( 'message' => $ensured->get_error_message() ), 400 );
}
}
@@ -717,6 +886,9 @@
}
$this->maybe_write_config_txt( $addon, $slug, $base );
+ if ( ! empty( $license_key ) ) {
+ $this->persist_addon_license_key_for_slug( $slug, $license_key );
+ }
wp_send_json_success(
array(
@@ -737,12 +909,28 @@
$addon = isset( $catalog[ $slug ] ) ? $catalog[ $slug ] : null;
if ( is_array( $addon ) ) {
$this->maybe_write_config_txt( $addon, $slug, $base );
+ $lk = $this->get_effective_license_key( $slug, $addon );
+ if ( ! empty( $lk ) && $this->catalog_addon_requires_edd_license( $addon ) ) {
+ $ensured = $this->ensure_edd_license_for_package_download( $this->addon_for_edd_api( $addon ), $lk );
+ if ( is_wp_error( $ensured ) ) {
+ wp_send_json_error( array( 'message' => $ensured->get_error_message() ), 400 );
+ }
+ }
}
}
$result = activate_plugin( $base );
if ( is_wp_error( $result ) ) {
wp_send_json_error( array( 'message' => $result->get_error_message() ), 400 );
}
+ if ( ! empty( $slug ) ) {
+ $addon_row = isset( $catalog[ $slug ] ) ? $catalog[ $slug ] : null;
+ if ( is_array( $addon_row ) ) {
+ $lk = $this->get_effective_license_key( $slug, $addon_row );
+ if ( ! empty( $lk ) ) {
+ $this->persist_addon_license_key_for_slug( $slug, $lk );
+ }
+ }
+ }
wp_send_json_success( array( 'message' => __( 'Plugin activated.', 'cubewp-framework' ), 'status' => 'active' ) );
case 'plugin_deactivate':
@@ -770,18 +958,10 @@
$addon_for_api['item_id'] = (string) $row['_hub']['download_id'];
}
- $act = $this->activate_license_for_site( $addon_for_api, $license_key );
+ $act = $this->ensure_edd_license_for_package_download( $addon_for_api, $license_key );
if ( is_wp_error( $act ) ) {
wp_send_json_error( array( 'message' => $act->get_error_message() ), 400 );
}
- $status = isset( $act['license'] ) ? (string) $act['license'] : '';
- if ( '' !== $status && ! in_array( $status, array( 'valid', 'active' ), true ) ) {
- $msg = __( 'License activation failed for this site.', 'cubewp-framework' ) . ' License: ' . $status;
- if ( ! empty( $act['error'] ) ) {
- $msg .= ' Error: ' . (string) $act['error'];
- }
- wp_send_json_error( array( 'message' => $msg ), 400 );
- }
$package = $this->get_download_package_url( $addon_for_api, $license_key );
if ( is_wp_error( $package ) ) {
@@ -818,6 +998,7 @@
$msg .= ' Package: ' . $package;
wp_send_json_error( array( 'message' => $msg ), 400 );
}
+ $this->persist_addon_license_key_for_slug( $slug, $license_key );
wp_send_json_success( array( 'message' => __( 'Theme installed.', 'cubewp-framework' ), 'status' => 'installed' ) );
case 'theme_activate':
@@ -832,7 +1013,35 @@
if ( ! $theme->exists() ) {
wp_send_json_error( array( 'message' => __( 'Theme is not installed.', 'cubewp-framework' ) ), 400 );
}
+ $matched_slug = '';
+ $matched_row = null;
+ foreach ( $catalog as $th_slug => $th_row ) {
+ if ( ! is_array( $th_row ) || empty( $th_row['type'] ) || 'theme' !== $th_row['type'] ) {
+ continue;
+ }
+ $ts = isset( $th_row['stylesheet'] ) ? (string) $th_row['stylesheet'] : '';
+ if ( $ts !== '' && $ts === $stylesheet ) {
+ $matched_slug = sanitize_key( (string) $th_slug );
+ $matched_row = $th_row;
+ break;
+ }
+ }
+ if ( null !== $matched_row ) {
+ $lk = $this->get_effective_license_key( $matched_slug, $matched_row );
+ if ( ! empty( $lk ) && $this->catalog_addon_requires_edd_license( $matched_row ) ) {
+ $ensured = $this->ensure_edd_license_for_package_download( $this->addon_for_edd_api( $matched_row ), $lk );
+ if ( is_wp_error( $ensured ) ) {
+ wp_send_json_error( array( 'message' => $ensured->get_error_message() ), 400 );
+ }
+ }
+ }
switch_theme( $stylesheet );
+ if ( null !== $matched_row ) {
+ $lk = $this->get_effective_license_key( $matched_slug, $matched_row );
+ if ( ! empty( $lk ) ) {
+ $this->persist_addon_license_key_for_slug( $matched_slug, $lk );
+ }
+ }
wp_send_json_success( array( 'message' => __( 'Theme activated.', 'cubewp-framework' ), 'status' => 'active' ) );
case 'license_check':
@@ -843,29 +1052,60 @@
if ( empty( $slug ) || ! is_array( $addon ) ) {
wp_send_json_error( array( 'message' => __( 'Addon not found.', 'cubewp-framework' ) ), 404 );
}
- $license_key = $this->get_effective_license_key( $slug, $addon );
- if ( empty( $license_key ) ) {
- wp_send_json_error( array( 'message' => __( 'Connect to CubeWP.com to sync a license first.', 'cubewp-framework' ) ), 400 );
+ $license_key = $this->resolve_license_key_for_slug_or_fail( $slug, $addon );
+ if ( is_wp_error( $license_key ) ) {
+ wp_send_json_error( array( 'message' => $license_key->get_error_message() ), 400 );
}
+ $license_key = (string) $license_key;
if ( 'license_check' === $op ) {
$data = $this->check_license_for_site( $this->addon_for_edd_api( $addon ), $license_key );
} elseif ( 'license_deactivate' === $op ) {
$data = $this->deactivate_license_for_site( $this->addon_for_edd_api( $addon ), $license_key );
} else {
- $data = $this->activate_license_for_site( $this->addon_for_edd_api( $addon ), $license_key );
+ // license_activate (Manage modal): same rules as package install — limits, check then activate, post-activate verify.
+ if ( '' !== $license_key && $this->catalog_addon_requires_edd_license( $addon ) ) {
+ $ensured = $this->ensure_edd_license_for_package_download( $this->addon_for_edd_api( $addon ), $license_key );
+ if ( is_wp_error( $ensured ) ) {
+ wp_send_json_error( array( 'message' => $ensured->get_error_message() ), 400 );
+ }
+ }
+ $data = $this->check_license_for_site( $this->addon_for_edd_api( $addon ), $license_key );
}
if ( is_wp_error( $data ) ) {
wp_send_json_error( array( 'message' => $data->get_error_message() ), 400 );
}
+
+ $api_ok = $this->assert_edd_license_api_success( $data );
+ if ( is_wp_error( $api_ok ) ) {
+ wp_send_json_error( array( 'message' => $api_ok->get_error_message() ), 400 );
+ }
+
+ if ( 'license_activate' === $op ) {
+ $act_ok = $this->assert_edd_license_allowed_for_site_response( $data );
+ if ( is_wp_error( $act_ok ) ) {
+ wp_send_json_error( array( 'message' => $act_ok->get_error_message() ), 400 );
+ }
+ }
+
$lic_status = isset( $data['license'] ) ? (string) $data['license'] : '';
- wp_send_json_success(
- array(
- 'message' => __( 'License request completed.', 'cubewp-framework' ),
- 'license' => $lic_status,
- )
+ $out = array(
+ 'message' => __( 'License request completed.', 'cubewp-framework' ),
+ 'license' => $lic_status,
);
+ if ( 'license_activate' === $op && in_array( $lic_status, array( 'valid', 'active' ), true ) ) {
+ $this->persist_addon_license_key_for_slug( $slug, $license_key );
+ $this->maybe_write_config_txt( $addon, $slug, isset( $addon['base'] ) ? (string) $addon['base'] : '' );
+ }
+ // license_deactivate: EDD removes this URL from the license only. Keep `{slug}_key` (and any `{slug}_status`) so the product still knows which key to prefer for re-activation / installs.
+ if ( 'license_deactivate' === $op && '' !== $lic_status ) {
+ $status_key = sanitize_key( (string) $slug ) . '_status';
+ if ( false !== get_option( $status_key, false ) ) {
+ update_option( $status_key, $lic_status, false );
+ }
+ }
+ wp_send_json_success( $out );
case 'manage_details':
$slug = isset( $_POST['addon_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['addon_slug'] ) ) : '';
@@ -874,46 +1114,98 @@
wp_send_json_error( array( 'message' => __( 'Addon not found.', 'cubewp-framework' ) ), 404 );
}
$hub = $this->hub_item_for_slug( sanitize_key( $slug ) );
- $license_id = ( is_array( $hub ) && ! empty( $hub['license_id'] ) ) ? (int) $hub['license_id'] : 0;
- $license_key = $this->get_effective_license_key( $slug, $addon );
-
- if ( empty( $license_key ) || empty( $license_id ) ) {
+ if ( ! is_array( $hub ) ) {
wp_send_json_error( array( 'message' => __( 'No license found for this product.', 'cubewp-framework' ) ), 400 );
}
- $sites = $this->hub_get_license_sites( $license_id );
- if ( is_wp_error( $sites ) ) {
- wp_send_json_error( array( 'message' => $sites->get_error_message() ), 400 );
+ $license_rows = array();
+ if ( ! empty( $hub['licenses'] ) && is_array( $hub['licenses'] ) ) {
+ $license_rows = $hub['licenses'];
+ } elseif ( ! empty( $hub['license_key'] ) && ! empty( $hub['license_id'] ) ) {
+ $license_rows = array(
+ array(
+ 'license_key' => (string) $hub['license_key'],
+ 'license_id' => (int) $hub['license_id'],
+ 'payment_id' => isset( $hub['payment_id'] ) ? (int) $hub['payment_id'] : 0,
+ ),
+ );
+ }
+
+ if ( empty( $license_rows ) ) {
+ wp_send_json_error( array( 'message' => __( 'No license found for this product.', 'cubewp-framework' ) ), 400 );
}
$download_name = isset( $addon['item_name'] ) ? (string) $addon['item_name'] : (string) $slug;
- $check = $this->check_license_for_site( $this->addon_for_edd_api( $addon ), $license_key );
- $summary = '';
- if ( ! is_wp_error( $check ) && is_array( $check ) ) {
- $parts = array();
- if ( isset( $check['license'] ) ) {
- $parts[] = 'Status: ' . (string) $check['license'];
+ $edd_addon = $this->addon_for_edd_api( $addon );
+ $licenses_out = array();
+
+ foreach ( $license_rows as $row ) {
+ if ( ! is_array( $row ) ) {
+ continue;
}
- if ( isset( $check['expires'] ) ) {
- $parts[] = 'Expires: ' . (string) $check['expires'];
+ $lid = isset( $row['license_id'] ) ? (int) $row['license_id'] : 0;
+ $lk = isset( $row['license_key'] ) ? (string) $row['license_key'] : '';
+ if ( $lid <= 0 || $lk === '' ) {
+ continue;
}
- if ( isset( $check['site_count'] ) ) {
- $parts[] = 'Sites: ' . (string) $check['site_count'];
+
+ $sites = $this->hub_get_license_sites( $lid );
+ if ( is_wp_error( $sites ) ) {
+ wp_send_json_error( array( 'message' => $sites->get_error_message() ), 400 );
}
- if ( isset( $check['license_limit'] ) ) {
- $parts[] = 'Limit: ' . (string) $check['license_limit'];
+ $sites = is_array( $sites ) ? $sites : array();
+
+ $check = $this->check_license_for_site( $edd_addon, $lk );
+ $summary = '';
+ if ( ! is_wp_error( $check ) && is_array( $check ) ) {
+ $parts = array();
+ if ( isset( $check['license'] ) ) {
+ $parts[] = 'Status: ' . (string) $check['license'];
+ }
+ if ( isset( $check['expires'] ) ) {
+ $parts[] = 'Expires: ' . (string) $check['expires'];
+ }
+ if ( isset( $check['site_count'] ) ) {
+ $parts[] = 'Sites: ' . (string) $check['site_count'];
+ }
+ if ( isset( $check['license_limit'] ) ) {
+ $parts[] = 'Limit: ' . (string) $check['license_limit'];
+ }
+ $summary = ! empty( $parts ) ? implode( ' ', $parts ) : '';
}
- $summary = ! empty( $parts ) ? implode( ' ' , $parts ) : '';
+
+ $lic_status = ( ! is_wp_error( $check ) && is_array( $check ) && isset( $check['license'] ) )
+ ? (string) $check['license']
+ : '';
+ $on_site = in_array( $lic_status, array( 'valid', 'active' ), true );
+
+ $licenses_out[] = array(
+ 'id' => $lid,
+ 'key' => $lk,
+ 'payment_id' => isset( $row['payment_id'] ) ? (int) $row['payment_id'] : 0,
+ 'summary' => $summary,
+ 'sites' => $sites,
+ 'on_this_site' => $on_site,
+ );
+ }
+
+ if ( empty( $licenses_out ) ) {
+ wp_send_json_error( array( 'message' => __( 'No license found for this product.', 'cubewp-framework' ) ), 400 );
}
+ $n = count( $licenses_out );
+ $primary = $n > 0 ? $licenses_out[ $n - 1 ] : array();
+
wp_send_json_success(
array(
- 'license' => array(
- 'key' => (string) $license_key,
+ 'product' => (string) $download_name,
+ 'licenses' => $licenses_out,
+ 'license' => array(
+ 'key' => (string) ( $primary['key'] ?? '' ),
'product' => (string) $download_name,
- 'id' => (int) $license_id,
- 'sites' => is_array( $sites ) ? $sites : array(),
- 'summary' => (string) $summary,
+ 'id' => (int) ( $primary['id'] ?? 0 ),
+ 'sites' => isset( $primary['sites'] ) && is_array( $primary['sites'] ) ? $primary['sites'] : array(),
+ 'summary' => (string) ( $primary['summary'] ?? '' ),
),
)
);
@@ -924,6 +1216,9 @@
if ( empty( $license_id ) || empty( $site_id ) ) {
wp_send_json_error( array( 'message' => __( 'Missing license or site.', 'cubewp-framework' ) ), 400 );
}
+ if ( ! $this->hub_license_id_is_allowed( $license_id ) ) {
+ wp_send_json_error( array( 'message' => __( 'That license is not in your hub list.', 'cubewp-framework' ) ), 403 );
+ }
$res = $this->hub_deactivate_license_site( $license_id, $site_id );
if ( is_wp_error( $res ) ) {
wp_send_json_error( array( 'message' => $res->get_error_message() ), 400 );
@@ -1067,27 +1362,27 @@
}
private function get_download_package_url( $addon, $license_key ) {
- $item_id = isset( $addon['item_id'] ) ? (string) $addon['item_id'] : '';
- $item_name = isset( $addon['item_name'] ) ? (string) $addon['item_name'] : '';
+ $license_key = (string) $license_key;
- $params = array(
- 'edd_action' => 'get_version',
- 'license' => (string) $license_key,
- 'url' => home_url(),
+ $params = array_merge(
+ array(
+ 'edd_action' => 'get_version',
+ 'license' => $license_key,
+ 'url' => $this->edd_license_client_site_url(),
+ ),
+ $this->edd_sl_addon_product_params( is_array( $addon ) ? $addon : array() )
);
- // Prefer item_id if present (less ambiguous than item_name).
- if ( ! empty( $item_id ) ) {
- $params['item_id'] = $item_id;
- } else {
- $params['item_name'] = urlencode( $item_name );
- }
-
$data = $this->edd_api_request( $params );
if ( is_wp_error( $data ) ) {
return $data;
}
+ $pkg_ok = $this->assert_edd_get_version_allows_package( $data, trim( $license_key ) !== '' );
+ if ( is_wp_error( $pkg_ok ) ) {
+ return $pkg_ok;
+ }
+
if ( isset( $data['package'] ) && is_string( $data['package'] ) && ! empty( $data['package'] ) ) {
return $data['package'];
}
@@ -1096,66 +1391,271 @@
}
private function activate_license_for_site( $addon, $license_key ) {
- $item_id = isset( $addon['item_id'] ) ? (string) $addon['item_id'] : '';
- $item_name = isset( $addon['item_name'] ) ? (string) $addon['item_name'] : '';
+ $license_key = (string) $license_key;
+ $site_url = $this->edd_license_client_site_url();
+ $slug = isset( $addon['slug'] ) ? sanitize_key( (string) $addon['slug'] ) : '';
+
+ if ( $this->hub_is_connected() && '' !== $slug && '' !== $license_key ) {
+ $lid = $this->hub_license_id_for_slug_and_license_key( $slug, $license_key );
+ if ( $lid > 0 ) {
+ $hub = $this->hub_api_request(
+ 'POST',
+ '/licenses/' . $lid . '/activate-site',
+ array( 'site_url' => $site_url )
+ );
+ if ( ! is_wp_error( $hub ) && is_array( $hub ) ) {
+ return $hub;
+ }
+ }
+ }
- $params = array(
- 'edd_action' => 'activate_license',
- 'license' => (string) $license_key,
- 'url' => home_url(),
+ $params = array_merge(
+ array(
+ 'edd_action' => 'activate_license',
+ 'license' => $license_key,
+ 'url' => $site_url,
+ ),
+ $this->edd_sl_addon_product_params( is_array( $addon ) ? $addon : array() )
);
- if ( ! empty( $item_id ) ) {
- $params['item_id'] = $item_id;
- } else {
- $params['item_name'] = urlencode( $item_name );
- }
+ return $this->edd_api_request( $params );
+ }
+
+ private function deactivate_license_for_site( $addon, $license_key ) {
+ $params = array_merge(
+ array(
+ 'edd_action' => 'deactivate_license',
+ 'license' => (string) $license_key,
+ 'url' => $this->edd_license_client_site_url(),
+ ),
+ $this->edd_sl_addon_product_params( is_array( $addon ) ? $addon : array() )
+ );
$data = $this->edd_api_request( $params );
return $data;
}
- private function deactivate_license_for_site( $addon, $license_key ) {
- $item_id = isset( $addon['item_id'] ) ? (string) $addon['item_id'] : '';
- $item_name = isset( $addon['item_name'] ) ? (string) $addon['item_name'] : '';
-
- $params = array(
- 'edd_action' => 'deactivate_license',
- 'license' => (string) $license_key,
- 'url' => home_url(),
+ private function check_license_for_site( $addon, $license_key ) {
+ $params = array_merge(
+ array(
+ 'edd_action' => 'check_license',
+ 'license' => (string) $license_key,
+ 'url' => $this->edd_license_client_site_url(),
+ ),
+ $this->edd_sl_addon_product_params( is_array( $addon ) ? $addon : array() )
);
- if ( ! empty( $item_id ) ) {
- $params['item_id'] = $item_id;
- } else {
- $params['item_name'] = urlencode( $item_name );
+ return $this->edd_api_request( $params );
+ }
+
+ /**
+ * EDD SL uses "valid" / "active" when this site URL is licensed.
+ *
+ * @param string $status Raw status from API.
+ */
+ private static function edd_license_status_allows_this_site( $status ) {
+ $s = strtolower( trim( (string) $status ) );
+ return in_array( $s, array( 'valid', 'active' ), true );
+ }
+
+ /**
+ * @param array<string, mixed> $data Decoded EDD SL JSON.
+ * @return true|WP_Error
+ */
+ private function assert_edd_license_api_success( array $data ) {
+ if ( isset( $data['success'] ) ) {
+ $s = $data['success'];
+ if ( false === $s || 0 === $s || '0' === $s || 0.0 === $s ) {
+ $msg = ! empty( $data['error'] ) ? (string) $data['error'] : __( 'The licensing server rejected this request.', 'cubewp-framework' );
+ return new WP_Error( 'cubewp_edd_license_rejected', $msg, $data );
+ }
+ if ( is_string( $s ) && 'false' === strtolower( $s ) ) {
+ $msg = ! empty( $data['error'] ) ? (string) $data['error'] : __( 'The licensing server rejected this request.', 'cubewp-framework' );
+ return new WP_Error( 'cubewp_edd_license_rejected', $msg, $data );
+ }
}
+ return true;
+ }
- $data = $this->edd_api_request( $params );
- return $data;
+ /**
+ * After activate_license or check_license: require success + valid/active when a status is returned.
+ *
+ * @param array<string, mixed> $data
+ * @return true|WP_Error
+ */
+ private function assert_edd_license_allowed_for_site_response( array $data ) {
+ $r = $this->assert_edd_license_api_success( $data );
+ if ( is_wp_error( $r ) ) {
+ return $r;
+ }
+ if ( isset( $data['license'] ) ) {
+ $lic = strtolower( trim( (string) $data['license'] ) );
+ if ( '' !== $lic && ! self::edd_license_status_allows_this_site( $lic ) ) {
+ $msg = ! empty( $data['error'] ) ? (string) $data['error'] : sprintf(
+ /* translators: %s: license state from EDD Software Licensing */
+ __( 'This license is not active for this site (%s). If your plan allows one site, deactivate it elsewhere or use a different license key.', 'cubewp-framework' ),
+ $lic
+ );
+ return new WP_Error( 'cubewp_edd_license_state', $msg, $data );
+ }
+ }
+ return true;
}
- private function check_license_for_site( $addon, $license_key ) {
- $item_id = isset( $addon['item_id'] ) ? (string) $addon['item_id'] : '';
- $item_name = isset( $addon['item_name'] ) ? (string) $addon['item_name'] : '';
+ /**
+ * get_version responses must not report failure or a non-licensed state when a package is returned.
+ *
+ * @param array<string, mixed> $data Decoded EDD SL JSON.
+ * @param bool $license_was_sent When true, reject explicit non-active `license` values; if `license` is absent, allow when a non-empty `package` is returned (many stores omit `license` on get_version).
+ * @return true|WP_Error
+ */
+ private function assert_edd_get_version_allows_package( array $data, $license_was_sent = true ) {
+ $r = $this->assert_edd_license_api_success( $data );
+ if ( is_wp_error( $r ) ) {
+ return $r;
+ }
+ if ( $license_was_sent ) {
+ if ( isset( $data['license'] ) && trim( (string) $data['license'] ) !== '' ) {
+ $lic = strtolower( trim( (string) $data['license'] ) );
+ if ( ! self::edd_license_status_allows_this_site( $lic ) ) {
+ $msg = ! empty( $data['error'] ) ? (string) $data['error'] : __( 'Download is not permitted for this license on this site (activation limit or invalid license).', 'cubewp-framework' );
+ return new WP_Error( 'cubewp_edd_package_license', $msg, $data );
+ }
+ } elseif ( ! isset( $data['package'] ) || ! is_string( $data['package'] ) || trim( $data['package'] ) === '' ) {
+ // Many EDD SL builds omit `license` on get_version even when the download is allowed; only fail if there is no package either.
+ return new WP_Error(
+ 'cubewp_edd_package_license_missing',
+ __( 'The licensing server did not confirm this site for downloads (missing license state and no package URL). If this license is limited to one site, deactivate it elsewhere first.', 'cubewp-framework' ),
+ $data
+ );
+ }
+ } elseif ( isset( $data['license'] ) ) {
+ $lic = strtolower( trim( (string) $data['license'] ) );
+ if ( '' !== $lic && ! self::edd_license_status_allows_this_site( $lic ) ) {
+ $msg = ! empty( $data['error'] ) ? (string) $data['error'] : __( 'Download is not permitted for this license on this site (activation limit or invalid license).', 'cubewp-framework' );
+ return new WP_Error( 'cubewp_edd_package_license', $msg, $data );
+ }
+ }
+ return true;
+ }
- $params = array(
- 'edd_action' => 'check_license',
- 'license' => (string) $license_key,
- 'url' => home_url(),
- );
+ /**
+ * When EDD reports this URL as licensed, sanity-check site_count vs license_limit (fail closed on inconsistent data).
+ *
+ * @param array<string, mixed> $check check_license JSON.
+ * @return true|WP_Error
+ */
+ private function assert_edd_check_license_site_cap_coherent( array $check ) {
+ $st = isset( $check['license'] ) ? strtolower( trim( (string) $check['license'] ) ) : '';
+ if ( ! self::edd_license_status_allows_this_site( $st ) ) {
+ return true;
+ }
+ $limit = isset( $check['license_limit'] ) ? (int) $check['license_limit'] : 0;
+ $count = isset( $check['site_count'] ) ? (int) $check['site_count'] : -1;
+ if ( $limit > 0 && $count >= 0 && $count > $limit ) {
+ return new WP_Error(
+ 'cubewp_edd_site_cap',
+ __( 'This license reports more active sites than allowed. Deactivate it on another installation or contact support.', 'cubewp-framework' ),
+ $check
+ );
+ }
+ return true;
+ }
- if ( ! empty( $item_id ) ) {
- $params['item_id'] = $item_id;
- } else {
- $params['item_name'] = urlencode( $item_name );
+ /**
+ * Re-check license state on the server after activate_license so we never treat a failed activation as success.
+ *
+ * @param array<string, mixed> $edd Row for EDD API.
+ * @param string $license_key License key.
+ * @return true|WP_Error
+ */
+ private function assert_fresh_check_license_allows_download( array $edd, $license_key ) {
+ $recheck = $this->check_license_for_site( $edd, $license_key );
+ if ( is_wp_error( $recheck ) ) {
+ return $recheck;
+ }
+ $r = $this->assert_edd_license_api_success( $recheck );
+ if ( is_wp_error( $r ) ) {
+ return $r;
+ }
+ $r = $this->assert_edd_license_allowed_for_site_response( $recheck );
+ if ( is_wp_error( $r ) ) {
+ return $r;
}
+ return $this->assert_edd_check_license_site_cap_coherent( $recheck );
+ }
- return $this->edd_api_request( $params );
+ /**
+ * @param array<string, mixed> $addon Catalog row.
+ */
+ private function catalog_addon_requires_edd_license( array $addon ) {
+ return empty( $addon['license_type'] ) || 'free' !== $addon['license_type'];
+ }
+
+ /**
+ * Check current URL first; activate only when needed so EDD limits apply consistently (hub + legacy).
+ *
+ * @param array<string, mixed> $addon Row with item_id / item_name for API.
+ * @param string $license_key
+ * @return true|WP_Error
+ */
+ private function ensure_edd_license_for_package_download( array $addon, $license_key ) {
+ $license_key = (string) $license_key;
+ if ( '' === $license_key ) {
+ return true;
+ }
+ $edd = $this->addon_for_edd_api( $addon );
+
+ $check = $this->check_license_for_site( $edd, $license_key );
+ if ( is_wp_error( $check ) ) {
+ return $check;
+ }
+ $check_success = $this->assert_edd_license_api_success( $check );
+ if ( is_wp_error( $check_success ) ) {
+ return $check_success;
+ }
+
+ $st = isset( $check['license'] ) ? strtolower( trim( (string) $check['license'] ) ) : '';
+ if ( self::edd_license_status_allows_this_site( $st ) ) {
+ $r = $this->assert_edd_license_allowed_for_site_response( $check );
+ if ( is_wp_error( $r ) ) {
+ return $r;
+ }
+ $r = $this->assert_edd_check_license_site_cap_coherent( $check );
+ if ( is_wp_error( $r ) ) {
+ return $r;
+ }
+ return true;
+ }
+
+ $blocked = array( 'expired', 'disabled', 'invalid', 'revoked', 'missing' );
+ if ( in_array( $st, $blocked, true ) ) {
+ return new WP_Error(
+ 'cubewp_edd_license_terminal',
+ sprintf(
+ /* translators: %s: license state */
+ __( 'License cannot be used on this site (%s).', 'cubewp-framework' ),
+ $st
+ ),
+ $check
+ );
+ }
+
+ $act = $this->activate_license_for_site( $edd, $license_key );
+ if ( is_wp_error( $act ) ) {
+ return $act;
+ }
+ $r = $this->assert_edd_license_allowed_for_site_response( $act );
+ if ( is_wp_error( $r ) ) {
+ return $r;
+ }
+ return $this->assert_fresh_check_license_allows_download( $edd, $license_key );
}
private function notice_from_query() {
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only admin notice text from our own redirect; no state change.
$type = isset( $_GET['cwp_notice_type'] ) ? sanitize_key( wp_unslash( $_GET['cwp_notice_type'] ) ) : '';
+ // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only admin notice text from our own redirect; no state change.
$msg = isset( $_GET['cwp_notice'] ) ? sanitize_text_field( wp_unslash( $_GET['cwp_notice'] ) ) : '';
if ( empty( $type ) || empty( $msg ) ) {
return;
@@ -1170,7 +1670,9 @@
public function handle_install() {
$this->verify_post();
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce and capability are verified by verify_post() at the top of this handler.
$slug = isset( $_POST['addon_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['addon_slug'] ) ) : '';
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce and capability are verified by verify_post() at the top of this handler.
$base = isset( $_POST['addon_base'] ) ? sanitize_text_field( wp_unslash( $_POST['addon_base'] ) ) : '';
$catalog = $this->get_catalog_rows();
@@ -1188,18 +1690,9 @@
// Ensure the license is activated for this site before requesting a package URL.
if ( ! empty( $license_key ) && ( empty( $addon['license_type'] ) || 'free' !== $addon['license_type'] ) ) {
- $act = $this->activate_license_for_site( $this->addon_for_edd_api( $addon ), $license_key );
- if ( is_wp_error( $act ) ) {
- wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $act->get_error_message() ) ) );
- exit;
- }
- $status = isset( $act['license'] ) ? (string) $act['license'] : '';
- if ( '' !== $status && ! in_array( $status, array( 'valid', 'active' ), true ) ) {
- $msg = __( 'License activation failed for this site.', 'cubewp-framework' ) . ' License: ' . $status;
- if ( ! empty( $act['error'] ) ) {
- $msg .= ' Error: ' . (string) $act['error'];
- }
- wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $msg ) ) );
+ $ensured = $this->ensure_edd_license_for_package_download( $this->addon_for_edd_api( $addon ), $license_key );
+ if ( is_wp_error( $ensured ) ) {
+ wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $ensured->get_error_message() ) ) );
exit;
}
}
@@ -1260,6 +1753,9 @@
// Ensure add-on activation passes CubeWP's own config.txt check.
$this->maybe_write_config_txt( $addon, $slug, $base );
+ if ( ! empty( $license_key ) ) {
+ $this->persist_addon_license_key_for_slug( $slug, $license_key );
+ }
wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'success', 'cwp_notice' => 'Addon installed.' ) ) );
exit;
@@ -1268,6 +1764,7 @@
public function handle_install_theme() {
$this->verify_post();
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce and capability are verified by verify_post() at the top of this handler.
$slug = isset( $_POST['theme_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['theme_slug'] ) ) : '';
$catalog = $this->get_catalog_rows();
$row = isset( $catalog[ $slug ] ) ? $catalog[ $slug ] : null;
@@ -1290,18 +1787,9 @@
// Ensure the license is activated for this site before requesting a package URL.
if ( ! empty( $license_key ) ) {
- $act = $this->activate_license_for_site( $addon_for_api, $license_key );
- if ( is_wp_error( $act ) ) {
- wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $act->get_error_message() ) ) );
- exit;
- }
- $status = isset( $act['license'] ) ? (string) $act['license'] : '';
- if ( '' !== $status && ! in_array( $status, array( 'valid', 'active' ), true ) ) {
- $msg = __( 'License activation failed for this site.', 'cubewp-framework' ) . ' License: ' . $status;
- if ( ! empty( $act['error'] ) ) {
- $msg .= ' Error: ' . (string) $act['error'];
- }
- wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $msg ) ) );
+ $ensured = $this->ensure_edd_license_for_package_download( $addon_for_api, $license_key );
+ if ( is_wp_error( $ensured ) ) {
+ wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $ensured->get_error_message() ) ) );
exit;
}
}
@@ -1347,6 +1835,7 @@
exit;
}
+ $this->persist_addon_license_key_for_slug( $slug, $license_key );
wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'success', 'cwp_notice' => __( 'Theme installed.', 'cubewp-framework' ) ) ) );
exit;
}
@@ -1354,6 +1843,7 @@
public function handle_activate_theme() {
$this->verify_post();
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce and capability are verified by verify_post() at the top of this handler.
$stylesheet = isset( $_POST['theme_stylesheet'] ) ? sanitize_text_field( wp_unslash( $_POST['theme_stylesheet'] ) ) : '';
if ( empty( $stylesheet ) ) {
wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => 'Missing theme.' ) ) );
@@ -1371,7 +1861,38 @@
exit;
}
+ $catalog = $this->get_catalog_rows();
+ $matched_slug = '';
+ $matched_row = null;
+ foreach ( $catalog as $th_slug => $th_row ) {
+ if ( ! is_array( $th_row ) || empty( $th_row['type'] ) || 'theme' !== $th_row['type'] ) {
+ continue;
+ }
+ $ts = isset( $th_row['stylesheet'] ) ? (string) $th_row['stylesheet'] : '';
+ if ( $ts !== '' && $ts === $stylesheet ) {
+ $matched_slug = sanitize_key( (string) $th_slug );
+ $matched_row = $th_row;
+ break;
+ }
+ }
+ if ( null !== $matched_row ) {
+ $lk = $this->get_effective_license_key( $matched_slug, $matched_row );
+ if ( ! empty( $lk ) && $this->catalog_addon_requires_edd_license( $matched_row ) ) {
+ $ensured = $this->ensure_edd_license_for_package_download( $this->addon_for_edd_api( $matched_row ), $lk );
+ if ( is_wp_error( $ensured ) ) {
+ wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $ensured->get_error_message() ) ) );
+ exit;
+ }
+ }
+ }
+
switch_theme( $stylesheet );
+ if ( null !== $matched_row ) {
+ $lk = $this->get_effective_license_key( $matched_slug, $matched_row );
+ if ( ! empty( $lk ) ) {
+ $this->persist_addon_license_key_for_slug( $matched_slug, $lk );
+ }
+ }
wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'success', 'cwp_notice' => __( 'Theme activated.', 'cubewp-framework' ) ) ) );
exit;
}
@@ -1381,19 +1902,29 @@
require_once ABSPATH . 'wp-admin/includes/plugin.php';
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce and capability are verified by verify_post() at the top of this handler.
$slug = isset( $_POST['addon_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['addon_slug'] ) ) : '';
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce and capability are verified by verify_post() at the top of this handler.
$base = isset( $_POST['addon_base'] ) ? sanitize_text_field( wp_unslash( $_POST['addon_base'] ) ) : '';
if ( empty( $base ) ) {
wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => 'Missing plugin base.' ) ) );
exit;
}
- // If the plugin was installed earlier without config.txt, fix it before activation.
+ $addon = null;
if ( ! empty( $slug ) ) {
$catalog = $this->get_catalog_rows();
$addon = isset( $catalog[ $slug ] ) ? $catalog[ $slug ] : null;
if ( is_array( $addon ) ) {
$this->maybe_write_config_txt( $addon, $slug, $base );
+ $lk = $this->get_effective_license_key( $slug, $addon );
+ if ( ! empty( $lk ) && $this->catalog_addon_requires_edd_license( $addon ) ) {
+ $ensured = $this->ensure_edd_license_for_package_download( $this->addon_for_edd_api( $addon ), $lk );
+ if ( is_wp_error( $ensured ) ) {
+ wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $ensured->get_error_message() ) ) );
+ exit;
+ }
+ }
}
}
@@ -1403,6 +1934,13 @@
exit;
}
+ if ( ! empty( $slug ) && is_array( $addon ) ) {
+ $lk = $this->get_effective_license_key( $slug, $addon );
+ if ( ! empty( $lk ) ) {
+ $this->persist_addon_license_key_for_slug( $slug, $lk );
+ }
+ }
+
wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'success', 'cwp_notice' => 'Plugin activated.' ) ) );
exit;
}
@@ -1412,6 +1950,7 @@
require_once ABSPATH . 'wp-admin/includes/plugin.php';
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce and capability are verified by verify_post() at the top of this handler.
$base = isset( $_POST['addon_base'] ) ? sanitize_text_field( wp_unslash( $_POST['addon_base'] ) ) : '';
if ( empty( $base ) ) {
wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => 'Missing plugin base.' ) ) );
@@ -1426,6 +1965,7 @@
public function handle_license_activate() {
$this->verify_post();
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce and capability are verified by verify_post() at the top of this handler.
$slug = isset( $_POST['addon_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['addon_slug'] ) ) : '';
$catalog = $this->get_catalog_rows();
$addon = isset( $catalog[ $slug ] ) ? $catalog[ $slug ] : null;
@@ -1446,6 +1986,11 @@
wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $data->get_error_message() ) ) );
exit;
}
+ $ok = $this->assert_edd_license_allowed_for_site_response( $data );
+ if ( is_wp_error( $ok ) ) {
+ wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $ok->get_error_message() ) ) );
+ exit;
+ }
$msg = isset( $data['license'] ) ? 'License: ' . $data['license'] : 'License activation requested.';
wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'success', 'cwp_notice' => $msg ) ) );
@@ -1455,6 +2000,7 @@
public function handle_license_deactivate() {
$this->verify_post();
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce and capability are verified by verify_post() at the top of this handler.
$slug = isset( $_POST['addon_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['addon_slug'] ) ) : '';
$catalog = $this->get_catalog_rows();
$addon = isset( $catalog[ $slug ] ) ? $catalog[ $slug ] : null;
@@ -1475,6 +2021,11 @@
wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $data->get_error_message() ) ) );
exit;
}
+ $deact_ok = $this->assert_edd_license_api_success( $data );
+ if ( is_wp_error( $deact_ok ) ) {
+ wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $deact_ok->get_error_message() ) ) );
+ exit;
+ }
$msg = isset( $data['license'] ) ? 'License: ' . $data['license'] : 'License deactivation requested.';
wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'success', 'cwp_notice' => $msg ) ) );
@@ -1484,6 +2035,7 @@
public function handle_license_check() {
$this->verify_post();
+ // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce and capability are verified by verify_post() at the top of this handler.
$slug = isset( $_POST['addon_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['addon_slug'] ) ) : '';
$catalog = $this->get_catalog_rows();
$addon = isset( $catalog[ $slug ] ) ? $catalog[ $slug ] : null;
@@ -1504,6 +2056,11 @@
wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $data->get_error_message() ) ) );
exit;
}
+ $chk_ok = $this->assert_edd_license_api_success( $data );
+ if ( is_wp_error( $chk_ok ) ) {
+ wp_safe_redirect( $this->back_url( array( 'cwp_notice_type' => 'error', 'cwp_notice' => $chk_ok->get_error_message() ) ) );
+ exit;
+ }
// Build a compact status message.
$parts = array();
--- a/cubewp-framework/cube/classes/class-cubewp-admin-enqueue.php
+++ b/cubewp-framework/cube/classes/class-cubewp-admin-enqueue.php
@@ -440,6 +440,13 @@
self::enqueue_script('cubewp-term-meta');
wp_enqueue_media();
}
+
+ if ( CWP()->is_admin_screen( 'cubewp_theme_builder' ) ) {
+ self::enqueue_style( 'select2' );
+ self::enqueue_script( 'select2' );
+ self::enqueue_style( 'cubewp-metaboxes' );
+ }
+
if(CWP()->is_admin_screen('cubewp_settings'))
{
--- a/cubewp-framework/cube/classes/class-cubewp-admin.php
+++ b/cubewp-framework/cube/classes/class-cubewp-admin.php
@@ -304,7 +304,7 @@
* @return void
* @since 1.0.0
*/
- public static function register_elementor_tags($module) {
+public static function register_elementor_tags($module) {
$tags = CubeWp_Custom_Fields_Markup::cwp_form_field_types( 'elementor_dynamic_tags' );
$module->register_group( 'cubewp-fields', [
'title' => esc_html__( 'CubeWP Custom Fields', 'cubewp-framework' ),
@@ -342,7 +342,6 @@
$module->register( new $tag() );
}
}
-
$module->register_group( 'cubewp-taxonomy-fields', [
'title' => esc_html__( 'CubeWP Taxonomy Custom Fields', 'cubewp-framework' ),
] );
@@ -366,7 +365,6 @@
$module->register( new $tag() );
}
}
-
$module->register_group( 'cubewp-user-data', [
'title' => esc_html__( 'CubeWP User Data', 'cubewp-framework' ),
] );
@@ -387,13 +385,18 @@
$module->register( new $tag() );
}
}
-
$module->register_group( 'cubewp-settings-fields', [
'title' => esc_html__( 'CubeWP Settings', 'cubewp-framework' ),
] );
if (class_exists('CubeWp_Tag_Cwp_Settings')) {
$module->register( new CubeWp_Tag_Cwp_Settings() );
}
+ $module->register_group( 'cubewp-form-fields', array(
+ 'title' => esc_html__( 'CubeWP Form Fields', 'cubewp-framework' ),
+ ) );
+
+ // Register extra Elementor dynamic tags (e.g. CubeWP Frontend Pro field name tag).
+ do_action( 'cubewp/elementor/register_dynamic_tags', $module );
}
public function cubewp_updated_post_type_messages( $messages ) {
--- a/cubewp-framework/cube/classes/class-cubewp-elementor-typography.php
+++ b/cubewp-framework/cube/classes/class-cubewp-elementor-typography.php
@@ -0,0 +1,217 @@
+<?php
+if (!defined('ABSPATH')) {
+ exit; // Exit if accessed directly.
+}
+
+if (class_exists('ElementorGroup_Control_Typography') && !class_exists('CubeWp_Group_Control_Typography')) {
+ /**
+ * Override Elementor typography group control selector for font-family.
+ * Keeps existing typography UI but allows CSS variable value without quotes.
+ */
+ class CubeWp_Group_Control_Typography extends ElementorGroup_Control_Typography
+ {
+ protected function init_fields()
+ {
+ $fields = parent::init_fields();
+
+ if (isset($fields['font_family'])) {
+ $fields['font_family']['selector_value'] = 'font-family: {{VALUE}};';
+ }
+
+ return $fields;
+ }
+ }
+}
+
+/**
+ * CubeWP Elementor typography integration.
+ */
+class CubeWp_Elementor_Typography
+{
+
+
+ /**
+ * Register CubeWP font group at top.
+ *
+ * @param array<string, string> $font_groups Font groups.
+ * @return array<string, string>
+ */
+ public static function register_cubewp_font_group($font_groups)
+ {
+ if (!is_array($font_groups)) {
+ $font_groups = array();
+ }
+
+ $cubewp_group = array(
+ 'cubewp_setting_fonts' => esc_html__('CubeWP Setting Fonts', 'cubewp-framework'),
+ );
+
+ // Put CubeWP group first.
+ return $font_groups + $cubewp_group;
+ }
+
+ /**
+ * Add CubeWP font-family values into Elementor's existing typography control.
+ *
+ * @param array<string, string> $additional_fonts Elementor additional fonts.
+ * @return array<string, string>
+ */
+ public static function add_fonts_to_elementor_typography_control($additional_fonts)
+ {
+ if (!is_array($additional_fonts)) {
+ $additional_fonts = array();
+ }
+
+ $cwp_options = get_option('cwpOptions', array());
+ if (empty($cwp_options) || !is_array($cwp_options)) {
+ return $additional_fonts;
+ }
+
+ foreach ($cwp_options as $option_key => $option_value) {
+ if (!is_array($option_value) || empty($option_value['font-family'])) {
+ continue;
+ }
+
+ $safe_key = sanitize_key((string) $option_key);
+ if ($safe_key === '') {
+ continue;
+ }
+
+ $font_variable = 'var(--cwp-font-family-' . $safe_key . ')';
+ if (!isset($additional_fonts[$font_variable])) {
+ $additional_fonts[$font_variable] = 'cubewp_setting_fonts';
+ }
+ }
+
+ return $additional_fonts;
+ }
+
+ /**
+ * Relabel var(--cwp-font-family-*) options in Elementor editor dropdown.
+ *
+ * @return void
+ */
+ public static function enqueue_editor_font_option_label_script()
+ {
+ wp_enqueue_script(
+ 'cubewp-elementor-font-labels',
+ CWP_PLUGIN_URI . 'cube/assets/admin/js/cubewp-elementor-font-labels.js',
+ array('elementor-editor'),
+ CUBEWP_VERSION,
+ true
+ );
+ }
+
+
+ /**
+ * Register/override Elementor typography group control.
+ *
+ * @param ElementorControls_Manager $controls_manager Elementor controls manager.
+ * @return void
+ */
+ public static function register_typography_group_control_override($controls_manager)
+ {
+ if (!is_object($controls_manager) || !class_exists('CubeWp_Group_Control_Typography') || !class_exists('ElementorGroup_Control_Typography')) {
+ return;
+ }
+
+ $controls_manager->add_group_control(
+ ElementorGroup_Control_Typography::get_type(),
+ new CubeWp_Group_Control_Typography()
+ );
+ }
+
+ /**
+ * Print CubeWP typography CSS variables on :root.
+ *
+ * Variable examples:
+ * --cwp-font-family-h1
+ * --cwp-color-h1
+ * --cwp-color-primary_color
+ *
+ * @return void
+ */
+ public static function print_root_typography_css_variables()
+ {
+ $css_vars = self::get_root_css_variable_map();
+ if (empty($css_vars)) {
+ return;
+ }
+
+ $declarations = array();
+ foreach ($css_vars as $name => $value) {
+ $safe_name = sanitize_key((string) $name);
+ $safe_value = sanitize_text_field((string) $value);
+ if ($safe_name === '' || $safe_value === '') {
+ continue;
+ }
+ $declarations[] = '--' . $safe_name . ': ' . $safe_value;
+ }
+
+ if (empty($declarations)) {
+ return;
+ }
+
+ echo '<style id="cubewp-typography-root-vars">:root{' . esc_html(implode(';', $declarations)) . ';}</style>';
+ }
+
+ /**
+ * Build map of root CSS variables from CubeWP options.
+ *
+ * @return array<string, string>
+ */
+ private static function get_root_css_variable_map()
+ {
+ $cwp_options = get_option('cwpOptions', array());
+ $vars = array();
+
+ if (empty($cwp_options) || !is_array($cwp_options)) {
+ return $vars;
+ }
+
+ foreach ($cwp_options as $option_key => $option_value) {
+ $safe_key = sanitize_key((string) $option_key);
+ if ($safe_key === '') {
+ continue;
+ }
+
+ if (is_array($option_value)) {
+ if (!empty($option_value['font-family'])) {
+ $font_value = sanitize_text_field((string) $option_value['font-family']);
+ if ($font_value !== '') {
+ $vars['cwp-font-family-' . $safe_key] = $font_value;
+ }
+ }
+ if (!empty($option_value['color'])) {
+ $color_value = sanitize_text_field((string) $option_value['color']);
+ if ($color_value !== '' && self::is_color_like_value($color_value)) {
+