/** * Create License Input Form in the admin notices area for this plugin * * @since 1.0.0 * @return void */ function show_license_form_in_notices() { ?> <div id="<?php echo $this->_plugin_name_slug; ?> -plugin-license-wrap-in-notices" class="error wrap"> <p class="plugin-description"><?php echo __("Enter your license to complete installation of ", 'mp_core') . $this->_args['plugin_name']; ?> </p> <form method="post"> <input style="float:left; margin-right:10px;" id="<?php echo $this->_plugin_name_slug; ?> _license_key_in_notices" name="<?php echo $this->_plugin_name_slug; ?> _license_key" type="text" class="regular-text" value="<?php esc_attr_e($this->_license_key); ?> " /> <?php echo mp_core_true_false_light(array('value' => false, 'description' => __('This license is not valid! ', 'mp_core'))); ?> <?php wp_nonce_field($this->_plugin_name_slug . '_nonce', $this->_plugin_name_slug . '_nonce'); ?> <div class="mp-core-clearedfix"></div> <?php submit_button(__('Submit License', 'mp_core')); ?> </form> </div> <?php }
/** * Output the code which will display the license form on the plugins page * * @access public * @since 1.0.0 * @see MP_CORE_Plugin_Updater::parse_the_args() * @see get_option() * @see wp_nonce_field() * @see submit_button() * @return void */ function display_license() { //Parse the args $args = $this->parse_the_args($this->_args); //This filter can be used to change the API URL. Useful when calling for updates to the API site's plugins which need to be loaded from a separate URL (see mp_repo_mirror) $args['software_api_url'] = has_filter('mp_core_plugin_update_package_url') ? apply_filters('mp_core_plugin_update_package_url', $args['software_api_url']) : $args['software_api_url']; //API response $api_response = get_site_transient($args['software_name_slug']); //If a new license has just been submitted if (isset($_POST[$args['software_name_slug'] . '_license_key'])) { //Get license from $_POST var $license_key = $_POST[$args['software_name_slug'] . '_license_key']; } else { //Get license from database $license_key = get_option($args['software_name_slug'] . '_license_key'); } //Only verify the license if the transient is older than 7 days $check_licenses_transient_time = get_site_transient('mp_check_licenses_transient'); //If our transient is older than 30 days (2592000 seconds) if (time() > $check_licenses_transient_time + 2592000) { //reset the transient set_site_transient('mp_check_licenses_transient', time()); //Set args to Verfiy the License $verify_license_args = array('software_name' => $args['software_name'], 'software_api_url' => $args['software_api_url'], 'software_license_key' => $license_key, 'software_store_license' => true); //Double check license. Use the Verfiy License function to verify and store whether this license is valid or not mp_core_verify_license($verify_license_args); } //Get license status (set in verify license class) $status = get_option($args['software_name_slug'] . '_license_status_valid'); //Get license link: $get_license_link = !empty($api_response->get_license) ? '<a href="' . $api_response->get_license . '" target="_blank" >' . __('Get License', 'mp_core') . '</a>' : NULL; ?> <div id="<?php echo $args['software_name_slug']; ?> -plugin-license-wrap" class="wrap mp-core-plugin-license-wrap"> <p class="plugin-description"><?php echo __('Enter your license key to enable automatic updates.', 'mp_core'); ?> </p> <form method="post"> <input style="float:left; margin-right:10px;" id="<?php echo $args['software_name_slug']; ?> _license_key" name="<?php echo $args['software_name_slug']; ?> _license_key" type="text" class="regular-text" value="<?php esc_attr_e($license_key); ?> " /> <?php mp_core_true_false_light(array('value' => $status, 'description' => $status == true ? __('Auto-updates enabled.', 'mp_core') : __('This license is not valid! ', 'mp_core') . $get_license_link)); ?> <?php wp_nonce_field($args['software_name_slug'] . '_nonce', $args['software_name_slug'] . '_nonce'); ?> <br /> <?php submit_button(__('Submit License', 'mp_core')); ?> </form> </div> <?php }