/**
  * Plugin Activation
  *
  * This method is run statically in dts_controller.php
  * on the register_activation_hook() function.
  *
  * @internal  Called via register_activation_hook
  * @uses      update_option, get_option, add_option
  * @return    void
  */
 static function activate()
 {
     if (is_admin()) {
         // Grab the single instace of this class
         $dts_core = DTS_Core::get_instance();
         // Do we need to run an update routine?
         if ($dts_core->does_need_update()) {
             // Yes, let's run the update
             $dts_core->update();
         } else {
             // Check if an install is needed
             if ($dts_core->need_install()) {
                 // Yes, we need to run the install routine
                 $dts_core->install();
             }
         }
     }
     // if is_admin
 }
<?php

// Bail if this file is being accessed directly
defined('ABSPATH') or exit;
/**
 * UPDATE VERSION to 2.6
 *
 * In 2.6 we changed the previous usage of PHP $_SESSION's to browser cookies
 * for the use of recalling which theme ('View Full Website') the user has chosen
 * 
 * On update, lets rename the previous dts_session_lifetime option (which also stored seconds)
 * to a new name which better represents the new convension; dts_cookie_lifespan
 */
// Set an option to store the plugin cookie name
// We'll reference this throughout the cookie setting/managing/removal process
update_option('dts_cookie_name', DTS_Core::build_cookie_name());
// Add the new option using the new name and existing dts_session_lifetime value
$dts_cookie_lifespan = intval(get_option('dts_session_lifetime'));
// If the session is still 900 seconds / 15 minutes (the default set in version 2.0)
// Change that to the new default (0 = until the user closes their browser)
if ($dts_cookie_lifespan == 900) {
    $dts_cookie_lifespan = 0;
}
// Save the new dts_cookie_lifespan option
update_option('dts_cookie_lifespan', $dts_cookie_lifespan);
// Remove the old option
delete_option('dts_session_lifetime');
// EOF
 /**
  * Detect Requested Theme Override
  *
  * The following logic determines if the user is requesting an alternate to the default theme.
  * By default the user is given their device theme as set in the admin.
  * An example of an override would be, 'View Full Website', as we're overriding
  * the default 'handheld' theme if the user is on an iPhone.
  *
  * While this function does not return anything, it does, under certain conditions,
  * populate a class variable named $theme_override containing a string of the
  * override theme name, e.g. 'active', 'handheld', 'tablet', 'low_support'.
  *
  * The following will also, under certain conditions, set and destroy a cookie
  * to be stored in the user's browser. This only occurs when an alternate theme
  * is requested, so the user can browse through the full website and the site
  * 'knows' the user requested the full site even though their on an iPhone..
  *
  * @internal  Called during object instantiation
  * @uses      DTS_Core::build_cookie_name, get_option, update_option
  * @param     void
  * @return    void
  */
 public function detect_requested_theme_override()
 {
     $this->theme_override = $requested_theme = "";
     $cookie_lifespan = 0;
     // Ensure our dts_cookie_name option is set
     $cookie_name = get_option('dts_cookie_name');
     if (empty($cookie_name)) {
         $cookie_name = DTS_Core::get_instance()->build_cookie_name();
         update_option('dts_cookie_name', $cookie_name);
     }
     // Is the user requesting a theme override?
     // This is how users can 'view full website' and vice versa
     if (isset($_GET['theme'])) {
         //i.e. site.com?theme=active
         // Capture the requested theme
         $requested_theme = sanitize_text_field($_GET['theme']);
         // Does the requested theme match the detected device theme?
         if ($requested_theme == $this->device) {
             // The default/active theme is given back and their cookie is going to be removed
             // this condition typically exsits when someone is navigating "Back to Mobile"
             setcookie($name = $cookie_name, $value = "", $expire = 1, $path = COOKIEPATH, $domain = COOKIE_DOMAIN, $secure = false);
         } else {
             // No it does not
             // this condition generally means that the user has just clicked "View full website"
             // Kill the request if it isn't valid, i.e. don't try to load ?theme=fooeybear unless it really exists
             if (isset($this->{$requested_theme . "_theme"})) {
                 // Only proceed if $this->requested_theme is not empty, hence it's a valid theme
                 if (!empty($this->{$requested_theme . "_theme"})) {
                     // Retrieve the stored cookie lifespan
                     // chosen in Appeance > Device Themes
                     $cookie_lifespan = get_option('dts_cookie_lifespan');
                     if ($cookie_lifespan == 0) {
                         $cookie_expiration = 0;
                     } else {
                         $cookie_expiration = time() + $cookie_lifespan;
                     }
                     // Build an array of the requested theme settings we'll need to know about when
                     // the user returns to the site (or navigates to another page)
                     // this way we can load the theme they previously requested
                     $cookie_settings = array('theme' => $requested_theme, 'device' => $this->device);
                     // Set a cookie in the users browser to identify the theme they've requested
                     setcookie($cookie_name, json_encode($cookie_settings), $cookie_expiration, COOKIEPATH, COOKIE_DOMAIN, false);
                     // Return the requested
                     $this->theme_override = $requested_theme;
                 }
                 // end if
             }
             // end if
         }
         // end if
     } else {
         // isset( $_GET['theme'] )
         // there is no new override being requested
         // Check if there is an already existant override stored in a cookie
         if (isset($_COOKIE[$cookie_name])) {
             // The requested theme is an array so we stored it as a json encoded string
             // lets decode that so we can see whats in it
             // Note: once decoded we'll be working with an object not an array
             $dts_cookie = json_decode($_COOKIE[$cookie_name]);
             if (isset($dts_cookie->theme)) {
                 // Kill the request if it isn't valid
                 if (isset($this->{$dts_cookie->theme . "_theme"})) {
                     // allow the override to continue
                     $this->theme_override = $dts_cookie->theme;
                 }
                 // end if
             }
             // end if
         }
         // end if
     }
     // end if
     /**
      * !! If none of the above conditions triggered
      * !! the user is given their device-assigned theme
      */
 }