| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @link https://wpcomplete.co |
| 5 |
* @since 1.0.0 |
| 6 |
* @package WPComplete |
| 7 |
* |
| 8 |
* @wordpress-plugin |
| 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 |
* Author: Zack Gilbert and Paul Jarvis |
| 13 |
* Author URI: https://wpcomplete.co |
| 14 |
* License: GPL-2.0+ |
| 15 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 16 |
* Text Domain: wpcomplete |
| 17 |
* Domain Path: /languages |
| 18 |
*/ |
| 19 |
|
| 20 |
// If this file is called directly, abort. |
| 21 |
if ( ! defined( 'WPINC' ) ) { |
| 22 |
die; |
| 23 |
} |
| 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 |
|
| 30 |
// Define some variables we will use throughout the plugin: |
| 31 |
define( 'WPCOMPLETE_STORE_URL', 'https://wpcomplete.co' ); |
| 32 |
define( 'WPCOMPLETE_PRODUCT_NAME', 'WPComplete' ); |
| 33 |
define( 'WPCOMPLETE_PREFIX', 'wpcomplete' ); |
| 34 |
define( 'WPCOMPLETE_IS_ACTIVATED', wpcomplete_license_is_valid() ); |
| 35 |
|
| 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 |
/** |
| 98 |
* The code that runs during plugin activation. |
| 99 |
* This action is documented in includes/class-wpcomplete-activator.php |
| 100 |
*/ |
| 101 |
function activate_wpcomplete() { |
| 102 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wpcomplete-activator.php'; |
| 103 |
WPComplete_Activator::activate(); |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* The code that runs during plugin deactivation. |
| 108 |
* This action is documented in includes/class-wpcomplete-deactivator.php |
| 109 |
*/ |
| 110 |
function deactivate_wpcomplete() { |
| 111 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wpcomplete-deactivator.php'; |
| 112 |
WPComplete_Deactivator::deactivate(); |
| 113 |
} |
| 114 |
|
| 115 |
register_activation_hook( __FILE__, 'activate_wpcomplete' ); |
| 116 |
register_deactivation_hook( __FILE__, 'deactivate_wpcomplete' ); |
| 117 |
|
| 118 |
/** |
| 119 |
* The core plugin class that is used to define internationalization, |
| 120 |
* admin-specific hooks, and public-facing site hooks. |
| 121 |
*/ |
| 122 |
require plugin_dir_path( __FILE__ ) . 'includes/class-wpcomplete.php'; |
| 123 |
|
| 124 |
/** |
| 125 |
* Begins execution of the plugin. |
| 126 |
* |
| 127 |
* Since everything within the plugin is registered via hooks, |
| 128 |
* then kicking off the plugin from this point in the file does |
| 129 |
* not affect the page life cycle. |
| 130 |
* |
| 131 |
* @since 1.0.0 |
| 132 |
*/ |
| 133 |
function run_wpcomplete() { |
| 134 |
|
| 135 |
$plugin = new WPComplete(); |
| 136 |
$plugin->run(); |
| 137 |
|
| 138 |
} |
| 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' );*/ |
| 162 |
|