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
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 » 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'));
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.
Dude , your code is wrong on so many levels !
(and I am expressing only My own opinion here . )
you have
$query_images = new WP_Query( $query_images_args );
but you did not defined$query_images_arg
( fix by defining arguments )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 )you have many syntax errors like
echo$abc?
( fix toecho $abc
)3.1. $abc is supposed to be an array ? then you can not even use echo but
print_r($abc);
you are using the
settings APi
, which is serialized array , and then you call single options likeecho get_option('kkpo_quote');
( fix decide which method to use )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 …