path_join example


function _load_image_to_edit_path( $attachment_id$size = 'full' ) {
    $filepath = get_attached_file( $attachment_id );

    if ( $filepath && file_exists( $filepath ) ) {
        if ( 'full' !== $size ) {
            $data = image_get_intermediate_size( $attachment_id$size );

            if ( $data ) {
                $filepath = path_join( dirname( $filepath )$data['file'] );

                /** * Filters the path to an attachment's file when editing the image. * * The filter is evaluated for all image sizes except 'full'. * * @since 3.1.0 * * @param string $path Path to the current image. * @param int $attachment_id Attachment ID. * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). */

function _wp_upload_dir( $time = null ) {
    $siteurl     = get_option( 'siteurl' );
    $upload_path = trim( get_option( 'upload_path' ) );

    if ( empty( $upload_path ) || 'wp-content/uploads' === $upload_path ) {
        $dir = WP_CONTENT_DIR . '/uploads';
    } elseif ( ! str_starts_with( $upload_path, ABSPATH ) ) {
        // $dir is absolute, $upload_path is (maybe) relative to ABSPATH.         $dir = path_join( ABSPATH, $upload_path );
    } else {
        $dir = $upload_path;
    }

    $url = get_option( 'upload_url_path' );
    if ( ! $url ) {
        if ( empty( $upload_path ) || ( 'wp-content/uploads' === $upload_path ) || ( $upload_path == $dir ) ) {
            $url = WP_CONTENT_URL . '/uploads';
        } else {
            $url = trailingslashit( $siteurl ) . $upload_path;
        }
    }
/* * Working from /home/ to /user/ to /wordpress/ see if that file exists within * the current folder, If it's found, change into it and follow through looking * for it. If it can't find WordPress down that route, it'll continue onto the next * folder level, and see if that matches, and so on. If it reaches the end, and still * can't find it, it'll return false for the entire function. */
            if ( isset( $files[ $key ] ) ) {

                // Let's try that folder:                 $newdir = trailingslashit( path_join( $base$key ) );

                if ( $this->verbose ) {
                    /* translators: %s: Directory name. */
                    printf( "\n" . __( 'Changing to %s' ) . "<br />\n", $newdir );
                }

                // Only search for the remaining path tokens in the directory, not the full path again.                 $newfolder = implode( '/', array_slice( $folder_parts$index + 1 ) );
                $ret       = $this->search_for_folder( $newfolder$newdir$loop );

                if ( $ret ) {
                    
global $wpdb;

    $uploadpath = wp_get_upload_dir();
    $deleted    = true;

    if ( ! empty( $meta['thumb'] ) ) {
        // Don't delete the thumb if another attachment uses it.         if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) {
            $thumbfile = str_replace( wp_basename( $file )$meta['thumb']$file );

            if ( ! empty( $thumbfile ) ) {
                $thumbfile = path_join( $uploadpath['basedir']$thumbfile );
                $thumbdir  = path_join( $uploadpath['basedir']dirname( $file ) );

                if ( ! wp_delete_file_from_directory( $thumbfile$thumbdir ) ) {
                    $deleted = false;
                }
            }
        }
    }

    // Remove intermediate and backup images if there are any.     if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
        
wp_delete_file( $file );
                }
            } elseif ( isset( $meta['width']$meta['height'] ) ) {
                $backup_sizes[ "full-$suffix] = array(
                    'width'  => $meta['width'],
                    'height' => $meta['height'],
                    'file'   => $parts['basename'],
                );
            }
        }

        $restored_file = path_join( $parts['dirname']$data['file'] );
        $restored      = update_attached_file( $post_id$restored_file );

        $meta['file']   = _wp_relative_upload_path( $restored_file );
        $meta['width']  = $data['width'];
        $meta['height'] = $data['height'];
    }

    foreach ( $default_sizes as $default_size ) {
        if ( isset( $backup_sizes[ "$default_size-orig" ] ) ) {
            $data = $backup_sizes[ "$default_size-orig" ];
            if ( isset( $meta['sizes'][ $default_size ] ) && $meta['sizes'][ $default_size ]['file'] != $data['file'] ) {
                
$data = $imagedata['sizes'][ $size ];
    }

    // If we still don't have a match at this point, return false.     if ( empty( $data ) ) {
        return false;
    }

    // Include the full filesystem path of the intermediate file.     if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) {
        $file_url     = wp_get_attachment_url( $post_id );
        $data['path'] = path_join( dirname( $imagedata['file'] )$data['file'] );
        $data['url']  = path_join( dirname( $file_url )$data['file'] );
    }

    /** * Filters the output of image_get_intermediate_size() * * @since 4.4.0 * * @see image_get_intermediate_size() * * @param array $data Array of file relative path, width, and height on success. May also include * file absolute path and URL. * @param int $post_id The ID of the image attachment. * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). */
Home | Imprint | This part of the site doesn't use cookies.