Skip to content
Draft
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
4 changes: 4 additions & 0 deletions includes/class-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public function get_dom_document( $validate_content_type = true ) {
$body = mb_convert_encoding( $body, 'HTML-ENTITIES', mb_detect_encoding( $body ) );
}

if ( empty( $body ) ) {
return new WP_Error( 'empty_body', __( 'Request body has no data', 'webmention' ) );
}

$dom_document = new DOMDocument();
$dom_document->loadHTML( $body );

Expand Down
36 changes: 30 additions & 6 deletions includes/class-webmention.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ public function get_version() {
return WEBMENTION_VERSION;
}

/**
* Check if Webmentions should be disabled for the current environment.
*
* By default, Webmentions are disabled for 'local', 'development',
* and 'staging' environments.
*
* @return bool Whether Webmentions are disabled for the current environment.
*/
public static function is_disabled_for_environment() {
$environment_type = \wp_get_environment_type();
$disabled = \in_array( $environment_type, array( 'local', 'development', 'staging' ), true );

/**
* Filter whether Webmentions should be disabled for the current environment.
*
* @param bool $disabled Whether Webmentions are disabled.
* @param string $environment_type The current environment type.
*/
return \apply_filters( 'webmention_disable_for_environment', $disabled, $environment_type );
}

/**
* Register hooks.
*/
Expand All @@ -108,14 +129,17 @@ public function register_hooks() {
// load HTTP 410 support.
\add_action( 'init', array( HTTP_Gone::class, 'init' ) );

// initialize Webmention Sender.
\add_action( 'init', array( Sender::class, 'init' ) );
// Disable sending, receiving, and discovery for non-production environments.
if ( ! self::is_disabled_for_environment() ) {
// initialize Webmention Sender.
\add_action( 'init', array( Sender::class, 'init' ) );

// initialize Webmention Receiver.
\add_action( 'init', array( Receiver::class, 'init' ) );
// initialize Webmention Receiver.
\add_action( 'init', array( Receiver::class, 'init' ) );

// initialize Webmention Discovery.
\add_action( 'init', array( Discovery::class, 'init' ) );
// initialize Webmention Discovery.
\add_action( 'init', array( Discovery::class, 'init' ) );
}

if ( site_supports_blocks() ) {
// initialize Webmention Bloks.
Expand Down