*/ public static function fields() { return array( 'afs_general_post_type' => array( 'section' => self::SECTION_GENERAL, 'type' => 'post_type', 'label' => __( 'Post type', 'ajax-filter-search' ), 'help' => __( 'Select a post type to pull the feed from.', 'ajax-filter-search' ), 'default' => 'post', ), 'afs_general_post_taxonomy' => array( 'section' => self::SECTION_GENERAL, 'type' => 'taxonomy', 'label' => __( 'Taxonomy', 'ajax-filter-search' ), 'help' => __( 'Select a taxonomy for the tabbed filters.', 'ajax-filter-search' ), 'default' => 'category', ), 'afs_general_posts_per_page' => array( 'section' => self::SECTION_GENERAL, 'type' => 'number', 'label' => __( 'Posts per page', 'ajax-filter-search' ), 'help' => __( 'How many posts to display per page (1 to 100).', 'ajax-filter-search' ), 'default' => 10, ), 'afs_general_show_filters' => array( 'section' => self::SECTION_GENERAL, 'type' => 'yesno', 'label' => __( 'Category tabs', 'ajax-filter-search' ), 'help' => __( 'Display tabbed filters.', 'ajax-filter-search' ), 'default' => 1, ), 'afs_general_views' => array( 'section' => self::SECTION_GENERAL, 'type' => 'yesno', 'label' => __( 'Layout switcher', 'ajax-filter-search' ), 'help' => __( 'Show the List View / Grid View switcher.', 'ajax-filter-search' ), 'default' => 1, ), 'afs_general_layout' => array( 'section' => self::SECTION_GENERAL, 'type' => 'layout', 'label' => __( 'Default layout', 'ajax-filter-search' ), 'help' => __( 'The layout used when a page first loads.', 'ajax-filter-search' ), 'default' => 'list', ), 'afs_general_show_sort' => array( 'section' => self::SECTION_GENERAL, 'type' => 'yesno', 'label' => __( 'Sort control', 'ajax-filter-search' ), 'help' => __( 'Let visitors sort by newest, oldest, A to Z, recently updated or most commented. Each feed can override this.', 'ajax-filter-search' ), 'default' => 0, ), 'afs_general_show_chips' => array( 'section' => self::SECTION_GENERAL, 'type' => 'yesno', 'label' => __( 'Active filter chips', 'ajax-filter-search' ), 'help' => __( 'Show the active filters as removable chips with a Clear all link, and offer a way out when nothing matches. Each feed can override this.', 'ajax-filter-search' ), 'default' => 0, ), 'afs_general_noindex_filtered' => array( 'section' => self::SECTION_GENERAL, 'type' => 'yesno', 'label' => __( 'Hide filtered views from search engines', 'ajax-filter-search' ), 'help' => __( 'Adds noindex to a page when it is shown with a filter, search or page number in the address, so only the main page is indexed.', 'ajax-filter-search' ), 'default' => 1, ), 'afs_appearance_design' => array( 'section' => self::SECTION_APPEARANCE, 'type' => 'design', 'label' => __( 'Design', 'ajax-filter-search' ), 'help' => __( 'How feeds look. Editorial Grid and Resource Library show image cards or compact rows; what they show is set under Cards. You can also choose a design for a single feed with the design attribute or the block setting.', 'ajax-filter-search' ), 'default' => AFS_Design::site_default(), ), 'afs_cards_show_image' => array( 'section' => self::SECTION_CARDS, 'type' => 'yesno', 'label' => __( 'Featured image', 'ajax-filter-search' ), 'help' => __( 'Show each post\'s featured image. A post without one gets a tinted tile with a letter.', 'ajax-filter-search' ), 'default' => 1, ), 'afs_cards_image_ratio' => array( 'section' => self::SECTION_CARDS, 'type' => 'ratio', 'label' => __( 'Image shape', 'ajax-filter-search' ), 'help' => __( 'Editorial Grid images only. Resource Library thumbnails are always square.', 'ajax-filter-search' ), 'default' => '16:10', 'needs' => 'afs_cards_show_image', ), 'afs_cards_columns' => array( 'section' => self::SECTION_CARDS, 'type' => 'columns', 'label' => __( 'Columns', 'ajax-filter-search' ), 'help' => __( 'The most columns the Editorial Grid uses. Fewer on narrow screens.', 'ajax-filter-search' ), 'default' => 3, ), 'afs_cards_show_excerpt' => array( 'section' => self::SECTION_CARDS, 'type' => 'yesno', 'label' => __( 'Excerpt', 'ajax-filter-search' ), 'help' => __( 'Show a short excerpt under each title.', 'ajax-filter-search' ), 'default' => 1, ), 'afs_cards_excerpt_length' => array( 'section' => self::SECTION_CARDS, 'type' => 'words', 'label' => __( 'Excerpt length', 'ajax-filter-search' ), 'help' => __( 'How many words of the excerpt to show (10 to 80).', 'ajax-filter-search' ), 'default' => 25, 'needs' => 'afs_cards_show_excerpt', ), 'afs_cards_show_date' => array( 'section' => self::SECTION_CARDS, 'type' => 'yesno', 'label' => __( 'Publication date', 'ajax-filter-search' ), 'help' => __( 'Show the date each post was published.', 'ajax-filter-search' ), 'default' => 1, ), 'afs_cards_show_time' => array( 'section' => self::SECTION_CARDS, 'type' => 'yesno', 'label' => __( 'Include the time', 'ajax-filter-search' ), 'help' => __( 'Show the time of day next to the date. It needs the publication date to be shown.', 'ajax-filter-search' ), 'default' => 0, 'needs' => 'afs_cards_show_date', ), 'afs_cards_show_category' => array( 'section' => self::SECTION_CARDS, 'type' => 'yesno', 'label' => __( 'Category badge', 'ajax-filter-search' ), 'help' => __( 'Show the post\'s category as a badge, using the taxonomy chosen above.', 'ajax-filter-search' ), 'default' => 1, ), 'afs_appearance_accent' => array( 'section' => self::SECTION_APPEARANCE, 'type' => 'color', 'label' => __( 'Accent color', 'ajax-filter-search' ), 'help' => __( 'Used for links, the active tab and the active page.', 'ajax-filter-search' ), 'default' => AFS_Design::default_accent(), ), ); } /** Defaults keyed by option key. */ public static function defaults() { $defaults = array(); foreach ( self::fields() as $key => $field ) { $defaults[ $key ] = $field['default']; } return $defaults; } /** * Retrieve a setting using the short 1.x key, e.g. '_general_post_type'. * * @param string $val Key suffix. * @return mixed */ public static function afs_retrieve( $val ) { return self::afs_get_option( AFS_SUB . $val ); } /** * Retrieve a setting by its full option key, falling back to the default. * * @param string $option_name Full key, e.g. 'afs_general_post_type'. * @return mixed False when the key is unknown. */ public static function afs_get_option( $option_name = '' ) { $defaults = self::defaults(); $options = get_option( AFS_SETTINGS, array() ); $options = wp_parse_args( is_array( $options ) ? $options : array(), $defaults ); return isset( $options[ $option_name ] ) ? $options[ $option_name ] : false; } /** Hook everything up. */ public static function init() { add_action( 'admin_menu', array( __CLASS__, 'add_admin_menu' ) ); add_action( 'admin_init', array( __CLASS__, 'register_settings' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_admin_scripts' ) ); add_filter( 'plugin_action_links_' . AFS_PLUGIN_FILE, array( __CLASS__, 'plugin_settings_link' ) ); } public static function add_admin_menu() { add_options_page( AFS_PAGE_TITLE, AFS_MENU_TAB_TITLE, AFS_CAPABILITIES, AFS_MENU_SLUG, array( __CLASS__, 'options_page' ) ); } public static function plugin_settings_link( $links ) { $url = admin_url( 'options-general.php?page=' . AFS_MENU_SLUG ); array_unshift( $links, '' . esc_html__( 'Settings', 'ajax-filter-search' ) . '' ); return $links; } public static function register_settings() { register_setting( 'afs_settings_group', AFS_SETTINGS, array( 'type' => 'array', 'sanitize_callback' => array( __CLASS__, 'sanitize' ), 'default' => self::defaults(), ) ); add_settings_section( self::SECTION_GENERAL, __( 'General', 'ajax-filter-search' ), array( __CLASS__, 'general_section_intro' ), 'afs_settings_page' ); add_settings_section( self::SECTION_APPEARANCE, __( 'Appearance', 'ajax-filter-search' ), '__return_null', 'afs_settings_page' ); add_settings_section( self::SECTION_CARDS, __( 'Cards', 'ajax-filter-search' ), '__return_null', 'afs_settings_page' ); foreach ( self::fields() as $key => $field ) { add_settings_field( $key, $field['label'], array( __CLASS__, 'render_field' ), 'afs_settings_page', $field['section'], array_merge( $field, array( 'key' => $key, 'label_for' => 'afs-' . $key, ) ) ); } } public static function general_section_intro() { echo '
' . wp_kses(
__( 'Customize your settings below, then add the shortcode [ajax_filter_search] (or the "Ajax Filter Search" block) to the page where you want the feed to appear.', 'ajax-filter-search' ),
array( 'code' => array() )
) . '
' . esc_html( $args['help'] ) . '
'; } } /** Which fields belong to which card, in order. */ private static function groups() { return array( 'appearance' => array( 'title' => __( 'Appearance', 'ajax-filter-search' ), 'intro' => __( 'How feeds look on your site.', 'ajax-filter-search' ), 'fields' => array( 'afs_appearance_design', 'afs_appearance_accent' ), ), 'cards' => array( 'title' => __( 'Cards', 'ajax-filter-search' ), 'intro' => __( 'What each result shows in Editorial Grid and Resource Library.', 'ajax-filter-search' ), 'callout' => array( __( 'Defaults, and how a feed overrides them.', 'ajax-filter-search' ), __( 'These apply to every feed that uses one of these designs. One feed can override any of them with a shortcode attribute (for example columns="2") or in the block\'s Cards panel ("Use plugin setting"). Classic and Modern ignore them.', 'ajax-filter-search' ), ), 'fold' => true, 'fields' => array( 'afs_cards_show_image', 'afs_cards_image_ratio', 'afs_cards_columns', 'afs_cards_show_excerpt', 'afs_cards_excerpt_length', 'afs_cards_show_date', 'afs_cards_show_time', 'afs_cards_show_category' ), ), 'feed' => array( 'title' => __( 'Feed', 'ajax-filter-search' ), 'intro' => __( 'What a feed lists by default. Every feed can override these with shortcode attributes or the block settings.', 'ajax-filter-search' ), 'fields' => array( 'afs_general_post_type', 'afs_general_post_taxonomy', 'afs_general_posts_per_page', 'afs_general_layout' ), ), 'filters' => array( 'title' => __( 'Filters and controls', 'ajax-filter-search' ), 'intro' => __( 'What visitors can use to narrow the results.', 'ajax-filter-search' ), 'fields' => array( 'afs_general_show_filters', 'afs_general_views', 'afs_general_show_sort', 'afs_general_show_chips' ), ), 'search' => array( 'title' => __( 'Search engines', 'ajax-filter-search' ), 'intro' => __( 'Keep filtered views out of search results so only your main page is indexed.', 'ajax-filter-search' ), 'fields' => array( 'afs_general_noindex_filtered' ), ), ); } /** Small illustrations for the design picker (decorative). */ private static function design_preview( $slug ) { if ( AFS_Design::EDITORIAL === $slug ) { return ''; } if ( AFS_Design::LIBRARY === $slug ) { return ''; } if ( AFS_Design::MODERN === $slug ) { return ''; } return ''; } public static function options_page() { if ( ! current_user_can( AFS_CAPABILITIES ) ) { return; } $fields = self::fields(); $icon = AFS_PLUGIN_URL . '/admin/images/icon.svg'; ?> $map, 'none' => __( 'None', 'ajax-filter-search' ), 'copied' => __( 'Copied', 'ajax-filter-search' ), 'unsaved' => __( 'You have unsaved changes.', 'ajax-filter-search' ), 'dismissed' => __( 'Announcement dismissed.', 'ajax-filter-search' ), ) ); } } endif;