[wp-hackers] Plugin custom page

Chris Taylor - stillbreathing.co.uk chris at stillbreathing.co.uk
Wed Nov 21 08:42:28 UTC 2012


Hi Mike,

Many thanks, but that isn't going to solve my problem either! Here's a
basic workflow for a "open" voucher:

1) The user creates a voucher that is available to anyone (i.e. it
doesn't require email registration to download)
2) The user puts the shortcode for that voucher on a page
3) A visitor clicks the link the shortcode generates (/?voucher=abc123)
4) The visitor downloads the resulting PDF file

And here's the workflow for a "closed" voucher:

1) The user creates a voucher that requires email registration to download
2) The user puts the shortcode for that voucher on a page
3) A visitor clicks the link the shortcode generates
(/?voucher=abc123) and sees the email registration form
4) The visitor enters their name and email address; the plugin then
creates a unique code for them and emails the visitor a link
5) The visitor clicks the link in the email
(/?voucher=abc123&downloadcode=xyz987)
6) The visitor downloads the resulting PDF file

So for step 3 of the process I'm using template_redirect to see if a
voucher is being requested. If it is, and it's a valid voucher ID, and
the voucher is "open", then the plugin generates a PDF and hands it
back to the HTTP request for download. If it is a "closed" voucher
then a form needs to be displayed.

I suppose, if this is getting really tricky, I could redirect to a
custom page at step 3 for a "closed" voucher. Therefore the process
would be like this:

3) The visitor clicks the link the shortcode generates (/?voucher=abc123)
4) The plugin sees that the voucher requires email registration and
redirects the visitor to /voucher-registration?voucher=abc123 which
then displays the email registration form
5) etc...

In that case the plugin needs to register a custom URL, which I
believe can be done with the WP_Rewrite class. However would that work
if pretty permalinks were not enabled?

Many thanks for the continuing help,

Chris


On Tue, Nov 20, 2012 at 11:44 PM, Mike Little <wordpress at zed1.com> wrote:
> OK. I re-read your orginal post and understand what you are trying to do.
>
> A quick and dirty solution is to use a shortcode.
> create a page with that shortcode in it.
>
> In the shortcode handler, do your processing.
> pseudo code:
>
> add_shortcode( 'voucher', 'my_voucher_shortcode_handler' );
>
> function my_voucher_shortcode_handler( $atts, $content = null, $code = '' )
> {
>  if ( isset( $_POST['name'] ) && isset( $_POST['email'] ) && isset(
> $_POST['voucher_code'] ) ) {
> //validate and
>  return 'pdf download link';
> }
> if ( isset( $_GET['voucher'] ) ) {
>  $voucher_code = intval( $_GET['voucher'] ); // validate this properly
> if ( need_login( $voucher_code ) ) {
>  // output login form with voucher_code in hidden field
> return get_login_form( $voucher_code );
>  } else {
> return 'pdf download link';
> }
>  }
> return 'some default output';
> }
>
> Mike
> --
> Mike Little
> http://zed1.com/
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list