Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Site plugin for essa.org.uk
- Description: Site specific code for essa.org.uk
- Version: 0.1
- Author: Plain Sailing Web Solutions
- Author URI: https://plainsailingweb.com
- https://eventespresso.com/wiki/customize-checkout-registration-button-text/
- for changing the Proceed to Payment Options, Finalize Registration, Update Attendee Information buttons text
- Also deals with changing View Details (on event list page) and Register Now (on single event pages)
- http://eventespresso.com/wiki/ee4-multiple-event-registration-add-on/#customizations
- Deals with Event Cart terminology
- https://gist.github.com/joshfeck/4028f3345d69bd312862b64b94f07e26
- */
- class essaChanges
- {
- //
- // CLASS ATTRIBUTES
- // field names for Event Espresso registration
- private $address;
- private $address2;
- private $city;
- private $state;
- private $country;
- private $zip;
- private $phone;
- private const MOBILE_PHONE_NUMBER = 'Mobile Phone Number';
- private const GROUP_NAME = 'Name of Scout/Guide/Youth Group if applicable';
- private $custom_questions_to_populate;
- //
- // array for the user data held by wp-members plugin
- private $wpmem_fields;
- //
- // field values for Event Espresso registration
- private $address_value;
- private $address2_value;
- private $city_value;
- private $state_value;
- private $country_iso2_value = 'GB'; // we want to default the country field as we can't remove it.
- private $zip_value;
- private $phone_value;
- private $mobile_phone_value;
- private $group_name_value;
- //
- /**
- * Class constructor.
- */
- final public function __construct()
- {
- # Enable customisation of the CSS in the EE admin screens
- # add_action('admin_enqueue_scripts', array($this,'custom_css_for_ee_admin', 20) );
- #
- # Do not show the admin bar unless the user has administrator role
- add_action('after_setup_theme', array($this,'remove_admin_bar') );
- #
- # Customise the page shown after log in
- # add_filter( 'wpmem_login_redirect', array($this,'my_login_redirect'), 10, 2 );
- #
- # Customise the forgotten password link
- add_filter( 'wpmem_forgot_link', array($this,'my_forgot_link') );
- #
- # Customise the text displayed if you attempt to purchase an event and are not logged in
- add_filter( 'gettext', array($this,'tw_ee_mycustom_filter_gettext'), 10, 3 );
- #
- # Customise the text of the submit buttons in the checkout registration process
- # add_filter( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
- # array($this,'ee_spco_submit_button_text'), 10, 2 );
- #
- # Get the value for certain fields from the user record
- add_filter( 'FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value',
- array($this,'jf_filter_address_answer_for_wpuser'), 10, 4 );
- #
- # This should retrieve previous answer value for emergency contact information from previous registrations
- add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args',
- array($this,'my_question_input'), 10, 4);
- #
- # Renaming the screens for wp-members plugin to Account to avoid confusion with registering for an event
- add_filter( 'wpmem_default_text', array($this, 'my_text_for_wp_members') );
- #
- $this->custom_questions_to_populate = array
- ( self::GROUP_NAME
- , self::MOBILE_PHONE_NUMBER
- , 'Emergency Contact Name (15)'
- , 'Emergency Contact Phone Number (16)'
- , 'Emergency Contact Relationship (17)'
- );
- }
- #
- # PRIVATE CLASS METHODS
- private function user_data()
- {
- if ( count($this->wpmem_fields) == 0)
- {
- $this->wpmem_fields = WP_Members_User::user_data();
- #
- $this->address_value = $this->wpmem_fields["billing_address_1"];
- $this->address2_value = $this->wpmem_fields["billing_address_2"];
- $this->city_value = $this->wpmem_fields["billing_city"];
- $this->state_value = $this->wpmem_fields["billing_state"];
- $this->zip_value = $this->wpmem_fields["billing_postcode"];
- $this->phone_value = $this->wpmem_fields["billing_phone"];
- #
- $this->mobile_phone_value = $this->wpmem_fields["mobile_phone_number"];
- $this->group_name_value = $this->wpmem_fields["group_name"];
- }
- return $wpmem_fields;
- }
- #
- # CLASS METHODS
- public function custom_css_for_ee_admin()
- {
- $css_txn = '.transactions .column-TXN_ID {
- width: 8%
- }
- .transactions .column-TXN_timestamp {
- width: 16%;
- }
- .transactions .column-actions {
- width: 16%;
- }';
- wp_add_inline_style('espresso_txn', $css_txn);
- #
- $css_event = 'select#venue {display:none;}';
- wp_add_inline_style('events-admin-css', $css_event);
- }
- #
- public function my_text_for_wp_members( $text )
- {
- $text['login_heading'] = 'Account holder log in';
- $text['register_link_before'] = '';
- $text['register_link'] = '';
- $text['profile_edit'] = 'Edit my Account';
- $text['profile_heading'] = 'Edit my Account';
- $text['profile_submit'] = 'Update Account';
- $text['register_submit'] = 'Create Account';
- $text['register_heading'] = 'New Account Creation';
- $text['success'] = 'Congratulations! Your account was created successfully.<br /><br />You may now log in using the password you entered. It has also been emailed to you.';
- return $text;
- }
- public function remove_admin_bar()
- {
- if ( !current_user_can('administrator') && !is_admin() )
- {
- show_admin_bar(false);
- }
- } # end remove_admin_bar
- #
- public function my_login_redirect( $redirect_to, $user_id )
- {
- return home_url( '/registration-checkout/?event_cart=view#checkout' );
- } # end my_login_redirect
- #
- public function my_forgot_link( $str )
- {
- return get_site_url() . '/forgotten-password/';
- } # end my_forgot_link
- #
- # Customise the text db2_field_display_size(stmt, column)ed if you attempt to purchase an event and are not logged in
- public function tw_ee_mycustom_filter_gettext( $translated, $original, $domain )
- {
- // This is an array of original strings
- // and what they should be replaced with
- $strings = array(
- 'The event you have selected requires logging in before you can register. You can %sregister for an account here%s if you don\'t have a login.' =>
- 'To purchase the event(s) you have selected, you need to be logged in to your account. Please enter your account username and password to log in. If you don\'t already have an account, please click "Create an Account".<br /><br /><button>%sCreate an Account%s</button><br /><br />',
- );
- #
- # See if the current string is in the $strings array
- # If so, replace its translation
- if ( isset( $strings[$original] ) ) {
- # This accomplishes the same thing as __()
- # but without running it through the filter again
- $translations = get_translations_for_domain( $domain );
- $translated = $translations->translate( $strings[$original] );
- }
- return $translated;
- } # end tw_ee_mycustom_filter_gettext
- #
- # Customise the button text for buttons in the Checkout/registration process
- public function ee_filter_spco_submit_button_text( $submit_button_text, EE_Checkout $checkout )
- {
- if ( ! $checkout instanceof EE_Checkout ||
- ! $checkout->current_step instanceof EE_SPCO_Reg_Step ||
- ! $checkout->next_step instanceof EE_SPCO_Reg_Step )
- {
- return $submit_button_text;
- }
- // $checkout->revisit - whether this is the first time thru SPCO or not : false = first visit, true = return visit (ie repay or edit)
- // details for the *current* reg step
- // $checkout->current_step->slug(); ex: 'attendee_information', 'payment_options', 'finalize_registration'
- // $checkout->current_step->name();
- // details for the NEXT SPCO Reg Step that follows the CURRENT SPCO Reg Step
- // $checkout->next_step->slug();
- // $checkout->next_step->name();
- if ( $checkout->next_step->slug() == 'finalize_registration' )
- {
- $submit_button_text = __( 'Go to Finalise Registration step', 'event_espresso' );
- }
- else if ( $checkout->current_step->slug() == 'attendee_information' && $checkout->revisit )
- {
- $submit_button_text =
- sprintf( __( 'Welcome back, you can go to %1$s', 'event_espresso' ), $checkout->next_step->name() );
- }
- else if ( $checkout->next_step->slug() == 'attendee_information' )
- {
- $submit_button_text = sprintf( __( 'Login and go to %1$s step', 'event_espresso' ), $checkout->next_step->name() );
- }
- else {
- $submit_button_text = sprintf( __( 'Finish %1$s and go to %2$s', 'event_espresso' ), $checkout->current_step->name(), $checkout->next_step->name() );
- }
- return $submit_button_text;
- } # end ee_filter_spco_submit_button_text
- #
- # PRIVATE METHOD CALLED BY THE NEXT FUNCTION
- private function getSystemQuestionNames()
- {
- if( class_exists( 'EED_WP_Users_SPCO' ) )
- {
- global $current_user;
- $attendee = EED_WP_Users_SPCO::get_attendee_for_user( $current_user );
- if( defined( 'EEM_Attendee::system_question_address' ) )
- {
- $this->address = EEM_Attendee::system_question_address;
- $this->address2 = EEM_Attendee::system_question_address2;
- $this->city = EEM_Attendee::system_question_city;
- $this->state = EEM_Attendee::system_question_state;
- $this->country = EEM_Attendee::system_question_country;
- $this->zip = EEM_Attendee::system_question_zip;
- $this->phone = EEM_Attendee::system_question_phone;
- }
- }
- } # end getSystemQuestionNames
- #
- public function jf_filter_address_answer_for_wpuser(
- $value, EE_Registration $registration, $question_id, $system_question_name = null )
- {
- // only fill for primary registrant and not in admin area
- if ( ! $registration->is_primary_registrant() || is_admin() )
- {
- return $value;
- }
- //
- if ( empty($value) )
- {
- $this->getSystemQuestionNames();
- //
- // first, see if we can get the values from wp-members then test whether there is any data. For a user who
- // registered before this upgrade and has not amended their user profile, this may be true. In this case,
- // get the system fields values from a previous registration
- $this->wpmem_fields = $this->user_data();
- if ( count($this->wpmem_fields) == 0 )
- {
- if ( $current_user instanceof WP_User && $attendee instanceof EE_Attendee )
- {
- $this->address_value = $attendee->get( 'ATT_address' );
- $this->address2_value = $attendee->get( 'ATT_address2' );
- $this->city_value = $attendee->get( 'ATT_city' );
- $this->state_value = $attendee->get( 'STA_ID' );
- $this->zip_value = $attendee->get( 'ATT_zip' );
- $this->phone_value = $attendee->get( 'ATT_phone' );
- }
- }
- //
- switch ( $system_question_name )
- {
- case $this->address :
- $value = $this->address_value;
- break;
- case $this->address2 :
- $value = $this->address2_value;
- break;
- case $this->city :
- $value = $this->city_value;
- break;
- case $this->country :
- $value = $this->country_iso2_value;
- break;
- case $this->state :
- $value = $this->state_value;
- break;
- case $this->zip :
- $value = $this->zip_value;
- break;
- case $this->phone :
- $value = $this->phone_value;
- break;
- default:
- }
- }
- return $value;
- } # end jf_filter_address_answer_for_wpuser
- #
- /**
- * Code snippet that extends the Event Espresso WP User integration addon,
- * so that we also remember the user's last answer to custom questions too.
- */
- function my_question_input(
- $input_args, EE_Registration $registration = null, EE_Question $question = null, EE_Answer $answer = null )
- {
- /**
- For this section we only want to fill in the mobile phone number and the group name from $this->wpmem_fields
- We can leave the emergency contact details being populated as they are from previous registrations
- BUT we need to ensure we do not pre-populate the following question:
- $question = #I agree to ESSA's booking terms & conditions (23)#
- nor any of the participant information
- */
- if ( is_admin() ||
- ! in_array($question->display_text(), $this->custom_questions_to_populate) ||
- ! $registration->is_primary_registrant() ||
- $question->system_ID )
- {
- return $input_args;
- }
- #
- if ( class_exists( 'EED_WP_Users_SPCO' ) )
- {
- switch ($question->display_text() )
- {
- case self::MOBILE_PHONE_NUMBER :
- $input_args[ 'default' ] = $this->mobile_phone_value;
- break;
- case self::GROUP_NAME :
- $input_args[ 'default' ] = $this->group_name_value;
- break;
- default:
- # this code executes for the three emergency contact questions
- global $current_user;
- $attendee = EED_WP_Users_SPCO::get_attendee_for_user( $current_user );
- if ( $question instanceof EE_Question &&
- $registration instanceof EE_Registration &&
- $attendee instanceof EE_Attendee )
- {
- $prev_answer_value = EEM_Answer::instance()->get_var(
- array(
- array(
- 'Registration.ATT_ID' => $attendee->ID(),
- 'QST_ID' => $question->ID()
- ),
- 'order_by' => array(
- 'ANS_ID' => 'DESC'
- ),
- 'limit' => 1
- ),
- 'ANS_value' );
- }
- #
- if ( $prev_answer_value )
- {
- $field_obj = EEM_Answer::instance()->field_settings_for( 'ANS_value' );
- $prev_answer_value = $field_obj->prepare_for_get( $field_obj->prepare_for_set_from_db( $prev_answer_value ) );
- $input_args[ 'default' ] = $prev_answer_value;
- }
- break;
- } # end switch
- }
- return $input_args;
- } # end my_question_input
- } # end class essaChanges
- $essaChanges = new essaChanges();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement