Support » Plugins » Trying to access wp_dropdown_pages() output in plugin from dashboard

  • Hi! I’m trying to figure out how to update the instance with the output from the wp_dropdown_menu() function from inside the dashboard. Here’s my code. Any ideas? I need to pull the page id, update the instance, and then be able to retrieve the id user-side so I can create a customized featured page by passing the id into WP functions.

    Plugin Name: Mardit's Featured Page Plugin
    Plugin URI:
    Description: This plugin will allow a user to choose a page to display in a featured page widget with a customizable learn more button and excerpt.
    Version: 1.0
    Author: Mario Keeney-Ditolla
    Author URI:
    class mardit_featured_page_plugin extends WP_Widget {
    	// constructor
    	function __construct(){
    			__('Mardit Featured Page', 'text_domain'),
    			array( 'description' => __('Mardit Featured Page Plugin', 'text_domain'),));
    	// display widget
    	function widget($args, $instance) {
    	   // these are the widget options
    	   $title = apply_filters('widget_title', $instance['title']);
    	   $page_id = $instance['page_id'];
    	   echo $args['before_widget'];
    	   // Display the widget
    	   echo '<div class="widget-text wp_widget_plugin_box">';
    	   // Check if title is set
    	   if ( $title ) {
    	      echo $args['before_title'] . 'Featured Page' . $args['after_title'];
    	   // Check if text is set
    	   echo $instance['page_id'];
    	   echo '</div>';
    	   echo $args['after_widget'];
    	// widget form creation
    	function form($instance) {
    	// Check values
    	if( $instance) {
    	     $title = esc_attr($instance['title']);
    	     $page_id = esc_attr($instance['page_id']);
    	} else {
    	     $title = '';
    	     $page_id = '';
    			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    			<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
    			<label for="<?php echo $this->get_field_id('page_id');?>"><?php _e('Page ID');?></label>
    			<?php wp_dropdown_pages(array(
    			    'id' => 'page_id',
    			    'name' => $this->get_field_name('page_id'),
    			    'selected' => $instance['page_id'],
    	}//end form
    	// widget update
    	function update($new_instance, $old_instance) {
    		$instance = array();
    		$instance['title'] = strip_tags($new_instance['title']);
    		$instance['page_id'] = strip_tags($new_instance['page_id']);
    		return instance;
    	}//end update
    }//end class
    // register widget
    function register_mardit_widget() {
    add_action('widgets_init', create_function('', 'return register_widget("mardit_featured_page_plugin");'));
  • The topic ‘Trying to access wp_dropdown_pages() output in plugin from dashboard’ is closed to new replies.