Forums

Widget Logic and Samsarin PHP 1 (3 posts)

  1. cmalamed
    Member
    Posted 6 months ago #

    Greetings,
    First, let me say that Widget Logic is brilliant and is allowing me to avoid having to make separate sidebars for different pages. Thanks very much.

    Since installing Widget Logic I installed the Samsarin PHP 1 plugin, which creates a widget that can handle PHP. The Widget Logic field does not show up in this plugin. Did I do something wrong? How can I use Widget Logic to control this php widget too? Thanks in advance.

  2. alanft
    Member
    Posted 6 months ago #

    I see this problem too - though I don't use samsarin for PHP. i use otto's older PHP code widget http://wordpress.org/extend/plugins/php-code-widget/

    i'll have a poke around to see why the samsarin widget does this

  3. alanft
    Member
    Posted 6 months ago #

    the plugin is trying to stay backwards-compatible so is using an old approach to multiple instances of a widget, and is registering the widget twice. the second time every time the widget admin interface loads just in case the number of widgets has changed, and this is AFTER widget logic has stepped in to add its controls, so this gets reset for that widget.

    i don't quite know how to make code like this work 100% but one workaround is to make it only do the re-register when the number of widgets changes. change

    function spw_admin_setup() {
        $options = get_option('samsarin_php_widget');
        if (isset($_POST['samsarin_php_widget_number_submit'])) {
            $number = (int) $_POST['samsarin_php_widget_number'];
            if ( $number < 1 ) $number = 1;
            if ($number > SPW_MAXWIDGETS) $number = SPW_MAXWIDGETS;
            $options['number'] = $number;
        }
    
        update_option('samsarin_php_widget', $options);
        spw_register_plugin($options['number']);
    }

    to

    function spw_admin_setup() {
        $options = get_option('samsarin_php_widget');
        if (isset($_POST['samsarin_php_widget_number_submit'])) {
            $number = (int) $_POST['samsarin_php_widget_number'];
            if ( $number < 1 ) $number = 1;
            if ($number > SPW_MAXWIDGETS) $number = SPW_MAXWIDGETS;
            $options['number'] = $number;
            update_option('samsarin_php_widget', $options);
            spw_register_plugin($options['number']);
        }
    
    }

    when you set the number of widgets you lose the widget logic field, but if you then reload the page it's back.

Reply

You must log in to post.

About this Topic