diff --git a/inc/admin/settings.php b/inc/admin/settings.php new file mode 100644 index 0000000..0241d2b --- /dev/null +++ b/inc/admin/settings.php @@ -0,0 +1,360 @@ + get_post_types(), + 'post_status' => 'publish', + 'numberposts' => -1, + ]); + foreach($posts as $post){ + $options_posts[$post->ID] = $post->post_title; + } + + // Register a new field in the "yoast_sitemaps_exclude_section_specific_posts" section, inside the "yoast_sitemaps_exclude_specific_posts" page + add_settings_field( + 'yoast_sitemaps_exclude_specific_posts_field', + __( 'Posts', 'yoast_sitemaps_exclude' ), + array($this, 'fields_callback'), + 'yoast_sitemaps_exclude_specific_posts', + 'yoast_sitemaps_exclude_section_specific_posts', + array( + 'options_name' => 'yoast_sitemaps_exclude_specific_posts_options', + 'field_name' => 'yoast_sitemaps_exclude_specific_posts_field', + 'options' => $options_posts, + 'class' => 'js-yoast-sitemaps-exclude' + ) + ); + + // Register a new setting for "yoast_sitemaps_exclude_post_type" page. + register_setting( 'yoast_sitemaps_exclude_post_type', 'yoast_sitemaps_exclude_post_type_options' ); + + + $options_post_types = array(); + + $post_types = get_post_types(); + foreach($post_types as $key => $post_type){ + $options_post_types[$key] = $key; + } + + // Register a new section in the "yoast_sitemaps_exclude_post_type" page. + add_settings_section( + 'yoast_sitemaps_exclude_section_post_type', + __( 'Exclude a post type.', 'yoast_sitemaps_exclude' ), + null, + 'yoast_sitemaps_exclude_post_type' + ); + + // Register a new field in the "yoast_sitemaps_exclude_section_specific_posts" section, inside the "yoast_sitemaps_exclude_specific_posts" page + add_settings_field( + 'yoast_sitemaps_exclude_post_type_field', + __( 'Post type', 'yoast_sitemaps_exclude' ), + array($this, 'fields_callback'), + 'yoast_sitemaps_exclude_post_type', + 'yoast_sitemaps_exclude_section_post_type', + array( + 'options_name' => 'yoast_sitemaps_exclude_post_type_options', + 'field_name' => 'yoast_sitemaps_exclude_post_type_field', + 'options' => $options_post_types, + 'class' => 'js-yoast-sitemaps-exclude' + ) + ); + + // Register a new setting for "yoast_sitemaps_exclude_taxonomy" page. + register_setting( 'yoast_sitemaps_exclude_taxonomy', 'yoast_sitemaps_exclude_taxonomy_options' ); + + $options_taxonomies = array(); + $taxonomies = get_taxonomies(); + foreach($taxonomies as $taxonomy){ + $options_taxonomies[$taxonomy] = $taxonomy; + } + + // Register a new section in the "yoast_sitemaps_exclude_taxonomy" page. + add_settings_section( + 'yoast_sitemaps_exclude_section_taxonomy', + __( 'Exclude a taxonomy.', 'yoast_sitemaps_exclude' ), + null, + 'yoast_sitemaps_exclude_taxonomy' + ); + + // Register a new field in the "yoast_sitemaps_exclude_section_specific_posts" section, inside the "yoast_sitemaps_exclude_specific_posts" page + add_settings_field( + 'yoast_sitemaps_exclude_taxonomy_field', + __( 'Taxonomy', 'yoast_sitemaps_exclude' ), + array($this, 'fields_callback'), + 'yoast_sitemaps_exclude_taxonomy', + 'yoast_sitemaps_exclude_section_taxonomy', + array( + 'options_name' => 'yoast_sitemaps_exclude_taxonomy_options', + 'field_name' => 'yoast_sitemaps_exclude_taxonomy_field', + 'options' => $options_taxonomies, + 'class' => 'js-yoast-sitemaps-exclude' + ) + ); + + // Register a new setting for "yoast_sitemaps_exclude_author" page. + register_setting( 'yoast_sitemaps_exclude_author', 'yoast_sitemaps_exclude_author_options' ); + + $options_authors = array(); + + $authors = get_users(); + foreach($authors as $author){ + $options_authors[$author->ID] = $author->display_name . '(' . $author->ID . ')'; + } + + // Register a new section in the "yoast_sitemaps_exclude" page. + add_settings_section( + 'yoast_sitemaps_exclude_section_author', + __( 'Exclude an author.', 'yoast_sitemaps_exclude' ), + null, + 'yoast_sitemaps_exclude_author' + ); + + // Register a new field in the "yoast_sitemaps_exclude_section_specific_posts" section, inside the "yoast_sitemaps_exclude_specific_posts" page + add_settings_field( + 'yoast_sitemaps_exclude_author_field', + __( 'Author', 'yoast_sitemaps_exclude' ), + array($this, 'fields_callback'), + 'yoast_sitemaps_exclude_author', + 'yoast_sitemaps_exclude_section_author', + array( + 'options_name' => 'yoast_sitemaps_exclude_author_options', + 'field_name' => 'yoast_sitemaps_exclude_author_field', + 'options' => $options_authors, + 'class' => 'js-yoast-sitemaps-exclude' + ) + ); + + // Register a new setting for "yoast_sitemaps_exclude_taxonomy_term" page. + register_setting( 'yoast_sitemaps_exclude_taxonomy_term', 'yoast_sitemaps_exclude_taxonomy_term_options' ); + + $options_terms = array(); + + $terms = get_terms(); + foreach($terms as $term){ + $options_terms[$term->term_id] = $term->name . '(' . $term->term_id . ')'; + } + + // Register a new section in the "yoast_sitemaps_exclude_taxonomy_term" page. + add_settings_section( + 'yoast_sitemaps_exclude_section_taxonomy_term', + __( 'Exclude a taxonomy term.', 'yoast_sitemaps_exclude' ), + null, + 'yoast_sitemaps_exclude_taxonomy_term' + ); + + // Register a new field in the "yoast_sitemaps_exclude_section_specific_posts" section, inside the "yoast_sitemaps_exclude_specific_posts" page + add_settings_field( + 'yoast_sitemaps_exclude_taxonomy_term_field', + __( 'Taxonomy term', 'yoast_sitemaps_exclude' ), + array($this, 'fields_callback'), + 'yoast_sitemaps_exclude_taxonomy_term', + 'yoast_sitemaps_exclude_section_taxonomy_term', + array( + 'options_name' => 'yoast_sitemaps_exclude_taxonomy_term_options', + 'field_name' => 'yoast_sitemaps_exclude_taxonomy_term_field', + 'options' => $options_terms, + 'class' => 'js-yoast-sitemaps-exclude' + ) + ); + + + } + + /** + * Pill field callbakc function. + * + * @param array $args + */ + public function fields_callback( $args ) { + // Get the value of the setting we've registered with register_setting() + $options_name = $args['options_name']; + $options = get_option( $options_name ); + $field_name = $args['field_name']; + $field_value = !empty($options[$field_name]) ? $options[$field_name] : array(); + ?> + + +
+ +
+ +%2$s