Advertisement
rainbowgeek

wpcloudy

Jan 11th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Add a widget to the dashboard.
  5.  */
  6. function wpc_add_dashboard_widgets() {
  7.  
  8.     wp_add_dashboard_widget(
  9.                  'wpcloudy_dashboard_widget',     // Widget slug.
  10.                  'WP Cloudy',    // Title.
  11.                  'wpc_dashboard_widget_function',  // Display function.
  12.                  'wpc_dashboard_widget_option'   //Options
  13.         ); 
  14. }
  15. add_action( 'wp_dashboard_setup', 'wpc_add_dashboard_widgets' );
  16.  
  17. /**
  18.  * Create the function to output the contents of our Dashboard Widget.
  19.  */
  20.  
  21. function wpc_dashboard_widget_function() {
  22.  
  23.     // Display selected weather.
  24.     if ( $my_weather = get_option( 'wpc_dashboard_widget_option' ) ) {
  25.         echo do_shortcode('[wpc-weather id="'.$my_weather['weather_db'].'"]');
  26.     }
  27. }
  28. /**
  29.  * Create the function to configure our Dashboard Widget.
  30.  */
  31. function wpc_dashboard_widget_option($widget_id) {
  32.    
  33.     // Get widget options
  34.     if ( !$wpc_widget_options = get_option( 'wpc_dashboard_widget_option' ) )
  35.         $wpc_widget_options = array();
  36.    
  37.     // Update widget options
  38.     if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['wpc_widget_post']) ) {
  39.         update_option( 'wpc_dashboard_widget_option', $_POST['wpc_widget'] );
  40.     }
  41.    
  42.     // Retrieve feed URLs
  43.     $weather_db = $wpc_widget_options['weather_db'];
  44.    
  45.  
  46.     echo'<p>';
  47.     echo'<label for="wpc_weather_db-">';
  48.             _e('Select the weather to display:', 'wpcloudy');
  49.     echo'</label>';
  50.  
  51.     echo'<select name="wpc_widget[weather_db]">';
  52.            
  53.             $query = new WP_Query( array( 'post_type' => array( 'wpc-weather' ) ) );
  54.    
  55.                 while ( $query->have_posts() ) : $query->the_post();
  56.    
  57.                     echo '<option value="'.get_the_ID().'"';
  58.                             selected( $weather_db, get_the_ID() );
  59.                     echo '>';
  60.                             the_title();
  61.    
  62.                     echo '</option>';
  63.                 endwhile;
  64.            
  65.        
  66.            
  67.         echo'</select>';
  68.                
  69.     echo'</p>';
  70.    
  71.     echo'<input name="wpc_widget_post" type="hidden" value="1" />';
  72.  
  73. }
  74.  
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement