• Resolved ianclark24

    (@ianclark24)


    I receive an error when I visit my page every now and then. I use the Code Snippet plugin to connect three fields with a Google Sheet. It seems it’s only one of the fields that is causing this error. If I refresh the page it usually loads properly but I have gotten alerts from Google that the site’s server is down, I’m guessing when they crawl the site at that exact moment.

    I have tried Elementor Support and they pointed me to the plugin support. Any ideas would be appreciated.

    Fatal error: Uncaught Error: Cannot use object of type WP_Error as array
    in /home/customer/www/ianclarkmortgages.ca/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()’d code on line 11

    Call stack:

    variable_value_shortcode()
    wp-includes/shortcodes.php:343
    do_shortcode_tag()
    preg_replace_callback()
    wp-includes/shortcodes.php:218
    do_shortcode()
    wp-content/plugins/elementor-pro/modules/dynamic-tags/tags/shortcode.php:53
    ElementorPro\M\D\T\Shortcode::render()
    wp-content/plugins/elementor/core/dynamic-tags/tag.php:35
    Elementor\C\D\Tag::get_content()
    wp-content/plugins/elementor/core/dynamic-tags/manager.php:216
    Elementor\C\D\Manager::get_tag_data_content()
    call_user_func_array()
    wp-content/plugins/elementor/core/dynamic-tags/manager.php:109
    Elementor\C\D\Manager::parse_tag_text()
    wp-content/plugins/elementor/core/dynamic-tags/manager.php:74
    Elementor\C\D\Manager::Elementor\C\D\{closure}()
    preg_replace_callback()
    wp-content/plugins/elementor/core/dynamic-tags/manager.php:73
    Elementor\C\D\Manager::parse_tags_text()
    wp-content/plugins/elementor/includes/controls/base-data.php:81
    Elementor\Base_Data_Control::parse_tags()
    wp-content/plugins/elementor/includes/base/controls-stack.php:1154
    Elementor\Controls_Stack::parse_dynamic_settings()
    wp-content/plugins/elementor/includes/base/controls-stack.php:1005
    Elementor\Controls_Stack::get_parsed_dynamic_settings()
    wp-content/plugins/elementor/core/files/css/post.php:296
    Elementor\C\F\C\Post::render_styles()
    wp-content/plugins/elementor/core/dynamic-tags/dynamic-css.php:32
    Elementor\C\D\Dynamic_CSS::render_styles()
    wp-content/plugins/elementor/core/dynamic-tags/dynamic-css.php:36
    Elementor\C\D\Dynamic_CSS::render_styles()
    wp-content/plugins/elementor/core/dynamic-tags/dynamic-css.php:36
    Elementor\C\D\Dynamic_CSS::render_styles()
    wp-content/plugins/elementor/core/dynamic-tags/dynamic-css.php:36
    Elementor\C\D\Dynamic_CSS::render_styles()
    wp-content/plugins/elementor/core/dynamic-tags/dynamic-css.php:36
    Elementor\C\D\Dynamic_CSS::render_styles()
    wp-content/plugins/elementor/core/files/css/post.php:178
    Elementor\C\F\C\Post::render_css()
    wp-content/plugins/elementor/core/files/css/base.php:617
    Elementor\C\F\C\Base::parse_content()
    wp-content/plugins/elementor/core/files/base.php:166
    Elementor\C\F\Base::update_file()
    wp-content/plugins/elementor/core/files/css/base.php:131
    Elementor\C\F\C\Base::update()
    wp-content/plugins/elementor/core/files/css/base.php:207
    Elementor\C\F\C\Base::enqueue()
    wp-content/plugins/elementor/core/files/css/post.php:199
    Elementor\C\F\C\Post::enqueue()
    wp-content/plugins/elementor/core/dynamic-tags/manager.php:424
    Elementor\C\D\Manager::after_enqueue_post_css()
    wp-includes/class-wp-hook.php:287
    WP_Hook::apply_filters()
    wp-includes/class-wp-hook.php:311
    WP_Hook::do_action()
    wp-includes/plugin.php:484
    do_action()
    wp-content/plugins/elementor/core/files/css/base.php:254
    Elementor\C\F\C\Base::enqueue()
    wp-content/plugins/elementor/core/files/css/post.php:199
    Elementor\C\F\C\Post::enqueue()
    wp-content/plugins/elementor/includes/frontend.php:647
    Elementor\Frontend::enqueue_styles()
    wp-content/plugins/elementor-pro/modules/theme-builder/classes/locations-manager.php:90
    ElementorPro\M\T\C\Locations_Manager::enqueue_styles()
    wp-includes/class-wp-hook.php:287
    WP_Hook::apply_filters()
    wp-includes/class-wp-hook.php:311
    WP_Hook::do_action()
    wp-includes/plugin.php:484
    do_action()
    wp-includes/script-loader.php:2004
    wp_enqueue_scripts()
    wp-includes/class-wp-hook.php:287
    WP_Hook::apply_filters()
    wp-includes/class-wp-hook.php:311
    WP_Hook::do_action()
    wp-includes/plugin.php:484
    do_action()
    wp-includes/general-template.php:3005
    wp_head()
    wp-content/themes/hello-elementor/header.php:21
    require_once()
    wp-includes/template.php:730
    load_template()
    wp-includes/template.php:676
    locate_template()
    wp-includes/general-template.php:48
    get_header()
    wp-content/plugins/elementor/modules/page-templates/templates/header-footer.php:9
    include()
    wp-includes/template-loader.php:106
    require_once()
    wp-blog-header.php:19
    require()
    index.php:17

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi @ianclark24,

    It seems like this error is coming from a snippet that’s creating a [variable_value_shortcode] shortcode. I would need to see the code of that snippet to be able to work out what’s going wrong.

    Thread Starter ianclark24

    (@ianclark24)

    I have made some changes to the site since and there have been some WordPress updates, but I have not changed the code snippet. This is the error I received the other day:

    Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in 
    /home/customer/www/ianclarkmortgages.ca/public_html/wp-content/plugins/code
    snippets/php/snippet-ops.php(446) : eval()'d code:26 Stack trace: #0 
    /home/customer/www/ianclarkmortgages.ca/public_html/wp-includes/shortcodes.php(343): 
    variable_value_shortcode(Array, '', 'get_variable_va...') #1 [internal function): 
    do_shortcode_tag(Array) #2 /home/customer/wwwi/ianclarkmortgages.ca/public_html/wp
    includes/shortcodes.php(218): preg_replace_callback('/\\[(\\[?)(get_va...', 'do_shortcode_ta..." 
    '[get_variable_v...') #3 /home/customer/wwwiianclarkmortgages.ca/public_html/wp
    content/plugins/elementor-pro/modules/dynamic-tags/tags/shortcode.php(53): 
    do_shortcode('[get_variable_v...') #4 
    /home/customer/www/ianclarkmortgages.ca/public_html/wp
    content/plugins/elementor/core/dynamic-tags/tag.php(35): 
    ElementorPro\Modules\DynamicTags\Tags\Shortcode->render() #5 
    /home/customer/wwwi/ianclarkmortgages.ca/public_html/wp
    content/plugins/elementor/core/dynamic-tags/mana in 
    /home/customer/wwwiianclarkmortgages.ca/public_html/wp-content/plugins/code
    snippets/php/snippet-ops.php(446) : eval()'d code on line 26 
    There has been a critical error on this website. 
    Learn more about debugging in WordPress.

    I have three of these code snippets, each pulling the value from a single cell in google sheets, but it always comes up for the one snippet. The code snippet is:

    add_action( 'init', function () {
    
    	$hook = 'run_snippet_daily';
    	$args = array();
    
    	if ( ! wp_next_scheduled( $hook, $args ) ) {
    		wp_schedule_event( time(), 'daily', $hook, $args );
    	}
    } );
    
    add_action( 'run_snippet_daily', function () {
    	
    	
    } );
    
    function variable_value_shortcode($atts) {
        $API = '[AIzaSyAvppcy7eYhb-YxpXFCKj3e9vnGxiUbWPI]';
        $google_spreadsheet_ID = '[1usYZn_1cDBwSb_skrKb6_W1-FksNbCely0HZa1-lf58]';
        $api_key = esc_attr( $API);
    
        $location = $atts['location'];
    
        $get_cell = new WP_Http();
        $cell_url = "https://sheets.googleapis.com/v4/spreadsheets/1usYZn_1cDBwSb_skrKb6_W1-FksNbCely0HZa1-lf58/values/Variable?&key=AIzaSyAvppcy7eYhb-YxpXFCKj3e9vnGxiUbWPI";	
        $cell_response = $get_cell -> get( $cell_url);
        $json_body = json_decode($cell_response['body'],true);	
        $cell_value = $json_body['values'][0][0];
        return $cell_value;
    }
    add_shortcode('get_variable_value', 'variable_value_shortcode');
    Plugin Author Shea Bunge

    (@bungeshea)

    The issue here is that sometimes the response is coming back as a WP_Error object, and the snippet is failing to check for that. I’d recommend adding a check before attempting to access the data to the variable_value_shortcode function:

    function variable_value_shortcode($atts) {
    	$API = '[AIzaSyAvppcy7eYhb-YxpXFCKj3e9vnGxiUbWPI]';
    	$google_spreadsheet_ID = '[1usYZn_1cDBwSb_skrKb6_W1-FksNbCely0HZa1-lf58]';
    	$api_key = esc_attr( $API);
    
    	$location = $atts['location'];
    
    	$get_cell = new WP_Http();
    	$cell_url = "https://sheets.googleapis.com/v4/spreadsheets/1usYZn_1cDBwSb_skrKb6_W1-FksNbCely0HZa1-lf58/values/Variable?&key=AIzaSyAvppcy7eYhb-YxpXFCKj3e9vnGxiUbWPI";
    	$cell_response = $get_cell -> get( $cell_url);
    	
    	if ( is_wp_error( $cell_response ) ) {
    		return 'An error occurred';
    	}
    	
    	$json_body = json_decode($cell_response['body'],true);
    	$cell_value = $json_body['values'][0][0];
    	return $cell_value;
    }
    add_shortcode('get_variable_value', 'variable_value_shortcode');
    Thread Starter ianclark24

    (@ianclark24)

    Great. I did add this to only run it once per day. THought it may take some load off.

    add_action( 'init', function () {
    
    	$hook = 'run_snippet_daily';
    	$args = array();
    
    	if ( ! wp_next_scheduled( $hook, $args ) ) {
    		wp_schedule_event( time(), 'daily', $hook, $args );
    	}
    } );
    
    add_action( 'run_snippet_daily', function () {
    	
    	
    } );
    Plugin Author Shea Bunge

    (@bungeshea)

    Sure, that shouldn’t be a problem. The error was in the variable_value_shortcode funcion, so that’s all I re-posted. The other parts of your code looked fine.

    Thread Starter ianclark24

    (@ianclark24)

    I am running the snippet once daily but I notice an error in my Query Monitor from time to time:

    429 Too Many Requests

    Thread Starter ianclark24

    (@ianclark24)

    Between updating WordPress and trying to go through a CDN something has happened again. This is the PHP error I am getting for that snippet. Along with an HTTP API Call Error. I think there is something wrong with my wordpress API

    wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()’d code:17
    variable_value_shortcode()
    wp-includes/shortcodes.php:343
    do_shortcode_tag()
    Unknown location
    preg_replace_callback()
    wp-includes/shortcodes.php:218
    do_shortcode()
    wp-content/plugins/elementor-pro/modules/dynamic-tags/tags/shortcode.php:53
    ElementorPro\M\D\T\Shortcode->render()
    wp-content/plugins/elementor/core/dynamic-tags/tag.php:35
    Elementor\C\D\Tag->get_content()
    wp-content/plugins/elementor/core/dynamic-tags/manager.php:216
    Elementor\C\D\Manager->get_tag_data_content()
    Unknown location
    Elementor\C\D\Manager->parse_tag_text()
    wp-content/plugins/elementor/core/dynamic-tags/manager.php:74
    Elementor\C\D\Manager->Elementor\C\D\{closure}()
    Unknown location
    preg_replace_callback()
    wp-content/plugins/elementor/core/dynamic-tags/manager.php:73
    Elementor\C\D\Manager->parse_tags_text()
    wp-content/plugins/elementor/includes/controls/base-data.php:81
    Elementor\Base_Data_Control->parse_tags()
    wp-content/plugins/elementor/includes/base/controls-stack.php:1154
    Elementor\Controls_Stack->parse_dynamic_settings()
    wp-content/plugins/elementor/includes/base/controls-stack.php:1005
    Elementor\Controls_Stack->get_parsed_dynamic_settings()
    wp-content/plugins/elementor/core/files/css/post.php:296
    Elementor\C\F\C\Post->render_styles()
    wp-content/plugins/elementor/core/dynamic-tags/dynamic-css.php:32
    Elementor\C\D\Dynamic_CSS->render_styles()
    wp-content/plugins/elementor/core/dynamic-tags/dynamic-css.php:36
    Elementor\C\D\Dynamic_CSS->render_styles()
    wp-content/plugins/elementor/core/dynamic-tags/dynamic-css.php:36
    Elementor\C\D\Dynamic_CSS->render_styles()
    wp-content/plugins/elementor/core/dynamic-tags/dynamic-css.php:36
    Elementor\C\D\Dynamic_CSS->render_styles()
    wp-content/plugins/elementor/core/dynamic-tags/dynamic-css.php:36
    Elementor\C\D\Dynamic_CSS->render_styles()
    wp-content/plugins/elementor/core/files/css/post.php:178
    Elementor\C\F\C\Post->render_css()
    wp-content/plugins/elementor/core/files/css/base.php:617
    Elementor\C\F\C\Base->parse_content()
    wp-content/plugins/elementor/core/files/base.php:166
    Elementor\C\F\Base->update_file()
    wp-content/plugins/elementor/core/files/css/base.php:131
    Elementor\C\F\C\Base->update()
    wp-content/plugins/elementor/core/files/css/base.php:207
    Elementor\C\F\C\Base->enqueue()
    wp-content/plugins/elementor/core/files/css/post.php:199
    Elementor\C\F\C\Post->enqueue()
    wp-content/plugins/elementor/core/dynamic-tags/manager.php:424
    Elementor\C\D\Manager->after_enqueue_post_css()
    wp-includes/class-wp-hook.php:292
    do_action(‘elementor/css-file/post/enqueue’)
    wp-content/plugins/elementor/core/files/css/base.php:254
    Elementor\C\F\C\Base->enqueue()
    wp-content/plugins/elementor/core/files/css/post.php:199
    Elementor\C\F\C\Post->enqueue()
    wp-content/plugins/elementor/includes/frontend.php:647
    Elementor\Frontend->enqueue_styles()
    wp-includes/class-wp-hook.php:292
    do_action(‘wp_enqueue_scripts’)
    wp-includes/script-loader.php:2027
    wp_enqueue_scripts()
    wp-includes/class-wp-hook.php:292
    do_action(‘wp_head’)
    wp-includes/general-template.php:3009
    wp_head()
    wp-content/plugins/elementor/modules/page-templates/templates/canvas.php:17

    403 Forbidden
    HTTP API Transport: curl
    DNS Resolution Time: 0.0021
    Connection Time: 0.0028
    Transfer Start Time (TTFB): 0.1529
    Response Size: 391 B
    Response Content Type: application/json; charset=UTF-8
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in’ is closed to new replies.