Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  • Hook Reference
  • Docs Home

Packages

  • None
  • Order-Delivery-Date-Pro-for-WooCommerce
    • Admin
      • Edit-Order
      • Non-Sensitive-Data-Capture
      • Settings
        • Custom-Delivery
        • General
        • Google-Calendar-Sync
    • Class-ORDDD-Email-Manager
    • Common-Functions
    • Delivery-Calendar
    • Emails
      • Class-ORDDD-Email-Update-Date
    • Filter
    • Frontend
      • Checkout-Page-Processes
      • ICS-Files-Data
    • Google-Calendar
    • Integration
    • Lang
    • License
    • Plugin-Updates
      • EDD-SL-Plugin-Updater

Classes

  • EDD_SL_Plugin_Updater
  • orddd_additional_settings
  • orddd_admin_delivery_class
  • orddd_appearance_settings
  • orddd_calendar_sync
  • orddd_calendar_sync_settings
  • orddd_class_view_deliveries
  • orddd_common
  • orddd_date_settings
  • orddd_delivery_days_settings
  • ORDDD_Email_Manager
  • ORDDD_Email_Update_Date
  • orddd_filter
  • orddd_holidays_settings
  • orddd_integration
  • orddd_license
  • orddd_process
  • orddd_settings
  • orddd_shipping_based_settings
  • orddd_shipping_days_settings
  • orddd_shipping_multiple_address
  • orddd_time_settings
  • orddd_time_slot_settings
  • ORDDD_View_Delivery_Dates_Table
  • ORDDD_View_Disable_Time_Slots_Table
  • ORDDD_View_Holidays_Table
  • ORDDD_View_Shipping_Settings_Table
  • ORDDD_View_Time_Slots_Table
  • OrdddGcal
  • order_delivery_date
  • TS_Tracker
  • TS_tracking

Functions

  • orddd_get_dateToCal
  • orddd_get_escapeString
  • orddd_t
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 
<?php
/**
 * Order Delivery Date Pro for WooCommerce
 *
 * Introduces and Miantains Licenses for the plugin.
 *
 * @author      Tyche Softwares
 * @package     Order-Delivery-Date-Pro-for-WooCommerce/License
 * @since       2.5
 */

/**
 * orddd_license Class
 *
 * @class orddd_license
 */
class orddd_license {
    
    /** 
    * Activate plugin license if License key is valid  
    * 
    * @hook admin_init
    * @since 2.5
    */
    public static function orddd_edd_sample_activate_license() {        
        // listen for our activate button to be clicked
        if ( isset( $_POST[ 'orddd_license_activate' ] ) ) {
            // run a quick security check
            if ( ! check_admin_referer( 'edd_sample_nonce', 'edd_sample_nonce' ) )
                return; // get out if we didn't click the Activate button
            // retrieve the license from the database
            $license = trim( get_option( 'edd_sample_license_key_odd_woo' ) );
            // data to send in our API request
            $api_params = array(
                'edd_action' => 'activate_license',
                'license'    => $license,
                'item_name'  => urlencode( EDD_SL_ITEM_NAME_ODD_WOO ) // the name of our product in EDD
            );

            // Call the custom API.
            $response = wp_remote_get( esc_url_raw( add_query_arg( $api_params, EDD_SL_STORE_URL_ODD_WOO ) ), array( 'timeout' => 15, 'sslverify' => false ) );

            // make sure the response came back okay
            if ( is_wp_error( $response ) )
                return false;

            // decode the license data
            $license_data = json_decode( wp_remote_retrieve_body( $response ) );

            // $license_data->license will be either "active" or "inactive"
            update_option( 'edd_sample_license_status_odd_woo', $license_data->license );
        }
    }

    /** 
    * Deactivate the License 
    * 
    * @hook admin_init
    * @since 2.5
    */
    public static function orddd_edd_sample_deactivate_license() {
        // listen for our activate button to be clicked
        if ( isset( $_POST[ 'orddd_license_deactivate' ] ) ) {
            // run a quick security check
            if ( ! check_admin_referer( 'edd_sample_nonce', 'edd_sample_nonce' ) )
                return; // get out if we didn't click the Activate button
    
            // retrieve the license from the database
            $license = trim( get_option( 'edd_sample_license_key_odd_woo' ) );
            
            // data to send in our API request
            $api_params = array(
                'edd_action' => 'deactivate_license',
                'license'    => $license,
                'item_name'  => urlencode( EDD_SL_ITEM_NAME_ODD_WOO ) // the name of our product in EDD
            );
    
            // Call the custom API.
            $response = wp_remote_get( esc_url_raw( add_query_arg( $api_params, EDD_SL_STORE_URL_ODD_WOO ) ), array( 'timeout' => 15, 'sslverify' => false ) );

            // make sure the response came back okay
            if ( is_wp_error( $response ) )
                return false;

            // decode the license data
            $license_data = json_decode( wp_remote_retrieve_body( $response ) );

            // $license_data->license will be either "deactivated" or "failed"
            if ( $license_data->license == 'deactivated' )
                delete_option( 'edd_sample_license_status_odd_woo' );
        }
    }
    
    /**
    * Checks if License key is valid or not
    * 
    * @since 2.5
    */
    public static function orddd_edd_sample_check_license() {
        global $wp_version;
        $license = trim( get_option( 'edd_sample_license_key_odd_woo' ) );

        $api_params = array(
            'edd_action' => 'check_license',
            'license'    => $license,
            'item_name'  => urlencode( EDD_SL_ITEM_NAME_ODD_WOO )
        );
        // Call the custom API.
        $response = wp_remote_get( esc_url_raw( add_query_arg( $api_params, EDD_SL_STORE_URL_ODD_WOO ) ), 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' ) {
            echo 'valid'; exit;
            // this license is still valid
        } else {
            echo 'invalid'; exit;
            // this license is no longer valid
        }
    }

    /**
    * Stores the license key in database of the site 
    * once the plugin is installed and the license key saved.
    * 
    * @hook admin_init
    * @since 2.5
    */
    public static function orddd_edd_sample_register_option() {
        // creates our settings in the options table
        register_setting( 'edd_sample_license', 'edd_sample_license_key_odd_woo',  array( 'orddd_license', 'orddd_get_edd_sanitize_license' ) );
    }

    /**
    * Checks if a new license has been entered, if yes plugin must be reactivated.
    * 
    * @param string $new - New License Key
    * @since 2.5
    */  
    public static function orddd_get_edd_sanitize_license( $new ) {
        $old = get_option( 'edd_sample_license_key_odd_woo' );
        if( $old && $old != $new ) {
            delete_option( 'edd_sample_license_status_odd_woo' ); // new license has been entered, so must reactivate
        }
        return $new;
    }

    /**
    * Add the license page in the Order delivery date menu.
    * 
    * @since 2.5
    */
    public static function orddd_edd_sample_license_page() {
        $license    = get_option( 'edd_sample_license_key_odd_woo' );
        $status     = get_option( 'edd_sample_license_status_odd_woo' );
    
        ?>
        <div class="wrap">
            <h2><?php _e( 'Plugin License Options', 'order-delivery-date' ); ?></h2>
                <form method="post" action="options.php">
                    <?php settings_fields( 'edd_sample_license' ); ?>
                        <table class="form-table">
                            <tbody>
                                <tr valign="top">   
                                    <th scope="row" valign="top">
                                        <?php _e( 'License Key', 'order-delivery-date' ); ?>
                                    </th>
                                    <td>
                                        <input id="edd_sample_license_key_odd_woo" name="edd_sample_license_key_odd_woo" type="text" class="regular-text"   value="<?php esc_attr_e( $license ); ?>" />
                                            <label class="description" for="edd_sample_license_key"><?php _e( 'Enter your license key', 'order-delivery-date' ); ?></label>
                                    </td>
                                </tr>
                                <?php if ( false !== $license ) { ?>
                                <tr valign="top">   
                                    <th scope="row" valign="top">
                                        <?php _e( 'Activate License', 'order-delivery-date' ); ?>
                                    </th>
                                    <td>
                                    <?php if ( $status !== false && $status == 'valid' ) { ?>
                                        <span style="color:green;"><?php _e( 'active', 'order-delivery-date' ); ?></span>
                                        <?php wp_nonce_field( 'edd_sample_nonce', 'edd_sample_nonce' ); ?>
                                        <input type="submit" class="button-secondary" name="orddd_license_deactivate" value="<?php _e( 'Deactivate License', 'order-delivery-date' ); ?>"/>
                                    <?php } else {
                                            wp_nonce_field( 'edd_sample_nonce', 'edd_sample_nonce' ); ?>
                                            <input type="submit" class="button-secondary" name="orddd_license_activate" value="<?php _e( 'Activate License', 'order-delivery-date' ); ?>"/>
                                        <?php } ?>
                                    </td>
                                </tr>
                            <?php } ?>
                        </tbody>
                    </table>    
                    <?php submit_button(); ?>
                </form>
        <?php
    }

    /**
     * Checks if the Plugin License is active or no. If not, a notice is displayed
     * in WordPress admin for the same.
     * 
     * @hook admin_init
     * @since 7.0
     */
    public static function orddd_check_if_license_active() {
        if ( ! self::orddd_check_active_license() ) {
            add_action( 'admin_notices', array( 'orddd_license', 'orddd_license_active_notice' ) );
        }
    }

    /**
     * Returns License active status
     * 
     * @return boolean License active status
     * @since 7.0
     */
    public static function orddd_check_active_license() {
        $status = get_option( 'edd_sample_license_status_odd_woo' );
        if( false !== $status && 'valid' == $status ) {
            return true;
        } else {
            return false;
        }
    }
    
    /**
     * Adds notice in WordPress admin dashboard when the plugin license
     * is not active.
     * 
     * @since 7.0
     */
    public static function orddd_license_active_notice() {
        $class = 'notice notice-error';
        $message = __( 'We have noticed that the license for <b>Order Delivery Date Pro for WooCommerce</b> plugin is not active. To receive automatic updates & support, please activate the license.', 'order-delivery-date' );
        printf( '<div class="%1$s"><p>%2$s</p></div>', $class, $message );
    }
}
API documentation generated by ApiGen