init_updates( UR_PLUGIN_FILE ); } /** * Init the updater. * * @param string $_plugin_file Plugin File. */ public function init_updates( $_plugin_file ) { $this->plugin_file = $_plugin_file; $this->plugin_slug = str_replace( '.php', '', basename( $this->plugin_file ) ); $this->plugin_name = basename( dirname( $this->plugin_file ) ) . '/' . $this->plugin_slug . '.php'; register_activation_hook( $this->plugin_name, array( $this, 'plugin_activation' ), 10 ); register_deactivation_hook( $this->plugin_name, array( $this, 'plugin_deactivation' ), 10 ); add_filter( 'block_local_requests', '__return_false' ); add_action( 'admin_init', array( $this, 'admin_init' ) ); // Include required files. include_once __DIR__ . '/admin/updater/class-ur-plugin-updater-api.php'; } /** * Run on admin init. */ public function admin_init() { $this->load_errors(); add_action( 'shutdown', array( $this, 'store_errors' ) ); $this->api_key = get_option( $this->plugin_slug . '_license_key' ); $this->plugin_data = get_plugin_data( $this->plugin_file ); // Check if pro is activated to display license notices. if ( ( file_exists( WP_PLUGIN_DIR . '/user-registration-pro/user-registration.php' ) && is_plugin_active( 'user-registration-pro/user-registration.php' ) ) && current_user_can( 'update_plugins' ) ) { $this->plugin_requests(); add_action( 'in_admin_header', array( $this, 'user_registration_upgrade_to_pro_notice' ) ); $this->plugin_license_view(); } $message = get_option( 'user_registration_failed_installing_extensions_message', '' ); if ( $message ) { add_action( 'admin_notices', array( $this, 'user_registration_failed_extension_install' ) ); } } /** * Process plugin requests. */ private function plugin_requests() { if ( ! current_user_can( 'manage_options' ) ) { return false; } if ( isset( $_POST['ur_license_nonce'] ) ) { if ( ! wp_verify_nonce( $_POST['ur_license_nonce'], '_ur_license_nonce' ) ) { return; } if ( ! empty( $_POST[ $this->plugin_slug . '_license_key' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $this->activate_license_request(); } elseif ( ! empty( $_POST['download_user_registration_pro'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $this->install_extension(); wp_redirect( remove_query_arg( array( 'deactivated_license', $this->plugin_slug . '_deactivate_license' ), add_query_arg( 'activated_license', $this->plugin_slug ) ) ); exit; } } if ( isset( $_GET['_wpnonce'] ) ) { if ( ! wp_verify_nonce( $_GET['_wpnonce'], '_ur_license_nonce' ) ) { return; } if ( ! empty( $_GET[ $this->plugin_slug . '_deactivate_license' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $this->deactivate_license_request(); } elseif ( ! empty( $_GET[ 'dismiss-' . sanitize_title( $this->plugin_slug ) ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended update_option( $this->plugin_slug . '_hide_key_notice', 1 ); } elseif ( ! empty( $_GET['activated_license'] ) && $_GET['activated_license'] === $this->plugin_slug ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $this->add_notice( array( $this, 'activated_key_notice' ) ); } elseif ( ! empty( $_GET['deactivated_license'] ) && $_GET['deactivated_license'] === $this->plugin_slug ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $this->add_notice( array( $this, 'deactivated_key_notice' ) ); } } } /** * Activate a license request. */ private function activate_license_request() { $license_key = sanitize_text_field( $_POST[ $this->plugin_slug . '_license_key' ] ); // phpcs:ignore if ( $this->activate_license( $license_key ) ) { $this->install_extension(); wp_redirect( remove_query_arg( array( 'deactivated_license', $this->plugin_slug . '_deactivate_license' ), add_query_arg( 'activated_license', $this->plugin_slug ) ) ); exit; } else { wp_redirect( remove_query_arg( array( 'activated_license', 'deactivated_license', $this->plugin_slug . '_deactivate_license' ) ) ); exit; } } /** * Install Extensions Action. */ public function install_extension() { $status = ur_install_extensions( 'User Registration PRO', 'user-registration-pro' ); if ( $status['success'] ) { add_action( 'admin_notices', array( $this, 'user_registration_extension_download_success_notice' ) ); } else { add_option( 'user_registration_failed_installing_extensions_message', $status['message'] ); } } /** * Deactivate a license request */ private function deactivate_license_request() { $this->deactivate_license(); wp_redirect( remove_query_arg( array( 'activated_license', $this->plugin_slug . '_deactivate_license' ), add_query_arg( 'deactivated_license', $this->plugin_slug ) ) ); exit; } /** * Display plugin license view. */ private function plugin_license_view() { add_filter( 'plugin_action_links_' . $this->plugin_name, array( $this, 'plugin_action_links' ) ); add_action( 'admin_notices', array( $this, 'user_registration_error_notices' ) ); } /** * Add notices * * @param string $callback Callback function. */ private function add_notice( $callback ) { add_action( 'admin_notices', $callback ); add_action( 'network_admin_notices', $callback ); } /** * Add an error message * * @param string $message Your error message. * @param string $type Type of error message. */ public function add_error( $message, $type = '' ) { if ( $type ) { $this->errors[ $type ] = $message; } else { $this->errors[] = $message; } } /** * Load errors from option */ public function load_errors() { $this->errors = get_option( $this->plugin_slug . '_errors', array() ); } /** * Store errors in option */ public function store_errors() { if ( count( $this->errors ) > 0 ) { update_option( $this->plugin_slug . '_errors', $this->errors ); } else { delete_option( $this->plugin_slug . '_errors' ); } } /** * Deprecation function for error notices. * * @deprecated 2.0.6 */ public function error_notices() { ur_deprecated_function( 'UR_Admin_Profile::error_notices', '1.4.1', 'UR_Plugin_Updater::user_registration_error_notices' ); } /** * Output errors */ public function user_registration_error_notices() { if ( ! empty( $this->errors ) ) { foreach ( $this->errors as $key => $error ) { include __DIR__ . '/admin/notifications/views/html-notice-error.php'; if ( 'invalid_key' !== $key && did_action( 'all_admin_notices' ) ) { unset( $this->errors[ $key ] ); } } } } /** * Ran on plugin-activation. */ public function plugin_activation() { delete_option( $this->plugin_slug . '_hide_key_notice' ); } /** * Ran on plugin-deactivation. */ public function plugin_deactivation() { delete_option( 'user_registration_activated' ); $this->deactivate_license(); } /** * Show the input form for the license key. * * @param string $plugin_file Plugin File. */ public function plugin_license_form( $plugin_file ) { $slug = $this->plugin_slug; if ( is_plugin_active( 'user-registration-pro/user-registration.php' ) ) { $slug .= '-pro'; } if ( strtolower( basename( dirname( $plugin_file ) ) ) === strtolower( $slug ) ) { include_once __DIR__ . '/admin/views/html-license-form.php'; } } /** * Display action links in the Plugins list table. * * @param array $actions Actions. * @return array */ public function plugin_action_links( $actions ) { $new_actions = array(); if ( ! $this->api_key ) { $new_actions['activate_license_settings'] = '' . __( 'Activate License', 'user-registration' ) . ''; } else { $new_actions['deactivate_license'] = '' . __( 'Deactivate License', 'user-registration' ) . ''; } return array_merge( $actions, $new_actions ); } /** * Try to activate a license. * * @param string $license_key License Key. * * @throws Exception Throws license activation failed error message. */ public function activate_license( $license_key ) { try { if ( empty( $license_key ) ) { throw new Exception( 'Please enter your license key' ); } $activate_results = json_decode( UR_Updater_Key_API::activate( array( 'license' => $license_key, ) ) ); // Update activate results. update_option( $this->plugin_slug . '_license_active', $activate_results ); if ( ! empty( $activate_results ) && is_object( $activate_results ) ) { if ( isset( $activate_results->error_code ) ) { throw new Exception( $activate_results->error ); } elseif ( false === $activate_results->success ) { switch ( $activate_results->error ) { case 'expired': $error_msg = wp_kses_post( sprintf( __( 'The provided license key expired on %1$s. Please renew your license key.', 'user-registration' ), esc_html( date_i18n( get_option( 'date_format' ) ), esc_html( strtotime( $activate_results->expires, current_time( 'timestamp' ) ) ) ), esc_url( 'https://wpeverest.com/checkout/?edd_license_key=' . $license_key . '&utm_campaign=admin&utm_source=licenses&utm_medium=expired' ) ) ); // phpcs:ignore. break; case 'revoked': /* translators: %s: Contact Support URL */ $error_msg = wp_kses_post( sprintf( __( 'The provided license key has been disabled. Please contact support for more information.', 'user-registration' ), 'https://wpeverest.com/contact?utm_campaign=admin&utm_source=licenses&utm_medium=revoked' ) ); break; case 'missing': /* translators: %s: Account Page URL */ $error_msg = wp_kses_post( sprintf( __( 'The provided license is invalid. Please visit your account page and verify it.', 'user-registration' ), 'https://wpeverest.com/my-account?utm_campaign=admin&utm_source=licenses&utm_medium=missing' ) ); break; case 'invalid': case 'site_inactive': /* translators: %s: Account Page URL */ $error_msg = wp_kses_post( sprintf( __( 'The provided license is not active for this URL. Please visit your account page to manage your license key URLs.', 'user-registration' ), 'https://wpeverest.com/my-account?utm_campaign=admin&utm_source=licenses&utm_medium=missing' ) ); break; case 'invalid_item_id': case 'item_name_mismatch': /* translators: %s: Plugin Name */ $error_msg = wp_kses_post( sprintf( __( 'This appears to be an invalid license key for %s.', 'user-registration' ), esc_html( $this->plugin_data['Name'] ) ) ); break; case 'no_activations_left': /* translators: %s: Pricing Page URL */ $error_msg = wp_kses_post( sprintf( __( 'The provided license key has reached its activation limit. Please View possible upgrades now.', 'user-registration' ), 'https://wpeverest.com/my-account/' ) ); break; case 'license_not_activable': $error_msg = __( 'The key you entered belongs to a bundle, please use the product specific license key.', 'user-registration' ); break; default: /* translators: %s: Contact Support URL */ $error_msg = wp_kses_post( sprintf( __( 'The provided license key could not be found. Please contact support for more information.', 'user-registration' ), 'https://wpeverest.com/contact/' ) ); break; } /* translators: %s: Error Message */ throw new Exception( wp_kses_post( sprintf( __( 'Activation error: %s', 'user-registration' ), wp_kses_post( $error_msg ) ) ) ); } elseif ( 'valid' === $activate_results->license ) { $this->api_key = $license_key; $this->errors = array(); update_option( $this->plugin_slug . '_license_key', $this->api_key ); delete_option( $this->plugin_slug . '_errors' ); $license_data = json_decode( UR_Updater_Key_API::check( array( 'license' => $this->api_key, ) ) ); if ( ! empty( $license_data->item_name ) ) { $license_data->item_plan = trim( strtolower( str_replace( 'LifeTime', '', str_replace( 'User Registration', '', $license_data->item_name ) ) ) ); set_transient( 'ur_pro_license_plan', $license_data, WEEK_IN_SECONDS ); } return true; } throw new Exception( 'License could not activate. Please contact support.' ); } else { throw new Exception( 'Connection failed to the License Key API server - possible server issue.' ); } } catch ( Exception $e ) { $this->add_error( $e->getMessage() ); return false; } } /** * Deactivate a license. */ public function deactivate_license() { if ( get_transient( 'user_registration_pro_activated' ) ) { return; } $reset = UR_Updater_Key_API::deactivate( array( 'license' => $this->api_key, ) ); delete_option( $this->plugin_slug . '_errors' ); delete_option( $this->plugin_slug . '_license_key' ); delete_option( $this->plugin_slug . '_license_active' ); delete_transient( 'ur_pro_license_plan' ); // Reset huh? $this->errors = array(); $this->api_key = ''; } /** * Show a notice prompting the user to update. */ public function key_notice() { if ( count( $this->errors ) === 0 && ! get_option( $this->plugin_slug . '_hide_key_notice' ) ) { include __DIR__ . '/admin/notifications/views/html-notice-key-unvalidated.php'; } } /** * Activation success notice. */ public function activated_key_notice() { include __DIR__ . '/admin/notifications/views/html-notice-key-activated.php'; } /** * Dectivation success notice. */ public function deactivated_key_notice() { include __DIR__ . '/admin/notifications/views/html-notice-key-deactivated.php'; } /** * Display error message when extension installation fails. * * @since 2.0.6 */ public function user_registration_failed_extension_install() { $ur_pro_plugins_path = WP_PLUGIN_DIR . '/user-registration-pro/user-registration.php'; $message = get_option( 'user_registration_failed_installing_extensions_message', '' ); if ( ! file_exists( $ur_pro_plugins_path ) ) { $message = $message . esc_html__( ' Please manually download User Registration PRO.', 'user-registration' ); echo '

' . wp_kses_post( $message ) . '

'; } elseif ( ! is_plugin_active( 'user-registration-pro/user-registration.php' ) ) { $message = esc_html__( ' Please manually activate User Registration PRO.', 'user-registration' ); echo '

' . wp_kses_post( $message ) . '

'; } delete_option( 'user_registration_failed_installing_extensions_message' ); } /** * Display upgrade to PRO notice. * * @since 2.1.0 */ public function user_registration_upgrade_to_pro_notice() { // Donot show notice on form builder page. if ( isset( $_REQUEST['page'] ) && 'add-new-registration' === $_REQUEST['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return; } $license_key = get_option( $this->plugin_slug . '_license_key' ); $ur_pro_plugins_path = WP_PLUGIN_DIR . '/user-registration-pro/user-registration.php'; $link = ''; $content = ''; if ( $license_key ) { $content .= sprintf( __( 'If you have active premium license of User Registration, please click button below to install and activate User Registration Pro. Going forward User Registration Pro is necessary for smooth running of premium addons of User Registration that you are currently using.', 'user-registration' ) ); $link .= ''; $link .= ''; } else { $content .= sprintf( '

%1$s, %2$s

', __( 'If you already have an active license key.', 'user-registration' ), __( 'please activate the key.', 'user-registration' ) ); $content .= sprintf( '

%1$s, %2$s

', __( 'If you do not have active premium license of User Registration', 'user-registration' ), __( 'please purchase premium license. Going forward active premium license will be vital for smooth running of premium addons of User Registration that you are currently using.', 'user-registration' ) ); $link .= '
  • ' . __( 'Purchase Premium License', 'user-registration' ) . '
  • '; $link .= '
  • ' . __( 'Activate License Key', 'user-registration' ) . '
  • '; } // If Pro is active do not show upgrade to pro notice but show update addons notice if not upto date. if ( is_plugin_active( 'user-registration-pro/user-registration.php' ) ) { $updated_addons_list = array( 'user-registration-advanced-fields/user-registration-advanced-fields.php' => array( 'title' => 'User Registration Advanced Fields', 'version' => '1.4.7', 'notice_slug' => 'user_registration_advanced_fields_admin_notice', ), 'user-registration-conditional-logic/user-registration-conditional-logic.php' => array( 'title' => 'User Registration Conditional Logic', 'version' => '1.3.0', 'notice_slug' => 'user_registration_conditional_logic_admin_notice', ), 'user-registration-customize-my-account/user-registration-customize-my-account.php' => array( 'title' => 'User Registration Customize My Account', 'version' => '1.1.4', 'notice_slug' => 'user_registration_customize_my_account_admin_notice', ), 'user-registration-email-templates/user-registration-email-templates.php' => array( 'title' => 'User Registration Email Templates', 'version' => '1.0.4', 'notice_slug' => 'user_registration_email_templates_admin_notice', ), 'user-registration-file-upload/user-registration-file-upload.php' => array( 'title' => 'User Registration File Upload', 'version' => '1.2.4', 'notice_slug' => 'user_registration_file_upload_admin_notice', ), 'user-registration-mailchimp/user-registration-mailchimp.php' => array( 'title' => 'User Registration MailChimp', 'version' => '1.3.0', 'notice_slug' => 'urmc_admin_notices', ), 'user-registration-pdf-form-submission/user-registration-pdf-form-submission.php' => array( 'title' => 'User Registration PDF Form Submission', 'version' => '1.0.8', 'notice_slug' => 'user_registration_pdf_admin_notice', ), 'user-registration-social-connect/user-registration-social-connect.php' => array( 'title' => 'User Registration Social Connect', 'version' => '1.3.7', 'notice_slug' => 'user_registration_social_connect_admin_notice', ), 'user-registration-woocommerce/user-registration-woocommerce.php' => array( 'title' => 'User Registration WooCommerce', 'version' => '1.2.7', 'notice_slug' => 'user_registration_woocommerce_admin_notice', ), ); $plugins = get_plugins(); $show_notice = false; // Remove user registration required notice in outdated version of addon when pro is installed. global $wp_filter; $update_addon_content = '

    Please update all the listed addons to the latest version.

      '; foreach ( $updated_addons_list as $addon_file => $addon_detail ) { if ( is_plugin_active( $addon_file ) && $plugins[ $addon_file ]['Version'] < $addon_detail['version'] ) { $show_notice = true; $update_addon_content .= '
    1. ' . $addon_detail['title'] . ' v( ' . $addon_detail['version'] . ' )
    2. '; if ( ! empty( $wp_filter['admin_notices']->callbacks ) && is_array( $wp_filter['admin_notices']->callbacks ) ) { foreach ( $wp_filter['admin_notices']->callbacks as $priority => $hooks ) { if ( ! empty( $wp_filter['admin_notices']->callbacks[ $priority ][ $addon_detail['notice_slug'] ] ) ) { unset( $wp_filter['admin_notices']->callbacks[ $priority ][ $addon_detail['notice_slug'] ] ); } } } } } $update_addon_content .= '
    '; // Display update addons notice. if ( $show_notice ) { ?>

    Update all addons of User Registration!!', 'user-registration' ) ) ); ?>

    User Registration Addons are outdated. Please update the outdated addons to the latest version for the User Registration Pro plugin to work correctly.
    ', 'user-registration' ) ) ); ?>

    Upgrade To PRO!!', 'user-registration' ) ) ); ?>

    ', 'user-registration' ) ) ); ?>

    ' . wp_kses_post( $content ) . '

    ' : wp_kses_post( $content ); ?>