wp_attachment_is example

$post['post_status'] = $changes['status'];
    }

    if ( isset( $changes['alt'] ) ) {
        $alt = wp_unslash( $changes['alt'] );
        if ( get_post_meta( $id, '_wp_attachment_image_alt', true ) !== $alt ) {
            $alt = wp_strip_all_tags( $alt, true );
            update_post_meta( $id, '_wp_attachment_image_alt', wp_slash( $alt ) );
        }
    }

    if ( wp_attachment_is( 'audio', $post['ID'] ) ) {
        $changed = false;
        $id3data = wp_get_attachment_metadata( $post['ID'] );

        if ( ! is_array( $id3data ) ) {
            $changed = true;
            $id3data = array();
        }

        foreach ( wp_get_attachment_id3_keys( (object) $post, 'edit' ) as $key => $label ) {
            if ( isset( $changes[ $key ] ) ) {
                $changed         = true;
                
if ( ! empty( $postarr['context'] ) ) {
            add_post_meta( $post_id, '_wp_attachment_context', $postarr['context'], true );
        }
    }

    // Set or remove featured image.     if ( isset( $postarr['_thumbnail_id'] ) ) {
        $thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type;

        if ( ! $thumbnail_support && 'attachment' === $post_type && $post_mime_type ) {
            if ( wp_attachment_is( 'audio', $post_id ) ) {
                $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
            } elseif ( wp_attachment_is( 'video', $post_id ) ) {
                $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
            }
        }

        if ( $thumbnail_support ) {
            $thumbnail_id = (int) $postarr['_thumbnail_id'];
            if ( -1 === $thumbnail_id ) {
                delete_post_thumbnail( $post_id );
            } else {
                
// Add post thumbnail to response if available.     $thumbnail_id = false;

    if ( has_post_thumbnail( $post->ID ) ) {
        $thumbnail_id = get_post_thumbnail_id( $post->ID );
    }

    if ( 'attachment' === get_post_type( $post ) ) {
        if ( wp_attachment_is_image( $post ) ) {
            $thumbnail_id = $post->ID;
        } elseif ( wp_attachment_is( 'video', $post ) ) {
            $thumbnail_id = get_post_thumbnail_id( $post );
            $data['type'] = 'video';
        }
    }

    if ( $thumbnail_id ) {
        list( $thumbnail_url$thumbnail_width$thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 99999 ) );
        $data['thumbnail_url']                                      = $thumbnail_url;
        $data['thumbnail_width']                                    = $thumbnail_width;
        $data['thumbnail_height']                                   = $thumbnail_height;
    }

    
$post = null;
    if ( isset( $args['post'] ) ) {
        $post             = get_post( $args['post'] );
        $settings['post'] = array(
            'id'    => $post->ID,
            'nonce' => wp_create_nonce( 'update-post_' . $post->ID ),
        );

        $thumbnail_support = current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' );
        if ( ! $thumbnail_support && 'attachment' === $post->post_type && $post->post_mime_type ) {
            if ( wp_attachment_is( 'audio', $post ) ) {
                $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
            } elseif ( wp_attachment_is( 'video', $post ) ) {
                $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
            }
        }

        if ( $thumbnail_support ) {
            $featured_image_id                   = get_post_meta( $post->ID, '_thumbnail_id', true );
            $settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
        }
    }

    

function register_and_do_post_meta_boxes( $post ) {
    $post_type        = $post->post_type;
    $post_type_object = get_post_type_object( $post_type );

    $thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' );
    if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) {
        if ( wp_attachment_is( 'audio', $post ) ) {
            $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
        } elseif ( wp_attachment_is( 'video', $post ) ) {
            $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
        }
    }

    $publish_callback_args = array( '__back_compat_meta_box' => true );

    if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' !== $post->post_status ) {
        $revisions = wp_get_latest_revision_id_and_total_count( $post->ID );

        

function prepend_attachment( $content ) {
    $post = get_post();

    if ( empty( $post->post_type ) || 'attachment' !== $post->post_type ) {
        return $content;
    }

    if ( wp_attachment_is( 'video', $post ) ) {
        $meta = wp_get_attachment_metadata( get_the_ID() );
        $atts = array( 'src' => wp_get_attachment_url() );
        if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
            $atts['width']  = (int) $meta['width'];
            $atts['height'] = (int) $meta['height'];
        }
        if ( has_post_thumbnail() ) {
            $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() );
        }
        $p = wp_video_shortcode( $atts );
    } elseif ( wp_attachment_is( 'audio', $post ) ) {
        
$post_ID = isset( $post_ID ) ? (int) $post_ID : 0;
$user_ID = isset( $user_ID ) ? (int) $user_ID : 0;
$action  = isset( $action ) ? $action : '';

if ( (int) get_option( 'page_for_posts' ) === $post->ID && empty( $post->post_content ) ) {
    add_action( 'edit_form_after_title', '_wp_posts_page_notice' );
    remove_post_type_support( $post_type, 'editor' );
}

$thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' );
if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) {
    if ( wp_attachment_is( 'audio', $post ) ) {
        $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
    } elseif ( wp_attachment_is( 'video', $post ) ) {
        $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
    }
}

if ( $thumbnail_support ) {
    add_thickbox();
    wp_enqueue_media( array( 'post' => $post->ID ) );
}

<?php echo $not_open_style; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>"> <?php
        if ( $open ) {
            wp_image_editor( $attachment_id );
        }

        ?> </div> <?php     elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ) :

        wp_maybe_generate_attachment_metadata( $post );

        echo wp_audio_shortcode( array( 'src' => $att_url ) );

    elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ) :

        wp_maybe_generate_attachment_metadata( $post );

        $meta = wp_get_attachment_metadata( $attachment_id );
        $w    = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0;
        

function wp_generate_attachment_metadata( $attachment_id$file ) {
    $attachment = get_post( $attachment_id );

    $metadata  = array();
    $support   = false;
    $mime_type = get_post_mime_type( $attachment );

    if ( preg_match( '!^image/!', $mime_type ) && file_is_displayable_image( $file ) ) {
        // Make thumbnails and other intermediate sizes.         $metadata = wp_create_image_subsizes( $file$attachment_id );
    } elseif ( wp_attachment_is( 'video', $attachment ) ) {
        $metadata = wp_read_video_metadata( $file );
        $support  = current_theme_supports( 'post-thumbnails', 'attachment:video' ) || post_type_supports( 'attachment:video', 'thumbnail' );
    } elseif ( wp_attachment_is( 'audio', $attachment ) ) {
        $metadata = wp_read_audio_metadata( $file );
        $support  = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) || post_type_supports( 'attachment:audio', 'thumbnail' );
    }

    /* * wp_read_video_metadata() and wp_read_audio_metadata() return `false` * if the attachment does not exist in the local filesystem, * so make sure to convert the value to an array. */
public function is_attachment_with_mime_type( $attachment$mime_type ) {
        if ( empty( $attachment ) ) {
            return false;
        }
        $attachment = get_post( $attachment );
        if ( ! $attachment ) {
            return false;
        }
        if ( 'attachment' !== $attachment->post_type ) {
            return false;
        }
        return wp_attachment_is( $mime_type$attachment );
    }

    /** * Sanitize a token list string, such as used in HTML rel and class attributes. * * @since 4.8.0 * * @link http://w3c.github.io/html/infrastructure.html#space-separated-tokens * @link https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList * @param string|array $tokens List of tokens separated by spaces, or an array of tokens. * @return string Sanitized token string list. */
Home | Imprint | This part of the site doesn't use cookies.