0
votes

I am creating a wordpress plugin and I would like to enable the user to use images from the media library. For example: the »Choose Image« button in the »header« section of Theme configuration does exactly what I am looking for.

Is there any wordpress method I can call to generate such a button?

Greetings philipp

1

1 Answers

1
votes

what you try to accomplish is not clear, using all the images is one thing and give them an option to use wordpress uploader is one thing.

give them the last option is not recommended because they can abuse your system without control.

to see all the images you can use this function, return an array :

function get_all_images(){
    $args = array(
        'post_type' => 'attachment',
        'post_mime_type' =>'image',
        'post_status' => 'inherit',
        'posts_per_page' => -1,
    );
    $query = new WP_Query( $args );
    $images = array();
    foreach ( $query->posts as $image) {
        $images[]= wp_get_attachment_url($image->ID);
    }
    return $images;
}