get_col("SELECT DISTINCT meta_key FROM {$wpdb->postmeta} WHERE meta_key NOT LIKE '\_%' ORDER BY meta_key ASC"); $keys = is_array($keys) ? $keys : array(); set_transient('ew_meta_keys', $keys, HOUR_IN_SECONDS); return $keys; } endif; if (! class_exists('EW_Pages')) : class EW_Pages extends WP_Widget // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- EW_ is this plugin's abbreviated prefix; wrapped in class_exists() guard. { /** * Holds widget settings defaults, populated in constructor. * * @var array */ protected $defaults; public function __construct() { // Set up the defaults. $this->defaults = array( 'title' => esc_attr__('Pages', 'essential-widgets'), 'post_type' => 'page', 'depth' => 0, 'number' => '', 'offset' => '', 'child_of' => '', 'include' => '', 'exclude' => '', // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Required wp_list_pages() parameter, not a WP_Query post__not_in clause. 'exclude_tree' => '', 'meta_key' => '', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Required wp_list_pages() parameter. 'meta_value' => '', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Required wp_list_pages() parameter. 'authors' => '', 'link_before' => '', 'link_after' => '', 'show_date' => '', 'hierarchical' => true, 'sort_column' => 'post_title', 'sort_order' => 'ASC', 'date_format' => get_option('date_format'), ); $widget_ops = array( 'classname' => 'essential-widgets ew-pages ewpages', 'description' => esc_html__('Displays a list of pages.', 'essential-widgets'), ); $control_ops = array( 'id_base' => 'ew-pages', ); parent::__construct( 'ew-pages', // Base ID esc_html__('EW: Pages', 'essential-widgets'), // Name $widget_ops, $control_ops ); } /** * Displays the widget control options in the Widgets admin screen. * * @since 1.0.0 * @access public * @param array $instance * @param void */ public function form($instance) { // Merge the user-selected arguments with the defaults. $instance = wp_parse_args((array) $instance, $this->defaults); $post_types = get_post_types( array( 'public' => true, 'hierarchical' => true, ), 'objects' ); $sort_order = array( 'ASC' => esc_attr__('Ascending', 'essential-widgets'), 'DESC' => esc_attr__('Descending', 'essential-widgets'), ); $sort_column = array( 'post_author' => esc_attr__('Author', 'essential-widgets'), 'post_date' => esc_attr__('Date', 'essential-widgets'), 'ID' => esc_attr__('ID', 'essential-widgets'), 'menu_order' => esc_attr__('Menu Order', 'essential-widgets'), 'post_modified' => esc_attr__('Modified', 'essential-widgets'), 'post_name' => esc_attr__('Slug', 'essential-widgets'), 'post_title' => esc_attr__('Title', 'essential-widgets'), ); $show_date = array( '' => esc_attr__('Select', 'essential-widgets'), 'created' => esc_attr__('Created', 'essential-widgets'), 'modified' => esc_attr__('Modified', 'essential-widgets'), ); $meta_key = array_merge(array(''), (array) get_meta_keys()); ?>

 
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) { // Set the $title_li and $echo to false. $atts['title_li'] = false; $atts['echo'] = false; $ew_pages = ''; // Only show this title in block element and not on widget. if (isset($atts['is_block']) && true === $atts['is_block'] && !empty($atts['title'])) { $ew_pages .= '

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

'; } // Output the page list. $ew_pages .= ''; return wp_kses_post($ew_pages); } } endif; if (! function_exists('ew_pages_register')) : /** * Intiate About_Widget Class. * * @since 1.0.0 */ function ew_pages_register() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- ew_ is this plugin's abbreviated prefix. register_widget('EW_Pages'); } add_action('widgets_init', 'ew_pages_register'); endif;