| @@ -5,11 +5,11 @@ | ||
| 5 | 5 | * @since 1.0.0 |
| 6 | 6 | * @package WPComplete |
| 7 | 7 | * |
| 8 | 8 | * @wordpress-plugin |
| 9 | - * Plugin Name: WPComplete (FREE) | |
| 10 | - * Description: A WordPress plugin that helps your students keep track of their progress through your course or membership site. <a href="https://wpcomplete.co">Upgrade to the PRO version</a> to unlock features. | |
| 11 | - * Version: 1.2.0 | |
| 9 | + * Plugin Name: WPComplete | |
| 10 | + * Description: A WordPress plugin that helps your students keep track of their progress through your course or membership site. | |
| 11 | + * Version: 2.3.0 | |
| 12 | 12 | * Author: Zack Gilbert and Paul Jarvis |
| 13 | 13 | * Author URI: https://wpcomplete.co |
| 14 | 14 | * License: GPL-2.0+ |
| 15 | 15 | * License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| @@ -18,23 +18,90 @@ | ||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | // If this file is called directly, abort. |
| 21 | 21 | if ( ! defined( 'WPINC' ) ) { |
| 22 | - die; | |
| 22 | + die; | |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | +// Fix for 5.3. This variable wasn't added until 5.4. | |
| 26 | +if ( ! defined( 'JSON_UNESCAPED_UNICODE' ) ) { | |
| 27 | + define( 'JSON_UNESCAPED_UNICODE', 256 ); | |
| 28 | +} | |
| 29 | + | |
| 25 | 30 | // Define some variables we will use throughout the plugin: |
| 26 | 31 | define( 'WPCOMPLETE_STORE_URL', 'https://wpcomplete.co' ); |
| 27 | 32 | define( 'WPCOMPLETE_PRODUCT_NAME', 'WPComplete' ); |
| 28 | 33 | define( 'WPCOMPLETE_PREFIX', 'wpcomplete' ); |
| 34 | +define( 'WPCOMPLETE_IS_ACTIVATED', wpcomplete_license_is_valid() ); | |
| 29 | 35 | |
| 30 | 36 | /** |
| 37 | + * PREMIUM: | |
| 38 | + * The code that runs to determine if a premium license is valid. | |
| 39 | + */ | |
| 40 | +function wpcomplete_license_is_valid() { | |
| 41 | + if ( !is_production() ) return true; | |
| 42 | + | |
| 43 | + $result = get_option( WPCOMPLETE_PREFIX . '_license_status' ); | |
| 44 | + | |
| 45 | + if ( ( false === $result ) || ( $result === 'valid' ) ) { | |
| 46 | + $store_url = WPCOMPLETE_STORE_URL; | |
| 47 | + $item_name = WPCOMPLETE_PRODUCT_NAME; | |
| 48 | + $license = get_option( WPCOMPLETE_PREFIX . '_license_key' ); | |
| 49 | + | |
| 50 | + if ( !$license || empty( $license ) ) | |
| 51 | + return false; | |
| 52 | + | |
| 53 | + $api_params = array( | |
| 54 | + 'edd_action' => 'check_license', | |
| 55 | + 'license' => $license, | |
| 56 | + 'item_name' => urlencode( $item_name ) | |
| 57 | + ); | |
| 58 | + | |
| 59 | + $response = wp_remote_get( add_query_arg( $api_params, $store_url ), array( 'timeout' => 15, 'sslverify' => false ) ); | |
| 60 | + | |
| 61 | + if ( is_wp_error( $response ) ) | |
| 62 | + return false; | |
| 63 | + | |
| 64 | + $license_data = json_decode( wp_remote_retrieve_body( $response ) ); | |
| 65 | + $result = false; | |
| 66 | + | |
| 67 | + if ($license_data->license == 'valid') { | |
| 68 | + update_option( WPCOMPLETE_PREFIX . '_license_status', $license_data->expires); | |
| 69 | + $result = $license_data->expires; | |
| 70 | + } | |
| 71 | + } | |
| 72 | + | |
| 73 | + return ( $result !== false ) && ( strtotime($result) > time() ); | |
| 74 | +} | |
| 75 | + | |
| 76 | +function is_production() { | |
| 77 | + if ( defined( 'WPCOM_IS_VIP_ENV' ) && ( true === WPCOM_IS_VIP_ENV ) ) return true; | |
| 78 | + if ( $_SERVER['SERVER_NAME'] == 'localhost' ) return false; | |
| 79 | + if ( $_SERVER['SERVER_NAME'] == '127.0.0.1' ) return false; | |
| 80 | + if ( substr( $_SERVER['SERVER_NAME'], -4 ) == '.dev' ) return false; | |
| 81 | + if ( substr( $_SERVER['SERVER_NAME'], -5 ) == '.test' ) return false; | |
| 82 | + if ( substr( $_SERVER['SERVER_NAME'], -6 ) == '.local' ) return false; | |
| 83 | + return true; | |
| 84 | +} | |
| 85 | + | |
| 86 | +/** | |
| 87 | + * The code that checks for plugin updates. | |
| 88 | + * Borrowed from: https://github.com/YahnisElsts/plugin-update-checker | |
| 89 | + */ | |
| 90 | +require plugin_dir_path( __FILE__ ) . 'includes/plugin-update-checker-3.1.php'; | |
| 91 | +$myUpdateChecker = PucFactory::buildUpdateChecker( | |
| 92 | + 'https://wpcomplete.co/premium.json', | |
| 93 | + //'https://wpcomplete.co/free.json', | |
| 94 | + __FILE__ | |
| 95 | +); | |
| 96 | + | |
| 97 | +/** | |
| 31 | 98 | * The code that runs during plugin activation. |
| 32 | 99 | * This action is documented in includes/class-wpcomplete-activator.php |
| 33 | 100 | */ |
| 34 | 101 | function activate_wpcomplete() { |
| 35 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wpcomplete-activator.php'; | |
| 36 | - WPComplete_Activator::activate(); | |
| 102 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wpcomplete-activator.php'; | |
| 103 | + WPComplete_Activator::activate(); | |
| 37 | 104 | } |
| 38 | 105 | |
| 39 | 106 | /** |
| 40 | 107 | * The code that runs during plugin deactivation. |
| @@ -40,10 +107,10 @@ | ||
| 40 | 107 | * The code that runs during plugin deactivation. |
| 41 | 108 | * This action is documented in includes/class-wpcomplete-deactivator.php |
| 42 | 109 | */ |
| 43 | 110 | function deactivate_wpcomplete() { |
| 44 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wpcomplete-deactivator.php'; | |
| 45 | - WPComplete_Deactivator::deactivate(); | |
| 111 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wpcomplete-deactivator.php'; | |
| 112 | + WPComplete_Deactivator::deactivate(); | |
| 46 | 113 | } |
| 47 | 114 | |
| 48 | 115 | register_activation_hook( __FILE__, 'activate_wpcomplete' ); |
| 49 | 116 | register_deactivation_hook( __FILE__, 'deactivate_wpcomplete' ); |
| @@ -48,18 +115,8 @@ | ||
| 48 | 115 | register_activation_hook( __FILE__, 'activate_wpcomplete' ); |
| 49 | 116 | register_deactivation_hook( __FILE__, 'deactivate_wpcomplete' ); |
| 50 | 117 | |
| 51 | 118 | /** |
| 52 | - * The code that checks for plugin updates. | |
| 53 | - * Borrowed from: https://github.com/YahnisElsts/plugin-update-checker | |
| 54 | - */ | |
| 55 | -require plugin_dir_path( __FILE__ ) . 'includes/plugin-update-checker-3.1.php'; | |
| 56 | -$myUpdateChecker = PucFactory::buildUpdateChecker( | |
| 57 | - 'https://wpcomplete.co/free.json', | |
| 58 | - __FILE__ | |
| 59 | -); | |
| 60 | - | |
| 61 | -/** | |
| 62 | 119 | * The core plugin class that is used to define internationalization, |
| 63 | 120 | * admin-specific hooks, and public-facing site hooks. |
| 64 | 121 | */ |
| 65 | 122 | require plugin_dir_path( __FILE__ ) . 'includes/class-wpcomplete.php'; |
| @@ -74,9 +131,31 @@ | ||
| 74 | 131 | * @since 1.0.0 |
| 75 | 132 | */ |
| 76 | 133 | function run_wpcomplete() { |
| 77 | 134 | |
| 78 | - $plugin = new WPComplete(); | |
| 79 | - $plugin->run(); | |
| 135 | + $plugin = new WPComplete(); | |
| 136 | + $plugin->run(); | |
| 80 | 137 | |
| 81 | 138 | } |
| 82 | 139 | run_wpcomplete(); |
| 140 | + | |
| 141 | +// FOR TESTING ONLY!!! | |
| 142 | +/*function create_post_type() { | |
| 143 | + //flush_rewrite_rules(); | |
| 144 | + register_post_type( 'acme_product', | |
| 145 | + array( | |
| 146 | + 'labels' => array( | |
| 147 | + 'name' => __( 'Products' ), | |
| 148 | + 'singular_name' => __( 'Product' ) | |
| 149 | + ), | |
| 150 | + 'supports' => array( | |
| 151 | + 'title', | |
| 152 | + 'editor', | |
| 153 | + 'page-attributes' | |
| 154 | + ), | |
| 155 | + 'public' => true, | |
| 156 | + 'has_archive' => true, | |
| 157 | + 'hierarchical' => true | |
| 158 | + ) | |
| 159 | + ); | |
| 160 | +} | |
| 161 | +add_action( 'init', 'create_post_type' );*/ | |