[wp-hackers] Plugin custom page

Bryan Gentry bryangentry at gmail.com
Mon Nov 19 14:58:28 UTC 2012


You will want to use the template_redirect hook:

          add_action( 'template_redirect', 'voucher_template' );
          function voucher_template() {
              //check your query variables to determine whether a voucher
is being displayed.
             if ( $voucher_is_being_displayed ) {
                       add_filter( 'the_content', 'voucher_content' );

Then you create a function that accepts the content and changes it

             function voucher_content($content) {
                          //now add or change whatever you want to $content
                          return $content;

My Easy FAQ With Expanding Text plugin uses this, as does an unpublished
plugin that allows one of my clients to create event pages.So far, this
does the trick and is working with several different themes.

Bryan Gentry

> Date: Mon, 19 Nov 2012 08:35:02 +0000
> From: "Chris Taylor - stillbreathing.co.uk"
>         <chris at stillbreathing.co.uk>
> Subject: [wp-hackers] Plugin custom page
> To: wp-hackers at lists.automattic.com
> Message-ID:
>         <CAOb_bYY4qP2ojOHSno1mgs2WHbN=jsgjfPbKJPRiT4n4D=
> t2XQ at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
> Hi,
> I'm currently updating my VoucherPress plugin which allows WP admins
> to create vouchers that visitors can download. One of the optional
> features of a voucher is to require the user to register their name
> and email address to get a link to download the voucher. When the user
> clicks a link to the voucher they should see a form asking for their
> name and email address. If the voucher doesn't require their email
> then they get the PDF immediately.
> To support any template I need the form to be output using something
> like the "the_content" filter, so it appears as if it's a real page.
> The URL which is requested is something like
> mysite.com/?voucher=abc123. This looked like it was going to work,
> however when the front page is set to display multiple posts each post
> gets its content filtered leading to multiple voucher forms on the
> page. What would be the best way to handle this kind of custom page in
> my plugin, seeing as just calling get_header() and get_footer() (which
> is what the current version of the plugin does) may miss out large
> parts of a templates design?
> 1) Use "the_content" and somehow break the loop?
> 2) Use a custom URL (e.g. "mysite.com/voucherpress/abc123") and map
> that to the page/single/index page?
> 3) Something else?
> Many thanks,
> Chris
> ------------------------------
> Message: 7
> Date: Mon, 19 Nov 2012 04:47:36 -0500
> From: Andrew Nacin <wp at andrewnacin.com>
> Subject: Re: [wp-hackers] Accessing Update Check API Outside of
>         WordPress
> To: wp-hackers at lists.automattic.com
> Message-ID:
>         <
> CAP29PvhLGM++K5qKnKK+f6zwZ_xUyMfHvk_LZ+EK+sM+ZXFkyA at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
> On Sun, Nov 11, 2012 at 1:01 AM, Mark Smith <mark.smith1187 at yahoo.com
> >wrote:
> > I took a look at update.php to see how WordPress does it but the myriad
> of
> > WordPress functions seems to just confuse me as to what exactly is being
> > posted to the API endpoints
> > http://api.wordpress.org/plugins/update-check/1.0/ and
> > http://api.wordpress.org/themes/update-check/1.0/. Can anyone explain to
> > me what eactly needs to be posted to get the current version of each
> plugin
> > and theme.
> If you use the /info/ endpoint for a single plugin, you'll end up with the
> current version. The update-check endpoints are designed for checking a
> bunch of plugins en masse, and for when you may not know the actual slug of
> the plugin. (It does some fairly complex matching using pretty much every
> plugin header to make sure it finds the right plugin.)
> Example: http://api.wordpress.org/plugins/info/1.0/debug-bar.json. Other
> accepted formats include .xml and .php.
> ------------------------------
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
> End of wp-hackers Digest, Vol 94, Issue 28
> ******************************************

*Bryan Gentry*
Web designer, writer, editor

More information about the wp-hackers mailing list