@@ -1,66 +1,66 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>'; |
| 3 | 3 | if ( |
| 4 | - ( is_single() && espresso_display_venue_in_event_details() ) |
|
| 5 | - || ( is_archive() && espresso_display_venue_in_event_list() ) |
|
| 4 | + (is_single() && espresso_display_venue_in_event_details()) |
|
| 5 | + || (is_archive() && espresso_display_venue_in_event_list()) |
|
| 6 | 6 | ) : |
| 7 | 7 | global $post; |
| 8 | - do_action( 'AHEE_event_details_before_venue_details', $post ); |
|
| 9 | - $venue_name = espresso_venue_name( 0, 'details', FALSE ); |
|
| 10 | - if ( empty( $venue_name ) && espresso_is_venue_private() ) { |
|
| 11 | - do_action( 'AHEE_event_details_after_venue_details', $post ); |
|
| 8 | + do_action('AHEE_event_details_before_venue_details', $post); |
|
| 9 | + $venue_name = espresso_venue_name(0, 'details', FALSE); |
|
| 10 | + if (empty($venue_name) && espresso_is_venue_private()) { |
|
| 11 | + do_action('AHEE_event_details_after_venue_details', $post); |
|
| 12 | 12 | return ''; |
| 13 | 13 | } |
| 14 | 14 | ?> |
| 15 | 15 | |
| 16 | 16 | <div class="espresso-venue-dv<?php echo espresso_is_venue_private() ? ' espresso-private-venue-dv' : ''; ?>"> |
| 17 | - <h4><strong><?php _e( 'Venue:', 'event_espresso' ); ?></strong> <strong> <?php echo $venue_name; ?></strong></h4> |
|
| 17 | + <h4><strong><?php _e('Venue:', 'event_espresso'); ?></strong> <strong> <?php echo $venue_name; ?></strong></h4> |
|
| 18 | 18 | <p><span class="smaller-text tags-links"><?php echo espresso_venue_categories(); ?></span></p> |
| 19 | -<?php if ( $venue_phone = espresso_venue_phone( $post->ID, FALSE )) : ?> |
|
| 19 | +<?php if ($venue_phone = espresso_venue_phone($post->ID, FALSE)) : ?> |
|
| 20 | 20 | <p> |
| 21 | - <span class="small-text"><strong><?php _e( 'Venue Phone:', 'event_espresso' ); ?></strong></span> <?php echo $venue_phone; ?> |
|
| 21 | + <span class="small-text"><strong><?php _e('Venue Phone:', 'event_espresso'); ?></strong></span> <?php echo $venue_phone; ?> |
|
| 22 | 22 | </p> |
| 23 | -<?php endif; ?> |
|
| 24 | -<?php if ( $venue_website = espresso_venue_website( $post->ID, FALSE )) : ?> |
|
| 23 | +<?php endif; ?> |
|
| 24 | +<?php if ($venue_website = espresso_venue_website($post->ID, FALSE)) : ?> |
|
| 25 | 25 | <p> |
| 26 | - <span class="small-text"><strong><?php _e( 'Venue Website:', 'event_espresso' ); ?></strong></span> <?php echo $venue_website; ?> |
|
| 26 | + <span class="small-text"><strong><?php _e('Venue Website:', 'event_espresso'); ?></strong></span> <?php echo $venue_website; ?> |
|
| 27 | 27 | </p> |
| 28 | 28 | <?php endif; ?> |
| 29 | -<?php if ( espresso_venue_has_address( $post->ID )) : ?> |
|
| 30 | - <strong><span class="dashicons dashicons-location-alt"></span><?php _e( 'Address:', 'event_espresso' ); ?></strong> |
|
| 31 | - <?php espresso_venue_address( 'inline' ); ?> |
|
| 32 | - <?php espresso_venue_gmap( $post->ID ); ?> |
|
| 29 | +<?php if (espresso_venue_has_address($post->ID)) : ?> |
|
| 30 | + <strong><span class="dashicons dashicons-location-alt"></span><?php _e('Address:', 'event_espresso'); ?></strong> |
|
| 31 | + <?php espresso_venue_address('inline'); ?> |
|
| 32 | + <?php espresso_venue_gmap($post->ID); ?> |
|
| 33 | 33 | <div class="clear"><br/></div> |
| 34 | -<?php endif; ?> |
|
| 34 | +<?php endif; ?> |
|
| 35 | 35 | |
| 36 | - <?php $VNU_ID = espresso_venue_id( $post->ID ); ?> |
|
| 37 | - <?php if ( is_single() ) : ?> |
|
| 38 | - <?php $venue_description = espresso_venue_description( $VNU_ID, FALSE ); ?> |
|
| 39 | - <?php if ( $venue_description ) : ?> |
|
| 36 | + <?php $VNU_ID = espresso_venue_id($post->ID); ?> |
|
| 37 | + <?php if (is_single()) : ?> |
|
| 38 | + <?php $venue_description = espresso_venue_description($VNU_ID, FALSE); ?> |
|
| 39 | + <?php if ($venue_description) : ?> |
|
| 40 | 40 | <p> |
| 41 | - <strong><?php _e( 'Description:', 'event_espresso' ); ?></strong><br/> |
|
| 42 | - <?php echo do_shortcode( $venue_description ); ?> |
|
| 41 | + <strong><?php _e('Description:', 'event_espresso'); ?></strong><br/> |
|
| 42 | + <?php echo do_shortcode($venue_description); ?> |
|
| 43 | 43 | </p> |
| 44 | - <?php endif; ?> |
|
| 44 | + <?php endif; ?> |
|
| 45 | 45 | <?php else : ?> |
| 46 | - <?php $venue_excerpt = espresso_venue_excerpt( $VNU_ID, FALSE ); ?> |
|
| 47 | - <?php if ( $venue_excerpt ) : ?> |
|
| 46 | + <?php $venue_excerpt = espresso_venue_excerpt($VNU_ID, FALSE); ?> |
|
| 47 | + <?php if ($venue_excerpt) : ?> |
|
| 48 | 48 | <p> |
| 49 | - <strong><?php _e( 'Description:', 'event_espresso' ); ?></strong><br/> |
|
| 49 | + <strong><?php _e('Description:', 'event_espresso'); ?></strong><br/> |
|
| 50 | 50 | <?php echo $venue_excerpt; ?> |
| 51 | 51 | </p> |
| 52 | - <?php endif; ?> |
|
| 53 | - <?php endif; ?> |
|
| 52 | + <?php endif; ?> |
|
| 53 | + <?php endif; ?> |
|
| 54 | 54 | </div> |
| 55 | 55 | <!-- .espresso-venue-dv --> |
| 56 | 56 | <?php |
| 57 | -do_action( 'AHEE_event_details_after_venue_details', $post ); |
|
| 57 | +do_action('AHEE_event_details_after_venue_details', $post); |
|
| 58 | 58 | else : |
| 59 | - if ( espresso_venue_is_password_protected() ) : |
|
| 59 | + if (espresso_venue_is_password_protected()) : |
|
| 60 | 60 | ?> |
| 61 | 61 | <div class="espresso-venue-dv espresso-password-protected-venue-dv" > |
| 62 | 62 | <h3 class="event-venues-h3 ee-event-h3"> |
| 63 | - <?php _e( 'Location', 'event_espresso' );?> |
|
| 63 | + <?php _e('Location', 'event_espresso'); ?> |
|
| 64 | 64 | </h3> |
| 65 | 65 | <?php echo espresso_password_protected_venue_form(); ?> |
| 66 | 66 | </div> |
@@ -14,133 +14,133 @@ |
||
| 14 | 14 | trait EventsAdmin |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param string $additional_params |
|
| 19 | - */ |
|
| 20 | - public function amOnDefaultEventsListTablePage($additional_params = '') |
|
| 21 | - { |
|
| 22 | - $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params)); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Triggers the publishing of the Event. |
|
| 28 | - */ |
|
| 29 | - public function publishEvent() |
|
| 30 | - { |
|
| 31 | - $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR); |
|
| 32 | - $this->actor()->wait(3); |
|
| 33 | - $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR); |
|
| 34 | - $this->actor()->waitForText('Event published.', 30); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Triggers saving the Event. |
|
| 40 | - */ |
|
| 41 | - public function saveEvent() |
|
| 42 | - { |
|
| 43 | - $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR); |
|
| 44 | - $this->actor()->wait(2); |
|
| 45 | - $this->actor()->click(EventsPage::EVENT_EDITOR_SAVE_BUTTON_SELECTOR); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Navigates the actor to the event list table page and will attempt to edit the event for the given title. |
|
| 51 | - * First this will search using the given title and then attempt to edit from the results of the search. |
|
| 52 | - * |
|
| 53 | - * Assumes actor is already logged in. |
|
| 54 | - * @param $event_title |
|
| 55 | - */ |
|
| 56 | - public function amEditingTheEventWithTitle($event_title) |
|
| 57 | - { |
|
| 58 | - $this->amOnDefaultEventsListTablePage(); |
|
| 59 | - $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title); |
|
| 60 | - $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR); |
|
| 61 | - $this->actor()->waitForText($event_title, 15); |
|
| 62 | - $this->actor()->click(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" |
|
| 68 | - * link for the event in the event list table. |
|
| 69 | - * Assumes the actor is already logged in and on the Event list table page. |
|
| 70 | - * |
|
| 71 | - * @param string $event_title |
|
| 72 | - */ |
|
| 73 | - public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title) |
|
| 74 | - { |
|
| 75 | - $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
| 76 | - $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title)); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Used to retrieve the event id for the event via the list table and for the given event. |
|
| 82 | - * @param string $event_title |
|
| 83 | - */ |
|
| 84 | - public function observeEventIdInListTableForEvent($event_title) |
|
| 85 | - { |
|
| 86 | - return $this->actor()->observeValueFromInputAt(EventsPage::eventListTableEventIdSelectorForTitle($event_title)); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * This performs the click action on the gear icon that triggers the advanced settings view state. |
|
| 92 | - * Assumes the actor is already logged in and editing an event. |
|
| 93 | - * |
|
| 94 | - * @param int $row_number What ticket row to toggle open/close. |
|
| 95 | - */ |
|
| 96 | - public function toggleAdvancedSettingsViewForTicketRow($row_number = 1) |
|
| 97 | - { |
|
| 98 | - $this->actor()->click(EventsPage::eventEditorTicketAdvancedDetailsSelector($row_number)); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Toggles the TKT_is_taxable checkbox for the ticket in the given row. |
|
| 104 | - * Assumes the actor is already logged in and editing an event and that the advanced settings view state for that |
|
| 105 | - * ticket is "open". |
|
| 106 | - * |
|
| 107 | - * @param int $row_number What ticket row to toggle the checkbox for. |
|
| 108 | - */ |
|
| 109 | - public function toggleTicketIsTaxableForTicketRow($row_number = 1) |
|
| 110 | - { |
|
| 111 | - $this->actor()->click(EventsPage::eventEditorTicketTaxableCheckboxSelector($row_number)); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Use to change the default registration status for the event. |
|
| 117 | - * Assumes the view is already on the event editor. |
|
| 118 | - * @param $registration_status |
|
| 119 | - */ |
|
| 120 | - public function changeDefaultRegistrationStatusTo($registration_status) |
|
| 121 | - { |
|
| 122 | - $this->actor()->selectOption( |
|
| 123 | - EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR, |
|
| 124 | - $registration_status |
|
| 125 | - ); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Use this from the context of the event editor to select the given custom template for a given message type and |
|
| 131 | - * messenger. |
|
| 132 | - * |
|
| 133 | - * @param string $message_type_label The visible label for the message type (eg Registration Approved) |
|
| 134 | - * @param string $messenger_slug The slug for the messenger (eg 'email') |
|
| 135 | - * @param string $custom_template_label The visible label in the select input for the custom template you want |
|
| 136 | - * selected. |
|
| 137 | - */ |
|
| 138 | - public function selectCustomTemplateFor($message_type_label, $messenger_slug, $custom_template_label) |
|
| 139 | - { |
|
| 140 | - $this->actor()->click(EventsPage::eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)); |
|
| 141 | - $this->actor()->selectOption( |
|
| 142 | - EventsPage::eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label), |
|
| 143 | - $custom_template_label |
|
| 144 | - ); |
|
| 145 | - } |
|
| 17 | + /** |
|
| 18 | + * @param string $additional_params |
|
| 19 | + */ |
|
| 20 | + public function amOnDefaultEventsListTablePage($additional_params = '') |
|
| 21 | + { |
|
| 22 | + $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params)); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Triggers the publishing of the Event. |
|
| 28 | + */ |
|
| 29 | + public function publishEvent() |
|
| 30 | + { |
|
| 31 | + $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR); |
|
| 32 | + $this->actor()->wait(3); |
|
| 33 | + $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR); |
|
| 34 | + $this->actor()->waitForText('Event published.', 30); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Triggers saving the Event. |
|
| 40 | + */ |
|
| 41 | + public function saveEvent() |
|
| 42 | + { |
|
| 43 | + $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR); |
|
| 44 | + $this->actor()->wait(2); |
|
| 45 | + $this->actor()->click(EventsPage::EVENT_EDITOR_SAVE_BUTTON_SELECTOR); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Navigates the actor to the event list table page and will attempt to edit the event for the given title. |
|
| 51 | + * First this will search using the given title and then attempt to edit from the results of the search. |
|
| 52 | + * |
|
| 53 | + * Assumes actor is already logged in. |
|
| 54 | + * @param $event_title |
|
| 55 | + */ |
|
| 56 | + public function amEditingTheEventWithTitle($event_title) |
|
| 57 | + { |
|
| 58 | + $this->amOnDefaultEventsListTablePage(); |
|
| 59 | + $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title); |
|
| 60 | + $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR); |
|
| 61 | + $this->actor()->waitForText($event_title, 15); |
|
| 62 | + $this->actor()->click(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" |
|
| 68 | + * link for the event in the event list table. |
|
| 69 | + * Assumes the actor is already logged in and on the Event list table page. |
|
| 70 | + * |
|
| 71 | + * @param string $event_title |
|
| 72 | + */ |
|
| 73 | + public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title) |
|
| 74 | + { |
|
| 75 | + $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
| 76 | + $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title)); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Used to retrieve the event id for the event via the list table and for the given event. |
|
| 82 | + * @param string $event_title |
|
| 83 | + */ |
|
| 84 | + public function observeEventIdInListTableForEvent($event_title) |
|
| 85 | + { |
|
| 86 | + return $this->actor()->observeValueFromInputAt(EventsPage::eventListTableEventIdSelectorForTitle($event_title)); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * This performs the click action on the gear icon that triggers the advanced settings view state. |
|
| 92 | + * Assumes the actor is already logged in and editing an event. |
|
| 93 | + * |
|
| 94 | + * @param int $row_number What ticket row to toggle open/close. |
|
| 95 | + */ |
|
| 96 | + public function toggleAdvancedSettingsViewForTicketRow($row_number = 1) |
|
| 97 | + { |
|
| 98 | + $this->actor()->click(EventsPage::eventEditorTicketAdvancedDetailsSelector($row_number)); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Toggles the TKT_is_taxable checkbox for the ticket in the given row. |
|
| 104 | + * Assumes the actor is already logged in and editing an event and that the advanced settings view state for that |
|
| 105 | + * ticket is "open". |
|
| 106 | + * |
|
| 107 | + * @param int $row_number What ticket row to toggle the checkbox for. |
|
| 108 | + */ |
|
| 109 | + public function toggleTicketIsTaxableForTicketRow($row_number = 1) |
|
| 110 | + { |
|
| 111 | + $this->actor()->click(EventsPage::eventEditorTicketTaxableCheckboxSelector($row_number)); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Use to change the default registration status for the event. |
|
| 117 | + * Assumes the view is already on the event editor. |
|
| 118 | + * @param $registration_status |
|
| 119 | + */ |
|
| 120 | + public function changeDefaultRegistrationStatusTo($registration_status) |
|
| 121 | + { |
|
| 122 | + $this->actor()->selectOption( |
|
| 123 | + EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR, |
|
| 124 | + $registration_status |
|
| 125 | + ); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Use this from the context of the event editor to select the given custom template for a given message type and |
|
| 131 | + * messenger. |
|
| 132 | + * |
|
| 133 | + * @param string $message_type_label The visible label for the message type (eg Registration Approved) |
|
| 134 | + * @param string $messenger_slug The slug for the messenger (eg 'email') |
|
| 135 | + * @param string $custom_template_label The visible label in the select input for the custom template you want |
|
| 136 | + * selected. |
|
| 137 | + */ |
|
| 138 | + public function selectCustomTemplateFor($message_type_label, $messenger_slug, $custom_template_label) |
|
| 139 | + { |
|
| 140 | + $this->actor()->click(EventsPage::eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)); |
|
| 141 | + $this->actor()->selectOption( |
|
| 142 | + EventsPage::eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label), |
|
| 143 | + $custom_template_label |
|
| 144 | + ); |
|
| 145 | + } |
|
| 146 | 146 | } |
| 147 | 147 | \ No newline at end of file |
@@ -10,293 +10,293 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | trait MessagesAdmin |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 15 | - * a string. |
|
| 16 | - */ |
|
| 17 | - public function amOnMessagesActivityListTablePage($additional_params = '') |
|
| 18 | - { |
|
| 19 | - $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
| 20 | - } |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 24 | - * a string. |
|
| 25 | - */ |
|
| 26 | - public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
| 27 | - { |
|
| 28 | - $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 34 | - * a string. |
|
| 35 | - */ |
|
| 36 | - public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
| 37 | - { |
|
| 38 | - $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Directs to message settings page |
|
| 44 | - */ |
|
| 45 | - public function amOnMessageSettingsPage() |
|
| 46 | - { |
|
| 47 | - $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
| 52 | - { |
|
| 53 | - $this->actor()->dragAndDrop( |
|
| 54 | - MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
| 55 | - MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Assumes you are already on the list table page that has the ui for editing the template. |
|
| 62 | - * @param string $message_type_slug |
|
| 63 | - * @param string $context [optional] if you want to click directly to the given context in the editor |
|
| 64 | - */ |
|
| 65 | - public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
| 66 | - { |
|
| 67 | - $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
| 73 | - * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
| 74 | - * |
|
| 75 | - * @param int $expected_occurence_count |
|
| 76 | - * @param string $text_to_check_for |
|
| 77 | - * @param string $field |
|
| 78 | - * @param string $message_type_label |
|
| 79 | - * @param string $message_status |
|
| 80 | - * @param string $messenger |
|
| 81 | - * @param string $context |
|
| 82 | - */ |
|
| 83 | - public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
| 84 | - $expected_occurence_count, |
|
| 85 | - $text_to_check_for, |
|
| 86 | - $field, |
|
| 87 | - $message_type_label, |
|
| 88 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 89 | - $messenger = 'Email', |
|
| 90 | - $context = 'Event Admin' |
|
| 91 | - ) { |
|
| 92 | - $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
| 93 | - $field, |
|
| 94 | - $message_type_label, |
|
| 95 | - $message_status, |
|
| 96 | - $messenger, |
|
| 97 | - $context, |
|
| 98 | - $text_to_check_for, |
|
| 99 | - 0 |
|
| 100 | - )); |
|
| 101 | - $actual_count = count($elements); |
|
| 102 | - $this->actor()->assertEquals( |
|
| 103 | - $expected_occurence_count, |
|
| 104 | - $actual_count, |
|
| 105 | - sprintf( |
|
| 106 | - 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
| 107 | - $expected_occurence_count, |
|
| 108 | - $text_to_check_for, |
|
| 109 | - $field, |
|
| 110 | - $actual_count |
|
| 111 | - ) |
|
| 112 | - ); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * This will create a custom message template for the given messenger and message type from the context of the |
|
| 118 | - * default (global) message template list table. |
|
| 119 | - * Also takes care of verifying the template was created. |
|
| 120 | - * @param string $message_type_label |
|
| 121 | - * @param string $messenger_label |
|
| 122 | - */ |
|
| 123 | - public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
| 124 | - { |
|
| 125 | - $this->amOnDefaultMessageTemplateListTablePage(); |
|
| 126 | - $this->actor()->click( |
|
| 127 | - MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
| 128 | - $message_type_label, |
|
| 129 | - $messenger_label |
|
| 130 | - ) |
|
| 131 | - ); |
|
| 132 | - $this->actor()->seeInField('#title', 'New Custom Template'); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * This switches the context of the current messages template to the given reference. |
|
| 138 | - * @param string $context_reference This should be the visible label for the option. |
|
| 139 | - */ |
|
| 140 | - public function switchContextTo($context_reference) |
|
| 141 | - { |
|
| 142 | - $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
| 143 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
| 144 | - $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
| 150 | - * toggling. |
|
| 151 | - * |
|
| 152 | - * @param string $context_string What context is being switched (used for the expected state text) |
|
| 153 | - * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
| 154 | - * (false) |
|
| 155 | - */ |
|
| 156 | - public function toggleContextState($context_string, $expected_state_is_active = true) |
|
| 157 | - { |
|
| 158 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
| 159 | - if ($expected_state_is_active) { |
|
| 160 | - $this->actor()->waitForText("The template for $context_string is currently active."); |
|
| 161 | - } else { |
|
| 162 | - $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Triggers saving the message template. |
|
| 169 | - * @param bool $and_close Use to indicate to click the Save and Close button. |
|
| 170 | - */ |
|
| 171 | - public function saveMessageTemplate($and_close = false) |
|
| 172 | - { |
|
| 173 | - $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
| 174 | - if ($and_close) { |
|
| 175 | - $this->actor()->click('Save and Close'); |
|
| 176 | - } else { |
|
| 177 | - $this->actor()->click('Save'); |
|
| 178 | - } |
|
| 179 | - $this->actor()->waitForText('successfully updated'); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * This takes care of clicking the View Message icon for the given parameters. |
|
| 185 | - * Assumes you are already viewing the messages activity list table. |
|
| 186 | - * @param $message_type_label |
|
| 187 | - * @param $message_status |
|
| 188 | - * @param string $messenger |
|
| 189 | - * @param string $context |
|
| 190 | - * @param int $number_in_set |
|
| 191 | - */ |
|
| 192 | - public function viewMessageInMessagesListTableFor( |
|
| 193 | - $message_type_label, |
|
| 194 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 195 | - $messenger = 'Email', |
|
| 196 | - $context = 'Event Admin', |
|
| 197 | - $number_in_set = 1 |
|
| 198 | - ) { |
|
| 199 | - $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
| 200 | - $message_type_label, |
|
| 201 | - $message_status, |
|
| 202 | - $messenger, |
|
| 203 | - $context, |
|
| 204 | - $number_in_set |
|
| 205 | - )); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
| 211 | - * Assumes you are already viewing the messages activity list table. |
|
| 212 | - * @param $message_type_label |
|
| 213 | - * @param $message_status |
|
| 214 | - * @param string $messenger |
|
| 215 | - * @param string $context |
|
| 216 | - * @param int $number_in_set |
|
| 217 | - */ |
|
| 218 | - public function deleteMessageInMessagesListTableFor( |
|
| 219 | - $message_type_label, |
|
| 220 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 221 | - $messenger = 'Email', |
|
| 222 | - $context = 'Event Admin', |
|
| 223 | - $number_in_set = 1 |
|
| 224 | - ) { |
|
| 225 | - $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
| 226 | - $message_type_label, |
|
| 227 | - $message_status, |
|
| 228 | - $messenger, |
|
| 229 | - $context, |
|
| 230 | - $number_in_set |
|
| 231 | - ); |
|
| 232 | - $cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor( |
|
| 233 | - 'to', |
|
| 234 | - $message_type_label, |
|
| 235 | - $message_status, |
|
| 236 | - $messenger, |
|
| 237 | - $context, |
|
| 238 | - '', |
|
| 239 | - $number_in_set |
|
| 240 | - ); |
|
| 241 | - $this->actor()->scrollTo($cell_selector, 0, -30); |
|
| 242 | - $this->actor()->moveMouseOver( |
|
| 243 | - $cell_selector, |
|
| 244 | - 5, |
|
| 245 | - 5 |
|
| 246 | - ); |
|
| 247 | - $this->actor()->waitForElementVisible( |
|
| 248 | - $delete_action_selector |
|
| 249 | - ); |
|
| 250 | - $this->actor()->click( |
|
| 251 | - $delete_action_selector |
|
| 252 | - ); |
|
| 253 | - $this->actor()->waitForText('successfully deleted', 20); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
| 259 | - * list table, this will take care of validating the given text is in that window. |
|
| 260 | - * @param string $text_to_view |
|
| 261 | - */ |
|
| 262 | - public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
| 263 | - { |
|
| 264 | - $this->actor()->wait(2); |
|
| 265 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
| 266 | - $this->actor()->switchToIframe('message-view-window'); |
|
| 267 | - $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
| 268 | - $this->actor()->switchToIframe(); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * This returns the value for the link at the given selector in the message modal. |
|
| 274 | - * @param string $selector (any selector string accepted by WebDriver) |
|
| 275 | - */ |
|
| 276 | - public function observeLinkAtSelectorInMessageModal($selector) |
|
| 277 | - { |
|
| 278 | - $this->actor()->wait(2); |
|
| 279 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
| 280 | - $this->actor()->switchToIframe('message-view-window'); |
|
| 281 | - $link = $this->actor()->observeLinkUrlAt($selector); |
|
| 282 | - $this->actor()->switchToIframe(); |
|
| 283 | - return $link; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
| 289 | - * list table, this will take care of validating the given text is NOT that window. |
|
| 290 | - * @param string $text_to_view |
|
| 291 | - */ |
|
| 292 | - public function dontSeeTextInViewMessageModal($text_to_view) |
|
| 293 | - { |
|
| 294 | - $this->seeTextInViewMessageModal($text_to_view, true); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - public function dismissMessageModal() |
|
| 299 | - { |
|
| 300 | - $this->actor()->executeJs('window.dialogHelper.closeModal()'); |
|
| 301 | - } |
|
| 13 | + /** |
|
| 14 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 15 | + * a string. |
|
| 16 | + */ |
|
| 17 | + public function amOnMessagesActivityListTablePage($additional_params = '') |
|
| 18 | + { |
|
| 19 | + $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
| 20 | + } |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 24 | + * a string. |
|
| 25 | + */ |
|
| 26 | + public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
| 27 | + { |
|
| 28 | + $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
| 34 | + * a string. |
|
| 35 | + */ |
|
| 36 | + public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
| 37 | + { |
|
| 38 | + $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Directs to message settings page |
|
| 44 | + */ |
|
| 45 | + public function amOnMessageSettingsPage() |
|
| 46 | + { |
|
| 47 | + $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
| 52 | + { |
|
| 53 | + $this->actor()->dragAndDrop( |
|
| 54 | + MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
| 55 | + MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Assumes you are already on the list table page that has the ui for editing the template. |
|
| 62 | + * @param string $message_type_slug |
|
| 63 | + * @param string $context [optional] if you want to click directly to the given context in the editor |
|
| 64 | + */ |
|
| 65 | + public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
| 66 | + { |
|
| 67 | + $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
| 73 | + * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
| 74 | + * |
|
| 75 | + * @param int $expected_occurence_count |
|
| 76 | + * @param string $text_to_check_for |
|
| 77 | + * @param string $field |
|
| 78 | + * @param string $message_type_label |
|
| 79 | + * @param string $message_status |
|
| 80 | + * @param string $messenger |
|
| 81 | + * @param string $context |
|
| 82 | + */ |
|
| 83 | + public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
| 84 | + $expected_occurence_count, |
|
| 85 | + $text_to_check_for, |
|
| 86 | + $field, |
|
| 87 | + $message_type_label, |
|
| 88 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 89 | + $messenger = 'Email', |
|
| 90 | + $context = 'Event Admin' |
|
| 91 | + ) { |
|
| 92 | + $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
| 93 | + $field, |
|
| 94 | + $message_type_label, |
|
| 95 | + $message_status, |
|
| 96 | + $messenger, |
|
| 97 | + $context, |
|
| 98 | + $text_to_check_for, |
|
| 99 | + 0 |
|
| 100 | + )); |
|
| 101 | + $actual_count = count($elements); |
|
| 102 | + $this->actor()->assertEquals( |
|
| 103 | + $expected_occurence_count, |
|
| 104 | + $actual_count, |
|
| 105 | + sprintf( |
|
| 106 | + 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
| 107 | + $expected_occurence_count, |
|
| 108 | + $text_to_check_for, |
|
| 109 | + $field, |
|
| 110 | + $actual_count |
|
| 111 | + ) |
|
| 112 | + ); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * This will create a custom message template for the given messenger and message type from the context of the |
|
| 118 | + * default (global) message template list table. |
|
| 119 | + * Also takes care of verifying the template was created. |
|
| 120 | + * @param string $message_type_label |
|
| 121 | + * @param string $messenger_label |
|
| 122 | + */ |
|
| 123 | + public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
| 124 | + { |
|
| 125 | + $this->amOnDefaultMessageTemplateListTablePage(); |
|
| 126 | + $this->actor()->click( |
|
| 127 | + MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
| 128 | + $message_type_label, |
|
| 129 | + $messenger_label |
|
| 130 | + ) |
|
| 131 | + ); |
|
| 132 | + $this->actor()->seeInField('#title', 'New Custom Template'); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * This switches the context of the current messages template to the given reference. |
|
| 138 | + * @param string $context_reference This should be the visible label for the option. |
|
| 139 | + */ |
|
| 140 | + public function switchContextTo($context_reference) |
|
| 141 | + { |
|
| 142 | + $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
| 143 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
| 144 | + $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
| 150 | + * toggling. |
|
| 151 | + * |
|
| 152 | + * @param string $context_string What context is being switched (used for the expected state text) |
|
| 153 | + * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
| 154 | + * (false) |
|
| 155 | + */ |
|
| 156 | + public function toggleContextState($context_string, $expected_state_is_active = true) |
|
| 157 | + { |
|
| 158 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
| 159 | + if ($expected_state_is_active) { |
|
| 160 | + $this->actor()->waitForText("The template for $context_string is currently active."); |
|
| 161 | + } else { |
|
| 162 | + $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Triggers saving the message template. |
|
| 169 | + * @param bool $and_close Use to indicate to click the Save and Close button. |
|
| 170 | + */ |
|
| 171 | + public function saveMessageTemplate($and_close = false) |
|
| 172 | + { |
|
| 173 | + $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
| 174 | + if ($and_close) { |
|
| 175 | + $this->actor()->click('Save and Close'); |
|
| 176 | + } else { |
|
| 177 | + $this->actor()->click('Save'); |
|
| 178 | + } |
|
| 179 | + $this->actor()->waitForText('successfully updated'); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * This takes care of clicking the View Message icon for the given parameters. |
|
| 185 | + * Assumes you are already viewing the messages activity list table. |
|
| 186 | + * @param $message_type_label |
|
| 187 | + * @param $message_status |
|
| 188 | + * @param string $messenger |
|
| 189 | + * @param string $context |
|
| 190 | + * @param int $number_in_set |
|
| 191 | + */ |
|
| 192 | + public function viewMessageInMessagesListTableFor( |
|
| 193 | + $message_type_label, |
|
| 194 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 195 | + $messenger = 'Email', |
|
| 196 | + $context = 'Event Admin', |
|
| 197 | + $number_in_set = 1 |
|
| 198 | + ) { |
|
| 199 | + $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
| 200 | + $message_type_label, |
|
| 201 | + $message_status, |
|
| 202 | + $messenger, |
|
| 203 | + $context, |
|
| 204 | + $number_in_set |
|
| 205 | + )); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
| 211 | + * Assumes you are already viewing the messages activity list table. |
|
| 212 | + * @param $message_type_label |
|
| 213 | + * @param $message_status |
|
| 214 | + * @param string $messenger |
|
| 215 | + * @param string $context |
|
| 216 | + * @param int $number_in_set |
|
| 217 | + */ |
|
| 218 | + public function deleteMessageInMessagesListTableFor( |
|
| 219 | + $message_type_label, |
|
| 220 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
| 221 | + $messenger = 'Email', |
|
| 222 | + $context = 'Event Admin', |
|
| 223 | + $number_in_set = 1 |
|
| 224 | + ) { |
|
| 225 | + $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
| 226 | + $message_type_label, |
|
| 227 | + $message_status, |
|
| 228 | + $messenger, |
|
| 229 | + $context, |
|
| 230 | + $number_in_set |
|
| 231 | + ); |
|
| 232 | + $cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor( |
|
| 233 | + 'to', |
|
| 234 | + $message_type_label, |
|
| 235 | + $message_status, |
|
| 236 | + $messenger, |
|
| 237 | + $context, |
|
| 238 | + '', |
|
| 239 | + $number_in_set |
|
| 240 | + ); |
|
| 241 | + $this->actor()->scrollTo($cell_selector, 0, -30); |
|
| 242 | + $this->actor()->moveMouseOver( |
|
| 243 | + $cell_selector, |
|
| 244 | + 5, |
|
| 245 | + 5 |
|
| 246 | + ); |
|
| 247 | + $this->actor()->waitForElementVisible( |
|
| 248 | + $delete_action_selector |
|
| 249 | + ); |
|
| 250 | + $this->actor()->click( |
|
| 251 | + $delete_action_selector |
|
| 252 | + ); |
|
| 253 | + $this->actor()->waitForText('successfully deleted', 20); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
| 259 | + * list table, this will take care of validating the given text is in that window. |
|
| 260 | + * @param string $text_to_view |
|
| 261 | + */ |
|
| 262 | + public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
| 263 | + { |
|
| 264 | + $this->actor()->wait(2); |
|
| 265 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
| 266 | + $this->actor()->switchToIframe('message-view-window'); |
|
| 267 | + $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
| 268 | + $this->actor()->switchToIframe(); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * This returns the value for the link at the given selector in the message modal. |
|
| 274 | + * @param string $selector (any selector string accepted by WebDriver) |
|
| 275 | + */ |
|
| 276 | + public function observeLinkAtSelectorInMessageModal($selector) |
|
| 277 | + { |
|
| 278 | + $this->actor()->wait(2); |
|
| 279 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
| 280 | + $this->actor()->switchToIframe('message-view-window'); |
|
| 281 | + $link = $this->actor()->observeLinkUrlAt($selector); |
|
| 282 | + $this->actor()->switchToIframe(); |
|
| 283 | + return $link; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
| 289 | + * list table, this will take care of validating the given text is NOT that window. |
|
| 290 | + * @param string $text_to_view |
|
| 291 | + */ |
|
| 292 | + public function dontSeeTextInViewMessageModal($text_to_view) |
|
| 293 | + { |
|
| 294 | + $this->seeTextInViewMessageModal($text_to_view, true); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + public function dismissMessageModal() |
|
| 299 | + { |
|
| 300 | + $this->actor()->executeJs('window.dialogHelper.closeModal()'); |
|
| 301 | + } |
|
| 302 | 302 | } |
@@ -25,1144 +25,1144 @@ |
||
| 25 | 25 | { |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * possibly truncated version of the EE core version string |
|
| 30 | - * |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - protected static $_core_version = ''; |
|
| 28 | + /** |
|
| 29 | + * possibly truncated version of the EE core version string |
|
| 30 | + * |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + protected static $_core_version = ''; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Holds values for registered addons |
|
| 37 | - * |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected static $_settings = array(); |
|
| 35 | + /** |
|
| 36 | + * Holds values for registered addons |
|
| 37 | + * |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected static $_settings = array(); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
| 44 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 45 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 46 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
| 47 | - * EE core with knowledge of ALL the addons out there. |
|
| 48 | - * If you want NO versions of an addon to run with a certain version of core, |
|
| 49 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 50 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 51 | - * minimum plugin version. |
|
| 52 | - * @access protected |
|
| 53 | - */ |
|
| 54 | - protected static $_incompatible_addons = array( |
|
| 55 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 56 | - 'Promotions' => '1.0.0.rc.084', |
|
| 57 | - ); |
|
| 42 | + /** |
|
| 43 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
| 44 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 45 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 46 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
| 47 | + * EE core with knowledge of ALL the addons out there. |
|
| 48 | + * If you want NO versions of an addon to run with a certain version of core, |
|
| 49 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 50 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 51 | + * minimum plugin version. |
|
| 52 | + * @access protected |
|
| 53 | + */ |
|
| 54 | + protected static $_incompatible_addons = array( |
|
| 55 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 56 | + 'Promotions' => '1.0.0.rc.084', |
|
| 57 | + ); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 62 | - * not just '4.3.0'. |
|
| 63 | - * So if the addon developer doesn't provide that full version string, |
|
| 64 | - * fill in the blanks for them |
|
| 65 | - * |
|
| 66 | - * @param string $min_core_version |
|
| 67 | - * @return string always like '4.3.0.rc.000' |
|
| 68 | - */ |
|
| 69 | - protected static function _effective_version($min_core_version) |
|
| 70 | - { |
|
| 71 | - // versions: 4 . 3 . 1 . p . 123 |
|
| 72 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 73 | - $version_parts = explode('.', $min_core_version); |
|
| 74 | - //check they specified the micro version (after 2nd period) |
|
| 75 | - if (! isset($version_parts[2])) { |
|
| 76 | - $version_parts[2] = '0'; |
|
| 77 | - } |
|
| 78 | - //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 79 | - //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 80 | - if (! isset($version_parts[3])) { |
|
| 81 | - $version_parts[3] = 'dev'; |
|
| 82 | - } |
|
| 83 | - if (! isset($version_parts[4])) { |
|
| 84 | - $version_parts[4] = '000'; |
|
| 85 | - } |
|
| 86 | - return implode('.', $version_parts); |
|
| 87 | - } |
|
| 60 | + /** |
|
| 61 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 62 | + * not just '4.3.0'. |
|
| 63 | + * So if the addon developer doesn't provide that full version string, |
|
| 64 | + * fill in the blanks for them |
|
| 65 | + * |
|
| 66 | + * @param string $min_core_version |
|
| 67 | + * @return string always like '4.3.0.rc.000' |
|
| 68 | + */ |
|
| 69 | + protected static function _effective_version($min_core_version) |
|
| 70 | + { |
|
| 71 | + // versions: 4 . 3 . 1 . p . 123 |
|
| 72 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 73 | + $version_parts = explode('.', $min_core_version); |
|
| 74 | + //check they specified the micro version (after 2nd period) |
|
| 75 | + if (! isset($version_parts[2])) { |
|
| 76 | + $version_parts[2] = '0'; |
|
| 77 | + } |
|
| 78 | + //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 79 | + //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 80 | + if (! isset($version_parts[3])) { |
|
| 81 | + $version_parts[3] = 'dev'; |
|
| 82 | + } |
|
| 83 | + if (! isset($version_parts[4])) { |
|
| 84 | + $version_parts[4] = '000'; |
|
| 85 | + } |
|
| 86 | + return implode('.', $version_parts); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Returns whether or not the min core version requirement of the addon is met |
|
| 92 | - * |
|
| 93 | - * @param string $min_core_version the minimum core version required by the addon |
|
| 94 | - * @param string $actual_core_version the actual core version, optional |
|
| 95 | - * @return boolean |
|
| 96 | - */ |
|
| 97 | - public static function _meets_min_core_version_requirement( |
|
| 98 | - $min_core_version, |
|
| 99 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 100 | - ) { |
|
| 101 | - return version_compare( |
|
| 102 | - self::_effective_version($actual_core_version), |
|
| 103 | - self::_effective_version($min_core_version), |
|
| 104 | - '>=' |
|
| 105 | - ); |
|
| 106 | - } |
|
| 90 | + /** |
|
| 91 | + * Returns whether or not the min core version requirement of the addon is met |
|
| 92 | + * |
|
| 93 | + * @param string $min_core_version the minimum core version required by the addon |
|
| 94 | + * @param string $actual_core_version the actual core version, optional |
|
| 95 | + * @return boolean |
|
| 96 | + */ |
|
| 97 | + public static function _meets_min_core_version_requirement( |
|
| 98 | + $min_core_version, |
|
| 99 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 100 | + ) { |
|
| 101 | + return version_compare( |
|
| 102 | + self::_effective_version($actual_core_version), |
|
| 103 | + self::_effective_version($min_core_version), |
|
| 104 | + '>=' |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Method for registering new EE_Addons. |
|
| 111 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 112 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 113 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 114 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 115 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 116 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 117 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 118 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
| 119 | - * |
|
| 120 | - * @since 4.3.0 |
|
| 121 | - * @param string $addon_name the EE_Addon's name. Required. |
|
| 122 | - * @param array $setup_args { |
|
| 123 | - * An array of arguments provided for registering the |
|
| 124 | - * message type. |
|
| 125 | - * @type string $class_name the addon's main file name. |
|
| 126 | - * If left blank, generated from the addon name, |
|
| 127 | - * changes something like "calendar" to "EE_Calendar" |
|
| 128 | - * @type string $min_core_version the minimum version of EE Core that the |
|
| 129 | - * addon will work with. eg "4.8.1.rc.084" |
|
| 130 | - * @type string $version the "software" version for the addon. eg |
|
| 131 | - * "1.0.0.p" for a first stable release, or |
|
| 132 | - * "1.0.0.rc.043" for a version in progress |
|
| 133 | - * @type string $main_file_path the full server path to the main file |
|
| 134 | - * loaded directly by WP |
|
| 135 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
| 136 | - * for the addon's Domain class |
|
| 137 | - * (see EventEspresso\core\domain\Domain) |
|
| 138 | - * @type string $admin_path full server path to the folder where the |
|
| 139 | - * addon\'s admin files reside |
|
| 140 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
| 141 | - * first invoked, can be used for hooking into |
|
| 142 | - * any admin page |
|
| 143 | - * @type string $config_section the section name for this addon's |
|
| 144 | - * configuration settings section |
|
| 145 | - * (defaults to "addons") |
|
| 146 | - * @type string $config_class the class name for this addon's |
|
| 147 | - * configuration settings object |
|
| 148 | - * @type string $config_name the class name for this addon's |
|
| 149 | - * configuration settings object |
|
| 150 | - * @type string $autoloader_paths an array of class names and the full server |
|
| 151 | - * paths to those files. Required. |
|
| 152 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
| 153 | - * folders containing classes that might be |
|
| 154 | - * invoked by the addon |
|
| 155 | - * @type string $dms_paths an array of full server paths to folders that |
|
| 156 | - * contain data migration scripts. Required. |
|
| 157 | - * @type string $module_paths an array of full server paths to any |
|
| 158 | - * EED_Modules used by the addon |
|
| 159 | - * @type string $shortcode_paths an array of full server paths to folders |
|
| 160 | - * that contain EES_Shortcodes |
|
| 161 | - * @type string $widget_paths an array of full server paths to folders |
|
| 162 | - * that contain WP_Widgets |
|
| 163 | - * @type string $pue_options |
|
| 164 | - * @type array $capabilities an array indexed by role name |
|
| 165 | - * (i.e administrator,author ) and the values |
|
| 166 | - * are an array of caps to add to the role. |
|
| 167 | - * 'administrator' => array( |
|
| 168 | - * 'read_addon', |
|
| 169 | - * 'edit_addon', |
|
| 170 | - * etc. |
|
| 171 | - * ). |
|
| 172 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 173 | - * for any addons that need to register any |
|
| 174 | - * special meta mapped capabilities. Should |
|
| 175 | - * be indexed where the key is the |
|
| 176 | - * EE_Meta_Capability_Map class name and the |
|
| 177 | - * values are the arguments sent to the class. |
|
| 178 | - * @type array $model_paths array of folders containing DB models |
|
| 179 | - * @see EE_Register_Model |
|
| 180 | - * @type array $class_paths array of folders containing DB classes |
|
| 181 | - * @see EE_Register_Model |
|
| 182 | - * @type array $model_extension_paths array of folders containing DB model |
|
| 183 | - * extensions |
|
| 184 | - * @see EE_Register_Model_Extension |
|
| 185 | - * @type array $class_extension_paths array of folders containing DB class |
|
| 186 | - * extensions |
|
| 187 | - * @see EE_Register_Model_Extension |
|
| 188 | - * @type array message_types { |
|
| 189 | - * An array of message types with the key as |
|
| 190 | - * the message type name and the values as |
|
| 191 | - * below: |
|
| 192 | - * @type string $mtfilename The filename of the message type being |
|
| 193 | - * registered. This will be the main |
|
| 194 | - * EE_{Message Type Name}_message_type class. |
|
| 195 | - * (eg. EE_Declined_Registration_message_type.class.php) |
|
| 196 | - * Required. |
|
| 197 | - * @type array $autoloadpaths An array of paths to add to the messages |
|
| 198 | - * autoloader for the new message type. |
|
| 199 | - * Required. |
|
| 200 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 201 | - * type should activate with. Each value in |
|
| 202 | - * the |
|
| 203 | - * array |
|
| 204 | - * should match the name property of a |
|
| 205 | - * EE_messenger. Optional. |
|
| 206 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 207 | - * type should validate with. Each value in |
|
| 208 | - * the |
|
| 209 | - * array |
|
| 210 | - * should match the name property of an |
|
| 211 | - * EE_messenger. |
|
| 212 | - * Optional. |
|
| 213 | - * } |
|
| 214 | - * @type array $custom_post_types |
|
| 215 | - * @type array $custom_taxonomies |
|
| 216 | - * @type array $payment_method_paths each element is the folder containing the |
|
| 217 | - * EE_PMT_Base child class |
|
| 218 | - * (eg, |
|
| 219 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 220 | - * which contains the files |
|
| 221 | - * EE_PMT_Payomatic.pm.php) |
|
| 222 | - * @type array $default_terms |
|
| 223 | - * @type array $namespace { |
|
| 224 | - * An array with two items for registering the |
|
| 225 | - * addon's namespace. (If, for some reason, you |
|
| 226 | - * require additional namespaces, |
|
| 227 | - * use EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 228 | - * directly) |
|
| 229 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 230 | - * @type string $FQNS the namespace prefix |
|
| 231 | - * @type string $DIR a base directory for class files in the |
|
| 232 | - * namespace. |
|
| 233 | - * } |
|
| 234 | - * } |
|
| 235 | - * @return void |
|
| 236 | - * @throws DomainException |
|
| 237 | - * @throws EE_Error |
|
| 238 | - * @throws InvalidArgumentException |
|
| 239 | - * @throws ReflectionException |
|
| 240 | - * @throws InvalidDataTypeException |
|
| 241 | - * @throws InvalidInterfaceException |
|
| 242 | - */ |
|
| 243 | - public static function register($addon_name = '', $setup_args = array()) |
|
| 244 | - { |
|
| 245 | - // required fields MUST be present, so let's make sure they are. |
|
| 246 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 247 | - // get class name for addon |
|
| 248 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 249 | - //setup $_settings array from incoming values. |
|
| 250 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 251 | - // setup PUE |
|
| 252 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 253 | - // does this addon work with this version of core or WordPress ? |
|
| 254 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 255 | - return; |
|
| 256 | - } |
|
| 257 | - // register namespaces |
|
| 258 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 259 | - // check if this is an activation request |
|
| 260 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 261 | - // dont bother setting up the rest of the addon atm |
|
| 262 | - return; |
|
| 263 | - } |
|
| 264 | - // we need cars |
|
| 265 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 266 | - // register new models and extensions |
|
| 267 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 268 | - // setup DMS |
|
| 269 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 270 | - // if config_class is present let's register config. |
|
| 271 | - EE_Register_Addon::_register_config($addon_name); |
|
| 272 | - // register admin pages |
|
| 273 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 274 | - // add to list of modules to be registered |
|
| 275 | - EE_Register_Addon::_register_modules($addon_name); |
|
| 276 | - // add to list of shortcodes to be registered |
|
| 277 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 278 | - // add to list of widgets to be registered |
|
| 279 | - EE_Register_Addon::_register_widgets($addon_name); |
|
| 280 | - // register capability related stuff. |
|
| 281 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
| 282 | - // any message type to register? |
|
| 283 | - EE_Register_Addon::_register_message_types($addon_name); |
|
| 284 | - // any custom post type/ custom capabilities or default terms to register |
|
| 285 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 286 | - // and any payment methods |
|
| 287 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 288 | - // load and instantiate main addon class |
|
| 289 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 290 | - //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 291 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 292 | - } |
|
| 109 | + /** |
|
| 110 | + * Method for registering new EE_Addons. |
|
| 111 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 112 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 113 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 114 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 115 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 116 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 117 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 118 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
| 119 | + * |
|
| 120 | + * @since 4.3.0 |
|
| 121 | + * @param string $addon_name the EE_Addon's name. Required. |
|
| 122 | + * @param array $setup_args { |
|
| 123 | + * An array of arguments provided for registering the |
|
| 124 | + * message type. |
|
| 125 | + * @type string $class_name the addon's main file name. |
|
| 126 | + * If left blank, generated from the addon name, |
|
| 127 | + * changes something like "calendar" to "EE_Calendar" |
|
| 128 | + * @type string $min_core_version the minimum version of EE Core that the |
|
| 129 | + * addon will work with. eg "4.8.1.rc.084" |
|
| 130 | + * @type string $version the "software" version for the addon. eg |
|
| 131 | + * "1.0.0.p" for a first stable release, or |
|
| 132 | + * "1.0.0.rc.043" for a version in progress |
|
| 133 | + * @type string $main_file_path the full server path to the main file |
|
| 134 | + * loaded directly by WP |
|
| 135 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
| 136 | + * for the addon's Domain class |
|
| 137 | + * (see EventEspresso\core\domain\Domain) |
|
| 138 | + * @type string $admin_path full server path to the folder where the |
|
| 139 | + * addon\'s admin files reside |
|
| 140 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
| 141 | + * first invoked, can be used for hooking into |
|
| 142 | + * any admin page |
|
| 143 | + * @type string $config_section the section name for this addon's |
|
| 144 | + * configuration settings section |
|
| 145 | + * (defaults to "addons") |
|
| 146 | + * @type string $config_class the class name for this addon's |
|
| 147 | + * configuration settings object |
|
| 148 | + * @type string $config_name the class name for this addon's |
|
| 149 | + * configuration settings object |
|
| 150 | + * @type string $autoloader_paths an array of class names and the full server |
|
| 151 | + * paths to those files. Required. |
|
| 152 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
| 153 | + * folders containing classes that might be |
|
| 154 | + * invoked by the addon |
|
| 155 | + * @type string $dms_paths an array of full server paths to folders that |
|
| 156 | + * contain data migration scripts. Required. |
|
| 157 | + * @type string $module_paths an array of full server paths to any |
|
| 158 | + * EED_Modules used by the addon |
|
| 159 | + * @type string $shortcode_paths an array of full server paths to folders |
|
| 160 | + * that contain EES_Shortcodes |
|
| 161 | + * @type string $widget_paths an array of full server paths to folders |
|
| 162 | + * that contain WP_Widgets |
|
| 163 | + * @type string $pue_options |
|
| 164 | + * @type array $capabilities an array indexed by role name |
|
| 165 | + * (i.e administrator,author ) and the values |
|
| 166 | + * are an array of caps to add to the role. |
|
| 167 | + * 'administrator' => array( |
|
| 168 | + * 'read_addon', |
|
| 169 | + * 'edit_addon', |
|
| 170 | + * etc. |
|
| 171 | + * ). |
|
| 172 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 173 | + * for any addons that need to register any |
|
| 174 | + * special meta mapped capabilities. Should |
|
| 175 | + * be indexed where the key is the |
|
| 176 | + * EE_Meta_Capability_Map class name and the |
|
| 177 | + * values are the arguments sent to the class. |
|
| 178 | + * @type array $model_paths array of folders containing DB models |
|
| 179 | + * @see EE_Register_Model |
|
| 180 | + * @type array $class_paths array of folders containing DB classes |
|
| 181 | + * @see EE_Register_Model |
|
| 182 | + * @type array $model_extension_paths array of folders containing DB model |
|
| 183 | + * extensions |
|
| 184 | + * @see EE_Register_Model_Extension |
|
| 185 | + * @type array $class_extension_paths array of folders containing DB class |
|
| 186 | + * extensions |
|
| 187 | + * @see EE_Register_Model_Extension |
|
| 188 | + * @type array message_types { |
|
| 189 | + * An array of message types with the key as |
|
| 190 | + * the message type name and the values as |
|
| 191 | + * below: |
|
| 192 | + * @type string $mtfilename The filename of the message type being |
|
| 193 | + * registered. This will be the main |
|
| 194 | + * EE_{Message Type Name}_message_type class. |
|
| 195 | + * (eg. EE_Declined_Registration_message_type.class.php) |
|
| 196 | + * Required. |
|
| 197 | + * @type array $autoloadpaths An array of paths to add to the messages |
|
| 198 | + * autoloader for the new message type. |
|
| 199 | + * Required. |
|
| 200 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 201 | + * type should activate with. Each value in |
|
| 202 | + * the |
|
| 203 | + * array |
|
| 204 | + * should match the name property of a |
|
| 205 | + * EE_messenger. Optional. |
|
| 206 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 207 | + * type should validate with. Each value in |
|
| 208 | + * the |
|
| 209 | + * array |
|
| 210 | + * should match the name property of an |
|
| 211 | + * EE_messenger. |
|
| 212 | + * Optional. |
|
| 213 | + * } |
|
| 214 | + * @type array $custom_post_types |
|
| 215 | + * @type array $custom_taxonomies |
|
| 216 | + * @type array $payment_method_paths each element is the folder containing the |
|
| 217 | + * EE_PMT_Base child class |
|
| 218 | + * (eg, |
|
| 219 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 220 | + * which contains the files |
|
| 221 | + * EE_PMT_Payomatic.pm.php) |
|
| 222 | + * @type array $default_terms |
|
| 223 | + * @type array $namespace { |
|
| 224 | + * An array with two items for registering the |
|
| 225 | + * addon's namespace. (If, for some reason, you |
|
| 226 | + * require additional namespaces, |
|
| 227 | + * use EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 228 | + * directly) |
|
| 229 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 230 | + * @type string $FQNS the namespace prefix |
|
| 231 | + * @type string $DIR a base directory for class files in the |
|
| 232 | + * namespace. |
|
| 233 | + * } |
|
| 234 | + * } |
|
| 235 | + * @return void |
|
| 236 | + * @throws DomainException |
|
| 237 | + * @throws EE_Error |
|
| 238 | + * @throws InvalidArgumentException |
|
| 239 | + * @throws ReflectionException |
|
| 240 | + * @throws InvalidDataTypeException |
|
| 241 | + * @throws InvalidInterfaceException |
|
| 242 | + */ |
|
| 243 | + public static function register($addon_name = '', $setup_args = array()) |
|
| 244 | + { |
|
| 245 | + // required fields MUST be present, so let's make sure they are. |
|
| 246 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 247 | + // get class name for addon |
|
| 248 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 249 | + //setup $_settings array from incoming values. |
|
| 250 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 251 | + // setup PUE |
|
| 252 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 253 | + // does this addon work with this version of core or WordPress ? |
|
| 254 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 255 | + return; |
|
| 256 | + } |
|
| 257 | + // register namespaces |
|
| 258 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 259 | + // check if this is an activation request |
|
| 260 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 261 | + // dont bother setting up the rest of the addon atm |
|
| 262 | + return; |
|
| 263 | + } |
|
| 264 | + // we need cars |
|
| 265 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 266 | + // register new models and extensions |
|
| 267 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 268 | + // setup DMS |
|
| 269 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 270 | + // if config_class is present let's register config. |
|
| 271 | + EE_Register_Addon::_register_config($addon_name); |
|
| 272 | + // register admin pages |
|
| 273 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 274 | + // add to list of modules to be registered |
|
| 275 | + EE_Register_Addon::_register_modules($addon_name); |
|
| 276 | + // add to list of shortcodes to be registered |
|
| 277 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 278 | + // add to list of widgets to be registered |
|
| 279 | + EE_Register_Addon::_register_widgets($addon_name); |
|
| 280 | + // register capability related stuff. |
|
| 281 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
| 282 | + // any message type to register? |
|
| 283 | + EE_Register_Addon::_register_message_types($addon_name); |
|
| 284 | + // any custom post type/ custom capabilities or default terms to register |
|
| 285 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 286 | + // and any payment methods |
|
| 287 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 288 | + // load and instantiate main addon class |
|
| 289 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 290 | + //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 291 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * @param string $addon_name |
|
| 297 | - * @param array $setup_args |
|
| 298 | - * @return void |
|
| 299 | - * @throws EE_Error |
|
| 300 | - */ |
|
| 301 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
| 302 | - { |
|
| 303 | - // required fields MUST be present, so let's make sure they are. |
|
| 304 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 305 | - throw new EE_Error( |
|
| 306 | - __( |
|
| 307 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 308 | - 'event_espresso' |
|
| 309 | - ) |
|
| 310 | - ); |
|
| 311 | - } |
|
| 312 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 313 | - throw new EE_Error( |
|
| 314 | - sprintf( |
|
| 315 | - __( |
|
| 316 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 317 | - 'event_espresso' |
|
| 318 | - ), |
|
| 319 | - implode(',', array_keys($setup_args)) |
|
| 320 | - ) |
|
| 321 | - ); |
|
| 322 | - } |
|
| 323 | - // check that addon has not already been registered with that name |
|
| 324 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 325 | - throw new EE_Error( |
|
| 326 | - sprintf( |
|
| 327 | - __( |
|
| 328 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 329 | - 'event_espresso' |
|
| 330 | - ), |
|
| 331 | - $addon_name |
|
| 332 | - ) |
|
| 333 | - ); |
|
| 334 | - } |
|
| 335 | - } |
|
| 295 | + /** |
|
| 296 | + * @param string $addon_name |
|
| 297 | + * @param array $setup_args |
|
| 298 | + * @return void |
|
| 299 | + * @throws EE_Error |
|
| 300 | + */ |
|
| 301 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
| 302 | + { |
|
| 303 | + // required fields MUST be present, so let's make sure they are. |
|
| 304 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 305 | + throw new EE_Error( |
|
| 306 | + __( |
|
| 307 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 308 | + 'event_espresso' |
|
| 309 | + ) |
|
| 310 | + ); |
|
| 311 | + } |
|
| 312 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 313 | + throw new EE_Error( |
|
| 314 | + sprintf( |
|
| 315 | + __( |
|
| 316 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 317 | + 'event_espresso' |
|
| 318 | + ), |
|
| 319 | + implode(',', array_keys($setup_args)) |
|
| 320 | + ) |
|
| 321 | + ); |
|
| 322 | + } |
|
| 323 | + // check that addon has not already been registered with that name |
|
| 324 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 325 | + throw new EE_Error( |
|
| 326 | + sprintf( |
|
| 327 | + __( |
|
| 328 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 329 | + 'event_espresso' |
|
| 330 | + ), |
|
| 331 | + $addon_name |
|
| 332 | + ) |
|
| 333 | + ); |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | 337 | |
| 338 | - /** |
|
| 339 | - * @param string $addon_name |
|
| 340 | - * @param array $setup_args |
|
| 341 | - * @return string |
|
| 342 | - */ |
|
| 343 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
| 344 | - { |
|
| 345 | - if (empty($setup_args['class_name'])) { |
|
| 346 | - // generate one by first separating name with spaces |
|
| 347 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 348 | - //capitalize, then replace spaces with underscores |
|
| 349 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 350 | - } else { |
|
| 351 | - $class_name = $setup_args['class_name']; |
|
| 352 | - } |
|
| 353 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 354 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 355 | - ? $class_name |
|
| 356 | - : 'EE_' . $class_name; |
|
| 357 | - } |
|
| 338 | + /** |
|
| 339 | + * @param string $addon_name |
|
| 340 | + * @param array $setup_args |
|
| 341 | + * @return string |
|
| 342 | + */ |
|
| 343 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
| 344 | + { |
|
| 345 | + if (empty($setup_args['class_name'])) { |
|
| 346 | + // generate one by first separating name with spaces |
|
| 347 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 348 | + //capitalize, then replace spaces with underscores |
|
| 349 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 350 | + } else { |
|
| 351 | + $class_name = $setup_args['class_name']; |
|
| 352 | + } |
|
| 353 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 354 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 355 | + ? $class_name |
|
| 356 | + : 'EE_' . $class_name; |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | 359 | |
| 360 | - /** |
|
| 361 | - * @param string $class_name |
|
| 362 | - * @param array $setup_args |
|
| 363 | - * @return array |
|
| 364 | - */ |
|
| 365 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
| 366 | - { |
|
| 367 | - //setup $_settings array from incoming values. |
|
| 368 | - $addon_settings = array( |
|
| 369 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 370 | - 'class_name' => $class_name, |
|
| 371 | - // the addon slug for use in URLs, etc |
|
| 372 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 373 | - ? (string) $setup_args['plugin_slug'] |
|
| 374 | - : '', |
|
| 375 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 376 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 377 | - ? (string) $setup_args['plugin_action_slug'] |
|
| 378 | - : '', |
|
| 379 | - // the "software" version for the addon |
|
| 380 | - 'version' => isset($setup_args['version']) |
|
| 381 | - ? (string) $setup_args['version'] |
|
| 382 | - : '', |
|
| 383 | - // the minimum version of EE Core that the addon will work with |
|
| 384 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 385 | - ? (string) $setup_args['min_core_version'] |
|
| 386 | - : '', |
|
| 387 | - // the minimum version of WordPress that the addon will work with |
|
| 388 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 389 | - ? (string) $setup_args['min_wp_version'] |
|
| 390 | - : EE_MIN_WP_VER_REQUIRED, |
|
| 391 | - // full server path to main file (file loaded directly by WP) |
|
| 392 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 393 | - ? (string) $setup_args['main_file_path'] |
|
| 394 | - : '', |
|
| 395 | - // Fully Qualified Class Name for the addon's Domain class |
|
| 396 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 397 | - ? (string) $setup_args['domain_fqcn'] |
|
| 398 | - : '', |
|
| 399 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 400 | - 'admin_path' => isset($setup_args['admin_path']) |
|
| 401 | - ? (string) $setup_args['admin_path'] : '', |
|
| 402 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 403 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 404 | - ? (string) $setup_args['admin_callback'] |
|
| 405 | - : '', |
|
| 406 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 407 | - 'config_section' => isset($setup_args['config_section']) |
|
| 408 | - ? (string) $setup_args['config_section'] |
|
| 409 | - : 'addons', |
|
| 410 | - // the class name for this addon's configuration settings object |
|
| 411 | - 'config_class' => isset($setup_args['config_class']) |
|
| 412 | - ? (string) $setup_args['config_class'] : '', |
|
| 413 | - //the name given to the config for this addons' configuration settings object (optional) |
|
| 414 | - 'config_name' => isset($setup_args['config_name']) |
|
| 415 | - ? (string) $setup_args['config_name'] : '', |
|
| 416 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 417 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 418 | - ? (array) $setup_args['autoloader_paths'] |
|
| 419 | - : array(), |
|
| 420 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 421 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 422 | - ? (array) $setup_args['autoloader_folders'] |
|
| 423 | - : array(), |
|
| 424 | - // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
| 425 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 426 | - ? (array) $setup_args['dms_paths'] |
|
| 427 | - : array(), |
|
| 428 | - // array of full server paths to any EED_Modules used by the addon |
|
| 429 | - 'module_paths' => isset($setup_args['module_paths']) |
|
| 430 | - ? (array) $setup_args['module_paths'] |
|
| 431 | - : array(), |
|
| 432 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
| 433 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 434 | - ? (array) $setup_args['shortcode_paths'] |
|
| 435 | - : array(), |
|
| 436 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 437 | - ? (array) $setup_args['shortcode_fqcns'] |
|
| 438 | - : array(), |
|
| 439 | - // array of full server paths to any WP_Widgets used by the addon |
|
| 440 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 441 | - ? (array) $setup_args['widget_paths'] |
|
| 442 | - : array(), |
|
| 443 | - // array of PUE options used by the addon |
|
| 444 | - 'pue_options' => isset($setup_args['pue_options']) |
|
| 445 | - ? (array) $setup_args['pue_options'] |
|
| 446 | - : array(), |
|
| 447 | - 'message_types' => isset($setup_args['message_types']) |
|
| 448 | - ? (array) $setup_args['message_types'] |
|
| 449 | - : array(), |
|
| 450 | - 'capabilities' => isset($setup_args['capabilities']) |
|
| 451 | - ? (array) $setup_args['capabilities'] |
|
| 452 | - : array(), |
|
| 453 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 454 | - ? (array) $setup_args['capability_maps'] |
|
| 455 | - : array(), |
|
| 456 | - 'model_paths' => isset($setup_args['model_paths']) |
|
| 457 | - ? (array) $setup_args['model_paths'] |
|
| 458 | - : array(), |
|
| 459 | - 'class_paths' => isset($setup_args['class_paths']) |
|
| 460 | - ? (array) $setup_args['class_paths'] |
|
| 461 | - : array(), |
|
| 462 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 463 | - ? (array) $setup_args['model_extension_paths'] |
|
| 464 | - : array(), |
|
| 465 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 466 | - ? (array) $setup_args['class_extension_paths'] |
|
| 467 | - : array(), |
|
| 468 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 469 | - ? (array) $setup_args['custom_post_types'] |
|
| 470 | - : array(), |
|
| 471 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 472 | - ? (array) $setup_args['custom_taxonomies'] |
|
| 473 | - : array(), |
|
| 474 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 475 | - ? (array) $setup_args['payment_method_paths'] |
|
| 476 | - : array(), |
|
| 477 | - 'default_terms' => isset($setup_args['default_terms']) |
|
| 478 | - ? (array) $setup_args['default_terms'] |
|
| 479 | - : array(), |
|
| 480 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 481 | - // that can be used for adding upgrading/marketing info |
|
| 482 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 483 | - ? $setup_args['plugins_page_row'] |
|
| 484 | - : '', |
|
| 485 | - 'namespace' => isset( |
|
| 486 | - $setup_args['namespace']['FQNS'], |
|
| 487 | - $setup_args['namespace']['DIR'] |
|
| 488 | - ) |
|
| 489 | - ? (array) $setup_args['namespace'] |
|
| 490 | - : array(), |
|
| 491 | - ); |
|
| 492 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 493 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 494 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 495 | - && ! empty($addon_settings['admin_path']) |
|
| 496 | - ? $addon_settings['plugin_slug'] |
|
| 497 | - : $addon_settings['plugin_action_slug']; |
|
| 498 | - // full server path to main file (file loaded directly by WP) |
|
| 499 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 500 | - return $addon_settings; |
|
| 501 | - } |
|
| 360 | + /** |
|
| 361 | + * @param string $class_name |
|
| 362 | + * @param array $setup_args |
|
| 363 | + * @return array |
|
| 364 | + */ |
|
| 365 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
| 366 | + { |
|
| 367 | + //setup $_settings array from incoming values. |
|
| 368 | + $addon_settings = array( |
|
| 369 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 370 | + 'class_name' => $class_name, |
|
| 371 | + // the addon slug for use in URLs, etc |
|
| 372 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 373 | + ? (string) $setup_args['plugin_slug'] |
|
| 374 | + : '', |
|
| 375 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 376 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 377 | + ? (string) $setup_args['plugin_action_slug'] |
|
| 378 | + : '', |
|
| 379 | + // the "software" version for the addon |
|
| 380 | + 'version' => isset($setup_args['version']) |
|
| 381 | + ? (string) $setup_args['version'] |
|
| 382 | + : '', |
|
| 383 | + // the minimum version of EE Core that the addon will work with |
|
| 384 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 385 | + ? (string) $setup_args['min_core_version'] |
|
| 386 | + : '', |
|
| 387 | + // the minimum version of WordPress that the addon will work with |
|
| 388 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 389 | + ? (string) $setup_args['min_wp_version'] |
|
| 390 | + : EE_MIN_WP_VER_REQUIRED, |
|
| 391 | + // full server path to main file (file loaded directly by WP) |
|
| 392 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 393 | + ? (string) $setup_args['main_file_path'] |
|
| 394 | + : '', |
|
| 395 | + // Fully Qualified Class Name for the addon's Domain class |
|
| 396 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 397 | + ? (string) $setup_args['domain_fqcn'] |
|
| 398 | + : '', |
|
| 399 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 400 | + 'admin_path' => isset($setup_args['admin_path']) |
|
| 401 | + ? (string) $setup_args['admin_path'] : '', |
|
| 402 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 403 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 404 | + ? (string) $setup_args['admin_callback'] |
|
| 405 | + : '', |
|
| 406 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 407 | + 'config_section' => isset($setup_args['config_section']) |
|
| 408 | + ? (string) $setup_args['config_section'] |
|
| 409 | + : 'addons', |
|
| 410 | + // the class name for this addon's configuration settings object |
|
| 411 | + 'config_class' => isset($setup_args['config_class']) |
|
| 412 | + ? (string) $setup_args['config_class'] : '', |
|
| 413 | + //the name given to the config for this addons' configuration settings object (optional) |
|
| 414 | + 'config_name' => isset($setup_args['config_name']) |
|
| 415 | + ? (string) $setup_args['config_name'] : '', |
|
| 416 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 417 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 418 | + ? (array) $setup_args['autoloader_paths'] |
|
| 419 | + : array(), |
|
| 420 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 421 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 422 | + ? (array) $setup_args['autoloader_folders'] |
|
| 423 | + : array(), |
|
| 424 | + // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
| 425 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 426 | + ? (array) $setup_args['dms_paths'] |
|
| 427 | + : array(), |
|
| 428 | + // array of full server paths to any EED_Modules used by the addon |
|
| 429 | + 'module_paths' => isset($setup_args['module_paths']) |
|
| 430 | + ? (array) $setup_args['module_paths'] |
|
| 431 | + : array(), |
|
| 432 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
| 433 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 434 | + ? (array) $setup_args['shortcode_paths'] |
|
| 435 | + : array(), |
|
| 436 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 437 | + ? (array) $setup_args['shortcode_fqcns'] |
|
| 438 | + : array(), |
|
| 439 | + // array of full server paths to any WP_Widgets used by the addon |
|
| 440 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 441 | + ? (array) $setup_args['widget_paths'] |
|
| 442 | + : array(), |
|
| 443 | + // array of PUE options used by the addon |
|
| 444 | + 'pue_options' => isset($setup_args['pue_options']) |
|
| 445 | + ? (array) $setup_args['pue_options'] |
|
| 446 | + : array(), |
|
| 447 | + 'message_types' => isset($setup_args['message_types']) |
|
| 448 | + ? (array) $setup_args['message_types'] |
|
| 449 | + : array(), |
|
| 450 | + 'capabilities' => isset($setup_args['capabilities']) |
|
| 451 | + ? (array) $setup_args['capabilities'] |
|
| 452 | + : array(), |
|
| 453 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 454 | + ? (array) $setup_args['capability_maps'] |
|
| 455 | + : array(), |
|
| 456 | + 'model_paths' => isset($setup_args['model_paths']) |
|
| 457 | + ? (array) $setup_args['model_paths'] |
|
| 458 | + : array(), |
|
| 459 | + 'class_paths' => isset($setup_args['class_paths']) |
|
| 460 | + ? (array) $setup_args['class_paths'] |
|
| 461 | + : array(), |
|
| 462 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 463 | + ? (array) $setup_args['model_extension_paths'] |
|
| 464 | + : array(), |
|
| 465 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 466 | + ? (array) $setup_args['class_extension_paths'] |
|
| 467 | + : array(), |
|
| 468 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 469 | + ? (array) $setup_args['custom_post_types'] |
|
| 470 | + : array(), |
|
| 471 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 472 | + ? (array) $setup_args['custom_taxonomies'] |
|
| 473 | + : array(), |
|
| 474 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 475 | + ? (array) $setup_args['payment_method_paths'] |
|
| 476 | + : array(), |
|
| 477 | + 'default_terms' => isset($setup_args['default_terms']) |
|
| 478 | + ? (array) $setup_args['default_terms'] |
|
| 479 | + : array(), |
|
| 480 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 481 | + // that can be used for adding upgrading/marketing info |
|
| 482 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 483 | + ? $setup_args['plugins_page_row'] |
|
| 484 | + : '', |
|
| 485 | + 'namespace' => isset( |
|
| 486 | + $setup_args['namespace']['FQNS'], |
|
| 487 | + $setup_args['namespace']['DIR'] |
|
| 488 | + ) |
|
| 489 | + ? (array) $setup_args['namespace'] |
|
| 490 | + : array(), |
|
| 491 | + ); |
|
| 492 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 493 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 494 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 495 | + && ! empty($addon_settings['admin_path']) |
|
| 496 | + ? $addon_settings['plugin_slug'] |
|
| 497 | + : $addon_settings['plugin_action_slug']; |
|
| 498 | + // full server path to main file (file loaded directly by WP) |
|
| 499 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 500 | + return $addon_settings; |
|
| 501 | + } |
|
| 502 | 502 | |
| 503 | 503 | |
| 504 | - /** |
|
| 505 | - * @param string $addon_name |
|
| 506 | - * @param array $addon_settings |
|
| 507 | - * @return boolean |
|
| 508 | - */ |
|
| 509 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 510 | - { |
|
| 511 | - global $wp_version; |
|
| 512 | - $incompatibility_message = ''; |
|
| 513 | - //check whether this addon version is compatible with EE core |
|
| 514 | - if ( |
|
| 515 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 516 | - && ! self::_meets_min_core_version_requirement( |
|
| 517 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 518 | - $addon_settings['version'] |
|
| 519 | - ) |
|
| 520 | - ) { |
|
| 521 | - $incompatibility_message = sprintf( |
|
| 522 | - __( |
|
| 523 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
| 524 | - ), |
|
| 525 | - $addon_name, |
|
| 526 | - '<br />', |
|
| 527 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 528 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 529 | - '</span><br />' |
|
| 530 | - ); |
|
| 531 | - } elseif ( |
|
| 532 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 533 | - ) { |
|
| 534 | - $incompatibility_message = sprintf( |
|
| 535 | - __( |
|
| 536 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 537 | - 'event_espresso' |
|
| 538 | - ), |
|
| 539 | - $addon_name, |
|
| 540 | - self::_effective_version($addon_settings['min_core_version']), |
|
| 541 | - self::_effective_version(espresso_version()), |
|
| 542 | - '<br />', |
|
| 543 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 544 | - '</span><br />' |
|
| 545 | - ); |
|
| 546 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 547 | - $incompatibility_message = sprintf( |
|
| 548 | - __( |
|
| 549 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 550 | - 'event_espresso' |
|
| 551 | - ), |
|
| 552 | - $addon_name, |
|
| 553 | - $addon_settings['min_wp_version'], |
|
| 554 | - '<br />', |
|
| 555 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 556 | - '</span><br />' |
|
| 557 | - ); |
|
| 558 | - } |
|
| 559 | - if (! empty($incompatibility_message)) { |
|
| 560 | - // remove 'activate' from the REQUEST |
|
| 561 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 562 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 563 | - if (current_user_can('activate_plugins')) { |
|
| 564 | - // show an error message indicating the plugin didn't activate properly |
|
| 565 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 566 | - } |
|
| 567 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 568 | - return false; |
|
| 569 | - } |
|
| 570 | - // addon IS compatible |
|
| 571 | - return true; |
|
| 572 | - } |
|
| 504 | + /** |
|
| 505 | + * @param string $addon_name |
|
| 506 | + * @param array $addon_settings |
|
| 507 | + * @return boolean |
|
| 508 | + */ |
|
| 509 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 510 | + { |
|
| 511 | + global $wp_version; |
|
| 512 | + $incompatibility_message = ''; |
|
| 513 | + //check whether this addon version is compatible with EE core |
|
| 514 | + if ( |
|
| 515 | + isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 516 | + && ! self::_meets_min_core_version_requirement( |
|
| 517 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 518 | + $addon_settings['version'] |
|
| 519 | + ) |
|
| 520 | + ) { |
|
| 521 | + $incompatibility_message = sprintf( |
|
| 522 | + __( |
|
| 523 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
| 524 | + ), |
|
| 525 | + $addon_name, |
|
| 526 | + '<br />', |
|
| 527 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 528 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 529 | + '</span><br />' |
|
| 530 | + ); |
|
| 531 | + } elseif ( |
|
| 532 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 533 | + ) { |
|
| 534 | + $incompatibility_message = sprintf( |
|
| 535 | + __( |
|
| 536 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 537 | + 'event_espresso' |
|
| 538 | + ), |
|
| 539 | + $addon_name, |
|
| 540 | + self::_effective_version($addon_settings['min_core_version']), |
|
| 541 | + self::_effective_version(espresso_version()), |
|
| 542 | + '<br />', |
|
| 543 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 544 | + '</span><br />' |
|
| 545 | + ); |
|
| 546 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 547 | + $incompatibility_message = sprintf( |
|
| 548 | + __( |
|
| 549 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 550 | + 'event_espresso' |
|
| 551 | + ), |
|
| 552 | + $addon_name, |
|
| 553 | + $addon_settings['min_wp_version'], |
|
| 554 | + '<br />', |
|
| 555 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 556 | + '</span><br />' |
|
| 557 | + ); |
|
| 558 | + } |
|
| 559 | + if (! empty($incompatibility_message)) { |
|
| 560 | + // remove 'activate' from the REQUEST |
|
| 561 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 562 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 563 | + if (current_user_can('activate_plugins')) { |
|
| 564 | + // show an error message indicating the plugin didn't activate properly |
|
| 565 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 566 | + } |
|
| 567 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 570 | + // addon IS compatible |
|
| 571 | + return true; |
|
| 572 | + } |
|
| 573 | 573 | |
| 574 | 574 | |
| 575 | - /** |
|
| 576 | - * if plugin update engine is being used for auto-updates, |
|
| 577 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
| 578 | - * (not needed if PUE is not being used) |
|
| 579 | - * |
|
| 580 | - * @param string $addon_name |
|
| 581 | - * @param string $class_name |
|
| 582 | - * @param array $setup_args |
|
| 583 | - * @return void |
|
| 584 | - */ |
|
| 585 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 586 | - { |
|
| 587 | - if (! empty($setup_args['pue_options'])) { |
|
| 588 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 589 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 590 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 591 | - : 'espresso_' . strtolower($class_name), |
|
| 592 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 593 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 594 | - : plugin_basename($setup_args['main_file_path']), |
|
| 595 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 596 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 597 | - : '24', |
|
| 598 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 599 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 600 | - : false, |
|
| 601 | - ); |
|
| 602 | - add_action( |
|
| 603 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 604 | - array('EE_Register_Addon', 'load_pue_update') |
|
| 605 | - ); |
|
| 606 | - } |
|
| 607 | - } |
|
| 575 | + /** |
|
| 576 | + * if plugin update engine is being used for auto-updates, |
|
| 577 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
| 578 | + * (not needed if PUE is not being used) |
|
| 579 | + * |
|
| 580 | + * @param string $addon_name |
|
| 581 | + * @param string $class_name |
|
| 582 | + * @param array $setup_args |
|
| 583 | + * @return void |
|
| 584 | + */ |
|
| 585 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 586 | + { |
|
| 587 | + if (! empty($setup_args['pue_options'])) { |
|
| 588 | + self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 589 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 590 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 591 | + : 'espresso_' . strtolower($class_name), |
|
| 592 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 593 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 594 | + : plugin_basename($setup_args['main_file_path']), |
|
| 595 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 596 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 597 | + : '24', |
|
| 598 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 599 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 600 | + : false, |
|
| 601 | + ); |
|
| 602 | + add_action( |
|
| 603 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 604 | + array('EE_Register_Addon', 'load_pue_update') |
|
| 605 | + ); |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | 608 | |
| 609 | 609 | |
| 610 | - /** |
|
| 611 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 612 | - * |
|
| 613 | - * @param array $addon_settings |
|
| 614 | - * @return void |
|
| 615 | - */ |
|
| 616 | - private static function _setup_namespaces(array $addon_settings) |
|
| 617 | - { |
|
| 618 | - // |
|
| 619 | - if ( |
|
| 620 | - isset( |
|
| 621 | - $addon_settings['namespace']['FQNS'], |
|
| 622 | - $addon_settings['namespace']['DIR'] |
|
| 623 | - ) |
|
| 624 | - ) { |
|
| 625 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 626 | - $addon_settings['namespace']['FQNS'], |
|
| 627 | - $addon_settings['namespace']['DIR'] |
|
| 628 | - ); |
|
| 629 | - } |
|
| 630 | - } |
|
| 610 | + /** |
|
| 611 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 612 | + * |
|
| 613 | + * @param array $addon_settings |
|
| 614 | + * @return void |
|
| 615 | + */ |
|
| 616 | + private static function _setup_namespaces(array $addon_settings) |
|
| 617 | + { |
|
| 618 | + // |
|
| 619 | + if ( |
|
| 620 | + isset( |
|
| 621 | + $addon_settings['namespace']['FQNS'], |
|
| 622 | + $addon_settings['namespace']['DIR'] |
|
| 623 | + ) |
|
| 624 | + ) { |
|
| 625 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 626 | + $addon_settings['namespace']['FQNS'], |
|
| 627 | + $addon_settings['namespace']['DIR'] |
|
| 628 | + ); |
|
| 629 | + } |
|
| 630 | + } |
|
| 631 | 631 | |
| 632 | 632 | |
| 633 | - /** |
|
| 634 | - * @param string $addon_name |
|
| 635 | - * @param array $addon_settings |
|
| 636 | - * @return bool |
|
| 637 | - * @throws EE_Error |
|
| 638 | - * @throws InvalidArgumentException |
|
| 639 | - * @throws ReflectionException |
|
| 640 | - * @throws InvalidDataTypeException |
|
| 641 | - * @throws InvalidInterfaceException |
|
| 642 | - */ |
|
| 643 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
| 644 | - { |
|
| 645 | - // this is an activation request |
|
| 646 | - if (did_action('activate_plugin')) { |
|
| 647 | - //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 648 | - //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 649 | - //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 650 | - //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 651 | - if (! isset(self::$_settings[ $addon_name ]) |
|
| 652 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 653 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 654 | - ) |
|
| 655 | - ) { |
|
| 656 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 657 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
| 658 | - $addon->set_activation_indicator_option(); |
|
| 659 | - // dont bother setting up the rest of the addon. |
|
| 660 | - // we know it was just activated and the request will end soon |
|
| 661 | - } |
|
| 662 | - return true; |
|
| 663 | - } |
|
| 664 | - // make sure this was called in the right place! |
|
| 665 | - if ( |
|
| 666 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 667 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 668 | - ) { |
|
| 669 | - EE_Error::doing_it_wrong( |
|
| 670 | - __METHOD__, |
|
| 671 | - sprintf( |
|
| 672 | - __( |
|
| 673 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 674 | - 'event_espresso' |
|
| 675 | - ), |
|
| 676 | - $addon_name |
|
| 677 | - ), |
|
| 678 | - '4.3.0' |
|
| 679 | - ); |
|
| 680 | - } |
|
| 681 | - // make sure addon settings are set correctly without overwriting anything existing |
|
| 682 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 683 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 684 | - } else { |
|
| 685 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 686 | - } |
|
| 687 | - return false; |
|
| 688 | - } |
|
| 633 | + /** |
|
| 634 | + * @param string $addon_name |
|
| 635 | + * @param array $addon_settings |
|
| 636 | + * @return bool |
|
| 637 | + * @throws EE_Error |
|
| 638 | + * @throws InvalidArgumentException |
|
| 639 | + * @throws ReflectionException |
|
| 640 | + * @throws InvalidDataTypeException |
|
| 641 | + * @throws InvalidInterfaceException |
|
| 642 | + */ |
|
| 643 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
| 644 | + { |
|
| 645 | + // this is an activation request |
|
| 646 | + if (did_action('activate_plugin')) { |
|
| 647 | + //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 648 | + //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 649 | + //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 650 | + //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 651 | + if (! isset(self::$_settings[ $addon_name ]) |
|
| 652 | + || (isset(self::$_settings[ $addon_name ]) |
|
| 653 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 654 | + ) |
|
| 655 | + ) { |
|
| 656 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 657 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
| 658 | + $addon->set_activation_indicator_option(); |
|
| 659 | + // dont bother setting up the rest of the addon. |
|
| 660 | + // we know it was just activated and the request will end soon |
|
| 661 | + } |
|
| 662 | + return true; |
|
| 663 | + } |
|
| 664 | + // make sure this was called in the right place! |
|
| 665 | + if ( |
|
| 666 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 667 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 668 | + ) { |
|
| 669 | + EE_Error::doing_it_wrong( |
|
| 670 | + __METHOD__, |
|
| 671 | + sprintf( |
|
| 672 | + __( |
|
| 673 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 674 | + 'event_espresso' |
|
| 675 | + ), |
|
| 676 | + $addon_name |
|
| 677 | + ), |
|
| 678 | + '4.3.0' |
|
| 679 | + ); |
|
| 680 | + } |
|
| 681 | + // make sure addon settings are set correctly without overwriting anything existing |
|
| 682 | + if (isset(self::$_settings[ $addon_name ])) { |
|
| 683 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
| 684 | + } else { |
|
| 685 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 686 | + } |
|
| 687 | + return false; |
|
| 688 | + } |
|
| 689 | 689 | |
| 690 | 690 | |
| 691 | - /** |
|
| 692 | - * @param string $addon_name |
|
| 693 | - * @return void |
|
| 694 | - * @throws EE_Error |
|
| 695 | - */ |
|
| 696 | - private static function _setup_autoloaders($addon_name) |
|
| 697 | - { |
|
| 698 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 699 | - // setup autoloader for single file |
|
| 700 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 701 | - } |
|
| 702 | - // setup autoloaders for folders |
|
| 703 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 704 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 705 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - } |
|
| 691 | + /** |
|
| 692 | + * @param string $addon_name |
|
| 693 | + * @return void |
|
| 694 | + * @throws EE_Error |
|
| 695 | + */ |
|
| 696 | + private static function _setup_autoloaders($addon_name) |
|
| 697 | + { |
|
| 698 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 699 | + // setup autoloader for single file |
|
| 700 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 701 | + } |
|
| 702 | + // setup autoloaders for folders |
|
| 703 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 704 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 705 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | 709 | |
| 710 | 710 | |
| 711 | - /** |
|
| 712 | - * register new models and extensions |
|
| 713 | - * |
|
| 714 | - * @param string $addon_name |
|
| 715 | - * @return void |
|
| 716 | - * @throws EE_Error |
|
| 717 | - */ |
|
| 718 | - private static function _register_models_and_extensions($addon_name) |
|
| 719 | - { |
|
| 720 | - // register new models |
|
| 721 | - if ( |
|
| 722 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 723 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 724 | - ) { |
|
| 725 | - EE_Register_Model::register( |
|
| 726 | - $addon_name, |
|
| 727 | - array( |
|
| 728 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 729 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 730 | - ) |
|
| 731 | - ); |
|
| 732 | - } |
|
| 733 | - // register model extensions |
|
| 734 | - if ( |
|
| 735 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 736 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 737 | - ) { |
|
| 738 | - EE_Register_Model_Extensions::register( |
|
| 739 | - $addon_name, |
|
| 740 | - array( |
|
| 741 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 742 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 743 | - ) |
|
| 744 | - ); |
|
| 745 | - } |
|
| 746 | - } |
|
| 711 | + /** |
|
| 712 | + * register new models and extensions |
|
| 713 | + * |
|
| 714 | + * @param string $addon_name |
|
| 715 | + * @return void |
|
| 716 | + * @throws EE_Error |
|
| 717 | + */ |
|
| 718 | + private static function _register_models_and_extensions($addon_name) |
|
| 719 | + { |
|
| 720 | + // register new models |
|
| 721 | + if ( |
|
| 722 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 723 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 724 | + ) { |
|
| 725 | + EE_Register_Model::register( |
|
| 726 | + $addon_name, |
|
| 727 | + array( |
|
| 728 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 729 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 730 | + ) |
|
| 731 | + ); |
|
| 732 | + } |
|
| 733 | + // register model extensions |
|
| 734 | + if ( |
|
| 735 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 736 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 737 | + ) { |
|
| 738 | + EE_Register_Model_Extensions::register( |
|
| 739 | + $addon_name, |
|
| 740 | + array( |
|
| 741 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 742 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 743 | + ) |
|
| 744 | + ); |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | 747 | |
| 748 | 748 | |
| 749 | - /** |
|
| 750 | - * @param string $addon_name |
|
| 751 | - * @return void |
|
| 752 | - * @throws EE_Error |
|
| 753 | - */ |
|
| 754 | - private static function _register_data_migration_scripts($addon_name) |
|
| 755 | - { |
|
| 756 | - // setup DMS |
|
| 757 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 758 | - EE_Register_Data_Migration_Scripts::register( |
|
| 759 | - $addon_name, |
|
| 760 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 761 | - ); |
|
| 762 | - } |
|
| 763 | - } |
|
| 749 | + /** |
|
| 750 | + * @param string $addon_name |
|
| 751 | + * @return void |
|
| 752 | + * @throws EE_Error |
|
| 753 | + */ |
|
| 754 | + private static function _register_data_migration_scripts($addon_name) |
|
| 755 | + { |
|
| 756 | + // setup DMS |
|
| 757 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 758 | + EE_Register_Data_Migration_Scripts::register( |
|
| 759 | + $addon_name, |
|
| 760 | + array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 761 | + ); |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | 765 | |
| 766 | - /** |
|
| 767 | - * @param string $addon_name |
|
| 768 | - * @return void |
|
| 769 | - * @throws EE_Error |
|
| 770 | - */ |
|
| 771 | - private static function _register_config($addon_name) |
|
| 772 | - { |
|
| 773 | - // if config_class is present let's register config. |
|
| 774 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 775 | - EE_Register_Config::register( |
|
| 776 | - self::$_settings[ $addon_name ]['config_class'], |
|
| 777 | - array( |
|
| 778 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 779 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 780 | - ) |
|
| 781 | - ); |
|
| 782 | - } |
|
| 783 | - } |
|
| 766 | + /** |
|
| 767 | + * @param string $addon_name |
|
| 768 | + * @return void |
|
| 769 | + * @throws EE_Error |
|
| 770 | + */ |
|
| 771 | + private static function _register_config($addon_name) |
|
| 772 | + { |
|
| 773 | + // if config_class is present let's register config. |
|
| 774 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 775 | + EE_Register_Config::register( |
|
| 776 | + self::$_settings[ $addon_name ]['config_class'], |
|
| 777 | + array( |
|
| 778 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 779 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 780 | + ) |
|
| 781 | + ); |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | 784 | |
| 785 | 785 | |
| 786 | - /** |
|
| 787 | - * @param string $addon_name |
|
| 788 | - * @return void |
|
| 789 | - * @throws EE_Error |
|
| 790 | - */ |
|
| 791 | - private static function _register_admin_pages($addon_name) |
|
| 792 | - { |
|
| 793 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 794 | - EE_Register_Admin_Page::register( |
|
| 795 | - $addon_name, |
|
| 796 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 797 | - ); |
|
| 798 | - } |
|
| 799 | - } |
|
| 786 | + /** |
|
| 787 | + * @param string $addon_name |
|
| 788 | + * @return void |
|
| 789 | + * @throws EE_Error |
|
| 790 | + */ |
|
| 791 | + private static function _register_admin_pages($addon_name) |
|
| 792 | + { |
|
| 793 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 794 | + EE_Register_Admin_Page::register( |
|
| 795 | + $addon_name, |
|
| 796 | + array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 797 | + ); |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | 800 | |
| 801 | 801 | |
| 802 | - /** |
|
| 803 | - * @param string $addon_name |
|
| 804 | - * @return void |
|
| 805 | - * @throws EE_Error |
|
| 806 | - */ |
|
| 807 | - private static function _register_modules($addon_name) |
|
| 808 | - { |
|
| 809 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 810 | - EE_Register_Module::register( |
|
| 811 | - $addon_name, |
|
| 812 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 813 | - ); |
|
| 814 | - } |
|
| 815 | - } |
|
| 802 | + /** |
|
| 803 | + * @param string $addon_name |
|
| 804 | + * @return void |
|
| 805 | + * @throws EE_Error |
|
| 806 | + */ |
|
| 807 | + private static function _register_modules($addon_name) |
|
| 808 | + { |
|
| 809 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 810 | + EE_Register_Module::register( |
|
| 811 | + $addon_name, |
|
| 812 | + array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 813 | + ); |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | 816 | |
| 817 | 817 | |
| 818 | - /** |
|
| 819 | - * @param string $addon_name |
|
| 820 | - * @return void |
|
| 821 | - * @throws EE_Error |
|
| 822 | - */ |
|
| 823 | - private static function _register_shortcodes($addon_name) |
|
| 824 | - { |
|
| 825 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 826 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 827 | - ) { |
|
| 828 | - EE_Register_Shortcode::register( |
|
| 829 | - $addon_name, |
|
| 830 | - array( |
|
| 831 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 832 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 833 | - : array(), |
|
| 834 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 835 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 836 | - : array(), |
|
| 837 | - ) |
|
| 838 | - ); |
|
| 839 | - } |
|
| 840 | - } |
|
| 818 | + /** |
|
| 819 | + * @param string $addon_name |
|
| 820 | + * @return void |
|
| 821 | + * @throws EE_Error |
|
| 822 | + */ |
|
| 823 | + private static function _register_shortcodes($addon_name) |
|
| 824 | + { |
|
| 825 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 826 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 827 | + ) { |
|
| 828 | + EE_Register_Shortcode::register( |
|
| 829 | + $addon_name, |
|
| 830 | + array( |
|
| 831 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 832 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 833 | + : array(), |
|
| 834 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 835 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 836 | + : array(), |
|
| 837 | + ) |
|
| 838 | + ); |
|
| 839 | + } |
|
| 840 | + } |
|
| 841 | 841 | |
| 842 | 842 | |
| 843 | - /** |
|
| 844 | - * @param string $addon_name |
|
| 845 | - * @return void |
|
| 846 | - * @throws EE_Error |
|
| 847 | - */ |
|
| 848 | - private static function _register_widgets($addon_name) |
|
| 849 | - { |
|
| 850 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 851 | - EE_Register_Widget::register( |
|
| 852 | - $addon_name, |
|
| 853 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 854 | - ); |
|
| 855 | - } |
|
| 856 | - } |
|
| 843 | + /** |
|
| 844 | + * @param string $addon_name |
|
| 845 | + * @return void |
|
| 846 | + * @throws EE_Error |
|
| 847 | + */ |
|
| 848 | + private static function _register_widgets($addon_name) |
|
| 849 | + { |
|
| 850 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 851 | + EE_Register_Widget::register( |
|
| 852 | + $addon_name, |
|
| 853 | + array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 854 | + ); |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | 857 | |
| 858 | 858 | |
| 859 | - /** |
|
| 860 | - * @param string $addon_name |
|
| 861 | - * @return void |
|
| 862 | - * @throws EE_Error |
|
| 863 | - */ |
|
| 864 | - private static function _register_capabilities($addon_name) |
|
| 865 | - { |
|
| 866 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 867 | - EE_Register_Capabilities::register( |
|
| 868 | - $addon_name, |
|
| 869 | - array( |
|
| 870 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 871 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 872 | - ) |
|
| 873 | - ); |
|
| 874 | - } |
|
| 875 | - } |
|
| 859 | + /** |
|
| 860 | + * @param string $addon_name |
|
| 861 | + * @return void |
|
| 862 | + * @throws EE_Error |
|
| 863 | + */ |
|
| 864 | + private static function _register_capabilities($addon_name) |
|
| 865 | + { |
|
| 866 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 867 | + EE_Register_Capabilities::register( |
|
| 868 | + $addon_name, |
|
| 869 | + array( |
|
| 870 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 871 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 872 | + ) |
|
| 873 | + ); |
|
| 874 | + } |
|
| 875 | + } |
|
| 876 | 876 | |
| 877 | 877 | |
| 878 | - /** |
|
| 879 | - * @param string $addon_name |
|
| 880 | - * @return void |
|
| 881 | - * @throws EE_Error |
|
| 882 | - */ |
|
| 883 | - private static function _register_message_types($addon_name) |
|
| 884 | - { |
|
| 885 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 886 | - add_action( |
|
| 887 | - 'EE_Brewing_Regular___messages_caf', |
|
| 888 | - array('EE_Register_Addon', 'register_message_types') |
|
| 889 | - ); |
|
| 890 | - } |
|
| 891 | - } |
|
| 878 | + /** |
|
| 879 | + * @param string $addon_name |
|
| 880 | + * @return void |
|
| 881 | + * @throws EE_Error |
|
| 882 | + */ |
|
| 883 | + private static function _register_message_types($addon_name) |
|
| 884 | + { |
|
| 885 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 886 | + add_action( |
|
| 887 | + 'EE_Brewing_Regular___messages_caf', |
|
| 888 | + array('EE_Register_Addon', 'register_message_types') |
|
| 889 | + ); |
|
| 890 | + } |
|
| 891 | + } |
|
| 892 | 892 | |
| 893 | 893 | |
| 894 | - /** |
|
| 895 | - * @param string $addon_name |
|
| 896 | - * @return void |
|
| 897 | - * @throws EE_Error |
|
| 898 | - */ |
|
| 899 | - private static function _register_custom_post_types($addon_name) |
|
| 900 | - { |
|
| 901 | - if ( |
|
| 902 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 903 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 904 | - ) { |
|
| 905 | - EE_Register_CPT::register( |
|
| 906 | - $addon_name, |
|
| 907 | - array( |
|
| 908 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 909 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 910 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 911 | - ) |
|
| 912 | - ); |
|
| 913 | - } |
|
| 914 | - } |
|
| 894 | + /** |
|
| 895 | + * @param string $addon_name |
|
| 896 | + * @return void |
|
| 897 | + * @throws EE_Error |
|
| 898 | + */ |
|
| 899 | + private static function _register_custom_post_types($addon_name) |
|
| 900 | + { |
|
| 901 | + if ( |
|
| 902 | + ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 903 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 904 | + ) { |
|
| 905 | + EE_Register_CPT::register( |
|
| 906 | + $addon_name, |
|
| 907 | + array( |
|
| 908 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 909 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 910 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 911 | + ) |
|
| 912 | + ); |
|
| 913 | + } |
|
| 914 | + } |
|
| 915 | 915 | |
| 916 | 916 | |
| 917 | - /** |
|
| 918 | - * @param string $addon_name |
|
| 919 | - * @return void |
|
| 920 | - * @throws InvalidArgumentException |
|
| 921 | - * @throws InvalidInterfaceException |
|
| 922 | - * @throws InvalidDataTypeException |
|
| 923 | - * @throws DomainException |
|
| 924 | - * @throws EE_Error |
|
| 925 | - */ |
|
| 926 | - private static function _register_payment_methods($addon_name) |
|
| 927 | - { |
|
| 928 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 929 | - EE_Register_Payment_Method::register( |
|
| 930 | - $addon_name, |
|
| 931 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 932 | - ); |
|
| 933 | - } |
|
| 934 | - } |
|
| 917 | + /** |
|
| 918 | + * @param string $addon_name |
|
| 919 | + * @return void |
|
| 920 | + * @throws InvalidArgumentException |
|
| 921 | + * @throws InvalidInterfaceException |
|
| 922 | + * @throws InvalidDataTypeException |
|
| 923 | + * @throws DomainException |
|
| 924 | + * @throws EE_Error |
|
| 925 | + */ |
|
| 926 | + private static function _register_payment_methods($addon_name) |
|
| 927 | + { |
|
| 928 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 929 | + EE_Register_Payment_Method::register( |
|
| 930 | + $addon_name, |
|
| 931 | + array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 932 | + ); |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | 935 | |
| 936 | 936 | |
| 937 | - /** |
|
| 938 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 939 | - * |
|
| 940 | - * @param string $addon_name |
|
| 941 | - * @return EE_Addon |
|
| 942 | - * @throws InvalidArgumentException |
|
| 943 | - * @throws InvalidInterfaceException |
|
| 944 | - * @throws InvalidDataTypeException |
|
| 945 | - * @throws ReflectionException |
|
| 946 | - * @throws EE_Error |
|
| 947 | - */ |
|
| 948 | - private static function _load_and_init_addon_class($addon_name) |
|
| 949 | - { |
|
| 950 | - $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
| 951 | - $addon = $loader->getShared( |
|
| 952 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 953 | - array('EE_Registry::create(addon)' => true) |
|
| 954 | - ); |
|
| 955 | - // setter inject dep map if required |
|
| 956 | - if($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null){ |
|
| 957 | - $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
| 958 | - } |
|
| 959 | - // setter inject domain if required |
|
| 960 | - if( |
|
| 961 | - $addon instanceof RequiresDomainInterface |
|
| 962 | - && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
| 963 | - && $addon->domain() === null |
|
| 964 | - ){ |
|
| 965 | - $addon->setDomain( |
|
| 966 | - $loader->getShared( |
|
| 967 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 968 | - array( |
|
| 969 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
| 970 | - self::$_settings[ $addon_name ]['version'] |
|
| 971 | - ) |
|
| 972 | - ) |
|
| 973 | - ); |
|
| 974 | - } |
|
| 937 | + /** |
|
| 938 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 939 | + * |
|
| 940 | + * @param string $addon_name |
|
| 941 | + * @return EE_Addon |
|
| 942 | + * @throws InvalidArgumentException |
|
| 943 | + * @throws InvalidInterfaceException |
|
| 944 | + * @throws InvalidDataTypeException |
|
| 945 | + * @throws ReflectionException |
|
| 946 | + * @throws EE_Error |
|
| 947 | + */ |
|
| 948 | + private static function _load_and_init_addon_class($addon_name) |
|
| 949 | + { |
|
| 950 | + $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
| 951 | + $addon = $loader->getShared( |
|
| 952 | + self::$_settings[ $addon_name ]['class_name'], |
|
| 953 | + array('EE_Registry::create(addon)' => true) |
|
| 954 | + ); |
|
| 955 | + // setter inject dep map if required |
|
| 956 | + if($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null){ |
|
| 957 | + $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
| 958 | + } |
|
| 959 | + // setter inject domain if required |
|
| 960 | + if( |
|
| 961 | + $addon instanceof RequiresDomainInterface |
|
| 962 | + && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
| 963 | + && $addon->domain() === null |
|
| 964 | + ){ |
|
| 965 | + $addon->setDomain( |
|
| 966 | + $loader->getShared( |
|
| 967 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 968 | + array( |
|
| 969 | + self::$_settings[ $addon_name ]['main_file_path'], |
|
| 970 | + self::$_settings[ $addon_name ]['version'] |
|
| 971 | + ) |
|
| 972 | + ) |
|
| 973 | + ); |
|
| 974 | + } |
|
| 975 | 975 | |
| 976 | - $addon->set_name($addon_name); |
|
| 977 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 978 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 979 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 980 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 981 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 982 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 983 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 984 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 985 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 986 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 987 | - //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 988 | - //the plugin mainfile's path upon construction. |
|
| 989 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 990 | - // call any additional admin_callback functions during load_admin_controller hook |
|
| 991 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 992 | - add_action( |
|
| 993 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 994 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 995 | - ); |
|
| 996 | - } |
|
| 997 | - return $addon; |
|
| 998 | - } |
|
| 976 | + $addon->set_name($addon_name); |
|
| 977 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 978 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 979 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 980 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 981 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 982 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 983 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 984 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 985 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 986 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 987 | + //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 988 | + //the plugin mainfile's path upon construction. |
|
| 989 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 990 | + // call any additional admin_callback functions during load_admin_controller hook |
|
| 991 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 992 | + add_action( |
|
| 993 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 994 | + array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 995 | + ); |
|
| 996 | + } |
|
| 997 | + return $addon; |
|
| 998 | + } |
|
| 999 | 999 | |
| 1000 | 1000 | |
| 1001 | - /** |
|
| 1002 | - * load_pue_update - Update notifications |
|
| 1003 | - * |
|
| 1004 | - * @return void |
|
| 1005 | - * @throws InvalidArgumentException |
|
| 1006 | - * @throws InvalidDataTypeException |
|
| 1007 | - * @throws InvalidInterfaceException |
|
| 1008 | - */ |
|
| 1009 | - public static function load_pue_update() |
|
| 1010 | - { |
|
| 1011 | - // load PUE client |
|
| 1012 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 1013 | - // cycle thru settings |
|
| 1014 | - foreach (self::$_settings as $settings) { |
|
| 1015 | - if (! empty($settings['pue_options'])) { |
|
| 1016 | - // initiate the class and start the plugin update engine! |
|
| 1017 | - new PluginUpdateEngineChecker( |
|
| 1018 | - // host file URL |
|
| 1019 | - 'https://eventespresso.com', |
|
| 1020 | - // plugin slug(s) |
|
| 1021 | - array( |
|
| 1022 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 1023 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1024 | - ), |
|
| 1025 | - // options |
|
| 1026 | - array( |
|
| 1027 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1028 | - 'lang_domain' => 'event_espresso', |
|
| 1029 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1030 | - 'option_key' => 'site_license_key', |
|
| 1031 | - 'options_page_slug' => 'event_espresso', |
|
| 1032 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1033 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1034 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1035 | - ) |
|
| 1036 | - ); |
|
| 1037 | - } |
|
| 1038 | - } |
|
| 1039 | - } |
|
| 1001 | + /** |
|
| 1002 | + * load_pue_update - Update notifications |
|
| 1003 | + * |
|
| 1004 | + * @return void |
|
| 1005 | + * @throws InvalidArgumentException |
|
| 1006 | + * @throws InvalidDataTypeException |
|
| 1007 | + * @throws InvalidInterfaceException |
|
| 1008 | + */ |
|
| 1009 | + public static function load_pue_update() |
|
| 1010 | + { |
|
| 1011 | + // load PUE client |
|
| 1012 | + require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 1013 | + // cycle thru settings |
|
| 1014 | + foreach (self::$_settings as $settings) { |
|
| 1015 | + if (! empty($settings['pue_options'])) { |
|
| 1016 | + // initiate the class and start the plugin update engine! |
|
| 1017 | + new PluginUpdateEngineChecker( |
|
| 1018 | + // host file URL |
|
| 1019 | + 'https://eventespresso.com', |
|
| 1020 | + // plugin slug(s) |
|
| 1021 | + array( |
|
| 1022 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 1023 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1024 | + ), |
|
| 1025 | + // options |
|
| 1026 | + array( |
|
| 1027 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1028 | + 'lang_domain' => 'event_espresso', |
|
| 1029 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1030 | + 'option_key' => 'site_license_key', |
|
| 1031 | + 'options_page_slug' => 'event_espresso', |
|
| 1032 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1033 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1034 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1035 | + ) |
|
| 1036 | + ); |
|
| 1037 | + } |
|
| 1038 | + } |
|
| 1039 | + } |
|
| 1040 | 1040 | |
| 1041 | 1041 | |
| 1042 | - /** |
|
| 1043 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1044 | - * |
|
| 1045 | - * @since 4.4.0 |
|
| 1046 | - * @return void |
|
| 1047 | - * @throws EE_Error |
|
| 1048 | - */ |
|
| 1049 | - public static function register_message_types() |
|
| 1050 | - { |
|
| 1051 | - foreach (self::$_settings as $addon_name => $settings) { |
|
| 1052 | - if (! empty($settings['message_types'])) { |
|
| 1053 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1054 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1055 | - } |
|
| 1056 | - } |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1042 | + /** |
|
| 1043 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1044 | + * |
|
| 1045 | + * @since 4.4.0 |
|
| 1046 | + * @return void |
|
| 1047 | + * @throws EE_Error |
|
| 1048 | + */ |
|
| 1049 | + public static function register_message_types() |
|
| 1050 | + { |
|
| 1051 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 1052 | + if (! empty($settings['message_types'])) { |
|
| 1053 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1054 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1055 | + } |
|
| 1056 | + } |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | 1059 | |
| 1060 | 1060 | |
| 1061 | - /** |
|
| 1062 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1063 | - * |
|
| 1064 | - * @since 4.3.0 |
|
| 1065 | - * @param string $addon_name the name for the addon that was previously registered |
|
| 1066 | - * @throws DomainException |
|
| 1067 | - * @throws EE_Error |
|
| 1068 | - * @throws InvalidArgumentException |
|
| 1069 | - * @throws InvalidDataTypeException |
|
| 1070 | - * @throws InvalidInterfaceException |
|
| 1071 | - */ |
|
| 1072 | - public static function deregister($addon_name = null) |
|
| 1073 | - { |
|
| 1074 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1075 | - try { |
|
| 1076 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1077 | - $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 1078 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1079 | - // setup DMS |
|
| 1080 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1081 | - } |
|
| 1082 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1083 | - // register admin page |
|
| 1084 | - EE_Register_Admin_Page::deregister($addon_name); |
|
| 1085 | - } |
|
| 1086 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1087 | - // add to list of modules to be registered |
|
| 1088 | - EE_Register_Module::deregister($addon_name); |
|
| 1089 | - } |
|
| 1090 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1091 | - || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 1092 | - ) { |
|
| 1093 | - // add to list of shortcodes to be registered |
|
| 1094 | - EE_Register_Shortcode::deregister($addon_name); |
|
| 1095 | - } |
|
| 1096 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1097 | - // if config_class present let's register config. |
|
| 1098 | - EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1099 | - } |
|
| 1100 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1101 | - // add to list of widgets to be registered |
|
| 1102 | - EE_Register_Widget::deregister($addon_name); |
|
| 1103 | - } |
|
| 1104 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1105 | - || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1106 | - ) { |
|
| 1107 | - // add to list of shortcodes to be registered |
|
| 1108 | - EE_Register_Model::deregister($addon_name); |
|
| 1109 | - } |
|
| 1110 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1111 | - || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1112 | - ) { |
|
| 1113 | - // add to list of shortcodes to be registered |
|
| 1114 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1115 | - } |
|
| 1116 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1117 | - foreach ( |
|
| 1118 | - (array)self::$_settings[$addon_name]['message_types'] as $message_type => |
|
| 1119 | - $message_type_settings |
|
| 1120 | - ) { |
|
| 1121 | - EE_Register_Message_Type::deregister($message_type); |
|
| 1122 | - } |
|
| 1123 | - } |
|
| 1124 | - //deregister capabilities for addon |
|
| 1125 | - if ( |
|
| 1126 | - ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1127 | - || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1128 | - ) { |
|
| 1129 | - EE_Register_Capabilities::deregister($addon_name); |
|
| 1130 | - } |
|
| 1131 | - //deregister custom_post_types for addon |
|
| 1132 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1133 | - EE_Register_CPT::deregister($addon_name); |
|
| 1134 | - } |
|
| 1135 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1136 | - EE_Register_Payment_Method::deregister($addon_name); |
|
| 1137 | - } |
|
| 1138 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1139 | - if ($addon instanceof EE_Addon) { |
|
| 1140 | - remove_action( |
|
| 1141 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1142 | - array($addon, 'deactivation') |
|
| 1143 | - ); |
|
| 1144 | - remove_action( |
|
| 1145 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1146 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1147 | - ); |
|
| 1148 | - //remove `after_registration` call |
|
| 1149 | - remove_action( |
|
| 1150 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1151 | - array($addon, 'after_registration'), |
|
| 1152 | - 999 |
|
| 1153 | - ); |
|
| 1154 | - } |
|
| 1155 | - EE_Registry::instance()->removeAddon($class_name); |
|
| 1156 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
| 1157 | - //the add-on was not yet registered in the registry, so RegistryContainer::__get() throws this exception. |
|
| 1158 | - //also no need to worry about this or log it, it's ok to deregister an add-on before its registered in the registry |
|
| 1159 | - } catch (Exception $e) { |
|
| 1160 | - new ExceptionLogger($e); |
|
| 1161 | - } |
|
| 1162 | - unset(self::$_settings[ $addon_name ]); |
|
| 1163 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1164 | - } |
|
| 1165 | - } |
|
| 1061 | + /** |
|
| 1062 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1063 | + * |
|
| 1064 | + * @since 4.3.0 |
|
| 1065 | + * @param string $addon_name the name for the addon that was previously registered |
|
| 1066 | + * @throws DomainException |
|
| 1067 | + * @throws EE_Error |
|
| 1068 | + * @throws InvalidArgumentException |
|
| 1069 | + * @throws InvalidDataTypeException |
|
| 1070 | + * @throws InvalidInterfaceException |
|
| 1071 | + */ |
|
| 1072 | + public static function deregister($addon_name = null) |
|
| 1073 | + { |
|
| 1074 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1075 | + try { |
|
| 1076 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1077 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 1078 | + if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1079 | + // setup DMS |
|
| 1080 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1081 | + } |
|
| 1082 | + if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1083 | + // register admin page |
|
| 1084 | + EE_Register_Admin_Page::deregister($addon_name); |
|
| 1085 | + } |
|
| 1086 | + if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1087 | + // add to list of modules to be registered |
|
| 1088 | + EE_Register_Module::deregister($addon_name); |
|
| 1089 | + } |
|
| 1090 | + if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1091 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 1092 | + ) { |
|
| 1093 | + // add to list of shortcodes to be registered |
|
| 1094 | + EE_Register_Shortcode::deregister($addon_name); |
|
| 1095 | + } |
|
| 1096 | + if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1097 | + // if config_class present let's register config. |
|
| 1098 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1099 | + } |
|
| 1100 | + if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1101 | + // add to list of widgets to be registered |
|
| 1102 | + EE_Register_Widget::deregister($addon_name); |
|
| 1103 | + } |
|
| 1104 | + if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1105 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1106 | + ) { |
|
| 1107 | + // add to list of shortcodes to be registered |
|
| 1108 | + EE_Register_Model::deregister($addon_name); |
|
| 1109 | + } |
|
| 1110 | + if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1111 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1112 | + ) { |
|
| 1113 | + // add to list of shortcodes to be registered |
|
| 1114 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1115 | + } |
|
| 1116 | + if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1117 | + foreach ( |
|
| 1118 | + (array)self::$_settings[$addon_name]['message_types'] as $message_type => |
|
| 1119 | + $message_type_settings |
|
| 1120 | + ) { |
|
| 1121 | + EE_Register_Message_Type::deregister($message_type); |
|
| 1122 | + } |
|
| 1123 | + } |
|
| 1124 | + //deregister capabilities for addon |
|
| 1125 | + if ( |
|
| 1126 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1127 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1128 | + ) { |
|
| 1129 | + EE_Register_Capabilities::deregister($addon_name); |
|
| 1130 | + } |
|
| 1131 | + //deregister custom_post_types for addon |
|
| 1132 | + if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1133 | + EE_Register_CPT::deregister($addon_name); |
|
| 1134 | + } |
|
| 1135 | + if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1136 | + EE_Register_Payment_Method::deregister($addon_name); |
|
| 1137 | + } |
|
| 1138 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1139 | + if ($addon instanceof EE_Addon) { |
|
| 1140 | + remove_action( |
|
| 1141 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1142 | + array($addon, 'deactivation') |
|
| 1143 | + ); |
|
| 1144 | + remove_action( |
|
| 1145 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1146 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1147 | + ); |
|
| 1148 | + //remove `after_registration` call |
|
| 1149 | + remove_action( |
|
| 1150 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1151 | + array($addon, 'after_registration'), |
|
| 1152 | + 999 |
|
| 1153 | + ); |
|
| 1154 | + } |
|
| 1155 | + EE_Registry::instance()->removeAddon($class_name); |
|
| 1156 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
| 1157 | + //the add-on was not yet registered in the registry, so RegistryContainer::__get() throws this exception. |
|
| 1158 | + //also no need to worry about this or log it, it's ok to deregister an add-on before its registered in the registry |
|
| 1159 | + } catch (Exception $e) { |
|
| 1160 | + new ExceptionLogger($e); |
|
| 1161 | + } |
|
| 1162 | + unset(self::$_settings[ $addon_name ]); |
|
| 1163 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1164 | + } |
|
| 1165 | + } |
|
| 1166 | 1166 | |
| 1167 | 1167 | |
| 1168 | 1168 | } |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | // offsets: 0 . 1 . 2 . 3 . 4 |
| 73 | 73 | $version_parts = explode('.', $min_core_version); |
| 74 | 74 | //check they specified the micro version (after 2nd period) |
| 75 | - if (! isset($version_parts[2])) { |
|
| 75 | + if ( ! isset($version_parts[2])) { |
|
| 76 | 76 | $version_parts[2] = '0'; |
| 77 | 77 | } |
| 78 | 78 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
| 79 | 79 | //soon we can assume that's 'rc', but this current version is 'alpha' |
| 80 | - if (! isset($version_parts[3])) { |
|
| 80 | + if ( ! isset($version_parts[3])) { |
|
| 81 | 81 | $version_parts[3] = 'dev'; |
| 82 | 82 | } |
| 83 | - if (! isset($version_parts[4])) { |
|
| 83 | + if ( ! isset($version_parts[4])) { |
|
| 84 | 84 | $version_parts[4] = '000'; |
| 85 | 85 | } |
| 86 | 86 | return implode('.', $version_parts); |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | // setup PUE |
| 252 | 252 | EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
| 253 | 253 | // does this addon work with this version of core or WordPress ? |
| 254 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 254 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 255 | 255 | return; |
| 256 | 256 | } |
| 257 | 257 | // register namespaces |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | ) |
| 310 | 310 | ); |
| 311 | 311 | } |
| 312 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 312 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 313 | 313 | throw new EE_Error( |
| 314 | 314 | sprintf( |
| 315 | 315 | __( |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | ); |
| 322 | 322 | } |
| 323 | 323 | // check that addon has not already been registered with that name |
| 324 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 324 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 325 | 325 | throw new EE_Error( |
| 326 | 326 | sprintf( |
| 327 | 327 | __( |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
| 354 | 354 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
| 355 | 355 | ? $class_name |
| 356 | - : 'EE_' . $class_name; |
|
| 356 | + : 'EE_'.$class_name; |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | |
@@ -512,9 +512,9 @@ discard block |
||
| 512 | 512 | $incompatibility_message = ''; |
| 513 | 513 | //check whether this addon version is compatible with EE core |
| 514 | 514 | if ( |
| 515 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 515 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 516 | 516 | && ! self::_meets_min_core_version_requirement( |
| 517 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 517 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 518 | 518 | $addon_settings['version'] |
| 519 | 519 | ) |
| 520 | 520 | ) { |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | ), |
| 525 | 525 | $addon_name, |
| 526 | 526 | '<br />', |
| 527 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 527 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 528 | 528 | '<span style="font-weight: bold; color: #D54E21;">', |
| 529 | 529 | '</span><br />' |
| 530 | 530 | ); |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | '</span><br />' |
| 557 | 557 | ); |
| 558 | 558 | } |
| 559 | - if (! empty($incompatibility_message)) { |
|
| 559 | + if ( ! empty($incompatibility_message)) { |
|
| 560 | 560 | // remove 'activate' from the REQUEST |
| 561 | 561 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
| 562 | 562 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -584,11 +584,11 @@ discard block |
||
| 584 | 584 | */ |
| 585 | 585 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
| 586 | 586 | { |
| 587 | - if (! empty($setup_args['pue_options'])) { |
|
| 588 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 587 | + if ( ! empty($setup_args['pue_options'])) { |
|
| 588 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
| 589 | 589 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
| 590 | 590 | ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
| 591 | - : 'espresso_' . strtolower($class_name), |
|
| 591 | + : 'espresso_'.strtolower($class_name), |
|
| 592 | 592 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
| 593 | 593 | ? (string) $setup_args['pue_options']['plugin_basename'] |
| 594 | 594 | : plugin_basename($setup_args['main_file_path']), |
@@ -648,12 +648,12 @@ discard block |
||
| 648 | 648 | //(as the newly-activated addon wasn't around the first time addons were registered). |
| 649 | 649 | //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
| 650 | 650 | //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
| 651 | - if (! isset(self::$_settings[ $addon_name ]) |
|
| 652 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 653 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 651 | + if ( ! isset(self::$_settings[$addon_name]) |
|
| 652 | + || (isset(self::$_settings[$addon_name]) |
|
| 653 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 654 | 654 | ) |
| 655 | 655 | ) { |
| 656 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 656 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 657 | 657 | $addon = self::_load_and_init_addon_class($addon_name); |
| 658 | 658 | $addon->set_activation_indicator_option(); |
| 659 | 659 | // dont bother setting up the rest of the addon. |
@@ -679,10 +679,10 @@ discard block |
||
| 679 | 679 | ); |
| 680 | 680 | } |
| 681 | 681 | // make sure addon settings are set correctly without overwriting anything existing |
| 682 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 683 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 682 | + if (isset(self::$_settings[$addon_name])) { |
|
| 683 | + self::$_settings[$addon_name] += $addon_settings; |
|
| 684 | 684 | } else { |
| 685 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 685 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 686 | 686 | } |
| 687 | 687 | return false; |
| 688 | 688 | } |
@@ -695,13 +695,13 @@ discard block |
||
| 695 | 695 | */ |
| 696 | 696 | private static function _setup_autoloaders($addon_name) |
| 697 | 697 | { |
| 698 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 698 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 699 | 699 | // setup autoloader for single file |
| 700 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 700 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 701 | 701 | } |
| 702 | 702 | // setup autoloaders for folders |
| 703 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 704 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 703 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 704 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 705 | 705 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
| 706 | 706 | } |
| 707 | 707 | } |
@@ -719,27 +719,27 @@ discard block |
||
| 719 | 719 | { |
| 720 | 720 | // register new models |
| 721 | 721 | if ( |
| 722 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 723 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 722 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 723 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 724 | 724 | ) { |
| 725 | 725 | EE_Register_Model::register( |
| 726 | 726 | $addon_name, |
| 727 | 727 | array( |
| 728 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 729 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 728 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 729 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 730 | 730 | ) |
| 731 | 731 | ); |
| 732 | 732 | } |
| 733 | 733 | // register model extensions |
| 734 | 734 | if ( |
| 735 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 736 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 735 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 736 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 737 | 737 | ) { |
| 738 | 738 | EE_Register_Model_Extensions::register( |
| 739 | 739 | $addon_name, |
| 740 | 740 | array( |
| 741 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 742 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 741 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 742 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 743 | 743 | ) |
| 744 | 744 | ); |
| 745 | 745 | } |
@@ -754,10 +754,10 @@ discard block |
||
| 754 | 754 | private static function _register_data_migration_scripts($addon_name) |
| 755 | 755 | { |
| 756 | 756 | // setup DMS |
| 757 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 757 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 758 | 758 | EE_Register_Data_Migration_Scripts::register( |
| 759 | 759 | $addon_name, |
| 760 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 760 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 761 | 761 | ); |
| 762 | 762 | } |
| 763 | 763 | } |
@@ -771,12 +771,12 @@ discard block |
||
| 771 | 771 | private static function _register_config($addon_name) |
| 772 | 772 | { |
| 773 | 773 | // if config_class is present let's register config. |
| 774 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 774 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 775 | 775 | EE_Register_Config::register( |
| 776 | - self::$_settings[ $addon_name ]['config_class'], |
|
| 776 | + self::$_settings[$addon_name]['config_class'], |
|
| 777 | 777 | array( |
| 778 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 779 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 778 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 779 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 780 | 780 | ) |
| 781 | 781 | ); |
| 782 | 782 | } |
@@ -790,10 +790,10 @@ discard block |
||
| 790 | 790 | */ |
| 791 | 791 | private static function _register_admin_pages($addon_name) |
| 792 | 792 | { |
| 793 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 793 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 794 | 794 | EE_Register_Admin_Page::register( |
| 795 | 795 | $addon_name, |
| 796 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 796 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 797 | 797 | ); |
| 798 | 798 | } |
| 799 | 799 | } |
@@ -806,10 +806,10 @@ discard block |
||
| 806 | 806 | */ |
| 807 | 807 | private static function _register_modules($addon_name) |
| 808 | 808 | { |
| 809 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 809 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 810 | 810 | EE_Register_Module::register( |
| 811 | 811 | $addon_name, |
| 812 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 812 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 813 | 813 | ); |
| 814 | 814 | } |
| 815 | 815 | } |
@@ -822,17 +822,17 @@ discard block |
||
| 822 | 822 | */ |
| 823 | 823 | private static function _register_shortcodes($addon_name) |
| 824 | 824 | { |
| 825 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 826 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 825 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 826 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 827 | 827 | ) { |
| 828 | 828 | EE_Register_Shortcode::register( |
| 829 | 829 | $addon_name, |
| 830 | 830 | array( |
| 831 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 832 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 831 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 832 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
| 833 | 833 | : array(), |
| 834 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 835 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 834 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 835 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
| 836 | 836 | : array(), |
| 837 | 837 | ) |
| 838 | 838 | ); |
@@ -847,10 +847,10 @@ discard block |
||
| 847 | 847 | */ |
| 848 | 848 | private static function _register_widgets($addon_name) |
| 849 | 849 | { |
| 850 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 850 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 851 | 851 | EE_Register_Widget::register( |
| 852 | 852 | $addon_name, |
| 853 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 853 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 854 | 854 | ); |
| 855 | 855 | } |
| 856 | 856 | } |
@@ -863,12 +863,12 @@ discard block |
||
| 863 | 863 | */ |
| 864 | 864 | private static function _register_capabilities($addon_name) |
| 865 | 865 | { |
| 866 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 866 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 867 | 867 | EE_Register_Capabilities::register( |
| 868 | 868 | $addon_name, |
| 869 | 869 | array( |
| 870 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 871 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 870 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 871 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 872 | 872 | ) |
| 873 | 873 | ); |
| 874 | 874 | } |
@@ -882,7 +882,7 @@ discard block |
||
| 882 | 882 | */ |
| 883 | 883 | private static function _register_message_types($addon_name) |
| 884 | 884 | { |
| 885 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 885 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 886 | 886 | add_action( |
| 887 | 887 | 'EE_Brewing_Regular___messages_caf', |
| 888 | 888 | array('EE_Register_Addon', 'register_message_types') |
@@ -899,15 +899,15 @@ discard block |
||
| 899 | 899 | private static function _register_custom_post_types($addon_name) |
| 900 | 900 | { |
| 901 | 901 | if ( |
| 902 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 903 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 902 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 903 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 904 | 904 | ) { |
| 905 | 905 | EE_Register_CPT::register( |
| 906 | 906 | $addon_name, |
| 907 | 907 | array( |
| 908 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 909 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 910 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 908 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 909 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 910 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 911 | 911 | ) |
| 912 | 912 | ); |
| 913 | 913 | } |
@@ -925,10 +925,10 @@ discard block |
||
| 925 | 925 | */ |
| 926 | 926 | private static function _register_payment_methods($addon_name) |
| 927 | 927 | { |
| 928 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 928 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 929 | 929 | EE_Register_Payment_Method::register( |
| 930 | 930 | $addon_name, |
| 931 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 931 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 932 | 932 | ); |
| 933 | 933 | } |
| 934 | 934 | } |
@@ -949,49 +949,49 @@ discard block |
||
| 949 | 949 | { |
| 950 | 950 | $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
| 951 | 951 | $addon = $loader->getShared( |
| 952 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 952 | + self::$_settings[$addon_name]['class_name'], |
|
| 953 | 953 | array('EE_Registry::create(addon)' => true) |
| 954 | 954 | ); |
| 955 | 955 | // setter inject dep map if required |
| 956 | - if($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null){ |
|
| 956 | + if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
| 957 | 957 | $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
| 958 | 958 | } |
| 959 | 959 | // setter inject domain if required |
| 960 | - if( |
|
| 960 | + if ( |
|
| 961 | 961 | $addon instanceof RequiresDomainInterface |
| 962 | - && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
| 962 | + && self::$_settings[$addon_name]['domain_fqcn'] !== '' |
|
| 963 | 963 | && $addon->domain() === null |
| 964 | - ){ |
|
| 964 | + ) { |
|
| 965 | 965 | $addon->setDomain( |
| 966 | 966 | $loader->getShared( |
| 967 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 967 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
| 968 | 968 | array( |
| 969 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
| 970 | - self::$_settings[ $addon_name ]['version'] |
|
| 969 | + self::$_settings[$addon_name]['main_file_path'], |
|
| 970 | + self::$_settings[$addon_name]['version'] |
|
| 971 | 971 | ) |
| 972 | 972 | ) |
| 973 | 973 | ); |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | $addon->set_name($addon_name); |
| 977 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 978 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 979 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 980 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 981 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 982 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 983 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 984 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 985 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 986 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 977 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 978 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 979 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 980 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 981 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 982 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 983 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 984 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 985 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 986 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 987 | 987 | //unfortunately this can't be hooked in upon construction, because we don't have |
| 988 | 988 | //the plugin mainfile's path upon construction. |
| 989 | 989 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
| 990 | 990 | // call any additional admin_callback functions during load_admin_controller hook |
| 991 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 991 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 992 | 992 | add_action( |
| 993 | 993 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
| 994 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 994 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 995 | 995 | ); |
| 996 | 996 | } |
| 997 | 997 | return $addon; |
@@ -1009,10 +1009,10 @@ discard block |
||
| 1009 | 1009 | public static function load_pue_update() |
| 1010 | 1010 | { |
| 1011 | 1011 | // load PUE client |
| 1012 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 1012 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
| 1013 | 1013 | // cycle thru settings |
| 1014 | 1014 | foreach (self::$_settings as $settings) { |
| 1015 | - if (! empty($settings['pue_options'])) { |
|
| 1015 | + if ( ! empty($settings['pue_options'])) { |
|
| 1016 | 1016 | // initiate the class and start the plugin update engine! |
| 1017 | 1017 | new PluginUpdateEngineChecker( |
| 1018 | 1018 | // host file URL |
@@ -1020,7 +1020,7 @@ discard block |
||
| 1020 | 1020 | // plugin slug(s) |
| 1021 | 1021 | array( |
| 1022 | 1022 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
| 1023 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1023 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
| 1024 | 1024 | ), |
| 1025 | 1025 | // options |
| 1026 | 1026 | array( |
@@ -1049,7 +1049,7 @@ discard block |
||
| 1049 | 1049 | public static function register_message_types() |
| 1050 | 1050 | { |
| 1051 | 1051 | foreach (self::$_settings as $addon_name => $settings) { |
| 1052 | - if (! empty($settings['message_types'])) { |
|
| 1052 | + if ( ! empty($settings['message_types'])) { |
|
| 1053 | 1053 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
| 1054 | 1054 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
| 1055 | 1055 | } |
@@ -1071,51 +1071,51 @@ discard block |
||
| 1071 | 1071 | */ |
| 1072 | 1072 | public static function deregister($addon_name = null) |
| 1073 | 1073 | { |
| 1074 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1074 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
| 1075 | 1075 | try { |
| 1076 | 1076 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
| 1077 | 1077 | $class_name = self::$_settings[$addon_name]['class_name']; |
| 1078 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1078 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1079 | 1079 | // setup DMS |
| 1080 | 1080 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
| 1081 | 1081 | } |
| 1082 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1082 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1083 | 1083 | // register admin page |
| 1084 | 1084 | EE_Register_Admin_Page::deregister($addon_name); |
| 1085 | 1085 | } |
| 1086 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1086 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1087 | 1087 | // add to list of modules to be registered |
| 1088 | 1088 | EE_Register_Module::deregister($addon_name); |
| 1089 | 1089 | } |
| 1090 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1090 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1091 | 1091 | || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
| 1092 | 1092 | ) { |
| 1093 | 1093 | // add to list of shortcodes to be registered |
| 1094 | 1094 | EE_Register_Shortcode::deregister($addon_name); |
| 1095 | 1095 | } |
| 1096 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1096 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1097 | 1097 | // if config_class present let's register config. |
| 1098 | 1098 | EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
| 1099 | 1099 | } |
| 1100 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1100 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1101 | 1101 | // add to list of widgets to be registered |
| 1102 | 1102 | EE_Register_Widget::deregister($addon_name); |
| 1103 | 1103 | } |
| 1104 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1104 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1105 | 1105 | || ! empty(self::$_settings[$addon_name]['class_paths']) |
| 1106 | 1106 | ) { |
| 1107 | 1107 | // add to list of shortcodes to be registered |
| 1108 | 1108 | EE_Register_Model::deregister($addon_name); |
| 1109 | 1109 | } |
| 1110 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1110 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1111 | 1111 | || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
| 1112 | 1112 | ) { |
| 1113 | 1113 | // add to list of shortcodes to be registered |
| 1114 | 1114 | EE_Register_Model_Extensions::deregister($addon_name); |
| 1115 | 1115 | } |
| 1116 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1116 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1117 | 1117 | foreach ( |
| 1118 | - (array)self::$_settings[$addon_name]['message_types'] as $message_type => |
|
| 1118 | + (array) self::$_settings[$addon_name]['message_types'] as $message_type => |
|
| 1119 | 1119 | $message_type_settings |
| 1120 | 1120 | ) { |
| 1121 | 1121 | EE_Register_Message_Type::deregister($message_type); |
@@ -1129,16 +1129,16 @@ discard block |
||
| 1129 | 1129 | EE_Register_Capabilities::deregister($addon_name); |
| 1130 | 1130 | } |
| 1131 | 1131 | //deregister custom_post_types for addon |
| 1132 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1132 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1133 | 1133 | EE_Register_CPT::deregister($addon_name); |
| 1134 | 1134 | } |
| 1135 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1135 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1136 | 1136 | EE_Register_Payment_Method::deregister($addon_name); |
| 1137 | 1137 | } |
| 1138 | 1138 | $addon = EE_Registry::instance()->getAddon($class_name); |
| 1139 | 1139 | if ($addon instanceof EE_Addon) { |
| 1140 | 1140 | remove_action( |
| 1141 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1141 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
| 1142 | 1142 | array($addon, 'deactivation') |
| 1143 | 1143 | ); |
| 1144 | 1144 | remove_action( |
@@ -1159,7 +1159,7 @@ discard block |
||
| 1159 | 1159 | } catch (Exception $e) { |
| 1160 | 1160 | new ExceptionLogger($e); |
| 1161 | 1161 | } |
| 1162 | - unset(self::$_settings[ $addon_name ]); |
|
| 1162 | + unset(self::$_settings[$addon_name]); |
|
| 1163 | 1163 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
| 1164 | 1164 | } |
| 1165 | 1165 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use EventEspresso\core\exceptions\InvalidEntityException; |
| 6 | 6 | |
| 7 | 7 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 8 | - exit('No direct script access allowed'); |
|
| 8 | + exit('No direct script access allowed'); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | |
@@ -20,1864 +20,1864 @@ discard block |
||
| 20 | 20 | class EED_Single_Page_Checkout extends EED_Module |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * $_initialized - has the SPCO controller already been initialized ? |
|
| 25 | - * |
|
| 26 | - * @access private |
|
| 27 | - * @var bool $_initialized |
|
| 28 | - */ |
|
| 29 | - private static $_initialized = false; |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
| 34 | - * |
|
| 35 | - * @access private |
|
| 36 | - * @var bool $_valid_checkout |
|
| 37 | - */ |
|
| 38 | - private static $_checkout_verified = true; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * $_reg_steps_array - holds initial array of reg steps |
|
| 42 | - * |
|
| 43 | - * @access private |
|
| 44 | - * @var array $_reg_steps_array |
|
| 45 | - */ |
|
| 46 | - private static $_reg_steps_array = array(); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
| 50 | - * |
|
| 51 | - * @access public |
|
| 52 | - * @var EE_Checkout $checkout |
|
| 53 | - */ |
|
| 54 | - public $checkout; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @return EED_Module|EED_Single_Page_Checkout |
|
| 60 | - */ |
|
| 61 | - public static function instance() |
|
| 62 | - { |
|
| 63 | - add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
| 64 | - return parent::get_instance(__CLASS__); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return EE_CART |
|
| 71 | - */ |
|
| 72 | - public function cart() |
|
| 73 | - { |
|
| 74 | - return $this->checkout->cart; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @return EE_Transaction |
|
| 81 | - */ |
|
| 82 | - public function transaction() |
|
| 83 | - { |
|
| 84 | - return $this->checkout->transaction; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 91 | - * |
|
| 92 | - * @access public |
|
| 93 | - * @return void |
|
| 94 | - * @throws EE_Error |
|
| 95 | - */ |
|
| 96 | - public static function set_hooks() |
|
| 97 | - { |
|
| 98 | - EED_Single_Page_Checkout::set_definitions(); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - * @return void |
|
| 108 | - * @throws EE_Error |
|
| 109 | - */ |
|
| 110 | - public static function set_hooks_admin() |
|
| 111 | - { |
|
| 112 | - EED_Single_Page_Checkout::set_definitions(); |
|
| 113 | - if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 116 | - // going to start an output buffer in case anything gets accidentally output |
|
| 117 | - // that might disrupt our JSON response |
|
| 118 | - ob_start(); |
|
| 119 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 120 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
| 121 | - // set ajax hooks |
|
| 122 | - add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 123 | - add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 124 | - add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 125 | - add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 126 | - add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 127 | - add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * process ajax request |
|
| 134 | - * |
|
| 135 | - * @param string $ajax_action |
|
| 136 | - * @throws EE_Error |
|
| 137 | - */ |
|
| 138 | - public static function process_ajax_request($ajax_action) |
|
| 139 | - { |
|
| 140 | - EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
| 141 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * ajax display registration step |
|
| 148 | - * |
|
| 149 | - * @throws EE_Error |
|
| 150 | - */ |
|
| 151 | - public static function display_reg_step() |
|
| 152 | - { |
|
| 153 | - EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * ajax process registration step |
|
| 160 | - * |
|
| 161 | - * @throws EE_Error |
|
| 162 | - */ |
|
| 163 | - public static function process_reg_step() |
|
| 164 | - { |
|
| 165 | - EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * ajax process registration step |
|
| 172 | - * |
|
| 173 | - * @throws EE_Error |
|
| 174 | - */ |
|
| 175 | - public static function update_reg_step() |
|
| 176 | - { |
|
| 177 | - EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * update_checkout |
|
| 184 | - * |
|
| 185 | - * @access public |
|
| 186 | - * @return void |
|
| 187 | - * @throws EE_Error |
|
| 188 | - */ |
|
| 189 | - public static function update_checkout() |
|
| 190 | - { |
|
| 191 | - EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * load_request_handler |
|
| 198 | - * |
|
| 199 | - * @access public |
|
| 200 | - * @return void |
|
| 201 | - */ |
|
| 202 | - public static function load_request_handler() |
|
| 203 | - { |
|
| 204 | - // load core Request_Handler class |
|
| 205 | - if (EE_Registry::instance()->REQ !== null) { |
|
| 206 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * set_definitions |
|
| 214 | - * |
|
| 215 | - * @access public |
|
| 216 | - * @return void |
|
| 217 | - * @throws EE_Error |
|
| 218 | - */ |
|
| 219 | - public static function set_definitions() |
|
| 220 | - { |
|
| 221 | - if(defined('SPCO_BASE_PATH')) { |
|
| 222 | - return; |
|
| 223 | - } |
|
| 224 | - define( |
|
| 225 | - 'SPCO_BASE_PATH', |
|
| 226 | - rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
| 227 | - ); |
|
| 228 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
| 229 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
| 230 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
| 231 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
| 232 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
| 233 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
| 234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
| 235 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
| 236 | - __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
| 237 | - 'event_espresso'), |
|
| 238 | - '<h4 class="important-notice">', |
|
| 239 | - '</h4>', |
|
| 240 | - '<br />', |
|
| 241 | - '<p>', |
|
| 242 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 243 | - '">', |
|
| 244 | - '</a>', |
|
| 245 | - '</p>' |
|
| 246 | - ); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * load_reg_steps |
|
| 253 | - * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
| 254 | - * |
|
| 255 | - * @access private |
|
| 256 | - * @throws EE_Error |
|
| 257 | - */ |
|
| 258 | - public static function load_reg_steps() |
|
| 259 | - { |
|
| 260 | - static $reg_steps_loaded = false; |
|
| 261 | - if ($reg_steps_loaded) { |
|
| 262 | - return; |
|
| 263 | - } |
|
| 264 | - // filter list of reg_steps |
|
| 265 | - $reg_steps_to_load = (array)apply_filters( |
|
| 266 | - 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
| 267 | - EED_Single_Page_Checkout::get_reg_steps() |
|
| 268 | - ); |
|
| 269 | - // sort by key (order) |
|
| 270 | - ksort($reg_steps_to_load); |
|
| 271 | - // loop through folders |
|
| 272 | - foreach ($reg_steps_to_load as $order => $reg_step) { |
|
| 273 | - // we need a |
|
| 274 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 275 | - // copy over to the reg_steps_array |
|
| 276 | - EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
| 277 | - // register custom key route for each reg step |
|
| 278 | - // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
| 279 | - EE_Config::register_route( |
|
| 280 | - $reg_step['slug'], |
|
| 281 | - 'EED_Single_Page_Checkout', |
|
| 282 | - 'run', |
|
| 283 | - 'step' |
|
| 284 | - ); |
|
| 285 | - // add AJAX or other hooks |
|
| 286 | - if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
| 287 | - // setup autoloaders if necessary |
|
| 288 | - if ( ! class_exists($reg_step['class_name'])) { |
|
| 289 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
| 290 | - $reg_step['file_path'], |
|
| 291 | - true |
|
| 292 | - ); |
|
| 293 | - } |
|
| 294 | - if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
| 295 | - call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - $reg_steps_loaded = true; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * get_reg_steps |
|
| 307 | - * |
|
| 308 | - * @access public |
|
| 309 | - * @return array |
|
| 310 | - */ |
|
| 311 | - public static function get_reg_steps() |
|
| 312 | - { |
|
| 313 | - $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
| 314 | - if (empty($reg_steps)) { |
|
| 315 | - $reg_steps = array( |
|
| 316 | - 10 => array( |
|
| 317 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
| 318 | - 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
| 319 | - 'slug' => 'attendee_information', |
|
| 320 | - 'has_hooks' => false, |
|
| 321 | - ), |
|
| 322 | - 20 => array( |
|
| 323 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
| 324 | - 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
| 325 | - 'slug' => 'registration_confirmation', |
|
| 326 | - 'has_hooks' => false, |
|
| 327 | - ), |
|
| 328 | - 30 => array( |
|
| 329 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
| 330 | - 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 331 | - 'slug' => 'payment_options', |
|
| 332 | - 'has_hooks' => true, |
|
| 333 | - ), |
|
| 334 | - 999 => array( |
|
| 335 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
| 336 | - 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
| 337 | - 'slug' => 'finalize_registration', |
|
| 338 | - 'has_hooks' => false, |
|
| 339 | - ), |
|
| 340 | - ); |
|
| 341 | - } |
|
| 342 | - return $reg_steps; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * registration_checkout_for_admin |
|
| 349 | - * |
|
| 350 | - * @access public |
|
| 351 | - * @return string |
|
| 352 | - * @throws EE_Error |
|
| 353 | - */ |
|
| 354 | - public static function registration_checkout_for_admin() |
|
| 355 | - { |
|
| 356 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 357 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 358 | - EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
| 359 | - EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
| 360 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 361 | - EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
| 362 | - return EE_Registry::instance()->REQ->get_output(); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * process_registration_from_admin |
|
| 369 | - * |
|
| 370 | - * @access public |
|
| 371 | - * @return \EE_Transaction |
|
| 372 | - * @throws EE_Error |
|
| 373 | - */ |
|
| 374 | - public static function process_registration_from_admin() |
|
| 375 | - { |
|
| 376 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 377 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 378 | - EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
| 379 | - EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
| 380 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 381 | - if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
| 382 | - $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
| 383 | - if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
| 384 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
| 385 | - if ($final_reg_step->process_reg_step()) { |
|
| 386 | - $final_reg_step->set_completed(); |
|
| 387 | - EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
| 388 | - return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - return null; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * run |
|
| 399 | - * |
|
| 400 | - * @access public |
|
| 401 | - * @param WP_Query $WP_Query |
|
| 402 | - * @return void |
|
| 403 | - * @throws EE_Error |
|
| 404 | - */ |
|
| 405 | - public function run($WP_Query) |
|
| 406 | - { |
|
| 407 | - if ( |
|
| 408 | - $WP_Query instanceof WP_Query |
|
| 409 | - && $WP_Query->is_main_query() |
|
| 410 | - && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
| 411 | - && $this->_is_reg_checkout() |
|
| 412 | - ) { |
|
| 413 | - $this->_initialize(); |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * determines whether current url matches reg page url |
|
| 421 | - * |
|
| 422 | - * @return bool |
|
| 423 | - */ |
|
| 424 | - protected function _is_reg_checkout() |
|
| 425 | - { |
|
| 426 | - // get current permalink for reg page without any extra query args |
|
| 427 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
| 428 | - // get request URI for current request, but without the scheme or host |
|
| 429 | - $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 430 | - $current_request_uri = html_entity_decode($current_request_uri); |
|
| 431 | - // get array of query args from the current request URI |
|
| 432 | - $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
| 433 | - // grab page id if it is set |
|
| 434 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
| 435 | - // and remove the page id from the query args (we will re-add it later) |
|
| 436 | - unset($query_args['page_id']); |
|
| 437 | - // now strip all query args from current request URI |
|
| 438 | - $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
| 439 | - // and re-add the page id if it was set |
|
| 440 | - if ($page_id) { |
|
| 441 | - $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
| 442 | - } |
|
| 443 | - // remove slashes and ? |
|
| 444 | - $current_request_uri = trim($current_request_uri, '?/'); |
|
| 445 | - // is current request URI part of the known full reg page URL ? |
|
| 446 | - return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @param WP_Query $wp_query |
|
| 453 | - * @return void |
|
| 454 | - * @throws EE_Error |
|
| 455 | - */ |
|
| 456 | - public static function init($wp_query) |
|
| 457 | - { |
|
| 458 | - EED_Single_Page_Checkout::instance()->run($wp_query); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * _initialize - initial module setup |
|
| 465 | - * |
|
| 466 | - * @access private |
|
| 467 | - * @throws EE_Error |
|
| 468 | - * @return void |
|
| 469 | - */ |
|
| 470 | - private function _initialize() |
|
| 471 | - { |
|
| 472 | - // ensure SPCO doesn't run twice |
|
| 473 | - if (EED_Single_Page_Checkout::$_initialized) { |
|
| 474 | - return; |
|
| 475 | - } |
|
| 476 | - try { |
|
| 477 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
| 478 | - $this->_verify_session(); |
|
| 479 | - // setup the EE_Checkout object |
|
| 480 | - $this->checkout = $this->_initialize_checkout(); |
|
| 481 | - // filter checkout |
|
| 482 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
| 483 | - // get the $_GET |
|
| 484 | - $this->_get_request_vars(); |
|
| 485 | - if ($this->_block_bots()) { |
|
| 486 | - return; |
|
| 487 | - } |
|
| 488 | - // filter continue_reg |
|
| 489 | - $this->checkout->continue_reg = apply_filters( |
|
| 490 | - 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
| 491 | - true, |
|
| 492 | - $this->checkout |
|
| 493 | - ); |
|
| 494 | - // load the reg steps array |
|
| 495 | - if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
| 496 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 497 | - return; |
|
| 498 | - } |
|
| 499 | - // set the current step |
|
| 500 | - $this->checkout->set_current_step($this->checkout->step); |
|
| 501 | - // and the next step |
|
| 502 | - $this->checkout->set_next_step(); |
|
| 503 | - // verify that everything has been setup correctly |
|
| 504 | - if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
| 505 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 506 | - return; |
|
| 507 | - } |
|
| 508 | - // lock the transaction |
|
| 509 | - $this->checkout->transaction->lock(); |
|
| 510 | - // make sure all of our cached objects are added to their respective model entity mappers |
|
| 511 | - $this->checkout->refresh_all_entities(); |
|
| 512 | - // set amount owing |
|
| 513 | - $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
| 514 | - // initialize each reg step, which gives them the chance to potentially alter the process |
|
| 515 | - $this->_initialize_reg_steps(); |
|
| 516 | - // DEBUG LOG |
|
| 517 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 518 | - // get reg form |
|
| 519 | - if( ! $this->_check_form_submission()) { |
|
| 520 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 521 | - return; |
|
| 522 | - } |
|
| 523 | - // checkout the action!!! |
|
| 524 | - $this->_process_form_action(); |
|
| 525 | - // add some style and make it dance |
|
| 526 | - $this->add_styles_and_scripts(); |
|
| 527 | - // kk... SPCO has successfully run |
|
| 528 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 529 | - // set no cache headers and constants |
|
| 530 | - EE_System::do_not_cache(); |
|
| 531 | - // add anchor |
|
| 532 | - add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
| 533 | - // remove transaction lock |
|
| 534 | - add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
| 535 | - } catch (Exception $e) { |
|
| 536 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * _verify_session |
|
| 544 | - * checks that the session is valid and not expired |
|
| 545 | - * |
|
| 546 | - * @access private |
|
| 547 | - * @throws EE_Error |
|
| 548 | - */ |
|
| 549 | - private function _verify_session() |
|
| 550 | - { |
|
| 551 | - if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 552 | - throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
| 553 | - } |
|
| 554 | - $clear_session_requested = filter_var( |
|
| 555 | - EE_Registry::instance()->REQ->get('clear_session', false), |
|
| 556 | - FILTER_VALIDATE_BOOLEAN |
|
| 557 | - ); |
|
| 558 | - // is session still valid ? |
|
| 559 | - if ($clear_session_requested |
|
| 560 | - || ( EE_Registry::instance()->SSN->expired() |
|
| 561 | - && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
| 562 | - ) |
|
| 563 | - ) { |
|
| 564 | - $this->checkout = new EE_Checkout(); |
|
| 565 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 566 | - // EE_Registry::instance()->SSN->reset_cart(); |
|
| 567 | - // EE_Registry::instance()->SSN->reset_checkout(); |
|
| 568 | - // EE_Registry::instance()->SSN->reset_transaction(); |
|
| 569 | - if (! $clear_session_requested) { |
|
| 570 | - EE_Error::add_attention( |
|
| 571 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
| 572 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 573 | - ); |
|
| 574 | - } |
|
| 575 | - // EE_Registry::instance()->SSN->reset_expired(); |
|
| 576 | - } |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * _initialize_checkout |
|
| 583 | - * loads and instantiates EE_Checkout |
|
| 584 | - * |
|
| 585 | - * @access private |
|
| 586 | - * @throws EE_Error |
|
| 587 | - * @return EE_Checkout |
|
| 588 | - */ |
|
| 589 | - private function _initialize_checkout() |
|
| 590 | - { |
|
| 591 | - // look in session for existing checkout |
|
| 592 | - /** @type EE_Checkout $checkout */ |
|
| 593 | - $checkout = EE_Registry::instance()->SSN->checkout(); |
|
| 594 | - // verify |
|
| 595 | - if ( ! $checkout instanceof EE_Checkout) { |
|
| 596 | - // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
| 597 | - $checkout = EE_Registry::instance()->load_file( |
|
| 598 | - SPCO_INC_PATH, |
|
| 599 | - 'EE_Checkout', |
|
| 600 | - 'class', array(), |
|
| 601 | - false |
|
| 602 | - ); |
|
| 603 | - } else { |
|
| 604 | - if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
| 605 | - $this->unlock_transaction(); |
|
| 606 | - wp_safe_redirect($checkout->redirect_url); |
|
| 607 | - exit(); |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
| 611 | - // verify again |
|
| 612 | - if ( ! $checkout instanceof EE_Checkout) { |
|
| 613 | - throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
| 614 | - } |
|
| 615 | - // reset anything that needs a clean slate for each request |
|
| 616 | - $checkout->reset_for_current_request(); |
|
| 617 | - return $checkout; |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * _get_request_vars |
|
| 624 | - * |
|
| 625 | - * @access private |
|
| 626 | - * @return void |
|
| 627 | - * @throws EE_Error |
|
| 628 | - */ |
|
| 629 | - private function _get_request_vars() |
|
| 630 | - { |
|
| 631 | - // load classes |
|
| 632 | - EED_Single_Page_Checkout::load_request_handler(); |
|
| 633 | - //make sure this request is marked as belonging to EE |
|
| 634 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 635 | - // which step is being requested ? |
|
| 636 | - $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
| 637 | - // which step is being edited ? |
|
| 638 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
| 639 | - // and what we're doing on the current step |
|
| 640 | - $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
| 641 | - // timestamp |
|
| 642 | - $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
| 643 | - // returning to edit ? |
|
| 644 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
| 645 | - // add reg url link to registration query params |
|
| 646 | - if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) { |
|
| 647 | - $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link; |
|
| 648 | - } |
|
| 649 | - // or some other kind of revisit ? |
|
| 650 | - $this->checkout->revisit = filter_var( |
|
| 651 | - EE_Registry::instance()->REQ->get('revisit', false), |
|
| 652 | - FILTER_VALIDATE_BOOLEAN |
|
| 653 | - ); |
|
| 654 | - // and whether or not to generate a reg form for this request |
|
| 655 | - $this->checkout->generate_reg_form = filter_var( |
|
| 656 | - EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
| 657 | - FILTER_VALIDATE_BOOLEAN |
|
| 658 | - ); |
|
| 659 | - // and whether or not to process a reg form submission for this request |
|
| 660 | - $this->checkout->process_form_submission = filter_var( |
|
| 661 | - EE_Registry::instance()->REQ->get( |
|
| 662 | - 'process_form_submission', |
|
| 663 | - $this->checkout->action === 'process_reg_step' |
|
| 664 | - ), |
|
| 665 | - FILTER_VALIDATE_BOOLEAN |
|
| 666 | - ); |
|
| 667 | - $this->checkout->process_form_submission = filter_var( |
|
| 668 | - $this->checkout->action !== 'display_spco_reg_step' |
|
| 669 | - ? $this->checkout->process_form_submission |
|
| 670 | - : false, |
|
| 671 | - FILTER_VALIDATE_BOOLEAN |
|
| 672 | - ); |
|
| 673 | - // $this->_display_request_vars(); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * _display_request_vars |
|
| 680 | - * |
|
| 681 | - * @access protected |
|
| 682 | - * @return void |
|
| 683 | - */ |
|
| 684 | - protected function _display_request_vars() |
|
| 685 | - { |
|
| 686 | - if ( ! WP_DEBUG) { |
|
| 687 | - return; |
|
| 688 | - } |
|
| 689 | - EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
| 690 | - EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
| 691 | - EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
| 692 | - EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
| 693 | - EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
| 694 | - EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
| 695 | - EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
| 696 | - EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * _block_bots |
|
| 703 | - * checks that the incoming request has either of the following set: |
|
| 704 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
| 705 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
| 706 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
| 707 | - * then where you coming from man? |
|
| 708 | - * |
|
| 709 | - * @return boolean |
|
| 710 | - */ |
|
| 711 | - private function _block_bots() |
|
| 712 | - { |
|
| 713 | - $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
| 714 | - if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
| 715 | - return true; |
|
| 716 | - } |
|
| 717 | - return false; |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * _get_first_step |
|
| 724 | - * gets slug for first step in $_reg_steps_array |
|
| 725 | - * |
|
| 726 | - * @access private |
|
| 727 | - * @throws EE_Error |
|
| 728 | - * @return string |
|
| 729 | - */ |
|
| 730 | - private function _get_first_step() |
|
| 731 | - { |
|
| 732 | - $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
| 733 | - return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - |
|
| 738 | - /** |
|
| 739 | - * _load_and_instantiate_reg_steps |
|
| 740 | - * instantiates each reg step based on the loaded reg_steps array |
|
| 741 | - * |
|
| 742 | - * @access private |
|
| 743 | - * @throws EE_Error |
|
| 744 | - * @return bool |
|
| 745 | - */ |
|
| 746 | - private function _load_and_instantiate_reg_steps() |
|
| 747 | - { |
|
| 748 | - do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
| 749 | - // have reg_steps already been instantiated ? |
|
| 750 | - if ( |
|
| 751 | - empty($this->checkout->reg_steps) |
|
| 752 | - || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
| 753 | - ) { |
|
| 754 | - // if not, then loop through raw reg steps array |
|
| 755 | - foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
| 756 | - if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
| 757 | - return false; |
|
| 758 | - } |
|
| 759 | - } |
|
| 760 | - EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
| 761 | - EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
| 762 | - // skip the registration_confirmation page ? |
|
| 763 | - if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
| 764 | - // just remove it from the reg steps array |
|
| 765 | - $this->checkout->remove_reg_step('registration_confirmation', false); |
|
| 766 | - } else if ( |
|
| 767 | - isset($this->checkout->reg_steps['registration_confirmation']) |
|
| 768 | - && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
| 769 | - ) { |
|
| 770 | - // set the order to something big like 100 |
|
| 771 | - $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
| 772 | - } |
|
| 773 | - // filter the array for good luck |
|
| 774 | - $this->checkout->reg_steps = apply_filters( |
|
| 775 | - 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
| 776 | - $this->checkout->reg_steps |
|
| 777 | - ); |
|
| 778 | - // finally re-sort based on the reg step class order properties |
|
| 779 | - $this->checkout->sort_reg_steps(); |
|
| 780 | - } else { |
|
| 781 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 782 | - // set all current step stati to FALSE |
|
| 783 | - $reg_step->set_is_current_step(false); |
|
| 784 | - } |
|
| 785 | - } |
|
| 786 | - if (empty($this->checkout->reg_steps)) { |
|
| 787 | - EE_Error::add_error( |
|
| 788 | - __('No Reg Steps were loaded..', 'event_espresso'), |
|
| 789 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 790 | - ); |
|
| 791 | - return false; |
|
| 792 | - } |
|
| 793 | - // make reg step details available to JS |
|
| 794 | - $this->checkout->set_reg_step_JSON_info(); |
|
| 795 | - return true; |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - |
|
| 800 | - /** |
|
| 801 | - * _load_and_instantiate_reg_step |
|
| 802 | - * |
|
| 803 | - * @access private |
|
| 804 | - * @param array $reg_step |
|
| 805 | - * @param int $order |
|
| 806 | - * @return bool |
|
| 807 | - */ |
|
| 808 | - private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
| 809 | - { |
|
| 810 | - // we need a file_path, class_name, and slug to add a reg step |
|
| 811 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 812 | - // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
| 813 | - if ( |
|
| 814 | - $this->checkout->reg_url_link |
|
| 815 | - && $this->checkout->step !== $reg_step['slug'] |
|
| 816 | - && $reg_step['slug'] !== 'finalize_registration' |
|
| 817 | - // normally at this point we would NOT load the reg step, but this filter can change that |
|
| 818 | - && apply_filters( |
|
| 819 | - 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
| 820 | - true, |
|
| 821 | - $reg_step, |
|
| 822 | - $this->checkout |
|
| 823 | - ) |
|
| 824 | - ) { |
|
| 825 | - return true; |
|
| 826 | - } |
|
| 827 | - // instantiate step class using file path and class name |
|
| 828 | - $reg_step_obj = EE_Registry::instance()->load_file( |
|
| 829 | - $reg_step['file_path'], |
|
| 830 | - $reg_step['class_name'], |
|
| 831 | - 'class', |
|
| 832 | - $this->checkout, |
|
| 833 | - false |
|
| 834 | - ); |
|
| 835 | - // did we gets the goods ? |
|
| 836 | - if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
| 837 | - // set reg step order based on config |
|
| 838 | - $reg_step_obj->set_order($order); |
|
| 839 | - // add instantiated reg step object to the master reg steps array |
|
| 840 | - $this->checkout->add_reg_step($reg_step_obj); |
|
| 841 | - } else { |
|
| 842 | - EE_Error::add_error( |
|
| 843 | - __('The current step could not be set.', 'event_espresso'), |
|
| 844 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 845 | - ); |
|
| 846 | - return false; |
|
| 847 | - } |
|
| 848 | - } else { |
|
| 849 | - if (WP_DEBUG) { |
|
| 850 | - EE_Error::add_error( |
|
| 851 | - sprintf( |
|
| 852 | - __( |
|
| 853 | - 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', |
|
| 854 | - 'event_espresso' |
|
| 855 | - ), |
|
| 856 | - isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
| 857 | - isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
| 858 | - isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
| 859 | - '<ul>', |
|
| 860 | - '<li>', |
|
| 861 | - '</li>', |
|
| 862 | - '</ul>' |
|
| 863 | - ), |
|
| 864 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 865 | - ); |
|
| 866 | - } |
|
| 867 | - return false; |
|
| 868 | - } |
|
| 869 | - return true; |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * _verify_transaction_and_get_registrations |
|
| 875 | - * |
|
| 876 | - * @access private |
|
| 877 | - * @return bool |
|
| 878 | - * @throws InvalidDataTypeException |
|
| 879 | - * @throws InvalidEntityException |
|
| 880 | - * @throws EE_Error |
|
| 881 | - */ |
|
| 882 | - private function _verify_transaction_and_get_registrations() |
|
| 883 | - { |
|
| 884 | - // was there already a valid transaction in the checkout from the session ? |
|
| 885 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 886 | - // get transaction from db or session |
|
| 887 | - $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
| 888 | - ? $this->_get_transaction_and_cart_for_previous_visit() |
|
| 889 | - : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
| 890 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 891 | - EE_Error::add_error( |
|
| 892 | - __('Your Registration and Transaction information could not be retrieved from the db.', |
|
| 893 | - 'event_espresso'), |
|
| 894 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 895 | - ); |
|
| 896 | - $this->checkout->transaction = EE_Transaction::new_instance(); |
|
| 897 | - // add some style and make it dance |
|
| 898 | - $this->add_styles_and_scripts(); |
|
| 899 | - EED_Single_Page_Checkout::$_initialized = true; |
|
| 900 | - return false; |
|
| 901 | - } |
|
| 902 | - // and the registrations for the transaction |
|
| 903 | - $this->_get_registrations($this->checkout->transaction); |
|
| 904 | - } |
|
| 905 | - return true; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * _get_transaction_and_cart_for_previous_visit |
|
| 912 | - * |
|
| 913 | - * @access private |
|
| 914 | - * @return mixed EE_Transaction|NULL |
|
| 915 | - */ |
|
| 916 | - private function _get_transaction_and_cart_for_previous_visit() |
|
| 917 | - { |
|
| 918 | - /** @var $TXN_model EEM_Transaction */ |
|
| 919 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
| 920 | - // because the reg_url_link is present in the request, |
|
| 921 | - // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
| 922 | - $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
| 923 | - // verify transaction |
|
| 924 | - if ($transaction instanceof EE_Transaction) { |
|
| 925 | - // and get the cart that was used for that transaction |
|
| 926 | - $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
| 927 | - return $transaction; |
|
| 928 | - } |
|
| 929 | - EE_Error::add_error( |
|
| 930 | - __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
| 931 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 932 | - ); |
|
| 933 | - return null; |
|
| 934 | - |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - |
|
| 938 | - |
|
| 939 | - /** |
|
| 940 | - * _get_cart_for_transaction |
|
| 941 | - * |
|
| 942 | - * @access private |
|
| 943 | - * @param EE_Transaction $transaction |
|
| 944 | - * @return EE_Cart |
|
| 945 | - */ |
|
| 946 | - private function _get_cart_for_transaction($transaction) |
|
| 947 | - { |
|
| 948 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * get_cart_for_transaction |
|
| 955 | - * |
|
| 956 | - * @access public |
|
| 957 | - * @param EE_Transaction $transaction |
|
| 958 | - * @return EE_Cart |
|
| 959 | - */ |
|
| 960 | - public function get_cart_for_transaction(EE_Transaction $transaction) |
|
| 961 | - { |
|
| 962 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - |
|
| 966 | - |
|
| 967 | - /** |
|
| 968 | - * _get_transaction_and_cart_for_current_session |
|
| 969 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 970 | - * |
|
| 971 | - * @access private |
|
| 972 | - * @return EE_Transaction |
|
| 973 | - * @throws EE_Error |
|
| 974 | - */ |
|
| 975 | - private function _get_cart_for_current_session_and_setup_new_transaction() |
|
| 976 | - { |
|
| 977 | - // if there's no transaction, then this is the FIRST visit to SPCO |
|
| 978 | - // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
| 979 | - $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
| 980 | - // and then create a new transaction |
|
| 981 | - $transaction = $this->_initialize_transaction(); |
|
| 982 | - // verify transaction |
|
| 983 | - if ($transaction instanceof EE_Transaction) { |
|
| 984 | - // save it so that we have an ID for other objects to use |
|
| 985 | - $transaction->save(); |
|
| 986 | - // and save TXN data to the cart |
|
| 987 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 988 | - } else { |
|
| 989 | - EE_Error::add_error( |
|
| 990 | - __('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
| 991 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 992 | - ); |
|
| 993 | - } |
|
| 994 | - return $transaction; |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - |
|
| 998 | - |
|
| 999 | - /** |
|
| 1000 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 1001 | - * |
|
| 1002 | - * @access private |
|
| 1003 | - * @return mixed EE_Transaction|NULL |
|
| 1004 | - */ |
|
| 1005 | - private function _initialize_transaction() |
|
| 1006 | - { |
|
| 1007 | - try { |
|
| 1008 | - // ensure cart totals have been calculated |
|
| 1009 | - $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
| 1010 | - // grab the cart grand total |
|
| 1011 | - $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
| 1012 | - // create new TXN |
|
| 1013 | - $transaction = EE_Transaction::new_instance( |
|
| 1014 | - array( |
|
| 1015 | - 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
| 1016 | - 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
| 1017 | - 'TXN_paid' => 0, |
|
| 1018 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
| 1019 | - ) |
|
| 1020 | - ); |
|
| 1021 | - // save it so that we have an ID for other objects to use |
|
| 1022 | - $transaction->save(); |
|
| 1023 | - // set cron job for following up on TXNs after their session has expired |
|
| 1024 | - EE_Cron_Tasks::schedule_expired_transaction_check( |
|
| 1025 | - EE_Registry::instance()->SSN->expiration() + 1, |
|
| 1026 | - $transaction->ID() |
|
| 1027 | - ); |
|
| 1028 | - return $transaction; |
|
| 1029 | - } catch (Exception $e) { |
|
| 1030 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1031 | - } |
|
| 1032 | - return null; |
|
| 1033 | - } |
|
| 1034 | - |
|
| 1035 | - |
|
| 1036 | - /** |
|
| 1037 | - * _get_registrations |
|
| 1038 | - * |
|
| 1039 | - * @access private |
|
| 1040 | - * @param EE_Transaction $transaction |
|
| 1041 | - * @return void |
|
| 1042 | - * @throws InvalidDataTypeException |
|
| 1043 | - * @throws InvalidEntityException |
|
| 1044 | - * @throws EE_Error |
|
| 1045 | - */ |
|
| 1046 | - private function _get_registrations(EE_Transaction $transaction) |
|
| 1047 | - { |
|
| 1048 | - // first step: grab the registrants { : o |
|
| 1049 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 1050 | - $this->checkout->total_ticket_count = count($registrations); |
|
| 1051 | - // verify registrations have been set |
|
| 1052 | - if (empty($registrations)) { |
|
| 1053 | - // if no cached registrations, then check the db |
|
| 1054 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 1055 | - // still nothing ? well as long as this isn't a revisit |
|
| 1056 | - if (empty($registrations) && ! $this->checkout->revisit) { |
|
| 1057 | - // generate new registrations from scratch |
|
| 1058 | - $registrations = $this->_initialize_registrations($transaction); |
|
| 1059 | - } |
|
| 1060 | - } |
|
| 1061 | - // sort by their original registration order |
|
| 1062 | - usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
| 1063 | - // then loop thru the array |
|
| 1064 | - foreach ($registrations as $registration) { |
|
| 1065 | - // verify each registration |
|
| 1066 | - if ($registration instanceof EE_Registration) { |
|
| 1067 | - // we display all attendee info for the primary registrant |
|
| 1068 | - if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
| 1069 | - && $registration->is_primary_registrant() |
|
| 1070 | - ) { |
|
| 1071 | - $this->checkout->primary_revisit = true; |
|
| 1072 | - break; |
|
| 1073 | - } |
|
| 1074 | - if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) { |
|
| 1075 | - // but hide info if it doesn't belong to you |
|
| 1076 | - $transaction->clear_cache('Registration', $registration->ID()); |
|
| 1077 | - $this->checkout->total_ticket_count--; |
|
| 1078 | - } |
|
| 1079 | - $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
| 1087 | - * |
|
| 1088 | - * @access private |
|
| 1089 | - * @param EE_Transaction $transaction |
|
| 1090 | - * @return array |
|
| 1091 | - * @throws InvalidDataTypeException |
|
| 1092 | - * @throws InvalidEntityException |
|
| 1093 | - * @throws EE_Error |
|
| 1094 | - */ |
|
| 1095 | - private function _initialize_registrations(EE_Transaction $transaction) |
|
| 1096 | - { |
|
| 1097 | - $att_nmbr = 0; |
|
| 1098 | - $registrations = array(); |
|
| 1099 | - if ($transaction instanceof EE_Transaction) { |
|
| 1100 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 1101 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 1102 | - $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
| 1103 | - // now let's add the cart items to the $transaction |
|
| 1104 | - foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
| 1105 | - //do the following for each ticket of this type they selected |
|
| 1106 | - for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
| 1107 | - $att_nmbr++; |
|
| 1108 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
| 1109 | - $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
| 1110 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 1111 | - array( |
|
| 1112 | - $transaction, |
|
| 1113 | - $line_item, |
|
| 1114 | - $att_nmbr, |
|
| 1115 | - $this->checkout->total_ticket_count, |
|
| 1116 | - ) |
|
| 1117 | - ); |
|
| 1118 | - // override capabilities for frontend registrations |
|
| 1119 | - if ( ! is_admin()) { |
|
| 1120 | - $CreateRegistrationCommand->setCapCheck( |
|
| 1121 | - new PublicCapabilities('', 'create_new_registration') |
|
| 1122 | - ); |
|
| 1123 | - } |
|
| 1124 | - $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
| 1125 | - if ( ! $registration instanceof EE_Registration) { |
|
| 1126 | - throw new InvalidEntityException($registration, 'EE_Registration'); |
|
| 1127 | - } |
|
| 1128 | - $registrations[ $registration->ID() ] = $registration; |
|
| 1129 | - } |
|
| 1130 | - } |
|
| 1131 | - $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
| 1132 | - } |
|
| 1133 | - return $registrations; |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - |
|
| 1137 | - |
|
| 1138 | - /** |
|
| 1139 | - * sorts registrations by REG_count |
|
| 1140 | - * |
|
| 1141 | - * @access public |
|
| 1142 | - * @param EE_Registration $reg_A |
|
| 1143 | - * @param EE_Registration $reg_B |
|
| 1144 | - * @return int |
|
| 1145 | - */ |
|
| 1146 | - public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
| 1147 | - { |
|
| 1148 | - // this shouldn't ever happen within the same TXN, but oh well |
|
| 1149 | - if ($reg_A->count() === $reg_B->count()) { |
|
| 1150 | - return 0; |
|
| 1151 | - } |
|
| 1152 | - return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - |
|
| 1156 | - |
|
| 1157 | - /** |
|
| 1158 | - * _final_verifications |
|
| 1159 | - * just makes sure that everything is set up correctly before proceeding |
|
| 1160 | - * |
|
| 1161 | - * @access private |
|
| 1162 | - * @return bool |
|
| 1163 | - * @throws EE_Error |
|
| 1164 | - */ |
|
| 1165 | - private function _final_verifications() |
|
| 1166 | - { |
|
| 1167 | - // filter checkout |
|
| 1168 | - $this->checkout = apply_filters( |
|
| 1169 | - 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
| 1170 | - $this->checkout |
|
| 1171 | - ); |
|
| 1172 | - //verify that current step is still set correctly |
|
| 1173 | - if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
| 1174 | - EE_Error::add_error( |
|
| 1175 | - __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1176 | - __FILE__, |
|
| 1177 | - __FUNCTION__, |
|
| 1178 | - __LINE__ |
|
| 1179 | - ); |
|
| 1180 | - return false; |
|
| 1181 | - } |
|
| 1182 | - // if returning to SPCO, then verify that primary registrant is set |
|
| 1183 | - if ( ! empty($this->checkout->reg_url_link)) { |
|
| 1184 | - $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
| 1185 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1186 | - EE_Error::add_error( |
|
| 1187 | - __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1188 | - __FILE__, |
|
| 1189 | - __FUNCTION__, |
|
| 1190 | - __LINE__ |
|
| 1191 | - ); |
|
| 1192 | - return false; |
|
| 1193 | - } |
|
| 1194 | - $valid_registrant = null; |
|
| 1195 | - foreach ( |
|
| 1196 | - $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration |
|
| 1197 | - ) { |
|
| 1198 | - if ( |
|
| 1199 | - $registration instanceof EE_Registration |
|
| 1200 | - && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
| 1201 | - ) { |
|
| 1202 | - $valid_registrant = $registration; |
|
| 1203 | - } |
|
| 1204 | - } |
|
| 1205 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1206 | - // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
| 1207 | - if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
| 1208 | - // clear the session, mark the checkout as unverified, and try again |
|
| 1209 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 1210 | - EED_Single_Page_Checkout::$_initialized = false; |
|
| 1211 | - EED_Single_Page_Checkout::$_checkout_verified = false; |
|
| 1212 | - $this->_initialize(); |
|
| 1213 | - EE_Error::reset_notices(); |
|
| 1214 | - return false; |
|
| 1215 | - } |
|
| 1216 | - EE_Error::add_error( |
|
| 1217 | - __( |
|
| 1218 | - 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', |
|
| 1219 | - 'event_espresso' |
|
| 1220 | - ), |
|
| 1221 | - __FILE__, |
|
| 1222 | - __FUNCTION__, |
|
| 1223 | - __LINE__ |
|
| 1224 | - ); |
|
| 1225 | - return false; |
|
| 1226 | - } |
|
| 1227 | - } |
|
| 1228 | - // now that things have been kinda sufficiently verified, |
|
| 1229 | - // let's add the checkout to the session so that it's available to other systems |
|
| 1230 | - EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
| 1231 | - return true; |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - |
|
| 1235 | - |
|
| 1236 | - /** |
|
| 1237 | - * _initialize_reg_steps |
|
| 1238 | - * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
| 1239 | - * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
| 1240 | - * |
|
| 1241 | - * @access private |
|
| 1242 | - * @param bool $reinitializing |
|
| 1243 | - * @throws EE_Error |
|
| 1244 | - */ |
|
| 1245 | - private function _initialize_reg_steps($reinitializing = false) |
|
| 1246 | - { |
|
| 1247 | - $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
| 1248 | - // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
| 1249 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 1250 | - if ( ! $reg_step->initialize_reg_step()) { |
|
| 1251 | - // if not initialized then maybe this step is being removed... |
|
| 1252 | - if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
| 1253 | - // if it was the current step, then we need to start over here |
|
| 1254 | - $this->_initialize_reg_steps(true); |
|
| 1255 | - return; |
|
| 1256 | - } |
|
| 1257 | - continue; |
|
| 1258 | - } |
|
| 1259 | - // add css and JS for current step |
|
| 1260 | - $reg_step->enqueue_styles_and_scripts(); |
|
| 1261 | - // i18n |
|
| 1262 | - $reg_step->translate_js_strings(); |
|
| 1263 | - if ($reg_step->is_current_step()) { |
|
| 1264 | - // the text that appears on the reg step form submit button |
|
| 1265 | - $reg_step->set_submit_button_text(); |
|
| 1266 | - } |
|
| 1267 | - } |
|
| 1268 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
| 1269 | - do_action( |
|
| 1270 | - "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
| 1271 | - $this->checkout->current_step |
|
| 1272 | - ); |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - |
|
| 1276 | - |
|
| 1277 | - /** |
|
| 1278 | - * _check_form_submission |
|
| 1279 | - * |
|
| 1280 | - * @access private |
|
| 1281 | - * @return boolean |
|
| 1282 | - */ |
|
| 1283 | - private function _check_form_submission() |
|
| 1284 | - { |
|
| 1285 | - //does this request require the reg form to be generated ? |
|
| 1286 | - if ($this->checkout->generate_reg_form) { |
|
| 1287 | - // ever heard that song by Blue Rodeo ? |
|
| 1288 | - try { |
|
| 1289 | - $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
| 1290 | - // if not displaying a form, then check for form submission |
|
| 1291 | - if ( |
|
| 1292 | - $this->checkout->process_form_submission |
|
| 1293 | - && $this->checkout->current_step->reg_form->was_submitted() |
|
| 1294 | - ) { |
|
| 1295 | - // clear out any old data in case this step is being run again |
|
| 1296 | - $this->checkout->current_step->set_valid_data(array()); |
|
| 1297 | - // capture submitted form data |
|
| 1298 | - $this->checkout->current_step->reg_form->receive_form_submission( |
|
| 1299 | - apply_filters( |
|
| 1300 | - 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
| 1301 | - EE_Registry::instance()->REQ->params(), |
|
| 1302 | - $this->checkout |
|
| 1303 | - ) |
|
| 1304 | - ); |
|
| 1305 | - // validate submitted form data |
|
| 1306 | - if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
| 1307 | - // thou shall not pass !!! |
|
| 1308 | - $this->checkout->continue_reg = false; |
|
| 1309 | - // any form validation errors? |
|
| 1310 | - if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
| 1311 | - $submission_error_messages = array(); |
|
| 1312 | - // bad, bad, bad registrant |
|
| 1313 | - foreach ( |
|
| 1314 | - $this->checkout->current_step->reg_form->get_validation_errors_accumulated() |
|
| 1315 | - as $validation_error |
|
| 1316 | - ) { |
|
| 1317 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1318 | - $submission_error_messages[] = sprintf( |
|
| 1319 | - __('%s : %s', 'event_espresso'), |
|
| 1320 | - $validation_error->get_form_section()->html_label_text(), |
|
| 1321 | - $validation_error->getMessage() |
|
| 1322 | - ); |
|
| 1323 | - } |
|
| 1324 | - } |
|
| 1325 | - EE_Error::add_error( |
|
| 1326 | - implode('<br />', $submission_error_messages), |
|
| 1327 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1328 | - ); |
|
| 1329 | - } |
|
| 1330 | - // well not really... what will happen is |
|
| 1331 | - // we'll just get redirected back to redo the current step |
|
| 1332 | - $this->go_to_next_step(); |
|
| 1333 | - return false; |
|
| 1334 | - } |
|
| 1335 | - } |
|
| 1336 | - } catch (EE_Error $e) { |
|
| 1337 | - $e->get_error(); |
|
| 1338 | - } |
|
| 1339 | - } |
|
| 1340 | - return true; |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - |
|
| 1344 | - |
|
| 1345 | - /** |
|
| 1346 | - * _process_action |
|
| 1347 | - * |
|
| 1348 | - * @access private |
|
| 1349 | - * @return void |
|
| 1350 | - * @throws EE_Error |
|
| 1351 | - */ |
|
| 1352 | - private function _process_form_action() |
|
| 1353 | - { |
|
| 1354 | - // what cha wanna do? |
|
| 1355 | - switch ($this->checkout->action) { |
|
| 1356 | - // AJAX next step reg form |
|
| 1357 | - case 'display_spco_reg_step' : |
|
| 1358 | - $this->checkout->redirect = false; |
|
| 1359 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 1360 | - $this->checkout->json_response->set_reg_step_html( |
|
| 1361 | - $this->checkout->current_step->display_reg_form() |
|
| 1362 | - ); |
|
| 1363 | - } |
|
| 1364 | - break; |
|
| 1365 | - default : |
|
| 1366 | - // meh... do one of those other steps first |
|
| 1367 | - if ( |
|
| 1368 | - ! empty($this->checkout->action) |
|
| 1369 | - && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
| 1370 | - ) { |
|
| 1371 | - // dynamically creates hook point like: |
|
| 1372 | - // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
| 1373 | - do_action( |
|
| 1374 | - "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
| 1375 | - $this->checkout->current_step |
|
| 1376 | - ); |
|
| 1377 | - // call action on current step |
|
| 1378 | - if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
| 1379 | - // good registrant, you get to proceed |
|
| 1380 | - if ( |
|
| 1381 | - $this->checkout->current_step->success_message() !== '' |
|
| 1382 | - && apply_filters( |
|
| 1383 | - 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
| 1384 | - false |
|
| 1385 | - ) |
|
| 1386 | - ) { |
|
| 1387 | - EE_Error::add_success( |
|
| 1388 | - $this->checkout->current_step->success_message() |
|
| 1389 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
| 1390 | - ); |
|
| 1391 | - } |
|
| 1392 | - // pack it up, pack it in... |
|
| 1393 | - $this->_setup_redirect(); |
|
| 1394 | - } |
|
| 1395 | - // dynamically creates hook point like: |
|
| 1396 | - // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
| 1397 | - do_action( |
|
| 1398 | - "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
| 1399 | - $this->checkout->current_step |
|
| 1400 | - ); |
|
| 1401 | - } else { |
|
| 1402 | - EE_Error::add_error( |
|
| 1403 | - sprintf( |
|
| 1404 | - __( |
|
| 1405 | - 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
| 1406 | - 'event_espresso' |
|
| 1407 | - ), |
|
| 1408 | - $this->checkout->action, |
|
| 1409 | - $this->checkout->current_step->name() |
|
| 1410 | - ), |
|
| 1411 | - __FILE__, |
|
| 1412 | - __FUNCTION__, |
|
| 1413 | - __LINE__ |
|
| 1414 | - ); |
|
| 1415 | - } |
|
| 1416 | - // end default |
|
| 1417 | - } |
|
| 1418 | - // store our progress so far |
|
| 1419 | - $this->checkout->stash_transaction_and_checkout(); |
|
| 1420 | - // advance to the next step! If you pass GO, collect $200 |
|
| 1421 | - $this->go_to_next_step(); |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - |
|
| 1425 | - |
|
| 1426 | - /** |
|
| 1427 | - * add_styles_and_scripts |
|
| 1428 | - * |
|
| 1429 | - * @access public |
|
| 1430 | - * @return void |
|
| 1431 | - */ |
|
| 1432 | - public function add_styles_and_scripts() |
|
| 1433 | - { |
|
| 1434 | - // i18n |
|
| 1435 | - $this->translate_js_strings(); |
|
| 1436 | - if ($this->checkout->admin_request) { |
|
| 1437 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1438 | - } else { |
|
| 1439 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - |
|
| 1443 | - |
|
| 1444 | - |
|
| 1445 | - /** |
|
| 1446 | - * translate_js_strings |
|
| 1447 | - * |
|
| 1448 | - * @access public |
|
| 1449 | - * @return void |
|
| 1450 | - */ |
|
| 1451 | - public function translate_js_strings() |
|
| 1452 | - { |
|
| 1453 | - EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
| 1454 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
| 1455 | - EE_Registry::$i18n_js_strings['server_error'] = __( |
|
| 1456 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 1457 | - 'event_espresso' |
|
| 1458 | - ); |
|
| 1459 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __( |
|
| 1460 | - 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 1461 | - 'event_espresso' |
|
| 1462 | - ); |
|
| 1463 | - EE_Registry::$i18n_js_strings['validation_error'] = __( |
|
| 1464 | - 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
| 1465 | - 'event_espresso' |
|
| 1466 | - ); |
|
| 1467 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( |
|
| 1468 | - 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
| 1469 | - 'event_espresso' |
|
| 1470 | - ); |
|
| 1471 | - EE_Registry::$i18n_js_strings['reg_step_error'] = __( |
|
| 1472 | - 'This registration step could not be completed. Please refresh the page and try again.', |
|
| 1473 | - 'event_espresso' |
|
| 1474 | - ); |
|
| 1475 | - EE_Registry::$i18n_js_strings['invalid_coupon'] = __( |
|
| 1476 | - 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
| 1477 | - 'event_espresso' |
|
| 1478 | - ); |
|
| 1479 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
| 1480 | - __( |
|
| 1481 | - 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
| 1482 | - 'event_espresso' |
|
| 1483 | - ), |
|
| 1484 | - '<br/>', |
|
| 1485 | - '<br/>' |
|
| 1486 | - ); |
|
| 1487 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
| 1488 | - EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
| 1489 | - EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
| 1490 | - EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
| 1491 | - EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
| 1492 | - EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
| 1493 | - EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
| 1494 | - EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
| 1495 | - EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
| 1496 | - EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
| 1497 | - EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
| 1498 | - EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
| 1499 | - EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
| 1500 | - EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
| 1501 | - EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
| 1502 | - EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
| 1503 | - EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
| 1504 | - EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
| 1505 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
| 1506 | - __( |
|
| 1507 | - '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
| 1508 | - 'event_espresso' |
|
| 1509 | - ), |
|
| 1510 | - '<h4 class="important-notice">', |
|
| 1511 | - '</h4>', |
|
| 1512 | - '<br />', |
|
| 1513 | - '<p>', |
|
| 1514 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1515 | - '">', |
|
| 1516 | - '</a>', |
|
| 1517 | - '</p>' |
|
| 1518 | - ); |
|
| 1519 | - EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
| 1520 | - 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
| 1521 | - true |
|
| 1522 | - ); |
|
| 1523 | - EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
| 1524 | - apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
| 1525 | - ); |
|
| 1526 | - EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
| 1527 | - 'M d, Y H:i:s', |
|
| 1528 | - EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1529 | - ); |
|
| 1530 | - } |
|
| 1531 | - |
|
| 1532 | - |
|
| 1533 | - |
|
| 1534 | - /** |
|
| 1535 | - * enqueue_styles_and_scripts |
|
| 1536 | - * |
|
| 1537 | - * @access public |
|
| 1538 | - * @return void |
|
| 1539 | - * @throws EE_Error |
|
| 1540 | - */ |
|
| 1541 | - public function enqueue_styles_and_scripts() |
|
| 1542 | - { |
|
| 1543 | - // load css |
|
| 1544 | - wp_register_style( |
|
| 1545 | - 'single_page_checkout', |
|
| 1546 | - SPCO_CSS_URL . 'single_page_checkout.css', |
|
| 1547 | - array('espresso_default'), |
|
| 1548 | - EVENT_ESPRESSO_VERSION |
|
| 1549 | - ); |
|
| 1550 | - wp_enqueue_style('single_page_checkout'); |
|
| 1551 | - // load JS |
|
| 1552 | - wp_register_script( |
|
| 1553 | - 'jquery_plugin', |
|
| 1554 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
| 1555 | - array('jquery'), |
|
| 1556 | - '1.0.1', |
|
| 1557 | - true |
|
| 1558 | - ); |
|
| 1559 | - wp_register_script( |
|
| 1560 | - 'jquery_countdown', |
|
| 1561 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
| 1562 | - array('jquery_plugin'), |
|
| 1563 | - '2.0.2', |
|
| 1564 | - true |
|
| 1565 | - ); |
|
| 1566 | - wp_register_script( |
|
| 1567 | - 'single_page_checkout', |
|
| 1568 | - SPCO_JS_URL . 'single_page_checkout.js', |
|
| 1569 | - array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
|
| 1570 | - EVENT_ESPRESSO_VERSION, |
|
| 1571 | - true |
|
| 1572 | - ); |
|
| 1573 | - if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
| 1574 | - $this->checkout->registration_form->enqueue_js(); |
|
| 1575 | - } |
|
| 1576 | - if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
| 1577 | - $this->checkout->current_step->reg_form->enqueue_js(); |
|
| 1578 | - } |
|
| 1579 | - wp_enqueue_script('single_page_checkout'); |
|
| 1580 | - /** |
|
| 1581 | - * global action hook for enqueueing styles and scripts with |
|
| 1582 | - * spco calls. |
|
| 1583 | - */ |
|
| 1584 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
| 1585 | - /** |
|
| 1586 | - * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
| 1587 | - * The hook will end up being something like: |
|
| 1588 | - * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
| 1589 | - */ |
|
| 1590 | - do_action( |
|
| 1591 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
| 1592 | - $this |
|
| 1593 | - ); |
|
| 1594 | - } |
|
| 1595 | - |
|
| 1596 | - |
|
| 1597 | - |
|
| 1598 | - /** |
|
| 1599 | - * display the Registration Single Page Checkout Form |
|
| 1600 | - * |
|
| 1601 | - * @access private |
|
| 1602 | - * @return void |
|
| 1603 | - * @throws EE_Error |
|
| 1604 | - */ |
|
| 1605 | - private function _display_spco_reg_form() |
|
| 1606 | - { |
|
| 1607 | - // if registering via the admin, just display the reg form for the current step |
|
| 1608 | - if ($this->checkout->admin_request) { |
|
| 1609 | - EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
| 1610 | - } else { |
|
| 1611 | - // add powered by EE msg |
|
| 1612 | - add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
| 1613 | - $empty_cart = count( |
|
| 1614 | - $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) |
|
| 1615 | - ) < 1; |
|
| 1616 | - EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
| 1617 | - $cookies_not_set_msg = ''; |
|
| 1618 | - if ($empty_cart) { |
|
| 1619 | - $cookies_not_set_msg = apply_filters( |
|
| 1620 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
| 1621 | - sprintf( |
|
| 1622 | - __( |
|
| 1623 | - '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
| 1624 | - 'event_espresso' |
|
| 1625 | - ), |
|
| 1626 | - '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">', |
|
| 1627 | - '</div>', |
|
| 1628 | - '<h6 class="important-notice">', |
|
| 1629 | - '</h6>', |
|
| 1630 | - '<p>', |
|
| 1631 | - '</p>', |
|
| 1632 | - '<br />', |
|
| 1633 | - '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
| 1634 | - '</a>' |
|
| 1635 | - ) |
|
| 1636 | - ); |
|
| 1637 | - } |
|
| 1638 | - $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
| 1639 | - array( |
|
| 1640 | - 'name' => 'single-page-checkout', |
|
| 1641 | - 'html_id' => 'ee-single-page-checkout-dv', |
|
| 1642 | - 'layout_strategy' => |
|
| 1643 | - new EE_Template_Layout( |
|
| 1644 | - array( |
|
| 1645 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
| 1646 | - 'template_args' => array( |
|
| 1647 | - 'empty_cart' => $empty_cart, |
|
| 1648 | - 'revisit' => $this->checkout->revisit, |
|
| 1649 | - 'reg_steps' => $this->checkout->reg_steps, |
|
| 1650 | - 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
| 1651 | - ? $this->checkout->next_step->slug() |
|
| 1652 | - : '', |
|
| 1653 | - 'empty_msg' => apply_filters( |
|
| 1654 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
| 1655 | - sprintf( |
|
| 1656 | - __( |
|
| 1657 | - 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
| 1658 | - 'event_espresso' |
|
| 1659 | - ), |
|
| 1660 | - '<a href="' |
|
| 1661 | - . get_post_type_archive_link('espresso_events') |
|
| 1662 | - . '" title="', |
|
| 1663 | - '">', |
|
| 1664 | - '</a>' |
|
| 1665 | - ) |
|
| 1666 | - ), |
|
| 1667 | - 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
| 1668 | - 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
| 1669 | - 'session_expiration' => gmdate( |
|
| 1670 | - 'M d, Y H:i:s', |
|
| 1671 | - EE_Registry::instance()->SSN->expiration() |
|
| 1672 | - + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1673 | - ), |
|
| 1674 | - ), |
|
| 1675 | - ) |
|
| 1676 | - ), |
|
| 1677 | - ) |
|
| 1678 | - ); |
|
| 1679 | - // load template and add to output sent that gets filtered into the_content() |
|
| 1680 | - EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
| 1681 | - } |
|
| 1682 | - } |
|
| 1683 | - |
|
| 1684 | - |
|
| 1685 | - |
|
| 1686 | - /** |
|
| 1687 | - * add_extra_finalize_registration_inputs |
|
| 1688 | - * |
|
| 1689 | - * @access public |
|
| 1690 | - * @param $next_step |
|
| 1691 | - * @internal param string $label |
|
| 1692 | - * @return void |
|
| 1693 | - */ |
|
| 1694 | - public function add_extra_finalize_registration_inputs($next_step) |
|
| 1695 | - { |
|
| 1696 | - if ($next_step === 'finalize_registration') { |
|
| 1697 | - echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
| 1698 | - } |
|
| 1699 | - } |
|
| 1700 | - |
|
| 1701 | - |
|
| 1702 | - |
|
| 1703 | - /** |
|
| 1704 | - * display_registration_footer |
|
| 1705 | - * |
|
| 1706 | - * @access public |
|
| 1707 | - * @return string |
|
| 1708 | - */ |
|
| 1709 | - public static function display_registration_footer() |
|
| 1710 | - { |
|
| 1711 | - if ( |
|
| 1712 | - apply_filters( |
|
| 1713 | - 'FHEE__EE_Front__Controller__show_reg_footer', |
|
| 1714 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 1715 | - ) |
|
| 1716 | - ) { |
|
| 1717 | - add_filter( |
|
| 1718 | - 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
| 1719 | - function ($url) { |
|
| 1720 | - return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
| 1721 | - } |
|
| 1722 | - ); |
|
| 1723 | - echo apply_filters( |
|
| 1724 | - 'FHEE__EE_Front_Controller__display_registration_footer', |
|
| 1725 | - \EEH_Template::powered_by_event_espresso( |
|
| 1726 | - '', |
|
| 1727 | - 'espresso-registration-footer-dv', |
|
| 1728 | - array('utm_content' => 'registration_checkout') |
|
| 1729 | - ) |
|
| 1730 | - ); |
|
| 1731 | - } |
|
| 1732 | - return ''; |
|
| 1733 | - } |
|
| 1734 | - |
|
| 1735 | - |
|
| 1736 | - |
|
| 1737 | - /** |
|
| 1738 | - * unlock_transaction |
|
| 1739 | - * |
|
| 1740 | - * @access public |
|
| 1741 | - * @return void |
|
| 1742 | - * @throws EE_Error |
|
| 1743 | - */ |
|
| 1744 | - public function unlock_transaction() |
|
| 1745 | - { |
|
| 1746 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 1747 | - $this->checkout->transaction->unlock(); |
|
| 1748 | - } |
|
| 1749 | - } |
|
| 1750 | - |
|
| 1751 | - |
|
| 1752 | - |
|
| 1753 | - /** |
|
| 1754 | - * _setup_redirect |
|
| 1755 | - * |
|
| 1756 | - * @access private |
|
| 1757 | - * @return void |
|
| 1758 | - */ |
|
| 1759 | - private function _setup_redirect() |
|
| 1760 | - { |
|
| 1761 | - if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
| 1762 | - $this->checkout->redirect = true; |
|
| 1763 | - if (empty($this->checkout->redirect_url)) { |
|
| 1764 | - $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
| 1765 | - } |
|
| 1766 | - $this->checkout->redirect_url = apply_filters( |
|
| 1767 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
| 1768 | - $this->checkout->redirect_url, |
|
| 1769 | - $this->checkout |
|
| 1770 | - ); |
|
| 1771 | - } |
|
| 1772 | - } |
|
| 1773 | - |
|
| 1774 | - |
|
| 1775 | - |
|
| 1776 | - /** |
|
| 1777 | - * handle ajax message responses and redirects |
|
| 1778 | - * |
|
| 1779 | - * @access public |
|
| 1780 | - * @return void |
|
| 1781 | - * @throws EE_Error |
|
| 1782 | - */ |
|
| 1783 | - public function go_to_next_step() |
|
| 1784 | - { |
|
| 1785 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 1786 | - // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
| 1787 | - $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
| 1788 | - } |
|
| 1789 | - $this->unlock_transaction(); |
|
| 1790 | - // just return for these conditions |
|
| 1791 | - if ( |
|
| 1792 | - $this->checkout->admin_request |
|
| 1793 | - || $this->checkout->action === 'redirect_form' |
|
| 1794 | - || $this->checkout->action === 'update_checkout' |
|
| 1795 | - ) { |
|
| 1796 | - return; |
|
| 1797 | - } |
|
| 1798 | - // AJAX response |
|
| 1799 | - $this->_handle_json_response(); |
|
| 1800 | - // redirect to next step or the Thank You page |
|
| 1801 | - $this->_handle_html_redirects(); |
|
| 1802 | - // hmmm... must be something wrong, so let's just display the form again ! |
|
| 1803 | - $this->_display_spco_reg_form(); |
|
| 1804 | - } |
|
| 1805 | - |
|
| 1806 | - |
|
| 1807 | - |
|
| 1808 | - /** |
|
| 1809 | - * _handle_json_response |
|
| 1810 | - * |
|
| 1811 | - * @access protected |
|
| 1812 | - * @return void |
|
| 1813 | - */ |
|
| 1814 | - protected function _handle_json_response() |
|
| 1815 | - { |
|
| 1816 | - // if this is an ajax request |
|
| 1817 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 1818 | - // DEBUG LOG |
|
| 1819 | - //$this->checkout->log( |
|
| 1820 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 1821 | - // array( |
|
| 1822 | - // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
| 1823 | - // 'redirect' => $this->checkout->redirect, |
|
| 1824 | - // 'continue_reg' => $this->checkout->continue_reg, |
|
| 1825 | - // ) |
|
| 1826 | - //); |
|
| 1827 | - $this->checkout->json_response->set_registration_time_limit( |
|
| 1828 | - $this->checkout->get_registration_time_limit() |
|
| 1829 | - ); |
|
| 1830 | - $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
| 1831 | - // just send the ajax ( |
|
| 1832 | - $json_response = apply_filters( |
|
| 1833 | - 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
| 1834 | - $this->checkout->json_response |
|
| 1835 | - ); |
|
| 1836 | - echo $json_response; |
|
| 1837 | - exit(); |
|
| 1838 | - } |
|
| 1839 | - } |
|
| 1840 | - |
|
| 1841 | - |
|
| 1842 | - |
|
| 1843 | - /** |
|
| 1844 | - * _handle_redirects |
|
| 1845 | - * |
|
| 1846 | - * @access protected |
|
| 1847 | - * @return void |
|
| 1848 | - */ |
|
| 1849 | - protected function _handle_html_redirects() |
|
| 1850 | - { |
|
| 1851 | - // going somewhere ? |
|
| 1852 | - if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
| 1853 | - // store notices in a transient |
|
| 1854 | - EE_Error::get_notices(false, true, true); |
|
| 1855 | - // DEBUG LOG |
|
| 1856 | - //$this->checkout->log( |
|
| 1857 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 1858 | - // array( |
|
| 1859 | - // 'headers_sent' => headers_sent(), |
|
| 1860 | - // 'redirect_url' => $this->checkout->redirect_url, |
|
| 1861 | - // 'headers_list' => headers_list(), |
|
| 1862 | - // ) |
|
| 1863 | - //); |
|
| 1864 | - wp_safe_redirect($this->checkout->redirect_url); |
|
| 1865 | - exit(); |
|
| 1866 | - } |
|
| 1867 | - } |
|
| 1868 | - |
|
| 1869 | - |
|
| 1870 | - |
|
| 1871 | - /** |
|
| 1872 | - * set_checkout_anchor |
|
| 1873 | - * |
|
| 1874 | - * @access public |
|
| 1875 | - * @return void |
|
| 1876 | - */ |
|
| 1877 | - public function set_checkout_anchor() |
|
| 1878 | - { |
|
| 1879 | - echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
| 1880 | - } |
|
| 23 | + /** |
|
| 24 | + * $_initialized - has the SPCO controller already been initialized ? |
|
| 25 | + * |
|
| 26 | + * @access private |
|
| 27 | + * @var bool $_initialized |
|
| 28 | + */ |
|
| 29 | + private static $_initialized = false; |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
| 34 | + * |
|
| 35 | + * @access private |
|
| 36 | + * @var bool $_valid_checkout |
|
| 37 | + */ |
|
| 38 | + private static $_checkout_verified = true; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * $_reg_steps_array - holds initial array of reg steps |
|
| 42 | + * |
|
| 43 | + * @access private |
|
| 44 | + * @var array $_reg_steps_array |
|
| 45 | + */ |
|
| 46 | + private static $_reg_steps_array = array(); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
| 50 | + * |
|
| 51 | + * @access public |
|
| 52 | + * @var EE_Checkout $checkout |
|
| 53 | + */ |
|
| 54 | + public $checkout; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @return EED_Module|EED_Single_Page_Checkout |
|
| 60 | + */ |
|
| 61 | + public static function instance() |
|
| 62 | + { |
|
| 63 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
| 64 | + return parent::get_instance(__CLASS__); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return EE_CART |
|
| 71 | + */ |
|
| 72 | + public function cart() |
|
| 73 | + { |
|
| 74 | + return $this->checkout->cart; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @return EE_Transaction |
|
| 81 | + */ |
|
| 82 | + public function transaction() |
|
| 83 | + { |
|
| 84 | + return $this->checkout->transaction; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 91 | + * |
|
| 92 | + * @access public |
|
| 93 | + * @return void |
|
| 94 | + * @throws EE_Error |
|
| 95 | + */ |
|
| 96 | + public static function set_hooks() |
|
| 97 | + { |
|
| 98 | + EED_Single_Page_Checkout::set_definitions(); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + * @return void |
|
| 108 | + * @throws EE_Error |
|
| 109 | + */ |
|
| 110 | + public static function set_hooks_admin() |
|
| 111 | + { |
|
| 112 | + EED_Single_Page_Checkout::set_definitions(); |
|
| 113 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | + // going to start an output buffer in case anything gets accidentally output |
|
| 117 | + // that might disrupt our JSON response |
|
| 118 | + ob_start(); |
|
| 119 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 120 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
| 121 | + // set ajax hooks |
|
| 122 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 123 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
| 124 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 125 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
| 126 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 127 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * process ajax request |
|
| 134 | + * |
|
| 135 | + * @param string $ajax_action |
|
| 136 | + * @throws EE_Error |
|
| 137 | + */ |
|
| 138 | + public static function process_ajax_request($ajax_action) |
|
| 139 | + { |
|
| 140 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
| 141 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * ajax display registration step |
|
| 148 | + * |
|
| 149 | + * @throws EE_Error |
|
| 150 | + */ |
|
| 151 | + public static function display_reg_step() |
|
| 152 | + { |
|
| 153 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * ajax process registration step |
|
| 160 | + * |
|
| 161 | + * @throws EE_Error |
|
| 162 | + */ |
|
| 163 | + public static function process_reg_step() |
|
| 164 | + { |
|
| 165 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * ajax process registration step |
|
| 172 | + * |
|
| 173 | + * @throws EE_Error |
|
| 174 | + */ |
|
| 175 | + public static function update_reg_step() |
|
| 176 | + { |
|
| 177 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * update_checkout |
|
| 184 | + * |
|
| 185 | + * @access public |
|
| 186 | + * @return void |
|
| 187 | + * @throws EE_Error |
|
| 188 | + */ |
|
| 189 | + public static function update_checkout() |
|
| 190 | + { |
|
| 191 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * load_request_handler |
|
| 198 | + * |
|
| 199 | + * @access public |
|
| 200 | + * @return void |
|
| 201 | + */ |
|
| 202 | + public static function load_request_handler() |
|
| 203 | + { |
|
| 204 | + // load core Request_Handler class |
|
| 205 | + if (EE_Registry::instance()->REQ !== null) { |
|
| 206 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * set_definitions |
|
| 214 | + * |
|
| 215 | + * @access public |
|
| 216 | + * @return void |
|
| 217 | + * @throws EE_Error |
|
| 218 | + */ |
|
| 219 | + public static function set_definitions() |
|
| 220 | + { |
|
| 221 | + if(defined('SPCO_BASE_PATH')) { |
|
| 222 | + return; |
|
| 223 | + } |
|
| 224 | + define( |
|
| 225 | + 'SPCO_BASE_PATH', |
|
| 226 | + rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
| 227 | + ); |
|
| 228 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
| 229 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
| 230 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
| 231 | + define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
| 232 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
| 233 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
| 234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
| 235 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
| 236 | + __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
| 237 | + 'event_espresso'), |
|
| 238 | + '<h4 class="important-notice">', |
|
| 239 | + '</h4>', |
|
| 240 | + '<br />', |
|
| 241 | + '<p>', |
|
| 242 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 243 | + '">', |
|
| 244 | + '</a>', |
|
| 245 | + '</p>' |
|
| 246 | + ); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * load_reg_steps |
|
| 253 | + * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
| 254 | + * |
|
| 255 | + * @access private |
|
| 256 | + * @throws EE_Error |
|
| 257 | + */ |
|
| 258 | + public static function load_reg_steps() |
|
| 259 | + { |
|
| 260 | + static $reg_steps_loaded = false; |
|
| 261 | + if ($reg_steps_loaded) { |
|
| 262 | + return; |
|
| 263 | + } |
|
| 264 | + // filter list of reg_steps |
|
| 265 | + $reg_steps_to_load = (array)apply_filters( |
|
| 266 | + 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
| 267 | + EED_Single_Page_Checkout::get_reg_steps() |
|
| 268 | + ); |
|
| 269 | + // sort by key (order) |
|
| 270 | + ksort($reg_steps_to_load); |
|
| 271 | + // loop through folders |
|
| 272 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
| 273 | + // we need a |
|
| 274 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 275 | + // copy over to the reg_steps_array |
|
| 276 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
| 277 | + // register custom key route for each reg step |
|
| 278 | + // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
| 279 | + EE_Config::register_route( |
|
| 280 | + $reg_step['slug'], |
|
| 281 | + 'EED_Single_Page_Checkout', |
|
| 282 | + 'run', |
|
| 283 | + 'step' |
|
| 284 | + ); |
|
| 285 | + // add AJAX or other hooks |
|
| 286 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
| 287 | + // setup autoloaders if necessary |
|
| 288 | + if ( ! class_exists($reg_step['class_name'])) { |
|
| 289 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
| 290 | + $reg_step['file_path'], |
|
| 291 | + true |
|
| 292 | + ); |
|
| 293 | + } |
|
| 294 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
| 295 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + $reg_steps_loaded = true; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * get_reg_steps |
|
| 307 | + * |
|
| 308 | + * @access public |
|
| 309 | + * @return array |
|
| 310 | + */ |
|
| 311 | + public static function get_reg_steps() |
|
| 312 | + { |
|
| 313 | + $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
| 314 | + if (empty($reg_steps)) { |
|
| 315 | + $reg_steps = array( |
|
| 316 | + 10 => array( |
|
| 317 | + 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
| 318 | + 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
| 319 | + 'slug' => 'attendee_information', |
|
| 320 | + 'has_hooks' => false, |
|
| 321 | + ), |
|
| 322 | + 20 => array( |
|
| 323 | + 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
| 324 | + 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
| 325 | + 'slug' => 'registration_confirmation', |
|
| 326 | + 'has_hooks' => false, |
|
| 327 | + ), |
|
| 328 | + 30 => array( |
|
| 329 | + 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
| 330 | + 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 331 | + 'slug' => 'payment_options', |
|
| 332 | + 'has_hooks' => true, |
|
| 333 | + ), |
|
| 334 | + 999 => array( |
|
| 335 | + 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
| 336 | + 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
| 337 | + 'slug' => 'finalize_registration', |
|
| 338 | + 'has_hooks' => false, |
|
| 339 | + ), |
|
| 340 | + ); |
|
| 341 | + } |
|
| 342 | + return $reg_steps; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * registration_checkout_for_admin |
|
| 349 | + * |
|
| 350 | + * @access public |
|
| 351 | + * @return string |
|
| 352 | + * @throws EE_Error |
|
| 353 | + */ |
|
| 354 | + public static function registration_checkout_for_admin() |
|
| 355 | + { |
|
| 356 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 357 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 358 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
| 359 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
| 360 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 361 | + EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
| 362 | + return EE_Registry::instance()->REQ->get_output(); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * process_registration_from_admin |
|
| 369 | + * |
|
| 370 | + * @access public |
|
| 371 | + * @return \EE_Transaction |
|
| 372 | + * @throws EE_Error |
|
| 373 | + */ |
|
| 374 | + public static function process_registration_from_admin() |
|
| 375 | + { |
|
| 376 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 377 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
| 378 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
| 379 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
| 380 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
| 381 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
| 382 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
| 383 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
| 384 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
| 385 | + if ($final_reg_step->process_reg_step()) { |
|
| 386 | + $final_reg_step->set_completed(); |
|
| 387 | + EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
| 388 | + return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + return null; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * run |
|
| 399 | + * |
|
| 400 | + * @access public |
|
| 401 | + * @param WP_Query $WP_Query |
|
| 402 | + * @return void |
|
| 403 | + * @throws EE_Error |
|
| 404 | + */ |
|
| 405 | + public function run($WP_Query) |
|
| 406 | + { |
|
| 407 | + if ( |
|
| 408 | + $WP_Query instanceof WP_Query |
|
| 409 | + && $WP_Query->is_main_query() |
|
| 410 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
| 411 | + && $this->_is_reg_checkout() |
|
| 412 | + ) { |
|
| 413 | + $this->_initialize(); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * determines whether current url matches reg page url |
|
| 421 | + * |
|
| 422 | + * @return bool |
|
| 423 | + */ |
|
| 424 | + protected function _is_reg_checkout() |
|
| 425 | + { |
|
| 426 | + // get current permalink for reg page without any extra query args |
|
| 427 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
| 428 | + // get request URI for current request, but without the scheme or host |
|
| 429 | + $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 430 | + $current_request_uri = html_entity_decode($current_request_uri); |
|
| 431 | + // get array of query args from the current request URI |
|
| 432 | + $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
| 433 | + // grab page id if it is set |
|
| 434 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
| 435 | + // and remove the page id from the query args (we will re-add it later) |
|
| 436 | + unset($query_args['page_id']); |
|
| 437 | + // now strip all query args from current request URI |
|
| 438 | + $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
| 439 | + // and re-add the page id if it was set |
|
| 440 | + if ($page_id) { |
|
| 441 | + $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
| 442 | + } |
|
| 443 | + // remove slashes and ? |
|
| 444 | + $current_request_uri = trim($current_request_uri, '?/'); |
|
| 445 | + // is current request URI part of the known full reg page URL ? |
|
| 446 | + return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @param WP_Query $wp_query |
|
| 453 | + * @return void |
|
| 454 | + * @throws EE_Error |
|
| 455 | + */ |
|
| 456 | + public static function init($wp_query) |
|
| 457 | + { |
|
| 458 | + EED_Single_Page_Checkout::instance()->run($wp_query); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * _initialize - initial module setup |
|
| 465 | + * |
|
| 466 | + * @access private |
|
| 467 | + * @throws EE_Error |
|
| 468 | + * @return void |
|
| 469 | + */ |
|
| 470 | + private function _initialize() |
|
| 471 | + { |
|
| 472 | + // ensure SPCO doesn't run twice |
|
| 473 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
| 474 | + return; |
|
| 475 | + } |
|
| 476 | + try { |
|
| 477 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
| 478 | + $this->_verify_session(); |
|
| 479 | + // setup the EE_Checkout object |
|
| 480 | + $this->checkout = $this->_initialize_checkout(); |
|
| 481 | + // filter checkout |
|
| 482 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
| 483 | + // get the $_GET |
|
| 484 | + $this->_get_request_vars(); |
|
| 485 | + if ($this->_block_bots()) { |
|
| 486 | + return; |
|
| 487 | + } |
|
| 488 | + // filter continue_reg |
|
| 489 | + $this->checkout->continue_reg = apply_filters( |
|
| 490 | + 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
| 491 | + true, |
|
| 492 | + $this->checkout |
|
| 493 | + ); |
|
| 494 | + // load the reg steps array |
|
| 495 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
| 496 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 497 | + return; |
|
| 498 | + } |
|
| 499 | + // set the current step |
|
| 500 | + $this->checkout->set_current_step($this->checkout->step); |
|
| 501 | + // and the next step |
|
| 502 | + $this->checkout->set_next_step(); |
|
| 503 | + // verify that everything has been setup correctly |
|
| 504 | + if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
| 505 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 506 | + return; |
|
| 507 | + } |
|
| 508 | + // lock the transaction |
|
| 509 | + $this->checkout->transaction->lock(); |
|
| 510 | + // make sure all of our cached objects are added to their respective model entity mappers |
|
| 511 | + $this->checkout->refresh_all_entities(); |
|
| 512 | + // set amount owing |
|
| 513 | + $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
| 514 | + // initialize each reg step, which gives them the chance to potentially alter the process |
|
| 515 | + $this->_initialize_reg_steps(); |
|
| 516 | + // DEBUG LOG |
|
| 517 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 518 | + // get reg form |
|
| 519 | + if( ! $this->_check_form_submission()) { |
|
| 520 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 521 | + return; |
|
| 522 | + } |
|
| 523 | + // checkout the action!!! |
|
| 524 | + $this->_process_form_action(); |
|
| 525 | + // add some style and make it dance |
|
| 526 | + $this->add_styles_and_scripts(); |
|
| 527 | + // kk... SPCO has successfully run |
|
| 528 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 529 | + // set no cache headers and constants |
|
| 530 | + EE_System::do_not_cache(); |
|
| 531 | + // add anchor |
|
| 532 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
| 533 | + // remove transaction lock |
|
| 534 | + add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
| 535 | + } catch (Exception $e) { |
|
| 536 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * _verify_session |
|
| 544 | + * checks that the session is valid and not expired |
|
| 545 | + * |
|
| 546 | + * @access private |
|
| 547 | + * @throws EE_Error |
|
| 548 | + */ |
|
| 549 | + private function _verify_session() |
|
| 550 | + { |
|
| 551 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 552 | + throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
| 553 | + } |
|
| 554 | + $clear_session_requested = filter_var( |
|
| 555 | + EE_Registry::instance()->REQ->get('clear_session', false), |
|
| 556 | + FILTER_VALIDATE_BOOLEAN |
|
| 557 | + ); |
|
| 558 | + // is session still valid ? |
|
| 559 | + if ($clear_session_requested |
|
| 560 | + || ( EE_Registry::instance()->SSN->expired() |
|
| 561 | + && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
| 562 | + ) |
|
| 563 | + ) { |
|
| 564 | + $this->checkout = new EE_Checkout(); |
|
| 565 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 566 | + // EE_Registry::instance()->SSN->reset_cart(); |
|
| 567 | + // EE_Registry::instance()->SSN->reset_checkout(); |
|
| 568 | + // EE_Registry::instance()->SSN->reset_transaction(); |
|
| 569 | + if (! $clear_session_requested) { |
|
| 570 | + EE_Error::add_attention( |
|
| 571 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
| 572 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 573 | + ); |
|
| 574 | + } |
|
| 575 | + // EE_Registry::instance()->SSN->reset_expired(); |
|
| 576 | + } |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * _initialize_checkout |
|
| 583 | + * loads and instantiates EE_Checkout |
|
| 584 | + * |
|
| 585 | + * @access private |
|
| 586 | + * @throws EE_Error |
|
| 587 | + * @return EE_Checkout |
|
| 588 | + */ |
|
| 589 | + private function _initialize_checkout() |
|
| 590 | + { |
|
| 591 | + // look in session for existing checkout |
|
| 592 | + /** @type EE_Checkout $checkout */ |
|
| 593 | + $checkout = EE_Registry::instance()->SSN->checkout(); |
|
| 594 | + // verify |
|
| 595 | + if ( ! $checkout instanceof EE_Checkout) { |
|
| 596 | + // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
| 597 | + $checkout = EE_Registry::instance()->load_file( |
|
| 598 | + SPCO_INC_PATH, |
|
| 599 | + 'EE_Checkout', |
|
| 600 | + 'class', array(), |
|
| 601 | + false |
|
| 602 | + ); |
|
| 603 | + } else { |
|
| 604 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
| 605 | + $this->unlock_transaction(); |
|
| 606 | + wp_safe_redirect($checkout->redirect_url); |
|
| 607 | + exit(); |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
| 611 | + // verify again |
|
| 612 | + if ( ! $checkout instanceof EE_Checkout) { |
|
| 613 | + throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
| 614 | + } |
|
| 615 | + // reset anything that needs a clean slate for each request |
|
| 616 | + $checkout->reset_for_current_request(); |
|
| 617 | + return $checkout; |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * _get_request_vars |
|
| 624 | + * |
|
| 625 | + * @access private |
|
| 626 | + * @return void |
|
| 627 | + * @throws EE_Error |
|
| 628 | + */ |
|
| 629 | + private function _get_request_vars() |
|
| 630 | + { |
|
| 631 | + // load classes |
|
| 632 | + EED_Single_Page_Checkout::load_request_handler(); |
|
| 633 | + //make sure this request is marked as belonging to EE |
|
| 634 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 635 | + // which step is being requested ? |
|
| 636 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
| 637 | + // which step is being edited ? |
|
| 638 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
| 639 | + // and what we're doing on the current step |
|
| 640 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
| 641 | + // timestamp |
|
| 642 | + $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
| 643 | + // returning to edit ? |
|
| 644 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
| 645 | + // add reg url link to registration query params |
|
| 646 | + if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) { |
|
| 647 | + $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link; |
|
| 648 | + } |
|
| 649 | + // or some other kind of revisit ? |
|
| 650 | + $this->checkout->revisit = filter_var( |
|
| 651 | + EE_Registry::instance()->REQ->get('revisit', false), |
|
| 652 | + FILTER_VALIDATE_BOOLEAN |
|
| 653 | + ); |
|
| 654 | + // and whether or not to generate a reg form for this request |
|
| 655 | + $this->checkout->generate_reg_form = filter_var( |
|
| 656 | + EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
| 657 | + FILTER_VALIDATE_BOOLEAN |
|
| 658 | + ); |
|
| 659 | + // and whether or not to process a reg form submission for this request |
|
| 660 | + $this->checkout->process_form_submission = filter_var( |
|
| 661 | + EE_Registry::instance()->REQ->get( |
|
| 662 | + 'process_form_submission', |
|
| 663 | + $this->checkout->action === 'process_reg_step' |
|
| 664 | + ), |
|
| 665 | + FILTER_VALIDATE_BOOLEAN |
|
| 666 | + ); |
|
| 667 | + $this->checkout->process_form_submission = filter_var( |
|
| 668 | + $this->checkout->action !== 'display_spco_reg_step' |
|
| 669 | + ? $this->checkout->process_form_submission |
|
| 670 | + : false, |
|
| 671 | + FILTER_VALIDATE_BOOLEAN |
|
| 672 | + ); |
|
| 673 | + // $this->_display_request_vars(); |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * _display_request_vars |
|
| 680 | + * |
|
| 681 | + * @access protected |
|
| 682 | + * @return void |
|
| 683 | + */ |
|
| 684 | + protected function _display_request_vars() |
|
| 685 | + { |
|
| 686 | + if ( ! WP_DEBUG) { |
|
| 687 | + return; |
|
| 688 | + } |
|
| 689 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
| 690 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
| 691 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
| 692 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
| 693 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
| 694 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
| 695 | + EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
| 696 | + EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * _block_bots |
|
| 703 | + * checks that the incoming request has either of the following set: |
|
| 704 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
| 705 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
| 706 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
| 707 | + * then where you coming from man? |
|
| 708 | + * |
|
| 709 | + * @return boolean |
|
| 710 | + */ |
|
| 711 | + private function _block_bots() |
|
| 712 | + { |
|
| 713 | + $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
| 714 | + if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
| 715 | + return true; |
|
| 716 | + } |
|
| 717 | + return false; |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * _get_first_step |
|
| 724 | + * gets slug for first step in $_reg_steps_array |
|
| 725 | + * |
|
| 726 | + * @access private |
|
| 727 | + * @throws EE_Error |
|
| 728 | + * @return string |
|
| 729 | + */ |
|
| 730 | + private function _get_first_step() |
|
| 731 | + { |
|
| 732 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
| 733 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + |
|
| 738 | + /** |
|
| 739 | + * _load_and_instantiate_reg_steps |
|
| 740 | + * instantiates each reg step based on the loaded reg_steps array |
|
| 741 | + * |
|
| 742 | + * @access private |
|
| 743 | + * @throws EE_Error |
|
| 744 | + * @return bool |
|
| 745 | + */ |
|
| 746 | + private function _load_and_instantiate_reg_steps() |
|
| 747 | + { |
|
| 748 | + do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
| 749 | + // have reg_steps already been instantiated ? |
|
| 750 | + if ( |
|
| 751 | + empty($this->checkout->reg_steps) |
|
| 752 | + || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
| 753 | + ) { |
|
| 754 | + // if not, then loop through raw reg steps array |
|
| 755 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
| 756 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
| 757 | + return false; |
|
| 758 | + } |
|
| 759 | + } |
|
| 760 | + EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
| 761 | + EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
| 762 | + // skip the registration_confirmation page ? |
|
| 763 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
| 764 | + // just remove it from the reg steps array |
|
| 765 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
| 766 | + } else if ( |
|
| 767 | + isset($this->checkout->reg_steps['registration_confirmation']) |
|
| 768 | + && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
| 769 | + ) { |
|
| 770 | + // set the order to something big like 100 |
|
| 771 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
| 772 | + } |
|
| 773 | + // filter the array for good luck |
|
| 774 | + $this->checkout->reg_steps = apply_filters( |
|
| 775 | + 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
| 776 | + $this->checkout->reg_steps |
|
| 777 | + ); |
|
| 778 | + // finally re-sort based on the reg step class order properties |
|
| 779 | + $this->checkout->sort_reg_steps(); |
|
| 780 | + } else { |
|
| 781 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 782 | + // set all current step stati to FALSE |
|
| 783 | + $reg_step->set_is_current_step(false); |
|
| 784 | + } |
|
| 785 | + } |
|
| 786 | + if (empty($this->checkout->reg_steps)) { |
|
| 787 | + EE_Error::add_error( |
|
| 788 | + __('No Reg Steps were loaded..', 'event_espresso'), |
|
| 789 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 790 | + ); |
|
| 791 | + return false; |
|
| 792 | + } |
|
| 793 | + // make reg step details available to JS |
|
| 794 | + $this->checkout->set_reg_step_JSON_info(); |
|
| 795 | + return true; |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + |
|
| 800 | + /** |
|
| 801 | + * _load_and_instantiate_reg_step |
|
| 802 | + * |
|
| 803 | + * @access private |
|
| 804 | + * @param array $reg_step |
|
| 805 | + * @param int $order |
|
| 806 | + * @return bool |
|
| 807 | + */ |
|
| 808 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
| 809 | + { |
|
| 810 | + // we need a file_path, class_name, and slug to add a reg step |
|
| 811 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
| 812 | + // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
| 813 | + if ( |
|
| 814 | + $this->checkout->reg_url_link |
|
| 815 | + && $this->checkout->step !== $reg_step['slug'] |
|
| 816 | + && $reg_step['slug'] !== 'finalize_registration' |
|
| 817 | + // normally at this point we would NOT load the reg step, but this filter can change that |
|
| 818 | + && apply_filters( |
|
| 819 | + 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
| 820 | + true, |
|
| 821 | + $reg_step, |
|
| 822 | + $this->checkout |
|
| 823 | + ) |
|
| 824 | + ) { |
|
| 825 | + return true; |
|
| 826 | + } |
|
| 827 | + // instantiate step class using file path and class name |
|
| 828 | + $reg_step_obj = EE_Registry::instance()->load_file( |
|
| 829 | + $reg_step['file_path'], |
|
| 830 | + $reg_step['class_name'], |
|
| 831 | + 'class', |
|
| 832 | + $this->checkout, |
|
| 833 | + false |
|
| 834 | + ); |
|
| 835 | + // did we gets the goods ? |
|
| 836 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
| 837 | + // set reg step order based on config |
|
| 838 | + $reg_step_obj->set_order($order); |
|
| 839 | + // add instantiated reg step object to the master reg steps array |
|
| 840 | + $this->checkout->add_reg_step($reg_step_obj); |
|
| 841 | + } else { |
|
| 842 | + EE_Error::add_error( |
|
| 843 | + __('The current step could not be set.', 'event_espresso'), |
|
| 844 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 845 | + ); |
|
| 846 | + return false; |
|
| 847 | + } |
|
| 848 | + } else { |
|
| 849 | + if (WP_DEBUG) { |
|
| 850 | + EE_Error::add_error( |
|
| 851 | + sprintf( |
|
| 852 | + __( |
|
| 853 | + 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', |
|
| 854 | + 'event_espresso' |
|
| 855 | + ), |
|
| 856 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
| 857 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
| 858 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
| 859 | + '<ul>', |
|
| 860 | + '<li>', |
|
| 861 | + '</li>', |
|
| 862 | + '</ul>' |
|
| 863 | + ), |
|
| 864 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 865 | + ); |
|
| 866 | + } |
|
| 867 | + return false; |
|
| 868 | + } |
|
| 869 | + return true; |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * _verify_transaction_and_get_registrations |
|
| 875 | + * |
|
| 876 | + * @access private |
|
| 877 | + * @return bool |
|
| 878 | + * @throws InvalidDataTypeException |
|
| 879 | + * @throws InvalidEntityException |
|
| 880 | + * @throws EE_Error |
|
| 881 | + */ |
|
| 882 | + private function _verify_transaction_and_get_registrations() |
|
| 883 | + { |
|
| 884 | + // was there already a valid transaction in the checkout from the session ? |
|
| 885 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 886 | + // get transaction from db or session |
|
| 887 | + $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
| 888 | + ? $this->_get_transaction_and_cart_for_previous_visit() |
|
| 889 | + : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
| 890 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
| 891 | + EE_Error::add_error( |
|
| 892 | + __('Your Registration and Transaction information could not be retrieved from the db.', |
|
| 893 | + 'event_espresso'), |
|
| 894 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 895 | + ); |
|
| 896 | + $this->checkout->transaction = EE_Transaction::new_instance(); |
|
| 897 | + // add some style and make it dance |
|
| 898 | + $this->add_styles_and_scripts(); |
|
| 899 | + EED_Single_Page_Checkout::$_initialized = true; |
|
| 900 | + return false; |
|
| 901 | + } |
|
| 902 | + // and the registrations for the transaction |
|
| 903 | + $this->_get_registrations($this->checkout->transaction); |
|
| 904 | + } |
|
| 905 | + return true; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * _get_transaction_and_cart_for_previous_visit |
|
| 912 | + * |
|
| 913 | + * @access private |
|
| 914 | + * @return mixed EE_Transaction|NULL |
|
| 915 | + */ |
|
| 916 | + private function _get_transaction_and_cart_for_previous_visit() |
|
| 917 | + { |
|
| 918 | + /** @var $TXN_model EEM_Transaction */ |
|
| 919 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
| 920 | + // because the reg_url_link is present in the request, |
|
| 921 | + // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
| 922 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
| 923 | + // verify transaction |
|
| 924 | + if ($transaction instanceof EE_Transaction) { |
|
| 925 | + // and get the cart that was used for that transaction |
|
| 926 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
| 927 | + return $transaction; |
|
| 928 | + } |
|
| 929 | + EE_Error::add_error( |
|
| 930 | + __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
| 931 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 932 | + ); |
|
| 933 | + return null; |
|
| 934 | + |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + |
|
| 938 | + |
|
| 939 | + /** |
|
| 940 | + * _get_cart_for_transaction |
|
| 941 | + * |
|
| 942 | + * @access private |
|
| 943 | + * @param EE_Transaction $transaction |
|
| 944 | + * @return EE_Cart |
|
| 945 | + */ |
|
| 946 | + private function _get_cart_for_transaction($transaction) |
|
| 947 | + { |
|
| 948 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * get_cart_for_transaction |
|
| 955 | + * |
|
| 956 | + * @access public |
|
| 957 | + * @param EE_Transaction $transaction |
|
| 958 | + * @return EE_Cart |
|
| 959 | + */ |
|
| 960 | + public function get_cart_for_transaction(EE_Transaction $transaction) |
|
| 961 | + { |
|
| 962 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + |
|
| 966 | + |
|
| 967 | + /** |
|
| 968 | + * _get_transaction_and_cart_for_current_session |
|
| 969 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 970 | + * |
|
| 971 | + * @access private |
|
| 972 | + * @return EE_Transaction |
|
| 973 | + * @throws EE_Error |
|
| 974 | + */ |
|
| 975 | + private function _get_cart_for_current_session_and_setup_new_transaction() |
|
| 976 | + { |
|
| 977 | + // if there's no transaction, then this is the FIRST visit to SPCO |
|
| 978 | + // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
| 979 | + $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
| 980 | + // and then create a new transaction |
|
| 981 | + $transaction = $this->_initialize_transaction(); |
|
| 982 | + // verify transaction |
|
| 983 | + if ($transaction instanceof EE_Transaction) { |
|
| 984 | + // save it so that we have an ID for other objects to use |
|
| 985 | + $transaction->save(); |
|
| 986 | + // and save TXN data to the cart |
|
| 987 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 988 | + } else { |
|
| 989 | + EE_Error::add_error( |
|
| 990 | + __('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
| 991 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 992 | + ); |
|
| 993 | + } |
|
| 994 | + return $transaction; |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + |
|
| 998 | + |
|
| 999 | + /** |
|
| 1000 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
| 1001 | + * |
|
| 1002 | + * @access private |
|
| 1003 | + * @return mixed EE_Transaction|NULL |
|
| 1004 | + */ |
|
| 1005 | + private function _initialize_transaction() |
|
| 1006 | + { |
|
| 1007 | + try { |
|
| 1008 | + // ensure cart totals have been calculated |
|
| 1009 | + $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
| 1010 | + // grab the cart grand total |
|
| 1011 | + $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
| 1012 | + // create new TXN |
|
| 1013 | + $transaction = EE_Transaction::new_instance( |
|
| 1014 | + array( |
|
| 1015 | + 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
| 1016 | + 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
| 1017 | + 'TXN_paid' => 0, |
|
| 1018 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
| 1019 | + ) |
|
| 1020 | + ); |
|
| 1021 | + // save it so that we have an ID for other objects to use |
|
| 1022 | + $transaction->save(); |
|
| 1023 | + // set cron job for following up on TXNs after their session has expired |
|
| 1024 | + EE_Cron_Tasks::schedule_expired_transaction_check( |
|
| 1025 | + EE_Registry::instance()->SSN->expiration() + 1, |
|
| 1026 | + $transaction->ID() |
|
| 1027 | + ); |
|
| 1028 | + return $transaction; |
|
| 1029 | + } catch (Exception $e) { |
|
| 1030 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1031 | + } |
|
| 1032 | + return null; |
|
| 1033 | + } |
|
| 1034 | + |
|
| 1035 | + |
|
| 1036 | + /** |
|
| 1037 | + * _get_registrations |
|
| 1038 | + * |
|
| 1039 | + * @access private |
|
| 1040 | + * @param EE_Transaction $transaction |
|
| 1041 | + * @return void |
|
| 1042 | + * @throws InvalidDataTypeException |
|
| 1043 | + * @throws InvalidEntityException |
|
| 1044 | + * @throws EE_Error |
|
| 1045 | + */ |
|
| 1046 | + private function _get_registrations(EE_Transaction $transaction) |
|
| 1047 | + { |
|
| 1048 | + // first step: grab the registrants { : o |
|
| 1049 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 1050 | + $this->checkout->total_ticket_count = count($registrations); |
|
| 1051 | + // verify registrations have been set |
|
| 1052 | + if (empty($registrations)) { |
|
| 1053 | + // if no cached registrations, then check the db |
|
| 1054 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
| 1055 | + // still nothing ? well as long as this isn't a revisit |
|
| 1056 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
| 1057 | + // generate new registrations from scratch |
|
| 1058 | + $registrations = $this->_initialize_registrations($transaction); |
|
| 1059 | + } |
|
| 1060 | + } |
|
| 1061 | + // sort by their original registration order |
|
| 1062 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
| 1063 | + // then loop thru the array |
|
| 1064 | + foreach ($registrations as $registration) { |
|
| 1065 | + // verify each registration |
|
| 1066 | + if ($registration instanceof EE_Registration) { |
|
| 1067 | + // we display all attendee info for the primary registrant |
|
| 1068 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
| 1069 | + && $registration->is_primary_registrant() |
|
| 1070 | + ) { |
|
| 1071 | + $this->checkout->primary_revisit = true; |
|
| 1072 | + break; |
|
| 1073 | + } |
|
| 1074 | + if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) { |
|
| 1075 | + // but hide info if it doesn't belong to you |
|
| 1076 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
| 1077 | + $this->checkout->total_ticket_count--; |
|
| 1078 | + } |
|
| 1079 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
| 1087 | + * |
|
| 1088 | + * @access private |
|
| 1089 | + * @param EE_Transaction $transaction |
|
| 1090 | + * @return array |
|
| 1091 | + * @throws InvalidDataTypeException |
|
| 1092 | + * @throws InvalidEntityException |
|
| 1093 | + * @throws EE_Error |
|
| 1094 | + */ |
|
| 1095 | + private function _initialize_registrations(EE_Transaction $transaction) |
|
| 1096 | + { |
|
| 1097 | + $att_nmbr = 0; |
|
| 1098 | + $registrations = array(); |
|
| 1099 | + if ($transaction instanceof EE_Transaction) { |
|
| 1100 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 1101 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 1102 | + $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
| 1103 | + // now let's add the cart items to the $transaction |
|
| 1104 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
| 1105 | + //do the following for each ticket of this type they selected |
|
| 1106 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
| 1107 | + $att_nmbr++; |
|
| 1108 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
| 1109 | + $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
| 1110 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 1111 | + array( |
|
| 1112 | + $transaction, |
|
| 1113 | + $line_item, |
|
| 1114 | + $att_nmbr, |
|
| 1115 | + $this->checkout->total_ticket_count, |
|
| 1116 | + ) |
|
| 1117 | + ); |
|
| 1118 | + // override capabilities for frontend registrations |
|
| 1119 | + if ( ! is_admin()) { |
|
| 1120 | + $CreateRegistrationCommand->setCapCheck( |
|
| 1121 | + new PublicCapabilities('', 'create_new_registration') |
|
| 1122 | + ); |
|
| 1123 | + } |
|
| 1124 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
| 1125 | + if ( ! $registration instanceof EE_Registration) { |
|
| 1126 | + throw new InvalidEntityException($registration, 'EE_Registration'); |
|
| 1127 | + } |
|
| 1128 | + $registrations[ $registration->ID() ] = $registration; |
|
| 1129 | + } |
|
| 1130 | + } |
|
| 1131 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
| 1132 | + } |
|
| 1133 | + return $registrations; |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + |
|
| 1137 | + |
|
| 1138 | + /** |
|
| 1139 | + * sorts registrations by REG_count |
|
| 1140 | + * |
|
| 1141 | + * @access public |
|
| 1142 | + * @param EE_Registration $reg_A |
|
| 1143 | + * @param EE_Registration $reg_B |
|
| 1144 | + * @return int |
|
| 1145 | + */ |
|
| 1146 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
| 1147 | + { |
|
| 1148 | + // this shouldn't ever happen within the same TXN, but oh well |
|
| 1149 | + if ($reg_A->count() === $reg_B->count()) { |
|
| 1150 | + return 0; |
|
| 1151 | + } |
|
| 1152 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + |
|
| 1156 | + |
|
| 1157 | + /** |
|
| 1158 | + * _final_verifications |
|
| 1159 | + * just makes sure that everything is set up correctly before proceeding |
|
| 1160 | + * |
|
| 1161 | + * @access private |
|
| 1162 | + * @return bool |
|
| 1163 | + * @throws EE_Error |
|
| 1164 | + */ |
|
| 1165 | + private function _final_verifications() |
|
| 1166 | + { |
|
| 1167 | + // filter checkout |
|
| 1168 | + $this->checkout = apply_filters( |
|
| 1169 | + 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
| 1170 | + $this->checkout |
|
| 1171 | + ); |
|
| 1172 | + //verify that current step is still set correctly |
|
| 1173 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
| 1174 | + EE_Error::add_error( |
|
| 1175 | + __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1176 | + __FILE__, |
|
| 1177 | + __FUNCTION__, |
|
| 1178 | + __LINE__ |
|
| 1179 | + ); |
|
| 1180 | + return false; |
|
| 1181 | + } |
|
| 1182 | + // if returning to SPCO, then verify that primary registrant is set |
|
| 1183 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
| 1184 | + $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
| 1185 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1186 | + EE_Error::add_error( |
|
| 1187 | + __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
| 1188 | + __FILE__, |
|
| 1189 | + __FUNCTION__, |
|
| 1190 | + __LINE__ |
|
| 1191 | + ); |
|
| 1192 | + return false; |
|
| 1193 | + } |
|
| 1194 | + $valid_registrant = null; |
|
| 1195 | + foreach ( |
|
| 1196 | + $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration |
|
| 1197 | + ) { |
|
| 1198 | + if ( |
|
| 1199 | + $registration instanceof EE_Registration |
|
| 1200 | + && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
| 1201 | + ) { |
|
| 1202 | + $valid_registrant = $registration; |
|
| 1203 | + } |
|
| 1204 | + } |
|
| 1205 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
| 1206 | + // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
| 1207 | + if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
| 1208 | + // clear the session, mark the checkout as unverified, and try again |
|
| 1209 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 1210 | + EED_Single_Page_Checkout::$_initialized = false; |
|
| 1211 | + EED_Single_Page_Checkout::$_checkout_verified = false; |
|
| 1212 | + $this->_initialize(); |
|
| 1213 | + EE_Error::reset_notices(); |
|
| 1214 | + return false; |
|
| 1215 | + } |
|
| 1216 | + EE_Error::add_error( |
|
| 1217 | + __( |
|
| 1218 | + 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', |
|
| 1219 | + 'event_espresso' |
|
| 1220 | + ), |
|
| 1221 | + __FILE__, |
|
| 1222 | + __FUNCTION__, |
|
| 1223 | + __LINE__ |
|
| 1224 | + ); |
|
| 1225 | + return false; |
|
| 1226 | + } |
|
| 1227 | + } |
|
| 1228 | + // now that things have been kinda sufficiently verified, |
|
| 1229 | + // let's add the checkout to the session so that it's available to other systems |
|
| 1230 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
| 1231 | + return true; |
|
| 1232 | + } |
|
| 1233 | + |
|
| 1234 | + |
|
| 1235 | + |
|
| 1236 | + /** |
|
| 1237 | + * _initialize_reg_steps |
|
| 1238 | + * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
| 1239 | + * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
| 1240 | + * |
|
| 1241 | + * @access private |
|
| 1242 | + * @param bool $reinitializing |
|
| 1243 | + * @throws EE_Error |
|
| 1244 | + */ |
|
| 1245 | + private function _initialize_reg_steps($reinitializing = false) |
|
| 1246 | + { |
|
| 1247 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
| 1248 | + // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
| 1249 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
| 1250 | + if ( ! $reg_step->initialize_reg_step()) { |
|
| 1251 | + // if not initialized then maybe this step is being removed... |
|
| 1252 | + if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
| 1253 | + // if it was the current step, then we need to start over here |
|
| 1254 | + $this->_initialize_reg_steps(true); |
|
| 1255 | + return; |
|
| 1256 | + } |
|
| 1257 | + continue; |
|
| 1258 | + } |
|
| 1259 | + // add css and JS for current step |
|
| 1260 | + $reg_step->enqueue_styles_and_scripts(); |
|
| 1261 | + // i18n |
|
| 1262 | + $reg_step->translate_js_strings(); |
|
| 1263 | + if ($reg_step->is_current_step()) { |
|
| 1264 | + // the text that appears on the reg step form submit button |
|
| 1265 | + $reg_step->set_submit_button_text(); |
|
| 1266 | + } |
|
| 1267 | + } |
|
| 1268 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
| 1269 | + do_action( |
|
| 1270 | + "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
| 1271 | + $this->checkout->current_step |
|
| 1272 | + ); |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + |
|
| 1276 | + |
|
| 1277 | + /** |
|
| 1278 | + * _check_form_submission |
|
| 1279 | + * |
|
| 1280 | + * @access private |
|
| 1281 | + * @return boolean |
|
| 1282 | + */ |
|
| 1283 | + private function _check_form_submission() |
|
| 1284 | + { |
|
| 1285 | + //does this request require the reg form to be generated ? |
|
| 1286 | + if ($this->checkout->generate_reg_form) { |
|
| 1287 | + // ever heard that song by Blue Rodeo ? |
|
| 1288 | + try { |
|
| 1289 | + $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
| 1290 | + // if not displaying a form, then check for form submission |
|
| 1291 | + if ( |
|
| 1292 | + $this->checkout->process_form_submission |
|
| 1293 | + && $this->checkout->current_step->reg_form->was_submitted() |
|
| 1294 | + ) { |
|
| 1295 | + // clear out any old data in case this step is being run again |
|
| 1296 | + $this->checkout->current_step->set_valid_data(array()); |
|
| 1297 | + // capture submitted form data |
|
| 1298 | + $this->checkout->current_step->reg_form->receive_form_submission( |
|
| 1299 | + apply_filters( |
|
| 1300 | + 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
| 1301 | + EE_Registry::instance()->REQ->params(), |
|
| 1302 | + $this->checkout |
|
| 1303 | + ) |
|
| 1304 | + ); |
|
| 1305 | + // validate submitted form data |
|
| 1306 | + if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
| 1307 | + // thou shall not pass !!! |
|
| 1308 | + $this->checkout->continue_reg = false; |
|
| 1309 | + // any form validation errors? |
|
| 1310 | + if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
| 1311 | + $submission_error_messages = array(); |
|
| 1312 | + // bad, bad, bad registrant |
|
| 1313 | + foreach ( |
|
| 1314 | + $this->checkout->current_step->reg_form->get_validation_errors_accumulated() |
|
| 1315 | + as $validation_error |
|
| 1316 | + ) { |
|
| 1317 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1318 | + $submission_error_messages[] = sprintf( |
|
| 1319 | + __('%s : %s', 'event_espresso'), |
|
| 1320 | + $validation_error->get_form_section()->html_label_text(), |
|
| 1321 | + $validation_error->getMessage() |
|
| 1322 | + ); |
|
| 1323 | + } |
|
| 1324 | + } |
|
| 1325 | + EE_Error::add_error( |
|
| 1326 | + implode('<br />', $submission_error_messages), |
|
| 1327 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1328 | + ); |
|
| 1329 | + } |
|
| 1330 | + // well not really... what will happen is |
|
| 1331 | + // we'll just get redirected back to redo the current step |
|
| 1332 | + $this->go_to_next_step(); |
|
| 1333 | + return false; |
|
| 1334 | + } |
|
| 1335 | + } |
|
| 1336 | + } catch (EE_Error $e) { |
|
| 1337 | + $e->get_error(); |
|
| 1338 | + } |
|
| 1339 | + } |
|
| 1340 | + return true; |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + |
|
| 1344 | + |
|
| 1345 | + /** |
|
| 1346 | + * _process_action |
|
| 1347 | + * |
|
| 1348 | + * @access private |
|
| 1349 | + * @return void |
|
| 1350 | + * @throws EE_Error |
|
| 1351 | + */ |
|
| 1352 | + private function _process_form_action() |
|
| 1353 | + { |
|
| 1354 | + // what cha wanna do? |
|
| 1355 | + switch ($this->checkout->action) { |
|
| 1356 | + // AJAX next step reg form |
|
| 1357 | + case 'display_spco_reg_step' : |
|
| 1358 | + $this->checkout->redirect = false; |
|
| 1359 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1360 | + $this->checkout->json_response->set_reg_step_html( |
|
| 1361 | + $this->checkout->current_step->display_reg_form() |
|
| 1362 | + ); |
|
| 1363 | + } |
|
| 1364 | + break; |
|
| 1365 | + default : |
|
| 1366 | + // meh... do one of those other steps first |
|
| 1367 | + if ( |
|
| 1368 | + ! empty($this->checkout->action) |
|
| 1369 | + && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
| 1370 | + ) { |
|
| 1371 | + // dynamically creates hook point like: |
|
| 1372 | + // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
| 1373 | + do_action( |
|
| 1374 | + "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
| 1375 | + $this->checkout->current_step |
|
| 1376 | + ); |
|
| 1377 | + // call action on current step |
|
| 1378 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
| 1379 | + // good registrant, you get to proceed |
|
| 1380 | + if ( |
|
| 1381 | + $this->checkout->current_step->success_message() !== '' |
|
| 1382 | + && apply_filters( |
|
| 1383 | + 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
| 1384 | + false |
|
| 1385 | + ) |
|
| 1386 | + ) { |
|
| 1387 | + EE_Error::add_success( |
|
| 1388 | + $this->checkout->current_step->success_message() |
|
| 1389 | + . '<br />' . $this->checkout->next_step->_instructions() |
|
| 1390 | + ); |
|
| 1391 | + } |
|
| 1392 | + // pack it up, pack it in... |
|
| 1393 | + $this->_setup_redirect(); |
|
| 1394 | + } |
|
| 1395 | + // dynamically creates hook point like: |
|
| 1396 | + // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
| 1397 | + do_action( |
|
| 1398 | + "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
| 1399 | + $this->checkout->current_step |
|
| 1400 | + ); |
|
| 1401 | + } else { |
|
| 1402 | + EE_Error::add_error( |
|
| 1403 | + sprintf( |
|
| 1404 | + __( |
|
| 1405 | + 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
| 1406 | + 'event_espresso' |
|
| 1407 | + ), |
|
| 1408 | + $this->checkout->action, |
|
| 1409 | + $this->checkout->current_step->name() |
|
| 1410 | + ), |
|
| 1411 | + __FILE__, |
|
| 1412 | + __FUNCTION__, |
|
| 1413 | + __LINE__ |
|
| 1414 | + ); |
|
| 1415 | + } |
|
| 1416 | + // end default |
|
| 1417 | + } |
|
| 1418 | + // store our progress so far |
|
| 1419 | + $this->checkout->stash_transaction_and_checkout(); |
|
| 1420 | + // advance to the next step! If you pass GO, collect $200 |
|
| 1421 | + $this->go_to_next_step(); |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + |
|
| 1425 | + |
|
| 1426 | + /** |
|
| 1427 | + * add_styles_and_scripts |
|
| 1428 | + * |
|
| 1429 | + * @access public |
|
| 1430 | + * @return void |
|
| 1431 | + */ |
|
| 1432 | + public function add_styles_and_scripts() |
|
| 1433 | + { |
|
| 1434 | + // i18n |
|
| 1435 | + $this->translate_js_strings(); |
|
| 1436 | + if ($this->checkout->admin_request) { |
|
| 1437 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1438 | + } else { |
|
| 1439 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + |
|
| 1443 | + |
|
| 1444 | + |
|
| 1445 | + /** |
|
| 1446 | + * translate_js_strings |
|
| 1447 | + * |
|
| 1448 | + * @access public |
|
| 1449 | + * @return void |
|
| 1450 | + */ |
|
| 1451 | + public function translate_js_strings() |
|
| 1452 | + { |
|
| 1453 | + EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
| 1454 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
| 1455 | + EE_Registry::$i18n_js_strings['server_error'] = __( |
|
| 1456 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 1457 | + 'event_espresso' |
|
| 1458 | + ); |
|
| 1459 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __( |
|
| 1460 | + 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
| 1461 | + 'event_espresso' |
|
| 1462 | + ); |
|
| 1463 | + EE_Registry::$i18n_js_strings['validation_error'] = __( |
|
| 1464 | + 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
| 1465 | + 'event_espresso' |
|
| 1466 | + ); |
|
| 1467 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( |
|
| 1468 | + 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
| 1469 | + 'event_espresso' |
|
| 1470 | + ); |
|
| 1471 | + EE_Registry::$i18n_js_strings['reg_step_error'] = __( |
|
| 1472 | + 'This registration step could not be completed. Please refresh the page and try again.', |
|
| 1473 | + 'event_espresso' |
|
| 1474 | + ); |
|
| 1475 | + EE_Registry::$i18n_js_strings['invalid_coupon'] = __( |
|
| 1476 | + 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
| 1477 | + 'event_espresso' |
|
| 1478 | + ); |
|
| 1479 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
| 1480 | + __( |
|
| 1481 | + 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
| 1482 | + 'event_espresso' |
|
| 1483 | + ), |
|
| 1484 | + '<br/>', |
|
| 1485 | + '<br/>' |
|
| 1486 | + ); |
|
| 1487 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
| 1488 | + EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
| 1489 | + EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
| 1490 | + EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
| 1491 | + EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
| 1492 | + EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
| 1493 | + EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
| 1494 | + EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
| 1495 | + EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
| 1496 | + EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
| 1497 | + EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
| 1498 | + EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
| 1499 | + EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
| 1500 | + EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
| 1501 | + EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
| 1502 | + EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
| 1503 | + EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
| 1504 | + EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
| 1505 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
| 1506 | + __( |
|
| 1507 | + '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
| 1508 | + 'event_espresso' |
|
| 1509 | + ), |
|
| 1510 | + '<h4 class="important-notice">', |
|
| 1511 | + '</h4>', |
|
| 1512 | + '<br />', |
|
| 1513 | + '<p>', |
|
| 1514 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
| 1515 | + '">', |
|
| 1516 | + '</a>', |
|
| 1517 | + '</p>' |
|
| 1518 | + ); |
|
| 1519 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
| 1520 | + 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
| 1521 | + true |
|
| 1522 | + ); |
|
| 1523 | + EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
| 1524 | + apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
| 1525 | + ); |
|
| 1526 | + EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
| 1527 | + 'M d, Y H:i:s', |
|
| 1528 | + EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1529 | + ); |
|
| 1530 | + } |
|
| 1531 | + |
|
| 1532 | + |
|
| 1533 | + |
|
| 1534 | + /** |
|
| 1535 | + * enqueue_styles_and_scripts |
|
| 1536 | + * |
|
| 1537 | + * @access public |
|
| 1538 | + * @return void |
|
| 1539 | + * @throws EE_Error |
|
| 1540 | + */ |
|
| 1541 | + public function enqueue_styles_and_scripts() |
|
| 1542 | + { |
|
| 1543 | + // load css |
|
| 1544 | + wp_register_style( |
|
| 1545 | + 'single_page_checkout', |
|
| 1546 | + SPCO_CSS_URL . 'single_page_checkout.css', |
|
| 1547 | + array('espresso_default'), |
|
| 1548 | + EVENT_ESPRESSO_VERSION |
|
| 1549 | + ); |
|
| 1550 | + wp_enqueue_style('single_page_checkout'); |
|
| 1551 | + // load JS |
|
| 1552 | + wp_register_script( |
|
| 1553 | + 'jquery_plugin', |
|
| 1554 | + EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
| 1555 | + array('jquery'), |
|
| 1556 | + '1.0.1', |
|
| 1557 | + true |
|
| 1558 | + ); |
|
| 1559 | + wp_register_script( |
|
| 1560 | + 'jquery_countdown', |
|
| 1561 | + EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
| 1562 | + array('jquery_plugin'), |
|
| 1563 | + '2.0.2', |
|
| 1564 | + true |
|
| 1565 | + ); |
|
| 1566 | + wp_register_script( |
|
| 1567 | + 'single_page_checkout', |
|
| 1568 | + SPCO_JS_URL . 'single_page_checkout.js', |
|
| 1569 | + array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
|
| 1570 | + EVENT_ESPRESSO_VERSION, |
|
| 1571 | + true |
|
| 1572 | + ); |
|
| 1573 | + if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
| 1574 | + $this->checkout->registration_form->enqueue_js(); |
|
| 1575 | + } |
|
| 1576 | + if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
| 1577 | + $this->checkout->current_step->reg_form->enqueue_js(); |
|
| 1578 | + } |
|
| 1579 | + wp_enqueue_script('single_page_checkout'); |
|
| 1580 | + /** |
|
| 1581 | + * global action hook for enqueueing styles and scripts with |
|
| 1582 | + * spco calls. |
|
| 1583 | + */ |
|
| 1584 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
| 1585 | + /** |
|
| 1586 | + * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
| 1587 | + * The hook will end up being something like: |
|
| 1588 | + * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
| 1589 | + */ |
|
| 1590 | + do_action( |
|
| 1591 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
| 1592 | + $this |
|
| 1593 | + ); |
|
| 1594 | + } |
|
| 1595 | + |
|
| 1596 | + |
|
| 1597 | + |
|
| 1598 | + /** |
|
| 1599 | + * display the Registration Single Page Checkout Form |
|
| 1600 | + * |
|
| 1601 | + * @access private |
|
| 1602 | + * @return void |
|
| 1603 | + * @throws EE_Error |
|
| 1604 | + */ |
|
| 1605 | + private function _display_spco_reg_form() |
|
| 1606 | + { |
|
| 1607 | + // if registering via the admin, just display the reg form for the current step |
|
| 1608 | + if ($this->checkout->admin_request) { |
|
| 1609 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
| 1610 | + } else { |
|
| 1611 | + // add powered by EE msg |
|
| 1612 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
| 1613 | + $empty_cart = count( |
|
| 1614 | + $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) |
|
| 1615 | + ) < 1; |
|
| 1616 | + EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
| 1617 | + $cookies_not_set_msg = ''; |
|
| 1618 | + if ($empty_cart) { |
|
| 1619 | + $cookies_not_set_msg = apply_filters( |
|
| 1620 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
| 1621 | + sprintf( |
|
| 1622 | + __( |
|
| 1623 | + '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
| 1624 | + 'event_espresso' |
|
| 1625 | + ), |
|
| 1626 | + '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">', |
|
| 1627 | + '</div>', |
|
| 1628 | + '<h6 class="important-notice">', |
|
| 1629 | + '</h6>', |
|
| 1630 | + '<p>', |
|
| 1631 | + '</p>', |
|
| 1632 | + '<br />', |
|
| 1633 | + '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
| 1634 | + '</a>' |
|
| 1635 | + ) |
|
| 1636 | + ); |
|
| 1637 | + } |
|
| 1638 | + $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
| 1639 | + array( |
|
| 1640 | + 'name' => 'single-page-checkout', |
|
| 1641 | + 'html_id' => 'ee-single-page-checkout-dv', |
|
| 1642 | + 'layout_strategy' => |
|
| 1643 | + new EE_Template_Layout( |
|
| 1644 | + array( |
|
| 1645 | + 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
| 1646 | + 'template_args' => array( |
|
| 1647 | + 'empty_cart' => $empty_cart, |
|
| 1648 | + 'revisit' => $this->checkout->revisit, |
|
| 1649 | + 'reg_steps' => $this->checkout->reg_steps, |
|
| 1650 | + 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
| 1651 | + ? $this->checkout->next_step->slug() |
|
| 1652 | + : '', |
|
| 1653 | + 'empty_msg' => apply_filters( |
|
| 1654 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
| 1655 | + sprintf( |
|
| 1656 | + __( |
|
| 1657 | + 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
| 1658 | + 'event_espresso' |
|
| 1659 | + ), |
|
| 1660 | + '<a href="' |
|
| 1661 | + . get_post_type_archive_link('espresso_events') |
|
| 1662 | + . '" title="', |
|
| 1663 | + '">', |
|
| 1664 | + '</a>' |
|
| 1665 | + ) |
|
| 1666 | + ), |
|
| 1667 | + 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
| 1668 | + 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
| 1669 | + 'session_expiration' => gmdate( |
|
| 1670 | + 'M d, Y H:i:s', |
|
| 1671 | + EE_Registry::instance()->SSN->expiration() |
|
| 1672 | + + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1673 | + ), |
|
| 1674 | + ), |
|
| 1675 | + ) |
|
| 1676 | + ), |
|
| 1677 | + ) |
|
| 1678 | + ); |
|
| 1679 | + // load template and add to output sent that gets filtered into the_content() |
|
| 1680 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
| 1681 | + } |
|
| 1682 | + } |
|
| 1683 | + |
|
| 1684 | + |
|
| 1685 | + |
|
| 1686 | + /** |
|
| 1687 | + * add_extra_finalize_registration_inputs |
|
| 1688 | + * |
|
| 1689 | + * @access public |
|
| 1690 | + * @param $next_step |
|
| 1691 | + * @internal param string $label |
|
| 1692 | + * @return void |
|
| 1693 | + */ |
|
| 1694 | + public function add_extra_finalize_registration_inputs($next_step) |
|
| 1695 | + { |
|
| 1696 | + if ($next_step === 'finalize_registration') { |
|
| 1697 | + echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
| 1698 | + } |
|
| 1699 | + } |
|
| 1700 | + |
|
| 1701 | + |
|
| 1702 | + |
|
| 1703 | + /** |
|
| 1704 | + * display_registration_footer |
|
| 1705 | + * |
|
| 1706 | + * @access public |
|
| 1707 | + * @return string |
|
| 1708 | + */ |
|
| 1709 | + public static function display_registration_footer() |
|
| 1710 | + { |
|
| 1711 | + if ( |
|
| 1712 | + apply_filters( |
|
| 1713 | + 'FHEE__EE_Front__Controller__show_reg_footer', |
|
| 1714 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
| 1715 | + ) |
|
| 1716 | + ) { |
|
| 1717 | + add_filter( |
|
| 1718 | + 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
| 1719 | + function ($url) { |
|
| 1720 | + return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
| 1721 | + } |
|
| 1722 | + ); |
|
| 1723 | + echo apply_filters( |
|
| 1724 | + 'FHEE__EE_Front_Controller__display_registration_footer', |
|
| 1725 | + \EEH_Template::powered_by_event_espresso( |
|
| 1726 | + '', |
|
| 1727 | + 'espresso-registration-footer-dv', |
|
| 1728 | + array('utm_content' => 'registration_checkout') |
|
| 1729 | + ) |
|
| 1730 | + ); |
|
| 1731 | + } |
|
| 1732 | + return ''; |
|
| 1733 | + } |
|
| 1734 | + |
|
| 1735 | + |
|
| 1736 | + |
|
| 1737 | + /** |
|
| 1738 | + * unlock_transaction |
|
| 1739 | + * |
|
| 1740 | + * @access public |
|
| 1741 | + * @return void |
|
| 1742 | + * @throws EE_Error |
|
| 1743 | + */ |
|
| 1744 | + public function unlock_transaction() |
|
| 1745 | + { |
|
| 1746 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 1747 | + $this->checkout->transaction->unlock(); |
|
| 1748 | + } |
|
| 1749 | + } |
|
| 1750 | + |
|
| 1751 | + |
|
| 1752 | + |
|
| 1753 | + /** |
|
| 1754 | + * _setup_redirect |
|
| 1755 | + * |
|
| 1756 | + * @access private |
|
| 1757 | + * @return void |
|
| 1758 | + */ |
|
| 1759 | + private function _setup_redirect() |
|
| 1760 | + { |
|
| 1761 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
| 1762 | + $this->checkout->redirect = true; |
|
| 1763 | + if (empty($this->checkout->redirect_url)) { |
|
| 1764 | + $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
| 1765 | + } |
|
| 1766 | + $this->checkout->redirect_url = apply_filters( |
|
| 1767 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
| 1768 | + $this->checkout->redirect_url, |
|
| 1769 | + $this->checkout |
|
| 1770 | + ); |
|
| 1771 | + } |
|
| 1772 | + } |
|
| 1773 | + |
|
| 1774 | + |
|
| 1775 | + |
|
| 1776 | + /** |
|
| 1777 | + * handle ajax message responses and redirects |
|
| 1778 | + * |
|
| 1779 | + * @access public |
|
| 1780 | + * @return void |
|
| 1781 | + * @throws EE_Error |
|
| 1782 | + */ |
|
| 1783 | + public function go_to_next_step() |
|
| 1784 | + { |
|
| 1785 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1786 | + // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
| 1787 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
| 1788 | + } |
|
| 1789 | + $this->unlock_transaction(); |
|
| 1790 | + // just return for these conditions |
|
| 1791 | + if ( |
|
| 1792 | + $this->checkout->admin_request |
|
| 1793 | + || $this->checkout->action === 'redirect_form' |
|
| 1794 | + || $this->checkout->action === 'update_checkout' |
|
| 1795 | + ) { |
|
| 1796 | + return; |
|
| 1797 | + } |
|
| 1798 | + // AJAX response |
|
| 1799 | + $this->_handle_json_response(); |
|
| 1800 | + // redirect to next step or the Thank You page |
|
| 1801 | + $this->_handle_html_redirects(); |
|
| 1802 | + // hmmm... must be something wrong, so let's just display the form again ! |
|
| 1803 | + $this->_display_spco_reg_form(); |
|
| 1804 | + } |
|
| 1805 | + |
|
| 1806 | + |
|
| 1807 | + |
|
| 1808 | + /** |
|
| 1809 | + * _handle_json_response |
|
| 1810 | + * |
|
| 1811 | + * @access protected |
|
| 1812 | + * @return void |
|
| 1813 | + */ |
|
| 1814 | + protected function _handle_json_response() |
|
| 1815 | + { |
|
| 1816 | + // if this is an ajax request |
|
| 1817 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 1818 | + // DEBUG LOG |
|
| 1819 | + //$this->checkout->log( |
|
| 1820 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 1821 | + // array( |
|
| 1822 | + // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
| 1823 | + // 'redirect' => $this->checkout->redirect, |
|
| 1824 | + // 'continue_reg' => $this->checkout->continue_reg, |
|
| 1825 | + // ) |
|
| 1826 | + //); |
|
| 1827 | + $this->checkout->json_response->set_registration_time_limit( |
|
| 1828 | + $this->checkout->get_registration_time_limit() |
|
| 1829 | + ); |
|
| 1830 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
| 1831 | + // just send the ajax ( |
|
| 1832 | + $json_response = apply_filters( |
|
| 1833 | + 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
| 1834 | + $this->checkout->json_response |
|
| 1835 | + ); |
|
| 1836 | + echo $json_response; |
|
| 1837 | + exit(); |
|
| 1838 | + } |
|
| 1839 | + } |
|
| 1840 | + |
|
| 1841 | + |
|
| 1842 | + |
|
| 1843 | + /** |
|
| 1844 | + * _handle_redirects |
|
| 1845 | + * |
|
| 1846 | + * @access protected |
|
| 1847 | + * @return void |
|
| 1848 | + */ |
|
| 1849 | + protected function _handle_html_redirects() |
|
| 1850 | + { |
|
| 1851 | + // going somewhere ? |
|
| 1852 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
| 1853 | + // store notices in a transient |
|
| 1854 | + EE_Error::get_notices(false, true, true); |
|
| 1855 | + // DEBUG LOG |
|
| 1856 | + //$this->checkout->log( |
|
| 1857 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 1858 | + // array( |
|
| 1859 | + // 'headers_sent' => headers_sent(), |
|
| 1860 | + // 'redirect_url' => $this->checkout->redirect_url, |
|
| 1861 | + // 'headers_list' => headers_list(), |
|
| 1862 | + // ) |
|
| 1863 | + //); |
|
| 1864 | + wp_safe_redirect($this->checkout->redirect_url); |
|
| 1865 | + exit(); |
|
| 1866 | + } |
|
| 1867 | + } |
|
| 1868 | + |
|
| 1869 | + |
|
| 1870 | + |
|
| 1871 | + /** |
|
| 1872 | + * set_checkout_anchor |
|
| 1873 | + * |
|
| 1874 | + * @access public |
|
| 1875 | + * @return void |
|
| 1876 | + */ |
|
| 1877 | + public function set_checkout_anchor() |
|
| 1878 | + { |
|
| 1879 | + echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
| 1880 | + } |
|
| 1881 | 1881 | |
| 1882 | 1882 | |
| 1883 | 1883 | |
@@ -45,25 +45,25 @@ discard block |
||
| 45 | 45 | * @param bool $password_check |
| 46 | 46 | * @return \EE_Venue|null |
| 47 | 47 | */ |
| 48 | - public static function get_venue( $VNU_ID = 0, $look_in_event = TRUE, $privacy_check = true, $password_check = true ) { |
|
| 49 | - $VNU_ID = absint( $VNU_ID ); |
|
| 48 | + public static function get_venue($VNU_ID = 0, $look_in_event = TRUE, $privacy_check = true, $password_check = true) { |
|
| 49 | + $VNU_ID = absint($VNU_ID); |
|
| 50 | 50 | // do we already have the Venue you are looking for? |
| 51 | - if ( EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID ) { |
|
| 51 | + if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
| 52 | 52 | //If the Venue ID matches $VNU_ID, return the venue. |
| 53 | - if( EEH_Venue_View::$_venue->ID() === $VNU_ID ) { |
|
| 54 | - return EEH_Venue_View::_get_venue( $privacy_check ); |
|
| 53 | + if (EEH_Venue_View::$_venue->ID() === $VNU_ID) { |
|
| 54 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
| 55 | 55 | } |
| 56 | 56 | //If the Venue ID does not match, try pulling a venue using $VNU_ID. |
| 57 | - $venue = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
| 58 | - if( $venue instanceof EE_Venue ) { |
|
| 57 | + $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
| 58 | + if ($venue instanceof EE_Venue) { |
|
| 59 | 59 | EEH_Venue_View::$_venue = $venue; |
| 60 | - return EEH_Venue_View::_get_venue( $privacy_check ); |
|
| 60 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | // international newspaper? |
| 64 | 64 | global $post; |
| 65 | - if ( $post instanceof WP_Post ) { |
|
| 66 | - switch ( $post->post_type ) { |
|
| 65 | + if ($post instanceof WP_Post) { |
|
| 66 | + switch ($post->post_type) { |
|
| 67 | 67 | // if this is being called from an EE_Venue post, |
| 68 | 68 | // and the EE_Venue post corresponds to the EE_Venue that is being asked for, |
| 69 | 69 | // then we can try to just grab the attached EE_Venue object |
@@ -71,31 +71,31 @@ discard block |
||
| 71 | 71 | // the post already contains the related EE_Venue object AND one of the following is TRUE: |
| 72 | 72 | // the requested Venue ID matches the post ID OR... |
| 73 | 73 | // there was no specific Venue ID requested |
| 74 | - if ( isset( $post->EE_Venue ) && ( $VNU_ID == $post->ID || ! $VNU_ID )) { |
|
| 74 | + if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) { |
|
| 75 | 75 | // use existing related EE_Venue object |
| 76 | - EEH_Venue_View::$_venue = $post->EE_Venue; |
|
| 77 | - } else if ( $VNU_ID ) { |
|
| 76 | + EEH_Venue_View::$_venue = $post->EE_Venue; |
|
| 77 | + } else if ($VNU_ID) { |
|
| 78 | 78 | // there WAS a specific Venue ID requested, but it's NOT the current post object |
| 79 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
| 79 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
| 80 | 80 | } else { |
| 81 | 81 | // no specific Venue ID requested, so use post ID to generate EE_Venue object |
| 82 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID( $post->ID ); |
|
| 82 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID); |
|
| 83 | 83 | } |
| 84 | 84 | break; |
| 85 | 85 | |
| 86 | 86 | case 'espresso_events': |
| 87 | - if ( $look_in_event ) { |
|
| 87 | + if ($look_in_event) { |
|
| 88 | 88 | // grab the events related venues |
| 89 | 89 | $venues = EEH_Venue_View::get_event_venues(); |
| 90 | 90 | // make sure the result is an array |
| 91 | - $venues = is_array( $venues ) ? $venues : array(); |
|
| 91 | + $venues = is_array($venues) ? $venues : array(); |
|
| 92 | 92 | // do we have an ID for a specific venue? |
| 93 | - if ( $VNU_ID ) { |
|
| 93 | + if ($VNU_ID) { |
|
| 94 | 94 | // loop thru the related venues |
| 95 | - foreach( $venues as $venue ) { |
|
| 96 | - if ( $venue instanceof EE_Venue ) { |
|
| 95 | + foreach ($venues as $venue) { |
|
| 96 | + if ($venue instanceof EE_Venue) { |
|
| 97 | 97 | // until we find the venue we're looking for |
| 98 | - if ( $venue->ID() == $VNU_ID ) { |
|
| 98 | + if ($venue->ID() == $VNU_ID) { |
|
| 99 | 99 | EEH_Venue_View::$_venue = $venue; |
| 100 | 100 | break; |
| 101 | 101 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | // then the global post is an events post and this function was called with no argument |
| 106 | 106 | } else { |
| 107 | 107 | // just grab the first related event venue |
| 108 | - EEH_Venue_View::$_venue = reset( $venues ); |
|
| 108 | + EEH_Venue_View::$_venue = reset($venues); |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | break; |
@@ -113,11 +113,11 @@ discard block |
||
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
| 116 | - if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID ) { |
|
| 116 | + if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
| 117 | 117 | // sigh... pull it from the db |
| 118 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
| 118 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
| 119 | 119 | } |
| 120 | - return EEH_Venue_View::_get_venue( $privacy_check, $password_check ); |
|
| 120 | + return EEH_Venue_View::_get_venue($privacy_check, $password_check); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
@@ -130,13 +130,13 @@ discard block |
||
| 130 | 130 | * @param bool $password_check |
| 131 | 131 | * @return EE_Venue |
| 132 | 132 | */ |
| 133 | - protected static function _get_venue( $privacy_check = true, $password_check = true ) { |
|
| 133 | + protected static function _get_venue($privacy_check = true, $password_check = true) { |
|
| 134 | 134 | // check for private venues. |
| 135 | 135 | if ( |
| 136 | 136 | EEH_Venue_View::$_venue instanceof EE_Venue |
| 137 | 137 | && EEH_Venue_View::$_venue->status() == 'private' |
| 138 | 138 | && $privacy_check |
| 139 | - && ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_venues', 'get_venues' ) |
|
| 139 | + && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues') |
|
| 140 | 140 | ) { |
| 141 | 141 | return null; |
| 142 | 142 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | if ( |
| 145 | 145 | EEH_Venue_View::$_venue instanceof EE_Venue |
| 146 | 146 | && $password_check |
| 147 | - && post_password_required( EEH_Venue_View::$_venue->ID() ) |
|
| 147 | + && post_password_required(EEH_Venue_View::$_venue->ID()) |
|
| 148 | 148 | ) { |
| 149 | 149 | return null; |
| 150 | 150 | } |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public static function get_event_venues() { |
| 163 | 163 | global $post; |
| 164 | - if ( $post->post_type == 'espresso_events' ) { |
|
| 165 | - if ( isset( $post->EE_Event ) && $post->EE_Event instanceof EE_Event ) { |
|
| 164 | + if ($post->post_type == 'espresso_events') { |
|
| 165 | + if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) { |
|
| 166 | 166 | return $post->EE_Event->venues(); |
| 167 | 167 | } |
| 168 | 168 | } |
@@ -182,9 +182,9 @@ discard block |
||
| 182 | 182 | * |
| 183 | 183 | * @return bool|null |
| 184 | 184 | */ |
| 185 | - public static function is_venue_private( $VNU_ID = false ) { |
|
| 186 | - $venue = EEH_Venue_View::get_venue( $VNU_ID, true, true ); |
|
| 187 | - if ( ! $venue instanceof EE_Venue ) { |
|
| 185 | + public static function is_venue_private($VNU_ID = false) { |
|
| 186 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true); |
|
| 187 | + if ( ! $venue instanceof EE_Venue) { |
|
| 188 | 188 | return null; |
| 189 | 189 | } |
| 190 | 190 | |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
| 200 | 200 | * @return bool |
| 201 | 201 | */ |
| 202 | - public static function is_venue_password_protected( $VNU_ID = false ) { |
|
| 203 | - $venue = EEH_Venue_View::get_venue( $VNU_ID, true, true, false ); |
|
| 202 | + public static function is_venue_password_protected($VNU_ID = false) { |
|
| 203 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
| 204 | 204 | if ( |
| 205 | 205 | $venue instanceof EE_Venue |
| 206 | - && post_password_required( $venue->ID() ) |
|
| 206 | + && post_password_required($venue->ID()) |
|
| 207 | 207 | ) { |
| 208 | 208 | return true; |
| 209 | 209 | } |
@@ -220,13 +220,13 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @return string |
| 222 | 222 | */ |
| 223 | - public static function password_protected_venue_form( $VNU_ID = false ) { |
|
| 224 | - $venue = EEH_Venue_View::get_venue( $VNU_ID, true, true, false ); |
|
| 223 | + public static function password_protected_venue_form($VNU_ID = false) { |
|
| 224 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
| 225 | 225 | if ( |
| 226 | 226 | $venue instanceof EE_Venue |
| 227 | - && post_password_required( $venue->ID() ) |
|
| 227 | + && post_password_required($venue->ID()) |
|
| 228 | 228 | ) { |
| 229 | - return get_the_password_form( $venue->ID() ); |
|
| 229 | + return get_the_password_form($venue->ID()); |
|
| 230 | 230 | } |
| 231 | 231 | return ''; |
| 232 | 232 | } |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | * @param int $VNU_ID |
| 241 | 241 | * @return string |
| 242 | 242 | */ |
| 243 | - public static function venue_description( $VNU_ID = 0 ) { |
|
| 244 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 245 | - if ( $venue instanceof EE_Venue ) { |
|
| 243 | + public static function venue_description($VNU_ID = 0) { |
|
| 244 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 245 | + if ($venue instanceof EE_Venue) { |
|
| 246 | 246 | return$venue->description(); |
| 247 | 247 | } |
| 248 | 248 | return ''; |
@@ -257,12 +257,12 @@ discard block |
||
| 257 | 257 | * @param int $VNU_ID |
| 258 | 258 | * @return string |
| 259 | 259 | */ |
| 260 | - public static function venue_excerpt( $VNU_ID = 0 ) { |
|
| 261 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 262 | - if ( $venue instanceof EE_Venue ) { |
|
| 260 | + public static function venue_excerpt($VNU_ID = 0) { |
|
| 261 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 262 | + if ($venue instanceof EE_Venue) { |
|
| 263 | 263 | $excerpt = $venue->excerpt() != NULL && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
| 264 | - $venue_link = ' ' . EEH_Venue_View::venue_details_link( $venue->ID(), __( 'more', 'event_espresso' ) . '…' ); |
|
| 265 | - return ! empty( $excerpt ) ? wp_trim_words( $excerpt, 25, '' ) . $venue_link : ''; |
|
| 264 | + $venue_link = ' '.EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso').'…'); |
|
| 265 | + return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '').$venue_link : ''; |
|
| 266 | 266 | } |
| 267 | 267 | return ''; |
| 268 | 268 | } |
@@ -277,22 +277,22 @@ discard block |
||
| 277 | 277 | * @param bool $hide_uncategorized |
| 278 | 278 | * @return string |
| 279 | 279 | */ |
| 280 | - public static function venue_categories( $VNU_ID = 0, $hide_uncategorized = TRUE ) { |
|
| 280 | + public static function venue_categories($VNU_ID = 0, $hide_uncategorized = TRUE) { |
|
| 281 | 281 | $category_links = array(); |
| 282 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 283 | - if ( $venue instanceof EE_Venue ) { |
|
| 282 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 283 | + if ($venue instanceof EE_Venue) { |
|
| 284 | 284 | // get category terms |
| 285 | - if ( $venue_categories = get_the_terms( $venue->ID(), 'espresso_venue_categories' )) { |
|
| 285 | + if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) { |
|
| 286 | 286 | // loop thru terms and create links |
| 287 | - foreach ( $venue_categories as $term ) { |
|
| 288 | - $url = get_term_link( $term, 'espresso_venue_categories' ); |
|
| 289 | - if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
|
| 290 | - $category_links[] = '<a href="' . esc_url( $url ) . '" rel="tag">' . $term->name . '</a> '; |
|
| 287 | + foreach ($venue_categories as $term) { |
|
| 288 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
| 289 | + if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) { |
|
| 290 | + $category_links[] = '<a href="'.esc_url($url).'" rel="tag">'.$term->name.'</a> '; |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | - return implode( ', ', $category_links ); |
|
| 295 | + return implode(', ', $category_links); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | |
@@ -307,10 +307,10 @@ discard block |
||
| 307 | 307 | * @param bool $add_wrapper |
| 308 | 308 | * @return string |
| 309 | 309 | */ |
| 310 | - public static function venue_address( $type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true ) { |
|
| 311 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 312 | - if ( $venue instanceof EE_Venue ) { |
|
| 313 | - return EEH_Address::format( $venue, $type, $use_schema, $add_wrapper ); |
|
| 310 | + public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true) { |
|
| 311 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 312 | + if ($venue instanceof EE_Venue) { |
|
| 313 | + return EEH_Address::format($venue, $type, $use_schema, $add_wrapper); |
|
| 314 | 314 | } |
| 315 | 315 | return ''; |
| 316 | 316 | } |
@@ -324,10 +324,10 @@ discard block |
||
| 324 | 324 | * @param int $VNU_ID |
| 325 | 325 | * @return bool|string |
| 326 | 326 | */ |
| 327 | - public static function venue_has_address( $VNU_ID = 0 ) { |
|
| 328 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 329 | - if ( $venue instanceof EE_Venue ) { |
|
| 330 | - return EEH_Address::format( $venue, 'inline', FALSE, FALSE ); |
|
| 327 | + public static function venue_has_address($VNU_ID = 0) { |
|
| 328 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 329 | + if ($venue instanceof EE_Venue) { |
|
| 330 | + return EEH_Address::format($venue, 'inline', FALSE, FALSE); |
|
| 331 | 331 | } |
| 332 | 332 | return false; |
| 333 | 333 | } |
@@ -342,30 +342,30 @@ discard block |
||
| 342 | 342 | * @param int $VNU_ID |
| 343 | 343 | * @return string |
| 344 | 344 | */ |
| 345 | - public static function venue_name( $link_to = 'details', $VNU_ID = 0 ) { |
|
| 346 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 347 | - if ( $venue instanceof EE_Venue ) { |
|
| 345 | + public static function venue_name($link_to = 'details', $VNU_ID = 0) { |
|
| 346 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 347 | + if ($venue instanceof EE_Venue) { |
|
| 348 | 348 | $venue_name = apply_filters( |
| 349 | 349 | 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
| 350 | 350 | EEH_Venue_View::is_venue_private() |
| 351 | - ? EEH_Venue_View::$_venue->name() . " " . __( '(Private)', 'event_espresso' ) |
|
| 351 | + ? EEH_Venue_View::$_venue->name()." ".__('(Private)', 'event_espresso') |
|
| 352 | 352 | : EEH_Venue_View::$_venue->name(), |
| 353 | 353 | EEH_Venue_View::$_venue |
| 354 | 354 | ); |
| 355 | - $venue_name = EEH_Schema::name( $venue_name ); |
|
| 355 | + $venue_name = EEH_Schema::name($venue_name); |
|
| 356 | 356 | |
| 357 | 357 | //if venue is trashed then ignore the "link to" setting because the venue is trashed. |
| 358 | - if ( $venue->get('status') == 'trash' ) { |
|
| 358 | + if ($venue->get('status') == 'trash') { |
|
| 359 | 359 | $link_to = ''; |
| 360 | 360 | } |
| 361 | - switch( $link_to ) { |
|
| 361 | + switch ($link_to) { |
|
| 362 | 362 | |
| 363 | 363 | case 'details' : |
| 364 | - return EEH_Venue_View::venue_details_link( $venue->ID(), $venue_name ); |
|
| 364 | + return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name); |
|
| 365 | 365 | break; |
| 366 | 366 | |
| 367 | 367 | case 'website' : |
| 368 | - return EEH_Venue_View::venue_website_link( $venue->ID(), $venue_name ); |
|
| 368 | + return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name); |
|
| 369 | 369 | break; |
| 370 | 370 | |
| 371 | 371 | default : |
@@ -385,10 +385,10 @@ discard block |
||
| 385 | 385 | * @param string $text |
| 386 | 386 | * @return string |
| 387 | 387 | */ |
| 388 | - public static function venue_details_link( $VNU_ID = 0, $text = '' ) { |
|
| 389 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 390 | - if ( $venue instanceof EE_Venue ) { |
|
| 391 | - return EEH_Schema::url( get_permalink( $venue->ID() ), $text ); |
|
| 388 | + public static function venue_details_link($VNU_ID = 0, $text = '') { |
|
| 389 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 390 | + if ($venue instanceof EE_Venue) { |
|
| 391 | + return EEH_Schema::url(get_permalink($venue->ID()), $text); |
|
| 392 | 392 | } |
| 393 | 393 | return ''; |
| 394 | 394 | } |
@@ -403,12 +403,12 @@ discard block |
||
| 403 | 403 | * @param string $text |
| 404 | 404 | * @return string |
| 405 | 405 | */ |
| 406 | - public static function venue_website_link( $VNU_ID = 0, $text = '' ) { |
|
| 407 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 408 | - if ( $venue instanceof EE_Venue ) { |
|
| 406 | + public static function venue_website_link($VNU_ID = 0, $text = '') { |
|
| 407 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 408 | + if ($venue instanceof EE_Venue) { |
|
| 409 | 409 | $url = $venue->venue_url(); |
| 410 | - $text = ! empty( $text ) ? $text : $url; |
|
| 411 | - return ! empty( $url ) ? EEH_Schema::url( $url, $text ) : ''; |
|
| 410 | + $text = ! empty($text) ? $text : $url; |
|
| 411 | + return ! empty($url) ? EEH_Schema::url($url, $text) : ''; |
|
| 412 | 412 | } |
| 413 | 413 | return ''; |
| 414 | 414 | } |
@@ -422,10 +422,10 @@ discard block |
||
| 422 | 422 | * @param int $VNU_ID |
| 423 | 423 | * @return string |
| 424 | 424 | */ |
| 425 | - public static function venue_phone( $VNU_ID = 0) { |
|
| 426 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 427 | - if ( $venue instanceof EE_Venue ) { |
|
| 428 | - return EEH_Schema::telephone( $venue->phone() ); |
|
| 425 | + public static function venue_phone($VNU_ID = 0) { |
|
| 426 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 427 | + if ($venue instanceof EE_Venue) { |
|
| 428 | + return EEH_Schema::telephone($venue->phone()); |
|
| 429 | 429 | } |
| 430 | 430 | return ''; |
| 431 | 431 | } |
@@ -441,48 +441,48 @@ discard block |
||
| 441 | 441 | * @param array $gmap map options |
| 442 | 442 | * @return string |
| 443 | 443 | */ |
| 444 | - public static function venue_gmap( $VNU_ID = 0, $map_ID = FALSE, $gmap = array() ) { |
|
| 444 | + public static function venue_gmap($VNU_ID = 0, $map_ID = FALSE, $gmap = array()) { |
|
| 445 | 445 | |
| 446 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 447 | - if ( $venue instanceof EE_Venue ) { |
|
| 446 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 447 | + if ($venue instanceof EE_Venue) { |
|
| 448 | 448 | // check for global espresso_events post and use it's ID if no map_ID is set |
| 449 | 449 | global $post; |
| 450 | - $map_ID = empty( $map_ID ) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
| 450 | + $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
| 451 | 451 | // grab map settings |
| 452 | 452 | $map_cfg = EE_Registry::instance()->CFG->map_settings; |
| 453 | 453 | // are maps enabled ? |
| 454 | - if ( $map_cfg->use_google_maps && $venue->enable_for_gmap() ) { |
|
| 454 | + if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
|
| 455 | 455 | |
| 456 | 456 | $details_page = is_single(); |
| 457 | 457 | $options = array(); |
| 458 | - $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
| 458 | + $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID.'-'.$venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
| 459 | 459 | |
| 460 | - $options['location'] = EEH_Address::format( $venue, 'inline', FALSE, FALSE ); |
|
| 460 | + $options['location'] = EEH_Address::format($venue, 'inline', FALSE, FALSE); |
|
| 461 | 461 | |
| 462 | 462 | $options['ee_map_width'] = $details_page ? $map_cfg->event_details_map_width : $map_cfg->event_list_map_width; |
| 463 | - $options['ee_map_width'] = isset( $gmap['ee_map_width'] ) && ! empty( $gmap['ee_map_width'] ) ? $gmap['ee_map_width'] : $options['ee_map_width']; |
|
| 463 | + $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) ? $gmap['ee_map_width'] : $options['ee_map_width']; |
|
| 464 | 464 | |
| 465 | 465 | $options['ee_map_height'] = $details_page ? $map_cfg->event_details_map_height : $map_cfg->event_list_map_height; |
| 466 | - $options['ee_map_height'] = isset( $gmap['ee_map_height'] ) && ! empty( $gmap['ee_map_height'] ) ? $gmap['ee_map_height'] : $options['ee_map_height']; |
|
| 466 | + $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) ? $gmap['ee_map_height'] : $options['ee_map_height']; |
|
| 467 | 467 | |
| 468 | 468 | $options['ee_map_zoom'] = $details_page ? $map_cfg->event_details_map_zoom : $map_cfg->event_list_map_zoom; |
| 469 | - $options['ee_map_zoom'] = isset( $gmap['ee_map_zoom'] ) && ! empty( $gmap['ee_map_zoom'] ) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom']; |
|
| 469 | + $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom']; |
|
| 470 | 470 | |
| 471 | 471 | $options['ee_map_nav_display'] = $details_page ? $map_cfg->event_details_display_nav : $map_cfg->event_list_display_nav; |
| 472 | - $options['ee_map_nav_display'] = isset( $gmap['ee_map_nav_display'] ) && ! empty( $gmap['ee_map_nav_display'] ) ? 'true' : $options['ee_map_nav_display'];; |
|
| 472 | + $options['ee_map_nav_display'] = isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) ? 'true' : $options['ee_map_nav_display']; ; |
|
| 473 | 473 | |
| 474 | 474 | $options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size; |
| 475 | - $options['ee_map_nav_size'] = isset( $gmap['ee_map_nav_size'] ) && ! empty( $gmap['ee_map_nav_size'] )? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
| 475 | + $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) ? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
| 476 | 476 | |
| 477 | 477 | $options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type; |
| 478 | - $options['ee_map_type_control'] = isset( $gmap['ee_map_type_control'] ) && ! empty( $gmap['ee_map_type_control'] )? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
| 478 | + $options['ee_map_type_control'] = isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) ? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
| 479 | 479 | |
| 480 | 480 | $options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align; |
| 481 | - $options['ee_map_align'] = isset( $gmap['ee_map_align'] ) && ! empty( $gmap['ee_map_align'] )? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
| 481 | + $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) ? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
| 482 | 482 | |
| 483 | - $options['ee_static_url'] = isset( $gmap['ee_static_url'] ) && ! empty( $gmap['ee_static_url'] ) ? (bool)absint( $gmap['ee_static_url'] ) : $venue->google_map_link(); |
|
| 483 | + $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link(); |
|
| 484 | 484 | |
| 485 | - return EEH_Maps::google_map( $options ); |
|
| 485 | + return EEH_Maps::google_map($options); |
|
| 486 | 486 | |
| 487 | 487 | } |
| 488 | 488 | } |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | * @param array $atts like EEH_Maps::google_map_link |
| 498 | 498 | * @return string |
| 499 | 499 | */ |
| 500 | - public static function espresso_google_static_map( EE_Venue $venue, $atts = array() ){ |
|
| 500 | + public static function espresso_google_static_map(EE_Venue $venue, $atts = array()) { |
|
| 501 | 501 | $state = $venue->state_obj(); |
| 502 | 502 | $country = $venue->country_obj(); |
| 503 | 503 | $atts = shortcode_atts( |
@@ -528,23 +528,23 @@ discard block |
||
| 528 | 528 | * @param string $after |
| 529 | 529 | * @return string |
| 530 | 530 | */ |
| 531 | - public static function edit_venue_link( $VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>' ) { |
|
| 532 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 533 | - if ( $venue instanceof EE_Venue ) { |
|
| 531 | + public static function edit_venue_link($VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>') { |
|
| 532 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 533 | + if ($venue instanceof EE_Venue) { |
|
| 534 | 534 | // can the user edit this post ? |
| 535 | - if ( current_user_can( 'edit_post', $venue->ID() )) { |
|
| 535 | + if (current_user_can('edit_post', $venue->ID())) { |
|
| 536 | 536 | // set link text |
| 537 | - $link = ! empty( $link ) ? $link : __('edit this venue'); |
|
| 537 | + $link = ! empty($link) ? $link : __('edit this venue'); |
|
| 538 | 538 | // generate nonce |
| 539 | - $nonce = wp_create_nonce( 'edit_nonce' ); |
|
| 539 | + $nonce = wp_create_nonce('edit_nonce'); |
|
| 540 | 540 | // generate url to venue editor for this venue |
| 541 | - $url = add_query_arg( array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url( 'admin.php' ) ); |
|
| 541 | + $url = add_query_arg(array('page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce), admin_url('admin.php')); |
|
| 542 | 542 | // get edit CPT text |
| 543 | - $post_type_obj = get_post_type_object( 'espresso_venues' ); |
|
| 543 | + $post_type_obj = get_post_type_object('espresso_venues'); |
|
| 544 | 544 | // build final link html |
| 545 | - $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $link . '</a>'; |
|
| 545 | + $link = '<a class="post-edit-link" href="'.$url.'" title="'.esc_attr($post_type_obj->labels->edit_item).'">'.$link.'</a>'; |
|
| 546 | 546 | // put it all together |
| 547 | - return $before . apply_filters( 'edit_post_link', $link, $venue->ID() ) . $after; |
|
| 547 | + return $before.apply_filters('edit_post_link', $link, $venue->ID()).$after; |
|
| 548 | 548 | } |
| 549 | 549 | } |
| 550 | 550 | return ''; |
@@ -425,7 +425,7 @@ |
||
| 425 | 425 | * with construction finalize being called later |
| 426 | 426 | * (realizing that the subsections' html names |
| 427 | 427 | * might not be set yet, etc.) |
| 428 | - * @return EE_Form_Section_Base |
|
| 428 | + * @return EE_Form_Section_Validatable|null |
|
| 429 | 429 | * @throws EE_Error |
| 430 | 430 | */ |
| 431 | 431 | public function get_subsection($name, $require_construction_to_be_finalized = true) |
@@ -14,1421 +14,1421 @@ |
||
| 14 | 14 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Subsections |
|
| 21 | - * |
|
| 22 | - * @var EE_Form_Section_Validatable[] |
|
| 23 | - */ |
|
| 24 | - protected $_subsections = array(); |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Strategy for laying out the form |
|
| 28 | - * |
|
| 29 | - * @var EE_Form_Section_Layout_Base |
|
| 30 | - */ |
|
| 31 | - protected $_layout_strategy; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Whether or not this form has received and validated a form submission yet |
|
| 35 | - * |
|
| 36 | - * @var boolean |
|
| 37 | - */ |
|
| 38 | - protected $_received_submission = false; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * message displayed to users upon successful form submission |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - protected $_form_submission_success_message = ''; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * message displayed to users upon unsuccessful form submission |
|
| 49 | - * |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - protected $_form_submission_error_message = ''; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Stores all the data that will localized for form validation |
|
| 56 | - * |
|
| 57 | - * @var array |
|
| 58 | - */ |
|
| 59 | - static protected $_js_localization = array(); |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * whether or not the form's localized validation JS vars have been set |
|
| 63 | - * |
|
| 64 | - * @type boolean |
|
| 65 | - */ |
|
| 66 | - static protected $_scripts_localized = false; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * when constructing a proper form section, calls _construct_finalize on children |
|
| 71 | - * so that they know who their parent is, and what name they've been given. |
|
| 72 | - * |
|
| 73 | - * @param array[] $options_array { |
|
| 74 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 75 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 76 | - * and in that order. This is handy if you want |
|
| 77 | - * the subsections to be ordered differently than the default, and if you override |
|
| 78 | - * which fields are shown |
|
| 79 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 80 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 81 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 82 | - * items from that list of inclusions) |
|
| 83 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 84 | - * } @see EE_Form_Section_Validatable::__construct() |
|
| 85 | - * @throws EE_Error |
|
| 86 | - */ |
|
| 87 | - public function __construct($options_array = array()) |
|
| 88 | - { |
|
| 89 | - $options_array = (array) apply_filters( |
|
| 90 | - 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
| 91 | - $options_array, |
|
| 92 | - $this |
|
| 93 | - ); |
|
| 94 | - //call parent first, as it may be setting the name |
|
| 95 | - parent::__construct($options_array); |
|
| 96 | - //if they've included subsections in the constructor, add them now |
|
| 97 | - if (isset($options_array['include'])) { |
|
| 98 | - //we are going to make sure we ONLY have those subsections to include |
|
| 99 | - //AND we are going to make sure they're in that specified order |
|
| 100 | - $reordered_subsections = array(); |
|
| 101 | - foreach ($options_array['include'] as $input_name) { |
|
| 102 | - if (isset($this->_subsections[ $input_name ])) { |
|
| 103 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - $this->_subsections = $reordered_subsections; |
|
| 107 | - } |
|
| 108 | - if (isset($options_array['exclude'])) { |
|
| 109 | - $exclude = $options_array['exclude']; |
|
| 110 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 111 | - } |
|
| 112 | - if (isset($options_array['layout_strategy'])) { |
|
| 113 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 114 | - } |
|
| 115 | - if (! $this->_layout_strategy) { |
|
| 116 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 117 | - } |
|
| 118 | - $this->_layout_strategy->_construct_finalize($this); |
|
| 119 | - //ok so we are definitely going to want the forms JS, |
|
| 120 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 121 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 122 | - //ok so they've constructed this object after when they should have. |
|
| 123 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 124 | - EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 125 | - } else { |
|
| 126 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 127 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 128 | - } |
|
| 129 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 130 | - /** |
|
| 131 | - * Gives other plugins a chance to hook in before construct finalize is called. |
|
| 132 | - * The form probably doesn't yet have a parent form section. |
|
| 133 | - * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
| 134 | - * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
| 135 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
| 136 | - * |
|
| 137 | - * @since 4.9.32 |
|
| 138 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
| 139 | - * except maybe calling _construct_finalize has been done |
|
| 140 | - * @param array $options_array options passed into the constructor |
|
| 141 | - */ |
|
| 142 | - do_action( |
|
| 143 | - 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
| 144 | - $this, |
|
| 145 | - $options_array |
|
| 146 | - ); |
|
| 147 | - if (isset($options_array['name'])) { |
|
| 148 | - $this->_construct_finalize(null, $options_array['name']); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Finishes construction given the parent form section and this form section's name |
|
| 155 | - * |
|
| 156 | - * @param EE_Form_Section_Proper $parent_form_section |
|
| 157 | - * @param string $name |
|
| 158 | - * @throws EE_Error |
|
| 159 | - */ |
|
| 160 | - public function _construct_finalize($parent_form_section, $name) |
|
| 161 | - { |
|
| 162 | - parent::_construct_finalize($parent_form_section, $name); |
|
| 163 | - $this->_set_default_name_if_empty(); |
|
| 164 | - $this->_set_default_html_id_if_empty(); |
|
| 165 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 166 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
| 167 | - $subsection->_construct_finalize($this, $subsection_name); |
|
| 168 | - } else { |
|
| 169 | - throw new EE_Error( |
|
| 170 | - sprintf( |
|
| 171 | - esc_html__( |
|
| 172 | - 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 173 | - 'event_espresso' |
|
| 174 | - ), |
|
| 175 | - $subsection_name, |
|
| 176 | - get_class($this), |
|
| 177 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 178 | - ) |
|
| 179 | - ); |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - /** |
|
| 183 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
| 184 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
| 185 | - * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
| 186 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
| 187 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
| 188 | - * ensured it has a name, HTML IDs, etc |
|
| 189 | - * |
|
| 190 | - * @param EE_Form_Section_Proper $this |
|
| 191 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 192 | - * @param string $name |
|
| 193 | - */ |
|
| 194 | - do_action( |
|
| 195 | - 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
| 196 | - $this, |
|
| 197 | - $parent_form_section, |
|
| 198 | - $name |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Gets the layout strategy for this form section |
|
| 205 | - * |
|
| 206 | - * @return EE_Form_Section_Layout_Base |
|
| 207 | - */ |
|
| 208 | - public function get_layout_strategy() |
|
| 209 | - { |
|
| 210 | - return $this->_layout_strategy; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Gets the HTML for a single input for this form section according |
|
| 216 | - * to the layout strategy |
|
| 217 | - * |
|
| 218 | - * @param EE_Form_Input_Base $input |
|
| 219 | - * @return string |
|
| 220 | - */ |
|
| 221 | - public function get_html_for_input($input) |
|
| 222 | - { |
|
| 223 | - return $this->_layout_strategy->layout_input($input); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * was_submitted - checks if form inputs are present in request data |
|
| 229 | - * Basically an alias for form_data_present_in() (which is used by both |
|
| 230 | - * proper form sections and form inputs) |
|
| 231 | - * |
|
| 232 | - * @param null $form_data |
|
| 233 | - * @return boolean |
|
| 234 | - * @throws EE_Error |
|
| 235 | - */ |
|
| 236 | - public function was_submitted($form_data = null) |
|
| 237 | - { |
|
| 238 | - return $this->form_data_present_in($form_data); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
| 244 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
| 245 | - * |
|
| 246 | - * @param array|null $req_data should usually be $_POST (the default). |
|
| 247 | - * However, you CAN supply a different array. |
|
| 248 | - * Consider using set_defaults() instead however. |
|
| 249 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 250 | - * the inputs will have the correct name in the request data for this function |
|
| 251 | - * to find them and populate the form with them. |
|
| 252 | - * If you have a flat form (with only input subsections), |
|
| 253 | - * you can supply a flat array where keys |
|
| 254 | - * are the form input names and values are their values) |
|
| 255 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 256 | - * of course, to validate that data, and set errors on the invalid values. |
|
| 257 | - * But if the data has already been validated |
|
| 258 | - * (eg you validated the data then stored it in the DB) |
|
| 259 | - * you may want to skip this step. |
|
| 260 | - * @throws InvalidArgumentException |
|
| 261 | - * @throws InvalidInterfaceException |
|
| 262 | - * @throws InvalidDataTypeException |
|
| 263 | - * @throws EE_Error |
|
| 264 | - */ |
|
| 265 | - public function receive_form_submission($req_data = null, $validate = true) |
|
| 266 | - { |
|
| 267 | - $req_data = apply_filters( |
|
| 268 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
| 269 | - $req_data, |
|
| 270 | - $this, |
|
| 271 | - $validate |
|
| 272 | - ); |
|
| 273 | - if ($req_data === null) { |
|
| 274 | - $req_data = array_merge($_GET, $_POST); |
|
| 275 | - } |
|
| 276 | - $req_data = apply_filters( |
|
| 277 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 278 | - $req_data, |
|
| 279 | - $this |
|
| 280 | - ); |
|
| 281 | - $this->_normalize($req_data); |
|
| 282 | - if ($validate) { |
|
| 283 | - $this->_validate(); |
|
| 284 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 285 | - if (! $this->is_valid()) { |
|
| 286 | - $this->store_submitted_form_data_in_session(); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - do_action( |
|
| 290 | - 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
| 291 | - $req_data, |
|
| 292 | - $this, |
|
| 293 | - $validate |
|
| 294 | - ); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * caches the originally submitted input values in the session |
|
| 300 | - * so that they can be used to repopulate the form if it failed validation |
|
| 301 | - * |
|
| 302 | - * @return boolean whether or not the data was successfully stored in the session |
|
| 303 | - * @throws InvalidArgumentException |
|
| 304 | - * @throws InvalidInterfaceException |
|
| 305 | - * @throws InvalidDataTypeException |
|
| 306 | - * @throws EE_Error |
|
| 307 | - */ |
|
| 308 | - protected function store_submitted_form_data_in_session() |
|
| 309 | - { |
|
| 310 | - return EE_Registry::instance()->SSN->set_session_data( |
|
| 311 | - array( |
|
| 312 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 313 | - ) |
|
| 314 | - ); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * retrieves the originally submitted input values in the session |
|
| 320 | - * so that they can be used to repopulate the form if it failed validation |
|
| 321 | - * |
|
| 322 | - * @return array |
|
| 323 | - * @throws InvalidArgumentException |
|
| 324 | - * @throws InvalidInterfaceException |
|
| 325 | - * @throws InvalidDataTypeException |
|
| 326 | - */ |
|
| 327 | - protected function get_submitted_form_data_from_session() |
|
| 328 | - { |
|
| 329 | - $session = EE_Registry::instance()->SSN; |
|
| 330 | - if ($session instanceof EE_Session) { |
|
| 331 | - return $session->get_session_data( |
|
| 332 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 333 | - ); |
|
| 334 | - } |
|
| 335 | - return array(); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * flushed the originally submitted input values from the session |
|
| 341 | - * |
|
| 342 | - * @return boolean whether or not the data was successfully removed from the session |
|
| 343 | - * @throws InvalidArgumentException |
|
| 344 | - * @throws InvalidInterfaceException |
|
| 345 | - * @throws InvalidDataTypeException |
|
| 346 | - */ |
|
| 347 | - protected function flush_submitted_form_data_from_session() |
|
| 348 | - { |
|
| 349 | - return EE_Registry::instance()->SSN->reset_data( |
|
| 350 | - array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 351 | - ); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Populates this form and its subsections with data from the session. |
|
| 357 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 358 | - * validation errors when displaying too) |
|
| 359 | - * Returns true if the form was populated from the session, false otherwise |
|
| 360 | - * |
|
| 361 | - * @return boolean |
|
| 362 | - * @throws InvalidArgumentException |
|
| 363 | - * @throws InvalidInterfaceException |
|
| 364 | - * @throws InvalidDataTypeException |
|
| 365 | - * @throws EE_Error |
|
| 366 | - */ |
|
| 367 | - public function populate_from_session() |
|
| 368 | - { |
|
| 369 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 370 | - if (empty($form_data_in_session)) { |
|
| 371 | - return false; |
|
| 372 | - } |
|
| 373 | - $this->receive_form_submission($form_data_in_session); |
|
| 374 | - $this->flush_submitted_form_data_from_session(); |
|
| 375 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
| 376 | - return true; |
|
| 377 | - } |
|
| 378 | - return false; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Populates the default data for the form, given an array where keys are |
|
| 384 | - * the input names, and values are their values (preferably normalized to be their |
|
| 385 | - * proper PHP types, not all strings... although that should be ok too). |
|
| 386 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 387 | - * the value being an array formatted in teh same way |
|
| 388 | - * |
|
| 389 | - * @param array $default_data |
|
| 390 | - * @throws EE_Error |
|
| 391 | - */ |
|
| 392 | - public function populate_defaults($default_data) |
|
| 393 | - { |
|
| 394 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
| 395 | - if (isset($default_data[ $subsection_name ])) { |
|
| 396 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 397 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
| 398 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 399 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * returns true if subsection exists |
|
| 408 | - * |
|
| 409 | - * @param string $name |
|
| 410 | - * @return boolean |
|
| 411 | - */ |
|
| 412 | - public function subsection_exists($name) |
|
| 413 | - { |
|
| 414 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * Gets the subsection specified by its name |
|
| 420 | - * |
|
| 421 | - * @param string $name |
|
| 422 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 423 | - * so that the inputs will be properly configured. |
|
| 424 | - * However, some client code may be ok |
|
| 425 | - * with construction finalize being called later |
|
| 426 | - * (realizing that the subsections' html names |
|
| 427 | - * might not be set yet, etc.) |
|
| 428 | - * @return EE_Form_Section_Base |
|
| 429 | - * @throws EE_Error |
|
| 430 | - */ |
|
| 431 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 432 | - { |
|
| 433 | - if ($require_construction_to_be_finalized) { |
|
| 434 | - $this->ensure_construct_finalized_called(); |
|
| 435 | - } |
|
| 436 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Gets all the validatable subsections of this form section |
|
| 442 | - * |
|
| 443 | - * @return EE_Form_Section_Validatable[] |
|
| 444 | - * @throws EE_Error |
|
| 445 | - */ |
|
| 446 | - public function get_validatable_subsections() |
|
| 447 | - { |
|
| 448 | - $validatable_subsections = array(); |
|
| 449 | - foreach ($this->subsections() as $name => $obj) { |
|
| 450 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 451 | - $validatable_subsections[ $name ] = $obj; |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - return $validatable_subsections; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 460 | - * throw an EE_Error. |
|
| 461 | - * |
|
| 462 | - * @param string $name |
|
| 463 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 464 | - * leave this as TRUE so that the inputs will be properly |
|
| 465 | - * configured. However, some client code may be ok with |
|
| 466 | - * construction finalize being called later |
|
| 467 | - * (realizing that the subsections' html names might not be |
|
| 468 | - * set yet, etc.) |
|
| 469 | - * @return EE_Form_Input_Base |
|
| 470 | - * @throws EE_Error |
|
| 471 | - */ |
|
| 472 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 473 | - { |
|
| 474 | - $subsection = $this->get_subsection( |
|
| 475 | - $name, |
|
| 476 | - $require_construction_to_be_finalized |
|
| 477 | - ); |
|
| 478 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 479 | - throw new EE_Error( |
|
| 480 | - sprintf( |
|
| 481 | - esc_html__( |
|
| 482 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 483 | - 'event_espresso' |
|
| 484 | - ), |
|
| 485 | - $name, |
|
| 486 | - get_class($this), |
|
| 487 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 488 | - ) |
|
| 489 | - ); |
|
| 490 | - } |
|
| 491 | - return $subsection; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
| 497 | - * otherwise throws an EE_Error |
|
| 498 | - * |
|
| 499 | - * @param string $name |
|
| 500 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 501 | - * leave this as TRUE so that the inputs will be properly |
|
| 502 | - * configured. However, some client code may be ok with |
|
| 503 | - * construction finalize being called later |
|
| 504 | - * (realizing that the subsections' html names might not be |
|
| 505 | - * set yet, etc.) |
|
| 506 | - * @return EE_Form_Section_Proper |
|
| 507 | - * @throws EE_Error |
|
| 508 | - */ |
|
| 509 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 510 | - { |
|
| 511 | - $subsection = $this->get_subsection( |
|
| 512 | - $name, |
|
| 513 | - $require_construction_to_be_finalized |
|
| 514 | - ); |
|
| 515 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 516 | - throw new EE_Error( |
|
| 517 | - sprintf( |
|
| 518 | - esc_html__( |
|
| 519 | - "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
| 520 | - 'event_espresso' |
|
| 521 | - ), |
|
| 522 | - $name, |
|
| 523 | - get_class($this) |
|
| 524 | - ) |
|
| 525 | - ); |
|
| 526 | - } |
|
| 527 | - return $subsection; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 533 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 534 | - * |
|
| 535 | - * @param string $name |
|
| 536 | - * @return mixed depending on the input's type and its normalization strategy |
|
| 537 | - * @throws EE_Error |
|
| 538 | - */ |
|
| 539 | - public function get_input_value($name) |
|
| 540 | - { |
|
| 541 | - $input = $this->get_input($name); |
|
| 542 | - return $input->normalized_value(); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Checks if this form section itself is valid, and then checks its subsections |
|
| 548 | - * |
|
| 549 | - * @throws EE_Error |
|
| 550 | - * @return boolean |
|
| 551 | - */ |
|
| 552 | - public function is_valid() |
|
| 553 | - { |
|
| 554 | - if (! $this->has_received_submission()) { |
|
| 555 | - throw new EE_Error( |
|
| 556 | - sprintf( |
|
| 557 | - esc_html__( |
|
| 558 | - 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
| 559 | - 'event_espresso' |
|
| 560 | - ) |
|
| 561 | - ) |
|
| 562 | - ); |
|
| 563 | - } |
|
| 564 | - if (! parent::is_valid()) { |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - // ok so no general errors to this entire form section. |
|
| 568 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 569 | - $set_submission_errors = $this->submission_error_message() === ''; |
|
| 570 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 571 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 572 | - if ($set_submission_errors) { |
|
| 573 | - $this->set_submission_error_message( |
|
| 574 | - $subsection->get_validation_error_string() |
|
| 575 | - ); |
|
| 576 | - } |
|
| 577 | - return false; |
|
| 578 | - } |
|
| 579 | - } |
|
| 580 | - return true; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * gets the default name of this form section if none is specified |
|
| 586 | - * |
|
| 587 | - * @return void |
|
| 588 | - */ |
|
| 589 | - protected function _set_default_name_if_empty() |
|
| 590 | - { |
|
| 591 | - if (! $this->_name) { |
|
| 592 | - $classname = get_class($this); |
|
| 593 | - $default_name = str_replace('EE_', '', $classname); |
|
| 594 | - $this->_name = $default_name; |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
| 601 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 602 | - * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
| 603 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 604 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 605 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 606 | - * any CSS. |
|
| 607 | - * |
|
| 608 | - * @throws InvalidArgumentException |
|
| 609 | - * @throws InvalidInterfaceException |
|
| 610 | - * @throws InvalidDataTypeException |
|
| 611 | - * @throws EE_Error |
|
| 612 | - */ |
|
| 613 | - public function get_html_and_js() |
|
| 614 | - { |
|
| 615 | - $this->enqueue_js(); |
|
| 616 | - return $this->get_html(); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 622 | - * |
|
| 623 | - * @param bool $display_previously_submitted_data |
|
| 624 | - * @return string |
|
| 625 | - * @throws InvalidArgumentException |
|
| 626 | - * @throws InvalidInterfaceException |
|
| 627 | - * @throws InvalidDataTypeException |
|
| 628 | - * @throws EE_Error |
|
| 629 | - * @throws EE_Error |
|
| 630 | - * @throws EE_Error |
|
| 631 | - */ |
|
| 632 | - public function get_html($display_previously_submitted_data = true) |
|
| 633 | - { |
|
| 634 | - $this->ensure_construct_finalized_called(); |
|
| 635 | - if ($display_previously_submitted_data) { |
|
| 636 | - $this->populate_from_session(); |
|
| 637 | - } |
|
| 638 | - return $this->_form_html_filter |
|
| 639 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
| 640 | - : $this->_layout_strategy->layout_form(); |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * enqueues JS and CSS for the form. |
|
| 646 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
| 647 | - * scripts and styles can be put in the header, but if called later |
|
| 648 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 649 | - * only be in the header; but in HTML5 its ok in the body. |
|
| 650 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 651 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 652 | - * |
|
| 653 | - * @return void |
|
| 654 | - * @throws EE_Error |
|
| 655 | - */ |
|
| 656 | - public function enqueue_js() |
|
| 657 | - { |
|
| 658 | - $this->_enqueue_and_localize_form_js(); |
|
| 659 | - foreach ($this->subsections() as $subsection) { |
|
| 660 | - $subsection->enqueue_js(); |
|
| 661 | - } |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - |
|
| 665 | - /** |
|
| 666 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 667 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 668 | - * the wp_enqueue_scripts hook. |
|
| 669 | - * However, registering the form js and localizing it can happen when we |
|
| 670 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
| 671 | - * could change until it's actually outputted) |
|
| 672 | - * |
|
| 673 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 674 | - * to be triggered automatically or not |
|
| 675 | - * @return void |
|
| 676 | - */ |
|
| 677 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 678 | - { |
|
| 679 | - wp_register_script( |
|
| 680 | - 'ee_form_section_validation', |
|
| 681 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 682 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 683 | - EVENT_ESPRESSO_VERSION, |
|
| 684 | - true |
|
| 685 | - ); |
|
| 686 | - wp_localize_script( |
|
| 687 | - 'ee_form_section_validation', |
|
| 688 | - 'ee_form_section_validation_init', |
|
| 689 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
| 690 | - ); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * gets the variables used by form_section_validation.js. |
|
| 696 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 697 | - * but before the wordpress hook wp_loaded |
|
| 698 | - * |
|
| 699 | - * @throws EE_Error |
|
| 700 | - */ |
|
| 701 | - public function _enqueue_and_localize_form_js() |
|
| 702 | - { |
|
| 703 | - $this->ensure_construct_finalized_called(); |
|
| 704 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 705 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
| 706 | - //and localize it just before the footer |
|
| 707 | - $this->localize_validation_rules(); |
|
| 708 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 709 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * add our form section data to a static variable accessible by all form sections |
|
| 715 | - * |
|
| 716 | - * @param bool $return_for_subsection |
|
| 717 | - * @return void |
|
| 718 | - * @throws EE_Error |
|
| 719 | - */ |
|
| 720 | - public function localize_validation_rules($return_for_subsection = false) |
|
| 721 | - { |
|
| 722 | - // we only want to localize vars ONCE for the entire form, |
|
| 723 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
| 724 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
| 725 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 726 | - 'form_section_id' => $this->html_id(true), |
|
| 727 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 728 | - 'other_data' => $this->get_other_js_data(), |
|
| 729 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 730 | - ); |
|
| 731 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 732 | - } |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - |
|
| 736 | - /** |
|
| 737 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
| 738 | - * This is primarily data added by inputs and forms in addition to any |
|
| 739 | - * scripts they might enqueue |
|
| 740 | - * |
|
| 741 | - * @param array $form_other_js_data |
|
| 742 | - * @return array |
|
| 743 | - * @throws EE_Error |
|
| 744 | - */ |
|
| 745 | - public function get_other_js_data($form_other_js_data = array()) |
|
| 746 | - { |
|
| 747 | - foreach ($this->subsections() as $subsection) { |
|
| 748 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 749 | - } |
|
| 750 | - return $form_other_js_data; |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - /** |
|
| 755 | - * Gets a flat array of inputs for this form section and its subsections. |
|
| 756 | - * Keys are their form names, and values are the inputs themselves |
|
| 757 | - * |
|
| 758 | - * @return EE_Form_Input_Base |
|
| 759 | - * @throws EE_Error |
|
| 760 | - */ |
|
| 761 | - public function inputs_in_subsections() |
|
| 762 | - { |
|
| 763 | - $inputs = array(); |
|
| 764 | - foreach ($this->subsections() as $subsection) { |
|
| 765 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 766 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
| 767 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 768 | - $inputs += $subsection->inputs_in_subsections(); |
|
| 769 | - } |
|
| 770 | - } |
|
| 771 | - return $inputs; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - |
|
| 775 | - /** |
|
| 776 | - * Gets a flat array of all the validation errors. |
|
| 777 | - * Keys are html names (because those should be unique) |
|
| 778 | - * and values are a string of all their validation errors |
|
| 779 | - * |
|
| 780 | - * @return string[] |
|
| 781 | - * @throws EE_Error |
|
| 782 | - */ |
|
| 783 | - public function subsection_validation_errors_by_html_name() |
|
| 784 | - { |
|
| 785 | - $inputs = $this->inputs(); |
|
| 786 | - $errors = array(); |
|
| 787 | - foreach ($inputs as $form_input) { |
|
| 788 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 789 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - return $errors; |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 798 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 799 | - * |
|
| 800 | - * @throws InvalidArgumentException |
|
| 801 | - * @throws InvalidInterfaceException |
|
| 802 | - * @throws InvalidDataTypeException |
|
| 803 | - */ |
|
| 804 | - public static function localize_script_for_all_forms() |
|
| 805 | - { |
|
| 806 | - //allow inputs and stuff to hook in their JS and stuff here |
|
| 807 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 808 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 809 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 810 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 811 | - : 'wp_default'; |
|
| 812 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 813 | - wp_enqueue_script('ee_form_section_validation'); |
|
| 814 | - wp_localize_script( |
|
| 815 | - 'ee_form_section_validation', |
|
| 816 | - 'ee_form_section_vars', |
|
| 817 | - EE_Form_Section_Proper::$_js_localization |
|
| 818 | - ); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - /** |
|
| 823 | - * ensure_scripts_localized |
|
| 824 | - * |
|
| 825 | - * @throws EE_Error |
|
| 826 | - */ |
|
| 827 | - public function ensure_scripts_localized() |
|
| 828 | - { |
|
| 829 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 830 | - $this->_enqueue_and_localize_form_js(); |
|
| 831 | - } |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 837 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 838 | - * |
|
| 839 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
| 840 | - */ |
|
| 841 | - private static function _get_localized_error_messages() |
|
| 842 | - { |
|
| 843 | - return array( |
|
| 844 | - 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
| 845 | - 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
| 846 | - ); |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - |
|
| 850 | - /** |
|
| 851 | - * @return array |
|
| 852 | - */ |
|
| 853 | - public static function js_localization() |
|
| 854 | - { |
|
| 855 | - return self::$_js_localization; |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - |
|
| 859 | - /** |
|
| 860 | - * @return void |
|
| 861 | - */ |
|
| 862 | - public static function reset_js_localization() |
|
| 863 | - { |
|
| 864 | - self::$_js_localization = array(); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 870 | - * See parent function for more... |
|
| 871 | - * |
|
| 872 | - * @return array |
|
| 873 | - * @throws EE_Error |
|
| 874 | - */ |
|
| 875 | - public function get_jquery_validation_rules() |
|
| 876 | - { |
|
| 877 | - $jquery_validation_rules = array(); |
|
| 878 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 879 | - $jquery_validation_rules = array_merge( |
|
| 880 | - $jquery_validation_rules, |
|
| 881 | - $subsection->get_jquery_validation_rules() |
|
| 882 | - ); |
|
| 883 | - } |
|
| 884 | - return $jquery_validation_rules; |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - |
|
| 888 | - /** |
|
| 889 | - * Sanitizes all the data and sets the sanitized value of each field |
|
| 890 | - * |
|
| 891 | - * @param array $req_data like $_POST |
|
| 892 | - * @return void |
|
| 893 | - * @throws EE_Error |
|
| 894 | - */ |
|
| 895 | - protected function _normalize($req_data) |
|
| 896 | - { |
|
| 897 | - $this->_received_submission = true; |
|
| 898 | - $this->_validation_errors = array(); |
|
| 899 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 900 | - try { |
|
| 901 | - $subsection->_normalize($req_data); |
|
| 902 | - } catch (EE_Validation_Error $e) { |
|
| 903 | - $subsection->add_validation_error($e); |
|
| 904 | - } |
|
| 905 | - } |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * Performs validation on this form section and its subsections. |
|
| 911 | - * For each subsection, |
|
| 912 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 913 | - * and passes it the subsection, then calls _validate on that subsection. |
|
| 914 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
| 915 | - * you would be best to override this _validate method, |
|
| 916 | - * calling parent::_validate() first. |
|
| 917 | - * |
|
| 918 | - * @throws EE_Error |
|
| 919 | - */ |
|
| 920 | - protected function _validate() |
|
| 921 | - { |
|
| 922 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 923 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 924 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 925 | - } |
|
| 926 | - $subsection->_validate(); |
|
| 927 | - } |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - |
|
| 931 | - /** |
|
| 932 | - * Gets all the validated inputs for the form section |
|
| 933 | - * |
|
| 934 | - * @return array |
|
| 935 | - * @throws EE_Error |
|
| 936 | - */ |
|
| 937 | - public function valid_data() |
|
| 938 | - { |
|
| 939 | - $inputs = array(); |
|
| 940 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 941 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 942 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 943 | - } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
| 944 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 945 | - } |
|
| 946 | - } |
|
| 947 | - return $inputs; |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - |
|
| 951 | - /** |
|
| 952 | - * Gets all the inputs on this form section |
|
| 953 | - * |
|
| 954 | - * @return EE_Form_Input_Base[] |
|
| 955 | - * @throws EE_Error |
|
| 956 | - */ |
|
| 957 | - public function inputs() |
|
| 958 | - { |
|
| 959 | - $inputs = array(); |
|
| 960 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 961 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 962 | - $inputs[ $subsection_name ] = $subsection; |
|
| 963 | - } |
|
| 964 | - } |
|
| 965 | - return $inputs; |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - |
|
| 969 | - /** |
|
| 970 | - * Gets all the subsections which are a proper form |
|
| 971 | - * |
|
| 972 | - * @return EE_Form_Section_Proper[] |
|
| 973 | - * @throws EE_Error |
|
| 974 | - */ |
|
| 975 | - public function subforms() |
|
| 976 | - { |
|
| 977 | - $form_sections = array(); |
|
| 978 | - foreach ($this->subsections() as $name => $obj) { |
|
| 979 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
| 980 | - $form_sections[ $name ] = $obj; |
|
| 981 | - } |
|
| 982 | - } |
|
| 983 | - return $form_sections; |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - |
|
| 987 | - /** |
|
| 988 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 989 | - * Consider using inputs() or subforms() |
|
| 990 | - * if you only want form inputs or proper form sections. |
|
| 991 | - * |
|
| 992 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
| 993 | - * leave this as TRUE so that the inputs will be properly |
|
| 994 | - * configured. However, some client code may be ok with |
|
| 995 | - * construction finalize being called later |
|
| 996 | - * (realizing that the subsections' html names might not be |
|
| 997 | - * set yet, etc.) |
|
| 998 | - * @return EE_Form_Section_Proper[] |
|
| 999 | - * @throws EE_Error |
|
| 1000 | - */ |
|
| 1001 | - public function subsections($require_construction_to_be_finalized = true) |
|
| 1002 | - { |
|
| 1003 | - if ($require_construction_to_be_finalized) { |
|
| 1004 | - $this->ensure_construct_finalized_called(); |
|
| 1005 | - } |
|
| 1006 | - return $this->_subsections; |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - /** |
|
| 1011 | - * Returns a simple array where keys are input names, and values are their normalized |
|
| 1012 | - * values. (Similar to calling get_input_value on inputs) |
|
| 1013 | - * |
|
| 1014 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1015 | - * or just this forms' direct children inputs |
|
| 1016 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1017 | - * or allow multidimensional array |
|
| 1018 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1019 | - * with array keys being input names |
|
| 1020 | - * (regardless of whether they are from a subsection or not), |
|
| 1021 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1022 | - * where keys are always subsection names and values are either |
|
| 1023 | - * the input's normalized value, or an array like the top-level array |
|
| 1024 | - * @throws EE_Error |
|
| 1025 | - */ |
|
| 1026 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 1027 | - { |
|
| 1028 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 1034 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 1035 | - * is not necessarily the value we want to display to users. This creates an array |
|
| 1036 | - * where keys are the input names, and values are their display values |
|
| 1037 | - * |
|
| 1038 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1039 | - * or just this forms' direct children inputs |
|
| 1040 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1041 | - * or allow multidimensional array |
|
| 1042 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1043 | - * with array keys being input names |
|
| 1044 | - * (regardless of whether they are from a subsection or not), |
|
| 1045 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1046 | - * where keys are always subsection names and values are either |
|
| 1047 | - * the input's normalized value, or an array like the top-level array |
|
| 1048 | - * @throws EE_Error |
|
| 1049 | - */ |
|
| 1050 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 1051 | - { |
|
| 1052 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - |
|
| 1056 | - /** |
|
| 1057 | - * Gets the input values from the form |
|
| 1058 | - * |
|
| 1059 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 1060 | - * or just the normalized value |
|
| 1061 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1062 | - * or just this forms' direct children inputs |
|
| 1063 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1064 | - * or allow multidimensional array |
|
| 1065 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 1066 | - * input names (regardless of whether they are from a subsection or not), |
|
| 1067 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1068 | - * where keys are always subsection names and values are either |
|
| 1069 | - * the input's normalized value, or an array like the top-level array |
|
| 1070 | - * @throws EE_Error |
|
| 1071 | - */ |
|
| 1072 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 1073 | - { |
|
| 1074 | - $input_values = array(); |
|
| 1075 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1076 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1077 | - $input_values[ $subsection_name ] = $pretty |
|
| 1078 | - ? $subsection->pretty_value() |
|
| 1079 | - : $subsection->normalized_value(); |
|
| 1080 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1081 | - $subform_input_values = $subsection->_input_values( |
|
| 1082 | - $pretty, |
|
| 1083 | - $include_subform_inputs, |
|
| 1084 | - $flatten |
|
| 1085 | - ); |
|
| 1086 | - if ($flatten) { |
|
| 1087 | - $input_values = array_merge($input_values, $subform_input_values); |
|
| 1088 | - } else { |
|
| 1089 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1090 | - } |
|
| 1091 | - } |
|
| 1092 | - } |
|
| 1093 | - return $input_values; |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - |
|
| 1097 | - /** |
|
| 1098 | - * Gets the originally submitted input values from the form |
|
| 1099 | - * |
|
| 1100 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1101 | - * or just this forms' direct children inputs |
|
| 1102 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1103 | - * with array keys being input names |
|
| 1104 | - * (regardless of whether they are from a subsection or not), |
|
| 1105 | - * and if $flatten is FALSE it can be a multidimensional array |
|
| 1106 | - * where keys are always subsection names and values are either |
|
| 1107 | - * the input's normalized value, or an array like the top-level array |
|
| 1108 | - * @throws EE_Error |
|
| 1109 | - */ |
|
| 1110 | - public function submitted_values($include_subforms = false) |
|
| 1111 | - { |
|
| 1112 | - $submitted_values = array(); |
|
| 1113 | - foreach ($this->subsections() as $subsection) { |
|
| 1114 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1115 | - // is this input part of an array of inputs? |
|
| 1116 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1117 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1118 | - explode( |
|
| 1119 | - '[', |
|
| 1120 | - str_replace(']', '', $subsection->html_name()) |
|
| 1121 | - ), |
|
| 1122 | - $subsection->raw_value() |
|
| 1123 | - ); |
|
| 1124 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1125 | - } else { |
|
| 1126 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1127 | - } |
|
| 1128 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1129 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1130 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1131 | - } |
|
| 1132 | - } |
|
| 1133 | - return $submitted_values; |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - |
|
| 1137 | - /** |
|
| 1138 | - * Indicates whether or not this form has received a submission yet |
|
| 1139 | - * (ie, had receive_form_submission called on it yet) |
|
| 1140 | - * |
|
| 1141 | - * @return boolean |
|
| 1142 | - * @throws EE_Error |
|
| 1143 | - */ |
|
| 1144 | - public function has_received_submission() |
|
| 1145 | - { |
|
| 1146 | - $this->ensure_construct_finalized_called(); |
|
| 1147 | - return $this->_received_submission; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - |
|
| 1151 | - /** |
|
| 1152 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1153 | - * Removes the listed inputs from the form |
|
| 1154 | - * |
|
| 1155 | - * @param array $inputs_to_exclude values are the input names |
|
| 1156 | - * @return void |
|
| 1157 | - */ |
|
| 1158 | - public function exclude(array $inputs_to_exclude = array()) |
|
| 1159 | - { |
|
| 1160 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1161 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1162 | - } |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - |
|
| 1166 | - /** |
|
| 1167 | - * @param array $inputs_to_hide |
|
| 1168 | - * @throws EE_Error |
|
| 1169 | - */ |
|
| 1170 | - public function hide(array $inputs_to_hide = array()) |
|
| 1171 | - { |
|
| 1172 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1173 | - $input = $this->get_input($input_to_hide); |
|
| 1174 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1175 | - } |
|
| 1176 | - } |
|
| 1177 | - |
|
| 1178 | - |
|
| 1179 | - /** |
|
| 1180 | - * add_subsections |
|
| 1181 | - * Adds the listed subsections to the form section. |
|
| 1182 | - * If $subsection_name_to_target is provided, |
|
| 1183 | - * then new subsections are added before or after that subsection, |
|
| 1184 | - * otherwise to the start or end of the entire subsections array. |
|
| 1185 | - * |
|
| 1186 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1187 | - * where keys are their names |
|
| 1188 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1189 | - * should be added before or after |
|
| 1190 | - * IF $subsection_name_to_target is null, |
|
| 1191 | - * then $new_subsections will be added to |
|
| 1192 | - * the beginning or end of the entire subsections array |
|
| 1193 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1194 | - * $subsection_name_to_target, |
|
| 1195 | - * or if $subsection_name_to_target is null, |
|
| 1196 | - * before or after entire subsections array |
|
| 1197 | - * @return void |
|
| 1198 | - * @throws EE_Error |
|
| 1199 | - */ |
|
| 1200 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1201 | - { |
|
| 1202 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1203 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1204 | - EE_Error::add_error( |
|
| 1205 | - sprintf( |
|
| 1206 | - esc_html__( |
|
| 1207 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1208 | - 'event_espresso' |
|
| 1209 | - ), |
|
| 1210 | - get_class($subsection), |
|
| 1211 | - $subsection_name, |
|
| 1212 | - $this->name() |
|
| 1213 | - ) |
|
| 1214 | - ); |
|
| 1215 | - unset($new_subsections[ $subsection_name ]); |
|
| 1216 | - } |
|
| 1217 | - } |
|
| 1218 | - $this->_subsections = EEH_Array::insert_into_array( |
|
| 1219 | - $this->_subsections, |
|
| 1220 | - $new_subsections, |
|
| 1221 | - $subsection_name_to_target, |
|
| 1222 | - $add_before |
|
| 1223 | - ); |
|
| 1224 | - if ($this->_construction_finalized) { |
|
| 1225 | - foreach ($this->_subsections as $name => $subsection) { |
|
| 1226 | - $subsection->_construct_finalize($this, $name); |
|
| 1227 | - } |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - |
|
| 1232 | - /** |
|
| 1233 | - * Just gets all validatable subsections to clean their sensitive data |
|
| 1234 | - * |
|
| 1235 | - * @throws EE_Error |
|
| 1236 | - */ |
|
| 1237 | - public function clean_sensitive_data() |
|
| 1238 | - { |
|
| 1239 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1240 | - $subsection->clean_sensitive_data(); |
|
| 1241 | - } |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - |
|
| 1245 | - /** |
|
| 1246 | - * @param string $form_submission_error_message |
|
| 1247 | - */ |
|
| 1248 | - public function set_submission_error_message($form_submission_error_message = '') |
|
| 1249 | - { |
|
| 1250 | - $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
| 1251 | - ? $form_submission_error_message |
|
| 1252 | - : esc_html__('Form submission failed due to errors', 'event_espresso'); |
|
| 1253 | - } |
|
| 1254 | - |
|
| 1255 | - |
|
| 1256 | - /** |
|
| 1257 | - * @return string |
|
| 1258 | - */ |
|
| 1259 | - public function submission_error_message() |
|
| 1260 | - { |
|
| 1261 | - return $this->_form_submission_error_message; |
|
| 1262 | - } |
|
| 1263 | - |
|
| 1264 | - |
|
| 1265 | - /** |
|
| 1266 | - * @param string $form_submission_success_message |
|
| 1267 | - */ |
|
| 1268 | - public function set_submission_success_message($form_submission_success_message) |
|
| 1269 | - { |
|
| 1270 | - $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
| 1271 | - ? $form_submission_success_message |
|
| 1272 | - : esc_html__('Form submitted successfully', 'event_espresso'); |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * @return string |
|
| 1278 | - */ |
|
| 1279 | - public function submission_success_message() |
|
| 1280 | - { |
|
| 1281 | - return $this->_form_submission_success_message; |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * Returns the prefix that should be used on child of this form section for |
|
| 1287 | - * their html names. If this form section itself has a parent, prepends ITS |
|
| 1288 | - * prefix onto this form section's prefix. Used primarily by |
|
| 1289 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1290 | - * |
|
| 1291 | - * @return string |
|
| 1292 | - * @throws EE_Error |
|
| 1293 | - */ |
|
| 1294 | - public function html_name_prefix() |
|
| 1295 | - { |
|
| 1296 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1297 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1298 | - } |
|
| 1299 | - return $this->name(); |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - |
|
| 1303 | - /** |
|
| 1304 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1305 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1306 | - * was set, which is probably nothing, or the classname) |
|
| 1307 | - * |
|
| 1308 | - * @return string |
|
| 1309 | - * @throws EE_Error |
|
| 1310 | - */ |
|
| 1311 | - public function name() |
|
| 1312 | - { |
|
| 1313 | - $this->ensure_construct_finalized_called(); |
|
| 1314 | - return parent::name(); |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - |
|
| 1318 | - /** |
|
| 1319 | - * @return EE_Form_Section_Proper |
|
| 1320 | - * @throws EE_Error |
|
| 1321 | - */ |
|
| 1322 | - public function parent_section() |
|
| 1323 | - { |
|
| 1324 | - $this->ensure_construct_finalized_called(); |
|
| 1325 | - return parent::parent_section(); |
|
| 1326 | - } |
|
| 1327 | - |
|
| 1328 | - |
|
| 1329 | - /** |
|
| 1330 | - * make sure construction finalized was called, otherwise children might not be ready |
|
| 1331 | - * |
|
| 1332 | - * @return void |
|
| 1333 | - * @throws EE_Error |
|
| 1334 | - */ |
|
| 1335 | - public function ensure_construct_finalized_called() |
|
| 1336 | - { |
|
| 1337 | - if (! $this->_construction_finalized) { |
|
| 1338 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1339 | - } |
|
| 1340 | - } |
|
| 1341 | - |
|
| 1342 | - |
|
| 1343 | - /** |
|
| 1344 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1345 | - * are in teh form data. If any are found, returns true. Else false |
|
| 1346 | - * |
|
| 1347 | - * @param array $req_data |
|
| 1348 | - * @return boolean |
|
| 1349 | - * @throws EE_Error |
|
| 1350 | - */ |
|
| 1351 | - public function form_data_present_in($req_data = null) |
|
| 1352 | - { |
|
| 1353 | - if ($req_data === null) { |
|
| 1354 | - $req_data = $_POST; |
|
| 1355 | - } |
|
| 1356 | - foreach ($this->subsections() as $subsection) { |
|
| 1357 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1358 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1359 | - return true; |
|
| 1360 | - } |
|
| 1361 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1362 | - if ($subsection->form_data_present_in($req_data)) { |
|
| 1363 | - return true; |
|
| 1364 | - } |
|
| 1365 | - } |
|
| 1366 | - } |
|
| 1367 | - return false; |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - |
|
| 1371 | - /** |
|
| 1372 | - * Gets validation errors for this form section and subsections |
|
| 1373 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1374 | - * gets the validation errors for ALL subsection |
|
| 1375 | - * |
|
| 1376 | - * @return EE_Validation_Error[] |
|
| 1377 | - * @throws EE_Error |
|
| 1378 | - */ |
|
| 1379 | - public function get_validation_errors_accumulated() |
|
| 1380 | - { |
|
| 1381 | - $validation_errors = $this->get_validation_errors(); |
|
| 1382 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1383 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1384 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1385 | - } else { |
|
| 1386 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1387 | - } |
|
| 1388 | - if ($validation_errors_on_this_subsection) { |
|
| 1389 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1390 | - } |
|
| 1391 | - } |
|
| 1392 | - return $validation_errors; |
|
| 1393 | - } |
|
| 1394 | - |
|
| 1395 | - |
|
| 1396 | - /** |
|
| 1397 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1398 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1399 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1400 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1401 | - * which will be returned. |
|
| 1402 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1403 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1404 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1405 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1406 | - * Etc |
|
| 1407 | - * |
|
| 1408 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1409 | - * @return EE_Form_Section_Base |
|
| 1410 | - * @throws EE_Error |
|
| 1411 | - */ |
|
| 1412 | - public function find_section_from_path($form_section_path) |
|
| 1413 | - { |
|
| 1414 | - //check if we can find the input from purely going straight up the tree |
|
| 1415 | - $input = parent::find_section_from_path($form_section_path); |
|
| 1416 | - if ($input instanceof EE_Form_Section_Base) { |
|
| 1417 | - return $input; |
|
| 1418 | - } |
|
| 1419 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1420 | - if ($next_slash_pos !== false) { |
|
| 1421 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1422 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1423 | - } else { |
|
| 1424 | - $child_section_name = $form_section_path; |
|
| 1425 | - $subpath = ''; |
|
| 1426 | - } |
|
| 1427 | - $child_section = $this->get_subsection($child_section_name); |
|
| 1428 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1429 | - return $child_section->find_section_from_path($subpath); |
|
| 1430 | - } |
|
| 1431 | - return null; |
|
| 1432 | - } |
|
| 17 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Subsections |
|
| 21 | + * |
|
| 22 | + * @var EE_Form_Section_Validatable[] |
|
| 23 | + */ |
|
| 24 | + protected $_subsections = array(); |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Strategy for laying out the form |
|
| 28 | + * |
|
| 29 | + * @var EE_Form_Section_Layout_Base |
|
| 30 | + */ |
|
| 31 | + protected $_layout_strategy; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Whether or not this form has received and validated a form submission yet |
|
| 35 | + * |
|
| 36 | + * @var boolean |
|
| 37 | + */ |
|
| 38 | + protected $_received_submission = false; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * message displayed to users upon successful form submission |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + protected $_form_submission_success_message = ''; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * message displayed to users upon unsuccessful form submission |
|
| 49 | + * |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + protected $_form_submission_error_message = ''; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Stores all the data that will localized for form validation |
|
| 56 | + * |
|
| 57 | + * @var array |
|
| 58 | + */ |
|
| 59 | + static protected $_js_localization = array(); |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * whether or not the form's localized validation JS vars have been set |
|
| 63 | + * |
|
| 64 | + * @type boolean |
|
| 65 | + */ |
|
| 66 | + static protected $_scripts_localized = false; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * when constructing a proper form section, calls _construct_finalize on children |
|
| 71 | + * so that they know who their parent is, and what name they've been given. |
|
| 72 | + * |
|
| 73 | + * @param array[] $options_array { |
|
| 74 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
| 75 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
| 76 | + * and in that order. This is handy if you want |
|
| 77 | + * the subsections to be ordered differently than the default, and if you override |
|
| 78 | + * which fields are shown |
|
| 79 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
| 80 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
| 81 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
| 82 | + * items from that list of inclusions) |
|
| 83 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
| 84 | + * } @see EE_Form_Section_Validatable::__construct() |
|
| 85 | + * @throws EE_Error |
|
| 86 | + */ |
|
| 87 | + public function __construct($options_array = array()) |
|
| 88 | + { |
|
| 89 | + $options_array = (array) apply_filters( |
|
| 90 | + 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
| 91 | + $options_array, |
|
| 92 | + $this |
|
| 93 | + ); |
|
| 94 | + //call parent first, as it may be setting the name |
|
| 95 | + parent::__construct($options_array); |
|
| 96 | + //if they've included subsections in the constructor, add them now |
|
| 97 | + if (isset($options_array['include'])) { |
|
| 98 | + //we are going to make sure we ONLY have those subsections to include |
|
| 99 | + //AND we are going to make sure they're in that specified order |
|
| 100 | + $reordered_subsections = array(); |
|
| 101 | + foreach ($options_array['include'] as $input_name) { |
|
| 102 | + if (isset($this->_subsections[ $input_name ])) { |
|
| 103 | + $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + $this->_subsections = $reordered_subsections; |
|
| 107 | + } |
|
| 108 | + if (isset($options_array['exclude'])) { |
|
| 109 | + $exclude = $options_array['exclude']; |
|
| 110 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
| 111 | + } |
|
| 112 | + if (isset($options_array['layout_strategy'])) { |
|
| 113 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
| 114 | + } |
|
| 115 | + if (! $this->_layout_strategy) { |
|
| 116 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
| 117 | + } |
|
| 118 | + $this->_layout_strategy->_construct_finalize($this); |
|
| 119 | + //ok so we are definitely going to want the forms JS, |
|
| 120 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
| 121 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 122 | + //ok so they've constructed this object after when they should have. |
|
| 123 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
| 124 | + EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
| 125 | + } else { |
|
| 126 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 127 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
| 128 | + } |
|
| 129 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
| 130 | + /** |
|
| 131 | + * Gives other plugins a chance to hook in before construct finalize is called. |
|
| 132 | + * The form probably doesn't yet have a parent form section. |
|
| 133 | + * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
| 134 | + * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
| 135 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
| 136 | + * |
|
| 137 | + * @since 4.9.32 |
|
| 138 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
| 139 | + * except maybe calling _construct_finalize has been done |
|
| 140 | + * @param array $options_array options passed into the constructor |
|
| 141 | + */ |
|
| 142 | + do_action( |
|
| 143 | + 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
| 144 | + $this, |
|
| 145 | + $options_array |
|
| 146 | + ); |
|
| 147 | + if (isset($options_array['name'])) { |
|
| 148 | + $this->_construct_finalize(null, $options_array['name']); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Finishes construction given the parent form section and this form section's name |
|
| 155 | + * |
|
| 156 | + * @param EE_Form_Section_Proper $parent_form_section |
|
| 157 | + * @param string $name |
|
| 158 | + * @throws EE_Error |
|
| 159 | + */ |
|
| 160 | + public function _construct_finalize($parent_form_section, $name) |
|
| 161 | + { |
|
| 162 | + parent::_construct_finalize($parent_form_section, $name); |
|
| 163 | + $this->_set_default_name_if_empty(); |
|
| 164 | + $this->_set_default_html_id_if_empty(); |
|
| 165 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
| 166 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
| 167 | + $subsection->_construct_finalize($this, $subsection_name); |
|
| 168 | + } else { |
|
| 169 | + throw new EE_Error( |
|
| 170 | + sprintf( |
|
| 171 | + esc_html__( |
|
| 172 | + 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
| 173 | + 'event_espresso' |
|
| 174 | + ), |
|
| 175 | + $subsection_name, |
|
| 176 | + get_class($this), |
|
| 177 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 178 | + ) |
|
| 179 | + ); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + /** |
|
| 183 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
| 184 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
| 185 | + * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
| 186 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
| 187 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
| 188 | + * ensured it has a name, HTML IDs, etc |
|
| 189 | + * |
|
| 190 | + * @param EE_Form_Section_Proper $this |
|
| 191 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
| 192 | + * @param string $name |
|
| 193 | + */ |
|
| 194 | + do_action( |
|
| 195 | + 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
| 196 | + $this, |
|
| 197 | + $parent_form_section, |
|
| 198 | + $name |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Gets the layout strategy for this form section |
|
| 205 | + * |
|
| 206 | + * @return EE_Form_Section_Layout_Base |
|
| 207 | + */ |
|
| 208 | + public function get_layout_strategy() |
|
| 209 | + { |
|
| 210 | + return $this->_layout_strategy; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Gets the HTML for a single input for this form section according |
|
| 216 | + * to the layout strategy |
|
| 217 | + * |
|
| 218 | + * @param EE_Form_Input_Base $input |
|
| 219 | + * @return string |
|
| 220 | + */ |
|
| 221 | + public function get_html_for_input($input) |
|
| 222 | + { |
|
| 223 | + return $this->_layout_strategy->layout_input($input); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * was_submitted - checks if form inputs are present in request data |
|
| 229 | + * Basically an alias for form_data_present_in() (which is used by both |
|
| 230 | + * proper form sections and form inputs) |
|
| 231 | + * |
|
| 232 | + * @param null $form_data |
|
| 233 | + * @return boolean |
|
| 234 | + * @throws EE_Error |
|
| 235 | + */ |
|
| 236 | + public function was_submitted($form_data = null) |
|
| 237 | + { |
|
| 238 | + return $this->form_data_present_in($form_data); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
| 244 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
| 245 | + * |
|
| 246 | + * @param array|null $req_data should usually be $_POST (the default). |
|
| 247 | + * However, you CAN supply a different array. |
|
| 248 | + * Consider using set_defaults() instead however. |
|
| 249 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
| 250 | + * the inputs will have the correct name in the request data for this function |
|
| 251 | + * to find them and populate the form with them. |
|
| 252 | + * If you have a flat form (with only input subsections), |
|
| 253 | + * you can supply a flat array where keys |
|
| 254 | + * are the form input names and values are their values) |
|
| 255 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
| 256 | + * of course, to validate that data, and set errors on the invalid values. |
|
| 257 | + * But if the data has already been validated |
|
| 258 | + * (eg you validated the data then stored it in the DB) |
|
| 259 | + * you may want to skip this step. |
|
| 260 | + * @throws InvalidArgumentException |
|
| 261 | + * @throws InvalidInterfaceException |
|
| 262 | + * @throws InvalidDataTypeException |
|
| 263 | + * @throws EE_Error |
|
| 264 | + */ |
|
| 265 | + public function receive_form_submission($req_data = null, $validate = true) |
|
| 266 | + { |
|
| 267 | + $req_data = apply_filters( |
|
| 268 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
| 269 | + $req_data, |
|
| 270 | + $this, |
|
| 271 | + $validate |
|
| 272 | + ); |
|
| 273 | + if ($req_data === null) { |
|
| 274 | + $req_data = array_merge($_GET, $_POST); |
|
| 275 | + } |
|
| 276 | + $req_data = apply_filters( |
|
| 277 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 278 | + $req_data, |
|
| 279 | + $this |
|
| 280 | + ); |
|
| 281 | + $this->_normalize($req_data); |
|
| 282 | + if ($validate) { |
|
| 283 | + $this->_validate(); |
|
| 284 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
| 285 | + if (! $this->is_valid()) { |
|
| 286 | + $this->store_submitted_form_data_in_session(); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + do_action( |
|
| 290 | + 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
| 291 | + $req_data, |
|
| 292 | + $this, |
|
| 293 | + $validate |
|
| 294 | + ); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * caches the originally submitted input values in the session |
|
| 300 | + * so that they can be used to repopulate the form if it failed validation |
|
| 301 | + * |
|
| 302 | + * @return boolean whether or not the data was successfully stored in the session |
|
| 303 | + * @throws InvalidArgumentException |
|
| 304 | + * @throws InvalidInterfaceException |
|
| 305 | + * @throws InvalidDataTypeException |
|
| 306 | + * @throws EE_Error |
|
| 307 | + */ |
|
| 308 | + protected function store_submitted_form_data_in_session() |
|
| 309 | + { |
|
| 310 | + return EE_Registry::instance()->SSN->set_session_data( |
|
| 311 | + array( |
|
| 312 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
| 313 | + ) |
|
| 314 | + ); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * retrieves the originally submitted input values in the session |
|
| 320 | + * so that they can be used to repopulate the form if it failed validation |
|
| 321 | + * |
|
| 322 | + * @return array |
|
| 323 | + * @throws InvalidArgumentException |
|
| 324 | + * @throws InvalidInterfaceException |
|
| 325 | + * @throws InvalidDataTypeException |
|
| 326 | + */ |
|
| 327 | + protected function get_submitted_form_data_from_session() |
|
| 328 | + { |
|
| 329 | + $session = EE_Registry::instance()->SSN; |
|
| 330 | + if ($session instanceof EE_Session) { |
|
| 331 | + return $session->get_session_data( |
|
| 332 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
| 333 | + ); |
|
| 334 | + } |
|
| 335 | + return array(); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * flushed the originally submitted input values from the session |
|
| 341 | + * |
|
| 342 | + * @return boolean whether or not the data was successfully removed from the session |
|
| 343 | + * @throws InvalidArgumentException |
|
| 344 | + * @throws InvalidInterfaceException |
|
| 345 | + * @throws InvalidDataTypeException |
|
| 346 | + */ |
|
| 347 | + protected function flush_submitted_form_data_from_session() |
|
| 348 | + { |
|
| 349 | + return EE_Registry::instance()->SSN->reset_data( |
|
| 350 | + array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
| 351 | + ); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Populates this form and its subsections with data from the session. |
|
| 357 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
| 358 | + * validation errors when displaying too) |
|
| 359 | + * Returns true if the form was populated from the session, false otherwise |
|
| 360 | + * |
|
| 361 | + * @return boolean |
|
| 362 | + * @throws InvalidArgumentException |
|
| 363 | + * @throws InvalidInterfaceException |
|
| 364 | + * @throws InvalidDataTypeException |
|
| 365 | + * @throws EE_Error |
|
| 366 | + */ |
|
| 367 | + public function populate_from_session() |
|
| 368 | + { |
|
| 369 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
| 370 | + if (empty($form_data_in_session)) { |
|
| 371 | + return false; |
|
| 372 | + } |
|
| 373 | + $this->receive_form_submission($form_data_in_session); |
|
| 374 | + $this->flush_submitted_form_data_from_session(); |
|
| 375 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
| 376 | + return true; |
|
| 377 | + } |
|
| 378 | + return false; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Populates the default data for the form, given an array where keys are |
|
| 384 | + * the input names, and values are their values (preferably normalized to be their |
|
| 385 | + * proper PHP types, not all strings... although that should be ok too). |
|
| 386 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
| 387 | + * the value being an array formatted in teh same way |
|
| 388 | + * |
|
| 389 | + * @param array $default_data |
|
| 390 | + * @throws EE_Error |
|
| 391 | + */ |
|
| 392 | + public function populate_defaults($default_data) |
|
| 393 | + { |
|
| 394 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
| 395 | + if (isset($default_data[ $subsection_name ])) { |
|
| 396 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 397 | + $subsection->set_default($default_data[ $subsection_name ]); |
|
| 398 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 399 | + $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * returns true if subsection exists |
|
| 408 | + * |
|
| 409 | + * @param string $name |
|
| 410 | + * @return boolean |
|
| 411 | + */ |
|
| 412 | + public function subsection_exists($name) |
|
| 413 | + { |
|
| 414 | + return isset($this->_subsections[ $name ]) ? true : false; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * Gets the subsection specified by its name |
|
| 420 | + * |
|
| 421 | + * @param string $name |
|
| 422 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
| 423 | + * so that the inputs will be properly configured. |
|
| 424 | + * However, some client code may be ok |
|
| 425 | + * with construction finalize being called later |
|
| 426 | + * (realizing that the subsections' html names |
|
| 427 | + * might not be set yet, etc.) |
|
| 428 | + * @return EE_Form_Section_Base |
|
| 429 | + * @throws EE_Error |
|
| 430 | + */ |
|
| 431 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
| 432 | + { |
|
| 433 | + if ($require_construction_to_be_finalized) { |
|
| 434 | + $this->ensure_construct_finalized_called(); |
|
| 435 | + } |
|
| 436 | + return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Gets all the validatable subsections of this form section |
|
| 442 | + * |
|
| 443 | + * @return EE_Form_Section_Validatable[] |
|
| 444 | + * @throws EE_Error |
|
| 445 | + */ |
|
| 446 | + public function get_validatable_subsections() |
|
| 447 | + { |
|
| 448 | + $validatable_subsections = array(); |
|
| 449 | + foreach ($this->subsections() as $name => $obj) { |
|
| 450 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
| 451 | + $validatable_subsections[ $name ] = $obj; |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + return $validatable_subsections; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
| 460 | + * throw an EE_Error. |
|
| 461 | + * |
|
| 462 | + * @param string $name |
|
| 463 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 464 | + * leave this as TRUE so that the inputs will be properly |
|
| 465 | + * configured. However, some client code may be ok with |
|
| 466 | + * construction finalize being called later |
|
| 467 | + * (realizing that the subsections' html names might not be |
|
| 468 | + * set yet, etc.) |
|
| 469 | + * @return EE_Form_Input_Base |
|
| 470 | + * @throws EE_Error |
|
| 471 | + */ |
|
| 472 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
| 473 | + { |
|
| 474 | + $subsection = $this->get_subsection( |
|
| 475 | + $name, |
|
| 476 | + $require_construction_to_be_finalized |
|
| 477 | + ); |
|
| 478 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 479 | + throw new EE_Error( |
|
| 480 | + sprintf( |
|
| 481 | + esc_html__( |
|
| 482 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
| 483 | + 'event_espresso' |
|
| 484 | + ), |
|
| 485 | + $name, |
|
| 486 | + get_class($this), |
|
| 487 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
| 488 | + ) |
|
| 489 | + ); |
|
| 490 | + } |
|
| 491 | + return $subsection; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
| 497 | + * otherwise throws an EE_Error |
|
| 498 | + * |
|
| 499 | + * @param string $name |
|
| 500 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 501 | + * leave this as TRUE so that the inputs will be properly |
|
| 502 | + * configured. However, some client code may be ok with |
|
| 503 | + * construction finalize being called later |
|
| 504 | + * (realizing that the subsections' html names might not be |
|
| 505 | + * set yet, etc.) |
|
| 506 | + * @return EE_Form_Section_Proper |
|
| 507 | + * @throws EE_Error |
|
| 508 | + */ |
|
| 509 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
| 510 | + { |
|
| 511 | + $subsection = $this->get_subsection( |
|
| 512 | + $name, |
|
| 513 | + $require_construction_to_be_finalized |
|
| 514 | + ); |
|
| 515 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 516 | + throw new EE_Error( |
|
| 517 | + sprintf( |
|
| 518 | + esc_html__( |
|
| 519 | + "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
| 520 | + 'event_espresso' |
|
| 521 | + ), |
|
| 522 | + $name, |
|
| 523 | + get_class($this) |
|
| 524 | + ) |
|
| 525 | + ); |
|
| 526 | + } |
|
| 527 | + return $subsection; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
| 533 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
| 534 | + * |
|
| 535 | + * @param string $name |
|
| 536 | + * @return mixed depending on the input's type and its normalization strategy |
|
| 537 | + * @throws EE_Error |
|
| 538 | + */ |
|
| 539 | + public function get_input_value($name) |
|
| 540 | + { |
|
| 541 | + $input = $this->get_input($name); |
|
| 542 | + return $input->normalized_value(); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Checks if this form section itself is valid, and then checks its subsections |
|
| 548 | + * |
|
| 549 | + * @throws EE_Error |
|
| 550 | + * @return boolean |
|
| 551 | + */ |
|
| 552 | + public function is_valid() |
|
| 553 | + { |
|
| 554 | + if (! $this->has_received_submission()) { |
|
| 555 | + throw new EE_Error( |
|
| 556 | + sprintf( |
|
| 557 | + esc_html__( |
|
| 558 | + 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
| 559 | + 'event_espresso' |
|
| 560 | + ) |
|
| 561 | + ) |
|
| 562 | + ); |
|
| 563 | + } |
|
| 564 | + if (! parent::is_valid()) { |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + // ok so no general errors to this entire form section. |
|
| 568 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
| 569 | + $set_submission_errors = $this->submission_error_message() === ''; |
|
| 570 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 571 | + if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 572 | + if ($set_submission_errors) { |
|
| 573 | + $this->set_submission_error_message( |
|
| 574 | + $subsection->get_validation_error_string() |
|
| 575 | + ); |
|
| 576 | + } |
|
| 577 | + return false; |
|
| 578 | + } |
|
| 579 | + } |
|
| 580 | + return true; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * gets the default name of this form section if none is specified |
|
| 586 | + * |
|
| 587 | + * @return void |
|
| 588 | + */ |
|
| 589 | + protected function _set_default_name_if_empty() |
|
| 590 | + { |
|
| 591 | + if (! $this->_name) { |
|
| 592 | + $classname = get_class($this); |
|
| 593 | + $default_name = str_replace('EE_', '', $classname); |
|
| 594 | + $this->_name = $default_name; |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
| 601 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
| 602 | + * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
| 603 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
| 604 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
| 605 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
| 606 | + * any CSS. |
|
| 607 | + * |
|
| 608 | + * @throws InvalidArgumentException |
|
| 609 | + * @throws InvalidInterfaceException |
|
| 610 | + * @throws InvalidDataTypeException |
|
| 611 | + * @throws EE_Error |
|
| 612 | + */ |
|
| 613 | + public function get_html_and_js() |
|
| 614 | + { |
|
| 615 | + $this->enqueue_js(); |
|
| 616 | + return $this->get_html(); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
| 622 | + * |
|
| 623 | + * @param bool $display_previously_submitted_data |
|
| 624 | + * @return string |
|
| 625 | + * @throws InvalidArgumentException |
|
| 626 | + * @throws InvalidInterfaceException |
|
| 627 | + * @throws InvalidDataTypeException |
|
| 628 | + * @throws EE_Error |
|
| 629 | + * @throws EE_Error |
|
| 630 | + * @throws EE_Error |
|
| 631 | + */ |
|
| 632 | + public function get_html($display_previously_submitted_data = true) |
|
| 633 | + { |
|
| 634 | + $this->ensure_construct_finalized_called(); |
|
| 635 | + if ($display_previously_submitted_data) { |
|
| 636 | + $this->populate_from_session(); |
|
| 637 | + } |
|
| 638 | + return $this->_form_html_filter |
|
| 639 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
| 640 | + : $this->_layout_strategy->layout_form(); |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * enqueues JS and CSS for the form. |
|
| 646 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
| 647 | + * scripts and styles can be put in the header, but if called later |
|
| 648 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
| 649 | + * only be in the header; but in HTML5 its ok in the body. |
|
| 650 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
| 651 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
| 652 | + * |
|
| 653 | + * @return void |
|
| 654 | + * @throws EE_Error |
|
| 655 | + */ |
|
| 656 | + public function enqueue_js() |
|
| 657 | + { |
|
| 658 | + $this->_enqueue_and_localize_form_js(); |
|
| 659 | + foreach ($this->subsections() as $subsection) { |
|
| 660 | + $subsection->enqueue_js(); |
|
| 661 | + } |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + |
|
| 665 | + /** |
|
| 666 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
| 667 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
| 668 | + * the wp_enqueue_scripts hook. |
|
| 669 | + * However, registering the form js and localizing it can happen when we |
|
| 670 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
| 671 | + * could change until it's actually outputted) |
|
| 672 | + * |
|
| 673 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
| 674 | + * to be triggered automatically or not |
|
| 675 | + * @return void |
|
| 676 | + */ |
|
| 677 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
| 678 | + { |
|
| 679 | + wp_register_script( |
|
| 680 | + 'ee_form_section_validation', |
|
| 681 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 682 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
| 683 | + EVENT_ESPRESSO_VERSION, |
|
| 684 | + true |
|
| 685 | + ); |
|
| 686 | + wp_localize_script( |
|
| 687 | + 'ee_form_section_validation', |
|
| 688 | + 'ee_form_section_validation_init', |
|
| 689 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
| 690 | + ); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * gets the variables used by form_section_validation.js. |
|
| 696 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
| 697 | + * but before the wordpress hook wp_loaded |
|
| 698 | + * |
|
| 699 | + * @throws EE_Error |
|
| 700 | + */ |
|
| 701 | + public function _enqueue_and_localize_form_js() |
|
| 702 | + { |
|
| 703 | + $this->ensure_construct_finalized_called(); |
|
| 704 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
| 705 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
| 706 | + //and localize it just before the footer |
|
| 707 | + $this->localize_validation_rules(); |
|
| 708 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
| 709 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * add our form section data to a static variable accessible by all form sections |
|
| 715 | + * |
|
| 716 | + * @param bool $return_for_subsection |
|
| 717 | + * @return void |
|
| 718 | + * @throws EE_Error |
|
| 719 | + */ |
|
| 720 | + public function localize_validation_rules($return_for_subsection = false) |
|
| 721 | + { |
|
| 722 | + // we only want to localize vars ONCE for the entire form, |
|
| 723 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
| 724 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
| 725 | + EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 726 | + 'form_section_id' => $this->html_id(true), |
|
| 727 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
| 728 | + 'other_data' => $this->get_other_js_data(), |
|
| 729 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
| 730 | + ); |
|
| 731 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 732 | + } |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + |
|
| 736 | + /** |
|
| 737 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
| 738 | + * This is primarily data added by inputs and forms in addition to any |
|
| 739 | + * scripts they might enqueue |
|
| 740 | + * |
|
| 741 | + * @param array $form_other_js_data |
|
| 742 | + * @return array |
|
| 743 | + * @throws EE_Error |
|
| 744 | + */ |
|
| 745 | + public function get_other_js_data($form_other_js_data = array()) |
|
| 746 | + { |
|
| 747 | + foreach ($this->subsections() as $subsection) { |
|
| 748 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
| 749 | + } |
|
| 750 | + return $form_other_js_data; |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + /** |
|
| 755 | + * Gets a flat array of inputs for this form section and its subsections. |
|
| 756 | + * Keys are their form names, and values are the inputs themselves |
|
| 757 | + * |
|
| 758 | + * @return EE_Form_Input_Base |
|
| 759 | + * @throws EE_Error |
|
| 760 | + */ |
|
| 761 | + public function inputs_in_subsections() |
|
| 762 | + { |
|
| 763 | + $inputs = array(); |
|
| 764 | + foreach ($this->subsections() as $subsection) { |
|
| 765 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 766 | + $inputs[ $subsection->html_name() ] = $subsection; |
|
| 767 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 768 | + $inputs += $subsection->inputs_in_subsections(); |
|
| 769 | + } |
|
| 770 | + } |
|
| 771 | + return $inputs; |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + |
|
| 775 | + /** |
|
| 776 | + * Gets a flat array of all the validation errors. |
|
| 777 | + * Keys are html names (because those should be unique) |
|
| 778 | + * and values are a string of all their validation errors |
|
| 779 | + * |
|
| 780 | + * @return string[] |
|
| 781 | + * @throws EE_Error |
|
| 782 | + */ |
|
| 783 | + public function subsection_validation_errors_by_html_name() |
|
| 784 | + { |
|
| 785 | + $inputs = $this->inputs(); |
|
| 786 | + $errors = array(); |
|
| 787 | + foreach ($inputs as $form_input) { |
|
| 788 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
| 789 | + $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + return $errors; |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
| 798 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
| 799 | + * |
|
| 800 | + * @throws InvalidArgumentException |
|
| 801 | + * @throws InvalidInterfaceException |
|
| 802 | + * @throws InvalidDataTypeException |
|
| 803 | + */ |
|
| 804 | + public static function localize_script_for_all_forms() |
|
| 805 | + { |
|
| 806 | + //allow inputs and stuff to hook in their JS and stuff here |
|
| 807 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
| 808 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
| 809 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
| 810 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
| 811 | + : 'wp_default'; |
|
| 812 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 813 | + wp_enqueue_script('ee_form_section_validation'); |
|
| 814 | + wp_localize_script( |
|
| 815 | + 'ee_form_section_validation', |
|
| 816 | + 'ee_form_section_vars', |
|
| 817 | + EE_Form_Section_Proper::$_js_localization |
|
| 818 | + ); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + /** |
|
| 823 | + * ensure_scripts_localized |
|
| 824 | + * |
|
| 825 | + * @throws EE_Error |
|
| 826 | + */ |
|
| 827 | + public function ensure_scripts_localized() |
|
| 828 | + { |
|
| 829 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 830 | + $this->_enqueue_and_localize_form_js(); |
|
| 831 | + } |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
| 837 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
| 838 | + * |
|
| 839 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
| 840 | + */ |
|
| 841 | + private static function _get_localized_error_messages() |
|
| 842 | + { |
|
| 843 | + return array( |
|
| 844 | + 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
| 845 | + 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
| 846 | + ); |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + |
|
| 850 | + /** |
|
| 851 | + * @return array |
|
| 852 | + */ |
|
| 853 | + public static function js_localization() |
|
| 854 | + { |
|
| 855 | + return self::$_js_localization; |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + |
|
| 859 | + /** |
|
| 860 | + * @return void |
|
| 861 | + */ |
|
| 862 | + public static function reset_js_localization() |
|
| 863 | + { |
|
| 864 | + self::$_js_localization = array(); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
| 870 | + * See parent function for more... |
|
| 871 | + * |
|
| 872 | + * @return array |
|
| 873 | + * @throws EE_Error |
|
| 874 | + */ |
|
| 875 | + public function get_jquery_validation_rules() |
|
| 876 | + { |
|
| 877 | + $jquery_validation_rules = array(); |
|
| 878 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 879 | + $jquery_validation_rules = array_merge( |
|
| 880 | + $jquery_validation_rules, |
|
| 881 | + $subsection->get_jquery_validation_rules() |
|
| 882 | + ); |
|
| 883 | + } |
|
| 884 | + return $jquery_validation_rules; |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + |
|
| 888 | + /** |
|
| 889 | + * Sanitizes all the data and sets the sanitized value of each field |
|
| 890 | + * |
|
| 891 | + * @param array $req_data like $_POST |
|
| 892 | + * @return void |
|
| 893 | + * @throws EE_Error |
|
| 894 | + */ |
|
| 895 | + protected function _normalize($req_data) |
|
| 896 | + { |
|
| 897 | + $this->_received_submission = true; |
|
| 898 | + $this->_validation_errors = array(); |
|
| 899 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 900 | + try { |
|
| 901 | + $subsection->_normalize($req_data); |
|
| 902 | + } catch (EE_Validation_Error $e) { |
|
| 903 | + $subsection->add_validation_error($e); |
|
| 904 | + } |
|
| 905 | + } |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * Performs validation on this form section and its subsections. |
|
| 911 | + * For each subsection, |
|
| 912 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
| 913 | + * and passes it the subsection, then calls _validate on that subsection. |
|
| 914 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
| 915 | + * you would be best to override this _validate method, |
|
| 916 | + * calling parent::_validate() first. |
|
| 917 | + * |
|
| 918 | + * @throws EE_Error |
|
| 919 | + */ |
|
| 920 | + protected function _validate() |
|
| 921 | + { |
|
| 922 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
| 923 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 924 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 925 | + } |
|
| 926 | + $subsection->_validate(); |
|
| 927 | + } |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + |
|
| 931 | + /** |
|
| 932 | + * Gets all the validated inputs for the form section |
|
| 933 | + * |
|
| 934 | + * @return array |
|
| 935 | + * @throws EE_Error |
|
| 936 | + */ |
|
| 937 | + public function valid_data() |
|
| 938 | + { |
|
| 939 | + $inputs = array(); |
|
| 940 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 941 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 942 | + $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 943 | + } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
| 944 | + $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + return $inputs; |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + |
|
| 951 | + /** |
|
| 952 | + * Gets all the inputs on this form section |
|
| 953 | + * |
|
| 954 | + * @return EE_Form_Input_Base[] |
|
| 955 | + * @throws EE_Error |
|
| 956 | + */ |
|
| 957 | + public function inputs() |
|
| 958 | + { |
|
| 959 | + $inputs = array(); |
|
| 960 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 961 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 962 | + $inputs[ $subsection_name ] = $subsection; |
|
| 963 | + } |
|
| 964 | + } |
|
| 965 | + return $inputs; |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + |
|
| 969 | + /** |
|
| 970 | + * Gets all the subsections which are a proper form |
|
| 971 | + * |
|
| 972 | + * @return EE_Form_Section_Proper[] |
|
| 973 | + * @throws EE_Error |
|
| 974 | + */ |
|
| 975 | + public function subforms() |
|
| 976 | + { |
|
| 977 | + $form_sections = array(); |
|
| 978 | + foreach ($this->subsections() as $name => $obj) { |
|
| 979 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
| 980 | + $form_sections[ $name ] = $obj; |
|
| 981 | + } |
|
| 982 | + } |
|
| 983 | + return $form_sections; |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + |
|
| 987 | + /** |
|
| 988 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
| 989 | + * Consider using inputs() or subforms() |
|
| 990 | + * if you only want form inputs or proper form sections. |
|
| 991 | + * |
|
| 992 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
| 993 | + * leave this as TRUE so that the inputs will be properly |
|
| 994 | + * configured. However, some client code may be ok with |
|
| 995 | + * construction finalize being called later |
|
| 996 | + * (realizing that the subsections' html names might not be |
|
| 997 | + * set yet, etc.) |
|
| 998 | + * @return EE_Form_Section_Proper[] |
|
| 999 | + * @throws EE_Error |
|
| 1000 | + */ |
|
| 1001 | + public function subsections($require_construction_to_be_finalized = true) |
|
| 1002 | + { |
|
| 1003 | + if ($require_construction_to_be_finalized) { |
|
| 1004 | + $this->ensure_construct_finalized_called(); |
|
| 1005 | + } |
|
| 1006 | + return $this->_subsections; |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + /** |
|
| 1011 | + * Returns a simple array where keys are input names, and values are their normalized |
|
| 1012 | + * values. (Similar to calling get_input_value on inputs) |
|
| 1013 | + * |
|
| 1014 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1015 | + * or just this forms' direct children inputs |
|
| 1016 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1017 | + * or allow multidimensional array |
|
| 1018 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1019 | + * with array keys being input names |
|
| 1020 | + * (regardless of whether they are from a subsection or not), |
|
| 1021 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1022 | + * where keys are always subsection names and values are either |
|
| 1023 | + * the input's normalized value, or an array like the top-level array |
|
| 1024 | + * @throws EE_Error |
|
| 1025 | + */ |
|
| 1026 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
| 1027 | + { |
|
| 1028 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + |
|
| 1032 | + /** |
|
| 1033 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
| 1034 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
| 1035 | + * is not necessarily the value we want to display to users. This creates an array |
|
| 1036 | + * where keys are the input names, and values are their display values |
|
| 1037 | + * |
|
| 1038 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1039 | + * or just this forms' direct children inputs |
|
| 1040 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1041 | + * or allow multidimensional array |
|
| 1042 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1043 | + * with array keys being input names |
|
| 1044 | + * (regardless of whether they are from a subsection or not), |
|
| 1045 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1046 | + * where keys are always subsection names and values are either |
|
| 1047 | + * the input's normalized value, or an array like the top-level array |
|
| 1048 | + * @throws EE_Error |
|
| 1049 | + */ |
|
| 1050 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
| 1051 | + { |
|
| 1052 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + |
|
| 1056 | + /** |
|
| 1057 | + * Gets the input values from the form |
|
| 1058 | + * |
|
| 1059 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
| 1060 | + * or just the normalized value |
|
| 1061 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
| 1062 | + * or just this forms' direct children inputs |
|
| 1063 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
| 1064 | + * or allow multidimensional array |
|
| 1065 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
| 1066 | + * input names (regardless of whether they are from a subsection or not), |
|
| 1067 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1068 | + * where keys are always subsection names and values are either |
|
| 1069 | + * the input's normalized value, or an array like the top-level array |
|
| 1070 | + * @throws EE_Error |
|
| 1071 | + */ |
|
| 1072 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
| 1073 | + { |
|
| 1074 | + $input_values = array(); |
|
| 1075 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
| 1076 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1077 | + $input_values[ $subsection_name ] = $pretty |
|
| 1078 | + ? $subsection->pretty_value() |
|
| 1079 | + : $subsection->normalized_value(); |
|
| 1080 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
| 1081 | + $subform_input_values = $subsection->_input_values( |
|
| 1082 | + $pretty, |
|
| 1083 | + $include_subform_inputs, |
|
| 1084 | + $flatten |
|
| 1085 | + ); |
|
| 1086 | + if ($flatten) { |
|
| 1087 | + $input_values = array_merge($input_values, $subform_input_values); |
|
| 1088 | + } else { |
|
| 1089 | + $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1090 | + } |
|
| 1091 | + } |
|
| 1092 | + } |
|
| 1093 | + return $input_values; |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + |
|
| 1097 | + /** |
|
| 1098 | + * Gets the originally submitted input values from the form |
|
| 1099 | + * |
|
| 1100 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
| 1101 | + * or just this forms' direct children inputs |
|
| 1102 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
| 1103 | + * with array keys being input names |
|
| 1104 | + * (regardless of whether they are from a subsection or not), |
|
| 1105 | + * and if $flatten is FALSE it can be a multidimensional array |
|
| 1106 | + * where keys are always subsection names and values are either |
|
| 1107 | + * the input's normalized value, or an array like the top-level array |
|
| 1108 | + * @throws EE_Error |
|
| 1109 | + */ |
|
| 1110 | + public function submitted_values($include_subforms = false) |
|
| 1111 | + { |
|
| 1112 | + $submitted_values = array(); |
|
| 1113 | + foreach ($this->subsections() as $subsection) { |
|
| 1114 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1115 | + // is this input part of an array of inputs? |
|
| 1116 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
| 1117 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1118 | + explode( |
|
| 1119 | + '[', |
|
| 1120 | + str_replace(']', '', $subsection->html_name()) |
|
| 1121 | + ), |
|
| 1122 | + $subsection->raw_value() |
|
| 1123 | + ); |
|
| 1124 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
| 1125 | + } else { |
|
| 1126 | + $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1127 | + } |
|
| 1128 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
| 1129 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
| 1130 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
| 1131 | + } |
|
| 1132 | + } |
|
| 1133 | + return $submitted_values; |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + |
|
| 1137 | + /** |
|
| 1138 | + * Indicates whether or not this form has received a submission yet |
|
| 1139 | + * (ie, had receive_form_submission called on it yet) |
|
| 1140 | + * |
|
| 1141 | + * @return boolean |
|
| 1142 | + * @throws EE_Error |
|
| 1143 | + */ |
|
| 1144 | + public function has_received_submission() |
|
| 1145 | + { |
|
| 1146 | + $this->ensure_construct_finalized_called(); |
|
| 1147 | + return $this->_received_submission; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + |
|
| 1151 | + /** |
|
| 1152 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
| 1153 | + * Removes the listed inputs from the form |
|
| 1154 | + * |
|
| 1155 | + * @param array $inputs_to_exclude values are the input names |
|
| 1156 | + * @return void |
|
| 1157 | + */ |
|
| 1158 | + public function exclude(array $inputs_to_exclude = array()) |
|
| 1159 | + { |
|
| 1160 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
| 1161 | + unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1162 | + } |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + |
|
| 1166 | + /** |
|
| 1167 | + * @param array $inputs_to_hide |
|
| 1168 | + * @throws EE_Error |
|
| 1169 | + */ |
|
| 1170 | + public function hide(array $inputs_to_hide = array()) |
|
| 1171 | + { |
|
| 1172 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
| 1173 | + $input = $this->get_input($input_to_hide); |
|
| 1174 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
| 1175 | + } |
|
| 1176 | + } |
|
| 1177 | + |
|
| 1178 | + |
|
| 1179 | + /** |
|
| 1180 | + * add_subsections |
|
| 1181 | + * Adds the listed subsections to the form section. |
|
| 1182 | + * If $subsection_name_to_target is provided, |
|
| 1183 | + * then new subsections are added before or after that subsection, |
|
| 1184 | + * otherwise to the start or end of the entire subsections array. |
|
| 1185 | + * |
|
| 1186 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
| 1187 | + * where keys are their names |
|
| 1188 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
| 1189 | + * should be added before or after |
|
| 1190 | + * IF $subsection_name_to_target is null, |
|
| 1191 | + * then $new_subsections will be added to |
|
| 1192 | + * the beginning or end of the entire subsections array |
|
| 1193 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
| 1194 | + * $subsection_name_to_target, |
|
| 1195 | + * or if $subsection_name_to_target is null, |
|
| 1196 | + * before or after entire subsections array |
|
| 1197 | + * @return void |
|
| 1198 | + * @throws EE_Error |
|
| 1199 | + */ |
|
| 1200 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
| 1201 | + { |
|
| 1202 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
| 1203 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1204 | + EE_Error::add_error( |
|
| 1205 | + sprintf( |
|
| 1206 | + esc_html__( |
|
| 1207 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
| 1208 | + 'event_espresso' |
|
| 1209 | + ), |
|
| 1210 | + get_class($subsection), |
|
| 1211 | + $subsection_name, |
|
| 1212 | + $this->name() |
|
| 1213 | + ) |
|
| 1214 | + ); |
|
| 1215 | + unset($new_subsections[ $subsection_name ]); |
|
| 1216 | + } |
|
| 1217 | + } |
|
| 1218 | + $this->_subsections = EEH_Array::insert_into_array( |
|
| 1219 | + $this->_subsections, |
|
| 1220 | + $new_subsections, |
|
| 1221 | + $subsection_name_to_target, |
|
| 1222 | + $add_before |
|
| 1223 | + ); |
|
| 1224 | + if ($this->_construction_finalized) { |
|
| 1225 | + foreach ($this->_subsections as $name => $subsection) { |
|
| 1226 | + $subsection->_construct_finalize($this, $name); |
|
| 1227 | + } |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + |
|
| 1232 | + /** |
|
| 1233 | + * Just gets all validatable subsections to clean their sensitive data |
|
| 1234 | + * |
|
| 1235 | + * @throws EE_Error |
|
| 1236 | + */ |
|
| 1237 | + public function clean_sensitive_data() |
|
| 1238 | + { |
|
| 1239 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1240 | + $subsection->clean_sensitive_data(); |
|
| 1241 | + } |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + |
|
| 1245 | + /** |
|
| 1246 | + * @param string $form_submission_error_message |
|
| 1247 | + */ |
|
| 1248 | + public function set_submission_error_message($form_submission_error_message = '') |
|
| 1249 | + { |
|
| 1250 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
| 1251 | + ? $form_submission_error_message |
|
| 1252 | + : esc_html__('Form submission failed due to errors', 'event_espresso'); |
|
| 1253 | + } |
|
| 1254 | + |
|
| 1255 | + |
|
| 1256 | + /** |
|
| 1257 | + * @return string |
|
| 1258 | + */ |
|
| 1259 | + public function submission_error_message() |
|
| 1260 | + { |
|
| 1261 | + return $this->_form_submission_error_message; |
|
| 1262 | + } |
|
| 1263 | + |
|
| 1264 | + |
|
| 1265 | + /** |
|
| 1266 | + * @param string $form_submission_success_message |
|
| 1267 | + */ |
|
| 1268 | + public function set_submission_success_message($form_submission_success_message) |
|
| 1269 | + { |
|
| 1270 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
| 1271 | + ? $form_submission_success_message |
|
| 1272 | + : esc_html__('Form submitted successfully', 'event_espresso'); |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * @return string |
|
| 1278 | + */ |
|
| 1279 | + public function submission_success_message() |
|
| 1280 | + { |
|
| 1281 | + return $this->_form_submission_success_message; |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + |
|
| 1285 | + /** |
|
| 1286 | + * Returns the prefix that should be used on child of this form section for |
|
| 1287 | + * their html names. If this form section itself has a parent, prepends ITS |
|
| 1288 | + * prefix onto this form section's prefix. Used primarily by |
|
| 1289 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
| 1290 | + * |
|
| 1291 | + * @return string |
|
| 1292 | + * @throws EE_Error |
|
| 1293 | + */ |
|
| 1294 | + public function html_name_prefix() |
|
| 1295 | + { |
|
| 1296 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
| 1297 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1298 | + } |
|
| 1299 | + return $this->name(); |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + |
|
| 1303 | + /** |
|
| 1304 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
| 1305 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
| 1306 | + * was set, which is probably nothing, or the classname) |
|
| 1307 | + * |
|
| 1308 | + * @return string |
|
| 1309 | + * @throws EE_Error |
|
| 1310 | + */ |
|
| 1311 | + public function name() |
|
| 1312 | + { |
|
| 1313 | + $this->ensure_construct_finalized_called(); |
|
| 1314 | + return parent::name(); |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + |
|
| 1318 | + /** |
|
| 1319 | + * @return EE_Form_Section_Proper |
|
| 1320 | + * @throws EE_Error |
|
| 1321 | + */ |
|
| 1322 | + public function parent_section() |
|
| 1323 | + { |
|
| 1324 | + $this->ensure_construct_finalized_called(); |
|
| 1325 | + return parent::parent_section(); |
|
| 1326 | + } |
|
| 1327 | + |
|
| 1328 | + |
|
| 1329 | + /** |
|
| 1330 | + * make sure construction finalized was called, otherwise children might not be ready |
|
| 1331 | + * |
|
| 1332 | + * @return void |
|
| 1333 | + * @throws EE_Error |
|
| 1334 | + */ |
|
| 1335 | + public function ensure_construct_finalized_called() |
|
| 1336 | + { |
|
| 1337 | + if (! $this->_construction_finalized) { |
|
| 1338 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
| 1339 | + } |
|
| 1340 | + } |
|
| 1341 | + |
|
| 1342 | + |
|
| 1343 | + /** |
|
| 1344 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
| 1345 | + * are in teh form data. If any are found, returns true. Else false |
|
| 1346 | + * |
|
| 1347 | + * @param array $req_data |
|
| 1348 | + * @return boolean |
|
| 1349 | + * @throws EE_Error |
|
| 1350 | + */ |
|
| 1351 | + public function form_data_present_in($req_data = null) |
|
| 1352 | + { |
|
| 1353 | + if ($req_data === null) { |
|
| 1354 | + $req_data = $_POST; |
|
| 1355 | + } |
|
| 1356 | + foreach ($this->subsections() as $subsection) { |
|
| 1357 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 1358 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1359 | + return true; |
|
| 1360 | + } |
|
| 1361 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1362 | + if ($subsection->form_data_present_in($req_data)) { |
|
| 1363 | + return true; |
|
| 1364 | + } |
|
| 1365 | + } |
|
| 1366 | + } |
|
| 1367 | + return false; |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + |
|
| 1371 | + /** |
|
| 1372 | + * Gets validation errors for this form section and subsections |
|
| 1373 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
| 1374 | + * gets the validation errors for ALL subsection |
|
| 1375 | + * |
|
| 1376 | + * @return EE_Validation_Error[] |
|
| 1377 | + * @throws EE_Error |
|
| 1378 | + */ |
|
| 1379 | + public function get_validation_errors_accumulated() |
|
| 1380 | + { |
|
| 1381 | + $validation_errors = $this->get_validation_errors(); |
|
| 1382 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
| 1383 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
| 1384 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
| 1385 | + } else { |
|
| 1386 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
| 1387 | + } |
|
| 1388 | + if ($validation_errors_on_this_subsection) { |
|
| 1389 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
| 1390 | + } |
|
| 1391 | + } |
|
| 1392 | + return $validation_errors; |
|
| 1393 | + } |
|
| 1394 | + |
|
| 1395 | + |
|
| 1396 | + /** |
|
| 1397 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
| 1398 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
| 1399 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
| 1400 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
| 1401 | + * which will be returned. |
|
| 1402 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
| 1403 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
| 1404 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
| 1405 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
| 1406 | + * Etc |
|
| 1407 | + * |
|
| 1408 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
| 1409 | + * @return EE_Form_Section_Base |
|
| 1410 | + * @throws EE_Error |
|
| 1411 | + */ |
|
| 1412 | + public function find_section_from_path($form_section_path) |
|
| 1413 | + { |
|
| 1414 | + //check if we can find the input from purely going straight up the tree |
|
| 1415 | + $input = parent::find_section_from_path($form_section_path); |
|
| 1416 | + if ($input instanceof EE_Form_Section_Base) { |
|
| 1417 | + return $input; |
|
| 1418 | + } |
|
| 1419 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
| 1420 | + if ($next_slash_pos !== false) { |
|
| 1421 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
| 1422 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
| 1423 | + } else { |
|
| 1424 | + $child_section_name = $form_section_path; |
|
| 1425 | + $subpath = ''; |
|
| 1426 | + } |
|
| 1427 | + $child_section = $this->get_subsection($child_section_name); |
|
| 1428 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
| 1429 | + return $child_section->find_section_from_path($subpath); |
|
| 1430 | + } |
|
| 1431 | + return null; |
|
| 1432 | + } |
|
| 1433 | 1433 | } |
| 1434 | 1434 | |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | //AND we are going to make sure they're in that specified order |
| 100 | 100 | $reordered_subsections = array(); |
| 101 | 101 | foreach ($options_array['include'] as $input_name) { |
| 102 | - if (isset($this->_subsections[ $input_name ])) { |
|
| 103 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
| 102 | + if (isset($this->_subsections[$input_name])) { |
|
| 103 | + $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | $this->_subsections = $reordered_subsections; |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | if (isset($options_array['layout_strategy'])) { |
| 113 | 113 | $this->_layout_strategy = $options_array['layout_strategy']; |
| 114 | 114 | } |
| 115 | - if (! $this->_layout_strategy) { |
|
| 115 | + if ( ! $this->_layout_strategy) { |
|
| 116 | 116 | $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
| 117 | 117 | } |
| 118 | 118 | $this->_layout_strategy->_construct_finalize($this); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | if ($validate) { |
| 283 | 283 | $this->_validate(); |
| 284 | 284 | //if it's invalid, we're going to want to re-display so remember what they submitted |
| 285 | - if (! $this->is_valid()) { |
|
| 285 | + if ( ! $this->is_valid()) { |
|
| 286 | 286 | $this->store_submitted_form_data_in_session(); |
| 287 | 287 | } |
| 288 | 288 | } |
@@ -392,11 +392,11 @@ discard block |
||
| 392 | 392 | public function populate_defaults($default_data) |
| 393 | 393 | { |
| 394 | 394 | foreach ($this->subsections(false) as $subsection_name => $subsection) { |
| 395 | - if (isset($default_data[ $subsection_name ])) { |
|
| 395 | + if (isset($default_data[$subsection_name])) { |
|
| 396 | 396 | if ($subsection instanceof EE_Form_Input_Base) { |
| 397 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
| 397 | + $subsection->set_default($default_data[$subsection_name]); |
|
| 398 | 398 | } elseif ($subsection instanceof EE_Form_Section_Proper) { |
| 399 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
| 399 | + $subsection->populate_defaults($default_data[$subsection_name]); |
|
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | } |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | */ |
| 412 | 412 | public function subsection_exists($name) |
| 413 | 413 | { |
| 414 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
| 414 | + return isset($this->_subsections[$name]) ? true : false; |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | if ($require_construction_to_be_finalized) { |
| 434 | 434 | $this->ensure_construct_finalized_called(); |
| 435 | 435 | } |
| 436 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
| 436 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | $validatable_subsections = array(); |
| 449 | 449 | foreach ($this->subsections() as $name => $obj) { |
| 450 | 450 | if ($obj instanceof EE_Form_Section_Validatable) { |
| 451 | - $validatable_subsections[ $name ] = $obj; |
|
| 451 | + $validatable_subsections[$name] = $obj; |
|
| 452 | 452 | } |
| 453 | 453 | } |
| 454 | 454 | return $validatable_subsections; |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | $name, |
| 476 | 476 | $require_construction_to_be_finalized |
| 477 | 477 | ); |
| 478 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
| 478 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
| 479 | 479 | throw new EE_Error( |
| 480 | 480 | sprintf( |
| 481 | 481 | esc_html__( |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | $name, |
| 513 | 513 | $require_construction_to_be_finalized |
| 514 | 514 | ); |
| 515 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
| 515 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
| 516 | 516 | throw new EE_Error( |
| 517 | 517 | sprintf( |
| 518 | 518 | esc_html__( |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | */ |
| 552 | 552 | public function is_valid() |
| 553 | 553 | { |
| 554 | - if (! $this->has_received_submission()) { |
|
| 554 | + if ( ! $this->has_received_submission()) { |
|
| 555 | 555 | throw new EE_Error( |
| 556 | 556 | sprintf( |
| 557 | 557 | esc_html__( |
@@ -561,14 +561,14 @@ discard block |
||
| 561 | 561 | ) |
| 562 | 562 | ); |
| 563 | 563 | } |
| 564 | - if (! parent::is_valid()) { |
|
| 564 | + if ( ! parent::is_valid()) { |
|
| 565 | 565 | return false; |
| 566 | 566 | } |
| 567 | 567 | // ok so no general errors to this entire form section. |
| 568 | 568 | // so let's check the subsections, but only set errors if that hasn't been done yet |
| 569 | 569 | $set_submission_errors = $this->submission_error_message() === ''; |
| 570 | 570 | foreach ($this->get_validatable_subsections() as $subsection) { |
| 571 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 571 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
| 572 | 572 | if ($set_submission_errors) { |
| 573 | 573 | $this->set_submission_error_message( |
| 574 | 574 | $subsection->get_validation_error_string() |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | */ |
| 589 | 589 | protected function _set_default_name_if_empty() |
| 590 | 590 | { |
| 591 | - if (! $this->_name) { |
|
| 591 | + if ( ! $this->_name) { |
|
| 592 | 592 | $classname = get_class($this); |
| 593 | 593 | $default_name = str_replace('EE_', '', $classname); |
| 594 | 594 | $this->_name = $default_name; |
@@ -678,7 +678,7 @@ discard block |
||
| 678 | 678 | { |
| 679 | 679 | wp_register_script( |
| 680 | 680 | 'ee_form_section_validation', |
| 681 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
| 681 | + EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', |
|
| 682 | 682 | array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
| 683 | 683 | EVENT_ESPRESSO_VERSION, |
| 684 | 684 | true |
@@ -722,13 +722,13 @@ discard block |
||
| 722 | 722 | // we only want to localize vars ONCE for the entire form, |
| 723 | 723 | // so if the form section doesn't have a parent, then it must be the top dog |
| 724 | 724 | if ($return_for_subsection || ! $this->parent_section()) { |
| 725 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
| 725 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
| 726 | 726 | 'form_section_id' => $this->html_id(true), |
| 727 | 727 | 'validation_rules' => $this->get_jquery_validation_rules(), |
| 728 | 728 | 'other_data' => $this->get_other_js_data(), |
| 729 | 729 | 'errors' => $this->subsection_validation_errors_by_html_name(), |
| 730 | 730 | ); |
| 731 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 731 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
| 732 | 732 | } |
| 733 | 733 | } |
| 734 | 734 | |
@@ -763,7 +763,7 @@ discard block |
||
| 763 | 763 | $inputs = array(); |
| 764 | 764 | foreach ($this->subsections() as $subsection) { |
| 765 | 765 | if ($subsection instanceof EE_Form_Input_Base) { |
| 766 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
| 766 | + $inputs[$subsection->html_name()] = $subsection; |
|
| 767 | 767 | } elseif ($subsection instanceof EE_Form_Section_Proper) { |
| 768 | 768 | $inputs += $subsection->inputs_in_subsections(); |
| 769 | 769 | } |
@@ -786,7 +786,7 @@ discard block |
||
| 786 | 786 | $errors = array(); |
| 787 | 787 | foreach ($inputs as $form_input) { |
| 788 | 788 | if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
| 789 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
| 789 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
| 790 | 790 | } |
| 791 | 791 | } |
| 792 | 792 | return $errors; |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
| 810 | 810 | ? EE_Registry::instance()->CFG->registration->email_validation_level |
| 811 | 811 | : 'wp_default'; |
| 812 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 812 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
| 813 | 813 | wp_enqueue_script('ee_form_section_validation'); |
| 814 | 814 | wp_localize_script( |
| 815 | 815 | 'ee_form_section_validation', |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | */ |
| 827 | 827 | public function ensure_scripts_localized() |
| 828 | 828 | { |
| 829 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 829 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
| 830 | 830 | $this->_enqueue_and_localize_form_js(); |
| 831 | 831 | } |
| 832 | 832 | } |
@@ -920,8 +920,8 @@ discard block |
||
| 920 | 920 | protected function _validate() |
| 921 | 921 | { |
| 922 | 922 | foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
| 923 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
| 924 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
| 923 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
| 924 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
| 925 | 925 | } |
| 926 | 926 | $subsection->_validate(); |
| 927 | 927 | } |
@@ -939,9 +939,9 @@ discard block |
||
| 939 | 939 | $inputs = array(); |
| 940 | 940 | foreach ($this->subsections() as $subsection_name => $subsection) { |
| 941 | 941 | if ($subsection instanceof EE_Form_Section_Proper) { |
| 942 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
| 942 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
| 943 | 943 | } elseif ($subsection instanceof EE_Form_Input_Base) { |
| 944 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
| 944 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
| 945 | 945 | } |
| 946 | 946 | } |
| 947 | 947 | return $inputs; |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | $inputs = array(); |
| 960 | 960 | foreach ($this->subsections() as $subsection_name => $subsection) { |
| 961 | 961 | if ($subsection instanceof EE_Form_Input_Base) { |
| 962 | - $inputs[ $subsection_name ] = $subsection; |
|
| 962 | + $inputs[$subsection_name] = $subsection; |
|
| 963 | 963 | } |
| 964 | 964 | } |
| 965 | 965 | return $inputs; |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | $form_sections = array(); |
| 978 | 978 | foreach ($this->subsections() as $name => $obj) { |
| 979 | 979 | if ($obj instanceof EE_Form_Section_Proper) { |
| 980 | - $form_sections[ $name ] = $obj; |
|
| 980 | + $form_sections[$name] = $obj; |
|
| 981 | 981 | } |
| 982 | 982 | } |
| 983 | 983 | return $form_sections; |
@@ -1074,7 +1074,7 @@ discard block |
||
| 1074 | 1074 | $input_values = array(); |
| 1075 | 1075 | foreach ($this->subsections() as $subsection_name => $subsection) { |
| 1076 | 1076 | if ($subsection instanceof EE_Form_Input_Base) { |
| 1077 | - $input_values[ $subsection_name ] = $pretty |
|
| 1077 | + $input_values[$subsection_name] = $pretty |
|
| 1078 | 1078 | ? $subsection->pretty_value() |
| 1079 | 1079 | : $subsection->normalized_value(); |
| 1080 | 1080 | } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
@@ -1086,7 +1086,7 @@ discard block |
||
| 1086 | 1086 | if ($flatten) { |
| 1087 | 1087 | $input_values = array_merge($input_values, $subform_input_values); |
| 1088 | 1088 | } else { |
| 1089 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
| 1089 | + $input_values[$subsection_name] = $subform_input_values; |
|
| 1090 | 1090 | } |
| 1091 | 1091 | } |
| 1092 | 1092 | } |
@@ -1114,7 +1114,7 @@ discard block |
||
| 1114 | 1114 | if ($subsection instanceof EE_Form_Input_Base) { |
| 1115 | 1115 | // is this input part of an array of inputs? |
| 1116 | 1116 | if (strpos($subsection->html_name(), '[') !== false) { |
| 1117 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1117 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
| 1118 | 1118 | explode( |
| 1119 | 1119 | '[', |
| 1120 | 1120 | str_replace(']', '', $subsection->html_name()) |
@@ -1123,7 +1123,7 @@ discard block |
||
| 1123 | 1123 | ); |
| 1124 | 1124 | $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
| 1125 | 1125 | } else { |
| 1126 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
| 1126 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
| 1127 | 1127 | } |
| 1128 | 1128 | } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
| 1129 | 1129 | $subform_input_values = $subsection->submitted_values($include_subforms); |
@@ -1158,7 +1158,7 @@ discard block |
||
| 1158 | 1158 | public function exclude(array $inputs_to_exclude = array()) |
| 1159 | 1159 | { |
| 1160 | 1160 | foreach ($inputs_to_exclude as $input_to_exclude_name) { |
| 1161 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
| 1161 | + unset($this->_subsections[$input_to_exclude_name]); |
|
| 1162 | 1162 | } |
| 1163 | 1163 | } |
| 1164 | 1164 | |
@@ -1200,7 +1200,7 @@ discard block |
||
| 1200 | 1200 | public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
| 1201 | 1201 | { |
| 1202 | 1202 | foreach ($new_subsections as $subsection_name => $subsection) { |
| 1203 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
| 1203 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
| 1204 | 1204 | EE_Error::add_error( |
| 1205 | 1205 | sprintf( |
| 1206 | 1206 | esc_html__( |
@@ -1212,7 +1212,7 @@ discard block |
||
| 1212 | 1212 | $this->name() |
| 1213 | 1213 | ) |
| 1214 | 1214 | ); |
| 1215 | - unset($new_subsections[ $subsection_name ]); |
|
| 1215 | + unset($new_subsections[$subsection_name]); |
|
| 1216 | 1216 | } |
| 1217 | 1217 | } |
| 1218 | 1218 | $this->_subsections = EEH_Array::insert_into_array( |
@@ -1294,7 +1294,7 @@ discard block |
||
| 1294 | 1294 | public function html_name_prefix() |
| 1295 | 1295 | { |
| 1296 | 1296 | if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
| 1297 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
| 1297 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
| 1298 | 1298 | } |
| 1299 | 1299 | return $this->name(); |
| 1300 | 1300 | } |
@@ -1334,7 +1334,7 @@ discard block |
||
| 1334 | 1334 | */ |
| 1335 | 1335 | public function ensure_construct_finalized_called() |
| 1336 | 1336 | { |
| 1337 | - if (! $this->_construction_finalized) { |
|
| 1337 | + if ( ! $this->_construction_finalized) { |
|
| 1338 | 1338 | $this->_construct_finalize($this->_parent_section, $this->_name); |
| 1339 | 1339 | } |
| 1340 | 1340 | } |
@@ -38,216 +38,216 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | |
| 64 | 64 | } else { |
| 65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 67 | - /** |
|
| 68 | - * espresso_minimum_php_version_error |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 67 | + /** |
|
| 68 | + * espresso_minimum_php_version_error |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.58.rc.007'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.58.rc.007'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | - /** |
|
| 119 | - * espresso_load_error_handling |
|
| 120 | - * this function loads EE's class for handling exceptions and errors |
|
| 121 | - */ |
|
| 122 | - function espresso_load_error_handling() |
|
| 123 | - { |
|
| 124 | - static $error_handling_loaded = false; |
|
| 125 | - if ($error_handling_loaded) { |
|
| 126 | - return; |
|
| 127 | - } |
|
| 128 | - // load debugging tools |
|
| 129 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 130 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
| 131 | - \EEH_Debug_Tools::instance(); |
|
| 132 | - } |
|
| 133 | - // load error handling |
|
| 134 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 135 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
| 136 | - } else { |
|
| 137 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 138 | - } |
|
| 139 | - $error_handling_loaded = true; |
|
| 140 | - } |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | + /** |
|
| 119 | + * espresso_load_error_handling |
|
| 120 | + * this function loads EE's class for handling exceptions and errors |
|
| 121 | + */ |
|
| 122 | + function espresso_load_error_handling() |
|
| 123 | + { |
|
| 124 | + static $error_handling_loaded = false; |
|
| 125 | + if ($error_handling_loaded) { |
|
| 126 | + return; |
|
| 127 | + } |
|
| 128 | + // load debugging tools |
|
| 129 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
| 130 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
| 131 | + \EEH_Debug_Tools::instance(); |
|
| 132 | + } |
|
| 133 | + // load error handling |
|
| 134 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
| 135 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
| 136 | + } else { |
|
| 137 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
| 138 | + } |
|
| 139 | + $error_handling_loaded = true; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * espresso_load_required |
|
| 144 | - * given a class name and path, this function will load that file or throw an exception |
|
| 145 | - * |
|
| 146 | - * @param string $classname |
|
| 147 | - * @param string $full_path_to_file |
|
| 148 | - * @throws EE_Error |
|
| 149 | - */ |
|
| 150 | - function espresso_load_required($classname, $full_path_to_file) |
|
| 151 | - { |
|
| 152 | - if (is_readable($full_path_to_file)) { |
|
| 153 | - require_once $full_path_to_file; |
|
| 154 | - } else { |
|
| 155 | - throw new \EE_Error ( |
|
| 156 | - sprintf( |
|
| 157 | - esc_html__( |
|
| 158 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 159 | - 'event_espresso' |
|
| 160 | - ), |
|
| 161 | - $classname |
|
| 162 | - ) |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - } |
|
| 142 | + /** |
|
| 143 | + * espresso_load_required |
|
| 144 | + * given a class name and path, this function will load that file or throw an exception |
|
| 145 | + * |
|
| 146 | + * @param string $classname |
|
| 147 | + * @param string $full_path_to_file |
|
| 148 | + * @throws EE_Error |
|
| 149 | + */ |
|
| 150 | + function espresso_load_required($classname, $full_path_to_file) |
|
| 151 | + { |
|
| 152 | + if (is_readable($full_path_to_file)) { |
|
| 153 | + require_once $full_path_to_file; |
|
| 154 | + } else { |
|
| 155 | + throw new \EE_Error ( |
|
| 156 | + sprintf( |
|
| 157 | + esc_html__( |
|
| 158 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
| 159 | + 'event_espresso' |
|
| 160 | + ), |
|
| 161 | + $classname |
|
| 162 | + ) |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * @since 4.9.27 |
|
| 169 | - * @throws \EE_Error |
|
| 170 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 171 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
| 172 | - * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
| 173 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 174 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 175 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
| 176 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
| 177 | - * @throws \OutOfBoundsException |
|
| 178 | - */ |
|
| 179 | - function bootstrap_espresso() |
|
| 180 | - { |
|
| 181 | - require_once __DIR__ . '/core/espresso_definitions.php'; |
|
| 182 | - try { |
|
| 183 | - espresso_load_error_handling(); |
|
| 184 | - espresso_load_required( |
|
| 185 | - 'EEH_Base', |
|
| 186 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
| 187 | - ); |
|
| 188 | - espresso_load_required( |
|
| 189 | - 'EEH_File', |
|
| 190 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
| 191 | - ); |
|
| 192 | - espresso_load_required( |
|
| 193 | - 'EEH_File', |
|
| 194 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
| 195 | - ); |
|
| 196 | - espresso_load_required( |
|
| 197 | - 'EEH_Array', |
|
| 198 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
| 199 | - ); |
|
| 200 | - // instantiate and configure PSR4 autoloader |
|
| 201 | - espresso_load_required( |
|
| 202 | - 'Psr4Autoloader', |
|
| 203 | - EE_CORE . 'Psr4Autoloader.php' |
|
| 204 | - ); |
|
| 205 | - espresso_load_required( |
|
| 206 | - 'EE_Psr4AutoloaderInit', |
|
| 207 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
| 208 | - ); |
|
| 209 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
| 210 | - $AutoloaderInit->initializeAutoloader(); |
|
| 211 | - espresso_load_required( |
|
| 212 | - 'EE_Request', |
|
| 213 | - EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
| 214 | - ); |
|
| 215 | - espresso_load_required( |
|
| 216 | - 'EE_Response', |
|
| 217 | - EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
| 218 | - ); |
|
| 219 | - espresso_load_required( |
|
| 220 | - 'EE_Bootstrap', |
|
| 221 | - EE_CORE . 'EE_Bootstrap.core.php' |
|
| 222 | - ); |
|
| 223 | - // bootstrap EE and the request stack |
|
| 224 | - new EE_Bootstrap( |
|
| 225 | - new EE_Request($_GET, $_POST, $_COOKIE), |
|
| 226 | - new EE_Response() |
|
| 227 | - ); |
|
| 228 | - } catch (Exception $e) { |
|
| 229 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
| 230 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - bootstrap_espresso(); |
|
| 234 | - } |
|
| 167 | + /** |
|
| 168 | + * @since 4.9.27 |
|
| 169 | + * @throws \EE_Error |
|
| 170 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 171 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
| 172 | + * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
| 173 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
| 174 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 175 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
| 176 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
| 177 | + * @throws \OutOfBoundsException |
|
| 178 | + */ |
|
| 179 | + function bootstrap_espresso() |
|
| 180 | + { |
|
| 181 | + require_once __DIR__ . '/core/espresso_definitions.php'; |
|
| 182 | + try { |
|
| 183 | + espresso_load_error_handling(); |
|
| 184 | + espresso_load_required( |
|
| 185 | + 'EEH_Base', |
|
| 186 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
| 187 | + ); |
|
| 188 | + espresso_load_required( |
|
| 189 | + 'EEH_File', |
|
| 190 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
| 191 | + ); |
|
| 192 | + espresso_load_required( |
|
| 193 | + 'EEH_File', |
|
| 194 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
| 195 | + ); |
|
| 196 | + espresso_load_required( |
|
| 197 | + 'EEH_Array', |
|
| 198 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
| 199 | + ); |
|
| 200 | + // instantiate and configure PSR4 autoloader |
|
| 201 | + espresso_load_required( |
|
| 202 | + 'Psr4Autoloader', |
|
| 203 | + EE_CORE . 'Psr4Autoloader.php' |
|
| 204 | + ); |
|
| 205 | + espresso_load_required( |
|
| 206 | + 'EE_Psr4AutoloaderInit', |
|
| 207 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
| 208 | + ); |
|
| 209 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
| 210 | + $AutoloaderInit->initializeAutoloader(); |
|
| 211 | + espresso_load_required( |
|
| 212 | + 'EE_Request', |
|
| 213 | + EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
| 214 | + ); |
|
| 215 | + espresso_load_required( |
|
| 216 | + 'EE_Response', |
|
| 217 | + EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
| 218 | + ); |
|
| 219 | + espresso_load_required( |
|
| 220 | + 'EE_Bootstrap', |
|
| 221 | + EE_CORE . 'EE_Bootstrap.core.php' |
|
| 222 | + ); |
|
| 223 | + // bootstrap EE and the request stack |
|
| 224 | + new EE_Bootstrap( |
|
| 225 | + new EE_Request($_GET, $_POST, $_COOKIE), |
|
| 226 | + new EE_Response() |
|
| 227 | + ); |
|
| 228 | + } catch (Exception $e) { |
|
| 229 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
| 230 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + bootstrap_espresso(); |
|
| 234 | + } |
|
| 235 | 235 | } |
| 236 | 236 | if (! function_exists('espresso_deactivate_plugin')) { |
| 237 | - /** |
|
| 238 | - * deactivate_plugin |
|
| 239 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 240 | - * |
|
| 241 | - * @access public |
|
| 242 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 243 | - * @return void |
|
| 244 | - */ |
|
| 245 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 246 | - { |
|
| 247 | - if (! function_exists('deactivate_plugins')) { |
|
| 248 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 249 | - } |
|
| 250 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 251 | - deactivate_plugins($plugin_basename); |
|
| 252 | - } |
|
| 237 | + /** |
|
| 238 | + * deactivate_plugin |
|
| 239 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 240 | + * |
|
| 241 | + * @access public |
|
| 242 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 243 | + * @return void |
|
| 244 | + */ |
|
| 245 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 246 | + { |
|
| 247 | + if (! function_exists('deactivate_plugins')) { |
|
| 248 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 249 | + } |
|
| 250 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 251 | + deactivate_plugins($plugin_basename); |
|
| 252 | + } |
|
| 253 | 253 | } |
@@ -101,7 +101,7 @@ |
||
| 101 | 101 | /** |
| 102 | 102 | * _get_table_filters |
| 103 | 103 | * |
| 104 | - * @return array |
|
| 104 | + * @return string[] |
|
| 105 | 105 | */ |
| 106 | 106 | protected function _get_table_filters() |
| 107 | 107 | { |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | |
@@ -27,210 +27,210 @@ discard block |
||
| 27 | 27 | class Payment_Log_Admin_List_Table extends EE_Admin_List_Table |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param \EE_Admin_Page $admin_page |
|
| 32 | - * @return Payment_Log_Admin_List_Table |
|
| 33 | - */ |
|
| 34 | - public function __construct($admin_page) |
|
| 35 | - { |
|
| 36 | - parent::__construct($admin_page); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * _setup_data |
|
| 43 | - * |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - protected function _setup_data() |
|
| 47 | - { |
|
| 48 | - $this->_data = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page); |
|
| 49 | - // if(isset($this->_req_data['status'] ) && $this->_req_data['status'] == 'trash'){ |
|
| 50 | - // $this->_data = $this->_admin_page->get_trashed_questions( $this->_per_page,$this->_current_page, FALSE ); |
|
| 51 | - // }else{ |
|
| 52 | - // $this->_data = $this->_admin_page->get_questions( $this->_per_page,$this->_current_page, FALSE ); |
|
| 53 | - // } |
|
| 54 | - $this->_all_data_count = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page, true); |
|
| 55 | - add_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', array($this, 'add_download_logs_checkbox')); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * add_download_logs_checkbox |
|
| 62 | - * adds a checkbox to the bottom of the list table, instead of at the top with the rest of the filters |
|
| 63 | - * |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - public function add_download_logs_checkbox() |
|
| 67 | - { |
|
| 68 | - echo "<input type='submit' class='button-primary' id='download_results' name='download_results' value='" . __('Download Results', 'event_espresso') . "'>"; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * _set_properties |
|
| 75 | - * |
|
| 76 | - * @return void |
|
| 77 | - */ |
|
| 78 | - protected function _set_properties() |
|
| 79 | - { |
|
| 80 | - $this->_wp_list_args = array( |
|
| 81 | - 'singular' => __('payment log', 'event_espresso'), |
|
| 82 | - 'plural' => __('payment logs', 'event_espresso'), |
|
| 83 | - 'ajax' => true, //for now, |
|
| 84 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 85 | - ); |
|
| 86 | - $this->_columns = array( |
|
| 87 | - 'cb' => '<input type="checkbox" />', |
|
| 88 | - 'id' => __('ID', 'event_espresso'), |
|
| 89 | - 'LOG_time' => __('Time', 'event_espresso'), |
|
| 90 | - 'PMD_ID' => __('Payment Method', 'event_espresso'), |
|
| 91 | - 'TXN_ID' => __('Transaction ID', 'event_espresso'), |
|
| 92 | - ); |
|
| 93 | - $this->_sortable_columns = array( |
|
| 94 | - 'LOG_time' => array('LOG_time' => true), |
|
| 95 | - ); |
|
| 96 | - $this->_hidden_columns = array(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * _get_table_filters |
|
| 103 | - * |
|
| 104 | - * @return array |
|
| 105 | - */ |
|
| 106 | - protected function _get_table_filters() |
|
| 107 | - { |
|
| 108 | - $filters = array(); |
|
| 109 | - //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as methods. |
|
| 110 | - $payment_methods = EEM_Payment_Method::instance()->get_all(); |
|
| 111 | - $payment_method_names = array(array('id' => 'all', 'text' => __("All", 'event_espresso')), array('id' => '0', 'text' => __("Unknown Payment Method", 'event_espresso'))); |
|
| 112 | - foreach ($payment_methods as $payment_method) { |
|
| 113 | - $payment_method_names[] = array('id' => $payment_method->ID(), 'text' => $payment_method->admin_name()); |
|
| 114 | - } |
|
| 115 | - $filters[] = EEH_Form_Fields::select_input('_payment_method', $payment_method_names, isset($this->_req_data['_payment_method']) ? $this->_req_data['_payment_method'] : 'all'); |
|
| 116 | - $start_date = isset($this->_req_data['payment-filter-start-date']) ? wp_strip_all_tags($this->_req_data['payment-filter-start-date']) : date('m/d/Y', strtotime('-6 months')); |
|
| 117 | - $end_date = isset($this->_req_data['payment-filter-end-date']) ? wp_strip_all_tags($this->_req_data['payment-filter-end-date']) : date('m/d/Y'); |
|
| 118 | - ob_start(); |
|
| 119 | - ?> |
|
| 30 | + /** |
|
| 31 | + * @param \EE_Admin_Page $admin_page |
|
| 32 | + * @return Payment_Log_Admin_List_Table |
|
| 33 | + */ |
|
| 34 | + public function __construct($admin_page) |
|
| 35 | + { |
|
| 36 | + parent::__construct($admin_page); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * _setup_data |
|
| 43 | + * |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + protected function _setup_data() |
|
| 47 | + { |
|
| 48 | + $this->_data = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page); |
|
| 49 | + // if(isset($this->_req_data['status'] ) && $this->_req_data['status'] == 'trash'){ |
|
| 50 | + // $this->_data = $this->_admin_page->get_trashed_questions( $this->_per_page,$this->_current_page, FALSE ); |
|
| 51 | + // }else{ |
|
| 52 | + // $this->_data = $this->_admin_page->get_questions( $this->_per_page,$this->_current_page, FALSE ); |
|
| 53 | + // } |
|
| 54 | + $this->_all_data_count = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page, true); |
|
| 55 | + add_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', array($this, 'add_download_logs_checkbox')); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * add_download_logs_checkbox |
|
| 62 | + * adds a checkbox to the bottom of the list table, instead of at the top with the rest of the filters |
|
| 63 | + * |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + public function add_download_logs_checkbox() |
|
| 67 | + { |
|
| 68 | + echo "<input type='submit' class='button-primary' id='download_results' name='download_results' value='" . __('Download Results', 'event_espresso') . "'>"; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * _set_properties |
|
| 75 | + * |
|
| 76 | + * @return void |
|
| 77 | + */ |
|
| 78 | + protected function _set_properties() |
|
| 79 | + { |
|
| 80 | + $this->_wp_list_args = array( |
|
| 81 | + 'singular' => __('payment log', 'event_espresso'), |
|
| 82 | + 'plural' => __('payment logs', 'event_espresso'), |
|
| 83 | + 'ajax' => true, //for now, |
|
| 84 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 85 | + ); |
|
| 86 | + $this->_columns = array( |
|
| 87 | + 'cb' => '<input type="checkbox" />', |
|
| 88 | + 'id' => __('ID', 'event_espresso'), |
|
| 89 | + 'LOG_time' => __('Time', 'event_espresso'), |
|
| 90 | + 'PMD_ID' => __('Payment Method', 'event_espresso'), |
|
| 91 | + 'TXN_ID' => __('Transaction ID', 'event_espresso'), |
|
| 92 | + ); |
|
| 93 | + $this->_sortable_columns = array( |
|
| 94 | + 'LOG_time' => array('LOG_time' => true), |
|
| 95 | + ); |
|
| 96 | + $this->_hidden_columns = array(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * _get_table_filters |
|
| 103 | + * |
|
| 104 | + * @return array |
|
| 105 | + */ |
|
| 106 | + protected function _get_table_filters() |
|
| 107 | + { |
|
| 108 | + $filters = array(); |
|
| 109 | + //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as methods. |
|
| 110 | + $payment_methods = EEM_Payment_Method::instance()->get_all(); |
|
| 111 | + $payment_method_names = array(array('id' => 'all', 'text' => __("All", 'event_espresso')), array('id' => '0', 'text' => __("Unknown Payment Method", 'event_espresso'))); |
|
| 112 | + foreach ($payment_methods as $payment_method) { |
|
| 113 | + $payment_method_names[] = array('id' => $payment_method->ID(), 'text' => $payment_method->admin_name()); |
|
| 114 | + } |
|
| 115 | + $filters[] = EEH_Form_Fields::select_input('_payment_method', $payment_method_names, isset($this->_req_data['_payment_method']) ? $this->_req_data['_payment_method'] : 'all'); |
|
| 116 | + $start_date = isset($this->_req_data['payment-filter-start-date']) ? wp_strip_all_tags($this->_req_data['payment-filter-start-date']) : date('m/d/Y', strtotime('-6 months')); |
|
| 117 | + $end_date = isset($this->_req_data['payment-filter-end-date']) ? wp_strip_all_tags($this->_req_data['payment-filter-end-date']) : date('m/d/Y'); |
|
| 118 | + ob_start(); |
|
| 119 | + ?> |
|
| 120 | 120 | <label for="txn-filter-start-date"><?php _e('Display Transactions from ', 'event_espresso'); ?></label> |
| 121 | 121 | <input id="payment-filter-start-date" class="datepicker" type="text" value="<?php echo $start_date; ?>" name="payment-filter-start-date" size="15"/> |
| 122 | 122 | <label for="txn-filter-end-date"><?php _e(' until ', 'event_espresso'); ?></label> |
| 123 | 123 | <input id="payment-filter-end-date" class="datepicker" type="text" value="<?php echo $end_date; ?>" name="payment-filter-end-date" size="15"/> |
| 124 | 124 | <?php |
| 125 | - $filters[] = ob_get_clean(); |
|
| 126 | - return $filters; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * _add_view_counts |
|
| 133 | - * |
|
| 134 | - * @return void |
|
| 135 | - */ |
|
| 136 | - protected function _add_view_counts() |
|
| 137 | - { |
|
| 138 | - $this->_views['all']['count'] = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page, true); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * column_cb |
|
| 145 | - * |
|
| 146 | - * @param \EE_Change_Log $item |
|
| 147 | - * @return string |
|
| 148 | - */ |
|
| 149 | - public function column_cb($item) |
|
| 150 | - { |
|
| 151 | - return sprintf('<input type="checkbox" class="option_id" name="checkbox[%1$d]" value="%1$d" />', $item->ID()); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * column_id |
|
| 158 | - * |
|
| 159 | - * @param \EE_Change_Log $item |
|
| 160 | - * @return string |
|
| 161 | - */ |
|
| 162 | - public function column_id(EE_Change_Log $item) |
|
| 163 | - { |
|
| 164 | - $details_query_args = array( |
|
| 165 | - 'action' => 'payment_log_details', |
|
| 166 | - 'ID' => $item->ID(), |
|
| 167 | - ); |
|
| 168 | - $url = EE_Admin_Page::add_query_args_and_nonce($details_query_args, EE_PAYMENTS_ADMIN_URL); |
|
| 169 | - return "<a href='$url'>{$item->ID()}</a>"; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * column_LOG_time |
|
| 176 | - * |
|
| 177 | - * @param \EE_Change_Log $item |
|
| 178 | - * @return string |
|
| 179 | - */ |
|
| 180 | - public function column_LOG_time(EE_Change_Log $item) |
|
| 181 | - { |
|
| 182 | - return $item->get_datetime('LOG_time'); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * column_PMD_ID |
|
| 189 | - * |
|
| 190 | - * @param \EE_Change_Log $item |
|
| 191 | - * @return string |
|
| 192 | - */ |
|
| 193 | - public function column_PMD_ID(EE_Change_Log $item) |
|
| 194 | - { |
|
| 195 | - if ($item->object() instanceof EE_Payment_Method) { |
|
| 196 | - return $item->object()->admin_name(); |
|
| 197 | - } elseif ($item->object() instanceof EE_Payment && $item->object()->payment_method()) { |
|
| 198 | - return $item->object()->payment_method()->admin_name(); |
|
| 199 | - } elseif ($item->object() instanceof EE_Transaction && $item->object()->payment_method()) { |
|
| 200 | - return sprintf( |
|
| 201 | - esc_html__('Probably %1$s', 'event_espresso'), |
|
| 202 | - $item->object()->payment_method()->admin_name() |
|
| 203 | - ); |
|
| 204 | - } else { |
|
| 205 | - return __("No longer exists", 'event_espresso'); |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * column_TXN_ID |
|
| 213 | - * |
|
| 214 | - * @param \EE_Change_Log $item |
|
| 215 | - * @return string |
|
| 216 | - */ |
|
| 217 | - public function column_TXN_ID(EE_Change_Log $item) |
|
| 218 | - { |
|
| 219 | - if ($item->object() instanceof EE_Payment) { |
|
| 220 | - $transaction_id = $item->object()->TXN_ID(); |
|
| 221 | - } elseif ($item->object() instanceof EE_Transaction) { |
|
| 222 | - $transaction_id = $item->object()->ID(); |
|
| 223 | - } else { |
|
| 224 | - $transaction_id = null; |
|
| 225 | - } |
|
| 226 | - if ($transaction_id && EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction', $transaction_id)) { |
|
| 227 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $transaction_id), TXN_ADMIN_URL); |
|
| 228 | - return '<a href="' . $view_txn_lnk_url . '" title="' . sprintf(esc_attr__('click to view transaction #%s', 'event_espresso'), $transaction_id) . '">' . sprintf(__('view txn %s', |
|
| 229 | - 'event_espresso'), $transaction_id) . '</a>'; |
|
| 230 | - } else { |
|
| 231 | - return __("Unable to find transaction", 'event_espresso'); |
|
| 232 | - } |
|
| 233 | - } |
|
| 125 | + $filters[] = ob_get_clean(); |
|
| 126 | + return $filters; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * _add_view_counts |
|
| 133 | + * |
|
| 134 | + * @return void |
|
| 135 | + */ |
|
| 136 | + protected function _add_view_counts() |
|
| 137 | + { |
|
| 138 | + $this->_views['all']['count'] = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page, true); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * column_cb |
|
| 145 | + * |
|
| 146 | + * @param \EE_Change_Log $item |
|
| 147 | + * @return string |
|
| 148 | + */ |
|
| 149 | + public function column_cb($item) |
|
| 150 | + { |
|
| 151 | + return sprintf('<input type="checkbox" class="option_id" name="checkbox[%1$d]" value="%1$d" />', $item->ID()); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * column_id |
|
| 158 | + * |
|
| 159 | + * @param \EE_Change_Log $item |
|
| 160 | + * @return string |
|
| 161 | + */ |
|
| 162 | + public function column_id(EE_Change_Log $item) |
|
| 163 | + { |
|
| 164 | + $details_query_args = array( |
|
| 165 | + 'action' => 'payment_log_details', |
|
| 166 | + 'ID' => $item->ID(), |
|
| 167 | + ); |
|
| 168 | + $url = EE_Admin_Page::add_query_args_and_nonce($details_query_args, EE_PAYMENTS_ADMIN_URL); |
|
| 169 | + return "<a href='$url'>{$item->ID()}</a>"; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * column_LOG_time |
|
| 176 | + * |
|
| 177 | + * @param \EE_Change_Log $item |
|
| 178 | + * @return string |
|
| 179 | + */ |
|
| 180 | + public function column_LOG_time(EE_Change_Log $item) |
|
| 181 | + { |
|
| 182 | + return $item->get_datetime('LOG_time'); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * column_PMD_ID |
|
| 189 | + * |
|
| 190 | + * @param \EE_Change_Log $item |
|
| 191 | + * @return string |
|
| 192 | + */ |
|
| 193 | + public function column_PMD_ID(EE_Change_Log $item) |
|
| 194 | + { |
|
| 195 | + if ($item->object() instanceof EE_Payment_Method) { |
|
| 196 | + return $item->object()->admin_name(); |
|
| 197 | + } elseif ($item->object() instanceof EE_Payment && $item->object()->payment_method()) { |
|
| 198 | + return $item->object()->payment_method()->admin_name(); |
|
| 199 | + } elseif ($item->object() instanceof EE_Transaction && $item->object()->payment_method()) { |
|
| 200 | + return sprintf( |
|
| 201 | + esc_html__('Probably %1$s', 'event_espresso'), |
|
| 202 | + $item->object()->payment_method()->admin_name() |
|
| 203 | + ); |
|
| 204 | + } else { |
|
| 205 | + return __("No longer exists", 'event_espresso'); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * column_TXN_ID |
|
| 213 | + * |
|
| 214 | + * @param \EE_Change_Log $item |
|
| 215 | + * @return string |
|
| 216 | + */ |
|
| 217 | + public function column_TXN_ID(EE_Change_Log $item) |
|
| 218 | + { |
|
| 219 | + if ($item->object() instanceof EE_Payment) { |
|
| 220 | + $transaction_id = $item->object()->TXN_ID(); |
|
| 221 | + } elseif ($item->object() instanceof EE_Transaction) { |
|
| 222 | + $transaction_id = $item->object()->ID(); |
|
| 223 | + } else { |
|
| 224 | + $transaction_id = null; |
|
| 225 | + } |
|
| 226 | + if ($transaction_id && EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction', $transaction_id)) { |
|
| 227 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $transaction_id), TXN_ADMIN_URL); |
|
| 228 | + return '<a href="' . $view_txn_lnk_url . '" title="' . sprintf(esc_attr__('click to view transaction #%s', 'event_espresso'), $transaction_id) . '">' . sprintf(__('view txn %s', |
|
| 229 | + 'event_espresso'), $transaction_id) . '</a>'; |
|
| 230 | + } else { |
|
| 231 | + return __("Unable to find transaction", 'event_espresso'); |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | |
| 236 | 236 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function add_download_logs_checkbox() |
| 67 | 67 | { |
| 68 | - echo "<input type='submit' class='button-primary' id='download_results' name='download_results' value='" . __('Download Results', 'event_espresso') . "'>"; |
|
| 68 | + echo "<input type='submit' class='button-primary' id='download_results' name='download_results' value='".__('Download Results', 'event_espresso')."'>"; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -225,8 +225,8 @@ discard block |
||
| 225 | 225 | } |
| 226 | 226 | if ($transaction_id && EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction', $transaction_id)) { |
| 227 | 227 | $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $transaction_id), TXN_ADMIN_URL); |
| 228 | - return '<a href="' . $view_txn_lnk_url . '" title="' . sprintf(esc_attr__('click to view transaction #%s', 'event_espresso'), $transaction_id) . '">' . sprintf(__('view txn %s', |
|
| 229 | - 'event_espresso'), $transaction_id) . '</a>'; |
|
| 228 | + return '<a href="'.$view_txn_lnk_url.'" title="'.sprintf(esc_attr__('click to view transaction #%s', 'event_espresso'), $transaction_id).'">'.sprintf(__('view txn %s', |
|
| 229 | + 'event_espresso'), $transaction_id).'</a>'; |
|
| 230 | 230 | } else { |
| 231 | 231 | return __("Unable to find transaction", 'event_espresso'); |
| 232 | 232 | } |