$69 GRAYBYTE WORDPRESS FILE MANAGER $44

SERVER : premium134.web-hosting.com #1 SMP Thu Mar 13 14:29:12 UTC 2025
SERVER IP : 162.0.232.104 | ADMIN IP 216.73.216.80
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/home/raydofqv/techfabasia.com/wp-content/plugins/akismet/

HOME
Current File : /home/raydofqv/techfabasia.com/wp-content/plugins/akismet//class-akismet-connector.php
<?php
/**
 * Akismet Connector integration.
 *
 * @package Akismet
 */

declare( strict_types = 1 );

/**
 * Integrates Akismet with the WordPress Connectors framework,
 * handling API key validation and connection status reporting.
 */
class Akismet_Connector {

	/**
	 * Register hooks for the WordPress Connectors integration.
	 */
	public static function init() {
		add_action( 'wp_connectors_init', array( 'Akismet_Connector', 'register_connector' ) );

		// Priority 9 so we validate the real key before core's connector masking filter at priority 10.
		add_filter( 'rest_post_dispatch', array( 'Akismet_Connector', 'validate_api_key' ), 9, 3 );
		add_filter( 'script_module_data_options-connectors-wp-admin', array( 'Akismet_Connector', 'set_connected_status' ), 11 );

		// Invalidate the connector key status cache on any key change.
		foreach ( array( 'add', 'update', 'delete' ) as $action ) {
			add_action( "{$action}_option_wordpress_api_key", array( 'Akismet_Connector', 'invalidate_key_status_cache' ) );
		}
	}

	/**
	 * Validate the Akismet API key when saved via the connectors REST settings endpoint.
	 * If the key is invalid, revert it to an empty string.
	 *
	 * @param WP_REST_Response $response The response object.
	 * @param WP_REST_Server   $server   The server instance.
	 * @param WP_REST_Request  $request  The request object.
	 * @return WP_REST_Response
	 */
	public static function validate_api_key( $response, $server, $request ) {
		if ( '/wp/v2/settings' !== $request->get_route() ) {
			return $response;
		}

		if ( 'POST' !== $request->get_method() && 'PUT' !== $request->get_method() ) {
			return $response;
		}

		$data = $response->get_data();
		if ( ! is_array( $data ) || ! array_key_exists( 'wordpress_api_key', $data ) ) {
			return $response;
		}

		$key = $data['wordpress_api_key'];
		if ( ! is_string( $key ) || '' === $key ) {
			return $response;
		}

		if ( Akismet::KEY_STATUS_INVALID === Akismet::verify_key( $key ) ) {
			update_option( 'wordpress_api_key', '' );
			$data['wordpress_api_key'] = '';
			$response->set_data( $data );
		}

		return $response;
	}

	/**
	 * Set the isConnected status for the Akismet connector based on actual key validity.
	 *
	 * @param array $data Script module data.
	 * @return array
	 */
	public static function set_connected_status( $data ) {
		if ( ! isset( $data['connectors']['akismet']['authentication'] ) ) {
			return $data;
		}

		$key = Akismet::get_api_key();

		if ( empty( $key ) ) {
			$data['connectors']['akismet']['authentication']['isConnected'] = false;
			return $data;
		}

		$is_connected = get_transient( 'akismet_connector_key_status' );

		if ( false === $is_connected ) {
			$is_connected = Akismet::verify_key( $key );

			// Don't cache failures (e.g. network timeouts) so we retry on the next page load.
			if ( Akismet::KEY_STATUS_FAILED !== $is_connected ) {
				set_transient( 'akismet_connector_key_status', $is_connected, DAY_IN_SECONDS );
			}
		}

		$data['connectors']['akismet']['authentication']['isConnected'] = ( Akismet::KEY_STATUS_VALID === $is_connected );

		return $data;
	}

	/**
	 * Clear the connector key status cache so it doesn't serve stale data.
	 */
	public static function invalidate_key_status_cache() {
		delete_transient( 'akismet_connector_key_status' );
	}

	/**
	 * Register the Akismet connector with an is_active callback so the
	 * connectors page can detect Akismet as active when installed as a mu-plugin.
	 *
	 * We re-register the full connector rather than patching the core one
	 * so that Akismet still has a connector even if core removes its own.
	 *
	 * @see https://github.com/WordPress/gutenberg/pull/76994
	 *
	 * @param WP_Connector_Registry $registry Connector registry instance.
	 */
	public static function register_connector( $registry ) {
		if ( method_exists( $registry, 'is_registered' ) && $registry->is_registered( 'akismet' ) ) {
			$registry->unregister( 'akismet' );
		}

		$registry->register(
			'akismet',
			array(
				'name'           => __( 'Akismet Anti-spam', 'akismet' ),
				'description'    => __( 'Protect your site from spam.', 'akismet' ),
				'type'           => 'spam_filtering',
				'plugin'         => array(
					'file'      => 'akismet/akismet.php',
					'is_active' => function () {
						return defined( 'AKISMET_VERSION' );
					},
				),
				'authentication' => array(
					'method'          => 'api_key',
					'credentials_url' => 'https://akismet.com/get/',
					'setting_name'    => 'wordpress_api_key',
					'constant_name'   => 'WPCOM_API_KEY',
				),
			)
		);
	}
}

Current_dir [ WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
2 May 2026 2.40 PM
raydofqv / raydofqv
0755
_inc
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
abilities
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
views
--
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0755
.htaccess
0.124 KB
29 Apr 2026 5.43 AM
raydofqv / raydofqv
0444
LICENSE.txt
17.668 KB
24 Aug 2015 7.32 AM
raydofqv / raydofqv
0644
akismet.php
3.307 KB
24 Apr 2026 2.34 AM
raydofqv / raydofqv
0644
changelog.txt
22.831 KB
21 Apr 2025 3.07 AM
raydofqv / raydofqv
0644
class-akismet-abilities.php
2.048 KB
6 Apr 2026 8.47 PM
raydofqv / raydofqv
0644
class-akismet-compatible-plugins.php
7.834 KB
19 Aug 2025 2.58 AM
raydofqv / raydofqv
0644
class-akismet-connector.php
4.473 KB
21 Apr 2026 8.24 AM
raydofqv / raydofqv
0644
class.akismet-admin.php
64.399 KB
22 Apr 2026 6.19 AM
raydofqv / raydofqv
0644
class.akismet-cli.php
4.892 KB
6 Nov 2024 6.49 AM
raydofqv / raydofqv
0644
class.akismet-rest-api.php
20.075 KB
23 Mar 2026 5.52 AM
raydofqv / raydofqv
0644
class.akismet-widget.php
4.389 KB
30 Oct 2025 3.01 AM
raydofqv / raydofqv
0644
class.akismet.php
87.361 KB
21 Apr 2026 7.04 AM
raydofqv / raydofqv
0644
index.php
0.057 KB
9 Apr 2025 3.40 AM
raydofqv / raydofqv
0644
readme.txt
6.521 KB
24 Apr 2026 2.34 AM
raydofqv / raydofqv
0644
wrapper.php
6.283 KB
6 Nov 2024 6.49 AM
raydofqv / raydofqv
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF Static GIF