public function register_shortcode($atts, $content = null) { $atts = shortcode_atts(array('layout' => 'block', 'order_number' => 1, 'order_number_from' => 1, 'order_number_to' => 3, 'show_more_link' => ''), $atts); $instance = array('type' => $atts['layout'], 'from' => absint($atts['order_number']), 'to' => absint($atts['order_number']), 'more_news' => $atts['show_more_link']); // If the inline layout is selected then set the from and to variables if ('inline' === $atts['layout']) { $instance['from'] = absint($atts['order_number_from']); $instance['to'] = absint($atts['order_number_to']); } // Bound from and to between 1 and max_post_number $instance['from'] = PW_Functions::bound($instance['from'], 1, $this->max_post_number); $instance['to'] = PW_Functions::bound($instance['to'], 1, $this->max_post_number); // to can't be lower than from if ($instance['from'] > $instance['to']) { $instance['to'] = $instance['from']; } ob_start(); the_widget('PW_Latest_News', $instance); return ob_get_clean(); }
/** * Sanitize widget form values as they are saved. * * @param array $new_instance The new options * @param array $old_instance The previous options */ public function update($new_instance, $old_instance) { $instance = array(); $instance['type'] = sanitize_key($new_instance['type']); $instance['from'] = sanitize_text_field($new_instance['from']); $instance['to'] = sanitize_text_field($new_instance['to']); if (!empty($new_instance['more_news'])) { $instance['more_news'] = sanitize_text_field($new_instance['more_news']); } else { $instance['more_news'] = ''; } // Bound from and to between 1 and max_post_number $instance['from'] = PW_Functions::bound($instance['from'], 1, $this->max_post_number); $instance['to'] = PW_Functions::bound($instance['to'], 1, $this->max_post_number); // to can't be lower than from if ($instance['from'] > $instance['to']) { $instance['to'] = $instance['from']; } $instance['read_more_text'] = sanitize_text_field($new_instance['read_more_text']); return $instance; }