How to get images of whole blog in option page of wordpress plugin?

I have to get all images sources of the blog in the options page of plugin and i am making a plugin option page as follows ..Plz look in to it ..

public function add_plugin_page(){  
                add_options_page('Settings Admin', 'Plugin_options', 'manage_options', 'test-setting-admin', array($this, 'create_admin_page'));
            }

Following code is for my plugin option page

Read More
public function create_admin_page(){
        ?>
    <div class="wrap">

    <?php screen_icon(); ?>

    <form action="options.php" method="post" id="<?php echo $plugin_id; ?>_options_form" name="<?php echo $plugin_id; ?>_options_form">

    <?php settings_fields($plugin_id.'_options'); ?>

    <h2>kk Plugin Options &raquo; Settings</h2>

   <table border="1" bordercolor="#FFCC00" style="background-color:#FFFFCC; margin-top:22px"  width="25%" cellpadding="2" cellspacing="1">
       <tbody>
       <tr>
        <td style="padding-left:8px;font-family:Verdana, Geneva, sans-serif;color:#666;"><h3>Blog Id:</h3></td>
        <td><p><?php echo$abc?></p></td>
    </tr>
    <tr>
        <td style="padding-left:8px;font-family:Verdana, Geneva, sans-serif;color:#666;"><h3>API Key:</h3></td>
        <td><input type="text" name="kkpo_quote" value="<?php echo get_option('kkpo_quote'); ?>" /></td>
    </tr>
        </tbody>

</table>
   <div id="mainCHImage" style="position:relative;height:'.$imgHeight.'px;width:'.$width.'px;">
         <img id="paletlyIcon" style="position:absolute;left:'.$imgWidth.'px;top:'.$imgHeight.'px;z-index:9999;cursor:pointer;background:none;border:none;" src="http://Images/favIcon.png" onclick="get_images()">'.   
        <img style="background:none;border:none;"></div>


    </form>

</div>
    <?php
    }

$abc is variable in which i want all image sources ..For that i have written a separate function

public function get_images(){
    if(is_single() || is_page() || is_home()||!is_admin() ){  
    global $post; 
    global $wpdb;

    $query_images = new WP_Query( $query_images_args );
    $images = array();

         foreach ( $query_images->posts as $image) {      
         $images[]= wp_get_attachment_url( $image->ID );
                 $abc=($images);
                 echo $abc;
                 }

    }


}

But i am getting error

ReferenceError: get_images is not defined
[Break On This Error]   

get_images();

I have added that function in my construct i.e.

add_action('IMages_grab', array(&$this, 'get_images'));
add_filter('IMages_grab', array(&$this, 'get_images'));

Related posts

Leave a Reply

2 comments

  1. I agree with most of @ObmerkKronen Answer, but with point 5. Which is the core of Question, in my opinion.

    Yes, it’s valid to want an array with all posts (and attachments are a post type). And a 10K array may not be that big depending of how it’s used.

    The following example displays an Admin Notice with links to all images in the Media Library. Consult the Codex to know the functions used here. Should be fairly easy to adapt this to a plugin’s option page.

    add_action( 'admin_notices', 'get_all_images_so_15985067' );
    
    function get_all_images_so_15985067() 
    {
        // get all images
        $args = array( 
            'post_type' => 'attachment', 
            'post_mime_type' => 'image',
            'numberposts' => -1,
        );
        $_attachments = get_posts( $args );
    
        // no images found, do nothing
        if ( empty( $_attachments ) )
            return;
    
        // build array only with IDs
        $attachments = array();
        foreach ( $_attachments as $key => $val ) {
            $attachments[ $val->ID ] = $_attachments[ $key ];
        }
    
        // print thumbnail links
        echo '<div class="updated">';
        foreach ( $attachments as $att_id => $attachment ) {
            echo wp_get_attachment_link( 
                $att_id, 
                'thumbnail', 
                false, 
                false, 
                $attachment->post_title 
            ) . "<br>";
        }
        echo '</div>';
    }
    
  2. Dude , your code is wrong on so many levels !
    (and I am expressing only My own opinion here . )

    1. you have $query_images = new WP_Query( $query_images_args ); but you did not defined $query_images_arg ( fix by defining arguments )

    2. you are constructing some kind of admin menu, but then you put the condition of !is_admin() which will null everything ( fix by deciding / defining where it operates )

    3. you have many syntax errors like echo$abc? ( fix to echo $abc )

      3.1. $abc is supposed to be an array ? then you can not even use echo but print_r($abc);

    4. you are using the settings APi , which is serialized array , and then you call single options like echo get_option('kkpo_quote'); ( fix decide which method to use )

    5. this is the most important one , why on earth would one want to get ALL the images of a whole website into an array , and further more , echo it ?? can you imagine what will happen with a site that has 10,000 images _ or even only 300 ?

    Now , your code is clearly some kind of an attempt or an exercise in cut & paste plugin development . and to give a good answer will mean you will have to better explain your intentions, but you can start with fixing what I have wrote in the above , and not complete, list …