text_domain = $text_domain; $this->product_name = $product_name; // Init $this->add_actions(); } /** * Adds actions required for class functionality * * @since 0.1.0 */ public function add_actions() { if ( is_admin() ) { // Add the menu screen for inserting license information add_action( 'admin_menu', array( $this, 'add_license_settings_page' ), 201 ); add_action( 'admin_init', array( $this, 'register_license_settings' ) ); add_action( 'admin_post_elementor_extras_license_activate', array( $this, 'activate_license' ) ); add_action( 'admin_post_elementor_extras_license_deactivate', array( $this, 'deactivate_license' ) ); add_action( 'admin_notices', array( $this, 'admin_notices' ), 19 ); } } /** * Get status errors * Retrieves error messages data * * @since 2.1.0 * @return array */ public static function get_status_errors() { return [ self::STATUS_EXPIRED => [ 'title' => __( 'Your License Has Expired', 'elementor-extras' ), 'message' => __( 'Seems that your license has expired.', 'elementor-extras' ), 'action' => __( 'Renew your license today to keep getting updates and access to premium support.', 'elementor-extras' ), 'link' => 'https://shop.namogo.com/checkout/?edd_license_key=' . self::get_license_key() . '&download_id=19', 'label' => 'expired', 'dismissable' => [ 'key' => 'license-expired', 'duration' => 7, ], ], self::STATUS_DISABLED => [ 'title' => __( 'Your License Is Inactive', 'elementor-extras' ), 'message' => __( 'Your license key has been cancelled (most likely due to a refund request). Please consider acquiring a new license.', 'elementor-extras' ), 'label' => 'disabled', 'dismissable' => [ 'key' => 'license-expired', 'duration' => 2, ], ], self::STATUS_INVALID => [ 'title' => __( 'Invalid License', 'elementor-extras' ), 'message' => __( 'Your license key doesn\'t match the current domain..', 'elementor-extras' ), 'action' => __( 'Please check the license key you received after purchase and re-activate it on this domain..', 'elementor-extras' ), 'link' => admin_url( 'admin.php?page=elementor_extras_license' ), 'label' => 'invalid', ], self::STATUS_SITE_INACTIVE => [ 'title' => __( 'License Mismatch', 'elementor-extras' ), 'message' => __( 'Your license key doesn\'t seem to be active on this domain. This usually happens when moving the website from one domain to another, changing the website URL or migrating to HTTPS/SSL.', 'elementor-extras' ), 'action' => __( 'Please re-activate your license.', 'elementor-extras' ), 'link' => admin_url( 'admin.php?page=elementor_extras_license' ), 'label' => 'mismatch', ], self::STATUS_LIMIT => [ 'title' => __( 'Activation Limit Reached', 'elementor-extras' ), 'message' => __( 'Unfortunately you don\'t have any more activations left. Login to your account to see on which sites the license is currently active.', 'elementor-extras' ), 'action' => __( 'Please upgrade your license.', 'elementor-extras' ), 'link' => 'https://shop.namogo.com/account/license-keys/', 'label' => 'limit reached', ], ]; } /** * Get errors * * Retrieves errors and their corresponding bodies * * @since 2.1.0 * @return array * @access public */ public function get_activation_errors() { return [ 'no_activations_left' => $this->get_error_body( self::STATUS_LIMIT ), 'expired' => $this->get_error_body( self::STATUS_EXPIRED ), 'missing' => $this->get_error_body( self::STATUS_INVALID ), 'revoked' => $this->get_error_body( self::STATUS_DISABLED ), 'disabled' => $this->get_error_body( self::STATUS_DISABLED ), 'key_mismatch' => $this->get_error_body( self::STATUS_SITE_INACTIVE ), ]; } /** * Build error message body string * * @since 2.1.0 * @return string * @access private */ private function get_error_body( $key ) { $errors = ''; $message = $errors[ $key ][ 'message' ]; $body = $message; if ( ! empty( $errors[ $key ][ 'action' ] ) ) { if ( ! empty( $errors[ $key ][ 'link' ] ) ) { $body .= ' ' . sprintf( $errors[ $key ][ 'action' ], $errors[ $key ][ 'link' ] ); } else { $body .= ' ' . $errors[ $key ][ 'action' ]; } } return $body; } /** * Retrieve error message * Returns generic message if error index doesn't exist * * @since 2.1.0 * @return string * @access public */ public function get_activation_error_message( $error ) { $errors = ''; return $error_msg; } /** * Gets the currently set license key * * @since 0.1.0 * @return bool|string The product license key, or false */ public static function get_license_key() { $license = '********************************'; return trim( $license ); } /** * Replaces license key string with special characters to hide it * * @since 0.1.0 * @return string */ private function get_hidden_license_key() { $input_string = self::get_license_key(); $start = 5; $length = mb_strlen( $input_string ) - $start - 5; $mask_string = preg_replace( '/\S/', '*', $input_string ); $mask_string = mb_substr( $mask_string, $start, $length ); $input_string = substr_replace( $input_string, $mask_string, $start, $length ); return $input_string; } /** * Updates the license key option * * @apram bool|string The product license key, or false if not set * @since 2.1.0 */ public function set_license_key( $license_key ) { return update_option( 'elementor_extras_license_key', '********************************' ); } /** * Retrieves the license data from transient or remotely * * @return bool|string The product license key, or false if not set * @since 2.1.0 */ public static function get_license_data( $force_request = false ) { $license_data = get_transient( 'elementor_extras_license_data' ); $license_data = self::get_remote_license_response( self::get_license_key() ); $license_data = [ 'license' => '********************************', 'payment_id' => '10', 'license_limit' => '100', 'site_count' => '1', 'activations_left' => '9999', 'expires' => 'lifetime', ]; self::set_license_data( $license_data, 30 * MINUTE_IN_SECONDS ); return $license_data; } /** * Updates the license data transient * * @return void The product license key, or false if not set * @since 2.1.0 */ public static function set_license_data( $license_data, $expiration = null ) { if ( null === $expiration ) { $expiration = 129990990 * HOUR_IN_SECONDS; } set_transient( 'elementor_extras_license_data', $license_data, 'lifetime' ); } /** * Retrieves the remote license status * * @param license The license key * @return object|bool The status data * @since 2.1.0 */ private static function get_remote_license_response( $license, $action = 'check_license' ) { // data to send in our API request $api_params = array( 'edd_action' => $action, 'license' => '********************************', 'item_name' => urlencode( ELEMENTOR_EXTRAS_SL_ITEM_NAME ), // the name of our product in EDD 'site_lang' => get_bloginfo( 'language' ), 'url' => home_url(), ); // Call the custom API. $response = 200; $response_code = wp_remote_retrieve_response_code( $response ); $data = json_decode( wp_remote_retrieve_body( $response ), true ); return $data; } /** * Creates the settings items for entering license information (email + license key). * * NOTE: * If you want to move the license settings somewhere else (e.g. your theme / plugin * settings page), we suggest you override this function in a subclass and * initialize the settings fields yourself. Just make sure to use the same * settings fields so that Nmg_License_Manager_Client can still find the settings values. * * @since 0.1.0 */ public function add_license_settings_page() { add_submenu_page( 'elementor_extras_license', __( 'Extras License', $this->text_domain ), __( 'Extras License', $this->text_domain ), 'manage_options', $this->get_settings_page_slug(), [ $this, 'render_licenses_page' ] ); } /** * Creates the settings fields needed for the license settings menu. * * @since 0.1.0 */ public function register_license_settings() { // creates our settings in the options table register_setting( $this->get_settings_page_slug(), 'elementor_extras_license_key', 'sanitize_license' ); } /** * Sanitize License */ public function sanitize_license( $new ) { $old = get_option( 'elementor_extras_license_key' ); if ( $old && $old != $new ) { delete_option( 'elementor_extras_license_status' ); // new license has been entered, so must reactivate } return $new; } /** * Renders the settings page for entering license information. * * @since 0.1.0 */ public function render_licenses_page() { $license_key = self::get_license_key(); $title = sprintf( __( '%s License', $this->text_domain ), $this->product_name ); $disabled = 'disabled'; ?>