0

I am facing error/Warning Illegal string offset

I have check all my code but no error reason found. with below function my theme style is working the code is written in word press theme in the function.php.

( ! ) SCREAM: Error suppression ignored for ( ! ) Warning: Illegal string offset 'face' in F:\wamp\www\wordpress-3.6.1-newsduke\wp-content\themes\hotnews\functions\theme-functions.php on line 140

 function freshthemes_theme_styles() {

        /* Google fonts array */
        $google_fonts = array_keys( freshthemes_typography_get_google_fonts() );

        /* Define all the options that possibly have a unique Google font */
        $body_font = ft_get_option('body_font', 'Arial, Helvetica, san-serif');
        $heading_font = ft_get_option('heading_font', 'Arial, Helvetica, san-serif');
        $menu_nav_font = ft_get_option('menu_nav_font', 'Arial, Helvetica, san-serif');

        /* Get the font face for each option and put it in an array */
        $selected_fonts = array(
            $body_font['face'],
            $heading_font['face'],
            $menu_nav_font['face'],
        );

        /* Remove any duplicates in the list */
        $selected_fonts = array_unique($selected_fonts);

        /* If it is a Google font, go ahead and call the function to enqueue it */
        foreach ( $selected_fonts as $font ) {
            if ( in_array( $font, $google_fonts ) ) {
                freshthemes_typography_enqueue_google_font($font);
            }
        }

        // Register our styles.
        wp_register_style('main', get_stylesheet_uri(), false, THEME_VERSION, 'all');
        wp_register_style('prettyPhoto', THEME_DIR . '/stylesheets/prettyPhoto.css', false, THEME_VERSION, 'all');
        wp_register_style('responsive', THEME_DIR . '/stylesheets/responsive.css', false, THEME_VERSION, 'all');
        wp_register_style('custom-style', THEME_DIR . '/functions/framework/frontend/custom-style.css', false, filemtime(THEME_PATH . '/functions/framework/frontend/custom-style.css'), 'all');

        // Enqueue them.
        wp_enqueue_style('main');
        wp_enqueue_style('custom-style');
        wp_enqueue_style('prettyPhoto');
        wp_enqueue_style('responsive');
    }
5
  • 1
    I find it hard to believe that the internet and search engines didn't list anything for Warning: Illegal string offset? Commented Sep 23, 2013 at 10:53
  • Sorry for this but no any helpful answer was found Commented Sep 23, 2013 at 10:54
  • What does var_dump($body_font, $heading_font, $menu_nav_font) shows? Commented Sep 23, 2013 at 10:59
  • @anupam var_dump showing " string 'Arial, Helvetica, san-serif' (length=27) " three times. Commented Sep 23, 2013 at 11:05
  • @ShagunSood Please see my answer below. Commented Sep 23, 2013 at 11:11

2 Answers 2

3
$selected_fonts = array(
    $body_font['face'],
    $heading_font['face'],
    $menu_nav_font['face'],
);

One or more of these variables is a string, which you are trying to access like an array, this only works if you access it with a numeric key slammer than strlen-1

To confirm this, do a var_dump($body_font, $heading_font, $menu_nav_font) too check which one is not actually an array, but a string.

Sign up to request clarification or add additional context in comments.

3 Comments

var_dump showing " string 'Arial, Helvetica, san-serif' (length=27) " three times.
well, then my assumption was correct, and you have an illegal offset because you are trying to access a string as if it were an array
sure give me your email address, and a list of your tasks and I'll email you the complete project by tomorrow noon, Sir.
2

Try:

$selected_fonts = array(
    $body_font,
    $heading_font,
    $menu_nav_font,
);

As $body_font, $heading_font and $menu_nav_font are string, using those as array will produce the warnings.

EDIT:

To be more generic:

$selected_fonts = array(
    is_array($body_font) && isset($body_font['face']) ? $body_font['face'] : $body_font,
    is_array($heading_font) && isset($heading_font['face']) ? $heading_font['face'] : $heading_font,
    is_array($menu_nav_font) && isset($menu_nav_font['face']) ? $menu_nav_font['face'] : $menu_nav_font,
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.