Skip to content

Commit d9989ac

Browse files
authored
Merge pull request #46 from brainstormforce/tested-with-wp-56
Tested with WordPress 5.6 and PHP 8
2 parents cbf636f + bde0254 commit d9989ac

8 files changed

+92
-84
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
**Donate link:** https://www.paypal.me/BrainstormForce
44
**Tags:** post, unlist posts, hide posts,
55
**Requires at least:** 4.4
6-
**Tested up to:** 5.5
7-
**Stable tag:** 1.1.0
6+
**Tested up to:** 5.6
7+
**Stable tag:** 1.1.1
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.1 ###
41+
- Improvement: Added the WordPress 5.6 compatibilty.
42+
4043
### 1.1.0 ###
4144
- New: Add post status filter to make it easier to find out the unlisted posts. (Props [@matthewmcvickar](https://github.com/matthewmcvickar) [#40](https://github.com/Nikschavan/unlist-posts/pull/40))
4245
- Fix: Don't save post status for the revision posts.

class-unlist-posts-admin.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ function metabox_render( $post ) {
7777

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

80-
if ( '' == $hidden_posts ) {
80+
if ( '' === $hidden_posts ) {
8181
$hidden_posts = array();
8282
}
8383

8484
$checked = '';
8585

86-
if ( in_array( $post->ID, $hidden_posts ) ) {
86+
if ( in_array( $post->ID, $hidden_posts, true ) ) {
8787
$checked = 'checked';
8888
}
8989

@@ -129,7 +129,7 @@ public function save_meta( $post_id ) {
129129

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

132-
if ( '' == $hidden_posts ) {
132+
if ( '' === $hidden_posts ) {
133133
$hidden_posts = array();
134134
}
135135

@@ -138,12 +138,12 @@ public function save_meta( $post_id ) {
138138

139139
// Get only the unique post id's in the option array.
140140
$hidden_posts = array_unique( $hidden_posts );
141-
} elseif ( in_array( $post_id, $hidden_posts ) ) {
141+
} elseif ( in_array( $post_id, $hidden_posts, true ) ) {
142142

143143
// Get only the unique post id's in the option array.
144144
$hidden_posts = array_unique( $hidden_posts );
145145

146-
$key = array_search( $post_id, $hidden_posts );
146+
$key = array_search( $post_id, $hidden_posts, true );
147147
unset( $hidden_posts[ $key ] );
148148
}
149149

@@ -160,15 +160,15 @@ public function save_meta( $post_id ) {
160160
*/
161161
function add_unlisted_post_status( $states, $post ) {
162162
// Bail if the unlisted post filter is active, to avoid redundancy.
163-
if ( is_admin() && isset( $_GET['post_status'] ) && 'unlisted' == $_GET['post_status'] ) {
163+
if ( is_admin() && isset( $_GET['post_status'] ) && 'unlisted' === $_GET['post_status'] ) {
164164
return;
165165
}
166166

167167
// Get the list of unlisted post IDs from the options table.
168168
$unlisted_posts = maybe_unserialize( get_option( 'unlist_posts', array() ) );
169169

170170
// Check if this post is unlisted and mark it as so if appropriate.
171-
if ( in_array( $post->ID, $unlisted_posts ) ) {
171+
if ( in_array( $post->ID, $unlisted_posts, true ) ) {
172172
$states[] = __( 'Unlisted', 'unlist-posts' );
173173
}
174174

@@ -185,20 +185,20 @@ function add_unlisted_post_status( $states, $post ) {
185185
function add_unlisted_post_filter( $views ) {
186186
// Get the list of unlisted post IDs from the options table.
187187
$unlisted_posts = maybe_unserialize( get_option( 'unlist_posts', array() ) );
188-
$count = false;
188+
$count = false;
189189

190190
// Mark 'Unlisted' filter as the current filter if it is.
191191
$link_attributes = '';
192-
if ( is_admin() && isset( $_GET['post_status'] ) && 'unlisted' == $_GET['post_status'] ) {
192+
if ( is_admin() && isset( $_GET['post_status'] ) && 'unlisted' === $_GET['post_status'] ) {
193193
$link_attributes = 'class="current" aria-current="page"';
194194
}
195195

196196
if ( ! empty( $unlisted_posts ) ) {
197197
$post_type = get_current_screen()->post_type ? get_current_screen()->post_type : get_post_types();
198-
$query = new WP_Query(
198+
$query = new WP_Query(
199199
array(
200200
'post_type' => $post_type,
201-
'post__in' => $unlisted_posts
201+
'post__in' => $unlisted_posts,
202202
)
203203
);
204204

@@ -207,12 +207,12 @@ function add_unlisted_post_filter( $views ) {
207207

208208
$link = add_query_arg(
209209
array(
210-
'post_status' => 'unlisted'
210+
'post_status' => 'unlisted',
211211
)
212212
);
213213

214214
if ( false !== $count && 0 !== $count ) {
215-
$views['unlisted'] = '<a href=" '. esc_url( $link ) .' " ' . $link_attributes . '>' . __( 'Unlisted', 'unlist-posts' ) . ' <span class="count">(' . esc_html( $count ) . ')</span></a>';
215+
$views['unlisted'] = '<a href=" ' . esc_url( $link ) . ' " ' . $link_attributes . '>' . __( 'Unlisted', 'unlist-posts' ) . ' <span class="count">(' . esc_html( $count ) . ')</span></a>';
216216
}
217217

218218
return $views;
@@ -230,7 +230,7 @@ function add_post_filter() {
230230

231231
$post_types = get_post_types( $args, 'names', 'and' );
232232

233-
foreach( $post_types as $post_type ) {
233+
foreach ( $post_types as $post_type ) {
234234
add_filter( 'views_edit-' . $post_type, array( $this, 'add_unlisted_post_filter' ) );
235235
}
236236
}
@@ -245,7 +245,7 @@ function add_post_filter() {
245245
function filter_unlisted_posts( $query ) {
246246
global $pagenow;
247247

248-
if ( is_admin() && 'edit.php' == $pagenow && isset( $_GET['post_status'] ) && 'unlisted' == $_GET['post_status'] ) {
248+
if ( is_admin() && 'edit.php' === $pagenow && isset( $_GET['post_status'] ) && 'unlisted' === $_GET['post_status'] ) {
249249
// Get the list of unlisted post IDs from the options table.
250250
$unlisted_posts = maybe_unserialize( get_option( 'unlist_posts', array() ) );
251251

class-unlist-posts.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function post_navigation_clause( $where ) {
126126
$hidden_posts = get_option( 'unlist_posts', array() );
127127

128128
// bail if none of the posts are hidden or we are on admin page or singular page.
129-
if ( ( is_admin() && ! wp_doing_ajax() ) || in_array( get_the_ID(), $hidden_posts ) || empty( $hidden_posts ) ) {
129+
if ( ( is_admin() && ! wp_doing_ajax() ) || in_array( get_the_ID(), $hidden_posts, true ) || empty( $hidden_posts ) ) {
130130
return $where;
131131
}
132132

@@ -149,7 +149,7 @@ public function hide_post_from_searchengines() {
149149

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

152-
if ( in_array( get_the_ID(), $hidden_posts ) && false !== get_the_ID() ) {
152+
if ( in_array( get_the_ID(), $hidden_posts, true ) && false !== get_the_ID() ) {
153153
wp_no_robots();
154154
}
155155
}
@@ -174,7 +174,7 @@ public function comments_clauses( $clauses, $query ) {
174174
$hidden_posts = get_option( 'unlist_posts', array() );
175175

176176
// bail if none of the posts are hidden or we are on admin page or singular page.
177-
if ( ( is_admin() && ! wp_doing_ajax() ) || in_array( get_the_ID(), $hidden_posts ) || empty( $hidden_posts ) ) {
177+
if ( ( is_admin() && ! wp_doing_ajax() ) || in_array( get_the_ID(), $hidden_posts, true ) || empty( $hidden_posts ) ) {
178178
return $clauses;
179179
}
180180

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require-dev": {
3-
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
3+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
44
"wp-coding-standards/wpcs": "dev-master",
55
"phpcompatibility/phpcompatibility-wp": "*"
66
},

0 commit comments

Comments
 (0)