Skip to content

Commit e856ba3

Browse files
authored
Merge pull request #525 from pfefferle/feature/disable-pings
Disable outgoing Webmentions
2 parents 4c8cc8b + b7c51ce commit e856ba3

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

build/editor-plugin/plugin.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-i18n', 'wp-plugins'), 'version' => '03845d869ccb1b1eb23c');
1+
<?php return array('dependencies' => array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-i18n', 'wp-plugins'), 'version' => '5b3078e57362374cb01e');

build/editor-plugin/plugin.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-block.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ public static function register_postmeta() {
2727
'type' => 'boolean',
2828
)
2929
);
30+
\register_post_meta(
31+
$post_type,
32+
'webmentions_disabled_pings',
33+
array(
34+
'show_in_rest' => true,
35+
'single' => true,
36+
'type' => 'boolean',
37+
)
38+
);
3039
}
3140
}
3241

includes/class-sender.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public static function init() {
4444
* @param int $post_id Post ID.
4545
*/
4646
public static function publish_hook( $post_id ) {
47-
add_post_meta( $post_id, '_mentionme', '1', true );
47+
if ( \get_post_meta( $post_id, 'webmentions_disabled_pings', 1 ) ) {
48+
return;
49+
}
50+
51+
\add_post_meta( $post_id, '_mentionme', '1', true );
4852
// Post Types Other than Post Do Not Trigger Pings. This will unless it is already scheduled.
4953
if ( ! wp_next_scheduled( 'do_pings' ) ) {
5054
wp_schedule_single_event( time(), 'do_pings' );
@@ -188,6 +192,10 @@ public static function send_webmention( $source, $target, $post_id = null ) {
188192
* @return array|bool array of results or false if failed.
189193
*/
190194
public static function send_webmentions( $post_id ) {
195+
if ( \get_post_meta( $post_id, 'webmentions_disabled_pings', 1 ) ) {
196+
return;
197+
}
198+
191199
$source = get_post_meta( $post_id, 'webmention_canonical_url', true );
192200

193201
if ( ! $source ) {
@@ -321,7 +329,7 @@ public static function do_webmentions() {
321329
remove_filter( 'pre_get_posts', 'ksuce_exclude_categories' );
322330
}
323331

324-
$mentions = get_posts(
332+
$post_ids = get_posts(
325333
array(
326334
'meta_key' => '_mentionme',
327335
'post_type' => get_post_types_by_support( 'webmentions' ),
@@ -334,14 +342,14 @@ public static function do_webmentions() {
334342
add_filter( 'pre_get_posts', 'ksuce_exclude_categories' );
335343
}
336344

337-
if ( empty( $mentions ) ) {
345+
if ( empty( $post_ids ) ) {
338346
return;
339347
}
340348

341-
foreach ( $mentions as $mention ) {
342-
delete_post_meta( $mention, '_mentionme' );
349+
foreach ( $post_ids as $post_id ) {
350+
\delete_post_meta( $post_id, '_mentionme' );
343351
// send them Webmentions
344-
self::send_webmentions( $mention );
352+
self::send_webmentions( $post_id );
345353
}
346354
}
347355
}

includes/class-webmention.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ public function enqueue_scripts() {
197197
* @param mixed $meta_value The meta value.
198198
*/
199199
public function maybe_bypass_webmentions_disabled( $check, $object_id, $meta_key, $meta_value ) {
200-
if ( 'webmentions_disabled' === $meta_key && empty( $meta_value ) ) {
200+
$meta_keys = array( 'webmentions_disabled', 'webmentions_disabled_pings' );
201+
202+
if ( \in_array( $meta_key, $meta_keys, true ) && empty( $meta_value ) ) {
201203
if ( 'update_post_metadata' === current_action() ) {
202204
\delete_post_meta( $object_id, $meta_key );
203205
}

src/editor-plugin/plugin.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@ const EditorPlugin = () => {
2020
>
2121
<CheckboxControl
2222
__nextHasNoMarginBottom
23-
label={ __( 'Disable Webmentions', 'webmention' ) }
23+
label={ __( 'Disable incoming', 'webmention' ) }
2424
help={ __( 'Do not accept incoming Webmentions for this post.', 'webmention' ) }
2525
checked={ meta.webmentions_disabled }
2626
onChange={ ( value ) => {
2727
setMeta( { ...meta, webmentions_disabled: value } );
2828
} }
2929
/>
30+
<CheckboxControl
31+
__nextHasNoMarginBottom
32+
label={ __( 'Disable outgoing', 'webmention' ) }
33+
help={ __( 'Do not send Webmentions for this post.', 'webmention' ) }
34+
checked={ meta.webmentions_disabled_pings }
35+
onChange={ ( value ) => {
36+
setMeta( { ...meta, webmentions_disabled_pings: value } );
37+
} }
38+
/>
3039
</PluginDocumentSettingPanel>
3140
);
3241
}

0 commit comments

Comments
 (0)