Skip to content

Commit eab6b77

Browse files
authored
Merge pull request #3 from ProgressPlanner/develop
1.0
2 parents c94f0c5 + 60cd7d0 commit eab6b77

File tree

8 files changed

+82
-11
lines changed

8 files changed

+82
-11
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Playground Comment
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
jobs:
9+
if_merged:
10+
if: github.event.pull_request.merged == true
11+
runs-on: ubuntu-latest
12+
permissions:
13+
pull-requests: write
14+
steps:
15+
- uses: mshick/add-pr-comment@v2
16+
with:
17+
message: |
18+
**Test merged PR on Playground**
19+
[Test this pull request on the Playground](https://playground.wordpress.net/#{"landingPage":"/wp-admin/","features":{"networking":true},"login":true,"plugins":["https://github-proxy.com/proxy/?repo=${{ github.repository }}"],"steps":[{"step":"defineWpConfigConsts","consts":{"IS_PLAYGROUND_PREVIEW":true}}]}) or [download the zip](${{ github.server_url }}/${{ github.repository }}/archive/refs/heads/develop.zip).

.wordpress-org/banner-1544x500.png

45.3 KB
Loading

.wordpress-org/banner-772x250.png

45.3 KB
Loading

.wordpress-org/icon-128x128.png

2.31 KB
Loading

.wordpress-org/icon-256x256.png

4.65 KB
Loading

.wordpress-org/icon.svg

Lines changed: 1 addition & 0 deletions
Loading

comment-free-zone.php

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @package Comment_Free_Zone
66
*
77
* Plugin name: Comment-free zone
8-
* Plugin URI: https://prpl.fyi/comment-free-zone
8+
* Plugin URI: https://progressplanner.com/plugins/comment-free-zone/#utm_medium=readme&utm_source=w.org&utm_campaign=comment-free-zone
99
* Description: A plugin to fully disable comments, trackbacks and all related features on your WordPress site.
1010
* Requires at least: 6.3
1111
* Requires PHP: 7.4
@@ -57,6 +57,20 @@ function ( $wp_admin_bar ) {
5757
999
5858
);
5959

60+
// Disable comments REST API endpoint.
61+
add_filter(
62+
'rest_endpoints',
63+
function ( $endpoints ) {
64+
if ( isset( $endpoints['/wp/v2/comments'] ) ) {
65+
unset( $endpoints['/wp/v2/comments'] );
66+
}
67+
if ( isset( $endpoints['/wp/v2/comments/(?P<id>[\d]+)'] ) ) {
68+
unset( $endpoints['/wp/v2/comments/(?P<id>[\d]+)'] );
69+
}
70+
return $endpoints;
71+
}
72+
);
73+
6074
add_filter( 'manage_pages_columns', [ $this, 'remove_comments_column_from_pages' ] );
6175
add_filter( 'comments_open', '__return_false', 20 );
6276
add_filter( 'pings_open', '__return_false', 20 );
@@ -66,6 +80,15 @@ function ( $wp_admin_bar ) {
6680
add_action( 'do_feed_rss', [ $this, 'disable_comment_feeds' ], 1 );
6781
add_filter( 'feed_links_show_comments_feed', '__return_false' );
6882

83+
// Disable default comment & ping status.
84+
add_filter(
85+
'get_default_comment_status',
86+
function () {
87+
return 'closed';
88+
},
89+
999
90+
);
91+
6992
// Disable comments on the frontend.
7093
add_filter(
7194
'comments_template',
@@ -103,10 +126,7 @@ function () {
103126
}
104127
$registry->unregister( 'core/' . $block );
105128
// Filter the output of the block to be empty.
106-
add_filter(
107-
'render_block_core/' . $block,
108-
'__return_empty_string'
109-
);
129+
add_filter( 'render_block_core/' . $block, '__return_empty_string' );
110130
}
111131

112132
// Disable outgoing pings.
@@ -133,9 +153,40 @@ function ( $methods ) {
133153
remove_post_type_support( $post_type, 'comments' );
134154
remove_post_type_support( $post_type, 'trackbacks' );
135155
}
156+
157+
add_filter( "rest_{$post_type}_item_schema", [ $this, 'cleanup_rest_api_schema' ] );
158+
159+
// Remove relpies link from REST API responses.
160+
add_filter( 'rest_prepare_' . $post_type, [ $this, 'cleanup_rest_prepare_post_type' ] );
136161
}
137162
}
138163

164+
/**
165+
* Remove comment_status and ping_status from the REST API schema.
166+
*
167+
* @param string[][] $schema The schema.
168+
*
169+
* @return string[][] The modified schema.
170+
*/
171+
public function cleanup_rest_api_schema( $schema ) {
172+
unset( $schema['properties']['comment_status'] );
173+
unset( $schema['properties']['ping_status'] );
174+
return $schema;
175+
}
176+
177+
/**
178+
* Remove the replies link from the REST API response - should only be present for posts and pages normally, but runs for all post types.
179+
*
180+
* @param WP_REST_Response $response The response object.
181+
*
182+
* @return WP_REST_Response The modified response object.
183+
*/
184+
public function cleanup_rest_prepare_post_type( $response ) {
185+
$response->remove_link( 'replies' );
186+
187+
return $response;
188+
}
189+
139190
/**
140191
* Disable comment feeds.
141192
*

readme.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
=== Comment-free zone ===
2-
Contributors: joostdevalk, aristath, mariekerakt, irisguelen, samalderson
2+
Contributors: progressplanner, joostdevalk, aristath, mariekerakt, irisguelen, samalderson
33
Tags: planning, maintenance, writing, blogging
44
Requires at least: 6.3
55
Tested up to: 6.7
@@ -17,10 +17,10 @@ This plugin fully removes comments, trackbacks and all related features from you
1717
This plugin will:
1818

1919
* In the admin:
20-
* Remove the comments menu
21-
* Remove the discussion settings page
22-
* Remove the comments column from posts and pages
23-
* Remove the comment section from the admin bar
20+
* Removes the Comments menu item.
21+
* Removes the Discussion settings page.
22+
* Removes the comments column from posts and pages.
23+
* Removes the comment section from the admin bar.
2424
* On the front-end:
2525
* Disable comments on all post types
2626
* Disable pingbacks and trackbacks
@@ -52,4 +52,4 @@ If you've found a bug, please follow the following steps:
5252

5353
= 1.0 =
5454

55-
* Initial release.
55+
* Initial release.

0 commit comments

Comments
 (0)