Skip to content

Disable outgoing Webmentions #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/editor-plugin/plugin.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-i18n', 'wp-plugins'), 'version' => '03845d869ccb1b1eb23c');
<?php return array('dependencies' => array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-i18n', 'wp-plugins'), 'version' => '5b3078e57362374cb01e');
2 changes: 1 addition & 1 deletion build/editor-plugin/plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions includes/class-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ public static function register_postmeta() {
'type' => 'boolean',
)
);
\register_post_meta(
$post_type,
'webmentions_disabled_pings',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
)
);
}
}

Expand Down
20 changes: 14 additions & 6 deletions includes/class-sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public static function init() {
* @param int $post_id Post ID.
*/
public static function publish_hook( $post_id ) {
add_post_meta( $post_id, '_mentionme', '1', true );
if ( \get_post_meta( $post_id, 'webmentions_disabled_pings', 1 ) ) {
return;
}

\add_post_meta( $post_id, '_mentionme', '1', true );
// Post Types Other than Post Do Not Trigger Pings. This will unless it is already scheduled.
if ( ! wp_next_scheduled( 'do_pings' ) ) {
wp_schedule_single_event( time(), 'do_pings' );
Expand Down Expand Up @@ -188,6 +192,10 @@ public static function send_webmention( $source, $target, $post_id = null ) {
* @return array|bool array of results or false if failed.
*/
public static function send_webmentions( $post_id ) {
if ( \get_post_meta( $post_id, 'webmentions_disabled_pings', 1 ) ) {
return;
}

$source = get_post_meta( $post_id, 'webmention_canonical_url', true );

if ( ! $source ) {
Expand Down Expand Up @@ -321,7 +329,7 @@ public static function do_webmentions() {
remove_filter( 'pre_get_posts', 'ksuce_exclude_categories' );
}

$mentions = get_posts(
$post_ids = get_posts(
array(
'meta_key' => '_mentionme',
'post_type' => get_post_types_by_support( 'webmentions' ),
Expand All @@ -334,14 +342,14 @@ public static function do_webmentions() {
add_filter( 'pre_get_posts', 'ksuce_exclude_categories' );
}

if ( empty( $mentions ) ) {
if ( empty( $post_ids ) ) {
return;
}

foreach ( $mentions as $mention ) {
delete_post_meta( $mention, '_mentionme' );
foreach ( $post_ids as $post_id ) {
\delete_post_meta( $post_id, '_mentionme' );
// send them Webmentions
self::send_webmentions( $mention );
self::send_webmentions( $post_id );
}
}
}
4 changes: 3 additions & 1 deletion includes/class-webmention.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ public function enqueue_scripts() {
* @param mixed $meta_value The meta value.
*/
public function maybe_bypass_webmentions_disabled( $check, $object_id, $meta_key, $meta_value ) {
if ( 'webmentions_disabled' === $meta_key && empty( $meta_value ) ) {
$meta_keys = array( 'webmentions_disabled', 'webmentions_disabled_pings' );

if ( \in_array( $meta_key, $meta_keys, true ) && empty( $meta_value ) ) {
if ( 'update_post_metadata' === current_action() ) {
\delete_post_meta( $object_id, $meta_key );
}
Expand Down
11 changes: 10 additions & 1 deletion src/editor-plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ const EditorPlugin = () => {
>
<CheckboxControl
__nextHasNoMarginBottom
label={ __( 'Disable Webmentions', 'webmention' ) }
label={ __( 'Disable incoming', 'webmention' ) }
help={ __( 'Do not accept incoming Webmentions for this post.', 'webmention' ) }
checked={ meta.webmentions_disabled }
onChange={ ( value ) => {
setMeta( { ...meta, webmentions_disabled: value } );
} }
/>
<CheckboxControl
__nextHasNoMarginBottom
label={ __( 'Disable outgoing', 'webmention' ) }
help={ __( 'Do not send Webmentions for this post.', 'webmention' ) }
checked={ meta.webmentions_disabled_pings }
onChange={ ( value ) => {
setMeta( { ...meta, webmentions_disabled_pings: value } );
} }
/>
</PluginDocumentSettingPanel>
);
}
Expand Down