Using "Simple PHP" plugin generates errors

Home Forums Support Using "Simple PHP" plugin generates errors

Home Forums Support Using "Simple PHP" plugin generates errors

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #208037
    Nik Bhatt

    I found the article in the knowledge base about adding PHP. I downloaded the Simple PHP plugin, and added

    echo “This is our custom template!”;

    I tried it with and without a closing ?>

    This is what I get now:

    This is our custom template!
    Warning: Cannot modify header information – headers already sent by (output started at /home/bsa566/public_html/wp-content/plugins/generate-simple-php/custom.php:8) in /home/bsa566/public_html/wp-content/plugins/wpclef/includes/lib/wp-session/class-wp-session.php on line 130

    Warning: Cannot modify header information – headers already sent by (output started at /home/bsa566/public_html/wp-content/plugins/generate-simple-php/custom.php:8) in /home/bsa566/public_html/wp-content/plugins/custom-database-tables/lib/webapis.php on line 131

    Warning: Cannot modify header information – headers already sent by (output started at /home/bsa566/public_html/wp-content/plugins/generate-simple-php/custom.php:8) in /home/bsa566/public_html/wp-content/plugins/custom-database-tables/lib/webapis.php on line 132

    Warning: Cannot modify header information – headers already sent by (output started at /home/bsa566/public_html/wp-content/plugins/generate-simple-php/custom.php:8) in /home/bsa566/public_html/wp-content/plugins/custom-database-tables/lib/webapis.php on line 133

    Also, I am a little confused. I want to write some custom PHP (custom database table access) on just a subset of the pages, not all of them — is this the right way to do it?

    #208038
    Tom
    Lead Developer
    Lead Developer

    Can you paste the entire contents of your simple PHP code into a pastebin and show me?: http://pastebin.com/

    Looks like there might be an error in there.

    #208548
    Nik Bhatt

    I have pasted it to <http://pastebin.com/Fd0ESh8M&gt;

    #208574
    Tom
    Lead Developer
    Lead Developer

    Not seeing anything wrong with it, but it just might be that you’re echoing code which can interfere with other code.

    Try this instead:

    add_action( 'generate_before_header','generate_test_function' );
    function generate_test_function()
    {
        echo 'This is a test.';
    }
    #208590
    Nik Bhatt

    OK – I tried that and I don’t get any errors now. Thanks!

    However, if I call that method (generate_test_function()) I get the same problem. It looks like it’s because the script code is injected PRIOR to the <html> tag (see below). That seems bad, but not fatal. Assuming it’s okay, this brings up my other question. I can define functions here, but how do I call them (and only on some pages, not all of them)? Calling them in the simple PHP causes an error. In my use case, I want to provide a search UI against some custom database tables, but only for certain pages, not all.

    Thanks.

    –Nik
    ———–

    This is a test.<br />
    <b>Warning</b>: Cannot modify header information – headers already sent by (output started at /home/bsa566/public_html/wp-content/plugins/generate-simple-php/custom.php:11) in <b>/home/bsa566/public_html/wp-content/plugins/wpclef/includes/lib/wp-session/class-wp-session.php</b> on line <b>130</b><br />
    <!DOCTYPE html>
    <!–[if IE 8]>
    <html xmlns=”http://www.w3.org/1999/xhtml&#8221; class=”ie8 wp-toolbar” lang=”en”>
    <![endif]–>
    <!–[if !(IE 8) ]><!–>
    <html xmlns=”http://www.w3.org/1999/xhtml&#8221; class=”wp-toolbar” lang=”en”>
    <!–<![endif]–>
    <head>
    <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
    <title>Edit Plugins ‹ — WordPress</title>
    <script type=”text/javascript”>

    #208592
    Tom
    Lead Developer
    Lead Developer

    Calling a function directly in that file will cause errors, as that file is for defining functions, or hooking them into the template.

    If you define a function in there, you need to then call that function inside a template file, inside a function which hooks it into the template (my example), or in GP Hooks.

    Hope this helps ๐Ÿ™‚

    #213426
    Nik Bhatt

    A few questions. The answer may be the same for both ๐Ÿ™‚

    1) I find that some of my HTML that I put into PHP is being ignored when in Generate Press pages. For example, table borders are always present, the align attribute is ignored, as is colspan for a TD. They work fine if I just make plain HTML and open it in the same browser. How can I get those to work again?

    2) I have an IFRAME that runs some PHP code. Though I’ve turned off all the page attributes, like footer, sidebar, etc., I still get a thick gray background color at the bottom and the page contents are inset. Is there a way to have GP just show a page without any “GP stuff”? I need access to WordPress database calls so it can’t be a vanilla PHP somewhere random.

    #213468
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    1. This will remove the borders: https://generatepress.com/forums/topic/table-boarders/#post-129050

    The align attribute should be replaced with CSS.

    You can remove all of GP’s styling of borders with this CSS:

    table {
        border-collapse: initial;
        border-spacing: initial;
        border-width: initial;
    }
    
    table, td, th {
        border: initial;
    }

    2. Can you link me to the page so I can see?

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.