Making WordPress.org

Ticket #441: camptix-require-login.diff

File camptix-require-login.diff, 2.8 KB (added by iandunn, 11 years ago)
  • addons/require-login.php

     
     1<?php
     2
     3/**
     4 * Require attendees to login to the website before purchasing tickets.
     5 */
     6class CampTix_Require_Login extends CampTix_Addon {
     7
     8        /**
     9         *
     10         */
     11        public function camptix_init() {
     12                add_action( 'template_redirect', array( $this, 'block_unauthenticated_actions' ), 8 );    // before CampTix_Plugin->template_redirect()
     13                add_filter( 'tix_action_login',  array( $this, 'login' ) );
     14        }
     15
     16        /**
     17         * Inject a step into the checkout workflow that asks the user to login
     18         */
     19        public function login( $shortcode_contents ) {
     20
     21                // if logged in, redirect to checkout action w/ the same data they submitted
     22                // if not, save the data in a hidden field and display a login form
     23                // if successful login, redirect to camptix w/ saved data
     24                // looks like there's already a mechanism to let 3rd party forms initiate checkout, so use that
     25                // if failed login, repeat until successful
     26
     27                $shortcode_contents = 'login';
     28
     29                return $shortcode_contents;
     30        }
     31
     32        /**
     33         * Block all normal CampTix checkout actions if the user is logged out
     34         *
     35         * If a logged-out user attempts to submit a request for any action other than 'login',
     36         * it will be overriden with the 'login' action so that they first have to login.
     37         */
     38        public function block_unauthenticated_actions() {
     39                if ( ! is_user_logged_in() && isset( $_REQUEST['tix_action'] ) && 'login' != $_REQUEST['tix_action'] ) {
     40                        //$_GET['tix_action'] = $_POST['tix_action'] = $_REQUEST['tix_action'] = 'login';
     41
     42                        wp_safe_redirect( wp_login_url( site_url( $_SERVER['REQUEST_URI'] ) ) );
     43                        exit();
     44
     45                        // need to make default login message for standalone camptix installs, but filter it so wordcamp.org can override with special instructions
     46
     47                        // when they come back, go to attendee_info to start over, and try to auto select ticket quantities?
     48                                // maybe have to go to the page they requested b/c could be access/edit token etc
     49
     50                        // what about edit token and access token, etc. should those be allowed without login?
     51                        // should you save the previous action and post/get, then restore it once then login? v2 maybe
     52                }
     53        }
     54}
     55
     56camptix_register_addon( 'CampTix_Require_Login' );
  • camptix.php

     
    66936693
    66946694                        // 'logging-file'  => $this->get_default_addon_path( 'logging-file.php' ),
    66956695                        // 'logging-json'  => $this->get_default_addon_path( 'logging-file-json.php' ),
     6696                        // 'require-login' => $this->get_default_addon_path( 'require-login.php' ),
    66966697                ) );
    66976698
    66986699                foreach ( $default_addons as $filename )