Site logo

Archived topic

PHP error in hook element

1 reply · Started by Sean on December 21, 2020

Viewing posts 1–2 of 2

I'm trying to create a button that downloads a text file that is generated from a php script.

So far I have:

<?php //Generate text file on the fly
 
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=savethis.txt");
 
// do your Db stuff here to get the content into $content
print "This is some text...";
print $content;
?> 

If I use a hook to show this after the content on a page I get the following error:

Warning: Cannot modify header information - headers already sent by (output started at /home/onecards/public_html/wp-includes/class.wp-styles.php:290) in /home/onecards/public_html/wp-content/plugins/gp-premium/elements/class-hooks.php(196) : eval()'d code on line 3

Warning: Cannot modify header information - headers already sent by (output started at /home/onecards/public_html/wp-includes/class.wp-styles.php:290) in /home/onecards/public_html/wp-content/plugins/gp-premium/elements/class-hooks.php(196) : eval()'d code on line 4

If I put the code into a .php file and call that with a href link it works.

Thanks!

Hi there,

Hooks aren't meant to be used with PHP like this - you need to use a custom .php file instead.

Hooks are built for displaying elements on the front-end of your website. If you need to output content from a file, you can look into a function like file_get_contents().

Let us know if you have any other questions :)

This archived topic is closed to new replies.