-1

New!

ok i deleted the bg options but now i get error from the font-family..

Warning: Illegal string offset 'font-family' in .../wp-content/themes/curves/includes/custom-css.php on line 20

Warning: Illegal string offset 'font-family' in .../wp-content/themes/curves/includes/custom-css.php on line 26

Warning: Illegal string offset 'font-family' in .../wp-content/themes/curves/includes/custom-css.php on line 31

Warning: Illegal string offset 'font-family' in .../wp-content/themes/curves/includes/custom-css.php on line 37

Warning: Illegal string offset 'font-family' in .../wp-content/themes/curves/includes/custom-css.php on line 42

Warning: Illegal string offset 'font-family' in .../wp-content/themes/curves/includes/custom-css.php on line 47

Warning: Illegal string offset 'font-family' in ..../wp-content/themes/curves/includes/custom-css.php on line 56

i think this is not writen well

$h1_font = ot_get_option( 'h1_font', 'lato' );

$custom_css = "
h1 { 
    font-family: ". $h1_font['font-family'] .";
    font-size: ". ot_get_option( 'h1_size', '24' ). "px;
    font-weight: 300;
}

any help? thx


Have some issues with PHP 5.4.. I have a friend who wrote the code for me because i only design and now the guy is unreachable and.. here i am :)

So I have a customcss.php who creates a dynamic.css for a Wordpress theme. I have installed the theme on host gator which has PHP 5.4 and i get this warnings:

Warning: Illegal string offset 'font-family' in /.../public_html/aaa/wp-       content/themes/curves/includes/custom-css.php on line 60

Notice: Uninitialized string offset: 0 in /.../public_html/aaa/wp-content/themes/curves/includes/custom-css.php on line 20

Warning: Illegal string offset 'background-color' in /home4/mthemes/public_html/aaa/wp-content/themes/curves/includes/custom-css.php on line 60

Notice: Uninitialized string offset: 0 in /.../public_html/aaa/wp-content/themes/curves/includes/custom-css.php on line 60

Warning: Illegal string offset 'background-repeat' in /.../public_html/aaa/wp-content/themes/curves/includes/custom-css.php on line 63

Notice: Uninitialized string offset: 0 in /.../public_html/aaa/wp-content/themes/curves/includes/custom-css.php on line 63

Warning: Illegal string offset 'background-attachment' in /.../public_html/aaa/wp-content/themes/curves/includes/custom-css.php on line 67

etc..

<?php
//custom inline css
function curves_style_custom() {
 wp_enqueue_style(
  'custom-style',
  get_template_directory_uri() . '/dynamic.css'
 );

$h1_font = ot_get_option( 'h1_font', 'lato' );
$h2_font = ot_get_option( 'h2_font', 'lato' );
$h3_font = ot_get_option( 'h3_font', 'lato' );
$h4_font = ot_get_option( 'h4_font', 'lato' );
$h5_font = ot_get_option( 'h5_font', 'lato' );
$h6_font = ot_get_option( 'h6_font', 'lato' );
$g_font = ot_get_option( 'g_font', 'lato' );


$custom_css = "
h1 { 
    font-family: ". $h1_font['font-family'] .";
    font-size: ". ot_get_option( 'h1_size', '24' ). "px;
    font-weight: 300;
}

h2 {     
    font-family: ". $h2_font['font-family'] .";
    font-size: ". ot_get_option( 'h2_size', '22' ) ."px;
    font-weight: 300;
}

h3 { 
    font-family: ". $h3_font['font-family'] .";
    font-size:". ot_get_option( 'h3_size', '18' ) ."px;
    font-weight: 300;

}

h4 { 
    font-family: ". $h4_font['font-family'] .";
    font-size: ". ot_get_option( 'h4_size', '16' ) ."px;
    font-weight: 300;
}
h5 { 
    font-family: ". $h5_font['font-family'] .";
    font-size: ". ot_get_option( 'h5_size', '12' ) ."px;
    font-weight: 300;
}

h6 { 
    font-family: ". $h6_font['font-family'] .";
    font-size: ". ot_get_option( 'h6_size', '10' ) ."px;
    font-weight: 300;
}   

p  { 
    font-size: ". ot_get_option( 'p_size', '14' ) ."px;
}

body{
    font-family: ". $g_font['font-family'] .";
";
$body_bg = ot_get_option( 'body_bg_image' );

if($body_bg['background-color'] != ""){
    $custom_css .= 'background-color: '. $body_bg['background-color'] .';';
} 
if($body_bg['background-repeat'] != ""){
    $custom_css .= 'background-repeat: '. $body_bg['background-repeat'] .';';
}

if($body_bg['background-attachment'] != ""){
    $custom_css .= 'background-attachment: '. $body_bg['background-attachment'] .';';
}

if($body_bg['background-position'] != ""){
    $custom_css .= 'background-position: '. $body_bg['background-position'] .';';
}

if($body_bg['background-size'] != ""){
    $custom_css .= 'background-size: '. $body_bg['background-size'] .';';
}

if($body_bg['background-image'] != ""){
    $custom_css .= 'background-image: url("'. $body_bg['background-image'] .'");';
}

$custom_css .= "}";

This code applies the option selected in admin (option tree) in an inline css.

In PHP 5.3 it works but in PHP 5.4 it shows the warning.

Also I discovered that this happens because, when I first install the theme, there are no option like font-family selected in option tree although as you ca see I set a default value.

1 Answers1

1

Before you use an array member, you should first check, if it is set via e.g.:

if(isset($body_bg['background-image'])) {
    // do something with it
}

See also the answers in Illegal string offset Warning PHP

For example you could do the following:

$h1_font = ot_get_option( 'h1_font', 'lato' );

$h1_font_family = "sans-serif";
if(isset($h1_font['font-family']))
    $h1_font_family = $h1_font['font-family'];

$custom_css = "
h1 { 
    font-family: ". $h1_font_family .";
    font-size: ". ot_get_option( 'h1_size', '24' ). "px;
    font-weight: 300;
}

And so on for all the styles you want do define. You are providing a default value ("sans-serif") and if the setting 'font-family' is available in your option, it replaces the default value.

Community
  • 1
  • 1
Stefan Neubert
  • 1,053
  • 8
  • 22