Okay
  Public Ticket #1627574
Serialized PHP - wp-load
Closed

Comments

  •  1
    Entrust_ICT started the conversation

    Hi All

    I've been using the Serialized PHP Array option and it is working well. I recently needed to get access to the WP API so used the include "wp-load" statement in my PHP file. As soon as I do I get the "Table in data source has no rows" error. 

    The php file works  via the browser and outputs the array correctly. 

    To debug I've tried making a static php array with just one row and a couple of columns. Executing via the browser with and without the wp-load statement outputs the array correctly.

    If I comment out the wp-load I can import the table but as soon as I uncomment I get the "no rows" error. 

    I've even tried passing WP User ID a PHP Session variable and via a cookie. Both execute correctly in the browser but produce the no rows error in wpdatatables. 

    I have a second WP test site with just wpdatatables, Elementor pro and Gravity Forms and the php file loads correctly with the wp-load statement! So it is definitely a conflict with somerthing on my main site. 

    I tried disabling all plugins on the main site, removing functions.php and changing the theme but still get the error. 

    I have used the Query Monitor plugin to see what errors generate when I try to import the table. It produces a the following PHP error:

    wp-content/plugins/wpdatatables/source/class.wpdatatable.php:2442
    unserialize(): Error at offset 0 of 66 bytes
    at location: 


    Does anyone have any suggestions as to what to do next? 

    thanks in advance.

    Jeff

  •  1
    Entrust_ICT replied

    Forgot to mention that with the wp-load statement I tried relative and absolute paths as well as creating a test php file in the same folder as wp-load.php and using no path. 

  •  471
    Isidora replied

    Hi Entrust_ICT,

    Thank you for your purchase.

    Can you please provide me a link of that script so I can debug it in our local environment and see what cause the issue?

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

    You can try our wpDataTables add-ons before purchase on these sandbox sites:

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables

  •  1
    Entrust_ICT replied

    Hi Milan

    It's basically just a  line in functions.php (to store a session variable) and a few lines in the Serialized PHP to retrieve the session variable. (I don't think the wp-load method to get the current WP user will work as the Serialized script seems to run in a different context / namespace as the normal user).

    So in functions.php I have:

    $_SESSION["Test"] = "green"; 

    And in the Serialized PHP I have

    $var1 = $_SESSION["Test"];

    $Test_Array[] = array(  'Col1' => 1,  'Col2'' => $var1,);

    echo serialize ($Test_Array);

    I think again - because the wpdatatable function is running in a different context - it can't see that session variable. 

    If I provide a Session Name in functions.php e.g.

    session_id("Test_Session");

    session_start();

    $_SESSION["Test"] = "green";


    and then in the Serialized PHP

    session_id("Test_Session");

    session_start();

    $var1 = $_SESSION["Test"];

    that actually works and I can see $var1 in the column. But that method means every user visiting the site sees the same session so it's very insecure.

    I saw in an older ticket that you were looking at having Placeholder variables for Serialized PHPs in v 2.1. 

    Any update on that? As then I could just use %CURRENT_USER_ID% 


    thanks

  •  471
    Isidora replied

    Hi Entrust_ICT,

    You can take a look with some solution on this ticket.

    Placeholders works with other table types (JSON, XML, PHP array) from version 2.2. You can check our changelog in our documentation.

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

    You can try our wpDataTables add-ons before purchase on these sandbox sites:

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables

  •  1
    Entrust_ICT replied

    Hi Milan

    That pretty much solved all my problems. Thank you. 

  •  1
    Entrust_ICT replied

    Sorry, quick question. What is the syntax for accessing the placeholder in PHP?


  •  1
    Entrust_ICT replied

    Hi Milan

    I can't access that ticket link you sent previously (in case the syntax is there). It just bounces back to my tickets.

  •  471
    Isidora replied

    Hi Entrust_ICT,

    Sorry about that, am not sure what happens.

    Here you go https://tmsplugins.ticksy.com//ticket/1512255

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

    You can try our wpDataTables add-ons before purchase on these sandbox sites:

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables