-
-
Save sumonst21/bdb0fe2276ef25b3d398458c8f1ac1cc to your computer and use it in GitHub Desktop.
Add EDD license system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $test_license = ''; | |
| $license_data = ''; | |
| define( 'DT_KEY', 'edd_sample_theme_license_key_status'); | |
| define( 'EDD_SL_STORE_URL', 'https://codenpy.com' ); /* IMPORTANT: Do not modify this line of code, the theme could stop working correctly */ | |
| define( 'EDD_SL_THEME_NAME', 'Industrue - Industrial & Factory WordPress Theme' ); /* IMPORTANT: Do not modify this line of code, the theme could stop working correctly */ | |
| if ( !class_exists( 'EDD_SL_Theme_Updater' ) ) { | |
| include( dirname( __FILE__ ) . '/edd-class-file-here.php' ); | |
| } | |
| function edd_sl_sample_theme_updater() { | |
| $test_license = trim( get_option( 'edd_sample_theme_license_key' ) ); | |
| $edd_updater = new EDD_SL_Theme_Updater( array( | |
| 'remote_api_url' => EDD_SL_STORE_URL, | |
| 'version' => '1.0.0', /* IMPORTANT: Do not modify this line of code, the theme could stop working correctly */ | |
| 'license' => $test_license, | |
| 'item_name' => EDD_SL_THEME_NAME, | |
| 'author' => 'codenpy') ); /* IMPORTANT: Do not modify this line of code, the theme could stop working correctly */ | |
| } | |
| add_action('admin_menu', 'add_psyplay_license_menu'); | |
| function add_psyplay_license_menu() { | |
| add_theme_page('Theme License', 'Theme License', 'manage_options', 'psythemes'); | |
| } | |
| add_action( 'admin_init', 'edd_sl_sample_theme_updater' ); | |
| function edd_sample_theme_license_menu() { | |
| add_menu_page( 'License', 'License', 'manage_options', 'psythemes', 'edd_sample_theme_license_page','dashicons-admin-network'); | |
| } | |
| add_action('admin_menu', 'edd_sample_theme_license_menu'); | |
| function edd_sample_theme_license_page() { | |
| $license = get_option( 'edd_sample_theme_license_key' ); | |
| $status = get_option( 'edd_sample_theme_license_key_status' ); | |
| ?> | |
| <div id="acera-content" class="wrap tab-content" style="display: block;"> | |
| <div class="acera-settings-headline"> | |
| <a href="https://psythemes.com/" target="_blank"> | |
| <img class="psythemes" src="<?php echo get_stylesheet_directory_uri()."/includes/core/framework/"; ?>images/logo.png"> | |
| </a> | |
| </div> | |
| <form method="post" action="options.php"> | |
| <?php settings_fields('edd_sample_theme_license'); ?> | |
| <table class="form-table"> | |
| <tbody> | |
| <tr valign="top"> | |
| <th scope="row" valign="top"> | |
| <?php _e('License Key','psythemes'); ?> | |
| </th> | |
| <td> | |
| <input id="edd_sample_theme_license_key" name="edd_sample_theme_license_key" type="text" class="regular-text mundotxt" value="<?php echo esc_attr( $license ); ?>" /> | |
| <label class="description" for="edd_sample_theme_license_key"><?php _e('Enter your license key','psythemes'); ?></label> | |
| </td> | |
| </tr> | |
| <?php if( false !== $license ) { ?> | |
| <tr valign="top"> | |
| <th scope="row" valign="top"><?php _e('License Status','psythemes'); ?></th> | |
| <td> | |
| <?php if( $status !== false && $status == 'valid' ) { ?> | |
| <span class="mundo"><span class="dashicons dashicons-admin-network"></span> <?php _e('Active','psythemes'); ?><br></span> | |
| <i class="cmsxx"><?php echo $_SERVER['HTTP_HOST']; ?></i> | |
| <?php wp_nonce_field( 'edd_sample_nonce', 'edd_sample_nonce' ); ?> | |
| <input type="submit" class="button-secondary mundobt" name="edd_theme_license_deactivate" value="<?php _e('Deactivate License','psythemes'); ?>"/> | |
| <?php } else { wp_nonce_field( 'edd_sample_nonce', 'edd_sample_nonce' ); ?> | |
| <span class="error"><span class="dashicons dashicons-dismiss"></span><?php _e('Inactive','psythemes'); ?></span> | |
| <i class="cmsxx"><?php echo $_SERVER['HTTP_HOST']; ?></i> | |
| <input type="submit" class="button-secondary mundobt" name="edd_theme_license_activate" value="<?php _e('Activate License','psythemes'); ?>"/> | |
| <?php } ?> | |
| </td> | |
| </tr> | |
| <?php } ?> | |
| </tbody> | |
| </table> | |
| <?php submit_button(); ?> | |
| </form> | |
| <?php | |
| } | |
| function edd_sample_theme_register_option() { | |
| register_setting('edd_sample_theme_license', 'edd_sample_theme_license_key', 'edd_theme_sanitize_license' ); | |
| } | |
| add_action('admin_init', 'edd_sample_theme_register_option'); | |
| function edd_theme_sanitize_license( $new ) { | |
| $old = get_option( 'edd_sample_theme_license_key' ); | |
| if( $old && $old != $new ) { | |
| delete_option( 'edd_sample_theme_license_key_status' ); | |
| } | |
| return $new; | |
| } | |
| function edd_sample_theme_activate_license() { | |
| if( isset( $_POST['edd_theme_license_activate'] ) ) { | |
| if( ! check_admin_referer( 'edd_sample_nonce', 'edd_sample_nonce' ) ) | |
| return; | |
| global $wp_version; | |
| $license = trim( get_option( 'edd_sample_theme_license_key' ) ); | |
| $api_params = array( | |
| 'edd_action' => 'activate_license', | |
| 'license' => $license, | |
| 'item_name' => urlencode( EDD_SL_THEME_NAME ) | |
| ); | |
| $response = wp_remote_get( add_query_arg( $api_params, EDD_SL_STORE_URL ), array( 'timeout' => 15, 'sslverify' => false ) ); | |
| if ( is_wp_error( $response ) ) | |
| return false; | |
| $license_data = json_decode( wp_remote_retrieve_body( $response ) ); | |
| update_option( 'edd_sample_theme_license_key_status', $license_data->license ); | |
| } | |
| } | |
| add_action('admin_init', 'edd_sample_theme_activate_license'); | |
| function edd_sample_theme_deactivate_license() { | |
| if( isset( $_POST['edd_theme_license_deactivate'] ) ) { | |
| if( ! check_admin_referer( 'edd_sample_nonce', 'edd_sample_nonce' ) ) | |
| return; | |
| $license = trim( get_option( 'edd_sample_theme_license_key' ) ); | |
| $api_params = array( | |
| 'edd_action'=> 'deactivate_license', | |
| 'license' => $license, | |
| 'item_name' => urlencode( EDD_SL_THEME_NAME ) | |
| ); | |
| $response = wp_remote_get( add_query_arg( $api_params, EDD_SL_STORE_URL ), array( 'timeout' => 15, 'sslverify' => false ) ); | |
| if ( is_wp_error( $response ) ) | |
| return false; | |
| $license_data = json_decode( wp_remote_retrieve_body( $response ) ); | |
| if( $license_data->license == 'deactivated' ) | |
| delete_option( 'edd_sample_theme_license_key_status' ); | |
| } | |
| } | |
| add_action('admin_init', 'edd_sample_theme_deactivate_license'); | |
| function edd_sample_theme_check_license() { | |
| global $wp_version; | |
| $license = trim( get_option( 'edd_sample_theme_license_key' ) ); | |
| $api_params = array( | |
| 'edd_action' => 'check_license', | |
| 'license' => $license, | |
| 'item_name' => urlencode( EDD_SL_THEME_NAME ) | |
| ); | |
| $response = wp_remote_get( add_query_arg( $api_params, EDD_SL_STORE_URL ), array( 'timeout' => 15, 'sslverify' => false ) ); | |
| if ( is_wp_error( $response ) ) | |
| return false; | |
| $license_data = json_decode( wp_remote_retrieve_body( $response ) ); | |
| if( $license_data->license == 'valid' ) { | |
| return true; | |
| } | |
| } | |
| // function that check is license VALID or NOT | |
| if (edd_sample_theme_check_license()) { | |
| //do whatever you want to do if license is valid | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment