function load_theme_functions()
 {
     // bail if we've done this already (can happen when calling /batch endpoint)
     if (defined('REST_API_THEME_FUNCTIONS_LOADED')) {
         return;
     }
     define('REST_API_THEME_FUNCTIONS_LOADED', true);
     // the theme info we care about is found either within functions.php or one of the jetpack files.
     $function_files = array('/functions.php', '/inc/jetpack.compat.php', '/inc/jetpack.php', '/includes/jetpack.compat.php');
     $copy_dirs = array(get_template_directory());
     if (wpcom_is_vip()) {
         $copy_dirs[] = WP_CONTENT_DIR . '/themes/vip/plugins/';
     }
     // Is this a child theme? Load the child theme's functions file.
     if (get_stylesheet_directory() !== get_template_directory() && wpcom_is_child_theme()) {
         foreach ($function_files as $function_file) {
             if (file_exists(get_stylesheet_directory() . $function_file)) {
                 require_once get_stylesheet_directory() . $function_file;
             }
         }
         $copy_dirs[] = get_stylesheet_directory();
     }
     foreach ($function_files as $function_file) {
         if (file_exists(get_template_directory() . $function_file)) {
             require_once get_template_directory() . $function_file;
         }
     }
     // add inc/wpcom.php and/or includes/wpcom.php
     wpcom_load_theme_compat_file();
     // since the stuff we care about (CPTS, post formats, are usually on setup or init hooks, we want to load those)
     $this->copy_hooks('after_setup_theme', 'restapi_theme_after_setup_theme', $copy_dirs);
     /**
      * Fires functions hooked onto `after_setup_theme` by the theme for the purpose of the REST API.
      *
      * The REST API does not load the theme when processing requests.
      * To enable theme-based functionality, the API will load the '/functions.php',
      * '/inc/jetpack.compat.php', '/inc/jetpack.php', '/includes/jetpack.compat.php files
      * of the theme (parent and child) and copy functions hooked onto 'after_setup_theme' within those files.
      *
      * @module json-api
      *
      * @since 3.2.0
      */
     do_action('restapi_theme_after_setup_theme');
     $this->copy_hooks('init', 'restapi_theme_init', $copy_dirs);
     /**
      * Fires functions hooked onto `init` by the theme for the purpose of the REST API.
      *
      * The REST API does not load the theme when processing requests.
      * To enable theme-based functionality, the API will load the '/functions.php',
      * '/inc/jetpack.compat.php', '/inc/jetpack.php', '/includes/jetpack.compat.php files
      * of the theme (parent and child) and copy functions hooked onto 'init' within those files.
      *
      * @module json-api
      *
      * @since 3.2.0
      */
     do_action('restapi_theme_init');
 }
 function load_theme_functions()
 {
     // the theme info we care about is found either within functions.php or one of the jetpack files.
     $function_files = array('/functions.php', '/inc/jetpack.compat.php', '/inc/jetpack.php', '/includes/jetpack.compat.php');
     // Is this a child theme? Load the child theme's functions file.
     if (get_stylesheet_directory() !== get_template_directory() && wpcom_is_child_theme()) {
         foreach ($function_files as $function_file) {
             if (file_exists(get_stylesheet_directory() . $function_file)) {
                 require_once get_stylesheet_directory() . $function_file;
             }
         }
     }
     foreach ($function_files as $function_file) {
         if (file_exists(get_template_directory() . $function_file)) {
             require_once get_template_directory() . $function_file;
         }
     }
     // add inc/wpcom.php and/or includes/wpcom.php
     wpcom_load_theme_compat_file();
     // since the stuff we care about (CPTS, post formats, are usually on setup or init hooks, we want to load those)
     $this->copy_hooks('after_setup_theme', 'restapi_theme_after_setup_theme', WP_CONTENT_DIR . '/themes');
     do_action('restapi_theme_after_setup_theme');
     $this->copy_hooks('init', 'restapi_theme_init', WP_CONTENT_DIR . '/themes');
     do_action('restapi_theme_init');
 }