Co jest nie tak? Illegal string offset problem

0

Czy ktoś może mi pomóc i podpowiedzieć co w tej linijce jest nie tak zapisane?

 <a href="<?php echo esc_url(get_site_url()); ?>"  class="logo" style="width: auto; color:<?php the_field('logo_color','options'); ?>!important; font-family: <?php echo esc_attr($font['font_name']); ?>; font-size: <?php the_field('text_font_size','options'); ?>px; " class="titleLogo"><?php the_field('text_logo','options');?></a>

generalnie chyba tutaj jest problem

<?php echo esc_attr($font['font_name']); ?>

a komunikat wyrzuca mi taki

[11-Jun-2019 20:37:09 UTC] PHP Warning:  Illegal string offset 'font_name' in 

Nie znam się na kodzie. Z góry dziękuję za pomoc.

0

Mógłbyś pokazać więcej kodu? Z tego co mówi komunikat błędu $font nie jest tablicą a stringiem.

Jesteś pewien że nigdzie nie przypisujesz do $font stringa?

Mały przykład:

<?php 

$font = Array("font_name" => "Montserrat"); 

echo $font['font_name']; // Jest tablica | Działa

$font = "No longer";

echo $font['font_name']; // Nie ma tablicy | Nie działa | Błąd "Illegal string offset"
 ?>
0

Wykasuj linijkę:

<?php echo esc_attr($font['font_name']); ?>

i zamiast niej daj: "Times New Roman"
albo jakaś inna nazwę czcionki

0

cały kod

<!DOCTYPE html>
<html <?php language_attributes();?>>
<head>
	<meta charset="<?php bloginfo( 'charset' ); ?>">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<?php wp_head(); ?>
</head>
<body <?php body_class( ); ?> <?php if(function_exists('get_field')){ if(get_field('enable_onepage','options')):?>id="one-page"<?php endif; }?>>
	
	<?php
		
		$gap_header_and_content = '';
		if(function_exists('get_field')){
			stonedthemes_branding();

			$site_font =  get_field('web_site_font','options');	
			if($site_font){
				echo '<style type="text/css">';
				echo 'body{font-family:'.esc_attr(str_replace("+"," ",$site_font["font_name"])).' !important;';
				echo '</style>';
			}

			if(get_field('custom_css','options'))
			{
			  echo '<style type="text/css">';
			  echo get_field('custom_css','options');
			  echo '</style>';
			}
			if(get_field('custom_js','options'))
			{
				echo '<script>';
				echo get_field('custom_js','options');
				echo '</script>';
			}  
			
			if(get_field('gap_header_and_content'))
			{
				$gap_header_and_content = 'header-gap';
			}
		}	

		$loading_image1 = get_template_directory_uri()."/admin/loading/loading_icon_collective1.png";
		$loading_image2 = get_template_directory_uri()."/admin/loading/loading_icon_collective2.png";
		if(function_exists('get_field')){	

			if(get_field('loading_image1','options'))
				$loading_image1 = get_field('loading_image1','options');
			if(get_field('loading_image2','options'))
				$loading_image2 = get_field('loading_image2','options');
		}	
	?>
	<div id="loading-container">
		<div class="vertical-center2-container">
			<div class="vertical-center2-content text-center">
				<div class="loading-logo-container">
					<img src="<?php echo esc_attr($loading_image1);?>" alt="">
					<div id="current-loading" class="current-loading-status">
						<img src="<?php echo esc_attr($loading_image2);?>" alt="">
					</div>
				</div>
			</div>
		</div>
	</div>
	<header class="<?php echo esc_attr($gap_header_and_content );?>">
		<div class="stoned-container">
			<div class="row">
				<div class="col-md-12">
					<?php 
						if(function_exists('get_field')){
							$header_version = get_field('header_type','options'); 
						} else {
							$header_version = 'v1'; 
						}

						if($header_version == 'v1'||$header_version ==''){
							get_template_part('headers/header', '1');
						}
						else if($header_version == 'v2'){
							get_template_part('headers/header', '2');
						}
						else if($header_version == 'v3'){
							get_template_part('headers/header', '3');
						}
						else if($header_version == 'v4'){
							get_template_part('headers/header', '4');
						}
						else if($header_version == 'v5'){
							get_template_part('headers/header', '5');
						}
						else if($header_version == 'v6'){
							get_template_part('headers/header', '6');
						}
					?>	
				</div>
			</div>
		</div>
		<div class="responsive-header">
			<div class="responsive-logo text-center">
				<?php if(function_exists('get_field')){ ?>
					<?php if(get_field("logo_type","options")=="image"||get_field('page_logo')){ ?>
						<?php
							$logo = esc_attr(get_field('logo','options'));
						
							if(get_field('logo_mobile','options'))
								$logo = esc_attr(get_field('logo_mobile','options'));?>

						<?php $image = wp_get_attachment_image_src($logo,'full'); ?>
						<a href="<?php echo esc_url(get_site_url()); ?>" class="logo">
							<img src="<?php echo esc_url($image[0]);?>" alt="logo">
						</a>
					<?php } else if (get_field("logo_type","options")=="text"){ ?>
						 <?php $font = esc_attr(get_field('logo_font','options'));?>
						 <a href="<?php echo esc_url(get_site_url()); ?>"  class="logo" style="width: auto; color:<?php the_field('logo_color','options'); ?>!important; font-family: <?php echo esc_attr($font['font_name']); ?>; font-size: <?php the_field('text_font_size','options'); ?>px; " class="titleLogo"><?php the_field('text_logo','options');?></a>
					<?php } else { ?>
						<a href="<?php echo esc_url(get_site_url()); ?>" class="logo"><?php bloginfo('name');?></a>
					 <?php } ?>
				<?php } else { ?>
						<a href="<?php echo esc_url(get_site_url()); ?>" class="logo"><?php bloginfo('name');?></a>
				<?php } ?>	 
			</div>
			<div class="responsive-menu text-center">
				<a href="#" class="responsive-menu-btn">
					<i class="fa fa-bars"></i>
				</a>
				<?php if ( class_exists( 'WooCommerce' ) ) { ?>
				<a href="<?php echo WC()->cart->get_cart_url(); ?>">
					<i class="fa fa-shopping-cart"></i>
				</a>
				<?php } ?>
				<?php if(function_exists('get_field')){ ?>
					<div class="responsive-social-shares text-center">
						<?php $social_medias =  get_field('social_networks','options'); ?>
						<?php if($social_medias): ?>
							<?php foreach($social_medias as $social_media):?>
								<a href="<?php echo esc_url($social_media['url']);?>"  target="_blank">
									<i class="fa fa-vertical-center <?php echo esc_attr($social_media['network']); ?>"></i>
								</a>
							<?php endforeach;?>
						<?php endif;?>
					</div>
				<?php } ?>	
				<?php if($header_version == 'v3'):?>
						<ul class="menu">
							<?php wp_nav_menu(array( 'theme_location' => 'primary', 'items_wrap' => '%3$s', 'container_class' => 'menu-menu-container'));?>
							<?php wp_nav_menu(array( 'theme_location' => 'secondary', 'items_wrap' => '%3$s', 'container_class' => 'menu-menu-container'));?>
						</ul>
				<?php else : ?>
					<?php wp_nav_menu(array( 'theme_location' => 'primary', 'container_class' => 'menu-menu-container'));?>
				<?php endif;?>
			</div>
		</div>
	</header>
0

I jeszcze drugi problem w innym pliku:

[13-Jun-2019 21:11:07 UTC] PHP Warning:  Illegal string offset 'font_name' 

i chyba chodzi o to:

font: <?php echo esc_attr($font['font_name']); ?>

wklejam cały kod

<div class="header-v1 <?php if(function_exists('get_field')){ if(get_field('gap_header_and_content')): echo 'header-gap'; endif;}?>">
	<div class="header-container">
		<div class="logo-container">
			<?php if(function_exists('get_field')){ ?>
				<?php if(get_field("logo_type","options")=="image"||get_field('page_logo')){ ?>
				<?php $logo = esc_attr(get_field('logo','options'));?>
				<?php if(get_field('page_logo')) $logo = get_field('page_logo');?>
				<?php $image = wp_get_attachment_image_src($logo,'full'); ?>
				<a href="<?php echo esc_url(get_site_url()); ?>" class="logo">
					<img src="<?php echo esc_url($image[0]);?>" alt="logo">
				</a>
				<?php } else if (get_field("logo_type","options")=="text"){ ?>
					 <?php $font = esc_attr(get_field('logo_font','options'));?>
					 <a href="<?php echo esc_url(get_site_url()); ?>"  class="logo" style="width: auto; color:<?php the_field('logo_color','options'); ?>!important; font: <?php echo esc_attr($font['font_name']); ?>; font-size: <?php the_field('text_font_size','options'); ?>px; " class="titleLogo"><?php the_field('text_logo','options');?></a>
				<?php } else { ?>
					<a href="<?php echo esc_url(get_site_url()); ?>" class="logo"><?php bloginfo('name');?></a>
				 <?php } ?>
			<?php } else { ?>
					<a href="<?php echo esc_url(get_site_url()); ?>" class="logo"><?php bloginfo('name');?></a>
			<?php } ?>		 
		</div>
		<div class="menu-container text-center">
			<?php wp_nav_menu(array( 'theme_location' => 'primary',  'container_class' => 'menu-menu-container'));?>
		</div>
		
		<div class="shares-container">
			<?php if(function_exists('get_field')){ ?>
			<?php $social_medias =  get_field('social_networks','options'); ?>
		
				<?php if($social_medias): ?>
				<div class="pull-right circle-shares">
					<ul class="list-unstyled list-inline margin-none">
						<li class="shares">
							<a href="">
								<i class="fa fa-share-alt fa-vertical-center"></i>
							</a>
							<ul class="list-unstyled">
								<?php foreach($social_medias as $social_media):?>
								<li>
									<a href="<?php echo esc_url($social_media['url']);?>"  target="_blank">
										<i class="fa fa <?php echo esc_attr($social_media['network']); ?>"></i>
									</a>
								</li>
								<?php endforeach;?>
							</ul>
						</li>
					</ul>
				</div>
				<?php endif;?>
			<?php } ?>
			<?php if ( class_exists( 'WooCommerce' ) ) { ?>
				<div class="minicart pull-right">
					<ul class="list-unstyled">
						<li><a href="<?php echo WC()->cart->get_cart_url(); ?>" class="cart-info"><span><?php echo WC()->cart->get_cart_total(); ?></span> - <?php echo sprintf (_n( '%d item', '%d items', WC()->cart->get_cart_contents_count(),'collective' ), WC()->cart->get_cart_contents_count() ); ?></a></li>
						<li><a href="<?php echo esc_url(wp_login_url()); ?>" class="sign"><?php esc_html_e( 'Sign In' ,'collective'); ?></a></li>
					</ul>
					<div class="minicart-container">
						<a href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php esc_html_e( 'View your shopping cart' ,'collective'); ?>" class="cart-button">
							<i class="fa fa-shopping-cart"></i>
							<span class="notification"><?php echo WC()->cart->get_cart_contents_count(); ?></span>
						</a>
						<div class="minicart-items">
							<?php st_mini_cart();?>
						</div>
					</div>
				</div>
			<?php } ?>
		</div>
	</div>
</div>
1

Chryste... jak tak patrzysz na te wklejone kody to coś rozumiesz z tego? Wrzuć to poprawnie w tag code. Tak btw, ten kod chyba trzeba przepisać, bo jego czystość nie istnieje - i jeszcze ten WordPress XD

1

Formatowanie!

0

I jeszcze drugi problem w innym pliku:

[13-Jun-2019 21:11:07 UTC] PHP Warning: Illegal string offset 'font_name'

i chyba chodzi o to:

font: <?php echo esc_attr($font['font_name']); ?>

wklejam cały kod

			<?php if(function_exists('get_field')){ ?>
				<?php if(get_field("logo_type","options")=="image"||get_field('page_logo')){ ?>
				<?php $logo = esc_attr(get_field('logo','options'));?>
				<?php if(get_field('page_logo')) $logo = get_field('page_logo');?>
				<?php $image = wp_get_attachment_image_src($logo,'full'); ?>
				<a href="<?php echo esc_url(get_site_url()); ?>" class="logo">
					<img src="<?php echo esc_url($image[0]);?>" alt="logo">
				</a>
				<?php } else if (get_field("logo_type","options")=="text"){ ?>
					 <?php $font = esc_attr(get_field('logo_font','options'));?>
					 <a href="<?php echo esc_url(get_site_url()); ?>"  class="logo" style="width: auto; color:<?php the_field('logo_color','options'); ?>!important; font: <?php echo esc_attr($font['font_name']); ?>; font-size: <?php the_field('text_font_size','options'); ?>px; " class="titleLogo"><?php the_field('text_logo','options');?></a>
				<?php } else { ?>
					<a href="<?php echo esc_url(get_site_url()); ?>" class="logo"><?php bloginfo('name');?></a>
				 <?php } ?>
			<?php } else { ?>
					<a href="<?php echo esc_url(get_site_url()); ?>" class="logo"><?php bloginfo('name');?></a>
			<?php } ?>		 
		</div>
		<div class="menu-container text-center">
			<?php wp_nav_menu(array( 'theme_location' => 'primary',  'container_class' => 'menu-menu-container'));?>
		</div>
		
		<div class="shares-container">
			<?php if(function_exists('get_field')){ ?>
			<?php $social_medias =  get_field('social_networks','options'); ?>
		
				<?php if($social_medias): ?>
				<div class="pull-right circle-shares">
					<ul class="list-unstyled list-inline margin-none">
						<li class="shares">
							<a href="">
								<i class="fa fa-share-alt fa-vertical-center"></i>
							</a>
							<ul class="list-unstyled">
								<?php foreach($social_medias as $social_media):?>
								<li>
									<a href="<?php echo esc_url($social_media['url']);?>"  target="_blank">
										<i class="fa fa <?php echo esc_attr($social_media['network']); ?>"></i>
									</a>
								</li>
								<?php endforeach;?>
							</ul>
						</li>
					</ul>
				</div>
				<?php endif;?>
			<?php } ?>
			<?php if ( class_exists( 'WooCommerce' ) ) { ?>
				<div class="minicart pull-right">
					<ul class="list-unstyled">
						<li><a href="<?php echo WC()->cart->get_cart_url(); ?>" class="cart-info"><span><?php echo WC()->cart->get_cart_total(); ?></span> - <?php echo sprintf (_n( '%d item', '%d items', WC()->cart->get_cart_contents_count(),'collective' ), WC()->cart->get_cart_contents_count() ); ?></a></li>
						<li><a href="<?php echo esc_url(wp_login_url()); ?>" class="sign"><?php esc_html_e( 'Sign In' ,'collective'); ?></a></li>
					</ul>
					<div class="minicart-container">
						<a href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php esc_html_e( 'View your shopping cart' ,'collective'); ?>" class="cart-button">
							<i class="fa fa-shopping-cart"></i>
							<span class="notification"><?php echo WC()->cart->get_cart_contents_count(); ?></span>
						</a>
						<div class="minicart-items">
							<?php st_mini_cart();?>
						</div>
					</div>
				</div>
			<?php } ?>
		</div>
	</div>
</div>
2

Dżizas, to formatowanie serio boli... Jeśli ktoś zdecyduje się to rozszyfrować, to pełen szacun, bo to na masochizm zakrawa :P

1

Skoro przy pierwszym błędzie zamiana $font['font_name'] na $site_font["font_name"] działała i w innym pliku masz dokładnie ten sam błąd to chyba masz rozwiązanie

1

Wejdź do: wp-config.php
znajdź: define(‘WP_DEBUG’, true);
zamień: true na false

1 użytkowników online, w tym zalogowanych: 0, gości: 1