Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,208,566 members, 8,002,992 topics. Date: Friday, 15 November 2024 at 12:22 AM

I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) (1062 Views)

Download Hundreds Of HTML, CSS, Wordpress Theme, PHP Scripts For Free / What Is Wrong With This Line Of Code? / Can Someone Explain This Line Of Code To Me (2) (3) (4)

(1) (Reply) (Go Down)

I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) by Nobody: 6:22am On Nov 05, 2018
I have this theme that now loads a blank page after host upgraded to PHP 7.2. I'm not good with PHP so I need help converting this line of code with PHP 7.2 Thanks.

The code

if ( ! function_exists( 'yit_button_style' ) ) {
/**
* Add button style to shortcode button.
*
* @param $button
*
* @return array
*
* @since 1.0.0
*/
function yit_button_style( $button = array() ) {
$button['flat'] = __('Black','yit');
$button['alternative'] = __('Alternative', 'yit');
$button['white'] = __('White','yit');
return $button;
}
}

Error logs

[05-Nov-2018 04:13:33 UTC] PHP Warning: Illegal string offset 'flat' in /www/wp-content/themes/jakobi-oud/theme/functions-template.php on line 505
[05-Nov-2018 04:13:33 UTC] PHP Warning: Illegal string offset 'alternative' in /www/wp-content/themes/jakobi-oud/theme/functions-template.php on line 506
[05-Nov-2018 04:13:33 UTC] PHP Warning: Illegal string offset 'white' in /www/wp-content/themes/jakobi-oud/theme/functions-template.php on line 507
[05-Nov-2018 04:13:33 UTC] PHP Fatal error: Uncaught Error: [] operator not supported for strings in /www/wp-content/themes/jakobi-oud/core/functions-core.php:432
Stack trace:
#0 /www/wp-content/themes/jakobi-oud/core/functions-template.php(93): yit_detect_browser_body_class()
#1 /www/wp-content/themes/jakobi-oud/theme/functions-theme.php(347): yit_is_old_ie()
#2 /www/wp-includes/class-wp-hook.php(286): yit_add_blog_stylesheet('')
#3 /www/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
#4 /www/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#5 /www/wp-includes/general-template.php(2614): do_action('wp_head')
#6 /www/wp-content/themes/jakobi-oud/header.php(42): wp_head()
#7 /www/wp-includes/template.php(688): require_once('/www/wp-content...')
#8 /www/wp-includes/template.php(647): load_template('/www/wp-content...', true)
#9 /www/wp-includes/general-template.php(41): locate_template(Array, true)
#10 /www/wp-content/themes/jakobi-oud/index.php(17): get_header()
#11 /www/wp-includes/template-loader.php(74): include('/www/wp in /www/wp-content/themes/jakobi-oud/core/functions-core.php on line 432
Re: I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) by ogunjobiolaide: 6:27am On Nov 05, 2018
Whatsapp me on 08063718360 to solve this for u.
Re: I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) by Nobody: 6:29am On Nov 05, 2018
ogunjobiolaide:
Whatsapp me on 08063718360 to solve this for u.
Please can you paste the code here? It could be of help to someone else in the future.
Re: I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) by etoluw: 7:37am On Nov 05, 2018
This happens when a function is expecting an array as its parameter but is receiving a string.
you should convert d string to array.

(*NOTE in PHP 7.1 and below this did not result in fatal errors )

ADD THIS TO THE BEGINNING OF THE FUNCTION

if(!is_array($button))
{ $button = (array)$button; }
Re: I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) by Nobody: 7:48am On Nov 05, 2018
etoluw:
This happens when a function is expecting an array as its parameter but is receiving a string.
you should convert d string to array.

(*NOTE in PHP 7.1 and below this did not result in fatal errors )

ADD THIS TO THE BEGINNING OF THE FUNCTION

if(!is_array($button))
{ $button = (array)$button; }

Thanks, I did make an adjustment but it lead to another error

This is what my code looks like:

if ( ! function_exists( 'yit_button_style' ) ) {
/**
* Add button style to shortcode button.
*
* @param $button
*
* @return array
*
* @since 1.0.0
*/

function yit_button_style( $button = array() ) {
if(!is_array($button)) {
$button = (array)$button; }
$button['flat'] = __('Black','yit');
$button['alternative'] = __('Alternative', 'yit');
$button['white'] = __('White','yit');
return $button;
}
}

I'm not sure if I did that correctly. Thanks for helping.
Re: I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) by etoluw: 8:24am On Nov 05, 2018
grossintel:

Thanks, I did make an adjustment but it lead to another error
This is what my code looks like:
if ( ! function_exists( 'yit_button_style' ) ) { /** * Add button style to shortcode button. * * @param $button * * @return array * * @since 1.0.0 */
function yit_button_style( $button = array() ) { if(!is_array($button)) { $button = (array)$button; } $button['flat'] = __('Black','yit'); $button['alternative'] = __('Alternative', 'yit'); $button['white'] = __('White','yit'); return $button; } }
I'm not sure if I did that correctly. Thanks for helping.
thats correct.
what is d new error it is displaying?
Re: I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) by Nobody: 8:43am On Nov 05, 2018
etoluw:


thats correct.

what is d new error it is displaying?


Debug error:

[05-Nov-2018 07:37:52 UTC] PHP Fatal error: Uncaught Error: [] operator not supported for strings in /www/wp-content/themes/jakobi-oud/core/functions-core.php:432

Stack trace:
#0 /www/wp-content/themes/jakobi-oud/core/functions-template.php(93): yit_detect_browser_body_class()
#1 /www/wp-content/themes/jakobi-oud/theme/functions-theme.php(347): yit_is_old_ie()
#2 /www/wp-includes/class-wp-hook.php(286): yit_add_blog_stylesheet('')
#3 /www/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
#4 /www/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#5 /www/wp-includes/general-template.php(2614): do_action('wp_head')
#6 /www/wp-content/themes/jakobi-oud/header.php(42): wp_head()
#7 /www/wp-includes/template.php(688): require_once('/www/wp-content...')
#8 /www/wp-includes/template.php(647): load_template('/www/wp-content...', true)
#9 /www/wp-includes/general-template.php(41): locate_template(Array, true)
#10 /www/wp-content/themes/jakobi-oud/index.php(17): get_header()
#11 /www/wp-includes/template-loader.php(74): include('/www/wp in /www/wp-content/themes/jakobi-oud/core/functions-core.php on line 432

Code:

function yit_sidebar_args( $name, $description = '', $widget_class = 'widget', $title = 'h3' ) {
$id = strtolower( str_replace( ' ', '-', $name ) );

return array(
'name' => $name,
'id' => $id,
'description' => $description,
'before_widget' => '<div id="%1$s" class="' . $widget_class . ' %2$s">',
'after_widget' => '</div>',
'before_title' => '<' . $title . '>',
'after_title' => '</' . $title . '>', //This is line 432
);
}


If you can help me solve this please drop your contact here for a token I have for you thanks. I have attached the file so you can see the rest of the code.

Re: I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) by etoluw: 9:11am On Nov 05, 2018
whatsapp - 08129615641

d actual file u should send is located here -
/wp-content/themes/jakobi-oud/core/functions-core.php

line: 432 is where d problem originates from
Re: I Need Help With This Line Of Code (wordpress Theme Php 7 Issue) by Nobody: 9:22am On Nov 05, 2018
etoluw:
whatsapp - 08129615641

d actual file u should send is located here -
/wp-content/themes/jakobi-oud/core/functions-core.php

line: 432 is where d problem originates from
Thanks, here is the file, I sent you a message on WhatsApp. When I switch to other themes it works.Thanks alot bro. You are a guru. Thank you for helping me fix it.

(1) (Reply)

Developer Needed For Portfolio Website / Free Domain From Me / Where Can I Get Telegram Group Scraper Cracked

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.