* @uses Dynamic_News_Featured_Content::delete_transient() * * @param array $input * @return array $output */ public static function validate_settings($input) { $output = array(); if (empty($input['tag-name'])) { $output['tag-id'] = 0; } else { $term = get_term_by('name', $input['tag-name'], 'post_tag'); if ($term) { $output['tag-id'] = $term->term_id; } else { $new_tag = wp_create_tag($input['tag-name']); if (!is_wp_error($new_tag) && isset($new_tag['term_id'])) { $output['tag-id'] = $new_tag['term_id']; } } $output['tag-name'] = $input['tag-name']; } $output['hide-tag'] = isset($input['hide-tag']) && $input['hide-tag'] ? 1 : 0; $output['show-all'] = isset($input['show-all']) && $input['show-all'] ? 1 : 0; $output['max-posts'] = isset($input['max-posts']) && $input['max-posts'] > 0 ? absint($input['max-posts']) : 20; self::delete_transient(); return $output; } } Dynamic_News_Featured_Content::setup();
/** * Conditionally hook into WordPress. * * Theme must declare that they support this module by adding * add_theme_support( 'featured-content' ); during after_setup_theme. * * If no theme support is found there is no need to hook into WordPress. * We'll just return early instead. * * @static * @access public * @since Dynamic News 1.0 */ public static function init() { $theme_support = get_theme_support('featured-content'); // Return early if theme does not support Featured Content. if (!$theme_support) { return; } /* * An array of named arguments must be passed as the second parameter * of add_theme_support(). */ if (!isset($theme_support[0])) { return; } // Return early if "featured_content_filter" has not been defined. if (!isset($theme_support[0]['featured_content_filter'])) { return; } $filter = $theme_support[0]['featured_content_filter']; // Theme can override the number of max posts. if (isset($theme_support[0]['max_posts'])) { self::$max_posts = absint($theme_support[0]['max_posts']); } add_filter($filter, array(__CLASS__, 'get_featured_posts')); add_action('customize_register', array(__CLASS__, 'customize_register'), 9); add_action('admin_init', array(__CLASS__, 'register_setting')); add_action('switch_theme', array(__CLASS__, 'delete_transient')); add_action('save_post', array(__CLASS__, 'delete_transient')); add_action('delete_post_tag', array(__CLASS__, 'delete_post_tag')); add_action('customize_controls_enqueue_scripts', array(__CLASS__, 'enqueue_scripts')); add_action('pre_get_posts', array(__CLASS__, 'pre_get_posts')); add_action('wp_loaded', array(__CLASS__, 'wp_loaded')); }