Skip to content

Commit 77d654c

Browse files
committed
Add classic editor fallback for webmention post settings
1 parent e856ba3 commit 77d654c

File tree

5 files changed

+107
-31
lines changed

5 files changed

+107
-31
lines changed

includes/class-admin.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public static function discussion_settings() {
5252
}
5353

5454
/**
55-
* Add Webmention meta boxes to the comment editor screen.
55+
* Add Webmention meta boxes to the omment editor screen.
5656
*
5757
* @param object $object The comment object.
5858
*/
59-
public static function meta_boxes( $object ) {
59+
public static function comment_metabox( $object ) {
6060
wp_nonce_field( 'webmention_comment_metabox', 'webmention_comment_nonce' );
6161

6262
if ( ! $object instanceof WP_Comment ) {
@@ -65,6 +65,16 @@ public static function meta_boxes( $object ) {
6565
load_template( __DIR__ . '/../templates/webmention-edit-comment-form.php' );
6666
}
6767

68+
/**
69+
* Add Webmention settings meta box to the Classic editor screen.
70+
*
71+
* @param object $object The comment object.
72+
*/
73+
public static function post_metabox( $object ) {
74+
wp_nonce_field( 'webmention_post_metabox', 'webmention_post_nonce' );
75+
load_template( __DIR__ . '/../templates/webmention-edit-post-form.php' );
76+
}
77+
6878
/**
6979
* Add comment-type as column in WP-Admin
7080
*
@@ -162,11 +172,23 @@ public static function add_meta_boxes() {
162172
add_meta_box(
163173
'webmention-meta',
164174
esc_html__( 'Webmention Data', 'webmention' ),
165-
array( static::class, 'meta_boxes' ),
175+
array( static::class, 'comment_metabox' ),
166176
'comment',
167177
'normal',
168178
'default'
169179
);
180+
add_meta_box(
181+
'webmention-meta',
182+
esc_html__( 'Webmention Settings', 'webmention' ),
183+
array( static::class, 'post_metabox' ),
184+
get_option( 'webmention_support_post_types', array( 'post', 'page' ) ),
185+
'side',
186+
'default',
187+
array(
188+
'__block_editor_compatible_meta_box' => true,
189+
'__back_compat_meta_box' => true, // This should only be used in the Classic Editor.
190+
)
191+
);
170192
}
171193

172194
/**

includes/class-block.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,6 @@ class Block {
99
public static function init() {
1010
// Add editor plugin.
1111
\add_action( 'enqueue_block_editor_assets', array( self::class, 'enqueue_editor_assets' ) );
12-
\add_action( 'init', array( self::class, 'register_postmeta' ), 11 );
13-
}
14-
15-
/**
16-
* Register post meta
17-
*/
18-
public static function register_postmeta() {
19-
$post_types = \get_post_types_by_support( 'webmentions' );
20-
foreach ( $post_types as $post_type ) {
21-
\register_post_meta(
22-
$post_type,
23-
'webmentions_disabled',
24-
array(
25-
'show_in_rest' => true,
26-
'single' => true,
27-
'type' => 'boolean',
28-
)
29-
);
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-
);
39-
}
4012
}
4113

4214
/**

includes/class-receiver.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,30 @@ public static function init() {
4343
// Add scheduler for async processing
4444
add_action( 'webmention_process_schedule', array( static::class, 'process' ) );
4545

46+
$post_types = get_post_types_by_support( 'webmentions' );
47+
foreach ( $post_types as $post_type ) {
48+
add_action( 'save_' . $post_type, array( static::class, 'save_hook' ), 3 );
49+
}
50+
4651
self::register_meta();
4752
}
4853

4954
/**
5055
* This is more to lay out the data structure than anything else.
5156
*/
5257
public static function register_meta() {
58+
$post_types = \get_post_types_by_support( 'webmentions' );
59+
foreach ( $post_types as $post_type ) {
60+
\register_post_meta(
61+
$post_type,
62+
'webmentions_disabled',
63+
array(
64+
'show_in_rest' => true,
65+
'single' => true,
66+
'type' => 'boolean',
67+
)
68+
);
69+
}
5370
$args = array(
5471
'type' => 'string',
5572
'description' => esc_html__( 'Protocol Used to Receive', 'webmention' ),
@@ -127,6 +144,22 @@ public static function register_meta() {
127144
register_meta( 'comment', 'avatar', $args );
128145
}
129146

147+
/**
148+
* Saves optional settings on save
149+
*
150+
* @param int $post_id Post ID.
151+
*/
152+
public static function save_hook( $post_id ) {
153+
if ( array_key_exists( 'webmentions_disabled', $_POST ) ) {
154+
if ( 1 === intval( $_POST['webmentions_disabled'] ) ) {
155+
\add_post_meta( $post_id, 'webmentions_disabled', '1', true );
156+
} else {
157+
\delete_post_meta( $post_id, 'webmentions_disabled' );
158+
159+
}
160+
}
161+
}
162+
130163
/**
131164
* Register the Route.
132165
*/

includes/class-sender.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static function init() {
2525
// Send Webmentions from Every Type that Declared Webmention Support
2626
$post_types = get_post_types_by_support( 'webmentions' );
2727
foreach ( $post_types as $post_type ) {
28+
add_action( 'save_' . $post_type, array( static::class, 'save_hook' ), 3 );
2829
add_action( 'publish_' . $post_type, array( static::class, 'publish_hook' ), 3 );
2930
add_action( 'trashed_' . $post_type, array( static::class, 'trash_hook' ) );
3031
}
@@ -36,6 +37,41 @@ public static function init() {
3637

3738
// remote delete posts
3839
add_action( 'webmention_delete', array( static::class, 'send_webmentions' ) );
40+
\add_action( 'init', array( self::class, 'register_postmeta' ), 11 );
41+
}
42+
43+
/**
44+
* Register post meta
45+
*/
46+
public static function register_postmeta() {
47+
$post_types = \get_post_types_by_support( 'webmentions' );
48+
foreach ( $post_types as $post_type ) {
49+
\register_post_meta(
50+
$post_type,
51+
'webmentions_disabled_pings',
52+
array(
53+
'show_in_rest' => true,
54+
'single' => true,
55+
'type' => 'boolean',
56+
)
57+
);
58+
}
59+
}
60+
61+
/**
62+
* Saves optional settings on save
63+
*
64+
* @param int $post_id Post ID.
65+
*/
66+
public static function save_hook( $post_id ) {
67+
if ( array_key_exists( 'webmentions_disabled_pings', $_POST ) ) {
68+
if ( 1 === intval( $_POST['webmentions_disabled_pings'] ) ) {
69+
\add_post_meta( $post_id, 'webmentions_disabled_pings', '1', true );
70+
} else {
71+
\delete_post_meta( $post_id, 'webmentions_disabled_pings' );
72+
73+
}
74+
}
3975
}
4076

4177
/**
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php $post_id = get_the_ID(); ?>
2+
<fieldset><ul>
3+
<li>
4+
<input type="hidden" name="webmentions_disabled" value="0" />
5+
<input type="checkbox" class="widefat" name="webmentions_disabled" id="webmentions_disabled" value="1" <?php checked( 1, get_post_meta( $post_id, 'webmentions_disabled', 1 ) ); ?> />
6+
<label><?php esc_html_e( 'Disable Incoming', 'webmention' ); ?></label>
7+
<legend><sub><?php _e( 'Do Not Accept incoming Webmentions for this post', 'webmention' ); ?></sub></legend><li>
8+
<li>
9+
<input type="hidden" name="webmentions_disabled_pings" value="0" />
10+
<input type="checkbox" class="widefat" name="webmentions_disabled_pings" id="webmentions_disabled_pings" value="1" <?php checked( 1, intval( get_post_meta( $post_id, 'webmentions_disabled_pings', 1 ) ) ); ?> />
11+
<label><?php esc_html_e( 'Disable Outgoing', 'webmention' ); ?></label>
12+
<legend><sub><?php _e( 'Do Not send outgoing Webmentions for this post', 'webmention' ); ?></sub></legend></li>
13+
</fieldset>

0 commit comments

Comments
 (0)