diff --git a/build/editor-plugin/plugin.asset.php b/build/editor-plugin/plugin.asset.php index 726932c..5eb229b 100644 --- a/build/editor-plugin/plugin.asset.php +++ b/build/editor-plugin/plugin.asset.php @@ -1 +1 @@ - array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-i18n', 'wp-plugins'), 'version' => '03845d869ccb1b1eb23c'); + array('react', 'wp-components', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-i18n', 'wp-plugins'), 'version' => '5b3078e57362374cb01e'); diff --git a/build/editor-plugin/plugin.js b/build/editor-plugin/plugin.js index b27222a..f4f89d6 100644 --- a/build/editor-plugin/plugin.js +++ b/build/editor-plugin/plugin.js @@ -1 +1 @@ -(()=>{"use strict";const e=window.React,n=window.wp.editor,t=window.wp.plugins,o=window.wp.components,i=window.wp.data,w=window.wp.coreData,s=window.wp.i18n;(0,t.registerPlugin)("webmention-editor-plugin",{render:()=>{const t=(0,i.useSelect)((e=>e("core/editor").getCurrentPostType()),[]),[r,a]=(0,w.useEntityProp)("postType",t,"meta");return(0,e.createElement)(n.PluginDocumentSettingPanel,{name:"webmention",title:(0,s.__)("Webmentions","webmention")},(0,e.createElement)(o.CheckboxControl,{__nextHasNoMarginBottom:!0,label:(0,s.__)("Disable Webmentions","webmention"),help:(0,s.__)("Do not accept incoming Webmentions for this post.","webmention"),checked:r.webmentions_disabled,onChange:e=>{a({...r,webmentions_disabled:e})}}))}})})(); \ No newline at end of file +(()=>{"use strict";const e=window.React,n=window.wp.editor,t=window.wp.plugins,o=window.wp.components,i=window.wp.data,s=window.wp.coreData,w=window.wp.i18n;(0,t.registerPlugin)("webmention-editor-plugin",{render:()=>{const t=(0,i.useSelect)((e=>e("core/editor").getCurrentPostType()),[]),[a,d]=(0,s.useEntityProp)("postType",t,"meta");return(0,e.createElement)(n.PluginDocumentSettingPanel,{name:"webmention",title:(0,w.__)("Webmentions","webmention")},(0,e.createElement)(o.CheckboxControl,{__nextHasNoMarginBottom:!0,label:(0,w.__)("Disable incoming","webmention"),help:(0,w.__)("Do not accept incoming Webmentions for this post.","webmention"),checked:a.webmentions_disabled,onChange:e=>{d({...a,webmentions_disabled:e})}}),(0,e.createElement)(o.CheckboxControl,{__nextHasNoMarginBottom:!0,label:(0,w.__)("Disable outgoing","webmention"),help:(0,w.__)("Do not send Webmentions for this post.","webmention"),checked:a.webmentions_disabled_pings,onChange:e=>{d({...a,webmentions_disabled_pings:e})}}))}})})(); \ No newline at end of file diff --git a/includes/class-block.php b/includes/class-block.php index 581d597..a5105e0 100644 --- a/includes/class-block.php +++ b/includes/class-block.php @@ -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', + ) + ); } } diff --git a/includes/class-sender.php b/includes/class-sender.php index 7063ca7..4bb78ad 100755 --- a/includes/class-sender.php +++ b/includes/class-sender.php @@ -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' ); @@ -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 ) { @@ -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' ), @@ -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 ); } } } diff --git a/includes/class-webmention.php b/includes/class-webmention.php index d10623b..a20988a 100644 --- a/includes/class-webmention.php +++ b/includes/class-webmention.php @@ -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 ); } diff --git a/src/editor-plugin/plugin.js b/src/editor-plugin/plugin.js index de82c7e..927987d 100644 --- a/src/editor-plugin/plugin.js +++ b/src/editor-plugin/plugin.js @@ -20,13 +20,22 @@ const EditorPlugin = () => { > { setMeta( { ...meta, webmentions_disabled: value } ); } } /> + { + setMeta( { ...meta, webmentions_disabled_pings: value } ); + } } + /> ); }