/** * Retrieve the name of the highest priority template file that exists. * * Searches in the child theme before parent theme so that themes which * inherit from a parent theme can just overload one file. If the template is * not found in either of those, it looks in the theme-compat folder last. * * @since bbPres (r3618) * * @param string|array $template_names Template file(s) to search for, in order. * @param bool $load If true the template file will be loaded if it is found. * @param bool $require_once Whether to require_once or require. Default true. * Has no effect if $load is false. * @return string The template filename if one is located. */ function bbp_locate_template($template_names, $load = false, $require_once = true) { // No file found yet $located = false; $template_locations = bbp_get_template_stack(); // Try to find a template file foreach ((array) $template_names as $template_name) { // Continue if template is empty if (empty($template_name)) { continue; } // Trim off any slashes from the template name $template_name = ltrim($template_name, '/'); // Loop through template stack foreach ((array) $template_locations as $template_location) { // Continue if $template_location is empty if (empty($template_location)) { continue; } // Check child theme first if (file_exists(trailingslashit($template_location) . $template_name)) { $located = trailingslashit($template_location) . $template_name; break 2; } } } // Maybe load the template if one was located if (true == $load && !empty($located)) { load_template($located, $require_once); } return $located; }
/** * Enqueue a script from the highest priority location in the template stack. * * Registers the style if file provided (does NOT overwrite) and enqueues. * * @since bbPress (r5180) * * @param string $handle Name of the script. * @param string|bool $file Relative path to the script. Example: '/js/myscript.js'. * @param array $deps An array of registered handles this script depends on. Default empty array. * @param string|bool $ver Optional. String specifying the script version number, if it has one. This parameter * is used to ensure that the correct version is sent to the client regardless of caching, * and so should be included if a version number is available and makes sense for the script. * @param bool $in_footer Optional. Whether to enqueue the script before </head> or before </body>. * Default 'false'. Accepts 'false' or 'true'. * * @return string The script filename if one is located. */ function bbp_enqueue_script($handle = '', $file = '', $dependencies = array(), $version = false, $in_footer = 'all') { // No file found yet $located = false; // Trim off any slashes from the template name $file = ltrim($file, '/'); // Make sure there is always a version if (empty($version)) { $version = bbp_get_version(); } // Loop through template stack foreach ((array) bbp_get_template_stack() as $template_location) { // Continue if $template_location is empty if (empty($template_location)) { continue; } // Check child theme first if (file_exists(trailingslashit($template_location) . $file)) { $located = trailingslashit($template_location) . $file; break; } } // Enqueue if located if (!empty($located)) { $content_dir = constant('WP_CONTENT_DIR'); // IIS (Windows) here // Replace back slashes with forward slash if (strpos($located, '\\') !== false) { $located = str_replace('\\', '/', $located); $content_dir = str_replace('\\', '/', $content_dir); } // Make path to file relative to site URL $located = str_replace($content_dir, WP_CONTENT_URL, $located); // Enqueue the style wp_enqueue_script($handle, $located, $dependencies, $version, $in_footer); } return $located; }