WordPress.org

Ready to get started?Download WordPress

Forums

PHP Code Widget
Running php dependent on includes outside of widget - doesn't work... (1 post)

  1. Erik
    Member
    Posted 3 years ago #

    I am trying to use the PHP Widget to run a script that is dependent on some other included files. But it appears that the php widget runs in a way that this isn't possible.

    Here is how I have it in a working state, the PHP widget basically has the following code in it:

    <?php
    include_once('variables.php');
    myDomain = $DOMAIN_ID;
    include_once('form_file.php');
    ?>

    This loads the variables file, declares the domain ID, and then loads the form_file.php in which the variables are placed.

    And then in a separate PHP widget, I have another included file for a different form, but it uses the same variables.php, so that widget contains

    <?php
    include_once('subscription_file.php');
    ?>

    This include will not run, but if I put them ALL in the same widget like this:

    <?php
    include_once('variables.php');
    myDomain = $DOMAIN_ID;
    include_once('form_file.php');
    include_once('subscription_file.php');
    ?>

    Then both of the included files run properly.

    But if I move the variables.php out of the widget and into the header of the theme, the rest of the scripts in the widget will not run.

    Also, if I try to run the widget twice with different includes, with the first widget looking like:

    <?php
    include_once('variables.php');
    myDomain = $DOMAIN_ID;
    include_once('form_file.php');
    ?>

    And then the second widget like

    <?php
    include_once('variables.php');
    myDomain = $DOMAIN_ID;
    include_once('subscription_file.php');
    ?>

    The 2nd instance of the widget doesn't run, and it doesn't matter if I use include_once or just include.

    I had wanted to have the variables in the header of my theme so that I could change the domain ID on my multisite install, and just use the widgets to load the form php files. But no matter how I set this up, all the code has to live inside the php widget or else it won't interact with any php includes in the header, or even in other php widgets.

    Is it possible to have something like an include in the header of your theme declare a bunch of variables, and then have those variables called in a PHP widget, or is the php widget just for running self contained scripts? I've tried both the php-exec widget and the Samsarin widget, the results are the same, I can't interact between php scripts that are outside of the widget.

    Do the php widgets process the code at a slightly different time than the rest of the page, and by the time the variables are ran the page has loaded already and they have no where to be called?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic