Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2e295de
Remove dependence on pings_open for whether a webmention was open.
dshanske Jul 22, 2024
525549c
Switch from using the ping list in the post to a separate list that o…
dshanske Jul 22, 2024
cff074e
Remove ping usage from sender
dshanske Jul 22, 2024
1b24c81
Merge branch 'main' into webmentionopen
pfefferle Jul 22, 2024
c3da954
Restore update punged
dshanske Aug 24, 2024
25bbcee
Merge branch 'main' into webmentionopen
dshanske Aug 24, 2024
3da5d65
Merge branch 'main' into webmentionopen
pfefferle Sep 13, 2024
ab67e07
Merge branch 'main' into webmentionopen
pfefferle Sep 14, 2024
0681b06
Simplify webmentions_open and add better comment
dshanske Nov 14, 2024
f140c1a
remove the "webmentions_closed" meta value if the post is updated
pfefferle Nov 14, 2024
9d5522c
add block-editor settings to disable webmentions
pfefferle Nov 14, 2024
18c89ce
Merge branch 'main' into webmentionopen
pfefferle Nov 14, 2024
d743ab0
fix phpcs
pfefferle Nov 14, 2024
e08d739
check if site supports blocks before loading them
pfefferle Nov 14, 2024
e0d7cfd
Merge branch 'main' into webmentionopen
dshanske Nov 17, 2024
8b11396
re-add block-editor dependencies
pfefferle Nov 17, 2024
3b26a5e
Merge branch 'main' into webmentionopen
pfefferle Nov 25, 2024
ed657c6
small change
pfefferle Dec 8, 2024
43ecf97
phpunit
pfefferle Dec 13, 2024
21a469c
Merge branch 'main' into webmentionopen
pfefferle Feb 23, 2025
b46e514
fix test
pfefferle Feb 23, 2025
9f2106e
fix tests
pfefferle Feb 23, 2025
b0d1085
change name
pfefferle Feb 23, 2025
a888261
use simpler name
pfefferle Feb 23, 2025
ef3e59e
update name
pfefferle Feb 23, 2025
84abba8
clear _mentionme after sending the mentions
pfefferle Feb 23, 2025
858506d
revert
pfefferle Feb 23, 2025
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
2 changes: 1 addition & 1 deletion includes/class-avatar-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static function store_avatar( $comment_id ) {
if ( empty( $author ) ) {
return false;
}
$host = webmention_extract_domain( get_url_from_webmention( $comment ) );
$host = webmention_extract_domain( get_url_from_webmention( $comment ) );
$avatar_url = self::sideload_avatar( $avatar, $host, $author );

if ( $avatar_url ) {
Expand Down
44 changes: 21 additions & 23 deletions includes/class-sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,15 @@ public static function send_webmentions( $post_id ) {
$urls = webmention_extract_urls( $post->post_content, $support_media_urls );

// filter links
$targets = apply_filters( 'webmention_links', $urls, $post_id );
$targets = array_unique( $targets );
$pung = get_pung( $post );
$targets = apply_filters( 'webmention_links', $urls, $post_id );
$targets = array_unique( $targets );
$mentioned = get_post_meta( $post->ID, 'webmention_last_mentioned_urls', true );
$mentioned = empty( $mentioned ) ? array() : $mentioned;

// Find previously sent Webmentions and send them one last time.
$deletes = array_diff( $pung, $targets );
$deletes = array_diff( $mentioned, $targets );

$ping = array();
$mentions = array();

foreach ( $targets as $target ) {
// send Webmention
Expand All @@ -225,16 +226,13 @@ public static function send_webmentions( $post_id ) {
continue;
}

// check response
if (
! is_wp_error( $response ) &&
wp_remote_retrieve_response_code( $response ) < 400
) {
$ping[] = $target;
}
$code = wp_remote_retrieve_response_code( $response );

// reschedule if server responds with a http error 5xx
if ( wp_remote_retrieve_response_code( $response ) >= 500 ) {
// check response
if ( ! is_wp_error( $response ) && $code < 400 ) {
$mentions[] = $target;
} elseif ( $code >= 500 ) {
// reschedule if server responds with a http error 5xx
self::reschedule( $post_id );
}
}
Expand All @@ -246,23 +244,23 @@ public static function send_webmentions( $post_id ) {
// reschedule if server responds with a http error 5xx
if ( wp_remote_retrieve_response_code( $response ) >= 500 ) {
self::reschedule( $post_id );
$ping[] = $deleted;
$mentions[] = $deleted;
}
}

if ( ! empty( $mentions ) ) {
update_post_meta( $post_id, 'webmention_last_mentioned_urls', $mentions );
}

$pung = get_pung( $post );

if ( ! empty( $ping ) ) {
self::update_ping( $post, $ping );
self::update_ping( $post, array_merge( $pung, $ping ) );
}

return $ping;
return $mentions;
}

/*
* Update the Pinged List as Opposed to Adding to It.
*
* @param int|WP_Post $post_id Post.
* @param array $pinged Array of URLs
*/
public static function update_ping( $post_id, $pinged ) {
global $wpdb;
$post = get_post( $post_id );
Expand Down
53 changes: 16 additions & 37 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,18 +550,23 @@ function ifset( &$var, $return = false ) { // phpcs:ignore Universal.NamingConve
* @return boolean if webmentions are open
*/
function webmentions_open( $post = null ) {
$_post = get_post( $post );
$post_id = $_post ? $_post->ID : 0;

// If the post type does not support Webmentions do not even check further
if ( ! post_type_supports( get_post_type( $post_id ), 'webmentions' ) ) {
return false;
$post = get_post( $post );
$post_id = $post ? $post->ID : 0;
$open = false;
if ( $post ) {
// Always consider the home mention link page to be open.
if ( get_option( 'webmention_home_mentions' ) === $post->ID ) {
$open = true;
} elseif ( ! post_type_supports( get_post_type( $post ), 'webmentions' ) ) {
// If the post type does not support Webmentions do not even check further.
$open = false;
} else {
// If the webmentions_closed meta ID has a value then consider webmentions to be open.
$open = get_post_meta( $post->ID, 'webmentions_closed', true );
$open = empty( $open ) ? true : false;
}
}

if ( get_option( 'webmention_home_mentions' ) === $post_id ) {
return true;
}
$open = ( $_post && ( pings_open( $post ) ) );
/**
* Filters whether the current post is open for webmentions.
*
Expand All @@ -572,23 +577,6 @@ function webmentions_open( $post = null ) {
return apply_filters( 'webmentions_open', $open, $post_id );
}

/**
* Return enabled status of Homepage Webmentions.
*
* @since 3.8.9
*
* @param bool $open Whether the current post is open for pings.
* @param int $post_id The post ID.
* @return boolean if pings are open
*/
function webmention_pings_open( $open, $post_id ) {
if ( get_option( 'webmention_home_mentions' ) === $post_id ) {
return true;
}

return $open;
}

/**
* Retrieve the default comment status for a given post type.
*
Expand All @@ -602,16 +590,7 @@ function webmention_pings_open( $open, $post_id ) {
* @return string
*/
function webmention_get_default_comment_status( $status, $post_type, $comment_type ) {
if ( 'webmention' === $comment_type ) {
return post_type_supports( $post_type, 'webmentions' ) ? 'open' : 'closed';
}

// Since support for the pingback comment type is used to keep pings open...
if ( ( 'pingback' === $comment_type ) ) {
return ( post_type_supports( $post_type, 'webmentions' ) ? 'open' : $status );
}

return $status;
return is_registered_webmention_comment_type( $comment_type ) ? 'open' : $status;
}

/**
Expand Down
1 change: 0 additions & 1 deletion webmention.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ function init() {

// Default Comment Status.
add_filter( 'get_default_comment_status', 'webmention_get_default_comment_status', 11, 3 );
add_filter( 'pings_open', 'webmention_pings_open', 10, 2 );

// Load language files.
load_plugin_textdomain( 'webmention', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
Expand Down
Loading