sage() ); } wp_send_json_error( array( 'message' => $errorMessage, ) ); } wp_send_json_error( array( 'message' => 'Plugin update failed.', ) ); } /** * Returns allowed plugin updates * * @return [type] [description] */ public function get_pluign_updates() { if ( ! $this->update_plugins ) { $this->update_plugins = get_site_transient( 'update_plugins' ); } if ( empty( $this->plugins ) || ! $this->update_plugins || empty( $this->update_plugins->response ) ) { return array(); } $to_update = array(); foreach ( $this->plugins as $plugin ) { if ( ! isset( $this->update_plugins->response[ $plugin['file'] ] ) ) { continue; } $new_version = $this->update_plugins->response[ $plugin['file'] ]->new_version; if ( version_compare( $new_version, $plugin['version'], '>' ) ) { $to_update[ $plugin['file'] ] = array( 'version' => $new_version, 'slug' => $plugin['slug'], ); } } return $to_update; } /** * Register module plugin for updater * * @param array $plugin [description] * @return [type] [description] */ public function register_plugin( $plugin = array() ) { $this->plugins[ $plugin['slug'] ] = $plugin; add_filter( 'in_plugin_update_message-' . $plugin['file'], array( $this, 'in_plugin_update_message' ), 10, 2 ); } /** * [plugin_row_meta description] * @param [type] $plugin_meta [description] * @param [type] $plugin_file [description] * @param [type] $plugin_data [description] * @return [type] [description] */ public function in_plugin_update_message( $plugin_data, $response ) { if ( ! $response->package ) { echo sprintf( ' %2$s', \Jet_Dashboard\Dashboard::get_instance()->get_dashboard_page_url( 'license-page', 'license-manager' ), 'Activate your JetEngine license for automatic updates.' ); } } /** * Check if update are avaliable. * * @since 1.0.0 * @return array */ protected function check_update( $slug, $version ) { $response = $this->remote_query( $slug ); if ( ! $response ) { return array( 'version' => false ); } if ( version_compare( $version, $response->version, '<' ) ) { return array( 'version' => $response->version, 'package' => $response->package, ); } return array( 'version' => false ); } /** * Remote request to updater API. * * @since 1.0.0 * @return array|bool */ protected function remote_query( $slug ) { $response = wp_remote_get( $this->api_url . $slug ); if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != '200' ) { return false; } $response = json_decode( $response['body'] ); return $response; } /** * Process update. * * @since 1.0.0 * @param object $data Update data. * @return object */ public function get_update( $data ) { if ( ! is_object( $data ) ) { $data = new \stdClass(); } foreach ( $this->plugins as $plugin ) { $new_update = $this->check_update( $plugin['slug'], $plugin['version'] ); if ( $new_update['version'] ) { $update = new stdClass(); if ( ! class_exists( 'Jet_Dashboard\Utils' ) ) { jet_engine()->jet_dashboard_init( true ); } $package = false; $license = \Jet_Dashboard\Utils::get_plugin_license_key( 'jet-engine/jet-engine.php' ); if ( $license ) { $package = jet_engine()->modules->installer->get_plugin_url( $plugin['slug'] ); } $update->slug = $plugin['slug']; $update->plugin = $plugin['file']; $update->new_version = $new_update['version']; $update->url = false; $update->package = $package; $data->response[ $plugin['file'] ] = $update; } } return $data; } } }