*/ public static function plugins() { require_once ABSPATH . 'wp-admin/includes/plugin.php'; $out = array(); foreach ( get_plugins() as $file => $data ) { $out[] = array( 'file' => (string) $file, 'name' => isset( $data['Name'] ) ? (string) $data['Name'] : '', 'version' => isset( $data['Version'] ) ? (string) $data['Version'] : '', 'active' => is_plugin_active( $file ), ); } return $out; } /** * Builds the Context of a pass. * * @param array $state ahcl_state (reference date, checksum outcomes). * @return Context */ public static function context( array $state ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; $hosts = array(); foreach ( array( get_option( 'home' ), get_option( 'siteurl' ) ) as $url ) { $host = wp_parse_url( (string) $url, PHP_URL_HOST ); if ( is_string( $host ) && '' !== $host ) { $hosts[] = strtolower( $host ); } } $roles = array(); foreach ( wp_roles()->roles as $name => $role ) { $roles[ $name ] = isset( $role['capabilities'] ) ? (array) $role['capabilities'] : array(); } $uploads = wp_upload_dir( null, false ); $themes = array_unique( array( self::relative( get_stylesheet_directory() ), self::relative( get_template_directory() ) ) ); $plugins = self::plugins(); $version = self::wp_version(); $locale = self::package_locale(); $a = array( 'referenceDate' => $state['reference_date'], 'siteHosts' => array_values( array_unique( $hosts ) ), 'absPath' => self::abspath(), 'contentDir' => self::relative( WP_CONTENT_DIR ), 'uploadsDir' => self::relative( $uploads['basedir'] ), 'pluginsDir' => self::relative( WP_PLUGIN_DIR ), 'muPluginsDir' => self::relative( WPMU_PLUGIN_DIR ), 'activeThemeDirs' => array_values( $themes ), 'plugins' => $plugins, 'locale' => $locale, 'wpVersion' => $version, 'dropins' => array_keys( _get_dropins() ), 'roles' => $roles, 'pluginChecksums' => array(), 'pluginUnavailable' => array(), ); $sums = isset( $state['sums'] ) ? $state['sums'] : array(); $core = isset( $sums['core'] ) ? $sums['core'] : array( 'status' => 'not_consented' ); if ( 'ok' === $core['status'] ) { $c = Checksums::core( $version, $core['locale'], $locale ); if ( null !== $c ) { $a['coreChecksums'] = $c->toArray(); } else { $a['coreUnavailable'] = 'network_error'; } } else { $a['coreUnavailable'] = $core['status']; } foreach ( isset( $sums['plugins'] ) ? $sums['plugins'] : array() as $slug => $p ) { if ( 'ok' === $p['status'] ) { $c = Checksums::plugin( $slug, $p['version'] ); if ( null !== $c ) { $a['pluginChecksums'][ $slug ] = $c; } else { $a['pluginUnavailable'][ $slug ] = 'network_error'; } } elseif ( '' !== $p['status'] ) { $a['pluginUnavailable'][ $slug ] = $p['status']; } } return Context::fromArray( $a ); } }