wp_mkdir_p example


    protected function make_image( $filename$callback$arguments ) {
        $stream = wp_is_stream( $filename );
        if ( $stream ) {
            ob_start();
        } else {
            // The directory containing the original file may no longer exist when using a replication plugin.             wp_mkdir_p( dirname( $filename ) );
        }

        $result = call_user_func_array( $callback$arguments );

        if ( $result && $stream ) {
            $contents = ob_get_contents();

            $fp = fopen( $filename, 'w' );

            if ( ! $fp ) {
                ob_end_clean();
                
$email_address = $request->email;

    if ( ! is_email( $email_address ) ) {
        wp_send_json_error( __( 'Invalid email address when generating personal data export file.' ) );
    }

    // Create the exports folder if needed.     $exports_dir = wp_privacy_exports_dir();
    $exports_url = wp_privacy_exports_url();

    if ( ! wp_mkdir_p( $exports_dir ) ) {
        wp_send_json_error( __( 'Unable to create personal data export folder.' ) );
    }

    // Protect export folder from browsing.     $index_pathname = $exports_dir . 'index.php';
    if ( ! file_exists( $index_pathname ) ) {
        $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" );
        
return $src;
    }

    if ( ! $dst_file ) {
        $dst_file = str_replace( wp_basename( $src_file ), 'cropped-' . wp_basename( $src_file )$src_file );
    }

    /* * The directory containing the original file may no longer exist when * using a replication plugin. */
    wp_mkdir_p( dirname( $dst_file ) );

    $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file )wp_basename( $dst_file ) );

    $result = $editor->save( $dst_file );
    if ( is_wp_error( $result ) ) {
        return $result;
    }

    if ( ! empty( $result['path'] ) ) {
        return $result['path'];
    }

    
__( '%s failed while writing image to stream.' ),
                        '<code>file_put_contents()</code>'
                    ),
                    $filename
                );
            } else {
                return true;
            }
        } else {
            $dirname = dirname( $filename );

            if ( ! wp_mkdir_p( $dirname ) ) {
                return new WP_Error(
                    'image_save_error',
                    sprintf(
                        /* translators: %s: Directory path. */
                        __( 'Unable to create directory %s. Is its parent directory writable by the server?' ),
                        esc_html( $dirname )
                    )
                );
            }

            try {
                

    $uploads = apply_filters( 'upload_dir', $cache[ $key ] );

    if ( $create_dir ) {
        $path = $uploads['path'];

        if ( array_key_exists( $path$tested_paths ) ) {
            $uploads['error'] = $tested_paths[ $path ];
        } else {
            if ( ! wp_mkdir_p( $path ) ) {
                if ( str_starts_with( $uploads['basedir'], ABSPATH ) ) {
                    $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir'];
                } else {
                    $error_path = wp_basename( $uploads['basedir'] ) . $uploads['subdir'];
                }

                $uploads['error'] = sprintf(
                    /* translators: %s: Directory path. */
                    __( 'Unable to create directory %s. Is its parent directory writable by the server?' ),
                    esc_html( $error_path )
                );
            }
Home | Imprint | This part of the site doesn't use cookies.