Esempio n. 1
0
 /**
  * Check SL service for new version
  * @param array existing WordPress transient array
  * @return bool|WP_Error
  */
 function checkUpdate($transient)
 {
     if (!defined('OP_FUNC')) {
         return $transient;
     }
     $plugin_version = OP_VERSION;
     $plugin_slug = OP_PLUGIN_SLUG;
     list($t1, $t2) = explode('/', $plugin_slug);
     $pluginName = str_replace('.php', '', $t2);
     if (!function_exists('op_sl_update')) {
         require_once OP_FUNC . 'options.php';
         require_once OP_FUNC . 'sl_api.php';
     }
     $apiResponse = op_sl_update('plugin');
     if (is_wp_error($apiResponse)) {
         return $response;
     }
     if (version_compare($plugin_version, $apiResponse->new_version, '<')) {
         //prepare object for WordPress
         $obj = new stdClass();
         $obj->name = __('OptimizePress Plugin', OP_SN);
         $obj->slug = $plugin_slug;
         $obj->version = $apiResponse->new_version;
         $obj->new_version = $apiResponse->new_version;
         $obj->homepage = $apiResponse->url;
         $obj->url = $apiResponse->url;
         $obj->download_url = $apiResponse->package;
         $obj->package = $apiResponse->package;
         $obj->requires = '3.5';
         $obj->tested = '3.9';
         $obj->sections = array('description' => $apiResponse->section->description, 'changelog' => $apiResponse->section->changelog);
         $transient->response[$plugin_slug] = $obj;
         // set transient for 12 hours
         set_transient('op_plugin_update', $obj, strtotime('+12 hours'));
     }
     return $transient;
 }
Esempio n. 2
0
 function hookFixOptimizePressThemeUpdate($transient)
 {
     if (!defined('OP_FUNC')) {
         return $transient;
     }
     $theme_slug = 'optimizePressTheme';
     if (!function_exists('op_sl_update')) {
         require_once OP_FUNC . 'options.php';
         require_once OP_FUNC . 'sl_api.php';
     }
     $apiResponse = op_sl_update('theme');
     if (is_wp_error($apiResponse)) {
         return $transient;
     }
     $obj = new stdClass();
     $obj->slug = $theme_slug;
     $obj->new_version = $apiResponse->new_version;
     $obj->url = $apiResponse->url;
     $obj->package = $apiResponse->s3_package;
     $obj->sections = array('description' => $apiResponse->section->description, 'changelog' => $apiResponse->section->changelog);
     $transient->response[$theme_slug] = (array) $obj;
     return $transient;
 }
Esempio n. 3
0
 /**
  * Check SL service for new version
  * @param array existing WordPress transient array
  * @return bool|WP_Error
  */
 function checkUpdate($transient)
 {
     if (!defined('OP_FUNC')) {
         return $transient;
     }
     //THEME
     if (function_exists('wp_get_theme')) {
         $theme_data = wp_get_theme(get_option('template'));
         $theme_version = $theme_data->Version;
     } else {
         $theme_data = get_theme_data(TEMPLATEPATH . '/style.css');
         $theme_version = $theme_data['Version'];
     }
     $theme_slug = get_option('template');
     if (!function_exists('op_sl_update')) {
         require_once OP_FUNC . 'options.php';
         require_once OP_FUNC . 'sl_api.php';
     }
     $apiResponse = op_sl_update('theme');
     if (is_wp_error($apiResponse)) {
         return $transient;
     }
     if (version_compare($theme_version, $apiResponse->new_version, '<')) {
         //prepare object for WordPress
         $obj = new stdClass();
         $obj->slug = $theme_slug;
         $obj->new_version = $apiResponse->new_version;
         $obj->url = $apiResponse->url;
         $obj->package = $apiResponse->package;
         $obj->sections = array('description' => $apiResponse->section->description, 'changelog' => $apiResponse->section->changelog);
         $transient->response[$theme_slug] = (array) $obj;
         // set transient for 12 hours
         set_transient('op_theme_update', $obj, strtotime('+12 hours'));
     }
     return $transient;
 }
Esempio n. 4
0
/**
 * Check SL service for new version
 * @param array existing WordPress transient array
 * @return bool|WP_Error
 */
function checkOpmUpdate($transient)
{
    $plugin_version = WS_PLUGIN__OPTIMIZEMEMBER_VERSION;
    $plugin_slug = OPM_PLUGIN_SLUG;
    list($t1, $t2) = explode('/', $plugin_slug);
    $pluginName = str_replace('.php', '', $t2);
    if (!defined('OP_SN')) {
        return $transient;
    }
    $apiResponse = op_sl_update('opm');
    if (is_wp_error($apiResponse)) {
        return $transient;
    }
    if (version_compare($plugin_version, $apiResponse->new_version, '<')) {
        //prepare object for WordPress
        $obj = new stdClass();
        $obj->name = __('OptimizeMember Plugin', OP_SN);
        $obj->slug = $plugin_slug;
        $obj->version = $apiResponse->new_version;
        $obj->new_version = $apiResponse->new_version;
        $obj->homepage = $apiResponse->url;
        $obj->url = $apiResponse->url;
        $obj->download_url = $apiResponse->package;
        $obj->package = $apiResponse->package;
        $obj->requires = '3.5';
        $obj->tested = '3.6';
        $obj->sections = array('description' => $apiResponse->section->description, 'changelog' => $apiResponse->section->changelog);
        $transient->response[$plugin_slug] = $obj;
        // set transient for 2 hours
        set_transient('op_opmplugin_update', $obj, strtotime('+12 hours'));
    }
    return $transient;
}
Esempio n. 5
0
 /**
  * Check SL service for new version
  * @param array existing WordPress transient array
  * @return bool|WP_Error
  */
 function checkUpdate($transient)
 {
     $response = get_transient('op_plugin_update');
     $plugin_version = OP_VERSION;
     $plugin_slug = plugin_basename(__FILE__);
     list($t1, $t2) = explode('/', $plugin_slug);
     $pluginName = str_replace('.php', '', $t2);
     if (false === $response) {
         $apiResponse = op_sl_update('plugin');
         if (is_wp_error($response)) {
             return $transient;
         }
         /*
          The WordPress update process needs an array formatted like the following:
         {
         "name" : "External Update Example",
         "slug" : "external-update-example",
         "homepage" : "http://example.com/",
         "download_url" : "http://w-shadow.com/files/external-update-example/external-update-example.zip",
         
         "version" : "2.0",
         "requires" : "3.0",
         "tested" : "3.1-alpha",
         "last_updated" : "2010-08-29 20:50:00",
         "upgrade_notice" : "Here's why you should upgrade...",
         
         "author" : "Janis Elsts",
         "author_homepage" : "http://w-shadow.com/",
         
         "sections" : {
         "description" : "(Required) Plugin description.<p>This section will be opened by default when the user clicks on 'View version XYZ information'. Basic HTML can be used in all sections.</p>",
         "installation" : "(Recommended) Installation instructions.",
         "changelog" : "(Recommended) Changelog.",
         "custom_section" : "This is a custom section labeled 'Custom Section'."
         },
         
         "rating" : 90,
         "num_ratings" : 123,
         "downloaded" : 1234
         }
         */
         if (version_compare($plugin_version, $apiResponse->new_version, '<')) {
             //prepare object for WordPress
             $obj = new stdClass();
             $obj->name = __('OptimizePress Plugin', OP_SN);
             $obj->slug = $plugin_slug;
             $obj->version = $apiResponse->new_version;
             $obj->new_version = $apiResponse->new_version;
             $obj->homepage = $apiResponse->url;
             $obj->url = $apiResponse->url;
             $obj->download_url = $apiResponse->package;
             $obj->package = $apiResponse->package;
             $obj->requires = '3.5';
             $obj->tested = '3.5.2';
             $obj->sections = array('description' => $apiResponse->section->description, 'changelog' => $apiResponse->section->changelog);
             $transient->response[$plugin_slug] = $obj;
         }
         // set transient for 12 hours
         set_transient('op_plugin_update', $obj, strtotime('+12 hours'));
     } else {
         if (version_compare($plugin_version, $response->new_version, '<')) {
             $transient->response[$plugin_slug] = $response;
         }
     }
     //die(print_r($transient));
     return $transient;
 }
Esempio n. 6
0
 /**
  * Fetches new presigned S3 link just before download will occur
  * @param  array $transient
  * @return array
  */
 function checkS3Update($transient)
 {
     if (!defined('OP_FUNC')) {
         return $transient;
     }
     $plugin_version = OP_VERSION;
     $plugin_slug = OP_PLUGIN_SLUG;
     list($t1, $t2) = explode('/', $plugin_slug);
     /*
      * We are only going on SL to get freshly presigned S3 link if the preconditions are OK
      */
     $do = false;
     if (isset($_SERVER['SCRIPT_NAME']) && strpos($_SERVER['SCRIPT_NAME'], 'update.php') && isset($_GET['action']) && $_GET['action'] === 'upgrade-plugin' && isset($_GET['plugin']) && $_GET['plugin'] === OP_PLUGIN_SLUG) {
         // single plugin upgrade
         $do = true;
     } elseif (isset($_SERVER['SCRIPT_NAME']) && strpos($_SERVER['SCRIPT_NAME'], 'update.php') && isset($_GET['action']) && $_GET['action'] === 'update-selected' && isset($_GET['plugins']) && in_array(OP_PLUGIN_SLUG, explode(',', $_GET['plugins']))) {
         // multi plugin upgrade
         $do = true;
     } elseif (isset($_SERVER['SCRIPT_NAME']) && strpos($_SERVER['SCRIPT_NAME'], 'plugins.php') && (isset($_POST['action']) && $_POST['action'] === 'update-selected' || isset($_POST['action2']) && $_POST['action2'] === 'update-selected') && isset($_POST['checked']) && in_array(OP_PLUGIN_SLUG, $_POST['checked'])) {
         // multi plugin upgrade
         $do = true;
     } elseif (isset($_SERVER['SCRIPT_NAME']) && strpos($_SERVER['SCRIPT_NAME'], 'update-core.php') && isset($_GET['action']) && $_GET['action'] === 'do-plugin-upgrade' && isset($_POST['checked']) && in_array(OP_PLUGIN_SLUG, $_POST['checked'])) {
         // update from dashboard
         $do = true;
     } elseif (defined('DOING_AJAX') && DOING_AJAX && isset($_POST['action']) && $_POST['action'] === 'update-plugin' && isset($_POST['slug']) && $_POST['slug'] === $t1) {
         // AJAX update
         $do = true;
     }
     if (false === $do) {
         return $transient;
     }
     if (!function_exists('op_sl_update')) {
         require_once OP_FUNC . 'options.php';
         require_once OP_FUNC . 'sl_api.php';
     }
     $apiResponse = op_sl_update('plugin');
     if (is_wp_error($apiResponse)) {
         return $response;
     }
     $obj = new stdClass();
     $obj->name = __('OptimizePress Plugin', OP_SN);
     $obj->slug = $t1;
     $obj->version = $apiResponse->new_version;
     $obj->new_version = $apiResponse->new_version;
     $obj->homepage = $apiResponse->url;
     $obj->url = $apiResponse->url;
     $obj->download_url = $apiResponse->s3_package;
     $obj->package = $apiResponse->s3_package;
     $obj->requires = '3.5';
     $obj->tested = '4.3';
     $obj->sections = array('description' => $apiResponse->section->description, 'changelog' => $apiResponse->section->changelog);
     $transient->response[$plugin_slug] = $obj;
     return $transient;
 }