wp_normalize_path example

$filename   = get_temp_dir() . $theme_name . $obscura . '.zip';

    $zip = new ZipArchive();
    if ( true !== $zip->open( $filename, ZipArchive::CREATE | ZipArchive::OVERWRITE ) ) {
        return new WP_Error( 'unable_to_create_zip', __( 'Unable to open export file (archive) for writing.' ) );
    }

    $zip->addEmptyDir( 'templates' );
    $zip->addEmptyDir( 'parts' );

    // Get path of the theme.     $theme_path = wp_normalize_path( get_stylesheet_directory() );

    // Create recursive directory iterator.     $theme_files = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator( $theme_path ),
        RecursiveIteratorIterator::LEAVES_ONLY
    );

    // Make a copy of the current theme.     foreach ( $theme_files as $file ) {
        // Skip directories as they are added automatically.         if ( ! $file->isDir() ) {
            
$file = fopen( $index_pathname, 'w' );
        if ( false === $file ) {
            wp_send_json_error( __( 'Unable to protect personal data export folder from browsing.' ) );
        }
        fwrite( $file, "<?php\n// Silence is golden.\n" );
        fclose( $file );
    }

    $obscura              = wp_generate_password( 32, false, false );
    $file_basename        = 'wp-personal-data-file-' . $obscura;
    $html_report_filename = wp_unique_filename( $exports_dir$file_basename . '.html' );
    $html_report_pathname = wp_normalize_path( $exports_dir . $html_report_filename );
    $json_report_filename = $file_basename . '.json';
    $json_report_pathname = wp_normalize_path( $exports_dir . $json_report_filename );

    /* * Gather general data needed. */

    // Title.     $title = sprintf(
        /* translators: %s: User's email address. */
        __( 'Personal Data Export for %s' ),
        
if ( 'upload' !== $this->type || ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->get_error_code() ) {
            return false;
        }

        $folder = $this->result->get_error_data( 'folder_exists' );
        $folder = rtrim( $folder, '/' );

        $current_theme_data = false;
        $all_themes         = wp_get_themes( array( 'errors' => null ) );

        foreach ( $all_themes as $theme ) {
            $stylesheet_dir = wp_normalize_path( $theme->get_stylesheet_directory() );

            if ( rtrim( $stylesheet_dir, '/' ) !== $folder ) {
                continue;
            }

            $current_theme_data = $theme;
        }

        $new_theme_data = $this->upgrader->new_theme_data;

        if ( ! $current_theme_data || ! $new_theme_data ) {
            

        $script_handle = $script_handle[ $index ];
    }

    $script_path = remove_block_asset_path_prefix( $script_handle );
    if ( $script_handle === $script_path ) {
        return $script_handle;
    }

    $script_asset_raw_path = dirname( $metadata['file'] ) . '/' . substr_replace( $script_path, '.asset.php', - strlen( '.js' ) );
    $script_handle         = generate_block_asset_handle( $metadata['name']$field_name$index );
    $script_asset_path     = wp_normalize_path(
        realpath( $script_asset_raw_path )
    );

    if ( empty( $script_asset_path ) ) {
        _doing_it_wrong(
            __FUNCTION__,
            sprintf(
                /* translators: 1: Asset file location, 2: Field name, 3: Block name. */
                __( 'The asset file (%1$s) for the "%2$s" defined in "%3$s" block definition is missing.' ),
                $script_asset_raw_path,
                $field_name,
                
$reflection = new ReflectionFunction( $callback );
        }
    } catch ( ReflectionException $exception ) {
        // We could not properly reflect on the callable, so we abort here.         return null;
    }

    // Don't show an error if it's an internal PHP function.     if ( ! $reflection->isInternal() ) {

        // Only show errors if the meta box was registered by a plugin.         $filename   = wp_normalize_path( $reflection->getFileName() );
        $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );

        if ( str_starts_with( $filename$plugin_dir ) ) {
            $filename = str_replace( $plugin_dir, '', $filename );
            $filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename );

            $plugins = get_plugins();

            foreach ( $plugins as $name => $plugin ) {
                if ( str_starts_with( $name$filename ) ) {
                    return $plugin;
                }
'editorStyle' => 'editor',
    );

    /* * Ignore transient cache when the development mode is set to 'core'. Why? To avoid interfering with * the core developer's workflow. */
    if ( ! wp_is_development_mode( 'core' ) ) {
        $transient_name = 'wp_core_block_css_files';
        $files          = get_transient( $transient_name );
        if ( ! $files ) {
            $files = glob( wp_normalize_path( __DIR__ . '/**/**.css' ) );
            set_transient( $transient_name$files );
        }
    } else {
        $files = glob( wp_normalize_path( __DIR__ . '/**/**.css' ) );
    }

    $register_style = static function( $name$filename$style_handle ) use ( $includes_path$includes_url$suffix$wp_styles$files ) {
        $style_path = "blocks/{$name}/{$filename}{$suffix}.css";
        $path       = wp_normalize_path( $includes_path . $style_path );

        if ( ! in_array( $path$files, true ) ) {
            

function wp_json_file_decode( $filename$options = array() ) {
    $result   = null;
    $filename = wp_normalize_path( realpath( $filename ) );

    if ( ! $filename ) {
        trigger_error(
            sprintf(
                /* translators: %s: Path to the JSON file. */
                __( "File %s doesn't exist!" ),
                $filename
            )
        );
        return $result;
    }

    

function plugins_url( $path = '', $plugin = '' ) {

    $path          = wp_normalize_path( $path );
    $plugin        = wp_normalize_path( $plugin );
    $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );

    if ( ! empty( $plugin ) && str_starts_with( $plugin$mu_plugin_dir ) ) {
        $url = WPMU_PLUGIN_URL;
    } else {
        $url = WP_PLUGIN_URL;
    }

    $url = set_url_scheme( $url );

    

function plugin_basename( $file ) {
    global $wp_plugin_paths;

    // $wp_plugin_paths contains normalized paths.     $file = wp_normalize_path( $file );

    arsort( $wp_plugin_paths );

    foreach ( $wp_plugin_paths as $dir => $realdir ) {
        if ( str_starts_with( $file$realdir ) ) {
            $file = $dir . substr( $filestrlen( $realdir ) );
        }
    }

    $plugin_dir    = wp_normalize_path( WP_PLUGIN_DIR );
    $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );

    


        // Allow only 'http' and 'https' schemes. No 'data:', etc.         if ( isset( $lp['scheme'] ) && ! ( 'http' === $lp['scheme'] || 'https' === $lp['scheme'] ) ) {
            return $fallback_url;
        }

        if ( ! isset( $lp['host'] ) && ! empty( $lp['path'] ) && '/' !== $lp['path'][0] ) {
            $path = '';
            if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
                $path = dirname( parse_url( 'http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH ) . '?' );
                $path = wp_normalize_path( $path );
            }
            $location = '/' . ltrim( $path . '/', '/' ) . $location;
        }

        /* * Reject if certain components are set but host is not. * This catches URLs like https:host.com for which parse_url() does not set the host field. */
        if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) {
            return $fallback_url;
        }

        
protected function get_extension_for_error( $error ) {
        global $wp_theme_directories;

        if ( ! isset( $error['file'] ) ) {
            return false;
        }

        if ( ! defined( 'WP_PLUGIN_DIR' ) ) {
            return false;
        }

        $error_file    = wp_normalize_path( $error['file'] );
        $wp_plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );

        if ( str_starts_with( $error_file$wp_plugin_dir ) ) {
            $path  = str_replace( $wp_plugin_dir . '/', '', $error_file );
            $parts = explode( '/', $path );

            return array(
                'type' => 'plugin',
                'slug' => $parts[0],
            );
        }

        
Home | Imprint | This part of the site doesn't use cookies.