Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm writing a plugin to do some specific business logic - edit records for authenticated users, etc.

Rather than having the overhead of a form processing plugin that uses stuff in template tags. I've created a rewrite do redirect like:

/mylisting/909  ->/wp-content/themes/myplugin/edit.php?id=909

Which seems to make sense as I'm keeping the very specific logic to an individual plugin.

The problem is, I want to use my theme within my plugins files as they'll be output in the site's frontend and as such I want them to have the same look and feel.

So I've tried get_header(); include('../mytheme/header.php')

As well as including wp-load.php

...None of which work (I get fatal errors)

Any help?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I've created a rewrite do redirect like:

/mylisting/909  ->/wp-content/themes/myplugin/edit.php?id=909

Which seems to make sense as I'm keeping the very specific logic to an individual plugin.

There is a better way: Create an endpoint, use your code in a callback handler for the new URL. You get the whole theme environment for free here: get_header(), sidebars, menus etc.
Do not forget to call exit; at the end of your endpoint, othrwise WordPress will use the theme files again. :)

The plugin URI is never a good address to edit or create content: It might be on another domain where the cookies are available, and no user is ever logged in.

share|improve this answer
    
That'll do nicely, just tested and this does exactly what I want. Thanks! –  gravy Nov 27 '12 at 21:54

The problem is, I want to use my theme within my plugins files as they'll be output in the site's frontend and as such I want them to have the same look and feel.

You already have your answer. You're trying to wrap WordPress and it's theme around your plugin rather than working within the designed mode of operation.

If you already have your plugin why don't you simply write a shortcode handling function to output your page? That way you have all of the functionality of WordPress, the look and feel of your theme; but you also follow WordPress standards and convention.

For a good introduction to writing plugins take a look at the WordPress Codex, it has links to tutorials at the bottom.

share|improve this answer
    
The thing with this approach is that I'd prefer to keep this functionality separated from the theme, plus it feels like bad practice putting the controller-like functionality into the theme. But appreciate your input. –  gravy Nov 27 '12 at 21:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.