Skip to content

Commit 06fe0f7

Browse files
authored
Merge pull request #55 from brainstormforce/unlisted-post-on-previeous-next-pages
Fix: Unlisted post visible on previous, next post pages.
2 parents 28f0f96 + d3e1721 commit 06fe0f7

16 files changed

+2233
-149
lines changed

.github/workflows/phpcs.yml

+21-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,28 @@ jobs:
1010
- name: Checkout
1111
uses: actions/checkout@v2
1212

13+
- name: Setup PHP
14+
uses: shivammathur/setup-php@v2
15+
with:
16+
php-version: 7.4
17+
coverage: none
18+
tools: composer, cs2pr
19+
20+
- name: Get Composer cache directory
21+
id: composer-cache
22+
run: |
23+
echo "::set-output name=dir::$(composer config cache-files-dir)"
24+
25+
- name: Setup cache
26+
uses: pat-s/[email protected]
27+
with:
28+
path: ${{ steps.composer-cache.outputs.dir }}
29+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
30+
restore-keys: |
31+
${{ runner.os }}-composer-
32+
1333
- name: Install dependencies
14-
run: composer install --dev --prefer-dist --no-progress --no-suggest
34+
run: composer install --no-progress --prefer-dist --optimize-autoloader
1535

1636
- name: PHPCS check
1737
uses: chekalsky/phpcs-action@v1

.github/workflows/phpunit.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: PHPUnit
2+
3+
on: push
4+
5+
jobs:
6+
phpunit:
7+
name: PHPUnit (PHP ${{ matrix.php }} with WordPress ${{ matrix.wordpress }})
8+
runs-on: ubuntu-latest
9+
10+
services:
11+
mysql:
12+
image: mysql:5.7
13+
ports:
14+
- 3306/tcp
15+
env:
16+
MYSQL_ROOT_PASSWORD: password
17+
# Set health checks to wait until mysql has started
18+
options: >-
19+
--health-cmd "mysqladmin ping"
20+
--health-interval 10s
21+
--health-timeout 5s
22+
--health-retries 3
23+
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
php: ['7.4']
28+
wordpress: ['trunk']
29+
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v2
33+
34+
- name: Setup PHP
35+
uses: shivammathur/setup-php@v2
36+
with:
37+
php-version: ${{ matrix.php }}
38+
coverage: none
39+
tools: composer, cs2pr
40+
41+
- name: Install WordPress test setup
42+
env:
43+
WP_VERSION: ${{ matrix.wordpress }}
44+
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
45+
run: bash bin/install-wp-tests.sh wordpress_test root password "127.0.0.1:$MYSQL_PORT" "$WP_VERSION"
46+
47+
- name: Get Composer cache directory
48+
id: composer-cache
49+
run: |
50+
echo "::set-output name=dir::$(composer config cache-files-dir)"
51+
52+
- name: Setup cache
53+
uses: pat-s/[email protected]
54+
with:
55+
path: ${{ steps.composer-cache.outputs.dir }}
56+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
57+
restore-keys: |
58+
${{ runner.os }}-composer-
59+
60+
- name: Install dependencies
61+
run: composer install --no-progress --prefer-dist --optimize-autoloader
62+
63+
- name: Setup problem matchers for PHPUnit
64+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
65+
66+
- name: Run tests
67+
run: composer run test

.travis.yml

-34
This file was deleted.

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.5
7+
**Stable tag:** 1.1.6
88
**License:** GPLv2 or later
99
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -36,6 +36,9 @@ Need help with something? Have an issue to report? [Get in touch](https://github
3636
Just select option "Unlist Post" in any post of any type and that post will be hidden from the whole site, it can be only accessed if you have the direct link to the post.
3737

3838
## Changelog ##
39+
### 1.1.6 ###
40+
- Fix: Unlisted post visible in preview/next post links.
41+
3942
### 1.1.5 ###
4043
- Fix: Compatibility with Yoast SEO's robots tags options. Robots tags from Unlist Posts will override tag changes from Yoast SEO.
4144

bin/install-wp-tests.sh

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/usr/bin/env bash
2+
3+
if [ $# -lt 3 ]; then
4+
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
5+
exit 1
6+
fi
7+
8+
DB_NAME=$1
9+
DB_USER=$2
10+
DB_PASS=$3
11+
DB_HOST=${4-localhost}
12+
WP_VERSION=${5-latest}
13+
SKIP_DB_CREATE=${6-false}
14+
15+
TMPDIR=${TMPDIR-/tmp}
16+
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
17+
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
18+
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}
19+
20+
download() {
21+
if [ `which curl` ]; then
22+
curl -s "$1" > "$2";
23+
elif [ `which wget` ]; then
24+
wget -nv -O "$2" "$1"
25+
fi
26+
}
27+
28+
if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
29+
WP_BRANCH=${WP_VERSION%\-*}
30+
WP_TESTS_TAG="branches/$WP_BRANCH"
31+
32+
elif [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
33+
WP_TESTS_TAG="branches/$WP_VERSION"
34+
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
35+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
36+
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
37+
WP_TESTS_TAG="tags/${WP_VERSION%??}"
38+
else
39+
WP_TESTS_TAG="tags/$WP_VERSION"
40+
fi
41+
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
42+
WP_TESTS_TAG="trunk"
43+
else
44+
# http serves a single offer, whereas https serves multiple. we only want one
45+
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
46+
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
47+
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
48+
if [[ -z "$LATEST_VERSION" ]]; then
49+
echo "Latest WordPress version could not be found"
50+
exit 1
51+
fi
52+
WP_TESTS_TAG="tags/$LATEST_VERSION"
53+
fi
54+
set -ex
55+
56+
install_wp() {
57+
58+
if [ -d $WP_CORE_DIR ]; then
59+
return;
60+
fi
61+
62+
mkdir -p $WP_CORE_DIR
63+
64+
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
65+
mkdir -p $TMPDIR/wordpress-nightly
66+
download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip
67+
unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/
68+
mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR
69+
else
70+
if [ $WP_VERSION == 'latest' ]; then
71+
local ARCHIVE_NAME='latest'
72+
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then
73+
# https serves multiple offers, whereas http serves single.
74+
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json
75+
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
76+
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
77+
LATEST_VERSION=${WP_VERSION%??}
78+
else
79+
# otherwise, scan the releases and get the most up to date minor version of the major release
80+
local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
81+
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
82+
fi
83+
if [[ -z "$LATEST_VERSION" ]]; then
84+
local ARCHIVE_NAME="wordpress-$WP_VERSION"
85+
else
86+
local ARCHIVE_NAME="wordpress-$LATEST_VERSION"
87+
fi
88+
else
89+
local ARCHIVE_NAME="wordpress-$WP_VERSION"
90+
fi
91+
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
92+
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
93+
fi
94+
95+
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
96+
}
97+
98+
install_test_suite() {
99+
# portable in-place argument for both GNU sed and Mac OSX sed
100+
if [[ $(uname -s) == 'Darwin' ]]; then
101+
local ioption='-i.bak'
102+
else
103+
local ioption='-i'
104+
fi
105+
106+
# set up testing suite if it doesn't yet exist
107+
if [ ! -d $WP_TESTS_DIR ]; then
108+
# set up testing suite
109+
mkdir -p $WP_TESTS_DIR
110+
svn co --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
111+
svn co --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
112+
fi
113+
114+
if [ ! -f wp-tests-config.php ]; then
115+
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
116+
# remove all forward slashes in the end
117+
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
118+
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
119+
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
120+
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
121+
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
122+
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
123+
fi
124+
125+
}
126+
127+
install_db() {
128+
129+
if [ ${SKIP_DB_CREATE} = "true" ]; then
130+
return 0
131+
fi
132+
133+
# parse DB_HOST for port or socket references
134+
local PARTS=(${DB_HOST//\:/ })
135+
local DB_HOSTNAME=${PARTS[0]};
136+
local DB_SOCK_OR_PORT=${PARTS[1]};
137+
local EXTRA=""
138+
139+
if ! [ -z $DB_HOSTNAME ] ; then
140+
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
141+
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
142+
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
143+
EXTRA=" --socket=$DB_SOCK_OR_PORT"
144+
elif ! [ -z $DB_HOSTNAME ] ; then
145+
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
146+
fi
147+
fi
148+
149+
# create database
150+
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
151+
}
152+
153+
install_wp
154+
install_test_suite
155+
install_db

class-unlist-posts.php

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

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

@@ -202,7 +202,7 @@ public function comments_clauses( $clauses, $query ) {
202202
$hidden_posts = get_option( 'unlist_posts', array() );
203203

204204
// bail if none of the posts are hidden or we are on admin page or singular page.
205-
if ( ( is_admin() && ! wp_doing_ajax() ) || in_array( get_the_ID(), $hidden_posts, true ) || empty( $hidden_posts ) ) {
205+
if ( ( is_admin() && ! wp_doing_ajax() ) || empty( $hidden_posts ) ) {
206206
return $clauses;
207207
}
208208

composer.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
"name": "brainstormforce/unlist-posts",
33
"description": "Unlist Posts from displaying anywhere on the site, only access the post with a direct link.",
44
"require-dev": {
5-
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
6-
"phpcompatibility/phpcompatibility-wp": "*",
7-
"wp-coding-standards/wpcs": "^2"
5+
"wp-coding-standards/wpcs": "^2.2",
6+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
7+
"phpcompatibility/php-compatibility": "^9.3",
8+
"phpunit/phpunit": "^5.7 || ^6.5 || ^7.5"
89
},
9-
"require": {}
10+
"require": {},
11+
"scripts": {
12+
"test": "vendor/bin/phpunit"
13+
}
1014
}

0 commit comments

Comments
 (0)