Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 3
CRAP
n/a
0 / 0
wpcom_rest_api_v2_load_plugin_files
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
wpcom_rest_api_v2_load_plugin
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
load_wpcom_rest_api_v2_plugin_files
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
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 */
15if ( ! 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 */
24function 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 */
41function 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
53require __DIR__ . '/class-wpcom-rest-field-controller.php';
54
55/**
56 * Load the REST API v2 plugin files during the plugins_loaded action.
57 */
58function 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}
62add_action( 'plugins_loaded', 'load_wpcom_rest_api_v2_plugin_files' );