Skip to content

Commit

Permalink
Merge pull request #52 from brainstormforce/page-not-appear-in-google…
Browse files Browse the repository at this point in the history
…-search

Fix - unlisted page appear in google search result.
  • Loading branch information
patilvikasj authored Mar 18, 2021
2 parents 4c83fab + 3785348 commit 63806ce
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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: 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.
- Security: Use escaping for displaying unlist post description.
Expand Down
28 changes: 27 additions & 1 deletion class-unlist-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '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' ) );
}
Expand Down Expand Up @@ -142,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;
Expand All @@ -150,8 +156,28 @@ 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_no_robots();
}
}

/**
* 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 no_robots_for_unlisted_posts( $robots ) {
// Bail if posts unlists is disabled.
if ( false === $this->allow_post_unlist() ) {
return $robots;
}

$hidden_posts = get_option( 'unlist_posts', array() );

if ( in_array( get_the_ID(), $hidden_posts, true ) && false !== get_the_ID() ) {
return wp_robots_no_robots( $robots );
}
return $robots;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hide-post",
"version": "1.1.3",
"version": "1.1.4",
"main": "Gruntfile.js",
"author": "Nikhil Chavan",
"devDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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: 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.
- Security: Use escaping for displaying unlist post description.
Expand Down
4 changes: 2 additions & 2 deletions unlist-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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';

0 comments on commit 63806ce

Please sign in to comment.