defaults = array( 'title' => esc_attr__('Authors', 'essential-widgets'), 'order' => 'ASC', 'orderby' => 'display_name', 'number' => '', 'include' => '', 'exclude' => '', // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Required wp_list_authors() parameter, not a WP_Query post__not_in clause. 'optioncount' => false, 'exclude_admin' => false, 'show_fullname' => true, 'hide_empty' => true, 'style' => 'list', 'html' => true, 'feed' => '', 'feed_type' => '', 'feed_image' => '' ); $widget_ops = array( 'classname' => 'essential-widgets ew-author ewauthor', 'description' => esc_html__('Displays a list of author', 'essential-widgets'), ); $control_ops = array( 'id_base' => 'ew-author' ); parent::__construct( 'ew-author', // Base ID __('EW: Authors', 'essential-widgets'), // Name $widget_ops, $control_ops ); } public function form($instance) { // Merge the user-selected arguments with the defaults. $instance = wp_parse_args((array) $instance, $this->defaults); $order = array( 'ASC' => esc_attr__('Ascending', 'essential-widgets'), 'DESC' => esc_attr__('Descending', 'essential-widgets') ); $orderby = array( 'display_name' => esc_attr__('Display Name', 'essential-widgets'), 'email' => esc_attr__('Email', 'essential-widgets'), 'ID' => esc_attr__('ID', 'essential-widgets'), 'nicename' => esc_attr__('Nice Name', 'essential-widgets'), 'post_count' => esc_attr__('Post Count', 'essential-widgets'), 'registered' => esc_attr__('Registered', 'essential-widgets'), 'url' => esc_attr__('URL', 'essential-widgets'), 'user_login' => esc_attr__('Login', 'essential-widgets') ); $style = array( 'list' => esc_attr__('List', 'essential-widgets'), 'none' => esc_attr__('Plain', 'essential-widgets') ); $feed_type = array( '' => '', 'atom' => esc_attr__('Atom', 'essential-widgets'), 'rdf' => esc_attr__('RDF', 'essential-widgets'), 'rss' => esc_attr__('RSS', 'essential-widgets'), 'rss2' => esc_attr__('RSS 2.0', 'essential-widgets') ); ?>

 
defaults ); // Escape widget wrapper attributes. echo wp_kses_post( $args['before_widget'] ); // If a title was input by the user, display it safely. if ( ! empty( $instance['title'] ) ) { echo wp_kses_post( $args['before_title'] ); // Apply filters to title, then escape it for output $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); echo esc_html( $title ); echo wp_kses_post( $args['after_title'] ); } // Output the main content of the widget (shortcode output) echo wp_kses_post( $this->shortcode( $instance ) ); // Close the widget wrapper safely. echo wp_kses_post( $args['after_widget'] ); } public function shortcode( $atts ) { $atts = wp_parse_args( $atts, $this->defaults ); // Normalize arguments $args = array(); $args['order'] = in_array( $atts['order'], array( 'ASC', 'DESC' ), true ) ? $atts['order'] : 'ASC'; $args['orderby'] = sanitize_key( $atts['orderby'] ); $args['number'] = absint( $atts['number'] ); $args['include'] = preg_replace( '/[^0-9,]/', '', $atts['include'] ); $args['exclude'] = preg_replace( '/[^0-9,]/', '', $atts['exclude'] ); // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Required wp_list_authors() parameter, not a WP_Query post__not_in clause. $args['html'] = (bool) $atts['html']; $args['echo'] = false; $args['optioncount'] = (bool) $atts['optioncount']; $args['exclude_admin'] = (bool) $atts['exclude_admin']; $args['show_fullname'] = (bool) $atts['show_fullname']; $args['hide_empty'] = (bool) $atts['hide_empty']; $args['feed'] = sanitize_text_field( $atts['feed'] ); $args['feed_type'] = sanitize_text_field( $atts['feed_type'] ); $args['feed_image'] = esc_url( $atts['feed_image'] ); $ew_author = ''; // Block-only title if ( isset( $atts['is_block'] ) && true === $atts['is_block'] && ! empty( $atts['title'] ) ) { $ew_author .= '

' . esc_html( $atts['title'] ) . '

'; } // Get authors HTML safely $authors = wp_list_authors( $args ); $authors = str_replace( array( "\r", "\n", "\t" ), '', $authors ); $authors = str_replace( ' (', ' (', $authors ); $authors = str_replace( ')', ')', $authors ); // Wrap output if ( 'list' === $atts['style'] && $args['html'] ) { $ew_author .= ''; } elseif ( 'none' === $atts['style'] && $args['html'] ) { $ew_author .= '

' . wp_kses_post( $authors ) . '

'; } return $ew_author; } } // end Author_Widget class endif; if (!function_exists('ew_authors_register')) : /** * Intiate Author_Widget Class. * * @since 1.0.0 */ function ew_authors_register() // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- ew_ is this plugin's abbreviated prefix. { register_widget('EW_Authors'); } add_action('widgets_init', 'ew_authors_register'); endif;