Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public static function discussion_settings() {
}

/**
* Add Webmention meta boxes to the comment editor screen.
* Add Webmention meta boxes to the omment editor screen.
*
* @param object $object The comment object.
*/
public static function meta_boxes( $object ) {
public static function comment_metabox( $object ) {
wp_nonce_field( 'webmention_comment_metabox', 'webmention_comment_nonce' );

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

/**
* Add Webmention settings meta box to the Classic editor screen.
*
* @param object $object The comment object.
*/
public static function post_metabox( $object ) {
wp_nonce_field( 'webmention_post_metabox', 'webmention_post_nonce' );
load_template( __DIR__ . '/../templates/webmention-edit-post-form.php' );
}

/**
* Add comment-type as column in WP-Admin
*
Expand Down Expand Up @@ -162,11 +172,23 @@ public static function add_meta_boxes() {
add_meta_box(
'webmention-meta',
esc_html__( 'Webmention Data', 'webmention' ),
array( static::class, 'meta_boxes' ),
array( static::class, 'comment_metabox' ),
'comment',
'normal',
'default'
);
add_meta_box(
'webmention-meta',
esc_html__( 'Webmention Settings', 'webmention' ),
array( static::class, 'post_metabox' ),
get_option( 'webmention_support_post_types', array( 'post', 'page' ) ),
'side',
'default',
array(
'__block_editor_compatible_meta_box' => true,
'__back_compat_meta_box' => true, // This should only be used in the Classic Editor.
)
);
}

/**
Expand Down
28 changes: 0 additions & 28 deletions includes/class-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,6 @@ class Block {
public static function init() {
// Add editor plugin.
\add_action( 'enqueue_block_editor_assets', array( self::class, 'enqueue_editor_assets' ) );
\add_action( 'init', array( self::class, 'register_postmeta' ), 11 );
}

/**
* Register post meta
*/
public static function register_postmeta() {
$post_types = \get_post_types_by_support( 'webmentions' );
foreach ( $post_types as $post_type ) {
\register_post_meta(
$post_type,
'webmentions_disabled',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
)
);
\register_post_meta(
$post_type,
'webmentions_disabled_pings',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
)
);
}
}

/**
Expand Down
33 changes: 33 additions & 0 deletions includes/class-receiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,30 @@ public static function init() {
// Add scheduler for async processing
add_action( 'webmention_process_schedule', array( static::class, 'process' ) );

$post_types = get_post_types_by_support( 'webmentions' );
foreach ( $post_types as $post_type ) {
add_action( 'save_' . $post_type, array( static::class, 'save_hook' ), 3 );
}

self::register_meta();
}

/**
* This is more to lay out the data structure than anything else.
*/
public static function register_meta() {
$post_types = \get_post_types_by_support( 'webmentions' );
foreach ( $post_types as $post_type ) {
\register_post_meta(
$post_type,
'webmentions_disabled',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
)
);
}
$args = array(
'type' => 'string',
'description' => esc_html__( 'Protocol Used to Receive', 'webmention' ),
Expand Down Expand Up @@ -127,6 +144,22 @@ public static function register_meta() {
register_meta( 'comment', 'avatar', $args );
}

/**
* Saves optional settings on save
*
* @param int $post_id Post ID.
*/
public static function save_hook( $post_id ) {
if ( array_key_exists( 'webmentions_disabled', $_POST ) ) {
if ( 1 === intval( $_POST['webmentions_disabled'] ) ) {
\add_post_meta( $post_id, 'webmentions_disabled', '1', true );
} else {
\delete_post_meta( $post_id, 'webmentions_disabled' );

}
}
}

/**
* Register the Route.
*/
Expand Down
36 changes: 36 additions & 0 deletions includes/class-sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static function init() {
// Send Webmentions from Every Type that Declared Webmention Support
$post_types = get_post_types_by_support( 'webmentions' );
foreach ( $post_types as $post_type ) {
add_action( 'save_' . $post_type, array( static::class, 'save_hook' ), 3 );
add_action( 'publish_' . $post_type, array( static::class, 'publish_hook' ), 3 );
add_action( 'trashed_' . $post_type, array( static::class, 'trash_hook' ) );
}
Expand All @@ -36,6 +37,41 @@ public static function init() {

// remote delete posts
add_action( 'webmention_delete', array( static::class, 'send_webmentions' ) );
\add_action( 'init', array( self::class, 'register_postmeta' ), 11 );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\add_action( 'init', array( self::class, 'register_postmeta' ), 11 );
self::register_postmeta();

I think the init function is already triggered on init?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense. I moved the code there and wasn't thinking.

}

/**
* Register post meta
*/
public static function register_postmeta() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static function register_postmeta() {
public static function register_meta() {

The other function is called register_meta I think we should be consistent. I have no preference which one to use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, moved it around...fine with changing it.

$post_types = \get_post_types_by_support( 'webmentions' );
foreach ( $post_types as $post_type ) {
\register_post_meta(
$post_type,
'webmentions_disabled_pings',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
)
);
}
}

/**
* Saves optional settings on save
*
* @param int $post_id Post ID.
*/
public static function save_hook( $post_id ) {
if ( array_key_exists( 'webmentions_disabled_pings', $_POST ) ) {
if ( 1 === intval( $_POST['webmentions_disabled_pings'] ) ) {
\add_post_meta( $post_id, 'webmentions_disabled_pings', '1', true );
} else {
\delete_post_meta( $post_id, 'webmentions_disabled_pings' );

}
}
}

/**
Expand Down
13 changes: 13 additions & 0 deletions templates/webmention-edit-post-form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php $post_id = get_the_ID(); ?>
<fieldset><ul>
<li>
<input type="hidden" name="webmentions_disabled" value="0" />
<input type="checkbox" class="widefat" name="webmentions_disabled" id="webmentions_disabled" value="1" <?php checked( 1, get_post_meta( $post_id, 'webmentions_disabled', 1 ) ); ?> />
<label><?php esc_html_e( 'Disable Incoming', 'webmention' ); ?></label>
<legend><sub><?php _e( 'Do Not Accept incoming Webmentions for this post', 'webmention' ); ?></sub></legend><li>
<li>
<input type="hidden" name="webmentions_disabled_pings" value="0" />
<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 ) ) ); ?> />
<label><?php esc_html_e( 'Disable Outgoing', 'webmention' ); ?></label>
<legend><sub><?php _e( 'Do Not send outgoing Webmentions for this post', 'webmention' ); ?></sub></legend></li>
</fieldset>