Skip to content

Commit 63806ce

Browse files
authored
Merge pull request #52 from brainstormforce/page-not-appear-in-google-search
Fix - unlisted page appear in google search result.
2 parents 4c83fab + 3785348 commit 63806ce

5 files changed

+38
-6
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
**Tags:** post, unlist posts, hide posts,
55
**Requires at least:** 4.4
66
**Tested up to:** 5.7
7-
**Stable tag:** 1.1.3
7+
**Stable tag:** 1.1.4
88
**License:** GPLv2 or later
99
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -37,6 +37,9 @@ Just select option "Unlist Post" in any post of any type and that post will be h
3737

3838
## Changelog ##
3939

40+
### 1.1.4 ###
41+
- Fix: Due to a bug unlisted posts were visible in the search results, which we have fixed now.
42+
4043
### 1.1.3 ###
4144
- Deprecated: wp_no_robots() has been deprecated.
4245
- Security: Use escaping for displaying unlist post description.

class-unlist-posts.php

+27-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function init() {
6262
add_filter( 'get_next_post_where', array( $this, 'post_navigation_clause' ), 20, 1 );
6363
add_filter( 'get_previous_post_where', array( $this, 'post_navigation_clause' ), 20, 1 );
6464
add_action( 'wp_head', array( $this, 'hide_post_from_searchengines' ) );
65+
add_filter( 'wp_robots', array( $this, 'no_robots_for_unlisted_posts' ) );
6566
add_filter( 'comments_clauses', array( $this, 'comments_clauses' ), 20, 2 );
6667
add_filter( 'wp_list_pages_excludes', array( $this, 'wp_list_pages_excludes' ) );
6768
}
@@ -142,6 +143,11 @@ function post_navigation_clause( $where ) {
142143
*/
143144
public function hide_post_from_searchengines() {
144145

146+
// wp_no_robots is deprecated since WP 5.7.
147+
if ( function_exists( 'wp_robots_no_robots' ) ) {
148+
return;
149+
}
150+
145151
// Bail if posts unlists is disabled.
146152
if ( false === $this->allow_post_unlist() ) {
147153
return false;
@@ -150,8 +156,28 @@ public function hide_post_from_searchengines() {
150156
$hidden_posts = get_option( 'unlist_posts', array() );
151157

152158
if ( in_array( get_the_ID(), $hidden_posts, true ) && false !== get_the_ID() ) {
153-
add_filter( 'wp_robots', 'wp_robots_no_robots' );
159+
wp_no_robots();
160+
}
161+
}
162+
163+
/**
164+
* This directive tells web robots not to index the page content if the page is unlisted.
165+
*
166+
* @since 1.1.4
167+
* @param Array $robots Associative array of robots directives.
168+
*/
169+
public function no_robots_for_unlisted_posts( $robots ) {
170+
// Bail if posts unlists is disabled.
171+
if ( false === $this->allow_post_unlist() ) {
172+
return $robots;
173+
}
174+
175+
$hidden_posts = get_option( 'unlist_posts', array() );
176+
177+
if ( in_array( get_the_ID(), $hidden_posts, true ) && false !== get_the_ID() ) {
178+
return wp_robots_no_robots( $robots );
154179
}
180+
return $robots;
155181
}
156182

157183
/**

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hide-post",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"main": "Gruntfile.js",
55
"author": "Nikhil Chavan",
66
"devDependencies": {

readme.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.me/BrainstormForce
44
Tags: post, unlist posts, hide posts,
55
Requires at least: 4.4
66
Tested up to: 5.7
7-
Stable tag: 1.1.3
7+
Stable tag: 1.1.4
88
License: GPLv2 or later
99
License URI: http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -37,6 +37,9 @@ Just select option "Unlist Post" in any post of any type and that post will be h
3737

3838
== Changelog ==
3939

40+
= 1.1.4 =
41+
- Fix: Due to a bug unlisted posts were visible in the search results, which we have fixed now.
42+
4043
= 1.1.3 =
4144
- Deprecated: wp_no_robots() has been deprecated.
4245
- Security: Use escaping for displaying unlist post description.

unlist-posts.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Author URI: https://www.nikhilchavan.com/
88
* Text Domain: unlist-posts
99
* Domain Path: /languages
10-
* Version: 1.1.3
10+
* Version: 1.1.4
1111
*
1212
* @package Hide_Post
1313
*/
@@ -16,6 +16,6 @@
1616

1717
define( 'UNLIST_POSTS_DIR', plugin_dir_path( __FILE__ ) );
1818
define( 'UNLIST_POSTS_URI', plugins_url( '/', __FILE__ ) );
19-
define( 'UNLIST_POSTS_VER', '1.1.3' );
19+
define( 'UNLIST_POSTS_VER', '1.1.4' );
2020

2121
require_once UNLIST_POSTS_DIR . 'class-unlist-posts.php';

0 commit comments

Comments
 (0)