phpwordpressredux-framework

Redux Framework - Custom Fonts Filter


I am trying to pass an array of custom fonts to what I believe is the custom_fonts filter on Redux Framework, this set-up so far is giving back the error of:

Warning: Invalid argument supplied for foreach() in ....

My filter:

add_filter('redux/theming/field/typography/custom_fonts', function ( $array ) {

  $array = array(
    "foo" => "foo font",
    "bar" => "bar font",
  );

    return $array;

});

Redux core which seems to handle the custom_fonts when passed:

if ( $this->field['custom_fonts'] !== false ) {
    $this->field['custom_fonts'] = apply_filters( "redux/{$this->parent->args['opt_name']}/field/typography/custom_fonts", array() );
    if ( ! empty( $this->field['custom_fonts'] ) ) {
        foreach ( $this->field['custom_fonts'] as $group => $fonts ) {
            $this->parent->font_groups['customfonts'] = array(
                'text'     => $group,
                'children' => array(),
            );
            foreach ( $fonts as $family => $v ) {
                $this->parent->font_groups['customfonts']['children'][] = array(
                    'id'          => $family,
                    'text'        => $family,
                    'data-google' => 'false',
                );
            }
        }
    }
}

The code above on the original file: https://github.com/reduxframework/redux-framework/blob/188ddf5a5bd86314775f872553ad6af6f07b51ed/ReduxCore/inc/fields/typography/field_typography.php#L903

My data is being passed to the filter as it's trying to process it through the foreach but don't see exactly why it may be breaking. Anyone able to clear up what maybe I am missing?


Solution

  • This is because you've return the array in the wrong format.

    Give this a try:

    $array = array(
        "custom_fonts"=> [
            "foo" => "foo font",
            "bar" => "bar font",
        ]
    );