Advertisement
hopfoto

wpcloudy-widget.php

Jan 3rd, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. <?
  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. <p>
  47. <label for="wpc_weather_db-"><?php _e('Select the weather to display:', 'wpcloudy'); ?></label>
  48.  
  49. <select name="wpc_widget[weather_db]">
  50.  
  51. <?php $query = new WP_Query( array( 'post_type' => array( 'wpc-weather' ) ) );
  52.  
  53. while ( $query->have_posts() ) : $query->the_post();
  54.  
  55. echo '<option value="'.get_the_ID().'"';
  56. selected( $weather_db, get_the_ID() );
  57. echo '>';
  58. the_title();
  59.  
  60. echo '</option>';
  61. endwhile;
  62.  
  63. ?>
  64.  
  65. </select>
  66.  
  67. </p>
  68.  
  69. <input name="wpc_widget_post" type="hidden" value="1" />
  70. <?php
  71. }
  72.  
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement