I'm creating a theme based on Sage WordPress starter theme and created a new namespace to store some of my functions (Roots\Sage\Color_Scheme).
When I try to call a function from that namespace, I get the error message
Call to undefined function Roots\Sage\Color_Scheme\custom_header_and_background() in C:\xampp\htdocs\wordpress\wp-content\themes\soaring\lib\setup.php on line 19
Since I have "use Roots\Sage\Color_Scheme" declared and the function is definitely in the color_scheme.php file, I'm not sure why it's not actually recognizing the function. Note that color_scheme.php is a namespaced collection of functions but contains no declared class.
Setup.php
namespace Roots\Sage\Setup;
use Roots\Sage\Assets;
use Roots\Sage\Color_Scheme;
/**
* Theme setup
*/
function setup() {
// Enable features from Soil when plugin is activated
// https://roots.io/plugins/soil/
add_theme_support('soil-clean-up');
add_theme_support('soil-nav-walker');
add_theme_support('soil-nice-search');
add_theme_support('soil-jquery-cdn');
add_theme_support('soil-relative-urls');
Color_Scheme\custom_header_and_background();
...
Here are the relevant portions of Color_Scheme.php (located in the same directory)
<?php
namespace Roots\Sage\Color_Scheme;
/**
* Adds theme support for custom background and custom header
*
* Include default values for several settings.
*/
function custom_header_and_background() {
$color_scheme = get_color_scheme();
$default_background_color = trim( $color_scheme[0], '#' );
$default_text_color = trim( $color_scheme[1], '#' );
/**
* Filter the arguments used when adding 'custom-background' support in Soaring.
*
* @since Soaring 1.0
*
* @param array $args {
* An array of custom-background support arguments.
*
* @type string $default-color Default color of the background.
* }
*/
add_theme_support( 'custom-background', apply_filters( 'soaring_custom_background_args', array(
'default-color' => $default_background_color,
)));
// HEADER
$custom_header_args = array(
'width' => 300,
'height' => 120,
'flex-width' => true,
'flex-height' => true,
'default-image' => get_template_directory_uri() . '/images/soaring-logo.png',
);
add_theme_support( 'custom-header', $custom_header_args );
}
includeto Color_Scheme.php?require_oncein yourSetup.phpfile. You can also include yourcolor_scheme.phpfile using Sage's$sage_includes = [ ]array found infunctions.php.