$this->widget_cssclass, 'description' => $this->widget_description, 'customize_selective_refresh' => $this->customize_selective_refresh, ); parent::__construct( $this->widget_id, $this->widget_name, $widget_options, $this->control_options ); } /** * Updates a particular instance of a widget. * * @param array $new_instance New instance. * @param array $old_instance Old instance. * * @return array * @see WP_Widget->update */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; if ( empty( $this->settings ) ) { return $instance; } // Loop settings and get values to save. foreach ( $this->settings as $key => $setting ) { if ( ! isset( $setting['type'] ) ) { continue; } // Format the value based on settings type. switch ( $setting['type'] ) { case 'url': $instance[ $key ] = isset( $new_instance[ $key ] ) ? esc_url_raw( $new_instance[ $key ] ) : $setting['default']; break; case 'textarea': $instance[ $key ] = wp_kses( trim( wp_unslash( $new_instance[ $key ] ) ), wp_kses_allowed_html( 'post' ) ); break; case 'image': /** * Array of valid image file types. * * The array includes image mime types that are included in wp_get_mime_types() */ $mimes = array( 'jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tiff|tif' => 'image/tiff', 'ico' => 'image/x-icon', ); // Return an array with file extension and mime_type. $file = wp_check_filetype( $new_instance[ $key ], $mimes ); // If $new_instance[ $key ] has a valid mime_type, assign it to $instance[ $key ], otherwise, assign empty value to $instance[ $key ]. $instance[ $key ] = $file['ext'] ? $new_instance[ $key ] : $setting['default']; break; case 'checkbox': $instance[ $key ] = ( '1' == $new_instance[ $key ] || 'on' == $new_instance[ $key ] ) ? '1' : '0'; break; case 'number': $instance[ $key ] = is_numeric( $new_instance[ $key ] ) ? intval( $new_instance[ $key ] ) : $setting['default']; if ( isset( $setting['input_attrs']['min'] ) && '' !== $setting['input_attrs']['min'] ) { $instance[ $key ] = max( $instance[ $key ], $setting['input_attrs']['min'] ); } if ( isset( $setting['input_attrs']['max'] ) && '' !== $setting['input_attrs']['max'] ) { $instance[ $key ] = min( $instance[ $key ], $setting['input_attrs']['max'] ); } break; case 'radio': case 'select': $new_instance[ $key ] = sanitize_key( $new_instance[ $key ] ); $available_choices = $setting['choices']; $instance[ $key ] = array_key_exists( $new_instance[ $key ], $available_choices ) ? $new_instance[ $key ] : $setting['default']; break; case 'dropdown_categories': $new_instance[ $key ] = ( '-1' == $new_instance[ $key ] ) ? '0' : absint( $new_instance[ $key ] ); $instance[ $key ] = term_exists( $new_instance[ $key ], 'category' ) ? $new_instance[ $key ] : $setting['default']; break; case 'dropdown_tags': $new_instance[ $key ] = ( '-1' == $new_instance[ $key ] ) ? '0' : absint( $new_instance[ $key ] ); $instance[ $key ] = term_exists( $new_instance[ $key ], 'post_tag' ) ? $new_instance[ $key ] : $setting['default']; break; case 'dropdown_users': $new_instance[ $key ] = ( '-1' == $new_instance[ $key ] ) ? '0' : absint( $new_instance[ $key ] ); $available_users = array(); $all_author_users = get_users( array( 'capability' => 'authors', ) ); foreach ( $all_author_users as $author_user ) { $available_users[ $author_user->ID ] = $author_user->display_name; } $instance[ $key ] = array_key_exists( $new_instance[ $key ], $available_users ) ? $new_instance[ $key ] : $setting['default']; break; case 'checkboxes': $saved_data = array(); $instance[ $key ] = $new_instance[ $key ]; foreach ( $instance[ $key ] as $item => $value ) { $saved_data[ $item ] = isset( $item ) ? 1 : 0; } $instance[ $key ] = $saved_data; break; case 'numbers': $saved_data = array(); $instance[ $key ] = $new_instance[ $key ]; foreach ( $instance[ $key ] as $item => $value ) { $temp_data = is_numeric( $value ) ? intval( $value ) : $setting['default'][ $item ]; if ( isset( $setting['input_attrs']['min'] ) && '' !== $setting['input_attrs']['min'] && ( $value < $setting['input_attrs']['min'] && ! $temp_data ) ) { $temp_data = max( $value, $setting['input_attrs']['min'] ); } if ( isset( $setting['input_attrs']['max'] ) && '' !== $setting['input_attrs']['max'] && $value > $setting['input_attrs']['max'] ) { $temp_data = min( $value, $setting['input_attrs']['max'] ); } $saved_data[ $item ] = $temp_data; } $instance[ $key ] = $saved_data; break; case 'multiselect': $selected_choices = array(); $available_choices = $setting['choices']; $new_instance[ $key ] = isset( $new_instance[ $key ] ) ? $new_instance[ $key ] : array(); foreach ( $new_instance[ $key ] as $selected_key => $selected_value ) { if ( array_key_exists( $selected_value, $available_choices ) ) { $selected_choices[] = $selected_value; } } $instance[ $key ] = $selected_choices; break; default: $instance[ $key ] = isset( $new_instance[ $key ] ) ? sanitize_text_field( $new_instance[ $key ] ) : $setting['default']; break; } /** * Sanitize the value of a setting. */ $instance[ $key ] = apply_filters( 'colormag_widget_settings_sanitize_option', $instance[ $key ], $new_instance, $key, $setting ); } return $instance; } /** * Outputs the settings update form. * * @param array $instance Instance. * * @see WP_Widget->form */ public function form( $instance ) { if ( empty( $this->settings ) ) { return; } foreach ( $this->settings as $key => $setting ) { $class = isset( $setting['class'] ) ? $setting['class'] : ''; $value = isset( $instance[ $key ] ) ? $instance[ $key ] : $setting['default']; switch ( $setting['type'] ) { case 'text': ?>

/>

step="" min="" max="" />

$choices_value ) { if ( 1 !== $count ) { echo '
'; } ?> />

' ', 'name' => $this->get_field_name( $key ), 'selected' => $value, 'class' => 'widefat postform', ) ); ?>

' ', 'name' => $this->get_field_name( $key ), 'selected' => $value, 'taxonomy' => 'post_tag', 'class' => 'widefat postform', ) ); ?>

' ', 'name' => $this->get_field_name( $key ), 'selected' => $value, 'orderby' => 'name', 'order' => 'ASC', 'capability' => 'authors', 'class' => 'widefat postform', ) ); ?>


$choices_value ) { ?>

$choices_value ) { ?>


', esc_attr( $this->get_field_name( $key ) ), esc_attr( $this->get_field_id( $key ) ), 'style="width:100%"' ); $available_values = ! empty( $value ) ? $value : array(); foreach ( $setting['choices'] as $choices_key => $choices_value ) { ?> '; ?>

' . esc_html( get_theme_mod( 'colormag_view_all_text', __( 'View All', 'colormag' ) ) ) . ''; // } // Display the title. echo '<' . apply_filters( 'colormag_widget_title_markup', 'h3' ) . ' class="cm-widget-title" ' . $border_color . '>' . esc_html( $title ) . '' . ''; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped } /** * Displays the widget description within the widgets. * * @param string $text The widget description. */ public function widget_description( $text ) { // Return if $text is empty. if ( ! $text ) { return; } echo '

' . wp_kses_post( $text ) . '

'; } /** * Query of the posts within the widgets. * * @param int $number The number of posts to display. * @param string $type The display posts from the widget setting. * @param int $category The category id of the widget setting. * * @return \WP_Query */ public function query_posts( $number, $type, $category ) { $post_status = 'publish'; if ( 1 == get_option( 'fresh_site' ) ) { $post_status = array( 'auto-draft', 'publish' ); } $args = array( 'posts_per_page' => $number, 'post_type' => 'post', 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'post_status' => $post_status, ); // Display posts from category. if ( 'category' == $type ) { $args['category__in'] = $category; } $get_featured_posts = new WP_Query( $args ); return $get_featured_posts; } /** * Displays the post title within the widgets. */ public function the_title() { ?>

'; } $image .= get_the_post_thumbnail( $post_id, $size, array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $image_alt_text ), ) ); if ( $link_enable ) { if ( has_post_format( 'video' ) ) { $image .= ' '; } $image .= ''; } $image .= ''; echo $image; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped } /** * Displays the post meta within the widgets. */ public function entry_meta() { $meta_orders = array( 'categories', 'date', 'author', 'tags', ); $human_diff_time = ''; if ( 'style-2' == get_theme_mod( 'colormag_post_meta_date_style', 'style-1' ) ) { $human_diff_time = 'human-diff-time'; } echo '
'; foreach ( $meta_orders as $key => $meta_order ) { if ( 'date' === $meta_order ) { colormag_date_meta_markup(); } if ( 'author' === $meta_order ) { colormag_author_meta_markup(); } } echo '
'; } }