| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* Loader for WP REST API endpoints that are synced with WP.com. |
| 5 |
* |
| 6 |
* On WP.com see: |
| 7 |
* - wp-content/mu-plugins/rest-api.php |
| 8 |
* - wp-content/rest-api-plugins/jetpack-endpoints/ |
| 9 |
*/ |
| 10 |
|
| 11 |
function wpcom_rest_api_v2_load_plugin_files( $file_pattern ) { |
| 12 |
$plugins = glob( dirname( __FILE__ ) . '/' . $file_pattern ); |
| 13 |
|
| 14 |
if ( ! is_array( $plugins ) ) { |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
foreach ( array_filter( $plugins, 'is_file' ) as $plugin ) { |
| 19 |
require_once $plugin; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
// API v2 plugins: define a class, then call this function. |
| 24 |
function wpcom_rest_api_v2_load_plugin( $class_name ) { |
| 25 |
global $wpcom_rest_api_v2_plugins; |
| 26 |
|
| 27 |
if ( ! isset( $wpcom_rest_api_v2_plugins ) ) { |
| 28 |
$_GLOBALS['wpcom_rest_api_v2_plugins'] = $wpcom_rest_api_v2_plugins = array(); |
| 29 |
} |
| 30 |
|
| 31 |
if ( ! isset( $wpcom_rest_api_v2_plugins[ $class_name ] ) ) { |
| 32 |
$wpcom_rest_api_v2_plugins[ $class_name ] = new $class_name; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
require dirname( __FILE__ ) . '/class-wpcom-rest-field-controller.php'; |
| 37 |
|
| 38 |
// Now load the endpoint files. |
| 39 |
wpcom_rest_api_v2_load_plugin_files( 'wpcom-endpoints/*.php' ); |
| 40 |
wpcom_rest_api_v2_load_plugin_files( 'wpcom-fields/*.php' ); |
| 41 |
|