From fff9c21ccd83ef3082d3167e07ab5a42fe2f415c Mon Sep 17 00:00:00 2001 From: Abhijit Babasaheb Nage Date: Thu, 18 Mar 2021 10:11:56 +0530 Subject: [PATCH 1/7] Fix unlisted page appear in google search result --- README.md | 5 ++++- class-unlist-posts.php | 2 +- package.json | 2 +- readme.txt | 5 ++++- unlist-posts.php | 4 ++-- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 030b1ee..96326e0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **Tags:** post, unlist posts, hide posts, **Requires at least:** 4.4 **Tested up to:** 5.7 -**Stable tag:** 1.1.3 +**Stable tag:** 1.1.4 **License:** GPLv2 or later **License URI:** http://www.gnu.org/licenses/gpl-2.0.html @@ -37,6 +37,9 @@ Just select option "Unlist Post" in any post of any type and that post will be h ## Changelog ## +### 1.1.4 ### +- Fix: Unlisted page appearing in google search result. + ### 1.1.3 ### - Deprecated: wp_no_robots() has been deprecated. - Security: Use escaping for displaying unlist post description. diff --git a/class-unlist-posts.php b/class-unlist-posts.php index c39d9d4..f26bf75 100644 --- a/class-unlist-posts.php +++ b/class-unlist-posts.php @@ -150,7 +150,7 @@ public function hide_post_from_searchengines() { $hidden_posts = get_option( 'unlist_posts', array() ); if ( in_array( get_the_ID(), $hidden_posts, true ) && false !== get_the_ID() ) { - add_filter( 'wp_robots', 'wp_robots_no_robots' ); + wp_robots_no_robots( $hidden_posts ); } } diff --git a/package.json b/package.json index 26742cd..79dcceb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hide-post", - "version": "1.1.3", + "version": "1.1.4", "main": "Gruntfile.js", "author": "Nikhil Chavan", "devDependencies": { diff --git a/readme.txt b/readme.txt index cd1043d..156914f 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.me/BrainstormForce Tags: post, unlist posts, hide posts, Requires at least: 4.4 Tested up to: 5.7 -Stable tag: 1.1.3 +Stable tag: 1.1.4 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -37,6 +37,9 @@ Just select option "Unlist Post" in any post of any type and that post will be h == Changelog == += 1.1.4 = +- Fix: Unlisted page appearing in google search result. + = 1.1.3 = - Deprecated: wp_no_robots() has been deprecated. - Security: Use escaping for displaying unlist post description. diff --git a/unlist-posts.php b/unlist-posts.php index a7d420b..ed77236 100644 --- a/unlist-posts.php +++ b/unlist-posts.php @@ -7,7 +7,7 @@ * Author URI: https://www.nikhilchavan.com/ * Text Domain: unlist-posts * Domain Path: /languages - * Version: 1.1.3 + * Version: 1.1.4 * * @package Hide_Post */ @@ -16,6 +16,6 @@ define( 'UNLIST_POSTS_DIR', plugin_dir_path( __FILE__ ) ); define( 'UNLIST_POSTS_URI', plugins_url( '/', __FILE__ ) ); -define( 'UNLIST_POSTS_VER', '1.1.3' ); +define( 'UNLIST_POSTS_VER', '1.1.4' ); require_once UNLIST_POSTS_DIR . 'class-unlist-posts.php'; From 84757da0897c13f429fa09428e21aa79751de514 Mon Sep 17 00:00:00 2001 From: Abhijit Babasaheb Nage Date: Thu, 18 Mar 2021 11:49:19 +0530 Subject: [PATCH 2/7] Added wp_robots() filter --- class-unlist-posts.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/class-unlist-posts.php b/class-unlist-posts.php index f26bf75..a83f0df 100644 --- a/class-unlist-posts.php +++ b/class-unlist-posts.php @@ -62,6 +62,7 @@ public function init() { add_filter( 'get_next_post_where', array( $this, 'post_navigation_clause' ), 20, 1 ); add_filter( 'get_previous_post_where', array( $this, 'post_navigation_clause' ), 20, 1 ); add_action( 'wp_head', array( $this, 'hide_post_from_searchengines' ) ); + add_filter( 'wp_robots', array( $this, 'hide_post_page_no_robots' ) ); add_filter( 'comments_clauses', array( $this, 'comments_clauses' ), 20, 2 ); add_filter( 'wp_list_pages_excludes', array( $this, 'wp_list_pages_excludes' ) ); } @@ -149,9 +150,34 @@ public function hide_post_from_searchengines() { $hidden_posts = get_option( 'unlist_posts', array() ); + // wp_no_robots is deprecated since WP 5.7. + if ( function_exists( 'wp_robots_no_robots' ) ) { + return; + } + + if ( in_array( get_the_ID(), $hidden_posts, true ) && false !== get_the_ID() ) { + wp_no_robots(); + } + } + + /** + * Add meta tags to block search engines on a page if the page is unlisted. + * + * @since 1.1.4 + */ + public function hide_post_page_no_robots( $robots ) { + + // Bail if posts unlists is disabled. + if ( false === $this->allow_post_unlist() ) { + return false; + } + + $hidden_posts = get_option( 'unlist_posts', array() ); + if ( in_array( get_the_ID(), $hidden_posts, true ) && false !== get_the_ID() ) { - wp_robots_no_robots( $hidden_posts ); + return wp_robots_no_robots( $robots ); } + return $robots; } /** From 96c60a317916eedd376589dfb83a0a548004cd57 Mon Sep 17 00:00:00 2001 From: Abhijit Babasaheb Nage Date: Thu, 18 Mar 2021 11:57:28 +0530 Subject: [PATCH 3/7] Added @param in function comment --- class-unlist-posts.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/class-unlist-posts.php b/class-unlist-posts.php index a83f0df..855dc69 100644 --- a/class-unlist-posts.php +++ b/class-unlist-posts.php @@ -161,12 +161,15 @@ public function hide_post_from_searchengines() { } /** - * Add meta tags to block search engines on a page if the page is unlisted. + * This directive tells web robots not to index the page content if the page is unlisted. * * @since 1.1.4 + * + * @param Array $robots Associative array of robots directives. + * */ public function hide_post_page_no_robots( $robots ) { - + // Bail if posts unlists is disabled. if ( false === $this->allow_post_unlist() ) { return false; From 00ffd9dfb87391770c008d31598a1ad83aa90325 Mon Sep 17 00:00:00 2001 From: Abhijit Babasaheb Nage Date: Thu, 18 Mar 2021 12:00:41 +0530 Subject: [PATCH 4/7] remove unwanted spaces --- class-unlist-posts.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/class-unlist-posts.php b/class-unlist-posts.php index 855dc69..1cbfd8a 100644 --- a/class-unlist-posts.php +++ b/class-unlist-posts.php @@ -164,9 +164,7 @@ public function hide_post_from_searchengines() { * This directive tells web robots not to index the page content if the page is unlisted. * * @since 1.1.4 - * * @param Array $robots Associative array of robots directives. - * */ public function hide_post_page_no_robots( $robots ) { From db47ad41b4a809e4b92173542da6b292c8dab958 Mon Sep 17 00:00:00 2001 From: Abhijit Babasaheb Nage Date: Thu, 18 Mar 2021 12:32:37 +0530 Subject: [PATCH 5/7] Updated readme, filter name and conditions --- README.md | 2 +- class-unlist-posts.php | 16 ++++++++-------- readme.txt | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 96326e0..0d59278 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Just select option "Unlist Post" in any post of any type and that post will be h ## Changelog ## ### 1.1.4 ### -- Fix: Unlisted page appearing in google search result. +- Fix: due to a bug unlisted posts were visible in the search results, which we have fixed now. ### 1.1.3 ### - Deprecated: wp_no_robots() has been deprecated. diff --git a/class-unlist-posts.php b/class-unlist-posts.php index 1cbfd8a..8b6f48e 100644 --- a/class-unlist-posts.php +++ b/class-unlist-posts.php @@ -62,7 +62,7 @@ public function init() { add_filter( 'get_next_post_where', array( $this, 'post_navigation_clause' ), 20, 1 ); add_filter( 'get_previous_post_where', array( $this, 'post_navigation_clause' ), 20, 1 ); add_action( 'wp_head', array( $this, 'hide_post_from_searchengines' ) ); - add_filter( 'wp_robots', array( $this, 'hide_post_page_no_robots' ) ); + add_filter( 'wp_robots', array( $this, 'no_robots_for_unlisted_posts' ) ); add_filter( 'comments_clauses', array( $this, 'comments_clauses' ), 20, 2 ); add_filter( 'wp_list_pages_excludes', array( $this, 'wp_list_pages_excludes' ) ); } @@ -143,6 +143,11 @@ function post_navigation_clause( $where ) { */ public function hide_post_from_searchengines() { + // wp_no_robots is deprecated since WP 5.7. + if ( function_exists( 'wp_robots_no_robots' ) ) { + return; + } + // Bail if posts unlists is disabled. if ( false === $this->allow_post_unlist() ) { return false; @@ -150,11 +155,6 @@ public function hide_post_from_searchengines() { $hidden_posts = get_option( 'unlist_posts', array() ); - // wp_no_robots is deprecated since WP 5.7. - if ( function_exists( 'wp_robots_no_robots' ) ) { - return; - } - if ( in_array( get_the_ID(), $hidden_posts, true ) && false !== get_the_ID() ) { wp_no_robots(); } @@ -166,11 +166,11 @@ public function hide_post_from_searchengines() { * @since 1.1.4 * @param Array $robots Associative array of robots directives. */ - public function hide_post_page_no_robots( $robots ) { + public function no_robots_for_unlisted_posts( $robots ) { // Bail if posts unlists is disabled. if ( false === $this->allow_post_unlist() ) { - return false; + return $robots; } $hidden_posts = get_option( 'unlist_posts', array() ); diff --git a/readme.txt b/readme.txt index 156914f..3390d11 100644 --- a/readme.txt +++ b/readme.txt @@ -38,7 +38,7 @@ Just select option "Unlist Post" in any post of any type and that post will be h == Changelog == = 1.1.4 = -- Fix: Unlisted page appearing in google search result. +- Fix: due to a bug unlisted posts were visible in the search results, which we have fixed now. = 1.1.3 = - Deprecated: wp_no_robots() has been deprecated. From 0eaf778ac39aa721a9d59a59a6e8593c8eb5cd9f Mon Sep 17 00:00:00 2001 From: Abhijit Babasaheb Nage Date: Thu, 18 Mar 2021 12:46:37 +0530 Subject: [PATCH 6/7] Remove unwanted line space --- class-unlist-posts.php | 1 - 1 file changed, 1 deletion(-) diff --git a/class-unlist-posts.php b/class-unlist-posts.php index 8b6f48e..0d0f80c 100644 --- a/class-unlist-posts.php +++ b/class-unlist-posts.php @@ -167,7 +167,6 @@ public function hide_post_from_searchengines() { * @param Array $robots Associative array of robots directives. */ public function no_robots_for_unlisted_posts( $robots ) { - // Bail if posts unlists is disabled. if ( false === $this->allow_post_unlist() ) { return $robots; From 37853486f002b3ed7a84850960f3d27820b01c3b Mon Sep 17 00:00:00 2001 From: Abhijit Babasaheb Nage Date: Thu, 18 Mar 2021 12:53:25 +0530 Subject: [PATCH 7/7] Updated readme --- README.md | 2 +- readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0d59278..aad4308 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Just select option "Unlist Post" in any post of any type and that post will be h ## Changelog ## ### 1.1.4 ### -- Fix: due to a bug unlisted posts were visible in the search results, which we have fixed now. +- Fix: Due to a bug unlisted posts were visible in the search results, which we have fixed now. ### 1.1.3 ### - Deprecated: wp_no_robots() has been deprecated. diff --git a/readme.txt b/readme.txt index 3390d11..edb6d32 100644 --- a/readme.txt +++ b/readme.txt @@ -38,7 +38,7 @@ Just select option "Unlist Post" in any post of any type and that post will be h == Changelog == = 1.1.4 = -- Fix: due to a bug unlisted posts were visible in the search results, which we have fixed now. +- Fix: Due to a bug unlisted posts were visible in the search results, which we have fixed now. = 1.1.3 = - Deprecated: wp_no_robots() has been deprecated.