Changeset 3111079
- Timestamp:
- 07/02/2024 10:56:10 AM (20 months ago)
- Location:
- fewer-tags
- Files:
-
- 2 added
- 12 edited
- 1 copied
-
tags/1.5 (copied) (copied from fewer-tags/trunk)
-
tags/1.5/fewer-tags.php (modified) (2 diffs)
-
tags/1.5/phpstan.neon.dist (added)
-
tags/1.5/readme.txt (modified) (3 diffs)
-
tags/1.5/src/class-admin.php (modified) (4 diffs)
-
tags/1.5/src/class-frontend.php (modified) (7 diffs)
-
tags/1.5/src/class-playground.php (modified) (6 diffs)
-
tags/1.5/src/class-plugin.php (modified) (2 diffs)
-
trunk/fewer-tags.php (modified) (2 diffs)
-
trunk/phpstan.neon.dist (added)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/src/class-admin.php (modified) (4 diffs)
-
trunk/src/class-frontend.php (modified) (7 diffs)
-
trunk/src/class-playground.php (modified) (6 diffs)
-
trunk/src/class-plugin.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
fewer-tags/tags/1.5/fewer-tags.php
r3029045 r3111079 4 4 * 5 5 * @package FewerTags 6 * @version 1. 4.16 * @version 1.5 7 7 * 8 8 * Plugin Name: Fewer Tags … … 11 11 * Requires at least: 6.2 12 12 * Requires PHP: 7.4 13 * Version: 1. 4.113 * Version: 1.5 14 14 * Author: Joost de Valk 15 15 * Author URI: https://joost.blog/ -
fewer-tags/tags/1.5/readme.txt
r3064750 r3111079 3 3 Tags: tag, tags, seo 4 4 Requires at least: 6.2 5 Tested up to: 6. 55 Tested up to: 6.6 6 6 Requires PHP: 7.4 7 Stable tag: 1. 4.17 Stable tag: 1.5 8 8 License: GPL3+ 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.en.html … … 20 20 * Are hidden from visitors and search engines on your site, and are redirected to your homepage. 21 21 * They don't show up in tag listings. 22 * The are no longer linked in WordPress core's or Yoast SEO generated XML sitemaps.22 * The are no longer linked in WordPress core's or Yoast SEO or Slim SEO generated XML sitemaps. 23 23 24 24 This positively affects your site's SEO and also leads to less crawling, as you have less useless tag pages. … … 65 65 == Changelog == 66 66 67 = 1.5 = 68 69 Enhancements: 70 71 * Add support for Slim SEO, props [Anh Tran](https://profiles.wordpress.org/rilwis/). 72 73 Bugfixes: 74 75 * Reinstates the "View" action for other taxonomies than tags. 76 77 Development: 78 79 * Updated PHPCompatibility, added PHPStan and fixed all resulting issues. 80 67 81 = 1.4.1 = 68 82 -
fewer-tags/tags/1.5/src/class-admin.php
r3028877 r3111079 17 17 /** 18 18 * Register the needed hooks. 19 * 20 * @return void 19 21 */ 20 22 public function register_hooks() { 21 add_action( 'admin_init', [ $this, 'register_settings' ] );22 add_filter( 'manage_edit-post_tag_columns', [ $this, 'add_tag_columns' ] );23 add_filter( 'manage_post_tag_custom_column', [ $this, 'manage_tag_columns' ], 10, 3 );24 add_filter( 'tag_row_actions', [ $this, 'remove_view_action' ], 10, 2 );23 \add_action( 'admin_init', [ $this, 'register_settings' ] ); 24 \add_filter( 'manage_edit-post_tag_columns', [ $this, 'add_tag_columns' ] ); 25 \add_filter( 'manage_post_tag_custom_column', [ $this, 'manage_tag_columns' ], 10, 3 ); 26 \add_filter( 'post_tag_row_actions', [ $this, 'remove_view_action' ], 10, 2 ); 25 27 } 26 28 27 29 /** 28 30 * Register settings and add settings field to the Reading settings page. 31 * 32 * @return void 29 33 */ 30 34 public function register_settings() { 31 add_settings_section(35 \add_settings_section( 32 36 'fewer_tags_section', 33 __( 'Fewer tags settings', 'fewer-tags' ),37 __( 'Fewer Tags settings', 'fewer-tags' ), 34 38 [ $this, 'display_section' ], 35 39 'reading' 36 40 ); 37 41 38 add_settings_field(42 \add_settings_field( 39 43 Plugin::$option_name, 40 44 __( 'Tags need to have', 'fewer-tags' ), … … 44 48 ); 45 49 46 register_setting( 'reading', Plugin::$option_name );50 \register_setting( 'reading', Plugin::$option_name ); 47 51 } 48 52 49 53 /** 50 54 * Display the section text. 55 * 56 * @return void 51 57 */ 52 58 public function display_section() { 53 esc_html_e( 'Set the minimum number of posts a tag should have to become live on the site and not be redirected to the homepage.', 'fewer-tags' );59 \esc_html_e( 'Set the minimum number of posts a tag should have to become live on the site and not be redirected to the homepage.', 'fewer-tags' ); 54 60 } 55 61 56 62 /** 57 63 * Display the setting field in the Reading settings page. 64 * 65 * @return void 58 66 */ 59 67 public function display_setting() { 60 68 ?> 61 69 <input 62 name="<?php echo esc_attr( Plugin::$option_name ); ?>"63 id="<?php echo esc_attr( Plugin::$option_name ); ?>"70 name="<?php echo \esc_attr( Plugin::$option_name ); ?>" 71 id="<?php echo \esc_attr( Plugin::$option_name ); ?>" 64 72 type="number" 65 73 min="1" 66 value="<?php echo esc_attr( Plugin::$min_posts_count ); ?>"74 value="<?php echo (int) Plugin::$min_posts_count; ?>" 67 75 class="small-text" 68 76 /> 69 <?php esc_html_e( 'posts before being live on the site.', 'fewer-tags' ); ?>77 <?php \esc_html_e( 'posts before being live on the site.', 'fewer-tags' ); ?> 70 78 <?php 71 79 } … … 94 102 public function manage_tag_columns( $out, $column_name, $tag_ID ) { 95 103 if ( $column_name === 'active' ) { 96 $term = get_term( $tag_ID );97 $out = esc_html__( 'Live', 'fewer-tags' );104 $term = \get_term( $tag_ID ); 105 $out = \esc_html__( 'Live', 'fewer-tags' ); 98 106 if ( $term->count < \FewerTags\Plugin::$min_posts_count ) { 99 $out = '<span title="' . esc_html__( 'Not live due to not enough posts being in this tag.', 'fewer-tags' ) . '">' .esc_html__( 'Not live', 'fewer-tags' ) . '</span>';107 $out = '<span title="' . \esc_html__( 'Not live due to not enough posts being in this tag.', 'fewer-tags' ) . '">' . \esc_html__( 'Not live', 'fewer-tags' ) . '</span>'; 100 108 } 101 109 } … … 107 115 * Removes the "View" action link for tags that have fewer than the minimum number of posts. 108 116 * 109 * @param array $actions An array of action links.110 * @param WP_Term $tag Current WP_Term object.117 * @param array $actions An array of action links. 118 * @param \WP_Term $tag Current WP_Term object. 111 119 * 112 120 * @return array Modified array of action links. -
fewer-tags/tags/1.5/src/class-frontend.php
r3028877 r3111079 15 15 /** 16 16 * Register the needed hooks. 17 * 18 * @return void 17 19 */ 18 20 public function register_hooks() { 19 add_action( 'template_redirect', [ $this, 'redirect_tag_pages' ] ); 20 add_filter( 'get_the_tags', [ $this, 'filter_get_the_tags' ] ); 21 add_filter( 'get_the_terms', [ $this, 'filter_get_the_terms' ], 10, 3 ); 22 add_filter( 'wpseo_exclude_from_sitemap_by_term_ids', [ $this, 'exclude_tags_from_yoast_sitemap' ] ); 23 add_filter( 'wp_sitemaps_taxonomies_query_args', [ $this, 'exclude_tags_from_core_sitemap' ], 10, 2 ); 21 \add_action( 'template_redirect', [ $this, 'redirect_tag_pages' ] ); 22 \add_filter( 'get_the_tags', [ $this, 'filter_get_the_tags' ] ); 23 \add_filter( 'get_the_terms', [ $this, 'filter_get_the_terms' ], 10, 3 ); 24 \add_filter( 'wpseo_exclude_from_sitemap_by_term_ids', [ $this, 'exclude_tags_from_yoast_sitemap' ] ); 25 \add_filter( 'wp_sitemaps_taxonomies_query_args', [ $this, 'exclude_tags_from_core_sitemap' ], 10, 2 ); 26 \add_filter( 'slim_seo_taxonomy_query_args', [ $this, 'exclude_tags_from_slim_seo_sitemap' ] ); 24 27 } 25 28 26 29 /** 27 30 * Redirect tag pages with fewer than the specified number of posts to the home page. 31 * 32 * @return void 28 33 */ 29 34 public function redirect_tag_pages() { 30 if ( is_tag() ) {31 $tag = get_queried_object();35 if ( \is_tag() ) { 36 $tag = \get_queried_object(); 32 37 if ( $tag && $tag->count < \FewerTags\Plugin::$min_posts_count ) { 33 wp_safe_redirect(home_url(), 301 );38 \wp_safe_redirect( \home_url(), 301 ); 34 39 // @codeCoverageIgnoreStart 35 40 exit; … … 44 49 * Only works on post_tag taxonomy. 45 50 * 46 * @param WP_Term[]|WP_Error $terms Array of attached terms, or WP_Error on failure.47 * @param int $post_id Post ID.48 * @param string $taxonomy Name of the taxonomy.51 * @param \WP_Term[]|\WP_Error $terms Array of attached terms, or WP_Error on failure. 52 * @param int $post_id Post ID. 53 * @param string $taxonomy Name of the taxonomy. 49 54 * 50 55 * @return array The filtered array of term objects. … … 55 60 } 56 61 57 if ( is_array( $terms ) ) {62 if ( \is_array( $terms ) ) { 58 63 foreach ( $terms as $key => $tag ) { 59 64 if ( $tag->count < \FewerTags\Plugin::$min_posts_count ) { … … 74 79 */ 75 80 public function filter_get_the_tags( $tags ) { 76 if ( is_array( $tags ) ) {81 if ( \is_array( $tags ) ) { 77 82 foreach ( $tags as $key => $tag ) { 78 83 if ( $tag->count < \FewerTags\Plugin::$min_posts_count ) { … … 103 108 104 109 // exclude terms with too few posts. 105 $args['exclude'] = array_merge( $args['exclude'], $this->get_tag_ids_with_fewer_than_min_posts() ); 110 $args['exclude'] = \array_merge( $args['exclude'], $this->get_tag_ids_with_fewer_than_min_posts() ); 111 return $args; 112 } 113 114 /** 115 * Excludes tags with fewer than the minimum number of posts from the Slim SEO sitemap. 116 * 117 * @param array $args The arguments for the sitemap query. 118 * 119 * @return array The modified arguments for the sitemap query. 120 */ 121 public function exclude_tags_from_slim_seo_sitemap( $args ) { 122 if ( ! isset( $args['exclude'] ) ) { 123 $args['exclude'] = []; 124 } 125 126 // exclude terms with too few posts. 127 $args['exclude'] = \array_merge( $args['exclude'], $this->get_tag_ids_with_fewer_than_min_posts() ); 106 128 return $args; 107 129 } … … 120 142 121 143 // Fetch all tag IDs. 122 $tag_ids = get_terms( $args );144 $tag_ids = \get_terms( $args ); 123 145 124 146 // Filter tag IDs based on post count. 125 $filtered_tag_ids = array_filter(147 $filtered_tag_ids = \array_filter( 126 148 $tag_ids, 127 149 function ( $tag_id ) { 128 $tag = get_term( $tag_id, 'post_tag' );150 $tag = \get_term( $tag_id, 'post_tag' ); 129 151 return ( $tag->count < \FewerTags\Plugin::$min_posts_count ); 130 152 } … … 154 176 $tags = get_terms( $args ); 155 177 156 if ( ! is_wp_error( $tags ) ) {178 if ( ! \is_wp_error( $tags ) ) { 157 179 foreach ( $tags as $tag_id ) { 158 $term = get_term( $tag_id );180 $term = \get_term( $tag_id ); 159 181 if ( $term->count < \FewerTags\Plugin::$min_posts_count ) { 160 182 $excluded_term_ids[] = $tag_id; -
fewer-tags/tags/1.5/src/class-playground.php
r3009870 r3111079 15 15 /** 16 16 * Register hooks. 17 * 18 * @return void 17 19 */ 18 20 public function register_hooks() { … … 26 28 /** 27 29 * Print an admin notice helping people. 30 * 31 * @return void 28 32 */ 29 33 public function admin_notices() { … … 38 42 echo '</p>'; 39 43 echo '<p>'; 40 \esc_html_e( 'You can go to Settings → Reading to change how many tags a tag needs to have to be live on the site.', 'fewer-tags' );44 \esc_html_e( 'You can go to Settings → Reading to change how many posts a tag needs to have to be live on the site.', 'fewer-tags' ); 41 45 echo '</p>'; 42 46 echo '</div>'; … … 45 49 /** 46 50 * Generate random posts & terms. 51 * 52 * @return void 47 53 */ 48 54 public function generate_data() { … … 66 72 * 67 73 * @param string $common_tag Tag to attach to all posts. 74 * 68 75 * @return int Post ID. 69 76 */ … … 88 95 */ 89 96 private function create_tag( $tag_name ) { 90 if ( ! \term_exists( $tag_name, 'post_tag' ) ) { 97 $term = \term_exists( $tag_name, 'post_tag' ); 98 if ( null === $term ) { 91 99 $term = \wp_insert_term( $tag_name, 'post_tag' ); 92 return $term['term_id'];93 100 } 101 102 return $term['term_id']; 94 103 } 95 104 -
fewer-tags/tags/1.5/src/class-plugin.php
r3028877 r3111079 29 29 /** 30 30 * Register plugin hooks. 31 * 32 * @return void 31 33 */ 32 34 public function register_hooks() { … … 37 39 /** 38 40 * Initialize the plugin and register hooks. 41 * 42 * @return void 39 43 */ 40 44 public function init() { -
fewer-tags/trunk/fewer-tags.php
r3029045 r3111079 4 4 * 5 5 * @package FewerTags 6 * @version 1. 4.16 * @version 1.5 7 7 * 8 8 * Plugin Name: Fewer Tags … … 11 11 * Requires at least: 6.2 12 12 * Requires PHP: 7.4 13 * Version: 1. 4.113 * Version: 1.5 14 14 * Author: Joost de Valk 15 15 * Author URI: https://joost.blog/ -
fewer-tags/trunk/readme.txt
r3064750 r3111079 3 3 Tags: tag, tags, seo 4 4 Requires at least: 6.2 5 Tested up to: 6. 55 Tested up to: 6.6 6 6 Requires PHP: 7.4 7 Stable tag: 1. 4.17 Stable tag: 1.5 8 8 License: GPL3+ 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.en.html … … 20 20 * Are hidden from visitors and search engines on your site, and are redirected to your homepage. 21 21 * They don't show up in tag listings. 22 * The are no longer linked in WordPress core's or Yoast SEO generated XML sitemaps.22 * The are no longer linked in WordPress core's or Yoast SEO or Slim SEO generated XML sitemaps. 23 23 24 24 This positively affects your site's SEO and also leads to less crawling, as you have less useless tag pages. … … 65 65 == Changelog == 66 66 67 = 1.5 = 68 69 Enhancements: 70 71 * Add support for Slim SEO, props [Anh Tran](https://profiles.wordpress.org/rilwis/). 72 73 Bugfixes: 74 75 * Reinstates the "View" action for other taxonomies than tags. 76 77 Development: 78 79 * Updated PHPCompatibility, added PHPStan and fixed all resulting issues. 80 67 81 = 1.4.1 = 68 82 -
fewer-tags/trunk/src/class-admin.php
r3028877 r3111079 17 17 /** 18 18 * Register the needed hooks. 19 * 20 * @return void 19 21 */ 20 22 public function register_hooks() { 21 add_action( 'admin_init', [ $this, 'register_settings' ] );22 add_filter( 'manage_edit-post_tag_columns', [ $this, 'add_tag_columns' ] );23 add_filter( 'manage_post_tag_custom_column', [ $this, 'manage_tag_columns' ], 10, 3 );24 add_filter( 'tag_row_actions', [ $this, 'remove_view_action' ], 10, 2 );23 \add_action( 'admin_init', [ $this, 'register_settings' ] ); 24 \add_filter( 'manage_edit-post_tag_columns', [ $this, 'add_tag_columns' ] ); 25 \add_filter( 'manage_post_tag_custom_column', [ $this, 'manage_tag_columns' ], 10, 3 ); 26 \add_filter( 'post_tag_row_actions', [ $this, 'remove_view_action' ], 10, 2 ); 25 27 } 26 28 27 29 /** 28 30 * Register settings and add settings field to the Reading settings page. 31 * 32 * @return void 29 33 */ 30 34 public function register_settings() { 31 add_settings_section(35 \add_settings_section( 32 36 'fewer_tags_section', 33 __( 'Fewer tags settings', 'fewer-tags' ),37 __( 'Fewer Tags settings', 'fewer-tags' ), 34 38 [ $this, 'display_section' ], 35 39 'reading' 36 40 ); 37 41 38 add_settings_field(42 \add_settings_field( 39 43 Plugin::$option_name, 40 44 __( 'Tags need to have', 'fewer-tags' ), … … 44 48 ); 45 49 46 register_setting( 'reading', Plugin::$option_name );50 \register_setting( 'reading', Plugin::$option_name ); 47 51 } 48 52 49 53 /** 50 54 * Display the section text. 55 * 56 * @return void 51 57 */ 52 58 public function display_section() { 53 esc_html_e( 'Set the minimum number of posts a tag should have to become live on the site and not be redirected to the homepage.', 'fewer-tags' );59 \esc_html_e( 'Set the minimum number of posts a tag should have to become live on the site and not be redirected to the homepage.', 'fewer-tags' ); 54 60 } 55 61 56 62 /** 57 63 * Display the setting field in the Reading settings page. 64 * 65 * @return void 58 66 */ 59 67 public function display_setting() { 60 68 ?> 61 69 <input 62 name="<?php echo esc_attr( Plugin::$option_name ); ?>"63 id="<?php echo esc_attr( Plugin::$option_name ); ?>"70 name="<?php echo \esc_attr( Plugin::$option_name ); ?>" 71 id="<?php echo \esc_attr( Plugin::$option_name ); ?>" 64 72 type="number" 65 73 min="1" 66 value="<?php echo esc_attr( Plugin::$min_posts_count ); ?>"74 value="<?php echo (int) Plugin::$min_posts_count; ?>" 67 75 class="small-text" 68 76 /> 69 <?php esc_html_e( 'posts before being live on the site.', 'fewer-tags' ); ?>77 <?php \esc_html_e( 'posts before being live on the site.', 'fewer-tags' ); ?> 70 78 <?php 71 79 } … … 94 102 public function manage_tag_columns( $out, $column_name, $tag_ID ) { 95 103 if ( $column_name === 'active' ) { 96 $term = get_term( $tag_ID );97 $out = esc_html__( 'Live', 'fewer-tags' );104 $term = \get_term( $tag_ID ); 105 $out = \esc_html__( 'Live', 'fewer-tags' ); 98 106 if ( $term->count < \FewerTags\Plugin::$min_posts_count ) { 99 $out = '<span title="' . esc_html__( 'Not live due to not enough posts being in this tag.', 'fewer-tags' ) . '">' .esc_html__( 'Not live', 'fewer-tags' ) . '</span>';107 $out = '<span title="' . \esc_html__( 'Not live due to not enough posts being in this tag.', 'fewer-tags' ) . '">' . \esc_html__( 'Not live', 'fewer-tags' ) . '</span>'; 100 108 } 101 109 } … … 107 115 * Removes the "View" action link for tags that have fewer than the minimum number of posts. 108 116 * 109 * @param array $actions An array of action links.110 * @param WP_Term $tag Current WP_Term object.117 * @param array $actions An array of action links. 118 * @param \WP_Term $tag Current WP_Term object. 111 119 * 112 120 * @return array Modified array of action links. -
fewer-tags/trunk/src/class-frontend.php
r3028877 r3111079 15 15 /** 16 16 * Register the needed hooks. 17 * 18 * @return void 17 19 */ 18 20 public function register_hooks() { 19 add_action( 'template_redirect', [ $this, 'redirect_tag_pages' ] ); 20 add_filter( 'get_the_tags', [ $this, 'filter_get_the_tags' ] ); 21 add_filter( 'get_the_terms', [ $this, 'filter_get_the_terms' ], 10, 3 ); 22 add_filter( 'wpseo_exclude_from_sitemap_by_term_ids', [ $this, 'exclude_tags_from_yoast_sitemap' ] ); 23 add_filter( 'wp_sitemaps_taxonomies_query_args', [ $this, 'exclude_tags_from_core_sitemap' ], 10, 2 ); 21 \add_action( 'template_redirect', [ $this, 'redirect_tag_pages' ] ); 22 \add_filter( 'get_the_tags', [ $this, 'filter_get_the_tags' ] ); 23 \add_filter( 'get_the_terms', [ $this, 'filter_get_the_terms' ], 10, 3 ); 24 \add_filter( 'wpseo_exclude_from_sitemap_by_term_ids', [ $this, 'exclude_tags_from_yoast_sitemap' ] ); 25 \add_filter( 'wp_sitemaps_taxonomies_query_args', [ $this, 'exclude_tags_from_core_sitemap' ], 10, 2 ); 26 \add_filter( 'slim_seo_taxonomy_query_args', [ $this, 'exclude_tags_from_slim_seo_sitemap' ] ); 24 27 } 25 28 26 29 /** 27 30 * Redirect tag pages with fewer than the specified number of posts to the home page. 31 * 32 * @return void 28 33 */ 29 34 public function redirect_tag_pages() { 30 if ( is_tag() ) {31 $tag = get_queried_object();35 if ( \is_tag() ) { 36 $tag = \get_queried_object(); 32 37 if ( $tag && $tag->count < \FewerTags\Plugin::$min_posts_count ) { 33 wp_safe_redirect(home_url(), 301 );38 \wp_safe_redirect( \home_url(), 301 ); 34 39 // @codeCoverageIgnoreStart 35 40 exit; … … 44 49 * Only works on post_tag taxonomy. 45 50 * 46 * @param WP_Term[]|WP_Error $terms Array of attached terms, or WP_Error on failure.47 * @param int $post_id Post ID.48 * @param string $taxonomy Name of the taxonomy.51 * @param \WP_Term[]|\WP_Error $terms Array of attached terms, or WP_Error on failure. 52 * @param int $post_id Post ID. 53 * @param string $taxonomy Name of the taxonomy. 49 54 * 50 55 * @return array The filtered array of term objects. … … 55 60 } 56 61 57 if ( is_array( $terms ) ) {62 if ( \is_array( $terms ) ) { 58 63 foreach ( $terms as $key => $tag ) { 59 64 if ( $tag->count < \FewerTags\Plugin::$min_posts_count ) { … … 74 79 */ 75 80 public function filter_get_the_tags( $tags ) { 76 if ( is_array( $tags ) ) {81 if ( \is_array( $tags ) ) { 77 82 foreach ( $tags as $key => $tag ) { 78 83 if ( $tag->count < \FewerTags\Plugin::$min_posts_count ) { … … 103 108 104 109 // exclude terms with too few posts. 105 $args['exclude'] = array_merge( $args['exclude'], $this->get_tag_ids_with_fewer_than_min_posts() ); 110 $args['exclude'] = \array_merge( $args['exclude'], $this->get_tag_ids_with_fewer_than_min_posts() ); 111 return $args; 112 } 113 114 /** 115 * Excludes tags with fewer than the minimum number of posts from the Slim SEO sitemap. 116 * 117 * @param array $args The arguments for the sitemap query. 118 * 119 * @return array The modified arguments for the sitemap query. 120 */ 121 public function exclude_tags_from_slim_seo_sitemap( $args ) { 122 if ( ! isset( $args['exclude'] ) ) { 123 $args['exclude'] = []; 124 } 125 126 // exclude terms with too few posts. 127 $args['exclude'] = \array_merge( $args['exclude'], $this->get_tag_ids_with_fewer_than_min_posts() ); 106 128 return $args; 107 129 } … … 120 142 121 143 // Fetch all tag IDs. 122 $tag_ids = get_terms( $args );144 $tag_ids = \get_terms( $args ); 123 145 124 146 // Filter tag IDs based on post count. 125 $filtered_tag_ids = array_filter(147 $filtered_tag_ids = \array_filter( 126 148 $tag_ids, 127 149 function ( $tag_id ) { 128 $tag = get_term( $tag_id, 'post_tag' );150 $tag = \get_term( $tag_id, 'post_tag' ); 129 151 return ( $tag->count < \FewerTags\Plugin::$min_posts_count ); 130 152 } … … 154 176 $tags = get_terms( $args ); 155 177 156 if ( ! is_wp_error( $tags ) ) {178 if ( ! \is_wp_error( $tags ) ) { 157 179 foreach ( $tags as $tag_id ) { 158 $term = get_term( $tag_id );180 $term = \get_term( $tag_id ); 159 181 if ( $term->count < \FewerTags\Plugin::$min_posts_count ) { 160 182 $excluded_term_ids[] = $tag_id; -
fewer-tags/trunk/src/class-playground.php
r3009870 r3111079 15 15 /** 16 16 * Register hooks. 17 * 18 * @return void 17 19 */ 18 20 public function register_hooks() { … … 26 28 /** 27 29 * Print an admin notice helping people. 30 * 31 * @return void 28 32 */ 29 33 public function admin_notices() { … … 38 42 echo '</p>'; 39 43 echo '<p>'; 40 \esc_html_e( 'You can go to Settings → Reading to change how many tags a tag needs to have to be live on the site.', 'fewer-tags' );44 \esc_html_e( 'You can go to Settings → Reading to change how many posts a tag needs to have to be live on the site.', 'fewer-tags' ); 41 45 echo '</p>'; 42 46 echo '</div>'; … … 45 49 /** 46 50 * Generate random posts & terms. 51 * 52 * @return void 47 53 */ 48 54 public function generate_data() { … … 66 72 * 67 73 * @param string $common_tag Tag to attach to all posts. 74 * 68 75 * @return int Post ID. 69 76 */ … … 88 95 */ 89 96 private function create_tag( $tag_name ) { 90 if ( ! \term_exists( $tag_name, 'post_tag' ) ) { 97 $term = \term_exists( $tag_name, 'post_tag' ); 98 if ( null === $term ) { 91 99 $term = \wp_insert_term( $tag_name, 'post_tag' ); 92 return $term['term_id'];93 100 } 101 102 return $term['term_id']; 94 103 } 95 104 -
fewer-tags/trunk/src/class-plugin.php
r3028877 r3111079 29 29 /** 30 30 * Register plugin hooks. 31 * 32 * @return void 31 33 */ 32 34 public function register_hooks() { … … 37 39 /** 38 40 * Initialize the plugin and register hooks. 41 * 42 * @return void 39 43 */ 40 44 public function init() {
Note: See TracChangeset
for help on using the changeset viewer.