getFileName(); self::$core = '' !== $file ? Owner::norm( dirname( $file, 2 ) ) : ''; } return self::$core; } /** * The content folder (normalised, no trailing slash), or '' when it cannot be told. WordPress has * no function that returns it, so it is read off the default theme or plugin root, but only while * that root's URL is still the one content_url() gives it, which means the root sits where * WordPress put it. */ public static function content(): string { if ( null === self::$content ) { self::$content = ''; $candidates = array( array( get_theme_root(), get_theme_root_uri(), 'themes' ), array( WP_PLUGIN_DIR, plugins_url(), 'plugins' ), ); foreach ( $candidates as $candidate ) { list( $dir, $url, $leaf ) = $candidate; $dir = untrailingslashit( wp_normalize_path( (string) $dir ) ); if ( basename( $dir ) === $leaf && untrailingslashit( (string) $url ) === untrailingslashit( content_url( $leaf ) ) ) { self::$content = Owner::norm( dirname( $dir ) ); break; } } } return self::$content; } /** * URL path roots and the folders they serve, longest root first. The WordPress folder itself * (site_url()) is not in the list: callers decide whether to fall back to it. * * @return array URL path (no trailing slash) => folder (normalised, no trailing slash) */ public static function url_roots(): array { $pairs = array( array( plugins_url(), WP_PLUGIN_DIR ), array( plugins_url( '', WPMU_PLUGIN_DIR . '/x.php' ), WPMU_PLUGIN_DIR ), ); $themes = array_unique( array_filter( array( get_stylesheet(), get_template() ) ) ); $uploads = wp_upload_dir( null, false ); foreach ( $themes as $theme ) { $pairs[] = array( get_theme_root_uri( $theme ), get_theme_root( $theme ) ); } if ( empty( $uploads['error'] ) ) { $pairs[] = array( (string) $uploads['baseurl'], (string) $uploads['basedir'] ); } if ( '' !== self::content() ) { $pairs[] = array( content_url(), self::content() ); } $roots = array(); foreach ( $pairs as $pair ) { $root = rtrim( (string) wp_parse_url( (string) $pair[0], PHP_URL_PATH ), '/' ); if ( '' !== $root && ! isset( $roots[ $root ] ) ) { $roots[ $root ] = Owner::norm( (string) $pair[1] ); } } uksort( $roots, static function ( $a, $b ) { return strlen( $b ) <=> strlen( $a ); } ); return $roots; } /** * Forget cached folders (tests change the theme and plugin roots). */ public static function reset(): void { self::$core = null; self::$content = null; } }