• Resolved vivlad

    (@vivlad)


    Hello. We really like your product and we use it.
    But when developing a new functional, we are faced with a problem and we hope that you will help us.

    Now we are using the latest version of the plug-in Poll, Survey, Quiz, Slideshow, Form & Story Article (Version 19.3.5).
    All works well when we add the widget to the sidebar, but when we try to load the sidebar with the widget using AJAX, we get a 500 error.

    For a better understanding, let’s take a sample code that can be run on any standard theme:

    PHP:

    add_action('widgets_init', function(){
      register_sidebar(array(
        'name' => 'test-sidebar',
        'id'   => 'test-sidebar'
      ));
    });
    
    add_action('wp_ajax_load_sidebar', 'load_sidebar_call');
    add_action('wp_ajax_nopriv_load_sidebar', 'load_sidebar_call');
    
    function load_sidebar_call(){
    
        ob_start();
        dynamic_sidebar('test-sidebar');
        $data = ob_get_contents();
        ob_end_clean();
        echo json_encode(
        array('data' => $data)
        );
        die();
    }

    jQuery:

    jQuery.ajax({
      url: location.origin + '/wp-admin/admin-ajax.php',
      type: 'POST',
      dataType: 'json',
      data: {
        action: 'load_sidebar',
      },
      success: ( response ) => {
        console.log(response);
      }
    });

    In the Apperance-> Widgets section, a test sidebar appears, into which you can add widgets.
    If you add any standard or third-party widgets to it and then execute jQuery code in the browser console on the home page of the site, console.log will show us the contents of the sidebar.
    If we add Opinion Stage Sidebar Widget to this sidebar then there will be a 500 error.
    In this case, the php error log will display information about the cause of the error:
    PHP Fatal error: Uncaught Error: Call to undefined function opinionstage_widget_placement ()
    Could you help us with this?
    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author opinion stage

    (@opinionstage)

    Hi there,
    Thanks for reporting, we will review this issue and get back to you,
    Best – O/S Team

    Hi there!

    We have sorted the issue, can you please upgrade your plugin to the latest version and verify that?

    Also when upgrading to latest version, you might encounter this error: https://www.ads-software.com/support/topic/19-0-4-upgrade-issue/

    Thanks!
    O/S Team.

    Thread Starter vivlad

    (@vivlad)

    Hello! Thanks for the quick response!

    We updated the widget to the latest version.
    But now we can not test it, because it can not be added to the sidebar.
    When we add the widget to the sidebar and specify the name of the widget, after clicking on the “Save” button it remains in the same mode:
    https://prnt.sc/kzaxs9
    Normal behavior for widgets – the button should switch to the “Saved” mode.
    If you then refresh the page, the widget disappears.
    If you look at the XHR query while saving the widget, you can see that the response is empty, and it should return the html code.
    The following entry appears in error.log:
    PHP Notice: Undefined index: opinionstage_widget-2 in [pathtofile] /wp-admin/includes/ajax-actions.php on line 2011, referer: [yoururl] /wp-admin/widgets.php

    We have tested it on two different fresh wordpress installation and behavior is the same

    Thanks

    • This reply was modified 6 years, 2 months ago by vivlad.
    Thread Starter vivlad

    (@vivlad)

    I can suggest a solution like this.
    plugin.php:

    /* Some fuctions moved here */
    require_once( plugin_dir_path( __FILE__ ).'includes/opinionstage-utility-functions.php' );
    require_once( plugin_dir_path( __FILE__ ).'includes/opinionstage-sidebar-widget.php' );
    add_action('widgets_init', 'opinionstage_init_widget');
    /* Some fuctions moved here */
    
    // Check if another OpinionStage plugin already installed and display warning message.
    if (opinionstage_check_plugin_available('opinionstage_popup')) {
    	add_action('admin_notices', 'opinionstage_other_plugin_installed_warning');
    } else {
    	if(  (function_exists('wp_doing_ajax') && wp_doing_ajax()) || (defined('DOING_AJAX')) ){
        // AJAX running, don't include anything.
    	}else{
    		//require_once( plugin_dir_path( __FILE__ ).'includes/opinionstage-utility-functions.php' );
    		require_once( plugin_dir_path( __FILE__ ).'includes/opinionstage-article-placement-functions.php' );
    		//require_once( plugin_dir_path( __FILE__ ).'includes/opinionstage-sidebar-widget.php' );
    
    		if ( is_admin() ) {
    			require( plugin_dir_path( __FILE__ ).'admin/init.php' );
    		} else {
    			require( plugin_dir_path( __FILE__ ).'public/init.php' );
    		}
    
    		//add_action('widgets_init', 'opinionstage_init_widget');
    		add_action('plugins_loaded', 'opinionstage_init');
    	}
    }

    I’m not sure that this is completely correct, but it seems it works.
    Thank you.

    Plugin Author opinion stage

    (@opinionstage)

    Great, thanks for suggesting that solution. Closing this issue or now, please free to open another one if you encounter more issues. Best – O/S Team

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Poll, Quiz not working in ajax.’ is closed to new replies.