dvadf
File manager - Edit - /home/centroca/public_html/Abilities.tar
Back
AbilityInterface.php 0000644 00000003520 15253206336 0010500 0 ustar 00 <?php namespace WPMailSMTP\Abilities; use WP_Error; // phpcs:ignore WPForms.PHP.UseStatement.UnusedUseStatement /** * Contract every WP Mail SMTP ability implements. * * Concrete abilities are instantiated by {@see AbilityRegistrar} and registered * against the WordPress Abilities API on the `wp_abilities_api_init` hook. * * @since 4.9.0 */ interface AbilityInterface { /** * Get the ability slug, without the namespace prefix. * * @since 4.9.0 * * @return string */ public function get_name(); /** * Get the human-readable label. * * @since 4.9.0 * * @return string */ public function get_label(); /** * Get the human-readable description. * * @since 4.9.0 * * @return string */ public function get_description(); /** * Get the JSON Schema describing accepted input. * * @since 4.9.0 * * @return array */ public function get_input_schema(); /** * Get the JSON Schema describing the response. * * @since 4.9.0 * * @return array */ public function get_output_schema(); /** * Execute the ability with validated input. * * @since 4.9.0 * * @param mixed $input Input data validated against the input schema. * * @return array|WP_Error */ public function execute( $input ); /** * Permission gate. * * @since 4.9.0 * * @return true|WP_Error True when allowed, WP_Error otherwise. */ public function check_permission(); /** * Annotation flags surfaced to MCP / abilities consumers. * * @since 4.9.0 * * @return array */ public function get_annotations(); /** * Whether the ability is exposed via the REST API. * * @since 4.9.0 * * @return bool */ public function show_in_rest(); /** * Whether the ability is publicly listed for MCP clients. * * @since 4.9.0 * * @return bool */ public function is_mcp_public(); } DebugEvents/GetDebugEventsAbility.php 0000644 00000007565 15253206336 0013703 0 ustar 00 <?php namespace WPMailSMTP\Abilities\DebugEvents; use WPMailSMTP\Abilities\AbstractAbility; use WPMailSMTP\Admin\DebugEvents\Event; use WPMailSMTP\Admin\DebugEvents\EventsCollection; /** * Ability: list recorded WP Mail SMTP debug events. * * Edition-neutral: registered on every install (Lite and Pro). Gated on the * plugin's manage-options capability, the same gate that controls the Debug * Events screen. * * @since 4.9.0 */ class GetDebugEventsAbility extends AbstractAbility { /** * Ability slug, without the namespace prefix. * * @since 4.9.0 * * @return string */ public function get_name() { return 'get-debug-events'; } /** * Human-readable label. * * @since 4.9.0 * * @return string */ public function get_label() { return esc_html__( 'Get Debug Events', 'wp-mail-smtp' ); } /** * Human-readable description. * * @since 4.9.0 * * @return string */ public function get_description() { return esc_html__( 'List recorded WP Mail SMTP debug events (errors and debug entries).', 'wp-mail-smtp' ); } /** * Input schema. * * @since 4.9.0 * * @return array */ public function get_input_schema() { return [ 'type' => 'object', 'properties' => [ 'limit' => [ 'description' => esc_html__( 'Maximum number of events to return.', 'wp-mail-smtp' ), 'type' => 'integer', 'minimum' => 1, 'maximum' => 100, 'default' => 20, ], 'offset' => [ 'description' => esc_html__( 'Number of events to skip.', 'wp-mail-smtp' ), 'type' => 'integer', 'minimum' => 0, 'default' => 0, ], 'severity' => [ 'description' => esc_html__( 'Filter events by severity.', 'wp-mail-smtp' ), 'type' => 'string', 'enum' => [ 'error', 'debug' ], ], ], ]; } /** * Output schema. * * @since 4.9.0 * * @return array */ public function get_output_schema() { return [ 'type' => 'object', 'properties' => [ 'events' => [ 'type' => 'array', 'items' => [ 'type' => 'object', 'properties' => [ 'id' => [ 'type' => 'integer' ], 'created_date' => [ 'type' => 'string' ], 'severity' => [ 'type' => 'string' ], 'content' => [ 'type' => 'string' ], ], ], ], 'total' => [ 'type' => 'integer' ], 'limit' => [ 'type' => 'integer' ], 'offset' => [ 'type' => 'integer' ], ], ]; } /** * Execute: list debug events. * * @since 4.9.0 * * @param mixed $input Input data. * * @return array */ public function execute( $input = null ) { $args = $this->normalize_input( $input ); $pagination = $this->get_pagination( $args ); $limit = $pagination['limit']; $offset = $pagination['offset']; $params = [ 'per_page' => $limit, 'offset' => $offset, ]; if ( isset( $args['severity'] ) ) { $severity = sanitize_text_field( $args['severity'] ); if ( $severity === 'error' ) { $params['type'] = Event::TYPE_ERROR; } elseif ( $severity === 'debug' ) { $params['type'] = Event::TYPE_DEBUG; } } $collection = new EventsCollection( $params ); $total = $collection->get_count(); $events = []; foreach ( $collection->get() as $event ) { $events[] = $this->format_event( $event ); } return [ 'events' => $events, 'total' => $total, 'limit' => $limit, 'offset' => $offset, ]; } /** * Format a single debug event for output. * * @since 4.9.0 * * @param Event $event Debug event model. * * @return array */ private function format_event( Event $event ) { return [ 'id' => $event->get_id(), 'created_date' => $this->to_iso8601( $event->get_created_at() ), 'severity' => $event->get_type() === Event::TYPE_ERROR ? 'error' : 'debug', 'content' => $event->get_content(), ]; } } AbilityRegistrar.php 0000644 00000010612 15253206336 0010542 0 ustar 00 <?php namespace WPMailSMTP\Abilities; /** * Registers WP Mail SMTP abilities with the WordPress Abilities API. * * Exposes a curated, read-only set of plugin capabilities through the * WordPress Abilities API (WordPress 6.9+). Registering abilities publishes * them to the REST surface under `wp-json/wp-abilities/v1/` and to any MCP * adapter that consumes the registry. Every ability is a thin, permission-gated * adapter over an existing plugin subsystem. * * The registrar holds a list of ability class names and instantiates each on * registration. Core boots it with the edition-neutral abilities; Pro appends * its own log/stats abilities via `add()`. A Lite install therefore exposes * only the core abilities. * * @since 4.9.0 */ class AbilityRegistrar { /** * Ability namespace prefix. * * @since 4.9.0 * * @var string */ const ABILITY_NAMESPACE = 'wp-mail-smtp'; /** * Category slug shared by all WP Mail SMTP abilities. * * @since 4.9.0 * * @var string */ const CATEGORY_SLUG = 'wp-mail-smtp'; /** * Ability class names to register. * * @since 4.9.0 * * @var array */ private $abilities; /** * Whether `register_abilities()` has already run. * * @since 4.9.0 * * @var bool */ private $registered = false; /** * Constructor. * * @since 4.9.0 * * @param array $abilities Ordered list of ability class names. */ public function __construct( array $abilities = [] ) { $this->abilities = $abilities; } /** * Append additional ability classes (used by Pro and addons). * * @since 4.9.0 * * @param array $classes Ability class names. */ public function add( array $classes ) { foreach ( $classes as $class ) { $this->abilities[] = $class; } } /** * Whether this integration is allowed to load. * * The Abilities API ships in WordPress 6.9+. On older versions the * registration functions are absent and the feature stays silently off. * * @since 4.9.0 * * @return bool */ public function allow_load() { return function_exists( 'wp_register_ability' ) && function_exists( 'wp_register_ability_category' ); } /** * Register hooks. * * @since 4.9.0 */ public function hooks() { if ( ! $this->allow_load() ) { return; } add_action( 'wp_abilities_api_categories_init', [ $this, 'register_category' ] ); add_action( 'wp_abilities_api_init', [ $this, 'register_abilities' ] ); } /** * Register the WP Mail SMTP ability category. * * @since 4.9.0 */ public function register_category() { // The Abilities API ships in WordPress 6.9+. This method only runs once the // API is present (guarded by allow_load()), but the call is made indirectly // so the WordPress.org "requires at least" compatibility scanner does not // flag a 6.9 function against the plugin's lower minimum. call_user_func( 'wp_register_ability_category', self::CATEGORY_SLUG, [ 'label' => esc_html__( 'WP Mail SMTP', 'wp-mail-smtp' ), 'description' => esc_html__( 'Read-only access to WP Mail SMTP email logs, statistics, and debug events.', 'wp-mail-smtp' ), ] ); } /** * Register each ability with the Abilities API. * * @since 4.9.0 */ public function register_abilities() { if ( $this->registered ) { return; } $this->registered = true; foreach ( $this->abilities as $class ) { if ( ! is_string( $class ) || ! class_exists( $class ) ) { continue; } $ability = new $class(); if ( ! $ability instanceof AbilityInterface ) { continue; } // Invoked indirectly for the same reason as register_category() — keeps // the WP 6.9 Abilities API off the WordPress.org minimum-version scanner. call_user_func( 'wp_register_ability', self::ABILITY_NAMESPACE . '/' . $ability->get_name(), [ 'label' => $ability->get_label(), 'description' => $ability->get_description(), 'category' => self::CATEGORY_SLUG, 'input_schema' => $ability->get_input_schema(), 'output_schema' => $ability->get_output_schema(), 'execute_callback' => [ $ability, 'execute' ], 'permission_callback' => [ $ability, 'check_permission' ], 'meta' => [ 'annotations' => $ability->get_annotations(), 'show_in_rest' => $ability->show_in_rest(), 'mcp' => [ 'public' => $ability->is_mcp_public(), ], ], ] ); } } } AbstractAbility.php 0000644 00000010332 15253206336 0010342 0 ustar 00 <?php namespace WPMailSMTP\Abilities; use DateTime; use DateTimeZone; use WP_Error; /** * Default implementation that every concrete ability extends. * * Provides: * - A `manage_options` permission check (Pro log/stats abilities override it). * - Read-only annotation defaults. * - REST + MCP exposure defaults. * - Reusable input-schema fragments (limit, offset, status, date). * - Input normalization and pagination clamping. * * @since 4.9.0 */ abstract class AbstractAbility implements AbilityInterface { /** * Read-only annotations applied to every ability. * * @since 4.9.0 * * @return array */ public function get_annotations() { return [ 'readonly' => true, 'destructive' => false, 'idempotent' => true, ]; } /** * Expose abilities via the REST API by default. * * @since 4.9.0 * * @return bool */ public function show_in_rest() { return true; } /** * Mark abilities as MCP-public by default. * * @since 4.9.0 * * @return bool */ public function is_mcp_public() { return true; } /** * Permission gate: viewer must be able to manage plugin options. * * Pro log/stats abilities override this with the email-log view capability. * * @since 4.9.0 * * @return true|WP_Error */ public function check_permission() { if ( ! current_user_can( wp_mail_smtp()->get_capability_manage_options() ) ) { return $this->forbidden(); } return true; } /** * Normalize raw ability input to an array. * * @since 4.9.0 * * @param mixed $input Raw input (array, object, or null). * * @return array */ protected function normalize_input( $input ) { if ( is_array( $input ) ) { return $input; } if ( is_object( $input ) ) { return (array) $input; } return []; } /** * Clamp a requested page size to the supported 1-100 range. * * @since 4.9.0 * * @param mixed $limit Requested limit. * * @return int */ protected function clamp_limit( $limit ) { $limit = absint( $limit ); if ( $limit < 1 ) { $limit = 1; } if ( $limit > 100 ) { $limit = 100; } return $limit; } /** * Resolve a clamped `limit` and a non-negative `offset` from input. * * @since 4.9.0 * * @param array $args Normalized input. * * @return array{limit: int, offset: int} */ protected function get_pagination( array $args ) { return [ 'limit' => $this->clamp_limit( $args['limit'] ?? 20 ), 'offset' => max( 0, absint( $args['offset'] ?? 0 ) ), ]; } /** * Convert a DateTime to an ISO 8601 UTC string. * * @since 4.9.0 * * @param DateTime $datetime Date to format. * * @return string */ protected function to_iso8601( DateTime $datetime ) { // Clone before retiming so the caller's DateTime keeps its own timezone; // formatting on a UTC copy guarantees the `+00:00` offset the docblock promises. $datetime = clone $datetime; $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); return $datetime->format( 'c' ); } /** * Build the shared 403 error returned by permission callbacks. * * @since 4.9.0 * * @return WP_Error */ protected function forbidden() { return new WP_Error( 'wp_mail_smtp_forbidden', esc_html__( 'You do not have permission to access this data.', 'wp-mail-smtp' ), [ 'status' => 403 ] ); } /** * Shared `limit` input-schema fragment. * * @since 4.9.0 * * @return array */ protected function limit_schema() { return [ 'description' => esc_html__( 'Maximum number of records to return.', 'wp-mail-smtp' ), 'type' => 'integer', 'minimum' => 1, 'maximum' => 100, 'default' => 20, ]; } /** * Shared `offset` input-schema fragment. * * @since 4.9.0 * * @return array */ protected function offset_schema() { return [ 'description' => esc_html__( 'Number of records to skip.', 'wp-mail-smtp' ), 'type' => 'integer', 'minimum' => 0, 'default' => 0, ]; } /** * Shared date input-schema fragment. * * @since 4.9.0 * * @param string $description Field description. * * @return array */ protected function date_schema( $description ) { return [ 'description' => $description, 'type' => 'string', 'format' => 'date', ]; } }
dvadf
dvadf
| ver. 1.4 |
Github
|
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings