wpcom-endpoints
2 days ago
class-wpcom-rest-field-controller.php
1 month ago
class.jetpack-core-api-module-endpoints.php
1 week ago
class.jetpack-core-api-site-endpoints.php
2 months ago
class.jetpack-core-api-widgets-endpoints.php
4 years ago
class.jetpack-core-api-xmlrpc-consumer-endpoint.php
4 years ago
load-wpcom-endpoints.php
7 months ago
load-wpcom-endpoints.php
63 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Loader for WP REST API endpoints that are synced with WP.com. |
| 4 | * |
| 5 | * On WP.com see: |
| 6 | * - wp-content/mu-plugins/rest-api.php |
| 7 | * - wp-content/rest-api-plugins/jetpack-endpoints/ |
| 8 | * |
| 9 | * @package automattic/jetpack |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * Disable direct access. |
| 14 | */ |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit( 0 ); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Loop through endpoint files and load them. |
| 21 | * |
| 22 | * @param string $file_pattern Path pattern to the endpoints (pattern must be supported by glob()). |
| 23 | */ |
| 24 | function wpcom_rest_api_v2_load_plugin_files( $file_pattern ) { |
| 25 | $plugins = glob( __DIR__ . '/' . $file_pattern ); |
| 26 | |
| 27 | if ( ! is_array( $plugins ) ) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | foreach ( array_filter( $plugins, 'is_file' ) as $plugin ) { |
| 32 | require_once $plugin; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * API v2 plugins: define a class, then call this function. |
| 38 | * |
| 39 | * @param string $class_name The name of the class to load. |
| 40 | */ |
| 41 | function wpcom_rest_api_v2_load_plugin( $class_name ) { |
| 42 | global $wpcom_rest_api_v2_plugins; |
| 43 | |
| 44 | if ( ! isset( $wpcom_rest_api_v2_plugins ) ) { |
| 45 | $wpcom_rest_api_v2_plugins = array(); |
| 46 | } |
| 47 | |
| 48 | if ( ! isset( $wpcom_rest_api_v2_plugins[ $class_name ] ) ) { |
| 49 | $wpcom_rest_api_v2_plugins[ $class_name ] = new $class_name(); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | require __DIR__ . '/class-wpcom-rest-field-controller.php'; |
| 54 | |
| 55 | /** |
| 56 | * Load the REST API v2 plugin files during the plugins_loaded action. |
| 57 | */ |
| 58 | function load_wpcom_rest_api_v2_plugin_files() { |
| 59 | wpcom_rest_api_v2_load_plugin_files( 'wpcom-endpoints/*.php' ); |
| 60 | wpcom_rest_api_v2_load_plugin_files( 'wpcom-fields/*.php' ); |
| 61 | } |
| 62 | add_action( 'plugins_loaded', 'load_wpcom_rest_api_v2_plugin_files' ); |
| 63 |