$data ) { $items[] = array( 'type' => 'plugin', 'id' => $file, 'slug' => false === strpos( $file, '/' ) ? basename( $file, '.php' ) : dirname( $file ), 'name' => (string) $data['Name'], 'version' => (string) $data['Version'], ); } foreach ( wp_get_themes() as $stylesheet => $theme ) { $items[] = array( 'type' => 'theme', 'id' => (string) $stylesheet, 'slug' => (string) $stylesheet, 'name' => (string) $theme->get( 'Name' ), 'version' => (string) $theme->get( 'Version' ), ); } $ctx->progress = array( 'done' => 0, 'total' => count( $items ) + 1, 'label' => __( 'Updates', 'safetybis-security' ), ); return array( 'items' => $items, 'i' => -1, ); } /** * Step. * * @param array $state State. * @param Context $ctx Context. * @return bool */ public function step( array &$state, Context $ctx ) { if ( -1 === $state['i'] ) { $this->core( $ctx ); $state['i'] = 0; } $plugin_updates = get_site_transient( 'update_plugins' ); $theme_updates = get_site_transient( 'update_themes' ); $total = count( $state['items'] ); while ( $state['i'] < $total ) { $item = $state['items'][ $state['i'] ]; $state['i']++; $ctx->progress = array( 'done' => $state['i'], 'total' => $total + 1, 'label' => $item['name'], ); $details = array( 'kind' => $item['type'], 'name' => $item['name'], 'version' => $item['version'], ); // 1. Update available (from WordPress, including vendors' own update servers). $new = ''; if ( 'plugin' === $item['type'] && isset( $plugin_updates->response[ $item['id'] ]->new_version ) ) { $new = (string) $plugin_updates->response[ $item['id'] ]->new_version; } elseif ( 'theme' === $item['type'] && isset( $theme_updates->response[ $item['id'] ]['new_version'] ) ) { $new = (string) $theme_updates->response[ $item['id'] ]['new_version']; } if ( '' !== $new ) { $ctx->add( 'update-available', 'medium', $item['slug'], $item['type'], $new, $details + array( 'new_version' => $new ) ); } // 2. Directory status. A network error here should not stop the whole module. // Hello Dolly is installed as hello.php but listed in the directory as hello-dolly. $slug = ( 'plugin' === $item['type'] && 'hello.php' === $item['id'] ) ? 'hello-dolly' : $item['slug']; try { $info = Reference::info( $item['type'], $slug ); } catch ( \RuntimeException $e ) { $ctx->count( 'info_errors' ); $info = null; } if ( is_array( $info ) ) { if ( $info['closed'] ) { $ctx->add( 'closed', 'high', $item['slug'], $item['type'], $info['closed_date'], $details + array( 'closed_date' => $info['closed_date'], 'reason' => $info['reason'] ) ); } elseif ( ! $info['found'] ) { $ctx->add( 'unknown-source', 'low', $item['slug'], $item['type'], 'unknown', $details ); } else { $updated = strtotime( (string) preg_replace( '/\s*GMT$/', '', $info['last_updated'] ) ); if ( $updated && ( time() - $updated ) > self::ABANDONED_DAYS * DAY_IN_SECONDS ) { $ctx->add( 'abandoned', 'medium', $item['slug'], $item['type'], gmdate( 'Y-m-d', $updated ), $details + array( 'last_updated' => gmdate( 'Y-m-d', $updated ) ) ); } } } $ctx->count( 'checked' ); if ( $ctx->out_of_time() ) { return $state['i'] >= $total; } } return true; } /** * WordPress core update. * * @param Context $ctx Context. */ private function core( Context $ctx ) { list( $current ) = CoreModule::installed(); // Not loaded in WP-Cron. require_once ABSPATH . 'wp-admin/includes/update.php'; $updates = get_core_updates(); if ( ! is_array( $updates ) ) { return; } $best = ''; foreach ( $updates as $update ) { if ( isset( $update->response, $update->current ) && 'upgrade' === $update->response && version_compare( $update->current, $current, '>' ) ) { if ( '' === $best || version_compare( $update->current, $best, '>' ) ) { $best = (string) $update->current; } } } if ( '' === $best ) { return; } // A newer release of the installed branch (6.8.1 -> 6.8.3) usually carries security fixes. $branch_fix = ''; foreach ( $updates as $update ) { if ( isset( $update->current ) && version_compare( $update->current, $current, '>' ) && implode( '.', array_slice( explode( '.', $current ), 0, 2 ) ) === implode( '.', array_slice( explode( '.', (string) $update->current ), 0, 2 ) ) ) { $branch_fix = (string) $update->current; } } $severity = '' !== $branch_fix ? 'high' : 'medium'; $ctx->add( 'update-available', $severity, 'core', 'core', $best, array( 'kind' => 'core', 'name' => 'WordPress', 'version' => $current, 'new_version' => $best, 'branch_fix' => $branch_fix, ) ); } }