This is because you directly call a PHP file from within your plugin folder. This is bad for two reasons, the first being that some people block direct access to PHP files inside the wp-content
folder. The second is you need to include wp-load.php
to access the WordPress API.
Instead of linking to…
site_url().""."/wp-content/plugins/Printer-Friendly-WP/print.php?id=page_id="."". get_the_ID()`
… which is a direct link and vulnerable to breaking, simply add a query arg to the current post permalink…
add_query_arg( 'print-page', true, get_permalink() )
… and then check to see if the URL contains the print-page
query arg before the template is loaded:
function load_printed_page() {
if ( ! get_query_arg( 'print-page' ) || ! $postid = get_the_ID() )
return;
query_posts('p='.$postid)
if (have_posts()) :
while (have_posts()) : the_post(); ?>
...
endwhile; endif;
}
add_action( 'template_redirect', 'load_printed_page' );
Also, you should use WP_Query
or get_posts()
instead of query_posts