function inject_update($transient) { // bail early if not admin if (!is_admin()) { return $transient; } // bail early if no update available if (!acf_pro_is_update_available()) { return $transient; } // vars $info = acf_pro_get_remote_info(); $basename = acf_get_setting('basename'); $slug = acf_get_setting('slug'); // create new object for update $obj = new stdClass(); $obj->slug = $slug; $obj->new_version = $info['version']; $obj->url = $info['homepage']; $obj->package = ''; // license if (acf_pro_is_license_active()) { $obj->package = acf_pro_get_remote_url('download', array('k' => acf_pro_get_license())); } // add to transient $transient->response[$basename] = $obj; // return return $transient; }
function acf_pro_is_update_available() { // vars $info = acf_pro_get_remote_info(); $version = acf_get_setting('version'); // return false if no info if (empty($info['version'])) { return false; } // return false if the external version is '<=' the current version if (version_compare($info['version'], $version, '<=')) { return false; } // return return true; }
function inject_update($transient) { // vars $basename = acf_get_setting('basename'); // bail early if no show_updates if (!acf_get_setting('show_updates')) { return $transient; } // bail early if not a plugin (included in theme) if (!is_plugin_active($basename)) { return; } // bail early if no update available if (!acf_pro_is_update_available()) { return $transient; } // vars $info = acf_pro_get_remote_info(); $basename = acf_get_setting('basename'); $slug = acf_get_setting('slug'); // create new object for update $obj = new stdClass(); $obj->slug = $slug; $obj->plugin = $basename; $obj->new_version = $info['version']; $obj->url = $info['homepage']; $obj->package = ''; // license if (acf_pro_is_license_active()) { $obj->package = acf_pro_get_remote_url('download', array('k' => acf_pro_get_license(), 'wp_url' => home_url(), 'acf_version' => acf_get_setting('version'), 'wp_version' => get_bloginfo('version'))); } // add to transient $transient->response[$basename] = $obj; // return return $transient; }
function load() { // $_POST if (acf_verify_nonce('activate_pro_licence')) { $this->activate_pro_licence(); } elseif (acf_verify_nonce('deactivate_pro_licence')) { $this->deactivate_pro_licence(); } // view $this->view = array('license' => '', 'active' => 0, 'current_version' => acf_get_setting('version'), 'remote_version' => '', 'update_available' => false, 'changelog' => '', 'upgrade_notice' => ''); // license if (acf_pro_is_license_active()) { $this->view['license'] = acf_pro_get_license(); $this->view['active'] = 1; } // vars $info = acf_pro_get_remote_info(); // validate if (empty($info)) { acf_add_admin_notice(__('<b>Error</b>. Could not connect to update server', 'acf'), 'error'); return; } // add info to view $this->view['remote_version'] = $info['version']; // add changelog if the remote version is '>' than the current version if (acf_pro_is_update_available()) { $this->view['update_available'] = true; // changelog $changelogs = explode('<h4>', $info['changelog']); foreach ($changelogs as $changelog) { // validate (first segment is always empty due to explode) if (empty($changelog)) { continue; } // explode $changelog = explode('</h4>', $changelog); $changelog_version = trim($changelog[0]); $changelog_text = trim($changelog[1]); $changelog_text = str_replace('<ul>', '<ul class="ul-disc">', $changelog_text); if (version_compare($this->view['remote_version'], $changelog_version, '==')) { $this->view['changelog'] = $changelog_text; break; } } // upgrade_notice $upgrade_notices = explode('<h4>', $info['upgrade_notice']); foreach ($upgrade_notices as $upgrade_notice) { // validate (first segment is always empty due to explode) if (empty($upgrade_notice)) { continue; } // explode $upgrade_notice = explode('</h4>', $upgrade_notice); $upgrade_version = trim($upgrade_notice[0]); $upgrade_text = trim($upgrade_notice[1]); $upgrade_text = str_replace('<ul>', '<ul class="ul-disc">', $upgrade_text); if (version_compare($this->view['current_version'], $upgrade_version, '<')) { $this->view['upgrade_notice'] = $upgrade_text; break; } } } }