文件操作 - class-connectors.php
返回文件管理
返回主菜单
删除本文件
文件: /storage/v12552/i2kdefense/public_html/wp-content/plugins/stream/classes/class-connectors.php
编辑文件内容
<?php /** * Validates and loads core connectors, integrated connectors, and * connectors registered using the "wp_stream_connectors" hook. * * @package WP_Stream */ namespace WP_Stream; /** * Class - Connectors */ class Connectors { /** * Holds instance of plugin object * * @var Plugin */ public $plugin; /** * Registered connectors. * * @var array */ public $connectors = array(); /** * Contexts registered to Connectors * * @var array */ public $contexts = array(); /** * Action taxonomy terms * * Holds slug to localized label association * * @var array */ public $term_labels = array( 'stream_connector' => array(), 'stream_context' => array(), 'stream_action' => array(), ); /** * Admin notice messages * * @var array */ protected $admin_notices = array(); /** * Class constructor. * * @param Plugin $plugin Instance of plugin object. */ public function __construct( $plugin ) { $this->plugin = $plugin; $this->load_connectors(); } /** * Load built-in connectors */ public function load_connectors() { $connectors = array( /** * Core Connectors */ 'blogs', 'comments', 'editor', 'installer', 'media', 'menus', 'posts', 'settings', 'taxonomies', 'users', 'widgets', /** * Integrated Connectors */ 'acf', 'bbpress', 'buddypress', 'edd', 'gravityforms', 'jetpack', 'mercator', 'two-factor', 'user-switching', 'woocommerce', 'wordpress-seo', ); // Get excluded connectors. $excluded_connectors = array(); $classes = array(); foreach ( $connectors as $connector ) { // Load connector class file. include_once $this->plugin->locations['dir'] . '/connectors/class-connector-' . $connector . '.php'; // Set fully qualified class name. $class_name = sprintf( '\WP_Stream\Connector_%s', str_replace( '-', '_', $connector ) ); // Bail if no class loaded. if ( ! class_exists( $class_name ) ) { continue; } // Initialize connector. $class = new $class_name(); $classes[ $class->name ] = $class; } /** * Allows for adding additional connectors via classes that extend Connector. * * @param array $classes An array of Connector objects. */ $connector_classes = apply_filters( 'wp_stream_connectors', $classes ); foreach ( $connector_classes as $connector ) { // Check if the connector class extends WP_Stream\Connector. if ( ! is_subclass_of( $connector, 'WP_Stream\Connector' ) ) { continue; } // Check if the connector events are allowed to be registered in the WP Admin. if ( is_admin() && ! $connector->register_admin ) { continue; } // Check if the connector events are allowed to be registered in the WP Frontend. if ( ! is_admin() && ! $connector->register_frontend ) { continue; } // Run any final validations the connector may have before used. if ( ! $connector->is_dependency_satisfied() ) { continue; } // Register error for invalid any connector class. if ( ! method_exists( $connector, 'get_label' ) ) { /* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */ $this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the get_label method.', 'stream' ), $connector->name, 'Connector' ), true ); continue; } if ( ! method_exists( $connector, 'register' ) ) { /* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */ $this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the register method.', 'stream' ), $connector->name, 'Connector' ), true ); continue; } if ( ! method_exists( $connector, 'get_context_labels' ) ) { /* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */ $this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the get_context_labels method.', 'stream' ), $connector->name, 'Connector' ), true ); continue; } if ( ! method_exists( $connector, 'get_action_labels' ) ) { /* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */ $this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the get_action_labels method.', 'stream' ), $connector->name, 'Connector' ), true ); continue; } /** * Allows excluded connectors to be overridden and registered. * * @param bool $is_excluded True if excluded, otherwise false. * @param string $connector The current connector's slug. * @param array $excluded_connectors An array of all excluded connector slugs. */ $is_excluded_connector = apply_filters( 'wp_stream_check_connector_is_excluded', in_array( $connector->name, $excluded_connectors, true ), $connector->name, $excluded_connectors ); if ( $is_excluded_connector ) { continue; } // Add connector to the registry. $this->connectors[ $connector->name ] = $connector; // Register the connector. $connector->register(); // Link context labels to their connector. $this->contexts[ $connector->name ] = $connector->get_context_labels(); // Store connector label. $this->term_labels['stream_connector'][ $connector->name ] = $connector->get_label(); // Add new terms to our label lookup array. $this->term_labels['stream_action'] = array_merge( $this->term_labels['stream_action'], $connector->get_action_labels() ); $this->term_labels['stream_context'] = array_merge( $this->term_labels['stream_context'], $connector->get_context_labels() ); } $labels = $this->term_labels['stream_connector']; /** * Fires after all connectors have been registered. * * @param array $labels All register connectors labels array * @param Connectors $connector_classes The Connectors object */ do_action( 'wp_stream_after_connectors_registration', $labels, $this ); } /** * Return the slugs of all registered connectors. * * @return string[] */ public function get_slugs() { return array_keys( (array) $this->connectors ); } /** * Return a normalized list of all registered connectors and their * context/action labels. * * @return array<int, array{slug:string,label:string,contexts:array<string,string>,actions:array<string,string>}> */ public function get_all() { $out = array(); foreach ( (array) $this->connectors as $slug => $connector ) { $out[] = array( 'slug' => (string) $slug, 'label' => method_exists( $connector, 'get_label' ) ? (string) $connector->get_label() : (string) $slug, 'contexts' => method_exists( $connector, 'get_context_labels' ) ? (array) $connector->get_context_labels() : array(), 'actions' => method_exists( $connector, 'get_action_labels' ) ? (array) $connector->get_action_labels() : array(), ); } return $out; } /** * Return metadata for every Stream connector, including ones that * load_connectors() skipped because their `register_frontend` is false * and the current request isn't wp-admin (REST is `! is_admin()`, so * connectors like "settings", "editor", "menus" are otherwise invisible * to abilities). Walks the connector class list once and asks each * instance for its identity, never calling register() — so no hooks * fire and the live $this->connectors registry stays exactly as * load_connectors() built it. * * Intended for the abilities layer (stream/get-connectors, * stream/create-exclusion-rule validation) where the answer should * reflect "what connectors exist on this site" rather than "what * connectors loaded their hooks for this specific request". * * @return array<int, array{slug:string,label:string,contexts:array<string,string>,actions:array<string,string>}> */ public function get_all_including_admin_only() { $out = array(); foreach ( $this->build_full_connector_classes() as $connector ) { $out[] = array( 'slug' => (string) $connector->name, 'label' => method_exists( $connector, 'get_label' ) ? (string) $connector->get_label() : (string) $connector->name, 'contexts' => method_exists( $connector, 'get_context_labels' ) ? (array) $connector->get_context_labels() : array(), 'actions' => method_exists( $connector, 'get_action_labels' ) ? (array) $connector->get_action_labels() : array(), ); } /** * Filter the connector list surfaced to the Abilities API. * * Mirrors `wp_stream_connectors` for the abilities-facing list so * third parties can add/remove entries shown to REST/MCP callers * without affecting which connectors actually register hooks. * * @param array $out Connector metadata entries. */ return apply_filters( 'wp_stream_abilities_connectors', $out ); } /** * Return slugs of every Stream connector, including admin-only ones. * Companion to get_all_including_admin_only(); used by abilities that * need to validate an incoming connector slug (e.g. stream/create- * exclusion-rule) against the full site-wide list rather than the * request-context-gated $this->connectors registry. * * @return string[] */ public function get_all_slugs_including_admin_only() { $slugs = array(); foreach ( $this->build_full_connector_classes() as $connector ) { $slugs[] = (string) $connector->name; } return $slugs; } /** * Instantiate every built-in and integrated connector class and return * the ones whose dependencies are satisfied, regardless of the * `register_admin` / `register_frontend` gates that load_connectors() * applies. Helper for the metadata-only accessors above; does not * register hooks and does not mutate $this->connectors. * * @return Connector[] */ protected function build_full_connector_classes() { // Same canonical slug list load_connectors() uses. Keep in sync. $connectors = array( // Core Connectors. 'blogs', 'comments', 'editor', 'installer', 'media', 'menus', 'posts', 'settings', 'taxonomies', 'users', 'widgets', // Integrated Connectors. 'acf', 'bbpress', 'buddypress', 'edd', 'gravityforms', 'jetpack', 'mercator', 'two-factor', 'user-switching', 'woocommerce', 'wordpress-seo', ); $classes = array(); foreach ( $connectors as $connector ) { include_once $this->plugin->locations['dir'] . '/connectors/class-connector-' . $connector . '.php'; $class_name = sprintf( '\WP_Stream\Connector_%s', str_replace( '-', '_', $connector ) ); if ( ! class_exists( $class_name ) ) { continue; } $class = new $class_name(); $classes[ $class->name ] = $class; } /** This filter is documented in classes/class-connectors.php */ $connector_classes = apply_filters( 'wp_stream_connectors', $classes ); $out = array(); foreach ( $connector_classes as $connector ) { if ( ! is_subclass_of( $connector, 'WP_Stream\Connector' ) ) { continue; } if ( ! $connector->is_dependency_satisfied() ) { continue; } if ( ! method_exists( $connector, 'get_label' ) || ! method_exists( $connector, 'get_context_labels' ) || ! method_exists( $connector, 'get_action_labels' ) ) { continue; } $out[] = $connector; } return $out; } /** * Unregisters the context hooks for all connectors. */ public function unload_connectors() { foreach ( $this->connectors as $connector ) { $connector->unregister(); } } /** * Reregisters the context hooks for all connectors. */ public function reload_connectors() { foreach ( $this->connectors as $connector ) { $connector->register(); } } /** * Unregisters the context hooks for a connectors. * * @param string $name Name of the connector. */ public function unload_connector( $name ) { if ( ! empty( $this->connectors[ $name ] ) ) { $this->connectors[ $name ]->unregister(); } } /** * Reregisters the context hooks for a connector. * * @param string $name Name of the connector. */ public function reload_connector( $name ) { if ( ! empty( $this->connectors[ $name ] ) ) { $this->connectors[ $name ]->register(); } } }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件