Changeset 12454 for trunk/src/bp-core/bp-core-rest-api.php
- Timestamp:
- 09/07/2019 05:26:24 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-rest-api.php
r12451 r12454 19 19 */ 20 20 function bp_rest_is_plugin_active() { 21 21 return (bool) has_action( 'bp_rest_api_init', 'bp_rest', 5 ); 22 22 } 23 23 … … 34 34 */ 35 35 function bp_rest_in_buddypress() { 36 37 38 36 $is_src = defined( 'BP_SOURCE_SUBDIRECTORY' ) && BP_SOURCE_SUBDIRECTORY === 'src'; 37 38 return ! $is_src && ! bp_rest_is_plugin_active(); 39 39 } 40 40 … … 48 48 function bp_rest_api_is_available() { 49 49 50 51 52 53 54 55 56 57 58 59 50 /** 51 * Filter here to disable the BP REST API. 52 * 53 * The BP REST API requires at least WordPress 4.7.0 54 * 55 * @since 5.0.0 56 * 57 * @param boolean $value True if the BP REST API is available. False otherwise. 58 */ 59 return apply_filters( 'bp_rest_api_is_available', function_exists( 'create_initial_rest_routes' ) && bp_rest_in_buddypress() ) || bp_rest_is_plugin_active(); 60 60 } 61 61 … … 66 66 */ 67 67 function bp_rest_api_register_request_script() { 68 if ( ! bp_rest_api_is_available() ) { 69 return; 70 } 71 72 $dependencies = array( 'jquery' ); 73 74 // The wrapper for WP REST API requests was introduced in WordPress 4.9.0 75 if ( wp_script_is( 'wp-api-request', 'registered' ) ) { 76 $dependencies = array( 'wp-api-request' ); 77 } 78 79 wp_register_script( 80 'bp-api-request', 81 sprintf( '%1$sbp-core/js/bp-api-request%2$s.js', buddypress()->plugin_url, bp_core_get_minified_asset_suffix() ), 82 $dependencies, 83 bp_get_version(), 84 true 85 ); 86 wp_localize_script( 87 'bp-api-request', 88 'bpApiSettings', 89 array( 90 'root' => esc_url_raw( get_rest_url() ), 91 'nonce' => wp_create_nonce( 'wp_rest' ), 92 ) 93 ); 68 if ( ! bp_rest_api_is_available() ) { 69 return; 70 } 71 72 $dependencies = array( 'jquery' ); 73 74 // The wrapper for WP REST API requests was introduced in WordPress 4.9.0. 75 if ( wp_script_is( 'wp-api-request', 'registered' ) ) { 76 $dependencies = array( 'wp-api-request' ); 77 } 78 79 wp_register_script( 80 'bp-api-request', 81 sprintf( '%1$sbp-core/js/bp-api-request%2$s.js', buddypress()->plugin_url, bp_core_get_minified_asset_suffix() ), 82 $dependencies, 83 bp_get_version(), 84 true 85 ); 86 87 wp_localize_script( 88 'bp-api-request', 89 'bpApiSettings', 90 array( 91 'root' => esc_url_raw( get_rest_url() ), 92 'nonce' => wp_create_nonce( 'wp_rest' ), 93 'unexpectedError' => __( 'An unexpected error occured. Please try again.', 'buddypress' ), 94 ) 95 ); 94 96 } 95 97 add_action( 'bp_init', 'bp_rest_api_register_request_script' );
Note: See TracChangeset
for help on using the changeset viewer.