wp_basename example


                $ext  = substr( $this->setting->default, -3 );
                $type = in_array( $ext, array( 'jpg', 'png', 'gif', 'bmp', 'webp' ), true ) ? 'image' : 'document';

                $default_attachment = array(
                    'id'    => 1,
                    'url'   => $this->setting->default,
                    'type'  => $type,
                    'icon'  => wp_mime_type_icon( $type ),
                    'title' => wp_basename( $this->setting->default ),
                );

                if ( 'image' === $type ) {
                    $default_attachment['sizes'] = array(
                        'full' => array( 'url' => $this->setting->default ),
                    );
                }

                $this->json['defaultAttachment'] = $default_attachment;
            }

            

function verify_file_signature( $filename$signatures$filename_for_errors = false ) {
    if ( ! $filename_for_errors ) {
        $filename_for_errors = wp_basename( $filename );
    }

    // Check we can process signatures.     if ( ! function_exists( 'sodium_crypto_sign_verify_detached' ) || ! in_array( 'sha384', array_map( 'strtolower', hash_algos() ), true ) ) {
        return new WP_Error(
            'signature_verification_unsupported',
            sprintf(
                /* translators: %s: The filename of the package. */
                __( 'The authenticity of %s could not be verified as signature verification is unavailable on this system.' ),
                '<span class="code">' . esc_html( $filename_for_errors ) . '</span>'
            ),
            (
if ( $current_screen->is_block_editor() ) {
    $admin_body_class .= ' block-editor-page wp-embed-responsive';
}

$error_get_last = error_get_last();

// Print a CSS class to make PHP errors visible. if ( $error_get_last && WP_DEBUG && WP_DEBUG_DISPLAY && ini_get( 'display_errors' )
    // Don't print the class for PHP notices in wp-config.php, as they happen before WP_DEBUG takes effect,     // and should not be displayed with the `error_reporting` level previously set in wp-load.php.     && ( E_NOTICE !== $error_get_last['type'] || 'wp-config.php' !== wp_basename( $error_get_last['file'] ) )
) {
    $admin_body_class .= ' php-error';
}

unset( $error_get_last );

?> </head> <?php /** * Filters the CSS classes for the body tag in the admin. * * This filter differs from the {@see 'post_class'} and {@see 'body_class'} filters * in two important ways: * * 1. `$classes` is a space-separated string of class names instead of an array. * 2. Not all core admin classes are filterable, notably: wp-admin, wp-core-ui, * and no-js cannot be removed. * * @since 2.3.0 * * @param string $classes Space-separated list of CSS classes. */

    }

    $file = wp_handle_upload( $_FILES[ $file_id ]$overrides$time );

    if ( isset( $file['error'] ) ) {
        return new WP_Error( 'upload_error', $file['error'] );
    }

    $name = $_FILES[ $file_id ]['name'];
    $ext  = pathinfo( $name, PATHINFO_EXTENSION );
    $name = wp_basename( $name, ".$ext);

    $url     = $file['url'];
    $type    = $file['type'];
    $file    = $file['file'];
    $title   = sanitize_text_field( $name );
    $content = '';
    $excerpt = '';

    if ( preg_match( '#^audio#', $type ) ) {
        $meta = wp_read_audio_metadata( $file );

        
<div class="media-item-wrapper"> <div class="attachment-details"> <?php                     $thumb_url = wp_get_attachment_image_src( $id, 'thumbnail', true );
                    if ( $thumb_url ) {
                        echo '<img class="pinkynail" src="' . esc_url( $thumb_url[0] ) . '" alt="" />';
                    }

                    // Title shouldn't ever be empty, but use filename just in case.                     $file     = get_attached_file( $post->ID );
                    $file_url = wp_get_attachment_url( $post->ID );
                    $title    = $post->post_title ? $post->post_title : wp_basename( $file );
                    ?> <div class="filename new"> <span class="media-list-title"><strong><?php echo esc_html( wp_html_excerpt( $title, 60, '&hellip;' ) ); ?></strong></span> <span class="media-list-subtitle"><?php echo wp_basename( $file ); ?></span> </div> </div> <div class="attachment-tools"> <span class="media-item-copy-container copy-to-clipboard-container edit-attachment"> <button type="button" class="button button-small copy-attachment-url" data-clipboard-text="<?php echo $file_url; ?>"><?php _e( 'Copy URL to clipboard' ); ?></button> <span class="success hidden" aria-hidden="true"><?php _e( 'Copied!' ); ?></span> </span>
return new WP_Error( 'image_save_error', $e->getMessage()$filename );
        }

        // Set correct file permissions.         $stat  = stat( dirname( $filename ) );
        $perms = $stat['mode'] & 0000666; // Same permissions as parent folder, strip off the executable bits.         chmod( $filename$perms );

        return array(
            'path'      => $filename,
            /** This filter is documented in wp-includes/class-wp-image-editor-gd.php */
            'file'      => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
            'width'     => $this->size['width'],
            'height'    => $this->size['height'],
            'mime-type' => $mime_type,
            'filesize'  => wp_filesize( $filename ),
        );
    }

    /** * Writes an image to a file or stream. * * @since 5.6.0 * * @param Imagick $image * @param string $filename The destination filename or stream URL. * @return true|WP_Error */

function wp_delete_attachment_files( $post_id$meta$backup_sizes$file ) {
    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;
                }
            }
        }
    }

    
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 )
                );
            }

            $tested_paths[ $path ] = $uploads['error'];
        }
    }
break;

    case 'editattachment':
        check_admin_referer( 'update-post_' . $post_id );

        // Don't let these be changed.         unset( $_POST['guid'] );
        $_POST['post_type'] = 'attachment';

        // Update the thumbnail filename.         $newmeta          = wp_get_attachment_metadata( $post_id, true );
        $newmeta['thumb'] = wp_basename( $_POST['thumb'] );

        wp_update_attachment_metadata( $post_id$newmeta );

        // Intentional fall-through to trigger the edit_post() call.     case 'editpost':
        check_admin_referer( 'update-post_' . $post_id );

        $post_id = edit_post();

        // Session cookie flag that the post was saved.         if ( isset( $_COOKIE['wp-saving-post'] ) && $_COOKIE['wp-saving-post'] === $post_id . '-check' ) {
            
if ( isset( $meta['width']$meta['height'] ) ) {
        $big = max( $meta['width']$meta['height'] );
    } else {
        die( __( 'Image data does not exist. Please re-upload the image.' ) );
    }

    $sizer = $big > 600 ? 600 / $big : 1;

    $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
    $can_restore  = false;
    if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig']$meta['file'] ) ) {
        $can_restore = wp_basename( $meta['file'] ) !== $backup_sizes['full-orig']['file'];
    }

    if ( $msg ) {
        if ( isset( $msg->error ) ) {
            $note = "<div class='notice notice-error' tabindex='-1' role='alert'><p>$msg->error</p></div>";
        } elseif ( isset( $msg->msg ) ) {
            $note = "<div class='notice notice-success' tabindex='-1' role='alert'><p>$msg->msg</p></div>";
        }
    }

    /** * Shows the settings in the Image Editor that allow selecting to edit only the thumbnail of an image. * * @since 6.3.0 * * @param bool $show Whether to show the settings in the Image Editor. Default false. */
        chmod( $filename$perms );

        return array(
            'path'      => $filename,
            /** * Filters the name of the saved image file. * * @since 2.6.0 * * @param string $filename Name of the file. */
            'file'      => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
            'width'     => $this->size['width'],
            'height'    => $this->size['height'],
            'mime-type' => $mime_type,
            'filesize'  => wp_filesize( $filename ),
        );
    }

    /** * Returns stream of current image. * * @since 3.5.0 * * @param string $mime_type The mime type of the image. * @return bool True on success, false on failure. */
if ( ! strpos( $src, '://' ) ) {
        $src = 'http://' . $src;
    }

    $src = sanitize_url( $src );
    if ( ! $src ) {
        wp_send_json_error();
    }

    $link_text = trim( wp_unslash( $_POST['link_text'] ) );
    if ( ! $link_text ) {
        $link_text = wp_basename( $src );
    }

    $post = get_post( isset( $_POST['post_id'] ) ? $_POST['post_id'] : 0 );

    // Ping WordPress for an embed.     $check_embed = $wp_embed->run_shortcode( '[embed]' . $src . '[/embed]' );

    // Fallback that WordPress creates when no oEmbed was found.     $fallback = $wp_embed->maybe_make_link( $src );

    if ( $check_embed !== $fallback ) {
        
// Re-generate attachment metadata since it was previously generated for a different theme.                         $metadata = wp_generate_attachment_metadata( $attachment_post->ID, $attached_file );
                        wp_update_attachment_metadata( $attachment_id$metadata );
                        update_post_meta( $attachment_id, '_starter_content_theme', $this->get_stylesheet() );
                    }
                }

                // Insert the attachment auto-draft because it doesn't yet exist or the attached file is gone.                 if ( ! $attachment_id ) {

                    // Copy file to temp location so that original file won't get deleted from theme after sideloading.                     $temp_file_name = wp_tempnam( wp_basename( $file_path ) );
                    if ( $temp_file_name && copy( $file_path$temp_file_name ) ) {
                        $file_array['tmp_name'] = $temp_file_name;
                    }
                    if ( empty( $file_array['tmp_name'] ) ) {
                        continue;
                    }

                    $attachment_post_data = array_merge(
                        wp_array_slice_assoc( $attachment, array( 'post_title', 'post_content', 'post_excerpt' ) ),
                        array(
                            'post_status' => 'auto-draft', // So attachment will be garbage collected in a week if changeset is never published.
if ( ! empty( $files ) ) {
            $file = $this->upload_from_file( $files$headers );
        } else {
            $file = $this->upload_from_data( $request->get_body()$headers );
        }

        if ( is_wp_error( $file ) ) {
            return $file;
        }

        $name       = wp_basename( $file['file'] );
        $name_parts = pathinfo( $name );
        $name       = trim( substr( $name, 0, -( 1 + strlen( $name_parts['extension'] ) ) ) );

        $url  = $file['url'];
        $type = $file['type'];
        $file = $file['file'];

        // Include image functions to get access to wp_read_image_metadata().         require_once ABSPATH . 'wp-admin/includes/image.php';

        // Use image exif/iptc data for title and caption defaults if possible.
$out = apply_filters( 'image_downsize', false, $id$size );

    if ( $out ) {
        return $out;
    }

    $img_url          = wp_get_attachment_url( $id );
    $meta             = wp_get_attachment_metadata( $id );
    $width            = 0;
    $height           = 0;
    $is_intermediate  = false;
    $img_url_basename = wp_basename( $img_url );

    /* * If the file isn't an image, attempt to replace its URL with a rendered image from its meta. * Otherwise, a non-image type could be returned. */
    if ( ! $is_image ) {
        if ( ! empty( $meta['sizes']['full'] ) ) {
            $img_url          = str_replace( $img_url_basename$meta['sizes']['full']['file']$img_url );
            $img_url_basename = $meta['sizes']['full']['file'];
            $width            = $meta['sizes']['full']['width'];
            $height           = $meta['sizes']['full']['height'];
        }
Home | Imprint | This part of the site doesn't use cookies.