'themeidol_widget_date_time', 'description' => __( 'Show the local date and/or time.', 'themeidol-all-widget') ) ); // Register admin styles and scripts add_action( 'admin_print_styles', array( $this, 'register_admin_styles' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_scripts' ) ); // Register site styles and scripts add_action( 'wp_enqueue_scripts', array( $this, 'register_widget_styles' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'register_widget_scripts' ) ); // Refreshing the widget's cached output with each new post add_action( 'save_post', array( $this, 'flush_widget_cache' ) ); add_action( 'deleted_post', array( $this, 'flush_widget_cache' ) ); add_action( 'switch_theme', array( $this, 'flush_widget_cache' ) ); } // end constructor /*--------------------------------------------------*/ /* Widget API Functions /*--------------------------------------------------*/ /** * Outputs the content of the widget. * * @param array args The array of form elements * @param array instance The current instance of the widget */ public function widget( $args, $instance ) { // Check if there is a cached output $cache = wp_cache_get( 'themeidol-dataandtime', 'widget' ); if ( !is_array( $cache ) ) { $cache = array(); } if ( !isset( $args['widget_id'] ) ) { $args['widget_id'] = $this->id; } if ( isset( $cache[ $args['widget_id'] ] ) ) { return print $cache[ $args['widget_id'] ]; } //Widget settings $time_format = $instance['time_format']; $date_format = $instance['date_format']; $font_family = $instance['font_family']; $font_size = $instance['font_size']; $text_color = $instance ['text_color']; $background_color = $instance ['background_color']; extract( $args, EXTR_SKIP ); $before_widget = str_replace('widget ', 'idol-widget ', $before_widget); $widget_string = $before_widget; ob_start(); ?>
'12-hour-seconds', 'date_format' => 'long', 'font_family' => 'Arial, Arial, Helvetica, sans-serif', 'font_size' => '20px', 'text_color' => '#000', 'background_color' => 'transparent' ) ); // Store the values of the widget in their own variables. $text_color = esc_attr( $instance['text_color'] ); $background_color = esc_attr( $instance['background_color'] ); // Display the admin form ?>

"None", "12-hour" => date("g:i A", current_time( 'timestamp', 0 ) ), "12-hour-seconds" => date("g:i:s A", current_time( 'timestamp', 0 ) ), "24-hour" => date("G:i", current_time( 'timestamp', 0 ) ), "24-hour-seconds" => date("G:i:s", current_time( 'timestamp', 0 ) ), ); foreach( $formats as $key => $value ) { $selected = ( $instance['time_format'] == $key ) ? 'selected="selected"' : ''; echo ''; } } /** * Render options in the Date Format dropdown. * * @since 1.1.0 */ public function render_date_format( $instance ) { $formats = array( "none" => "None", "short" => date( "n/j/Y", current_time( 'timestamp', 0 ) ), "european" => date( "j/n/Y", current_time( 'timestamp', 0 ) ), "medium" => date( "M j Y", current_time( 'timestamp', 0 ) ), "long" => date( "F j, Y", current_time( 'timestamp', 0 ) ), ); foreach( $formats as $key => $value ) { $selected = ( $instance['date_format'] == $key ) ? 'selected="selected"' : ''; echo ''; } } /** * Render options in the Font Family dropdown. * * @since 1.1.0 */ public function render_font_family( $instance ) { $font_families = array( "Arial, Arial, Helvetica, sans-serif" => "Arial", "Comic Sans MS, Comic Sans MS, cursive" => "Comic Sans MS", "Courier New, Courier New, Courier, monospace" => "Courier New", "Georgia, Georgia, serif" => "Georgia", "Lucida Sans Unicode, Lucida Grande, sans-serif" => "Lucida Sans Unicode", "Tahoma, Geneva, sans-serif" => "Tahoma", "Times New Roman, Times, serif" => "Times New Roman", "Trebuchet MS, Helvetica, sans-serif" => "Trebuchet MS", "Verdana, Verdana, Geneva, sans-serif" => "Verdana", ); foreach( $font_families as $key => $value ) { $selected = ( $instance['font_family'] == $key ) ? 'selected="selected"' : ''; echo ''; } } /** * Render options in the Font Size dropdown. * * @since 1.1.0 */ public function render_font_size( $instance ) { $font_sizes = array( "8px" => "8", "9px" => "9", "10px" => "10", "11px" => "11", "12px" => "12", "14px" => "14", "16px" => "16", "18px" => "18", "20px" => "20", "22px" => "22", "24px" => "24", "26px" => "26", "28px" => "28", "36px" => "36", "48px" => "48", "72px" => "72", ); foreach( $font_sizes as $key => $value ) { $selected = ( $instance['font_size'] == $key ) ? 'selected="selected"' : ''; echo ''; } } } // end class add_action( 'widgets_init', create_function( '', 'register_widget("Themeidol_Date_and_Time");' ) );