WPCOM_JSON_API_Endpoint::load_theme_functions PHP Метод

load_theme_functions() публичный Метод

Load the functions.php file for the current theme to get its post formats, CPTs, etc.
    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;
        }
        // VIP context loading is handled elsewhere, so bail to prevent
        // duplicate loading. See `switch_to_blog_and_validate_user()`
        if (function_exists('wpcom_is_vip') && wpcom_is_vip()) {
            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());
        // 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');
    }