[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/ -> bp-core-rest-api.php (source)

   1  <?php
   2  /**
   3   * Core REST API functions.
   4   *
   5   * @package BuddyPress
   6   * @subpackage Core
   7   * @since 5.0.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Is the BP REST plugin is active?
  15   *
  16   * @since 5.0.0
  17   *
  18   * @return boolean True if the BP REST plugin is active. False otherwise.
  19   */
  20  function bp_rest_is_plugin_active() {
  21      return (bool) has_action( 'bp_rest_api_init', 'bp_rest', 5 );
  22  }
  23  
  24  /**
  25   * Check the availability of the BP REST API.
  26   *
  27   * @since 5.0.0
  28   *
  29   * @return boolean True if the BP REST API is available. False otherwise.
  30   */
  31  function bp_rest_api_is_available() {
  32      /**
  33       * Filter here to disable the BP REST API.
  34       *
  35       * The BP REST API requires at least WordPress 4.7.0
  36       *
  37       * @since 5.0.0
  38       *
  39       * @param boolean $value True if the BP REST API is available. False otherwise.
  40       */
  41      return apply_filters( 'bp_rest_api_is_available', function_exists( 'create_initial_rest_routes' ) && bp_rest_is_plugin_active() );
  42  }
  43  
  44  /**
  45   * Register the jQuery.ajax wrapper for BP REST API requests.
  46   *
  47   * @since 5.0.0
  48   */
  49  function bp_rest_api_register_request_script() {
  50      if ( ! bp_rest_api_is_available() ) {
  51          return;
  52      }
  53  
  54      $dependencies = array( 'jquery' );
  55  
  56      // The wrapper for WP REST API requests was introduced in WordPress 4.9.0
  57      if ( wp_script_is( 'wp-api-request', 'registered' ) ) {
  58          $dependencies = array( 'wp-api-request' );
  59      }
  60  
  61      wp_register_script(
  62          'bp-api-request',
  63          sprintf( '%1$sbp-core/js/bp-api-request%2$s.js', buddypress()->plugin_url, bp_core_get_minified_asset_suffix() ),
  64          $dependencies,
  65          bp_get_version(),
  66          true
  67      );
  68      wp_localize_script(
  69          'bp-api-request',
  70          'bpApiSettings',
  71          array(
  72              'root'  => esc_url_raw( get_rest_url() ),
  73              'nonce' => wp_create_nonce( 'wp_rest' ),
  74          )
  75      );
  76  }
  77  add_action( 'bp_init', 'bp_rest_api_register_request_script' );


Generated: Mon Jul 15 01:01:40 2019 Cross-referenced by PHPXref 0.7.1