Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output errors on typography settings #975

Closed
qantumthemes opened this issue May 16, 2016 · 2 comments
Closed

Output errors on typography settings #975

qantumthemes opened this issue May 16, 2016 · 2 comments

Comments

@qantumthemes
Copy link

Issue description:

Warning: array_key_exists(): The first argument should be either a string or an integer in kirki/includes/class-kirki-fonts.php on line 229

Warning: strpos() expects parameter 1 to be string, array given in kirki/includes/output/property/class-kirki-output-property-font-family.php on line 49

Warning: strpos() expects parameter 1 to be string, array given in
kirki/includes/output/property/class-kirki-output-property-font-family.php on line 49

Version used:

latest dev from today

Using theme_mods or options?

yes

Code to reproduce the issue (config + field(s))


Kirki2_Kirki::add_field( 'qt_config', array(
    'type'        => 'typography',
    'settings'    => 'qt_typography_text',
    'label'       => esc_attr__( 'Basic font', '_s' ),
    'section'     => 'qt_typography',
    'default'     => array(
        'font-family'    => 'Roboto',
        'variant'        => 'regular',
        'font-size'      => '14px',
        'line-height'    => '1.5',
        'letter-spacing' => '0',
        'subsets'        => array( 'latin-ext' ),
        'color'          => '#333333',
        'text-transform' => 'none',
        'text-align'     => 'left'
    ),
    'priority'    => 10,
    'output'      => array(
        array(
            'element' => 'body',
            'property' => 'font-family'
        ),
    ),
) );

Analysis of the issue:

  1. line 229 the var $fontname is an array:
Array
(
    [font-family] => Ribeye Marrow
    [font-size] => 14px
    [variant] => regular
    [line-height] => 1.5
    [letter-spacing] => 0
    [color] => #AFAFAF
    [text-align] => left
    [subsets] => Array
        (
            [0] => latin-ext
        )

    [text-transform] => none
)

The issue seems to come in
class-kirki-output-property-font-family.php

Where $this->value is the array so the function works better like this:

`
if ( Kirki_Fonts::is_google_font( $this->value["font-family"] ) ) {

`

ERROR 2: SAME THING:

everywhere it refers to $this->value as string while is always the array, so it works perfectly when we rewrite all the function like this:

`

value = str_replace( '"', '"', $this->value ); // Add backup font. if ( Kirki_Fonts::is_google_font( $this->value["font-family"] ) ) { if ( isset( $google_fonts_array[ $this->value["font-family"] ] ) && isset( $google_fonts_array[ $this->value["font-family"] ]['category'] ) ) { if ( isset( $backup_fonts[ $google_fonts_array[ $this->value["font-family"] ]['category'] ] ) ) { // Add double quotes if needed. if ( false !== strpos( $this->value["font-family"], ' ' ) && false === strpos( $this->value["font-family"], '"' ) ) { $this->value = '"' . $this->value["font-family"] . '", ' . $backup_fonts[ $google_fonts_array[ $this->value["font-family"] ]['category'] ]; } else { $this->value .= ', ' . $backup_fonts[ $google_fonts_array[ $this->value["font-family"] ]['category'] ]; } } } } else { // Add double quotes if needed. if ( false !== strpos( $this->value["font-family"], ' ' ) && false === strpos( $this->value["font-family"], '"' ) ) { $this->value = '"' . $this->value["font-family"] . '"'; } } } } ``` } ` I don't know if i'm doing it right, but now all works perfectly and no errors are thrown... Thanks!!
@qantumthemes
Copy link
Author

Ok, after long debugging, sounds like the function is called twice for a single font.
The first time $this->value is an array. the second is a string.
So is like I'm trying to fix something that is broken elseware...
Plus not all the families have a category, so a check is needed there for sure...

Don't really know what to do at this point :octocat:

@qantumthemes
Copy link
Author

This added at the beginning of the function solves all: let's skip whatever if it's an array

protected function process_value() {

            if(gettype($this->value) == "array") {
                return;
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant