should_display_notice() ) { return; } // Fetch the theme's current/new version pair; false means no update pending. $theme_data = $this->get_theme_update_data(); if ( !$theme_data ) { return; } // All checks passed, so output the notice markup. $this->render_notice( $theme_data ); } /** * Decide whether the notice is allowed to appear. * * @return bool True when not previously dismissed, the user can update * themes, and this is not an AJAX request. */ private function should_display_notice() { return !get_option( $this->notice_option ) && // not dismissed before current_user_can( 'update_themes' ) && // user has the capability !wp_doing_ajax(); // not during an AJAX call } /** * Resolve the companion theme's installed and available versions. * * @return array|false Array with 'current_version'/'new_version', or false * if the theme is missing or has no pending update. */ private function get_theme_update_data() { // The companion theme must actually be installed on the site. $theme = wp_get_theme( $this->theme_slug ); if ( !$theme->exists() ) { return false; } // WordPress caches pending theme updates in this site transient. $updates = get_site_transient( 'update_themes' ); if ( !isset( $updates->response[$this->theme_slug] ) ) { return false; } // Hand back the installed version and the version WordPress is offering. return array( 'current_version' => $theme->get( 'Version' ), 'new_version' => $updates->response[$this->theme_slug]['new_version'], ); } /** * Render the notice markup from its template partial. * * @param array $data Version data made available to the included template. */ public function render_notice( $data ) { // $data is in scope for the template to print current/new versions. include plugin_dir_path( dirname( __FILE__ ) ) . 'templates/admin/wpstream-theme-update-notice.php'; } }