Skip to content

Instantly share code, notes, and snippets.

@jgalea
Last active December 19, 2015 10:19
Show Gist options
  • Select an option

  • Save jgalea/5939198 to your computer and use it in GitHub Desktop.

Select an option

Save jgalea/5939198 to your computer and use it in GitHub Desktop.

Revisions

  1. jgalea revised this gist Jul 6, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions activation-deactivation.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    add_action( 'admin_init', 'wprss_et_activate_deactivate_license' );
    /**
    * Handles the activation/deactivation process
  2. jgalea created this gist Jul 6, 2013.
    52 changes: 52 additions & 0 deletions activation-deactivation.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    add_action( 'admin_init', 'wprss_et_activate_deactivate_license' );
    /**
    * Handles the activation/deactivation process
    *
    * @since 1.1
    */
    function wprss_et_activate_deactivate_license() {

    // listen for our activate button to be clicked
    if( isset( $_POST['wprss_et_license_activate'] ) || isset( $_POST['wprss_et_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/Deactivate button

    // retrieve the license from the database
    $license = trim( get_option( 'wprss_et_license_key' ) );

    if ( isset( $_POST['wprss_et_license_activate'] ) ) {
    // data to send in our API request
    $api_params = array(
    'edd_action'=> 'activate_license',
    'license' => $license,
    'item_name' => urlencode( WPRSS_ET_SL_ITEM_NAME ) // the name of our product in EDD
    );
    }

    else if ( isset( $_POST['wprss_et_license_deactivate'] ) ) {
    // data to send in our API request
    $api_params = array(
    'edd_action'=> 'deactivate_license',
    'license' => $license,
    'item_name' => urlencode( WPRSS_ET_SL_ITEM_NAME ) // the name of our product in EDD
    );
    }

    // Call the custom API.
    $response = wp_remote_get( add_query_arg( $api_params, WPRSS_ET_SL_STORE_URL ) );

    // 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( 'wprss_et_license_status', $license_data->license );

    }
    }