wp_get_upload_dir example


function get_attached_file( $attachment_id$unfiltered = false ) {
    $file = get_post_meta( $attachment_id, '_wp_attached_file', true );

    // If the file is relative, prepend upload dir.     if ( $file && ! str_starts_with( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) ) {
        $uploads = wp_get_upload_dir();
        if ( false === $uploads['error'] ) {
            $file = $uploads['basedir'] . "/$file";
        }
    }

    if ( $unfiltered ) {
        return $file;
    }

    /** * Filters the attached file based on the given ID. * * @since 2.1.0 * * @param string|false $file The file path to where the attached file should be, false otherwise. * @param int $attachment_id Attachment ID. */
            $filename = str_replace( "{$fname}{$ext}", "{$fname}-{$number}{$ext}", $filename );
        }

        /* * Get the mime type. Uploaded files were already checked with wp_check_filetype_and_ext() * in _wp_handle_upload(). Using wp_check_filetype() would be sufficient here. */
        $file_type = wp_check_filetype( $filename );
        $mime_type = $file_type['type'];

        $is_image    = ( ! empty( $mime_type ) && str_starts_with( $mime_type, 'image/' ) );
        $upload_dir  = wp_get_upload_dir();
        $lc_filename = null;

        $lc_ext = strtolower( $ext );
        $_dir   = trailingslashit( $dir );

        /* * If the extension is uppercase add an alternate file name with lowercase extension. * Both need to be tested for uniqueness as the extension will be changed to lowercase * for better compatibility with different filesystems. Fixes an inconsistency in WP < 2.9 * where uppercase extensions were allowed but image sub-sizes were created with * lowercase extensions. */
foreach ( $users as $user_id ) {
            remove_user_from_blog( $user_id$site->id );
        }
    }

    $switch = false;
    if ( get_current_blog_id() !== $site->id ) {
        $switch = true;
        switch_to_blog( $site->id );
    }

    $uploads = wp_get_upload_dir();

    $tables = $wpdb->tables( 'blog' );

    /** * Filters the tables to drop when the site is deleted. * * @since MU (3.0.0) * * @param string[] $tables Array of names of the site tables to be dropped. * @param int $site_id The ID of the site to drop tables for. */
    
 elseif ( str_contains( $image_src$image_meta['file'] ) ) {
        return false;
    }

    // Retrieve the uploads sub-directory from the full size image.     $dirname = _wp_get_attachment_relative_path( $image_meta['file'] );

    if ( $dirname ) {
        $dirname = trailingslashit( $dirname );
    }

    $upload_dir    = wp_get_upload_dir();
    $image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname;

    /* * If currently on HTTPS, prefer HTTPS URLs when we know they're supported by the domain * (which is to say, when they share the domain name of the current request). */
    if ( is_ssl() && ! str_starts_with( $image_baseurl, 'https' ) && parse_url( $image_baseurl, PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) {
        $image_baseurl = set_url_scheme( $image_baseurl, 'https' );
    }

    /* * Images that have been edited in WordPress after being uploaded will * contain a unique hash. Look for that hash and use it later to filter * out images that are leftovers from previous versions. */
$pingback_str_dquote = 'rel="pingback"';
    $pingback_str_squote = 'rel=\'pingback\'';

    /** @todo Should use Filter Extension or custom preg_match instead. */
    $parsed_url = parse_url( $url );

    if ( ! isset( $parsed_url['host'] ) ) { // Not a URL. This should never happen.         return false;
    }

    // Do not search for a pingback server on our own uploads.     $uploads_dir = wp_get_upload_dir();
    if ( str_starts_with( $url$uploads_dir['baseurl'] ) ) {
        return false;
    }

    $response = wp_safe_remote_head(
        $url,
        array(
            'timeout'     => 2,
            'httpversion' => '1.0',
        )
    );

    
/** * Fetches the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`. * Intended to supplement the array returned by `WP_Debug_Data::debug_data()`. * * @since 5.2.0 * * @return array The sizes of the directories, also the database size and total installation size. */
    public static function get_sizes() {
        $size_db    = self::get_database_size();
        $upload_dir = wp_get_upload_dir();

        /* * We will be using the PHP max execution time to prevent the size calculations * from causing a timeout. The default value is 30 seconds, and some * hosts do not allow you to read configuration values. */
        if ( function_exists( 'ini_get' ) ) {
            $max_execution_time = ini_get( 'max_execution_time' );
        }

        /* * The max_execution_time defaults to 0 when PHP runs from cli. * We still want to limit it below. */
Home | Imprint | This part of the site doesn't use cookies.