@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\libraries\iframe_display\Iframe; |
| 5 | 5 | |
| 6 | 6 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
| 7 | - exit( 'No direct script access allowed' ); |
|
| 7 | + exit( 'No direct script access allowed' ); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | |
@@ -21,64 +21,64 @@ discard block |
||
| 21 | 21 | class TicketSelectorIframe extends Iframe |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * TicketSelectorIframe constructor. |
|
| 26 | - * |
|
| 27 | - * @throws \DomainException |
|
| 28 | - * @throws \EE_Error |
|
| 29 | - */ |
|
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - \EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
| 33 | - /** @type \EEM_Event $EEM_Event */ |
|
| 34 | - $EEM_Event = \EE_Registry::instance()->load_model( 'Event' ); |
|
| 35 | - $event = $EEM_Event->get_one_by_ID( |
|
| 36 | - \EE_Registry::instance()->REQ->get( 'event', 0 ) |
|
| 37 | - ); |
|
| 38 | - $ticket_selector = new DisplayTicketSelector(); |
|
| 39 | - $ticket_selector->setIframe( true ); |
|
| 40 | - parent::__construct( |
|
| 41 | - esc_html__( 'Ticket Selector', 'event_espresso' ), |
|
| 42 | - $ticket_selector->display( $event ) |
|
| 43 | - ); |
|
| 44 | - $this->addStylesheets( |
|
| 45 | - apply_filters( |
|
| 46 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
| 47 | - array( |
|
| 48 | - 'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL |
|
| 49 | - . 'ticket_selector_embed.css?ver=' |
|
| 50 | - . EVENT_ESPRESSO_VERSION, |
|
| 51 | - 'ticket_selector' => TICKET_SELECTOR_ASSETS_URL |
|
| 52 | - . 'ticket_selector.css?ver=' |
|
| 53 | - . EVENT_ESPRESSO_VERSION, |
|
| 54 | - ), |
|
| 55 | - $this |
|
| 56 | - ) |
|
| 57 | - ); |
|
| 58 | - if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) { |
|
| 59 | - $this->addStylesheets( array('site_theme' => '' ) ); |
|
| 60 | - } |
|
| 61 | - $this->addScripts( |
|
| 62 | - apply_filters( |
|
| 63 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
| 64 | - array( |
|
| 65 | - 'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL |
|
| 66 | - . 'ticket_selector_iframe_embed.js?ver=' |
|
| 67 | - . EVENT_ESPRESSO_VERSION, |
|
| 68 | - ), |
|
| 69 | - $this |
|
| 70 | - ) |
|
| 71 | - ); |
|
| 72 | - $this->addLocalizedVars( |
|
| 73 | - array( |
|
| 74 | - 'ticket_selector_iframe' => true, |
|
| 75 | - 'EEDTicketSelectorMsg' => __( |
|
| 76 | - 'Please choose at least one ticket before continuing.', |
|
| 77 | - 'event_espresso' |
|
| 78 | - ), |
|
| 79 | - ) |
|
| 80 | - ); |
|
| 81 | - } |
|
| 24 | + /** |
|
| 25 | + * TicketSelectorIframe constructor. |
|
| 26 | + * |
|
| 27 | + * @throws \DomainException |
|
| 28 | + * @throws \EE_Error |
|
| 29 | + */ |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + \EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
| 33 | + /** @type \EEM_Event $EEM_Event */ |
|
| 34 | + $EEM_Event = \EE_Registry::instance()->load_model( 'Event' ); |
|
| 35 | + $event = $EEM_Event->get_one_by_ID( |
|
| 36 | + \EE_Registry::instance()->REQ->get( 'event', 0 ) |
|
| 37 | + ); |
|
| 38 | + $ticket_selector = new DisplayTicketSelector(); |
|
| 39 | + $ticket_selector->setIframe( true ); |
|
| 40 | + parent::__construct( |
|
| 41 | + esc_html__( 'Ticket Selector', 'event_espresso' ), |
|
| 42 | + $ticket_selector->display( $event ) |
|
| 43 | + ); |
|
| 44 | + $this->addStylesheets( |
|
| 45 | + apply_filters( |
|
| 46 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
| 47 | + array( |
|
| 48 | + 'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL |
|
| 49 | + . 'ticket_selector_embed.css?ver=' |
|
| 50 | + . EVENT_ESPRESSO_VERSION, |
|
| 51 | + 'ticket_selector' => TICKET_SELECTOR_ASSETS_URL |
|
| 52 | + . 'ticket_selector.css?ver=' |
|
| 53 | + . EVENT_ESPRESSO_VERSION, |
|
| 54 | + ), |
|
| 55 | + $this |
|
| 56 | + ) |
|
| 57 | + ); |
|
| 58 | + if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) { |
|
| 59 | + $this->addStylesheets( array('site_theme' => '' ) ); |
|
| 60 | + } |
|
| 61 | + $this->addScripts( |
|
| 62 | + apply_filters( |
|
| 63 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
| 64 | + array( |
|
| 65 | + 'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL |
|
| 66 | + . 'ticket_selector_iframe_embed.js?ver=' |
|
| 67 | + . EVENT_ESPRESSO_VERSION, |
|
| 68 | + ), |
|
| 69 | + $this |
|
| 70 | + ) |
|
| 71 | + ); |
|
| 72 | + $this->addLocalizedVars( |
|
| 73 | + array( |
|
| 74 | + 'ticket_selector_iframe' => true, |
|
| 75 | + 'EEDTicketSelectorMsg' => __( |
|
| 76 | + 'Please choose at least one ticket before continuing.', |
|
| 77 | + 'event_espresso' |
|
| 78 | + ), |
|
| 79 | + ) |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | } |
| 84 | 84 | // End of file TicketSelectorIframe.php |
@@ -3,8 +3,8 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | use EventEspresso\core\libraries\iframe_display\Iframe; |
| 5 | 5 | |
| 6 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 7 | - exit( 'No direct script access allowed' ); |
|
| 6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 7 | + exit('No direct script access allowed'); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | |
@@ -29,17 +29,17 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function __construct() |
| 31 | 31 | { |
| 32 | - \EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
| 32 | + \EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 33 | 33 | /** @type \EEM_Event $EEM_Event */ |
| 34 | - $EEM_Event = \EE_Registry::instance()->load_model( 'Event' ); |
|
| 34 | + $EEM_Event = \EE_Registry::instance()->load_model('Event'); |
|
| 35 | 35 | $event = $EEM_Event->get_one_by_ID( |
| 36 | - \EE_Registry::instance()->REQ->get( 'event', 0 ) |
|
| 36 | + \EE_Registry::instance()->REQ->get('event', 0) |
|
| 37 | 37 | ); |
| 38 | 38 | $ticket_selector = new DisplayTicketSelector(); |
| 39 | - $ticket_selector->setIframe( true ); |
|
| 39 | + $ticket_selector->setIframe(true); |
|
| 40 | 40 | parent::__construct( |
| 41 | - esc_html__( 'Ticket Selector', 'event_espresso' ), |
|
| 42 | - $ticket_selector->display( $event ) |
|
| 41 | + esc_html__('Ticket Selector', 'event_espresso'), |
|
| 42 | + $ticket_selector->display($event) |
|
| 43 | 43 | ); |
| 44 | 44 | $this->addStylesheets( |
| 45 | 45 | apply_filters( |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | ) |
| 57 | 57 | ); |
| 58 | 58 | if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) { |
| 59 | - $this->addStylesheets( array('site_theme' => '' ) ); |
|
| 59 | + $this->addStylesheets(array('site_theme' => '')); |
|
| 60 | 60 | } |
| 61 | 61 | $this->addScripts( |
| 62 | 62 | apply_filters( |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -17,151 +17,151 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * enqueues css and js, so that this can be called statically |
|
| 22 | - */ |
|
| 23 | - public static function enqueue_styles_and_scripts() |
|
| 24 | - { |
|
| 25 | - wp_register_style( |
|
| 26 | - 'checkbox_dropdown_selector', |
|
| 27 | - EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css', |
|
| 28 | - array('espresso_default'), |
|
| 29 | - EVENT_ESPRESSO_VERSION |
|
| 30 | - ); |
|
| 31 | - wp_enqueue_style('checkbox_dropdown_selector'); |
|
| 32 | - wp_register_script( |
|
| 33 | - 'checkbox_dropdown_selector', |
|
| 34 | - EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js', |
|
| 35 | - array('jquery'), |
|
| 36 | - EVENT_ESPRESSO_VERSION, |
|
| 37 | - true |
|
| 38 | - ); |
|
| 39 | - wp_enqueue_script('checkbox_dropdown_selector'); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
| 46 | - */ |
|
| 47 | - public function enqueue_js(){ |
|
| 48 | - EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * callback for Iframe::addStylesheets() child class methods |
|
| 55 | - * |
|
| 56 | - * @param array $iframe_css |
|
| 57 | - * @return array |
|
| 58 | - */ |
|
| 59 | - public function iframe_css(array $iframe_css){ |
|
| 60 | - $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css'; |
|
| 61 | - return $iframe_css; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * callback for Iframe::addScripts() child class methods |
|
| 68 | - * |
|
| 69 | - * @param array $iframe_js |
|
| 70 | - * @return array |
|
| 71 | - */ |
|
| 72 | - public function iframe_js(array $iframe_js){ |
|
| 73 | - $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js'; |
|
| 74 | - return $iframe_js; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @throws EE_Error |
|
| 80 | - * @return string of html to display the field |
|
| 81 | - */ |
|
| 82 | - public function display() |
|
| 83 | - { |
|
| 84 | - $input = $this->get_input(); |
|
| 85 | - $select_button_text = $input instanceof EE_Checkbox_Dropdown_Selector_Input ? $input->select_button_text() : ''; |
|
| 86 | - // $multi = count( $input->options() ) > 1 ? TRUE : FALSE; |
|
| 87 | - $input->set_label_sizes(); |
|
| 88 | - $label_size_class = $input->get_label_size_class(); |
|
| 89 | - if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
| 90 | - EE_Error::doing_it_wrong( |
|
| 91 | - 'EE_Checkbox_Display_Strategy::display()', |
|
| 92 | - sprintf( |
|
| 93 | - esc_html__( |
|
| 94 | - 'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"', |
|
| 95 | - 'event_espresso' |
|
| 96 | - ), |
|
| 97 | - $input->html_id(), |
|
| 98 | - var_export($input->raw_value(), true), |
|
| 99 | - $input->html_name() . '[]' |
|
| 100 | - ), |
|
| 101 | - '4.8.1' |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - $html = \EEH_HTML::div('', '', 'checkbox-dropdown-selector-wrap-dv'); |
|
| 107 | - $html .= '<button id="' . $input->html_id() . '-btn"'; |
|
| 108 | - // $html .= ' name="' . $input->html_name() . '"'; |
|
| 109 | - $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"'; |
|
| 110 | - $html .= ' style="' . $input->html_style() . '"'; |
|
| 111 | - $html .= ' data-target="' . $input->html_id() . '-options-dv"'; |
|
| 112 | - $html .= ' ' . $input->html_other_attributes() . '>'; |
|
| 113 | - $html .= '<span class="checkbox-dropdown-selector-selected-spn">'; |
|
| 114 | - $html .= $select_button_text; |
|
| 115 | - $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>'; |
|
| 116 | - $html .= '</button>'; |
|
| 117 | - $html .= EEH_HTML::div( |
|
| 118 | - '', |
|
| 119 | - $input->html_id() . '-options-dv', |
|
| 120 | - 'checkbox-dropdown-selector' |
|
| 121 | - ); |
|
| 122 | - $html .= EEH_HTML::link( |
|
| 123 | - '', |
|
| 124 | - '<span class="dashicons dashicons-no"></span>', |
|
| 125 | - esc_html__('close datetime selector', 'event_espresso'), |
|
| 126 | - '', |
|
| 127 | - 'close-espresso-notice' |
|
| 128 | - ); |
|
| 129 | - $html .= EEH_HTML::ul(); |
|
| 130 | - $input_raw_value = (array)$input->raw_value(); |
|
| 131 | - foreach ($input->options() as $value => $display_text) { |
|
| 132 | - $html .= EEH_HTML::li(); |
|
| 133 | - $value = $input->get_normalization_strategy()->unnormalize_one($value); |
|
| 134 | - $html_id = $this->get_sub_input_id($value); |
|
| 135 | - $html .= EEH_HTML::nl(0, 'checkbox'); |
|
| 136 | - $html .= '<label for="' |
|
| 137 | - . $html_id |
|
| 138 | - . '" id="' |
|
| 139 | - . $html_id |
|
| 140 | - . '-lbl" class="ee-checkbox-label-after' |
|
| 141 | - . $label_size_class |
|
| 142 | - . '">'; |
|
| 143 | - $html .= EEH_HTML::nl(1, 'checkbox'); |
|
| 144 | - $html .= '<input type="checkbox"'; |
|
| 145 | - $html .= ' name="' . $input->html_name() . '[]"'; |
|
| 146 | - $html .= ' id="' . $html_id . '"'; |
|
| 147 | - $html .= ' class="' . $input->html_class() . '-option"'; |
|
| 148 | - $html .= ' style="' . $input->html_style() . '"'; |
|
| 149 | - $html .= ' value="' . esc_attr($value) . '"'; |
|
| 150 | - $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
|
| 151 | - ? ' checked="checked"' |
|
| 152 | - : ''; |
|
| 153 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
| 154 | - $html .= '>'; |
|
| 155 | - $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>'; |
|
| 156 | - $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
| 157 | - $html .= EEH_HTML::lix(); |
|
| 158 | - } |
|
| 159 | - $html .= EEH_HTML::ulx(); |
|
| 160 | - $html .= EEH_HTML::divx(); |
|
| 161 | - $html .= EEH_HTML::divx(); |
|
| 162 | - $html .= \EEH_HTML::br(); |
|
| 163 | - return $html; |
|
| 164 | - } |
|
| 20 | + /** |
|
| 21 | + * enqueues css and js, so that this can be called statically |
|
| 22 | + */ |
|
| 23 | + public static function enqueue_styles_and_scripts() |
|
| 24 | + { |
|
| 25 | + wp_register_style( |
|
| 26 | + 'checkbox_dropdown_selector', |
|
| 27 | + EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css', |
|
| 28 | + array('espresso_default'), |
|
| 29 | + EVENT_ESPRESSO_VERSION |
|
| 30 | + ); |
|
| 31 | + wp_enqueue_style('checkbox_dropdown_selector'); |
|
| 32 | + wp_register_script( |
|
| 33 | + 'checkbox_dropdown_selector', |
|
| 34 | + EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js', |
|
| 35 | + array('jquery'), |
|
| 36 | + EVENT_ESPRESSO_VERSION, |
|
| 37 | + true |
|
| 38 | + ); |
|
| 39 | + wp_enqueue_script('checkbox_dropdown_selector'); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
| 46 | + */ |
|
| 47 | + public function enqueue_js(){ |
|
| 48 | + EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * callback for Iframe::addStylesheets() child class methods |
|
| 55 | + * |
|
| 56 | + * @param array $iframe_css |
|
| 57 | + * @return array |
|
| 58 | + */ |
|
| 59 | + public function iframe_css(array $iframe_css){ |
|
| 60 | + $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css'; |
|
| 61 | + return $iframe_css; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * callback for Iframe::addScripts() child class methods |
|
| 68 | + * |
|
| 69 | + * @param array $iframe_js |
|
| 70 | + * @return array |
|
| 71 | + */ |
|
| 72 | + public function iframe_js(array $iframe_js){ |
|
| 73 | + $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js'; |
|
| 74 | + return $iframe_js; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @throws EE_Error |
|
| 80 | + * @return string of html to display the field |
|
| 81 | + */ |
|
| 82 | + public function display() |
|
| 83 | + { |
|
| 84 | + $input = $this->get_input(); |
|
| 85 | + $select_button_text = $input instanceof EE_Checkbox_Dropdown_Selector_Input ? $input->select_button_text() : ''; |
|
| 86 | + // $multi = count( $input->options() ) > 1 ? TRUE : FALSE; |
|
| 87 | + $input->set_label_sizes(); |
|
| 88 | + $label_size_class = $input->get_label_size_class(); |
|
| 89 | + if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
| 90 | + EE_Error::doing_it_wrong( |
|
| 91 | + 'EE_Checkbox_Display_Strategy::display()', |
|
| 92 | + sprintf( |
|
| 93 | + esc_html__( |
|
| 94 | + 'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"', |
|
| 95 | + 'event_espresso' |
|
| 96 | + ), |
|
| 97 | + $input->html_id(), |
|
| 98 | + var_export($input->raw_value(), true), |
|
| 99 | + $input->html_name() . '[]' |
|
| 100 | + ), |
|
| 101 | + '4.8.1' |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + $html = \EEH_HTML::div('', '', 'checkbox-dropdown-selector-wrap-dv'); |
|
| 107 | + $html .= '<button id="' . $input->html_id() . '-btn"'; |
|
| 108 | + // $html .= ' name="' . $input->html_name() . '"'; |
|
| 109 | + $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"'; |
|
| 110 | + $html .= ' style="' . $input->html_style() . '"'; |
|
| 111 | + $html .= ' data-target="' . $input->html_id() . '-options-dv"'; |
|
| 112 | + $html .= ' ' . $input->html_other_attributes() . '>'; |
|
| 113 | + $html .= '<span class="checkbox-dropdown-selector-selected-spn">'; |
|
| 114 | + $html .= $select_button_text; |
|
| 115 | + $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>'; |
|
| 116 | + $html .= '</button>'; |
|
| 117 | + $html .= EEH_HTML::div( |
|
| 118 | + '', |
|
| 119 | + $input->html_id() . '-options-dv', |
|
| 120 | + 'checkbox-dropdown-selector' |
|
| 121 | + ); |
|
| 122 | + $html .= EEH_HTML::link( |
|
| 123 | + '', |
|
| 124 | + '<span class="dashicons dashicons-no"></span>', |
|
| 125 | + esc_html__('close datetime selector', 'event_espresso'), |
|
| 126 | + '', |
|
| 127 | + 'close-espresso-notice' |
|
| 128 | + ); |
|
| 129 | + $html .= EEH_HTML::ul(); |
|
| 130 | + $input_raw_value = (array)$input->raw_value(); |
|
| 131 | + foreach ($input->options() as $value => $display_text) { |
|
| 132 | + $html .= EEH_HTML::li(); |
|
| 133 | + $value = $input->get_normalization_strategy()->unnormalize_one($value); |
|
| 134 | + $html_id = $this->get_sub_input_id($value); |
|
| 135 | + $html .= EEH_HTML::nl(0, 'checkbox'); |
|
| 136 | + $html .= '<label for="' |
|
| 137 | + . $html_id |
|
| 138 | + . '" id="' |
|
| 139 | + . $html_id |
|
| 140 | + . '-lbl" class="ee-checkbox-label-after' |
|
| 141 | + . $label_size_class |
|
| 142 | + . '">'; |
|
| 143 | + $html .= EEH_HTML::nl(1, 'checkbox'); |
|
| 144 | + $html .= '<input type="checkbox"'; |
|
| 145 | + $html .= ' name="' . $input->html_name() . '[]"'; |
|
| 146 | + $html .= ' id="' . $html_id . '"'; |
|
| 147 | + $html .= ' class="' . $input->html_class() . '-option"'; |
|
| 148 | + $html .= ' style="' . $input->html_style() . '"'; |
|
| 149 | + $html .= ' value="' . esc_attr($value) . '"'; |
|
| 150 | + $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
|
| 151 | + ? ' checked="checked"' |
|
| 152 | + : ''; |
|
| 153 | + $html .= ' ' . $this->_input->other_html_attributes(); |
|
| 154 | + $html .= '>'; |
|
| 155 | + $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>'; |
|
| 156 | + $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
| 157 | + $html .= EEH_HTML::lix(); |
|
| 158 | + } |
|
| 159 | + $html .= EEH_HTML::ulx(); |
|
| 160 | + $html .= EEH_HTML::divx(); |
|
| 161 | + $html .= EEH_HTML::divx(); |
|
| 162 | + $html .= \EEH_HTML::br(); |
|
| 163 | + return $html; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | 166 | |
| 167 | 167 | |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | wp_register_style( |
| 26 | 26 | 'checkbox_dropdown_selector', |
| 27 | - EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css', |
|
| 27 | + EE_GLOBAL_ASSETS_URL.'css/checkbox_dropdown_selector.css', |
|
| 28 | 28 | array('espresso_default'), |
| 29 | 29 | EVENT_ESPRESSO_VERSION |
| 30 | 30 | ); |
| 31 | 31 | wp_enqueue_style('checkbox_dropdown_selector'); |
| 32 | 32 | wp_register_script( |
| 33 | 33 | 'checkbox_dropdown_selector', |
| 34 | - EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js', |
|
| 34 | + EE_GLOBAL_ASSETS_URL.'scripts/checkbox_dropdown_selector.js', |
|
| 35 | 35 | array('jquery'), |
| 36 | 36 | EVENT_ESPRESSO_VERSION, |
| 37 | 37 | true |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | /** |
| 45 | 45 | * Informs the rest of the forms system what CSS and JS is needed to display the input |
| 46 | 46 | */ |
| 47 | - public function enqueue_js(){ |
|
| 47 | + public function enqueue_js() { |
|
| 48 | 48 | EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | * @param array $iframe_css |
| 57 | 57 | * @return array |
| 58 | 58 | */ |
| 59 | - public function iframe_css(array $iframe_css){ |
|
| 60 | - $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'css/checkbox_dropdown_selector.css'; |
|
| 59 | + public function iframe_css(array $iframe_css) { |
|
| 60 | + $iframe_css['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL.'css/checkbox_dropdown_selector.css'; |
|
| 61 | 61 | return $iframe_css; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | * @param array $iframe_js |
| 70 | 70 | * @return array |
| 71 | 71 | */ |
| 72 | - public function iframe_js(array $iframe_js){ |
|
| 73 | - $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL . 'scripts/checkbox_dropdown_selector.js'; |
|
| 72 | + public function iframe_js(array $iframe_js) { |
|
| 73 | + $iframe_js['checkbox_dropdown_selector'] = EE_GLOBAL_ASSETS_URL.'scripts/checkbox_dropdown_selector.js'; |
|
| 74 | 74 | return $iframe_js; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | ), |
| 97 | 97 | $input->html_id(), |
| 98 | 98 | var_export($input->raw_value(), true), |
| 99 | - $input->html_name() . '[]' |
|
| 99 | + $input->html_name().'[]' |
|
| 100 | 100 | ), |
| 101 | 101 | '4.8.1' |
| 102 | 102 | ); |
@@ -104,19 +104,19 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | |
| 106 | 106 | $html = \EEH_HTML::div('', '', 'checkbox-dropdown-selector-wrap-dv'); |
| 107 | - $html .= '<button id="' . $input->html_id() . '-btn"'; |
|
| 107 | + $html .= '<button id="'.$input->html_id().'-btn"'; |
|
| 108 | 108 | // $html .= ' name="' . $input->html_name() . '"'; |
| 109 | - $html .= ' class="' . $input->html_class() . ' checkbox-dropdown-selector-btn button-secondary button"'; |
|
| 110 | - $html .= ' style="' . $input->html_style() . '"'; |
|
| 111 | - $html .= ' data-target="' . $input->html_id() . '-options-dv"'; |
|
| 112 | - $html .= ' ' . $input->html_other_attributes() . '>'; |
|
| 109 | + $html .= ' class="'.$input->html_class().' checkbox-dropdown-selector-btn button-secondary button"'; |
|
| 110 | + $html .= ' style="'.$input->html_style().'"'; |
|
| 111 | + $html .= ' data-target="'.$input->html_id().'-options-dv"'; |
|
| 112 | + $html .= ' '.$input->html_other_attributes().'>'; |
|
| 113 | 113 | $html .= '<span class="checkbox-dropdown-selector-selected-spn">'; |
| 114 | 114 | $html .= $select_button_text; |
| 115 | 115 | $html .= '</span> <span class="dashicons dashicons-arrow-down"></span>'; |
| 116 | 116 | $html .= '</button>'; |
| 117 | 117 | $html .= EEH_HTML::div( |
| 118 | 118 | '', |
| 119 | - $input->html_id() . '-options-dv', |
|
| 119 | + $input->html_id().'-options-dv', |
|
| 120 | 120 | 'checkbox-dropdown-selector' |
| 121 | 121 | ); |
| 122 | 122 | $html .= EEH_HTML::link( |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | 'close-espresso-notice' |
| 128 | 128 | ); |
| 129 | 129 | $html .= EEH_HTML::ul(); |
| 130 | - $input_raw_value = (array)$input->raw_value(); |
|
| 130 | + $input_raw_value = (array) $input->raw_value(); |
|
| 131 | 131 | foreach ($input->options() as $value => $display_text) { |
| 132 | 132 | $html .= EEH_HTML::li(); |
| 133 | 133 | $value = $input->get_normalization_strategy()->unnormalize_one($value); |
@@ -142,18 +142,18 @@ discard block |
||
| 142 | 142 | . '">'; |
| 143 | 143 | $html .= EEH_HTML::nl(1, 'checkbox'); |
| 144 | 144 | $html .= '<input type="checkbox"'; |
| 145 | - $html .= ' name="' . $input->html_name() . '[]"'; |
|
| 146 | - $html .= ' id="' . $html_id . '"'; |
|
| 147 | - $html .= ' class="' . $input->html_class() . '-option"'; |
|
| 148 | - $html .= ' style="' . $input->html_style() . '"'; |
|
| 149 | - $html .= ' value="' . esc_attr($value) . '"'; |
|
| 145 | + $html .= ' name="'.$input->html_name().'[]"'; |
|
| 146 | + $html .= ' id="'.$html_id.'"'; |
|
| 147 | + $html .= ' class="'.$input->html_class().'-option"'; |
|
| 148 | + $html .= ' style="'.$input->html_style().'"'; |
|
| 149 | + $html .= ' value="'.esc_attr($value).'"'; |
|
| 150 | 150 | $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
| 151 | 151 | ? ' checked="checked"' |
| 152 | 152 | : ''; |
| 153 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
| 153 | + $html .= ' '.$this->_input->other_html_attributes(); |
|
| 154 | 154 | $html .= '>'; |
| 155 | - $html .= '<span class="datetime-selector-option-text-spn">' . $display_text . '</span>'; |
|
| 156 | - $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
| 155 | + $html .= '<span class="datetime-selector-option-text-spn">'.$display_text.'</span>'; |
|
| 156 | + $html .= EEH_HTML::nl(-1, 'checkbox').'</label>'; |
|
| 157 | 157 | $html .= EEH_HTML::lix(); |
| 158 | 158 | } |
| 159 | 159 | $html .= EEH_HTML::ulx(); |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -12,165 +12,165 @@ discard block |
||
| 12 | 12 | class EE_Cron_Tasks extends EE_Base |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
| 17 | - * so we'll set our retry time for just over 10 minutes to avoid that |
|
| 18 | - */ |
|
| 19 | - const reschedule_timeout = 605; |
|
| 20 | - |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var EE_Cron_Tasks |
|
| 24 | - */ |
|
| 25 | - private static $_instance; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @return EE_Cron_Tasks |
|
| 30 | - */ |
|
| 31 | - public static function instance() |
|
| 32 | - { |
|
| 33 | - if ( ! self::$_instance instanceof EE_Cron_Tasks) { |
|
| 34 | - self::$_instance = new self(); |
|
| 35 | - } |
|
| 36 | - return self::$_instance; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @access private |
|
| 42 | - */ |
|
| 43 | - private function __construct() |
|
| 44 | - { |
|
| 45 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 46 | - // verify that WP Cron is enabled |
|
| 47 | - if ( |
|
| 48 | - defined('DISABLE_WP_CRON') |
|
| 49 | - && DISABLE_WP_CRON |
|
| 50 | - && is_admin() |
|
| 51 | - && ! get_option('ee_disabled_wp_cron_check') |
|
| 52 | - ) { |
|
| 53 | - /** |
|
| 54 | - * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
| 55 | - * config is loaded. |
|
| 56 | - * This is intentionally using a anonymous function so that its not easily de-registered. Client code |
|
| 57 | - * wanting to not have this functionality can just register its own action at a priority after this one to |
|
| 58 | - * reverse any changes. |
|
| 59 | - */ |
|
| 60 | - add_action('AHEE__EE_System__load_core_configuration__complete', function () { |
|
| 61 | - EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
|
| 62 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 63 | - add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
| 64 | - }); |
|
| 65 | - } |
|
| 66 | - // UPDATE TRANSACTION WITH PAYMENT |
|
| 67 | - add_action( |
|
| 68 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 69 | - array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
| 70 | - 10, 2 |
|
| 71 | - ); |
|
| 72 | - // FINALIZE ABANDONED TRANSACTIONS |
|
| 73 | - add_action( |
|
| 74 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
| 75 | - array('EE_Cron_Tasks', 'check_for_abandoned_transactions'), |
|
| 76 | - 10, 1 |
|
| 77 | - ); |
|
| 15 | + /** |
|
| 16 | + * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
| 17 | + * so we'll set our retry time for just over 10 minutes to avoid that |
|
| 18 | + */ |
|
| 19 | + const reschedule_timeout = 605; |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var EE_Cron_Tasks |
|
| 24 | + */ |
|
| 25 | + private static $_instance; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @return EE_Cron_Tasks |
|
| 30 | + */ |
|
| 31 | + public static function instance() |
|
| 32 | + { |
|
| 33 | + if ( ! self::$_instance instanceof EE_Cron_Tasks) { |
|
| 34 | + self::$_instance = new self(); |
|
| 35 | + } |
|
| 36 | + return self::$_instance; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @access private |
|
| 42 | + */ |
|
| 43 | + private function __construct() |
|
| 44 | + { |
|
| 45 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 46 | + // verify that WP Cron is enabled |
|
| 47 | + if ( |
|
| 48 | + defined('DISABLE_WP_CRON') |
|
| 49 | + && DISABLE_WP_CRON |
|
| 50 | + && is_admin() |
|
| 51 | + && ! get_option('ee_disabled_wp_cron_check') |
|
| 52 | + ) { |
|
| 53 | + /** |
|
| 54 | + * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
| 55 | + * config is loaded. |
|
| 56 | + * This is intentionally using a anonymous function so that its not easily de-registered. Client code |
|
| 57 | + * wanting to not have this functionality can just register its own action at a priority after this one to |
|
| 58 | + * reverse any changes. |
|
| 59 | + */ |
|
| 60 | + add_action('AHEE__EE_System__load_core_configuration__complete', function () { |
|
| 61 | + EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
|
| 62 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
| 63 | + add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
| 64 | + }); |
|
| 65 | + } |
|
| 66 | + // UPDATE TRANSACTION WITH PAYMENT |
|
| 67 | + add_action( |
|
| 68 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 69 | + array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
| 70 | + 10, 2 |
|
| 71 | + ); |
|
| 72 | + // FINALIZE ABANDONED TRANSACTIONS |
|
| 73 | + add_action( |
|
| 74 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
| 75 | + array('EE_Cron_Tasks', 'check_for_abandoned_transactions'), |
|
| 76 | + 10, 1 |
|
| 77 | + ); |
|
| 78 | 78 | // EXPIRED TRANSACTION CHECK |
| 79 | 79 | add_action( |
| 80 | 80 | 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
| 81 | 81 | array( 'EE_Cron_Tasks', 'expired_transaction_check' ), |
| 82 | 82 | 10, 1 |
| 83 | 83 | ); |
| 84 | - // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
|
| 85 | - add_action( |
|
| 86 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 87 | - array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
| 88 | - ); |
|
| 89 | - // logging |
|
| 90 | - add_action( |
|
| 91 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
| 92 | - array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
| 93 | - ); |
|
| 94 | - EE_Registry::instance()->load_lib('Messages_Scheduler'); |
|
| 95 | - //clean out old gateway logs |
|
| 96 | - add_action( |
|
| 97 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs', |
|
| 98 | - array('EE_Cron_Tasks', 'clean_out_old_gateway_logs') |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @access protected |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - public static function log_scheduled_ee_crons() |
|
| 108 | - { |
|
| 109 | - $ee_crons = array( |
|
| 110 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
| 111 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
| 112 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 113 | - ); |
|
| 114 | - $crons = (array) get_option('cron'); |
|
| 115 | - if ( ! is_array($crons)) { |
|
| 116 | - return; |
|
| 117 | - } |
|
| 118 | - foreach ($crons as $timestamp => $cron) { |
|
| 119 | - foreach ($ee_crons as $ee_cron) { |
|
| 120 | - if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) { |
|
| 121 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
| 122 | - foreach ($cron[$ee_cron] as $ee_cron_details) { |
|
| 123 | - if ( ! empty($ee_cron_details['args'])) { |
|
| 124 | - do_action( |
|
| 125 | - 'AHEE_log', |
|
| 126 | - __CLASS__, |
|
| 127 | - __FUNCTION__, |
|
| 128 | - print_r($ee_cron_details['args'], true), |
|
| 129 | - "{$ee_cron} args" |
|
| 130 | - ); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * reschedule_cron_for_transactions_if_maintenance_mode |
|
| 142 | - * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
| 143 | - * |
|
| 144 | - * @param string $cron_task |
|
| 145 | - * @param array $TXN_IDs |
|
| 146 | - * @return bool |
|
| 147 | - * @throws \DomainException |
|
| 148 | - */ |
|
| 84 | + // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
|
| 85 | + add_action( |
|
| 86 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 87 | + array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
| 88 | + ); |
|
| 89 | + // logging |
|
| 90 | + add_action( |
|
| 91 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
| 92 | + array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
| 93 | + ); |
|
| 94 | + EE_Registry::instance()->load_lib('Messages_Scheduler'); |
|
| 95 | + //clean out old gateway logs |
|
| 96 | + add_action( |
|
| 97 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs', |
|
| 98 | + array('EE_Cron_Tasks', 'clean_out_old_gateway_logs') |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @access protected |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + public static function log_scheduled_ee_crons() |
|
| 108 | + { |
|
| 109 | + $ee_crons = array( |
|
| 110 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
| 111 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
| 112 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
| 113 | + ); |
|
| 114 | + $crons = (array) get_option('cron'); |
|
| 115 | + if ( ! is_array($crons)) { |
|
| 116 | + return; |
|
| 117 | + } |
|
| 118 | + foreach ($crons as $timestamp => $cron) { |
|
| 119 | + foreach ($ee_crons as $ee_cron) { |
|
| 120 | + if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) { |
|
| 121 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
| 122 | + foreach ($cron[$ee_cron] as $ee_cron_details) { |
|
| 123 | + if ( ! empty($ee_cron_details['args'])) { |
|
| 124 | + do_action( |
|
| 125 | + 'AHEE_log', |
|
| 126 | + __CLASS__, |
|
| 127 | + __FUNCTION__, |
|
| 128 | + print_r($ee_cron_details['args'], true), |
|
| 129 | + "{$ee_cron} args" |
|
| 130 | + ); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * reschedule_cron_for_transactions_if_maintenance_mode |
|
| 142 | + * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
| 143 | + * |
|
| 144 | + * @param string $cron_task |
|
| 145 | + * @param array $TXN_IDs |
|
| 146 | + * @return bool |
|
| 147 | + * @throws \DomainException |
|
| 148 | + */ |
|
| 149 | 149 | public static function reschedule_cron_for_transactions_if_maintenance_mode( $cron_task, array $TXN_IDs ) { |
| 150 | - if( ! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
| 151 | - throw new \DomainException( |
|
| 152 | - sprintf( |
|
| 153 | - __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
|
| 154 | - $cron_task |
|
| 155 | - ) |
|
| 156 | - ); |
|
| 157 | - } |
|
| 150 | + if( ! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
| 151 | + throw new \DomainException( |
|
| 152 | + sprintf( |
|
| 153 | + __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
|
| 154 | + $cron_task |
|
| 155 | + ) |
|
| 156 | + ); |
|
| 157 | + } |
|
| 158 | 158 | // reschedule the cron if we can't hit the db right now |
| 159 | 159 | if ( ! EE_Maintenance_Mode::instance()->models_can_query() ) { |
| 160 | 160 | foreach( $TXN_IDs as $TXN_ID => $additional_vars ) { |
| 161 | - // ensure $additional_vars is an array |
|
| 162 | - $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
|
| 161 | + // ensure $additional_vars is an array |
|
| 162 | + $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
|
| 163 | 163 | // reset cron job for the TXN |
| 164 | - call_user_func_array( |
|
| 165 | - array('EE_Cron_Tasks', $cron_task), |
|
| 166 | - array_merge( |
|
| 167 | - array( |
|
| 168 | - time() + (10 * MINUTE_IN_SECONDS), |
|
| 169 | - $TXN_ID |
|
| 170 | - ), |
|
| 171 | - $additional_vars |
|
| 172 | - ) |
|
| 173 | - ); |
|
| 164 | + call_user_func_array( |
|
| 165 | + array('EE_Cron_Tasks', $cron_task), |
|
| 166 | + array_merge( |
|
| 167 | + array( |
|
| 168 | + time() + (10 * MINUTE_IN_SECONDS), |
|
| 169 | + $TXN_ID |
|
| 170 | + ), |
|
| 171 | + $additional_vars |
|
| 172 | + ) |
|
| 173 | + ); |
|
| 174 | 174 | } |
| 175 | 175 | return true; |
| 176 | 176 | } |
@@ -180,85 +180,85 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | |
| 182 | 182 | |
| 183 | - /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * array of TXN IDs and the payment |
|
| 188 | - * |
|
| 189 | - * @var array |
|
| 190 | - */ |
|
| 191 | - protected static $_update_transactions_with_payment = array(); |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * schedule_update_transaction_with_payment |
|
| 196 | - * sets a wp_schedule_single_event() for updating any TXNs that may |
|
| 197 | - * require updating due to recently received payments |
|
| 198 | - * |
|
| 199 | - * @param int $timestamp |
|
| 200 | - * @param int $TXN_ID |
|
| 201 | - * @param int $PAY_ID |
|
| 202 | - */ |
|
| 203 | - public static function schedule_update_transaction_with_payment( |
|
| 204 | - $timestamp, |
|
| 205 | - $TXN_ID, |
|
| 206 | - $PAY_ID |
|
| 207 | - ) { |
|
| 208 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 209 | - // validate $TXN_ID and $timestamp |
|
| 210 | - $TXN_ID = absint($TXN_ID); |
|
| 211 | - $timestamp = absint($timestamp); |
|
| 212 | - if ($TXN_ID && $timestamp) { |
|
| 213 | - wp_schedule_single_event( |
|
| 214 | - $timestamp, |
|
| 215 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 216 | - array($TXN_ID, $PAY_ID) |
|
| 217 | - ); |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * setup_update_for_transaction_with_payment |
|
| 224 | - * this is the callback for the action hook: |
|
| 225 | - * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
| 226 | - * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
| 227 | - * The passed TXN_ID and associated payment gets added to an array, and then |
|
| 228 | - * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
| 229 | - * 'shutdown' which will actually handle the processing of any |
|
| 230 | - * transactions requiring updating, because doing so now would be too early |
|
| 231 | - * and the required resources may not be available |
|
| 232 | - * |
|
| 233 | - * @param int $TXN_ID |
|
| 234 | - * @param int $PAY_ID |
|
| 235 | - */ |
|
| 236 | - public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) |
|
| 237 | - { |
|
| 238 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
| 239 | - if (absint($TXN_ID)) { |
|
| 240 | - self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID; |
|
| 241 | - add_action( |
|
| 242 | - 'shutdown', |
|
| 243 | - array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
| 244 | - 5 |
|
| 245 | - ); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * update_transaction_with_payment |
|
| 252 | - * loops through the self::$_abandoned_transactions array |
|
| 253 | - * and attempts to finalize any TXNs that have not been completed |
|
| 254 | - * but have had their sessions expired, most likely due to a user not |
|
| 255 | - * returning from an off-site payment gateway |
|
| 256 | - * |
|
| 257 | - * @throws \EE_Error |
|
| 258 | - */ |
|
| 259 | - public static function update_transaction_with_payment() |
|
| 260 | - { |
|
| 261 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 183 | + /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * array of TXN IDs and the payment |
|
| 188 | + * |
|
| 189 | + * @var array |
|
| 190 | + */ |
|
| 191 | + protected static $_update_transactions_with_payment = array(); |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * schedule_update_transaction_with_payment |
|
| 196 | + * sets a wp_schedule_single_event() for updating any TXNs that may |
|
| 197 | + * require updating due to recently received payments |
|
| 198 | + * |
|
| 199 | + * @param int $timestamp |
|
| 200 | + * @param int $TXN_ID |
|
| 201 | + * @param int $PAY_ID |
|
| 202 | + */ |
|
| 203 | + public static function schedule_update_transaction_with_payment( |
|
| 204 | + $timestamp, |
|
| 205 | + $TXN_ID, |
|
| 206 | + $PAY_ID |
|
| 207 | + ) { |
|
| 208 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 209 | + // validate $TXN_ID and $timestamp |
|
| 210 | + $TXN_ID = absint($TXN_ID); |
|
| 211 | + $timestamp = absint($timestamp); |
|
| 212 | + if ($TXN_ID && $timestamp) { |
|
| 213 | + wp_schedule_single_event( |
|
| 214 | + $timestamp, |
|
| 215 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
| 216 | + array($TXN_ID, $PAY_ID) |
|
| 217 | + ); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * setup_update_for_transaction_with_payment |
|
| 224 | + * this is the callback for the action hook: |
|
| 225 | + * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
| 226 | + * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
| 227 | + * The passed TXN_ID and associated payment gets added to an array, and then |
|
| 228 | + * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
| 229 | + * 'shutdown' which will actually handle the processing of any |
|
| 230 | + * transactions requiring updating, because doing so now would be too early |
|
| 231 | + * and the required resources may not be available |
|
| 232 | + * |
|
| 233 | + * @param int $TXN_ID |
|
| 234 | + * @param int $PAY_ID |
|
| 235 | + */ |
|
| 236 | + public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) |
|
| 237 | + { |
|
| 238 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
| 239 | + if (absint($TXN_ID)) { |
|
| 240 | + self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID; |
|
| 241 | + add_action( |
|
| 242 | + 'shutdown', |
|
| 243 | + array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
| 244 | + 5 |
|
| 245 | + ); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * update_transaction_with_payment |
|
| 252 | + * loops through the self::$_abandoned_transactions array |
|
| 253 | + * and attempts to finalize any TXNs that have not been completed |
|
| 254 | + * but have had their sessions expired, most likely due to a user not |
|
| 255 | + * returning from an off-site payment gateway |
|
| 256 | + * |
|
| 257 | + * @throws \EE_Error |
|
| 258 | + */ |
|
| 259 | + public static function update_transaction_with_payment() |
|
| 260 | + { |
|
| 261 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 262 | 262 | if ( |
| 263 | 263 | // are there any TXNs that need cleaning up ? |
| 264 | 264 | empty( self::$_update_transactions_with_payment ) |
@@ -268,119 +268,119 @@ discard block |
||
| 268 | 268 | self::$_update_transactions_with_payment |
| 269 | 269 | ) |
| 270 | 270 | ) { |
| 271 | - return; |
|
| 272 | - } |
|
| 273 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 274 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 275 | - // set revisit flag for payment processor |
|
| 276 | - $payment_processor->set_revisit(false); |
|
| 277 | - // load EEM_Transaction |
|
| 278 | - EE_Registry::instance()->load_model('Transaction'); |
|
| 279 | - foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
| 280 | - // reschedule the cron if we can't hit the db right now |
|
| 281 | - if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 282 | - // reset cron job for updating the TXN |
|
| 283 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
| 284 | - time() + EE_Cron_Tasks::reschedule_timeout, |
|
| 285 | - $TXN_ID, |
|
| 286 | - $PAY_ID |
|
| 287 | - ); |
|
| 288 | - continue; |
|
| 289 | - } |
|
| 290 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 291 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 292 | - // verify transaction |
|
| 293 | - if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
| 294 | - // now try to update the TXN with any payments |
|
| 295 | - $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
| 296 | - } |
|
| 297 | - unset(self::$_update_transactions_with_payment[$TXN_ID]); |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * array of TXN IDs |
|
| 311 | - * |
|
| 312 | - * @var array |
|
| 313 | - */ |
|
| 314 | - protected static $_abandoned_transactions = array(); |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * schedule_finalize_abandoned_transactions_check |
|
| 319 | - * sets a wp_schedule_single_event() for finalizing any TXNs that may |
|
| 320 | - * have been abandoned during the registration process |
|
| 321 | - * |
|
| 322 | - * @param int $timestamp |
|
| 323 | - * @param int $TXN_ID |
|
| 324 | - */ |
|
| 325 | - public static function schedule_finalize_abandoned_transactions_check( |
|
| 326 | - $timestamp, |
|
| 327 | - $TXN_ID |
|
| 328 | - ) { |
|
| 329 | - // validate $TXN_ID and $timestamp |
|
| 330 | - $TXN_ID = absint($TXN_ID); |
|
| 331 | - $timestamp = absint($timestamp); |
|
| 332 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
| 333 | - if ($TXN_ID && $timestamp) { |
|
| 334 | - wp_schedule_single_event( |
|
| 335 | - $timestamp, |
|
| 336 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
| 337 | - array($TXN_ID) |
|
| 338 | - ); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * check_for_abandoned_transactions |
|
| 345 | - * this is the callback for the action hook: |
|
| 346 | - * 'AHEE__EE_Cron_Tasks__espresso_finalize_abandoned_transactions' |
|
| 347 | - * which is utilized by wp_schedule_single_event() |
|
| 348 | - * in EE_SPCO_Reg_Step_Payment_Options::_post_payment_processing(). |
|
| 349 | - * The passed TXN_ID gets added to an array, and then the |
|
| 350 | - * espresso_finalize_abandoned_transactions() function is hooked into |
|
| 351 | - * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
| 352 | - * processing of any abandoned transactions, because doing so now would be |
|
| 353 | - * too early and the required resources may not be available |
|
| 354 | - * |
|
| 355 | - * @param int $TXN_ID |
|
| 356 | - */ |
|
| 357 | - public static function check_for_abandoned_transactions($TXN_ID = 0) |
|
| 358 | - { |
|
| 359 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
| 360 | - if (absint($TXN_ID)) { |
|
| 361 | - self::$_abandoned_transactions[] = $TXN_ID; |
|
| 362 | - add_action( |
|
| 363 | - 'shutdown', |
|
| 364 | - array('EE_Cron_Tasks', 'finalize_abandoned_transactions'), |
|
| 365 | - 5 |
|
| 366 | - ); |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * finalize_abandoned_transactions |
|
| 373 | - * loops through the self::$_abandoned_transactions array |
|
| 374 | - * and attempts to finalize any TXNs that have not been completed |
|
| 375 | - * but have had their sessions expired, most likely due to a user not |
|
| 376 | - * returning from an off-site payment gateway |
|
| 377 | - * |
|
| 378 | - * @throws \EE_Error |
|
| 379 | - */ |
|
| 380 | - public static function finalize_abandoned_transactions() |
|
| 381 | - { |
|
| 382 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 383 | - if ( |
|
| 271 | + return; |
|
| 272 | + } |
|
| 273 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 274 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 275 | + // set revisit flag for payment processor |
|
| 276 | + $payment_processor->set_revisit(false); |
|
| 277 | + // load EEM_Transaction |
|
| 278 | + EE_Registry::instance()->load_model('Transaction'); |
|
| 279 | + foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
| 280 | + // reschedule the cron if we can't hit the db right now |
|
| 281 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 282 | + // reset cron job for updating the TXN |
|
| 283 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
| 284 | + time() + EE_Cron_Tasks::reschedule_timeout, |
|
| 285 | + $TXN_ID, |
|
| 286 | + $PAY_ID |
|
| 287 | + ); |
|
| 288 | + continue; |
|
| 289 | + } |
|
| 290 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 291 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 292 | + // verify transaction |
|
| 293 | + if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
| 294 | + // now try to update the TXN with any payments |
|
| 295 | + $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
| 296 | + } |
|
| 297 | + unset(self::$_update_transactions_with_payment[$TXN_ID]); |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * array of TXN IDs |
|
| 311 | + * |
|
| 312 | + * @var array |
|
| 313 | + */ |
|
| 314 | + protected static $_abandoned_transactions = array(); |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * schedule_finalize_abandoned_transactions_check |
|
| 319 | + * sets a wp_schedule_single_event() for finalizing any TXNs that may |
|
| 320 | + * have been abandoned during the registration process |
|
| 321 | + * |
|
| 322 | + * @param int $timestamp |
|
| 323 | + * @param int $TXN_ID |
|
| 324 | + */ |
|
| 325 | + public static function schedule_finalize_abandoned_transactions_check( |
|
| 326 | + $timestamp, |
|
| 327 | + $TXN_ID |
|
| 328 | + ) { |
|
| 329 | + // validate $TXN_ID and $timestamp |
|
| 330 | + $TXN_ID = absint($TXN_ID); |
|
| 331 | + $timestamp = absint($timestamp); |
|
| 332 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
| 333 | + if ($TXN_ID && $timestamp) { |
|
| 334 | + wp_schedule_single_event( |
|
| 335 | + $timestamp, |
|
| 336 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
| 337 | + array($TXN_ID) |
|
| 338 | + ); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * check_for_abandoned_transactions |
|
| 345 | + * this is the callback for the action hook: |
|
| 346 | + * 'AHEE__EE_Cron_Tasks__espresso_finalize_abandoned_transactions' |
|
| 347 | + * which is utilized by wp_schedule_single_event() |
|
| 348 | + * in EE_SPCO_Reg_Step_Payment_Options::_post_payment_processing(). |
|
| 349 | + * The passed TXN_ID gets added to an array, and then the |
|
| 350 | + * espresso_finalize_abandoned_transactions() function is hooked into |
|
| 351 | + * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
| 352 | + * processing of any abandoned transactions, because doing so now would be |
|
| 353 | + * too early and the required resources may not be available |
|
| 354 | + * |
|
| 355 | + * @param int $TXN_ID |
|
| 356 | + */ |
|
| 357 | + public static function check_for_abandoned_transactions($TXN_ID = 0) |
|
| 358 | + { |
|
| 359 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
| 360 | + if (absint($TXN_ID)) { |
|
| 361 | + self::$_abandoned_transactions[] = $TXN_ID; |
|
| 362 | + add_action( |
|
| 363 | + 'shutdown', |
|
| 364 | + array('EE_Cron_Tasks', 'finalize_abandoned_transactions'), |
|
| 365 | + 5 |
|
| 366 | + ); |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * finalize_abandoned_transactions |
|
| 373 | + * loops through the self::$_abandoned_transactions array |
|
| 374 | + * and attempts to finalize any TXNs that have not been completed |
|
| 375 | + * but have had their sessions expired, most likely due to a user not |
|
| 376 | + * returning from an off-site payment gateway |
|
| 377 | + * |
|
| 378 | + * @throws \EE_Error |
|
| 379 | + */ |
|
| 380 | + public static function finalize_abandoned_transactions() |
|
| 381 | + { |
|
| 382 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
| 383 | + if ( |
|
| 384 | 384 | // are there any TXNs that need cleaning up ? |
| 385 | 385 | empty( self::$_abandoned_transactions ) |
| 386 | 386 | // reschedule the cron if we can't hit the db right now |
@@ -389,45 +389,45 @@ discard block |
||
| 389 | 389 | self::$_abandoned_transactions |
| 390 | 390 | ) |
| 391 | 391 | ) { |
| 392 | - return; |
|
| 393 | - } |
|
| 394 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 395 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 396 | - // set revisit flag for txn processor |
|
| 397 | - $transaction_processor->set_revisit(false); |
|
| 398 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 399 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 400 | - // load EEM_Transaction |
|
| 401 | - EE_Registry::instance()->load_model('Transaction'); |
|
| 402 | - foreach (self::$_abandoned_transactions as $TXN_ID) { |
|
| 403 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
| 404 | - // reschedule the cron if we can't hit the db right now |
|
| 405 | - if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 406 | - // reset cron job for finalizing the TXN |
|
| 407 | - EE_Cron_Tasks::schedule_finalize_abandoned_transactions_check( |
|
| 408 | - time() + EE_Cron_Tasks::reschedule_timeout, |
|
| 409 | - $TXN_ID |
|
| 410 | - ); |
|
| 411 | - continue; |
|
| 412 | - } |
|
| 413 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 414 | - // verify transaction |
|
| 415 | - if ($transaction instanceof EE_Transaction) { |
|
| 416 | - // don't finalize the TXN if it has already been completed |
|
| 417 | - if ($transaction->all_reg_steps_completed() === true) { |
|
| 418 | - continue; |
|
| 419 | - } |
|
| 420 | - // let's simulate an IPN here which will trigger any notifications that need to go out |
|
| 421 | - $payment_processor->update_txn_based_on_payment($transaction, $transaction->last_payment(), true, |
|
| 422 | - true); |
|
| 423 | - } |
|
| 424 | - unset(self::$_abandoned_transactions[$TXN_ID]); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
|
| 392 | + return; |
|
| 393 | + } |
|
| 394 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 395 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 396 | + // set revisit flag for txn processor |
|
| 397 | + $transaction_processor->set_revisit(false); |
|
| 398 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 399 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 400 | + // load EEM_Transaction |
|
| 401 | + EE_Registry::instance()->load_model('Transaction'); |
|
| 402 | + foreach (self::$_abandoned_transactions as $TXN_ID) { |
|
| 403 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
| 404 | + // reschedule the cron if we can't hit the db right now |
|
| 405 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 406 | + // reset cron job for finalizing the TXN |
|
| 407 | + EE_Cron_Tasks::schedule_finalize_abandoned_transactions_check( |
|
| 408 | + time() + EE_Cron_Tasks::reschedule_timeout, |
|
| 409 | + $TXN_ID |
|
| 410 | + ); |
|
| 411 | + continue; |
|
| 412 | + } |
|
| 413 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 414 | + // verify transaction |
|
| 415 | + if ($transaction instanceof EE_Transaction) { |
|
| 416 | + // don't finalize the TXN if it has already been completed |
|
| 417 | + if ($transaction->all_reg_steps_completed() === true) { |
|
| 418 | + continue; |
|
| 419 | + } |
|
| 420 | + // let's simulate an IPN here which will trigger any notifications that need to go out |
|
| 421 | + $payment_processor->update_txn_based_on_payment($transaction, $transaction->last_payment(), true, |
|
| 422 | + true); |
|
| 423 | + } |
|
| 424 | + unset(self::$_abandoned_transactions[$TXN_ID]); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
|
| 431 | 431 | |
| 432 | 432 | |
| 433 | 433 | /***************** EXPIRED TRANSACTION CHECK *****************/ |
@@ -496,12 +496,12 @@ discard block |
||
| 496 | 496 | |
| 497 | 497 | |
| 498 | 498 | |
| 499 | - /** |
|
| 500 | - * process_expired_transactions |
|
| 501 | - * loops through the self::$_expired_transactions array and processes any failed TXNs |
|
| 502 | - * |
|
| 503 | - * @throws \EE_Error |
|
| 504 | - */ |
|
| 499 | + /** |
|
| 500 | + * process_expired_transactions |
|
| 501 | + * loops through the self::$_expired_transactions array and processes any failed TXNs |
|
| 502 | + * |
|
| 503 | + * @throws \EE_Error |
|
| 504 | + */ |
|
| 505 | 505 | public static function process_expired_transactions() { |
| 506 | 506 | if ( |
| 507 | 507 | // are there any TXNs that need cleaning up ? |
@@ -512,58 +512,58 @@ discard block |
||
| 512 | 512 | self::$_expired_transactions |
| 513 | 513 | ) |
| 514 | 514 | ) { |
| 515 | - return; |
|
| 516 | - } |
|
| 517 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 518 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
| 519 | - // set revisit flag for txn processor |
|
| 520 | - $transaction_processor->set_revisit( false ); |
|
| 521 | - // load EEM_Transaction |
|
| 522 | - EE_Registry::instance()->load_model( 'Transaction' ); |
|
| 523 | - foreach ( self::$_expired_transactions as $TXN_ID ) { |
|
| 524 | - $transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID ); |
|
| 525 | - // verify transaction and whether it is failed or not |
|
| 526 | - if ( $transaction instanceof EE_Transaction) { |
|
| 527 | - switch( $transaction->status_ID() ) { |
|
| 528 | - // Completed TXNs |
|
| 529 | - case EEM_Transaction::complete_status_code : |
|
| 530 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', $transaction ); |
|
| 531 | - break; |
|
| 532 | - // Overpaid TXNs |
|
| 533 | - case EEM_Transaction::overpaid_status_code : |
|
| 534 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', $transaction ); |
|
| 535 | - break; |
|
| 536 | - // Incomplete TXNs |
|
| 537 | - case EEM_Transaction::incomplete_status_code : |
|
| 538 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', $transaction ); |
|
| 539 | - // todo : merge the finalize_abandoned_transactions cron into this one... |
|
| 540 | - // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
| 541 | - break; |
|
| 542 | - // Failed TXNs |
|
| 543 | - case EEM_Transaction::failed_status_code : |
|
| 544 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', $transaction ); |
|
| 545 | - // todo : perform garbage collection here and remove clean_out_junk_transactions() |
|
| 546 | - //$registrations = $transaction->registrations(); |
|
| 547 | - //if ( ! empty( $registrations ) ) { |
|
| 548 | - // foreach ( $registrations as $registration ) { |
|
| 549 | - // if ( $registration instanceof EE_Registration ) { |
|
| 550 | - //$delete_registration = true; |
|
| 551 | - //if ( $registration->attendee() instanceof EE_Attendee ) { |
|
| 552 | - // $delete_registration = false; |
|
| 553 | - //} |
|
| 554 | - //if ( $delete_registration ) { |
|
| 555 | - // $registration->delete_permanently(); |
|
| 556 | - // $registration->delete_related_permanently(); |
|
| 557 | - //} |
|
| 558 | - // } |
|
| 559 | - // } |
|
| 560 | - //} |
|
| 561 | - break; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - } |
|
| 565 | - unset( self::$_expired_transactions[ $TXN_ID ] ); |
|
| 566 | - } |
|
| 515 | + return; |
|
| 516 | + } |
|
| 517 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 518 | + $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
| 519 | + // set revisit flag for txn processor |
|
| 520 | + $transaction_processor->set_revisit( false ); |
|
| 521 | + // load EEM_Transaction |
|
| 522 | + EE_Registry::instance()->load_model( 'Transaction' ); |
|
| 523 | + foreach ( self::$_expired_transactions as $TXN_ID ) { |
|
| 524 | + $transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID ); |
|
| 525 | + // verify transaction and whether it is failed or not |
|
| 526 | + if ( $transaction instanceof EE_Transaction) { |
|
| 527 | + switch( $transaction->status_ID() ) { |
|
| 528 | + // Completed TXNs |
|
| 529 | + case EEM_Transaction::complete_status_code : |
|
| 530 | + do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', $transaction ); |
|
| 531 | + break; |
|
| 532 | + // Overpaid TXNs |
|
| 533 | + case EEM_Transaction::overpaid_status_code : |
|
| 534 | + do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', $transaction ); |
|
| 535 | + break; |
|
| 536 | + // Incomplete TXNs |
|
| 537 | + case EEM_Transaction::incomplete_status_code : |
|
| 538 | + do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', $transaction ); |
|
| 539 | + // todo : merge the finalize_abandoned_transactions cron into this one... |
|
| 540 | + // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
| 541 | + break; |
|
| 542 | + // Failed TXNs |
|
| 543 | + case EEM_Transaction::failed_status_code : |
|
| 544 | + do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', $transaction ); |
|
| 545 | + // todo : perform garbage collection here and remove clean_out_junk_transactions() |
|
| 546 | + //$registrations = $transaction->registrations(); |
|
| 547 | + //if ( ! empty( $registrations ) ) { |
|
| 548 | + // foreach ( $registrations as $registration ) { |
|
| 549 | + // if ( $registration instanceof EE_Registration ) { |
|
| 550 | + //$delete_registration = true; |
|
| 551 | + //if ( $registration->attendee() instanceof EE_Attendee ) { |
|
| 552 | + // $delete_registration = false; |
|
| 553 | + //} |
|
| 554 | + //if ( $delete_registration ) { |
|
| 555 | + // $registration->delete_permanently(); |
|
| 556 | + // $registration->delete_related_permanently(); |
|
| 557 | + //} |
|
| 558 | + // } |
|
| 559 | + // } |
|
| 560 | + //} |
|
| 561 | + break; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + } |
|
| 565 | + unset( self::$_expired_transactions[ $TXN_ID ] ); |
|
| 566 | + } |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | |
@@ -571,33 +571,33 @@ discard block |
||
| 571 | 571 | /************* END OF EXPIRED TRANSACTION CHECK *************/ |
| 572 | 572 | |
| 573 | 573 | |
| 574 | - /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
|
| 575 | - |
|
| 576 | - //when a transaction is initially made, schedule this check. |
|
| 577 | - //if it has NO REG data by the time it has expired, forget about it |
|
| 578 | - public static function clean_out_junk_transactions() |
|
| 579 | - { |
|
| 580 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 581 | - EEM_Transaction::instance('')->delete_junk_transactions(); |
|
| 582 | - EEM_Registration::instance('')->delete_registrations_with_no_transaction(); |
|
| 583 | - EEM_Line_Item::instance('')->delete_line_items_with_no_transaction(); |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
|
| 591 | - */ |
|
| 592 | - public static function clean_out_old_gateway_logs(){ |
|
| 593 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 594 | - $time_diff_for_comparison = apply_filters( |
|
| 595 | - 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
|
| 596 | - "-1 week" |
|
| 597 | - ); |
|
| 598 | - EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
|
| 599 | - } |
|
| 600 | - } |
|
| 574 | + /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
|
| 575 | + |
|
| 576 | + //when a transaction is initially made, schedule this check. |
|
| 577 | + //if it has NO REG data by the time it has expired, forget about it |
|
| 578 | + public static function clean_out_junk_transactions() |
|
| 579 | + { |
|
| 580 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 581 | + EEM_Transaction::instance('')->delete_junk_transactions(); |
|
| 582 | + EEM_Registration::instance('')->delete_registrations_with_no_transaction(); |
|
| 583 | + EEM_Line_Item::instance('')->delete_line_items_with_no_transaction(); |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
|
| 591 | + */ |
|
| 592 | + public static function clean_out_old_gateway_logs(){ |
|
| 593 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 594 | + $time_diff_for_comparison = apply_filters( |
|
| 595 | + 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
|
| 596 | + "-1 week" |
|
| 597 | + ); |
|
| 598 | + EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | 601 | |
| 602 | 602 | |
| 603 | 603 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * wanting to not have this functionality can just register its own action at a priority after this one to |
| 58 | 58 | * reverse any changes. |
| 59 | 59 | */ |
| 60 | - add_action('AHEE__EE_System__load_core_configuration__complete', function () { |
|
| 60 | + add_action('AHEE__EE_System__load_core_configuration__complete', function() { |
|
| 61 | 61 | EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
| 62 | 62 | EE_Registry::instance()->NET_CFG->update_config(true, false); |
| 63 | 63 | add_option('ee_disabled_wp_cron_check', 1, '', false); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | // EXPIRED TRANSACTION CHECK |
| 79 | 79 | add_action( |
| 80 | 80 | 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
| 81 | - array( 'EE_Cron_Tasks', 'expired_transaction_check' ), |
|
| 81 | + array('EE_Cron_Tasks', 'expired_transaction_check'), |
|
| 82 | 82 | 10, 1 |
| 83 | 83 | ); |
| 84 | 84 | // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | * @return bool |
| 147 | 147 | * @throws \DomainException |
| 148 | 148 | */ |
| 149 | - public static function reschedule_cron_for_transactions_if_maintenance_mode( $cron_task, array $TXN_IDs ) { |
|
| 150 | - if( ! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
| 149 | + public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs) { |
|
| 150 | + if ( ! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
| 151 | 151 | throw new \DomainException( |
| 152 | 152 | sprintf( |
| 153 | 153 | __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
@@ -156,8 +156,8 @@ discard block |
||
| 156 | 156 | ); |
| 157 | 157 | } |
| 158 | 158 | // reschedule the cron if we can't hit the db right now |
| 159 | - if ( ! EE_Maintenance_Mode::instance()->models_can_query() ) { |
|
| 160 | - foreach( $TXN_IDs as $TXN_ID => $additional_vars ) { |
|
| 159 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 160 | + foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
|
| 161 | 161 | // ensure $additional_vars is an array |
| 162 | 162 | $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
| 163 | 163 | // reset cron job for the TXN |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | do_action('AHEE_log', __CLASS__, __FUNCTION__); |
| 262 | 262 | if ( |
| 263 | 263 | // are there any TXNs that need cleaning up ? |
| 264 | - empty( self::$_update_transactions_with_payment ) |
|
| 264 | + empty(self::$_update_transactions_with_payment) |
|
| 265 | 265 | // reschedule the cron if we can't hit the db right now |
| 266 | 266 | || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
| 267 | 267 | 'schedule_update_transaction_with_payment', |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | do_action('AHEE_log', __CLASS__, __FUNCTION__); |
| 383 | 383 | if ( |
| 384 | 384 | // are there any TXNs that need cleaning up ? |
| 385 | - empty( self::$_abandoned_transactions ) |
|
| 385 | + empty(self::$_abandoned_transactions) |
|
| 386 | 386 | // reschedule the cron if we can't hit the db right now |
| 387 | 387 | || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
| 388 | 388 | 'schedule_finalize_abandoned_transactions_check', |
@@ -455,13 +455,13 @@ discard block |
||
| 455 | 455 | $TXN_ID |
| 456 | 456 | ) { |
| 457 | 457 | // validate $TXN_ID and $timestamp |
| 458 | - $TXN_ID = absint( $TXN_ID ); |
|
| 459 | - $timestamp = absint( $timestamp ); |
|
| 460 | - if ( $TXN_ID && $timestamp ) { |
|
| 458 | + $TXN_ID = absint($TXN_ID); |
|
| 459 | + $timestamp = absint($timestamp); |
|
| 460 | + if ($TXN_ID && $timestamp) { |
|
| 461 | 461 | wp_schedule_single_event( |
| 462 | 462 | $timestamp, |
| 463 | 463 | 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
| 464 | - array( $TXN_ID ) |
|
| 464 | + array($TXN_ID) |
|
| 465 | 465 | ); |
| 466 | 466 | } |
| 467 | 467 | } |
@@ -483,12 +483,12 @@ discard block |
||
| 483 | 483 | * |
| 484 | 484 | * @param int $TXN_ID |
| 485 | 485 | */ |
| 486 | - public static function expired_transaction_check( $TXN_ID = 0 ) { |
|
| 487 | - if ( absint( $TXN_ID )) { |
|
| 488 | - self::$_expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
| 486 | + public static function expired_transaction_check($TXN_ID = 0) { |
|
| 487 | + if (absint($TXN_ID)) { |
|
| 488 | + self::$_expired_transactions[$TXN_ID] = $TXN_ID; |
|
| 489 | 489 | add_action( |
| 490 | 490 | 'shutdown', |
| 491 | - array( 'EE_Cron_Tasks', 'process_expired_transactions' ), |
|
| 491 | + array('EE_Cron_Tasks', 'process_expired_transactions'), |
|
| 492 | 492 | 5 |
| 493 | 493 | ); |
| 494 | 494 | } |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | public static function process_expired_transactions() { |
| 506 | 506 | if ( |
| 507 | 507 | // are there any TXNs that need cleaning up ? |
| 508 | - empty( self::$_expired_transactions ) |
|
| 508 | + empty(self::$_expired_transactions) |
|
| 509 | 509 | // reschedule the cron if we can't hit the db right now |
| 510 | 510 | || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
| 511 | 511 | 'schedule_expired_transaction_check', |
@@ -515,33 +515,33 @@ discard block |
||
| 515 | 515 | return; |
| 516 | 516 | } |
| 517 | 517 | /** @type EE_Transaction_Processor $transaction_processor */ |
| 518 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
| 518 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 519 | 519 | // set revisit flag for txn processor |
| 520 | - $transaction_processor->set_revisit( false ); |
|
| 520 | + $transaction_processor->set_revisit(false); |
|
| 521 | 521 | // load EEM_Transaction |
| 522 | - EE_Registry::instance()->load_model( 'Transaction' ); |
|
| 523 | - foreach ( self::$_expired_transactions as $TXN_ID ) { |
|
| 524 | - $transaction = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID ); |
|
| 522 | + EE_Registry::instance()->load_model('Transaction'); |
|
| 523 | + foreach (self::$_expired_transactions as $TXN_ID) { |
|
| 524 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 525 | 525 | // verify transaction and whether it is failed or not |
| 526 | - if ( $transaction instanceof EE_Transaction) { |
|
| 527 | - switch( $transaction->status_ID() ) { |
|
| 526 | + if ($transaction instanceof EE_Transaction) { |
|
| 527 | + switch ($transaction->status_ID()) { |
|
| 528 | 528 | // Completed TXNs |
| 529 | 529 | case EEM_Transaction::complete_status_code : |
| 530 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', $transaction ); |
|
| 530 | + do_action('AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', $transaction); |
|
| 531 | 531 | break; |
| 532 | 532 | // Overpaid TXNs |
| 533 | 533 | case EEM_Transaction::overpaid_status_code : |
| 534 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', $transaction ); |
|
| 534 | + do_action('AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', $transaction); |
|
| 535 | 535 | break; |
| 536 | 536 | // Incomplete TXNs |
| 537 | 537 | case EEM_Transaction::incomplete_status_code : |
| 538 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', $transaction ); |
|
| 538 | + do_action('AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', $transaction); |
|
| 539 | 539 | // todo : merge the finalize_abandoned_transactions cron into this one... |
| 540 | 540 | // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
| 541 | 541 | break; |
| 542 | 542 | // Failed TXNs |
| 543 | 543 | case EEM_Transaction::failed_status_code : |
| 544 | - do_action( 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', $transaction ); |
|
| 544 | + do_action('AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', $transaction); |
|
| 545 | 545 | // todo : perform garbage collection here and remove clean_out_junk_transactions() |
| 546 | 546 | //$registrations = $transaction->registrations(); |
| 547 | 547 | //if ( ! empty( $registrations ) ) { |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | } |
| 565 | - unset( self::$_expired_transactions[ $TXN_ID ] ); |
|
| 565 | + unset(self::$_expired_transactions[$TXN_ID]); |
|
| 566 | 566 | } |
| 567 | 567 | } |
| 568 | 568 | |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | /** |
| 590 | 590 | * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
| 591 | 591 | */ |
| 592 | - public static function clean_out_old_gateway_logs(){ |
|
| 592 | + public static function clean_out_old_gateway_logs() { |
|
| 593 | 593 | if (EE_Maintenance_Mode::instance()->models_can_query()) { |
| 594 | 594 | $time_diff_for_comparison = apply_filters( |
| 595 | 595 | 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
@@ -174,22 +174,22 @@ |
||
| 174 | 174 | |
| 175 | 175 | |
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Executes a database query to delete gateway logs. Does not affect model objects, so if you attempt to use |
|
| 179 | - * models after this, they may be out-of-sync with the database |
|
| 180 | - * @param DateTime $datetime |
|
| 181 | - * @return false|int |
|
| 182 | - */ |
|
| 177 | + /** |
|
| 178 | + * Executes a database query to delete gateway logs. Does not affect model objects, so if you attempt to use |
|
| 179 | + * models after this, they may be out-of-sync with the database |
|
| 180 | + * @param DateTime $datetime |
|
| 181 | + * @return false|int |
|
| 182 | + */ |
|
| 183 | 183 | public function delete_gateway_logs_older_than(DateTime $datetime ) { |
| 184 | - global $wpdb; |
|
| 185 | - return $wpdb->query( |
|
| 186 | - $wpdb->prepare( |
|
| 187 | - 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
| 188 | - EEM_Change_Log::type_gateway, |
|
| 189 | - $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
|
| 190 | - ) |
|
| 191 | - ); |
|
| 192 | - } |
|
| 184 | + global $wpdb; |
|
| 185 | + return $wpdb->query( |
|
| 186 | + $wpdb->prepare( |
|
| 187 | + 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
| 188 | + EEM_Change_Log::type_gateway, |
|
| 189 | + $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
|
| 190 | + ) |
|
| 191 | + ); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | 194 | |
| 195 | 195 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * ------------------------------------------------------------------------ |
| 27 | 27 | */ |
| 28 | -class EEM_Change_Log extends EEM_Base{ |
|
| 28 | +class EEM_Change_Log extends EEM_Base { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * the related object was created log type |
@@ -68,19 +68,19 @@ discard block |
||
| 68 | 68 | * @access protected |
| 69 | 69 | * @return EEM_Change_Log |
| 70 | 70 | */ |
| 71 | - protected function __construct( $timezone = null ){ |
|
| 71 | + protected function __construct($timezone = null) { |
|
| 72 | 72 | global $current_user; |
| 73 | - $this->singular_item = __('Log','event_espresso'); |
|
| 74 | - $this->plural_item = __('Logs','event_espresso'); |
|
| 73 | + $this->singular_item = __('Log', 'event_espresso'); |
|
| 74 | + $this->plural_item = __('Logs', 'event_espresso'); |
|
| 75 | 75 | $this->_tables = array( |
| 76 | 76 | 'Log'=> new EE_Primary_Table('esp_log', 'LOG_ID') |
| 77 | 77 | ); |
| 78 | 78 | $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
| 79 | 79 | $this->_fields = array( |
| 80 | 80 | 'Log'=>array( |
| 81 | - 'LOG_ID'=> new EE_Primary_Key_Int_Field('LOG_ID', __('Log ID','event_espresso')), |
|
| 82 | - 'LOG_time'=>new EE_Datetime_Field('LOG_time', __("Log Time", 'event_espresso'), false, EE_Datetime_Field::now ), |
|
| 83 | - 'OBJ_ID'=>new EE_Foreign_Key_String_Field('OBJ_ID', __("Object ID (int or string)", 'event_espresso'), true, NULL,$models_this_can_attach_to), |
|
| 81 | + 'LOG_ID'=> new EE_Primary_Key_Int_Field('LOG_ID', __('Log ID', 'event_espresso')), |
|
| 82 | + 'LOG_time'=>new EE_Datetime_Field('LOG_time', __("Log Time", 'event_espresso'), false, EE_Datetime_Field::now), |
|
| 83 | + 'OBJ_ID'=>new EE_Foreign_Key_String_Field('OBJ_ID', __("Object ID (int or string)", 'event_espresso'), true, NULL, $models_this_can_attach_to), |
|
| 84 | 84 | 'OBJ_type'=>new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Object Type", 'event_espresso'), true, NULL, $models_this_can_attach_to), |
| 85 | 85 | 'LOG_type'=>new EE_Enum_Text_Field('LOG_type', __("Type of log entry", "event_espresso"), false, self::type_debug, |
| 86 | 86 | array( |
@@ -92,24 +92,24 @@ discard block |
||
| 92 | 92 | self::type_gateway=> __("Gateway Interaction (IPN or Direct Payment)", 'event_espresso'), |
| 93 | 93 | )), |
| 94 | 94 | 'LOG_message'=>new EE_Maybe_Serialized_Text_Field('LOG_message', __("Log Message (body)", 'event_espresso'), true), |
| 95 | - 'LOG_wp_user' => new EE_WP_User_Field('LOG_wp_user', __("User who was logged in while this occurred", 'event_espresso'), true ), |
|
| 95 | + 'LOG_wp_user' => new EE_WP_User_Field('LOG_wp_user', __("User who was logged in while this occurred", 'event_espresso'), true), |
|
| 96 | 96 | |
| 97 | 97 | )); |
| 98 | 98 | $this->_model_relations = array(); |
| 99 | - foreach($models_this_can_attach_to as $model){ |
|
| 100 | - if( $model == 'WP_User' ){ |
|
| 101 | - $this->_model_relations[ $model ] = new EE_Belongs_To_Relation(); |
|
| 102 | - }elseif( $model != 'Change_Log' ) { |
|
| 99 | + foreach ($models_this_can_attach_to as $model) { |
|
| 100 | + if ($model == 'WP_User') { |
|
| 101 | + $this->_model_relations[$model] = new EE_Belongs_To_Relation(); |
|
| 102 | + }elseif ($model != 'Change_Log') { |
|
| 103 | 103 | $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | //use completely custom caps for this |
| 107 | 107 | $this->_cap_restriction_generators = false; |
| 108 | 108 | //caps-wise this is all-or-nothing: if you have the default role you can access anything, otherwise nothing |
| 109 | - foreach( $this->_cap_contexts_to_cap_action_map as $cap_context => $action ) { |
|
| 110 | - $this->_cap_restrictions[ $cap_context ][ EE_Restriction_Generator_Base::get_default_restrictions_cap() ] = new EE_Return_None_Where_Conditions(); |
|
| 109 | + foreach ($this->_cap_contexts_to_cap_action_map as $cap_context => $action) { |
|
| 110 | + $this->_cap_restrictions[$cap_context][EE_Restriction_Generator_Base::get_default_restrictions_cap()] = new EE_Return_None_Where_Conditions(); |
|
| 111 | 111 | } |
| 112 | - parent::__construct( $timezone ); |
|
| 112 | + parent::__construct($timezone); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -119,11 +119,11 @@ discard block |
||
| 119 | 119 | * @param EE_Base_Class $related_model_obj |
| 120 | 120 | * @return EE_Change_Log |
| 121 | 121 | */ |
| 122 | - public function log($log_type,$message,$related_model_obj){ |
|
| 123 | - if($related_model_obj instanceof EE_Base_Class){ |
|
| 122 | + public function log($log_type, $message, $related_model_obj) { |
|
| 123 | + if ($related_model_obj instanceof EE_Base_Class) { |
|
| 124 | 124 | $obj_id = $related_model_obj->ID(); |
| 125 | 125 | $obj_type = $related_model_obj->get_model()->get_this_model_name(); |
| 126 | - }else{ |
|
| 126 | + } else { |
|
| 127 | 127 | $obj_id = NULL; |
| 128 | 128 | $obj_type = NULL; |
| 129 | 129 | } |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | * @throws EE_Error |
| 148 | 148 | * @return EE_Change_Log |
| 149 | 149 | */ |
| 150 | - public function gateway_log( $message, $related_obj_id, $related_obj_type ){ |
|
| 151 | - if( ! EE_Registry::instance()->is_model_name($related_obj_type)){ |
|
| 152 | - throw new EE_Error(sprintf(__("'%s' is not a model name. A model name must be provided when making a gateway log. Eg, 'Payment', 'Payment_Method', etc", "event_espresso"),$related_obj_type)); |
|
| 150 | + public function gateway_log($message, $related_obj_id, $related_obj_type) { |
|
| 151 | + if ( ! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
| 152 | + throw new EE_Error(sprintf(__("'%s' is not a model name. A model name must be provided when making a gateway log. Eg, 'Payment', 'Payment_Method', etc", "event_espresso"), $related_obj_type)); |
|
| 153 | 153 | } |
| 154 | 154 | $log = EE_Change_Log::new_instance(array( |
| 155 | 155 | 'LOG_type'=>EEM_Change_Log::type_gateway, |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * @param array $query_params @see EEM_Base::get_all |
| 169 | 169 | * @return array of arrays |
| 170 | 170 | */ |
| 171 | - public function get_all_efficiently($query_params){ |
|
| 171 | + public function get_all_efficiently($query_params) { |
|
| 172 | 172 | return $this->_get_all_wpdb_results($query_params); |
| 173 | 173 | } |
| 174 | 174 | |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | * @param DateTime $datetime |
| 181 | 181 | * @return false|int |
| 182 | 182 | */ |
| 183 | - public function delete_gateway_logs_older_than(DateTime $datetime ) { |
|
| 183 | + public function delete_gateway_logs_older_than(DateTime $datetime) { |
|
| 184 | 184 | global $wpdb; |
| 185 | 185 | return $wpdb->query( |
| 186 | 186 | $wpdb->prepare( |
| 187 | - 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
| 187 | + 'DELETE FROM '.$this->table().' WHERE LOG_type = %s AND LOG_time < %s', |
|
| 188 | 188 | EEM_Change_Log::type_gateway, |
| 189 | 189 | $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
| 190 | 190 | ) |
@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | * @param string $table_name |
| 25 | 25 | * @return string $tableName, having ensured it has the wpdb prefix on the front |
| 26 | 26 | */ |
| 27 | - public function ensureTableNameHasPrefix( $table_name ) |
|
| 27 | + public function ensureTableNameHasPrefix($table_name) |
|
| 28 | 28 | { |
| 29 | 29 | global $wpdb; |
| 30 | - return strpos( $table_name, $wpdb->base_prefix ) === 0 ? $table_name : $wpdb->prefix . $table_name; |
|
| 30 | + return strpos($table_name, $wpdb->base_prefix) === 0 ? $table_name : $wpdb->prefix.$table_name; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | * @param string $table_name |
| 40 | 40 | * @return bool |
| 41 | 41 | */ |
| 42 | - public function tableIsEmpty( $table_name ) |
|
| 42 | + public function tableIsEmpty($table_name) |
|
| 43 | 43 | { |
| 44 | 44 | global $wpdb; |
| 45 | - $table_name = $this->ensureTableNameHasPrefix( $table_name ); |
|
| 46 | - if ( $this->tableExists( $table_name ) ) { |
|
| 47 | - $count = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" ); |
|
| 48 | - return absint( $count ) === 0 ? true : false; |
|
| 45 | + $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
| 46 | + if ($this->tableExists($table_name)) { |
|
| 47 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM $table_name"); |
|
| 48 | + return absint($count) === 0 ? true : false; |
|
| 49 | 49 | } |
| 50 | 50 | return false; |
| 51 | 51 | } |
@@ -60,24 +60,24 @@ discard block |
||
| 60 | 60 | * @param $table_name |
| 61 | 61 | * @return bool |
| 62 | 62 | */ |
| 63 | - public function tableExists( $table_name ) |
|
| 63 | + public function tableExists($table_name) |
|
| 64 | 64 | { |
| 65 | 65 | global $wpdb, $EZSQL_ERROR; |
| 66 | - $table_name = $this->ensureTableNameHasPrefix( $table_name ); |
|
| 66 | + $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
| 67 | 67 | //ignore if this causes an sql error |
| 68 | 68 | $old_error = $wpdb->last_error; |
| 69 | 69 | $old_suppress_errors = $wpdb->suppress_errors(); |
| 70 | - $old_show_errors_value = $wpdb->show_errors( FALSE ); |
|
| 70 | + $old_show_errors_value = $wpdb->show_errors(FALSE); |
|
| 71 | 71 | $ezsql_error_cache = $EZSQL_ERROR; |
| 72 | - $wpdb->get_results( "SELECT * from $table_name LIMIT 1"); |
|
| 73 | - $wpdb->show_errors( $old_show_errors_value ); |
|
| 74 | - $wpdb->suppress_errors( $old_suppress_errors ); |
|
| 72 | + $wpdb->get_results("SELECT * from $table_name LIMIT 1"); |
|
| 73 | + $wpdb->show_errors($old_show_errors_value); |
|
| 74 | + $wpdb->suppress_errors($old_suppress_errors); |
|
| 75 | 75 | $new_error = $wpdb->last_error; |
| 76 | 76 | $wpdb->last_error = $old_error; |
| 77 | 77 | $EZSQL_ERROR = $ezsql_error_cache; |
| 78 | 78 | //if there was a table doesn't exist error |
| 79 | - if( ! empty( $new_error ) ) { |
|
| 80 | - if( |
|
| 79 | + if ( ! empty($new_error)) { |
|
| 80 | + if ( |
|
| 81 | 81 | in_array( |
| 82 | 82 | \EEH_Activation::last_wpdb_error_code(), |
| 83 | 83 | array( |
@@ -87,14 +87,14 @@ discard block |
||
| 87 | 87 | ) |
| 88 | 88 | ) |
| 89 | 89 | || |
| 90 | - preg_match( '~^Table .* doesn\'t exist~', $new_error ) //in case not using mysql and error codes aren't reliable, just check for this error string |
|
| 90 | + preg_match('~^Table .* doesn\'t exist~', $new_error) //in case not using mysql and error codes aren't reliable, just check for this error string |
|
| 91 | 91 | ) { |
| 92 | 92 | return false; |
| 93 | 93 | } else { |
| 94 | 94 | //log this because that's weird. Just use the normal PHP error log |
| 95 | 95 | error_log( |
| 96 | 96 | sprintf( |
| 97 | - __( 'Event Espresso error detected when checking if table existed: %1$s (it wasn\'t just that the table didn\'t exist either)', 'event_espresso' ), |
|
| 97 | + __('Event Espresso error detected when checking if table existed: %1$s (it wasn\'t just that the table didn\'t exist either)', 'event_espresso'), |
|
| 98 | 98 | $new_error |
| 99 | 99 | ) |
| 100 | 100 | ); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @type string Index_comment |
| 125 | 125 | * } |
| 126 | 126 | */ |
| 127 | - public function showIndexes($table_name, $index_name){ |
|
| 127 | + public function showIndexes($table_name, $index_name) { |
|
| 128 | 128 | global $wpdb; |
| 129 | 129 | $table_name = $this->ensureTableNameHasPrefix($table_name); |
| 130 | 130 | $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'"; |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | class TableAnalysis extends \EE_Base { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The maximum number of characters that can be indexed on a column using utf8mb4 collation, |
|
| 21 | - * see https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/ |
|
| 22 | - */ |
|
| 23 | - const INDEX_COLUMN_SIZE = 191; |
|
| 19 | + /** |
|
| 20 | + * The maximum number of characters that can be indexed on a column using utf8mb4 collation, |
|
| 21 | + * see https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/ |
|
| 22 | + */ |
|
| 23 | + const INDEX_COLUMN_SIZE = 191; |
|
| 24 | 24 | /** |
| 25 | 25 | * Returns the table name which will definitely have the wpdb prefix on the front, |
| 26 | 26 | * except if it currently has the wpdb->base_prefix on the front, in which case |
@@ -111,29 +111,29 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | |
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * @param $table_name |
|
| 116 | - * @param $index_name |
|
| 117 | - * @return array of columns used on that index, Each entry is an object with the following properties { |
|
| 118 | - * @type string Table |
|
| 119 | - * @type string Non_unique "0" or "1" |
|
| 120 | - * @type string Key_name |
|
| 121 | - * @type string Seq_in_index |
|
| 122 | - * @type string Column_name |
|
| 123 | - * @type string Collation |
|
| 124 | - * @type string Cardinality |
|
| 125 | - * @type string Sub_part on a column, usually this is just the number of characters from this column to use in indexing |
|
| 126 | - * @type string|null Packed |
|
| 127 | - * @type string Null |
|
| 128 | - * @type string Index_type |
|
| 129 | - * @type string Comment |
|
| 130 | - * @type string Index_comment |
|
| 131 | - * } |
|
| 132 | - */ |
|
| 114 | + /** |
|
| 115 | + * @param $table_name |
|
| 116 | + * @param $index_name |
|
| 117 | + * @return array of columns used on that index, Each entry is an object with the following properties { |
|
| 118 | + * @type string Table |
|
| 119 | + * @type string Non_unique "0" or "1" |
|
| 120 | + * @type string Key_name |
|
| 121 | + * @type string Seq_in_index |
|
| 122 | + * @type string Column_name |
|
| 123 | + * @type string Collation |
|
| 124 | + * @type string Cardinality |
|
| 125 | + * @type string Sub_part on a column, usually this is just the number of characters from this column to use in indexing |
|
| 126 | + * @type string|null Packed |
|
| 127 | + * @type string Null |
|
| 128 | + * @type string Index_type |
|
| 129 | + * @type string Comment |
|
| 130 | + * @type string Index_comment |
|
| 131 | + * } |
|
| 132 | + */ |
|
| 133 | 133 | public function showIndexes($table_name, $index_name){ |
| 134 | - global $wpdb; |
|
| 135 | - $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
| 136 | - $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'"; |
|
| 137 | - return $wpdb->get_results($index_exists_query); |
|
| 138 | - } |
|
| 134 | + global $wpdb; |
|
| 135 | + $table_name = $this->ensureTableNameHasPrefix($table_name); |
|
| 136 | + $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'"; |
|
| 137 | + return $wpdb->get_results($index_exists_query); |
|
| 138 | + } |
|
| 139 | 139 | } |
@@ -390,43 +390,43 @@ |
||
| 390 | 390 | ), |
| 391 | 391 | 'EE_Data_Migration_Class_Base' => array( |
| 392 | 392 | 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
| 393 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 393 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 394 | 394 | ), |
| 395 | 395 | 'EE_DMS_Core_4_1_0' => array( |
| 396 | 396 | 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
| 397 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 397 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 398 | 398 | ), |
| 399 | 399 | 'EE_DMS_Core_4_2_0' => array( |
| 400 | 400 | 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
| 401 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 401 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 402 | 402 | ), |
| 403 | 403 | 'EE_DMS_Core_4_3_0' => array( |
| 404 | 404 | 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
| 405 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 405 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 406 | 406 | ), |
| 407 | 407 | 'EE_DMS_Core_4_4_0' => array( |
| 408 | 408 | 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
| 409 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 409 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 410 | 410 | ), |
| 411 | 411 | 'EE_DMS_Core_4_5_0' => array( |
| 412 | 412 | 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
| 413 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 413 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 414 | 414 | ), |
| 415 | 415 | 'EE_DMS_Core_4_6_0' => array( |
| 416 | 416 | 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
| 417 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 417 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 418 | 418 | ), |
| 419 | 419 | 'EE_DMS_Core_4_7_0' => array( |
| 420 | 420 | 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
| 421 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 421 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 422 | 422 | ), |
| 423 | 423 | 'EE_DMS_Core_4_8_0' => array( |
| 424 | 424 | 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
| 425 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 425 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 426 | 426 | ), |
| 427 | 427 | 'EE_DMS_Core_4_9_0' => array( |
| 428 | 428 | 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
| 429 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 429 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 430 | 430 | ), |
| 431 | 431 | ); |
| 432 | 432 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public static function getTableAnalysis() |
| 63 | 63 | { |
| 64 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 64 | + if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 65 | 65 | self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
| 66 | 66 | } |
| 67 | 67 | return self::$table_analysis; |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public static function getTableManager() |
| 75 | 75 | { |
| 76 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 76 | + if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 77 | 77 | self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
| 78 | 78 | } |
| 79 | 79 | return self::$table_manager; |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | if ($which_to_include === 'old') { |
| 190 | 190 | $cron_tasks = array_filter( |
| 191 | 191 | $cron_tasks, |
| 192 | - function ($value) { |
|
| 192 | + function($value) { |
|
| 193 | 193 | return $value === EEH_Activation::cron_task_no_longer_in_use; |
| 194 | 194 | } |
| 195 | 195 | ); |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | { |
| 220 | 220 | |
| 221 | 221 | foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
| 222 | - if (! wp_next_scheduled($hook_name)) { |
|
| 222 | + if ( ! wp_next_scheduled($hook_name)) { |
|
| 223 | 223 | /** |
| 224 | 224 | * This allows client code to define the initial start timestamp for this schedule. |
| 225 | 225 | */ |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | 3 |
| 325 | 325 | ); |
| 326 | 326 | //EE_Config::reset(); |
| 327 | - if (! EE_Config::logging_enabled()) { |
|
| 327 | + if ( ! EE_Config::logging_enabled()) { |
|
| 328 | 328 | delete_option(EE_Config::LOG_NAME); |
| 329 | 329 | } |
| 330 | 330 | } |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | public static function load_calendar_config() |
| 340 | 340 | { |
| 341 | 341 | // grab array of all plugin folders and loop thru it |
| 342 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 342 | + $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR); |
|
| 343 | 343 | if (empty($plugins)) { |
| 344 | 344 | return; |
| 345 | 345 | } |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | || strpos($plugin, 'calendar') !== false |
| 357 | 357 | ) { |
| 358 | 358 | // this is what we are looking for |
| 359 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 359 | + $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php'; |
|
| 360 | 360 | // does it exist in this folder ? |
| 361 | 361 | if (is_readable($calendar_config)) { |
| 362 | 362 | // YEAH! let's load it |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | ) { |
| 490 | 490 | //update Config with post ID |
| 491 | 491 | $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
| 492 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 492 | + if ( ! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 493 | 493 | $msg = __( |
| 494 | 494 | 'The Event Espresso critical page configuration settings could not be updated.', |
| 495 | 495 | 'event_espresso' |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | public static function get_page_by_ee_shortcode($ee_shortcode) |
| 539 | 539 | { |
| 540 | 540 | global $wpdb; |
| 541 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 541 | + $shortcode_and_opening_bracket = '['.$ee_shortcode; |
|
| 542 | 542 | $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
| 543 | 543 | if ($post_id) { |
| 544 | 544 | return get_post($post_id); |
@@ -564,11 +564,11 @@ discard block |
||
| 564 | 564 | 'post_status' => 'publish', |
| 565 | 565 | 'post_type' => 'page', |
| 566 | 566 | 'comment_status' => 'closed', |
| 567 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 567 | + 'post_content' => '['.$critical_page['code'].']', |
|
| 568 | 568 | ); |
| 569 | 569 | |
| 570 | 570 | $post_id = wp_insert_post($post_args); |
| 571 | - if (! $post_id) { |
|
| 571 | + if ( ! $post_id) { |
|
| 572 | 572 | $msg = sprintf( |
| 573 | 573 | __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
| 574 | 574 | $critical_page['name'] |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | return $critical_page; |
| 578 | 578 | } |
| 579 | 579 | // get newly created post's details |
| 580 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
| 580 | + if ( ! $critical_page['post'] = get_post($post_id)) { |
|
| 581 | 581 | $msg = sprintf( |
| 582 | 582 | __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
| 583 | 583 | $critical_page['name'] |
@@ -664,17 +664,17 @@ discard block |
||
| 664 | 664 | $role_to_check |
| 665 | 665 | ); |
| 666 | 666 | if ($pre_filtered_id !== false) { |
| 667 | - return (int)$pre_filtered_id; |
|
| 667 | + return (int) $pre_filtered_id; |
|
| 668 | 668 | } |
| 669 | 669 | $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
| 670 | 670 | $query = $wpdb->prepare( |
| 671 | 671 | "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
| 672 | - '%' . $role_to_check . '%' |
|
| 672 | + '%'.$role_to_check.'%' |
|
| 673 | 673 | ); |
| 674 | 674 | $user_id = $wpdb->get_var($query); |
| 675 | 675 | $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
| 676 | - if ($user_id && (int)$user_id) { |
|
| 677 | - self::$_default_creator_id = (int)$user_id; |
|
| 676 | + if ($user_id && (int) $user_id) { |
|
| 677 | + self::$_default_creator_id = (int) $user_id; |
|
| 678 | 678 | return self::$_default_creator_id; |
| 679 | 679 | } else { |
| 680 | 680 | return null; |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | } |
| 710 | 710 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 711 | 711 | if ( ! function_exists('dbDelta')) { |
| 712 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 712 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
| 713 | 713 | } |
| 714 | 714 | $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
| 715 | 715 | $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
@@ -920,13 +920,13 @@ discard block |
||
| 920 | 920 | // reset values array |
| 921 | 921 | $QSG_values = array(); |
| 922 | 922 | // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
| 923 | - if (! in_array("$QSG_system", $question_groups)) { |
|
| 923 | + if ( ! in_array("$QSG_system", $question_groups)) { |
|
| 924 | 924 | // add it |
| 925 | 925 | switch ($QSG_system) { |
| 926 | 926 | case 1: |
| 927 | 927 | $QSG_values = array( |
| 928 | 928 | 'QSG_name' => __('Personal Information', 'event_espresso'), |
| 929 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
| 929 | + 'QSG_identifier' => 'personal-information-'.time(), |
|
| 930 | 930 | 'QSG_desc' => '', |
| 931 | 931 | 'QSG_order' => 1, |
| 932 | 932 | 'QSG_show_group_name' => 1, |
@@ -938,7 +938,7 @@ discard block |
||
| 938 | 938 | case 2: |
| 939 | 939 | $QSG_values = array( |
| 940 | 940 | 'QSG_name' => __('Address Information', 'event_espresso'), |
| 941 | - 'QSG_identifier' => 'address-information-' . time(), |
|
| 941 | + 'QSG_identifier' => 'address-information-'.time(), |
|
| 942 | 942 | 'QSG_desc' => '', |
| 943 | 943 | 'QSG_order' => 2, |
| 944 | 944 | 'QSG_show_group_name' => 1, |
@@ -949,7 +949,7 @@ discard block |
||
| 949 | 949 | break; |
| 950 | 950 | } |
| 951 | 951 | // make sure we have some values before inserting them |
| 952 | - if (! empty($QSG_values)) { |
|
| 952 | + if ( ! empty($QSG_values)) { |
|
| 953 | 953 | // insert system question |
| 954 | 954 | $wpdb->insert( |
| 955 | 955 | $table_name, |
@@ -986,7 +986,7 @@ discard block |
||
| 986 | 986 | // reset values array |
| 987 | 987 | $QST_values = array(); |
| 988 | 988 | // if we don't have what we should have |
| 989 | - if (! in_array($QST_system, $questions)) { |
|
| 989 | + if ( ! in_array($QST_system, $questions)) { |
|
| 990 | 990 | // add it |
| 991 | 991 | switch ($QST_system) { |
| 992 | 992 | case 'fname': |
@@ -1138,7 +1138,7 @@ discard block |
||
| 1138 | 1138 | ); |
| 1139 | 1139 | break; |
| 1140 | 1140 | } |
| 1141 | - if (! empty($QST_values)) { |
|
| 1141 | + if ( ! empty($QST_values)) { |
|
| 1142 | 1142 | // insert system question |
| 1143 | 1143 | $wpdb->insert( |
| 1144 | 1144 | $table_name, |
@@ -1199,7 +1199,7 @@ discard block |
||
| 1199 | 1199 | */ |
| 1200 | 1200 | public static function insert_default_payment_methods() |
| 1201 | 1201 | { |
| 1202 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1202 | + if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1203 | 1203 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
| 1204 | 1204 | EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
| 1205 | 1205 | } else { |
@@ -1287,9 +1287,9 @@ discard block |
||
| 1287 | 1287 | $folders = array( |
| 1288 | 1288 | EVENT_ESPRESSO_TEMPLATE_DIR, |
| 1289 | 1289 | EVENT_ESPRESSO_GATEWAY_DIR, |
| 1290 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1291 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1292 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1290 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/', |
|
| 1291 | + EVENT_ESPRESSO_UPLOAD_DIR.'css/', |
|
| 1292 | + EVENT_ESPRESSO_UPLOAD_DIR.'tickets/', |
|
| 1293 | 1293 | ); |
| 1294 | 1294 | foreach ($folders as $folder) { |
| 1295 | 1295 | try { |
@@ -1300,7 +1300,7 @@ discard block |
||
| 1300 | 1300 | sprintf( |
| 1301 | 1301 | __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
| 1302 | 1302 | $folder, |
| 1303 | - '<br />' . $e->getMessage() |
|
| 1303 | + '<br />'.$e->getMessage() |
|
| 1304 | 1304 | ), |
| 1305 | 1305 | __FILE__, __FUNCTION__, __LINE__ |
| 1306 | 1306 | ); |
@@ -1311,7 +1311,7 @@ discard block |
||
| 1311 | 1311 | } |
| 1312 | 1312 | //just add the .htaccess file to the logs directory to begin with. Even if logging |
| 1313 | 1313 | //is disabled, there might be activation errors recorded in there |
| 1314 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1314 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs/'); |
|
| 1315 | 1315 | //remember EE's folders are all good |
| 1316 | 1316 | delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
| 1317 | 1317 | return true; |
@@ -1547,7 +1547,7 @@ discard block |
||
| 1547 | 1547 | // this creates an array for tracking events that have no active ticket prices created |
| 1548 | 1548 | // this allows us to warn admins of the situation so that it can be corrected |
| 1549 | 1549 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
| 1550 | - if (! $espresso_no_ticket_prices) { |
|
| 1550 | + if ( ! $espresso_no_ticket_prices) { |
|
| 1551 | 1551 | add_option('ee_no_ticket_prices', array(), '', false); |
| 1552 | 1552 | } |
| 1553 | 1553 | } |
@@ -1586,7 +1586,7 @@ discard block |
||
| 1586 | 1586 | } |
| 1587 | 1587 | } |
| 1588 | 1588 | //get all our CPTs |
| 1589 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1589 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")"; |
|
| 1590 | 1590 | $cpt_ids = $wpdb->get_col($query); |
| 1591 | 1591 | //delete each post meta and term relations too |
| 1592 | 1592 | foreach ($cpt_ids as $post_id) { |
@@ -1726,7 +1726,7 @@ discard block |
||
| 1726 | 1726 | if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
| 1727 | 1727 | $db_update_sans_ee4 = array(); |
| 1728 | 1728 | foreach ($espresso_db_update as $version => $times_activated) { |
| 1729 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1729 | + if ((string) $version[0] === '3') {//if its NON EE4 |
|
| 1730 | 1730 | $db_update_sans_ee4[$version] = $times_activated; |
| 1731 | 1731 | } |
| 1732 | 1732 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -14,244 +14,244 @@ discard block |
||
| 14 | 14 | class EEH_Activation |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * constant used to indicate a cron task is no longer in use |
|
| 19 | - */ |
|
| 20 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * option name that will indicate whether or not we still |
|
| 24 | - * need to create EE's folders in the uploads directory |
|
| 25 | - * (because if EE was installed without file system access, |
|
| 26 | - * we need to request credentials before we can create them) |
|
| 27 | - */ |
|
| 28 | - const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * WP_User->ID |
|
| 32 | - * |
|
| 33 | - * @var int |
|
| 34 | - */ |
|
| 35 | - private static $_default_creator_id; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * indicates whether or not we've already verified core's default data during this request, |
|
| 39 | - * because after migrations are done, any addons activated while in maintenance mode |
|
| 40 | - * will want to setup their own default data, and they might hook into core's default data |
|
| 41 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 42 | - * This prevents doing that for EVERY single addon. |
|
| 43 | - * |
|
| 44 | - * @var boolean |
|
| 45 | - */ |
|
| 46 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 50 | - */ |
|
| 51 | - private static $table_analysis; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 55 | - */ |
|
| 56 | - private static $table_manager; |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 61 | - */ |
|
| 62 | - public static function getTableAnalysis() |
|
| 63 | - { |
|
| 64 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 65 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 66 | - } |
|
| 67 | - return self::$table_analysis; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return \EventEspresso\core\services\database\TableManager |
|
| 73 | - */ |
|
| 74 | - public static function getTableManager() |
|
| 75 | - { |
|
| 76 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 77 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 78 | - } |
|
| 79 | - return self::$table_manager; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * _ensure_table_name_has_prefix |
|
| 85 | - * |
|
| 86 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 87 | - * @access public |
|
| 88 | - * @static |
|
| 89 | - * @param $table_name |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public static function ensure_table_name_has_prefix($table_name) |
|
| 93 | - { |
|
| 94 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * system_initialization |
|
| 100 | - * ensures the EE configuration settings are loaded with at least default options set |
|
| 101 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 102 | - * |
|
| 103 | - * @access public |
|
| 104 | - * @static |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - public static function system_initialization() |
|
| 108 | - { |
|
| 109 | - EEH_Activation::reset_and_update_config(); |
|
| 110 | - //which is fired BEFORE activation of plugin anyways |
|
| 111 | - EEH_Activation::verify_default_pages_exist(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Sets the database schema and creates folders. This should |
|
| 117 | - * be called on plugin activation and reactivation |
|
| 118 | - * |
|
| 119 | - * @return boolean success, whether the database and folders are setup properly |
|
| 120 | - * @throws \EE_Error |
|
| 121 | - */ |
|
| 122 | - public static function initialize_db_and_folders() |
|
| 123 | - { |
|
| 124 | - $good_filesystem = EEH_Activation::create_upload_directories(); |
|
| 125 | - $good_db = EEH_Activation::create_database_tables(); |
|
| 126 | - return $good_filesystem && $good_db; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * assuming we have an up-to-date database schema, this will populate it |
|
| 132 | - * with default and initial data. This should be called |
|
| 133 | - * upon activation of a new plugin, reactivation, and at the end |
|
| 134 | - * of running migration scripts |
|
| 135 | - * |
|
| 136 | - * @throws \EE_Error |
|
| 137 | - */ |
|
| 138 | - public static function initialize_db_content() |
|
| 139 | - { |
|
| 140 | - //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 141 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 142 | - return; |
|
| 143 | - } |
|
| 144 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 145 | - |
|
| 146 | - EEH_Activation::initialize_system_questions(); |
|
| 147 | - EEH_Activation::insert_default_status_codes(); |
|
| 148 | - EEH_Activation::generate_default_message_templates(); |
|
| 149 | - EEH_Activation::create_no_ticket_prices_array(); |
|
| 150 | - EE_Registry::instance()->CAP->init_caps(); |
|
| 151 | - |
|
| 152 | - EEH_Activation::validate_messages_system(); |
|
| 153 | - EEH_Activation::insert_default_payment_methods(); |
|
| 154 | - //in case we've |
|
| 155 | - EEH_Activation::remove_cron_tasks(); |
|
| 156 | - EEH_Activation::create_cron_tasks(); |
|
| 157 | - // remove all TXN locks since that is being done via extra meta now |
|
| 158 | - delete_option('ee_locked_transactions'); |
|
| 159 | - //also, check for CAF default db content |
|
| 160 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 161 | - //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 162 | - //which users really won't care about on initial activation |
|
| 163 | - EE_Error::overwrite_success(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 169 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 170 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 171 | - * (null) |
|
| 172 | - * |
|
| 173 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 174 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 175 | - * @return array |
|
| 176 | - * @throws \EE_Error |
|
| 177 | - */ |
|
| 178 | - public static function get_cron_tasks($which_to_include) |
|
| 179 | - { |
|
| 180 | - $cron_tasks = apply_filters( |
|
| 181 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 182 | - array( |
|
| 183 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 17 | + /** |
|
| 18 | + * constant used to indicate a cron task is no longer in use |
|
| 19 | + */ |
|
| 20 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * option name that will indicate whether or not we still |
|
| 24 | + * need to create EE's folders in the uploads directory |
|
| 25 | + * (because if EE was installed without file system access, |
|
| 26 | + * we need to request credentials before we can create them) |
|
| 27 | + */ |
|
| 28 | + const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * WP_User->ID |
|
| 32 | + * |
|
| 33 | + * @var int |
|
| 34 | + */ |
|
| 35 | + private static $_default_creator_id; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * indicates whether or not we've already verified core's default data during this request, |
|
| 39 | + * because after migrations are done, any addons activated while in maintenance mode |
|
| 40 | + * will want to setup their own default data, and they might hook into core's default data |
|
| 41 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 42 | + * This prevents doing that for EVERY single addon. |
|
| 43 | + * |
|
| 44 | + * @var boolean |
|
| 45 | + */ |
|
| 46 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 50 | + */ |
|
| 51 | + private static $table_analysis; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 55 | + */ |
|
| 56 | + private static $table_manager; |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 61 | + */ |
|
| 62 | + public static function getTableAnalysis() |
|
| 63 | + { |
|
| 64 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 65 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 66 | + } |
|
| 67 | + return self::$table_analysis; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return \EventEspresso\core\services\database\TableManager |
|
| 73 | + */ |
|
| 74 | + public static function getTableManager() |
|
| 75 | + { |
|
| 76 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 77 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 78 | + } |
|
| 79 | + return self::$table_manager; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * _ensure_table_name_has_prefix |
|
| 85 | + * |
|
| 86 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 87 | + * @access public |
|
| 88 | + * @static |
|
| 89 | + * @param $table_name |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public static function ensure_table_name_has_prefix($table_name) |
|
| 93 | + { |
|
| 94 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * system_initialization |
|
| 100 | + * ensures the EE configuration settings are loaded with at least default options set |
|
| 101 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 102 | + * |
|
| 103 | + * @access public |
|
| 104 | + * @static |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + public static function system_initialization() |
|
| 108 | + { |
|
| 109 | + EEH_Activation::reset_and_update_config(); |
|
| 110 | + //which is fired BEFORE activation of plugin anyways |
|
| 111 | + EEH_Activation::verify_default_pages_exist(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Sets the database schema and creates folders. This should |
|
| 117 | + * be called on plugin activation and reactivation |
|
| 118 | + * |
|
| 119 | + * @return boolean success, whether the database and folders are setup properly |
|
| 120 | + * @throws \EE_Error |
|
| 121 | + */ |
|
| 122 | + public static function initialize_db_and_folders() |
|
| 123 | + { |
|
| 124 | + $good_filesystem = EEH_Activation::create_upload_directories(); |
|
| 125 | + $good_db = EEH_Activation::create_database_tables(); |
|
| 126 | + return $good_filesystem && $good_db; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * assuming we have an up-to-date database schema, this will populate it |
|
| 132 | + * with default and initial data. This should be called |
|
| 133 | + * upon activation of a new plugin, reactivation, and at the end |
|
| 134 | + * of running migration scripts |
|
| 135 | + * |
|
| 136 | + * @throws \EE_Error |
|
| 137 | + */ |
|
| 138 | + public static function initialize_db_content() |
|
| 139 | + { |
|
| 140 | + //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 141 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 142 | + return; |
|
| 143 | + } |
|
| 144 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 145 | + |
|
| 146 | + EEH_Activation::initialize_system_questions(); |
|
| 147 | + EEH_Activation::insert_default_status_codes(); |
|
| 148 | + EEH_Activation::generate_default_message_templates(); |
|
| 149 | + EEH_Activation::create_no_ticket_prices_array(); |
|
| 150 | + EE_Registry::instance()->CAP->init_caps(); |
|
| 151 | + |
|
| 152 | + EEH_Activation::validate_messages_system(); |
|
| 153 | + EEH_Activation::insert_default_payment_methods(); |
|
| 154 | + //in case we've |
|
| 155 | + EEH_Activation::remove_cron_tasks(); |
|
| 156 | + EEH_Activation::create_cron_tasks(); |
|
| 157 | + // remove all TXN locks since that is being done via extra meta now |
|
| 158 | + delete_option('ee_locked_transactions'); |
|
| 159 | + //also, check for CAF default db content |
|
| 160 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 161 | + //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 162 | + //which users really won't care about on initial activation |
|
| 163 | + EE_Error::overwrite_success(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 169 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 170 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 171 | + * (null) |
|
| 172 | + * |
|
| 173 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 174 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 175 | + * @return array |
|
| 176 | + * @throws \EE_Error |
|
| 177 | + */ |
|
| 178 | + public static function get_cron_tasks($which_to_include) |
|
| 179 | + { |
|
| 180 | + $cron_tasks = apply_filters( |
|
| 181 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 182 | + array( |
|
| 183 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 184 | 184 | // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
| 185 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 186 | - //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 187 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 188 | - ) |
|
| 189 | - ); |
|
| 190 | - if ($which_to_include === 'old') { |
|
| 191 | - $cron_tasks = array_filter( |
|
| 192 | - $cron_tasks, |
|
| 193 | - function ($value) { |
|
| 194 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 195 | - } |
|
| 196 | - ); |
|
| 197 | - } elseif ($which_to_include === 'current') { |
|
| 198 | - $cron_tasks = array_filter($cron_tasks); |
|
| 199 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 200 | - throw new EE_Error( |
|
| 201 | - sprintf( |
|
| 202 | - __( |
|
| 203 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 204 | - 'event_espresso' |
|
| 205 | - ), |
|
| 206 | - $which_to_include |
|
| 207 | - ) |
|
| 208 | - ); |
|
| 209 | - } |
|
| 210 | - return $cron_tasks; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 216 | - * |
|
| 217 | - * @throws \EE_Error |
|
| 218 | - */ |
|
| 219 | - public static function create_cron_tasks() |
|
| 220 | - { |
|
| 221 | - |
|
| 222 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 223 | - if (! wp_next_scheduled($hook_name)) { |
|
| 224 | - /** |
|
| 225 | - * This allows client code to define the initial start timestamp for this schedule. |
|
| 226 | - */ |
|
| 227 | - if (is_array($frequency) |
|
| 228 | - && count($frequency) === 2 |
|
| 229 | - && isset($frequency[0], $frequency[1]) |
|
| 230 | - ) { |
|
| 231 | - $start_timestamp = $frequency[0]; |
|
| 232 | - $frequency = $frequency[1]; |
|
| 233 | - } else { |
|
| 234 | - $start_timestamp = time(); |
|
| 235 | - } |
|
| 236 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Remove the currently-existing and now-removed cron tasks. |
|
| 245 | - * |
|
| 246 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 247 | - * @throws \EE_Error |
|
| 248 | - */ |
|
| 249 | - public static function remove_cron_tasks($remove_all = true) |
|
| 250 | - { |
|
| 251 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 252 | - $crons = _get_cron_array(); |
|
| 253 | - $crons = is_array($crons) ? $crons : array(); |
|
| 254 | - /* reminder of what $crons look like: |
|
| 185 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 186 | + //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 187 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 188 | + ) |
|
| 189 | + ); |
|
| 190 | + if ($which_to_include === 'old') { |
|
| 191 | + $cron_tasks = array_filter( |
|
| 192 | + $cron_tasks, |
|
| 193 | + function ($value) { |
|
| 194 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 195 | + } |
|
| 196 | + ); |
|
| 197 | + } elseif ($which_to_include === 'current') { |
|
| 198 | + $cron_tasks = array_filter($cron_tasks); |
|
| 199 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 200 | + throw new EE_Error( |
|
| 201 | + sprintf( |
|
| 202 | + __( |
|
| 203 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 204 | + 'event_espresso' |
|
| 205 | + ), |
|
| 206 | + $which_to_include |
|
| 207 | + ) |
|
| 208 | + ); |
|
| 209 | + } |
|
| 210 | + return $cron_tasks; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 216 | + * |
|
| 217 | + * @throws \EE_Error |
|
| 218 | + */ |
|
| 219 | + public static function create_cron_tasks() |
|
| 220 | + { |
|
| 221 | + |
|
| 222 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 223 | + if (! wp_next_scheduled($hook_name)) { |
|
| 224 | + /** |
|
| 225 | + * This allows client code to define the initial start timestamp for this schedule. |
|
| 226 | + */ |
|
| 227 | + if (is_array($frequency) |
|
| 228 | + && count($frequency) === 2 |
|
| 229 | + && isset($frequency[0], $frequency[1]) |
|
| 230 | + ) { |
|
| 231 | + $start_timestamp = $frequency[0]; |
|
| 232 | + $frequency = $frequency[1]; |
|
| 233 | + } else { |
|
| 234 | + $start_timestamp = time(); |
|
| 235 | + } |
|
| 236 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Remove the currently-existing and now-removed cron tasks. |
|
| 245 | + * |
|
| 246 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 247 | + * @throws \EE_Error |
|
| 248 | + */ |
|
| 249 | + public static function remove_cron_tasks($remove_all = true) |
|
| 250 | + { |
|
| 251 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 252 | + $crons = _get_cron_array(); |
|
| 253 | + $crons = is_array($crons) ? $crons : array(); |
|
| 254 | + /* reminder of what $crons look like: |
|
| 255 | 255 | * Top-level keys are timestamps, and their values are arrays. |
| 256 | 256 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
| 257 | 257 | * and their values are arrays. |
@@ -268,971 +268,971 @@ discard block |
||
| 268 | 268 | * ... |
| 269 | 269 | * ... |
| 270 | 270 | */ |
| 271 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 272 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 273 | - if (is_array($hooks_to_fire_at_time)) { |
|
| 274 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 275 | - if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 276 | - && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 277 | - ) { |
|
| 278 | - unset($crons[$timestamp][$hook_name]); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - //also take care of any empty cron timestamps. |
|
| 282 | - if (empty($hooks_to_fire_at_time)) { |
|
| 283 | - unset($crons[$timestamp]); |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - _set_cron_array($crons); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * CPT_initialization |
|
| 293 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 294 | - * |
|
| 295 | - * @access public |
|
| 296 | - * @static |
|
| 297 | - * @return void |
|
| 298 | - */ |
|
| 299 | - public static function CPT_initialization() |
|
| 300 | - { |
|
| 301 | - // register Custom Post Types |
|
| 302 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 303 | - flush_rewrite_rules(); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * reset_and_update_config |
|
| 310 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 311 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
| 312 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 313 | - * |
|
| 314 | - * @access public |
|
| 315 | - * @static |
|
| 316 | - * @return void |
|
| 317 | - */ |
|
| 318 | - public static function reset_and_update_config() |
|
| 319 | - { |
|
| 320 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 321 | - add_filter( |
|
| 322 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 323 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
| 324 | - 10, |
|
| 325 | - 3 |
|
| 326 | - ); |
|
| 327 | - //EE_Config::reset(); |
|
| 328 | - if (! EE_Config::logging_enabled()) { |
|
| 329 | - delete_option(EE_Config::LOG_NAME); |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * load_calendar_config |
|
| 336 | - * |
|
| 337 | - * @access public |
|
| 338 | - * @return void |
|
| 339 | - */ |
|
| 340 | - public static function load_calendar_config() |
|
| 341 | - { |
|
| 342 | - // grab array of all plugin folders and loop thru it |
|
| 343 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 344 | - if (empty($plugins)) { |
|
| 345 | - return; |
|
| 346 | - } |
|
| 347 | - foreach ($plugins as $plugin_path) { |
|
| 348 | - // grab plugin folder name from path |
|
| 349 | - $plugin = basename($plugin_path); |
|
| 350 | - // drill down to Espresso plugins |
|
| 351 | - // then to calendar related plugins |
|
| 352 | - if ( |
|
| 353 | - strpos($plugin, 'espresso') !== false |
|
| 354 | - || strpos($plugin, 'Espresso') !== false |
|
| 355 | - || strpos($plugin, 'ee4') !== false |
|
| 356 | - || strpos($plugin, 'EE4') !== false |
|
| 357 | - || strpos($plugin, 'calendar') !== false |
|
| 358 | - ) { |
|
| 359 | - // this is what we are looking for |
|
| 360 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 361 | - // does it exist in this folder ? |
|
| 362 | - if (is_readable($calendar_config)) { |
|
| 363 | - // YEAH! let's load it |
|
| 364 | - require_once($calendar_config); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * _migrate_old_config_data |
|
| 374 | - * |
|
| 375 | - * @access public |
|
| 376 | - * @param array|stdClass $settings |
|
| 377 | - * @param string $config |
|
| 378 | - * @param \EE_Config $EE_Config |
|
| 379 | - * @return \stdClass |
|
| 380 | - */ |
|
| 381 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 382 | - { |
|
| 383 | - $convert_from_array = array('addons'); |
|
| 384 | - // in case old settings were saved as an array |
|
| 385 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 386 | - // convert existing settings to an object |
|
| 387 | - $config_array = $settings; |
|
| 388 | - $settings = new stdClass(); |
|
| 389 | - foreach ($config_array as $key => $value) { |
|
| 390 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 391 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 392 | - } else { |
|
| 393 | - $settings->{$key} = $value; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 397 | - } |
|
| 398 | - return $settings; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * deactivate_event_espresso |
|
| 404 | - * |
|
| 405 | - * @access public |
|
| 406 | - * @static |
|
| 407 | - * @return void |
|
| 408 | - */ |
|
| 409 | - public static function deactivate_event_espresso() |
|
| 410 | - { |
|
| 411 | - // check permissions |
|
| 412 | - if (current_user_can('activate_plugins')) { |
|
| 413 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * verify_default_pages_exist |
|
| 423 | - * |
|
| 424 | - * @access public |
|
| 425 | - * @static |
|
| 426 | - * @return void |
|
| 427 | - */ |
|
| 428 | - public static function verify_default_pages_exist() |
|
| 429 | - { |
|
| 430 | - $critical_page_problem = false; |
|
| 431 | - $critical_pages = array( |
|
| 432 | - array( |
|
| 433 | - 'id' => 'reg_page_id', |
|
| 434 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 435 | - 'post' => null, |
|
| 436 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
| 437 | - ), |
|
| 438 | - array( |
|
| 439 | - 'id' => 'txn_page_id', |
|
| 440 | - 'name' => __('Transactions', 'event_espresso'), |
|
| 441 | - 'post' => null, |
|
| 442 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 443 | - ), |
|
| 444 | - array( |
|
| 445 | - 'id' => 'thank_you_page_id', |
|
| 446 | - 'name' => __('Thank You', 'event_espresso'), |
|
| 447 | - 'post' => null, |
|
| 448 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
| 449 | - ), |
|
| 450 | - array( |
|
| 451 | - 'id' => 'cancel_page_id', |
|
| 452 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 453 | - 'post' => null, |
|
| 454 | - 'code' => 'ESPRESSO_CANCELLED', |
|
| 455 | - ), |
|
| 456 | - ); |
|
| 457 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 458 | - foreach ($critical_pages as $critical_page) { |
|
| 459 | - // is critical page ID set in config ? |
|
| 460 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 461 | - // attempt to find post by ID |
|
| 462 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 463 | - } |
|
| 464 | - // no dice? |
|
| 465 | - if ($critical_page['post'] === null) { |
|
| 466 | - // attempt to find post by title |
|
| 467 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 468 | - // still nothing? |
|
| 469 | - if ($critical_page['post'] === null) { |
|
| 470 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 471 | - // REALLY? Still nothing ??!?!? |
|
| 472 | - if ($critical_page['post'] === null) { |
|
| 473 | - $msg = __( |
|
| 474 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 475 | - 'event_espresso' |
|
| 476 | - ); |
|
| 477 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 478 | - break; |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - // track post_shortcodes |
|
| 483 | - if ($critical_page['post']) { |
|
| 484 | - EEH_Activation::_track_critical_page_post_shortcodes($critical_page); |
|
| 485 | - } |
|
| 486 | - // check that Post ID matches critical page ID in config |
|
| 487 | - if ( |
|
| 488 | - isset($critical_page['post']->ID) |
|
| 489 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 490 | - ) { |
|
| 491 | - //update Config with post ID |
|
| 492 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 493 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 494 | - $msg = __( |
|
| 495 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 496 | - 'event_espresso' |
|
| 497 | - ); |
|
| 498 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - $critical_page_problem = |
|
| 502 | - ! isset($critical_page['post']->post_status) |
|
| 503 | - || $critical_page['post']->post_status !== 'publish' |
|
| 504 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 505 | - ? true |
|
| 506 | - : $critical_page_problem; |
|
| 507 | - } |
|
| 508 | - if ($critical_page_problem) { |
|
| 509 | - $msg = sprintf( |
|
| 510 | - __( |
|
| 511 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 512 | - 'event_espresso' |
|
| 513 | - ), |
|
| 514 | - '<a href="' |
|
| 515 | - . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
| 516 | - . '">' |
|
| 517 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 518 | - . '</a>' |
|
| 519 | - ); |
|
| 520 | - EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 521 | - } |
|
| 522 | - if (EE_Error::has_notices()) { |
|
| 523 | - EE_Error::get_notices(false, true, true); |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Returns the first post which uses the specified shortcode |
|
| 531 | - * |
|
| 532 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 533 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 534 | - * "[ESPRESSO_THANK_YOU" |
|
| 535 | - * (we don't search for the closing shortcode bracket because they might have added |
|
| 536 | - * parameter to the shortcode |
|
| 537 | - * @return WP_Post or NULl |
|
| 538 | - */ |
|
| 539 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 540 | - { |
|
| 541 | - global $wpdb; |
|
| 542 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 543 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 544 | - if ($post_id) { |
|
| 545 | - return get_post($post_id); |
|
| 546 | - } else { |
|
| 547 | - return null; |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * This function generates a post for critical espresso pages |
|
| 554 | - * |
|
| 555 | - * @access public |
|
| 556 | - * @static |
|
| 557 | - * @param array $critical_page |
|
| 558 | - * @return array |
|
| 559 | - */ |
|
| 560 | - public static function create_critical_page($critical_page) |
|
| 561 | - { |
|
| 562 | - |
|
| 563 | - $post_args = array( |
|
| 564 | - 'post_title' => $critical_page['name'], |
|
| 565 | - 'post_status' => 'publish', |
|
| 566 | - 'post_type' => 'page', |
|
| 567 | - 'comment_status' => 'closed', |
|
| 568 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 569 | - ); |
|
| 570 | - |
|
| 571 | - $post_id = wp_insert_post($post_args); |
|
| 572 | - if (! $post_id) { |
|
| 573 | - $msg = sprintf( |
|
| 574 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 575 | - $critical_page['name'] |
|
| 576 | - ); |
|
| 577 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 578 | - return $critical_page; |
|
| 579 | - } |
|
| 580 | - // get newly created post's details |
|
| 581 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
| 582 | - $msg = sprintf( |
|
| 583 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 584 | - $critical_page['name'] |
|
| 585 | - ); |
|
| 586 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return $critical_page; |
|
| 590 | - |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * This function adds a critical page's shortcode to the post_shortcodes array |
|
| 599 | - * |
|
| 600 | - * @access private |
|
| 601 | - * @static |
|
| 602 | - * @param array $critical_page |
|
| 603 | - * @return void |
|
| 604 | - */ |
|
| 605 | - private static function _track_critical_page_post_shortcodes($critical_page = array()) |
|
| 606 | - { |
|
| 607 | - // check the goods |
|
| 608 | - if ( ! $critical_page['post'] instanceof WP_Post) { |
|
| 609 | - $msg = sprintf( |
|
| 610 | - __( |
|
| 611 | - 'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', |
|
| 612 | - 'event_espresso' |
|
| 613 | - ), |
|
| 614 | - $critical_page['name'] |
|
| 615 | - ); |
|
| 616 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 617 | - return; |
|
| 618 | - } |
|
| 619 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 620 | - // map shortcode to post |
|
| 621 | - $EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID; |
|
| 622 | - // and make sure it's NOT added to the WP "Posts Page" |
|
| 623 | - // name of the WP Posts Page |
|
| 624 | - $posts_page = EE_Config::get_page_for_posts(); |
|
| 625 | - if (isset($EE_Core_Config->post_shortcodes[$posts_page])) { |
|
| 626 | - unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]); |
|
| 627 | - } |
|
| 628 | - if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) { |
|
| 629 | - unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]); |
|
| 630 | - } |
|
| 631 | - // update post_shortcode CFG |
|
| 632 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 633 | - // verify that saved ID in the config matches the ID for the post the shortcode is on |
|
| 634 | - if ( |
|
| 635 | - EE_Registry::instance()->CFG->core->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] |
|
| 636 | - !== $critical_page['post']->ID |
|
| 637 | - ) { |
|
| 638 | - $msg = sprintf( |
|
| 639 | - __( |
|
| 640 | - 'The Event Espresso critical page shortcode for the %s page could not be configured properly.', |
|
| 641 | - 'event_espresso' |
|
| 642 | - ), |
|
| 643 | - $critical_page['name'] |
|
| 644 | - ); |
|
| 645 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 653 | - * The role being used to check is filterable. |
|
| 654 | - * |
|
| 655 | - * @since 4.6.0 |
|
| 656 | - * @global WPDB $wpdb |
|
| 657 | - * @return mixed null|int WP_user ID or NULL |
|
| 658 | - */ |
|
| 659 | - public static function get_default_creator_id() |
|
| 660 | - { |
|
| 661 | - global $wpdb; |
|
| 662 | - if ( ! empty(self::$_default_creator_id)) { |
|
| 663 | - return self::$_default_creator_id; |
|
| 664 | - }/**/ |
|
| 665 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 666 | - //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 667 | - $pre_filtered_id = apply_filters( |
|
| 668 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 669 | - false, |
|
| 670 | - $role_to_check |
|
| 671 | - ); |
|
| 672 | - if ($pre_filtered_id !== false) { |
|
| 673 | - return (int)$pre_filtered_id; |
|
| 674 | - } |
|
| 675 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 676 | - $query = $wpdb->prepare( |
|
| 677 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 678 | - '%' . $role_to_check . '%' |
|
| 679 | - ); |
|
| 680 | - $user_id = $wpdb->get_var($query); |
|
| 681 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 682 | - if ($user_id && (int)$user_id) { |
|
| 683 | - self::$_default_creator_id = (int)$user_id; |
|
| 684 | - return self::$_default_creator_id; |
|
| 685 | - } else { |
|
| 686 | - return null; |
|
| 687 | - } |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - |
|
| 692 | - /** |
|
| 693 | - * used by EE and EE addons during plugin activation to create tables. |
|
| 694 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 695 | - * but includes extra logic regarding activations. |
|
| 696 | - * |
|
| 697 | - * @access public |
|
| 698 | - * @static |
|
| 699 | - * @param string $table_name without the $wpdb->prefix |
|
| 700 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 701 | - * table query) |
|
| 702 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 703 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 704 | - * and new once this function is done (ie, you really do want to CREATE a |
|
| 705 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 706 | - * you just want to verify the table exists and matches this definition |
|
| 707 | - * (and if it HAS data in it you want to leave it be) |
|
| 708 | - * @return void |
|
| 709 | - * @throws EE_Error if there are database errors |
|
| 710 | - */ |
|
| 711 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 712 | - { |
|
| 713 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 714 | - return; |
|
| 715 | - } |
|
| 716 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 717 | - if ( ! function_exists('dbDelta')) { |
|
| 718 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 719 | - } |
|
| 720 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 721 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 722 | - // do we need to first delete an existing version of this table ? |
|
| 723 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 724 | - // ok, delete the table... but ONLY if it's empty |
|
| 725 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 726 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 727 | - if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 728 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 729 | - } else if ( ! $deleted_safely) { |
|
| 730 | - // so we should be more cautious rather than just dropping tables so easily |
|
| 731 | - error_log( |
|
| 732 | - sprintf( |
|
| 733 | - __( |
|
| 734 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 735 | - 'event_espresso' |
|
| 736 | - ), |
|
| 737 | - $wp_table_name, |
|
| 738 | - '<br/>', |
|
| 739 | - 'espresso_db_update' |
|
| 740 | - ) |
|
| 741 | - ); |
|
| 742 | - } |
|
| 743 | - } |
|
| 744 | - $engine = str_replace('ENGINE=', '', $engine); |
|
| 745 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * add_column_if_it_doesn't_exist |
|
| 752 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 753 | - * |
|
| 754 | - * @access public |
|
| 755 | - * @static |
|
| 756 | - * @deprecated instead use TableManager::addColumn() |
|
| 757 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 758 | - * @param string $column_name |
|
| 759 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 760 | - * 'VARCHAR(10)' |
|
| 761 | - * @return bool|int |
|
| 762 | - */ |
|
| 763 | - public static function add_column_if_it_doesnt_exist( |
|
| 764 | - $table_name, |
|
| 765 | - $column_name, |
|
| 766 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
| 767 | - ) { |
|
| 768 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * get_fields_on_table |
|
| 774 | - * Gets all the fields on the database table. |
|
| 775 | - * |
|
| 776 | - * @access public |
|
| 777 | - * @deprecated instead use TableManager::getTableColumns() |
|
| 778 | - * @static |
|
| 779 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
| 780 | - * @return array of database column names |
|
| 781 | - */ |
|
| 782 | - public static function get_fields_on_table($table_name = null) |
|
| 783 | - { |
|
| 784 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - |
|
| 788 | - /** |
|
| 789 | - * db_table_is_empty |
|
| 790 | - * |
|
| 791 | - * @access public\ |
|
| 792 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 793 | - * @static |
|
| 794 | - * @param string $table_name |
|
| 795 | - * @return bool |
|
| 796 | - */ |
|
| 797 | - public static function db_table_is_empty($table_name) |
|
| 798 | - { |
|
| 799 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * delete_db_table_if_empty |
|
| 805 | - * |
|
| 806 | - * @access public |
|
| 807 | - * @static |
|
| 808 | - * @param string $table_name |
|
| 809 | - * @return bool | int |
|
| 810 | - */ |
|
| 811 | - public static function delete_db_table_if_empty($table_name) |
|
| 812 | - { |
|
| 813 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 814 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 815 | - } |
|
| 816 | - return false; |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - |
|
| 820 | - /** |
|
| 821 | - * delete_unused_db_table |
|
| 822 | - * |
|
| 823 | - * @access public |
|
| 824 | - * @static |
|
| 825 | - * @deprecated instead use TableManager::dropTable() |
|
| 826 | - * @param string $table_name |
|
| 827 | - * @return bool | int |
|
| 828 | - */ |
|
| 829 | - public static function delete_unused_db_table($table_name) |
|
| 830 | - { |
|
| 831 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * drop_index |
|
| 837 | - * |
|
| 838 | - * @access public |
|
| 839 | - * @static |
|
| 840 | - * @deprecated instead use TableManager::dropIndex() |
|
| 841 | - * @param string $table_name |
|
| 842 | - * @param string $index_name |
|
| 843 | - * @return bool | int |
|
| 844 | - */ |
|
| 845 | - public static function drop_index($table_name, $index_name) |
|
| 846 | - { |
|
| 847 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - |
|
| 851 | - |
|
| 852 | - /** |
|
| 853 | - * create_database_tables |
|
| 854 | - * |
|
| 855 | - * @access public |
|
| 856 | - * @static |
|
| 857 | - * @throws EE_Error |
|
| 858 | - * @return boolean success (whether database is setup properly or not) |
|
| 859 | - */ |
|
| 860 | - public static function create_database_tables() |
|
| 861 | - { |
|
| 862 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 863 | - //find the migration script that sets the database to be compatible with the code |
|
| 864 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 865 | - if ($dms_name) { |
|
| 866 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 867 | - $current_data_migration_script->set_migrating(false); |
|
| 868 | - $current_data_migration_script->schema_changes_before_migration(); |
|
| 869 | - $current_data_migration_script->schema_changes_after_migration(); |
|
| 870 | - if ($current_data_migration_script->get_errors()) { |
|
| 871 | - if (WP_DEBUG) { |
|
| 872 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 873 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 874 | - } |
|
| 875 | - } else { |
|
| 876 | - EE_Error::add_error( |
|
| 877 | - __( |
|
| 878 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 271 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 272 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 273 | + if (is_array($hooks_to_fire_at_time)) { |
|
| 274 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 275 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 276 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 277 | + ) { |
|
| 278 | + unset($crons[$timestamp][$hook_name]); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + //also take care of any empty cron timestamps. |
|
| 282 | + if (empty($hooks_to_fire_at_time)) { |
|
| 283 | + unset($crons[$timestamp]); |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + _set_cron_array($crons); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * CPT_initialization |
|
| 293 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 294 | + * |
|
| 295 | + * @access public |
|
| 296 | + * @static |
|
| 297 | + * @return void |
|
| 298 | + */ |
|
| 299 | + public static function CPT_initialization() |
|
| 300 | + { |
|
| 301 | + // register Custom Post Types |
|
| 302 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 303 | + flush_rewrite_rules(); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * reset_and_update_config |
|
| 310 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 311 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
| 312 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 313 | + * |
|
| 314 | + * @access public |
|
| 315 | + * @static |
|
| 316 | + * @return void |
|
| 317 | + */ |
|
| 318 | + public static function reset_and_update_config() |
|
| 319 | + { |
|
| 320 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 321 | + add_filter( |
|
| 322 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 323 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
| 324 | + 10, |
|
| 325 | + 3 |
|
| 326 | + ); |
|
| 327 | + //EE_Config::reset(); |
|
| 328 | + if (! EE_Config::logging_enabled()) { |
|
| 329 | + delete_option(EE_Config::LOG_NAME); |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * load_calendar_config |
|
| 336 | + * |
|
| 337 | + * @access public |
|
| 338 | + * @return void |
|
| 339 | + */ |
|
| 340 | + public static function load_calendar_config() |
|
| 341 | + { |
|
| 342 | + // grab array of all plugin folders and loop thru it |
|
| 343 | + $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 344 | + if (empty($plugins)) { |
|
| 345 | + return; |
|
| 346 | + } |
|
| 347 | + foreach ($plugins as $plugin_path) { |
|
| 348 | + // grab plugin folder name from path |
|
| 349 | + $plugin = basename($plugin_path); |
|
| 350 | + // drill down to Espresso plugins |
|
| 351 | + // then to calendar related plugins |
|
| 352 | + if ( |
|
| 353 | + strpos($plugin, 'espresso') !== false |
|
| 354 | + || strpos($plugin, 'Espresso') !== false |
|
| 355 | + || strpos($plugin, 'ee4') !== false |
|
| 356 | + || strpos($plugin, 'EE4') !== false |
|
| 357 | + || strpos($plugin, 'calendar') !== false |
|
| 358 | + ) { |
|
| 359 | + // this is what we are looking for |
|
| 360 | + $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 361 | + // does it exist in this folder ? |
|
| 362 | + if (is_readable($calendar_config)) { |
|
| 363 | + // YEAH! let's load it |
|
| 364 | + require_once($calendar_config); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * _migrate_old_config_data |
|
| 374 | + * |
|
| 375 | + * @access public |
|
| 376 | + * @param array|stdClass $settings |
|
| 377 | + * @param string $config |
|
| 378 | + * @param \EE_Config $EE_Config |
|
| 379 | + * @return \stdClass |
|
| 380 | + */ |
|
| 381 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 382 | + { |
|
| 383 | + $convert_from_array = array('addons'); |
|
| 384 | + // in case old settings were saved as an array |
|
| 385 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 386 | + // convert existing settings to an object |
|
| 387 | + $config_array = $settings; |
|
| 388 | + $settings = new stdClass(); |
|
| 389 | + foreach ($config_array as $key => $value) { |
|
| 390 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 391 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 392 | + } else { |
|
| 393 | + $settings->{$key} = $value; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 397 | + } |
|
| 398 | + return $settings; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * deactivate_event_espresso |
|
| 404 | + * |
|
| 405 | + * @access public |
|
| 406 | + * @static |
|
| 407 | + * @return void |
|
| 408 | + */ |
|
| 409 | + public static function deactivate_event_espresso() |
|
| 410 | + { |
|
| 411 | + // check permissions |
|
| 412 | + if (current_user_can('activate_plugins')) { |
|
| 413 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * verify_default_pages_exist |
|
| 423 | + * |
|
| 424 | + * @access public |
|
| 425 | + * @static |
|
| 426 | + * @return void |
|
| 427 | + */ |
|
| 428 | + public static function verify_default_pages_exist() |
|
| 429 | + { |
|
| 430 | + $critical_page_problem = false; |
|
| 431 | + $critical_pages = array( |
|
| 432 | + array( |
|
| 433 | + 'id' => 'reg_page_id', |
|
| 434 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 435 | + 'post' => null, |
|
| 436 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
| 437 | + ), |
|
| 438 | + array( |
|
| 439 | + 'id' => 'txn_page_id', |
|
| 440 | + 'name' => __('Transactions', 'event_espresso'), |
|
| 441 | + 'post' => null, |
|
| 442 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 443 | + ), |
|
| 444 | + array( |
|
| 445 | + 'id' => 'thank_you_page_id', |
|
| 446 | + 'name' => __('Thank You', 'event_espresso'), |
|
| 447 | + 'post' => null, |
|
| 448 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
| 449 | + ), |
|
| 450 | + array( |
|
| 451 | + 'id' => 'cancel_page_id', |
|
| 452 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 453 | + 'post' => null, |
|
| 454 | + 'code' => 'ESPRESSO_CANCELLED', |
|
| 455 | + ), |
|
| 456 | + ); |
|
| 457 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 458 | + foreach ($critical_pages as $critical_page) { |
|
| 459 | + // is critical page ID set in config ? |
|
| 460 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 461 | + // attempt to find post by ID |
|
| 462 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 463 | + } |
|
| 464 | + // no dice? |
|
| 465 | + if ($critical_page['post'] === null) { |
|
| 466 | + // attempt to find post by title |
|
| 467 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 468 | + // still nothing? |
|
| 469 | + if ($critical_page['post'] === null) { |
|
| 470 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 471 | + // REALLY? Still nothing ??!?!? |
|
| 472 | + if ($critical_page['post'] === null) { |
|
| 473 | + $msg = __( |
|
| 474 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 475 | + 'event_espresso' |
|
| 476 | + ); |
|
| 477 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 478 | + break; |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + // track post_shortcodes |
|
| 483 | + if ($critical_page['post']) { |
|
| 484 | + EEH_Activation::_track_critical_page_post_shortcodes($critical_page); |
|
| 485 | + } |
|
| 486 | + // check that Post ID matches critical page ID in config |
|
| 487 | + if ( |
|
| 488 | + isset($critical_page['post']->ID) |
|
| 489 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 490 | + ) { |
|
| 491 | + //update Config with post ID |
|
| 492 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 493 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 494 | + $msg = __( |
|
| 495 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 496 | + 'event_espresso' |
|
| 497 | + ); |
|
| 498 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + $critical_page_problem = |
|
| 502 | + ! isset($critical_page['post']->post_status) |
|
| 503 | + || $critical_page['post']->post_status !== 'publish' |
|
| 504 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 505 | + ? true |
|
| 506 | + : $critical_page_problem; |
|
| 507 | + } |
|
| 508 | + if ($critical_page_problem) { |
|
| 509 | + $msg = sprintf( |
|
| 510 | + __( |
|
| 511 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 512 | + 'event_espresso' |
|
| 513 | + ), |
|
| 514 | + '<a href="' |
|
| 515 | + . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
| 516 | + . '">' |
|
| 517 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 518 | + . '</a>' |
|
| 519 | + ); |
|
| 520 | + EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 521 | + } |
|
| 522 | + if (EE_Error::has_notices()) { |
|
| 523 | + EE_Error::get_notices(false, true, true); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Returns the first post which uses the specified shortcode |
|
| 531 | + * |
|
| 532 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 533 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 534 | + * "[ESPRESSO_THANK_YOU" |
|
| 535 | + * (we don't search for the closing shortcode bracket because they might have added |
|
| 536 | + * parameter to the shortcode |
|
| 537 | + * @return WP_Post or NULl |
|
| 538 | + */ |
|
| 539 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 540 | + { |
|
| 541 | + global $wpdb; |
|
| 542 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 543 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 544 | + if ($post_id) { |
|
| 545 | + return get_post($post_id); |
|
| 546 | + } else { |
|
| 547 | + return null; |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * This function generates a post for critical espresso pages |
|
| 554 | + * |
|
| 555 | + * @access public |
|
| 556 | + * @static |
|
| 557 | + * @param array $critical_page |
|
| 558 | + * @return array |
|
| 559 | + */ |
|
| 560 | + public static function create_critical_page($critical_page) |
|
| 561 | + { |
|
| 562 | + |
|
| 563 | + $post_args = array( |
|
| 564 | + 'post_title' => $critical_page['name'], |
|
| 565 | + 'post_status' => 'publish', |
|
| 566 | + 'post_type' => 'page', |
|
| 567 | + 'comment_status' => 'closed', |
|
| 568 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 569 | + ); |
|
| 570 | + |
|
| 571 | + $post_id = wp_insert_post($post_args); |
|
| 572 | + if (! $post_id) { |
|
| 573 | + $msg = sprintf( |
|
| 574 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 575 | + $critical_page['name'] |
|
| 576 | + ); |
|
| 577 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 578 | + return $critical_page; |
|
| 579 | + } |
|
| 580 | + // get newly created post's details |
|
| 581 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
| 582 | + $msg = sprintf( |
|
| 583 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 584 | + $critical_page['name'] |
|
| 585 | + ); |
|
| 586 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return $critical_page; |
|
| 590 | + |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * This function adds a critical page's shortcode to the post_shortcodes array |
|
| 599 | + * |
|
| 600 | + * @access private |
|
| 601 | + * @static |
|
| 602 | + * @param array $critical_page |
|
| 603 | + * @return void |
|
| 604 | + */ |
|
| 605 | + private static function _track_critical_page_post_shortcodes($critical_page = array()) |
|
| 606 | + { |
|
| 607 | + // check the goods |
|
| 608 | + if ( ! $critical_page['post'] instanceof WP_Post) { |
|
| 609 | + $msg = sprintf( |
|
| 610 | + __( |
|
| 611 | + 'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.', |
|
| 612 | + 'event_espresso' |
|
| 613 | + ), |
|
| 614 | + $critical_page['name'] |
|
| 615 | + ); |
|
| 616 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 617 | + return; |
|
| 618 | + } |
|
| 619 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 620 | + // map shortcode to post |
|
| 621 | + $EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID; |
|
| 622 | + // and make sure it's NOT added to the WP "Posts Page" |
|
| 623 | + // name of the WP Posts Page |
|
| 624 | + $posts_page = EE_Config::get_page_for_posts(); |
|
| 625 | + if (isset($EE_Core_Config->post_shortcodes[$posts_page])) { |
|
| 626 | + unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]); |
|
| 627 | + } |
|
| 628 | + if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) { |
|
| 629 | + unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]); |
|
| 630 | + } |
|
| 631 | + // update post_shortcode CFG |
|
| 632 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 633 | + // verify that saved ID in the config matches the ID for the post the shortcode is on |
|
| 634 | + if ( |
|
| 635 | + EE_Registry::instance()->CFG->core->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] |
|
| 636 | + !== $critical_page['post']->ID |
|
| 637 | + ) { |
|
| 638 | + $msg = sprintf( |
|
| 639 | + __( |
|
| 640 | + 'The Event Espresso critical page shortcode for the %s page could not be configured properly.', |
|
| 641 | + 'event_espresso' |
|
| 642 | + ), |
|
| 643 | + $critical_page['name'] |
|
| 644 | + ); |
|
| 645 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 653 | + * The role being used to check is filterable. |
|
| 654 | + * |
|
| 655 | + * @since 4.6.0 |
|
| 656 | + * @global WPDB $wpdb |
|
| 657 | + * @return mixed null|int WP_user ID or NULL |
|
| 658 | + */ |
|
| 659 | + public static function get_default_creator_id() |
|
| 660 | + { |
|
| 661 | + global $wpdb; |
|
| 662 | + if ( ! empty(self::$_default_creator_id)) { |
|
| 663 | + return self::$_default_creator_id; |
|
| 664 | + }/**/ |
|
| 665 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 666 | + //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 667 | + $pre_filtered_id = apply_filters( |
|
| 668 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 669 | + false, |
|
| 670 | + $role_to_check |
|
| 671 | + ); |
|
| 672 | + if ($pre_filtered_id !== false) { |
|
| 673 | + return (int)$pre_filtered_id; |
|
| 674 | + } |
|
| 675 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 676 | + $query = $wpdb->prepare( |
|
| 677 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 678 | + '%' . $role_to_check . '%' |
|
| 679 | + ); |
|
| 680 | + $user_id = $wpdb->get_var($query); |
|
| 681 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 682 | + if ($user_id && (int)$user_id) { |
|
| 683 | + self::$_default_creator_id = (int)$user_id; |
|
| 684 | + return self::$_default_creator_id; |
|
| 685 | + } else { |
|
| 686 | + return null; |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + |
|
| 692 | + /** |
|
| 693 | + * used by EE and EE addons during plugin activation to create tables. |
|
| 694 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 695 | + * but includes extra logic regarding activations. |
|
| 696 | + * |
|
| 697 | + * @access public |
|
| 698 | + * @static |
|
| 699 | + * @param string $table_name without the $wpdb->prefix |
|
| 700 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 701 | + * table query) |
|
| 702 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 703 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 704 | + * and new once this function is done (ie, you really do want to CREATE a |
|
| 705 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 706 | + * you just want to verify the table exists and matches this definition |
|
| 707 | + * (and if it HAS data in it you want to leave it be) |
|
| 708 | + * @return void |
|
| 709 | + * @throws EE_Error if there are database errors |
|
| 710 | + */ |
|
| 711 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 712 | + { |
|
| 713 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 714 | + return; |
|
| 715 | + } |
|
| 716 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 717 | + if ( ! function_exists('dbDelta')) { |
|
| 718 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 719 | + } |
|
| 720 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 721 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 722 | + // do we need to first delete an existing version of this table ? |
|
| 723 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 724 | + // ok, delete the table... but ONLY if it's empty |
|
| 725 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 726 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 727 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 728 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 729 | + } else if ( ! $deleted_safely) { |
|
| 730 | + // so we should be more cautious rather than just dropping tables so easily |
|
| 731 | + error_log( |
|
| 732 | + sprintf( |
|
| 733 | + __( |
|
| 734 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 735 | + 'event_espresso' |
|
| 736 | + ), |
|
| 737 | + $wp_table_name, |
|
| 738 | + '<br/>', |
|
| 739 | + 'espresso_db_update' |
|
| 740 | + ) |
|
| 741 | + ); |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | + $engine = str_replace('ENGINE=', '', $engine); |
|
| 745 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * add_column_if_it_doesn't_exist |
|
| 752 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 753 | + * |
|
| 754 | + * @access public |
|
| 755 | + * @static |
|
| 756 | + * @deprecated instead use TableManager::addColumn() |
|
| 757 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 758 | + * @param string $column_name |
|
| 759 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 760 | + * 'VARCHAR(10)' |
|
| 761 | + * @return bool|int |
|
| 762 | + */ |
|
| 763 | + public static function add_column_if_it_doesnt_exist( |
|
| 764 | + $table_name, |
|
| 765 | + $column_name, |
|
| 766 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
| 767 | + ) { |
|
| 768 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * get_fields_on_table |
|
| 774 | + * Gets all the fields on the database table. |
|
| 775 | + * |
|
| 776 | + * @access public |
|
| 777 | + * @deprecated instead use TableManager::getTableColumns() |
|
| 778 | + * @static |
|
| 779 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
| 780 | + * @return array of database column names |
|
| 781 | + */ |
|
| 782 | + public static function get_fields_on_table($table_name = null) |
|
| 783 | + { |
|
| 784 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + |
|
| 788 | + /** |
|
| 789 | + * db_table_is_empty |
|
| 790 | + * |
|
| 791 | + * @access public\ |
|
| 792 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 793 | + * @static |
|
| 794 | + * @param string $table_name |
|
| 795 | + * @return bool |
|
| 796 | + */ |
|
| 797 | + public static function db_table_is_empty($table_name) |
|
| 798 | + { |
|
| 799 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * delete_db_table_if_empty |
|
| 805 | + * |
|
| 806 | + * @access public |
|
| 807 | + * @static |
|
| 808 | + * @param string $table_name |
|
| 809 | + * @return bool | int |
|
| 810 | + */ |
|
| 811 | + public static function delete_db_table_if_empty($table_name) |
|
| 812 | + { |
|
| 813 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 814 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 815 | + } |
|
| 816 | + return false; |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + |
|
| 820 | + /** |
|
| 821 | + * delete_unused_db_table |
|
| 822 | + * |
|
| 823 | + * @access public |
|
| 824 | + * @static |
|
| 825 | + * @deprecated instead use TableManager::dropTable() |
|
| 826 | + * @param string $table_name |
|
| 827 | + * @return bool | int |
|
| 828 | + */ |
|
| 829 | + public static function delete_unused_db_table($table_name) |
|
| 830 | + { |
|
| 831 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * drop_index |
|
| 837 | + * |
|
| 838 | + * @access public |
|
| 839 | + * @static |
|
| 840 | + * @deprecated instead use TableManager::dropIndex() |
|
| 841 | + * @param string $table_name |
|
| 842 | + * @param string $index_name |
|
| 843 | + * @return bool | int |
|
| 844 | + */ |
|
| 845 | + public static function drop_index($table_name, $index_name) |
|
| 846 | + { |
|
| 847 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + |
|
| 851 | + |
|
| 852 | + /** |
|
| 853 | + * create_database_tables |
|
| 854 | + * |
|
| 855 | + * @access public |
|
| 856 | + * @static |
|
| 857 | + * @throws EE_Error |
|
| 858 | + * @return boolean success (whether database is setup properly or not) |
|
| 859 | + */ |
|
| 860 | + public static function create_database_tables() |
|
| 861 | + { |
|
| 862 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 863 | + //find the migration script that sets the database to be compatible with the code |
|
| 864 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 865 | + if ($dms_name) { |
|
| 866 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 867 | + $current_data_migration_script->set_migrating(false); |
|
| 868 | + $current_data_migration_script->schema_changes_before_migration(); |
|
| 869 | + $current_data_migration_script->schema_changes_after_migration(); |
|
| 870 | + if ($current_data_migration_script->get_errors()) { |
|
| 871 | + if (WP_DEBUG) { |
|
| 872 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 873 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 874 | + } |
|
| 875 | + } else { |
|
| 876 | + EE_Error::add_error( |
|
| 877 | + __( |
|
| 878 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 879 | 879 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
| 880 | - 'event_espresso' |
|
| 881 | - ) |
|
| 882 | - ); |
|
| 883 | - } |
|
| 884 | - return false; |
|
| 885 | - } |
|
| 886 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 887 | - } else { |
|
| 888 | - EE_Error::add_error( |
|
| 889 | - __( |
|
| 890 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 880 | + 'event_espresso' |
|
| 881 | + ) |
|
| 882 | + ); |
|
| 883 | + } |
|
| 884 | + return false; |
|
| 885 | + } |
|
| 886 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 887 | + } else { |
|
| 888 | + EE_Error::add_error( |
|
| 889 | + __( |
|
| 890 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 891 | 891 | structure. So database is probably not setup properly', |
| 892 | - 'event_espresso' |
|
| 893 | - ), |
|
| 894 | - __FILE__, |
|
| 895 | - __FUNCTION__, |
|
| 896 | - __LINE__ |
|
| 897 | - ); |
|
| 898 | - return false; |
|
| 899 | - } |
|
| 900 | - return true; |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - |
|
| 904 | - |
|
| 905 | - /** |
|
| 906 | - * initialize_system_questions |
|
| 907 | - * |
|
| 908 | - * @access public |
|
| 909 | - * @static |
|
| 910 | - * @return void |
|
| 911 | - */ |
|
| 912 | - public static function initialize_system_questions() |
|
| 913 | - { |
|
| 914 | - // QUESTION GROUPS |
|
| 915 | - global $wpdb; |
|
| 916 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 917 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 918 | - // what we have |
|
| 919 | - $question_groups = $wpdb->get_col($SQL); |
|
| 920 | - // check the response |
|
| 921 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 922 | - // what we should have |
|
| 923 | - $QSG_systems = array(1, 2); |
|
| 924 | - // loop thru what we should have and compare to what we have |
|
| 925 | - foreach ($QSG_systems as $QSG_system) { |
|
| 926 | - // reset values array |
|
| 927 | - $QSG_values = array(); |
|
| 928 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 929 | - if (! in_array("$QSG_system", $question_groups)) { |
|
| 930 | - // add it |
|
| 931 | - switch ($QSG_system) { |
|
| 932 | - case 1: |
|
| 933 | - $QSG_values = array( |
|
| 934 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 935 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
| 936 | - 'QSG_desc' => '', |
|
| 937 | - 'QSG_order' => 1, |
|
| 938 | - 'QSG_show_group_name' => 1, |
|
| 939 | - 'QSG_show_group_desc' => 1, |
|
| 940 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 941 | - 'QSG_deleted' => 0, |
|
| 942 | - ); |
|
| 943 | - break; |
|
| 944 | - case 2: |
|
| 945 | - $QSG_values = array( |
|
| 946 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 947 | - 'QSG_identifier' => 'address-information-' . time(), |
|
| 948 | - 'QSG_desc' => '', |
|
| 949 | - 'QSG_order' => 2, |
|
| 950 | - 'QSG_show_group_name' => 1, |
|
| 951 | - 'QSG_show_group_desc' => 1, |
|
| 952 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
| 953 | - 'QSG_deleted' => 0, |
|
| 954 | - ); |
|
| 955 | - break; |
|
| 956 | - } |
|
| 957 | - // make sure we have some values before inserting them |
|
| 958 | - if (! empty($QSG_values)) { |
|
| 959 | - // insert system question |
|
| 960 | - $wpdb->insert( |
|
| 961 | - $table_name, |
|
| 962 | - $QSG_values, |
|
| 963 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 964 | - ); |
|
| 965 | - $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 966 | - } |
|
| 967 | - } |
|
| 968 | - } |
|
| 969 | - // QUESTIONS |
|
| 970 | - global $wpdb; |
|
| 971 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 972 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 973 | - // what we have |
|
| 974 | - $questions = $wpdb->get_col($SQL); |
|
| 975 | - // what we should have |
|
| 976 | - $QST_systems = array( |
|
| 977 | - 'fname', |
|
| 978 | - 'lname', |
|
| 979 | - 'email', |
|
| 980 | - 'address', |
|
| 981 | - 'address2', |
|
| 982 | - 'city', |
|
| 983 | - 'country', |
|
| 984 | - 'state', |
|
| 985 | - 'zip', |
|
| 986 | - 'phone', |
|
| 987 | - ); |
|
| 988 | - $order_for_group_1 = 1; |
|
| 989 | - $order_for_group_2 = 1; |
|
| 990 | - // loop thru what we should have and compare to what we have |
|
| 991 | - foreach ($QST_systems as $QST_system) { |
|
| 992 | - // reset values array |
|
| 993 | - $QST_values = array(); |
|
| 994 | - // if we don't have what we should have |
|
| 995 | - if (! in_array($QST_system, $questions)) { |
|
| 996 | - // add it |
|
| 997 | - switch ($QST_system) { |
|
| 998 | - case 'fname': |
|
| 999 | - $QST_values = array( |
|
| 1000 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 1001 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 1002 | - 'QST_system' => 'fname', |
|
| 1003 | - 'QST_type' => 'TEXT', |
|
| 1004 | - 'QST_required' => 1, |
|
| 1005 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1006 | - 'QST_order' => 1, |
|
| 1007 | - 'QST_admin_only' => 0, |
|
| 1008 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1009 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1010 | - 'QST_deleted' => 0, |
|
| 1011 | - ); |
|
| 1012 | - break; |
|
| 1013 | - case 'lname': |
|
| 1014 | - $QST_values = array( |
|
| 1015 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 1016 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 1017 | - 'QST_system' => 'lname', |
|
| 1018 | - 'QST_type' => 'TEXT', |
|
| 1019 | - 'QST_required' => 1, |
|
| 1020 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1021 | - 'QST_order' => 2, |
|
| 1022 | - 'QST_admin_only' => 0, |
|
| 1023 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1024 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1025 | - 'QST_deleted' => 0, |
|
| 1026 | - ); |
|
| 1027 | - break; |
|
| 1028 | - case 'email': |
|
| 1029 | - $QST_values = array( |
|
| 1030 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 1031 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 1032 | - 'QST_system' => 'email', |
|
| 1033 | - 'QST_type' => 'EMAIL', |
|
| 1034 | - 'QST_required' => 1, |
|
| 1035 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1036 | - 'QST_order' => 3, |
|
| 1037 | - 'QST_admin_only' => 0, |
|
| 1038 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1039 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1040 | - 'QST_deleted' => 0, |
|
| 1041 | - ); |
|
| 1042 | - break; |
|
| 1043 | - case 'address': |
|
| 1044 | - $QST_values = array( |
|
| 1045 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 1046 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 1047 | - 'QST_system' => 'address', |
|
| 1048 | - 'QST_type' => 'TEXT', |
|
| 1049 | - 'QST_required' => 0, |
|
| 1050 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1051 | - 'QST_order' => 4, |
|
| 1052 | - 'QST_admin_only' => 0, |
|
| 1053 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1054 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1055 | - 'QST_deleted' => 0, |
|
| 1056 | - ); |
|
| 1057 | - break; |
|
| 1058 | - case 'address2': |
|
| 1059 | - $QST_values = array( |
|
| 1060 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 1061 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 1062 | - 'QST_system' => 'address2', |
|
| 1063 | - 'QST_type' => 'TEXT', |
|
| 1064 | - 'QST_required' => 0, |
|
| 1065 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1066 | - 'QST_order' => 5, |
|
| 1067 | - 'QST_admin_only' => 0, |
|
| 1068 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1069 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1070 | - 'QST_deleted' => 0, |
|
| 1071 | - ); |
|
| 1072 | - break; |
|
| 1073 | - case 'city': |
|
| 1074 | - $QST_values = array( |
|
| 1075 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1076 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1077 | - 'QST_system' => 'city', |
|
| 1078 | - 'QST_type' => 'TEXT', |
|
| 1079 | - 'QST_required' => 0, |
|
| 1080 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1081 | - 'QST_order' => 6, |
|
| 1082 | - 'QST_admin_only' => 0, |
|
| 1083 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1084 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1085 | - 'QST_deleted' => 0, |
|
| 1086 | - ); |
|
| 1087 | - break; |
|
| 1088 | - case 'country': |
|
| 1089 | - $QST_values = array( |
|
| 1090 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1091 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1092 | - 'QST_system' => 'country', |
|
| 1093 | - 'QST_type' => 'COUNTRY', |
|
| 1094 | - 'QST_required' => 0, |
|
| 1095 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1096 | - 'QST_order' => 7, |
|
| 1097 | - 'QST_admin_only' => 0, |
|
| 1098 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1099 | - 'QST_deleted' => 0, |
|
| 1100 | - ); |
|
| 1101 | - break; |
|
| 1102 | - case 'state': |
|
| 1103 | - $QST_values = array( |
|
| 1104 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1105 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1106 | - 'QST_system' => 'state', |
|
| 1107 | - 'QST_type' => 'STATE', |
|
| 1108 | - 'QST_required' => 0, |
|
| 1109 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1110 | - 'QST_order' => 8, |
|
| 1111 | - 'QST_admin_only' => 0, |
|
| 1112 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1113 | - 'QST_deleted' => 0, |
|
| 1114 | - ); |
|
| 1115 | - break; |
|
| 1116 | - case 'zip': |
|
| 1117 | - $QST_values = array( |
|
| 1118 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1119 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1120 | - 'QST_system' => 'zip', |
|
| 1121 | - 'QST_type' => 'TEXT', |
|
| 1122 | - 'QST_required' => 0, |
|
| 1123 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1124 | - 'QST_order' => 9, |
|
| 1125 | - 'QST_admin_only' => 0, |
|
| 1126 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1127 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1128 | - 'QST_deleted' => 0, |
|
| 1129 | - ); |
|
| 1130 | - break; |
|
| 1131 | - case 'phone': |
|
| 1132 | - $QST_values = array( |
|
| 1133 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1134 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1135 | - 'QST_system' => 'phone', |
|
| 1136 | - 'QST_type' => 'TEXT', |
|
| 1137 | - 'QST_required' => 0, |
|
| 1138 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1139 | - 'QST_order' => 10, |
|
| 1140 | - 'QST_admin_only' => 0, |
|
| 1141 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1142 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1143 | - 'QST_deleted' => 0, |
|
| 1144 | - ); |
|
| 1145 | - break; |
|
| 1146 | - } |
|
| 1147 | - if (! empty($QST_values)) { |
|
| 1148 | - // insert system question |
|
| 1149 | - $wpdb->insert( |
|
| 1150 | - $table_name, |
|
| 1151 | - $QST_values, |
|
| 1152 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1153 | - ); |
|
| 1154 | - $QST_ID = $wpdb->insert_id; |
|
| 1155 | - // QUESTION GROUP QUESTIONS |
|
| 1156 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1157 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1158 | - } else { |
|
| 1159 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1160 | - } |
|
| 1161 | - if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1162 | - $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1163 | - } else { |
|
| 1164 | - $id_col = EEM_Question_Group::instance() |
|
| 1165 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1166 | - if (is_array($id_col)) { |
|
| 1167 | - $QSG_ID = reset($id_col); |
|
| 1168 | - } else { |
|
| 1169 | - //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1170 | - EE_Log::instance()->log( |
|
| 1171 | - __FILE__, |
|
| 1172 | - __FUNCTION__, |
|
| 1173 | - sprintf( |
|
| 1174 | - __( |
|
| 1175 | - 'Could not associate question %1$s to a question group because no system question |
|
| 892 | + 'event_espresso' |
|
| 893 | + ), |
|
| 894 | + __FILE__, |
|
| 895 | + __FUNCTION__, |
|
| 896 | + __LINE__ |
|
| 897 | + ); |
|
| 898 | + return false; |
|
| 899 | + } |
|
| 900 | + return true; |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + |
|
| 904 | + |
|
| 905 | + /** |
|
| 906 | + * initialize_system_questions |
|
| 907 | + * |
|
| 908 | + * @access public |
|
| 909 | + * @static |
|
| 910 | + * @return void |
|
| 911 | + */ |
|
| 912 | + public static function initialize_system_questions() |
|
| 913 | + { |
|
| 914 | + // QUESTION GROUPS |
|
| 915 | + global $wpdb; |
|
| 916 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 917 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 918 | + // what we have |
|
| 919 | + $question_groups = $wpdb->get_col($SQL); |
|
| 920 | + // check the response |
|
| 921 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 922 | + // what we should have |
|
| 923 | + $QSG_systems = array(1, 2); |
|
| 924 | + // loop thru what we should have and compare to what we have |
|
| 925 | + foreach ($QSG_systems as $QSG_system) { |
|
| 926 | + // reset values array |
|
| 927 | + $QSG_values = array(); |
|
| 928 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 929 | + if (! in_array("$QSG_system", $question_groups)) { |
|
| 930 | + // add it |
|
| 931 | + switch ($QSG_system) { |
|
| 932 | + case 1: |
|
| 933 | + $QSG_values = array( |
|
| 934 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 935 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
| 936 | + 'QSG_desc' => '', |
|
| 937 | + 'QSG_order' => 1, |
|
| 938 | + 'QSG_show_group_name' => 1, |
|
| 939 | + 'QSG_show_group_desc' => 1, |
|
| 940 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 941 | + 'QSG_deleted' => 0, |
|
| 942 | + ); |
|
| 943 | + break; |
|
| 944 | + case 2: |
|
| 945 | + $QSG_values = array( |
|
| 946 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 947 | + 'QSG_identifier' => 'address-information-' . time(), |
|
| 948 | + 'QSG_desc' => '', |
|
| 949 | + 'QSG_order' => 2, |
|
| 950 | + 'QSG_show_group_name' => 1, |
|
| 951 | + 'QSG_show_group_desc' => 1, |
|
| 952 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
| 953 | + 'QSG_deleted' => 0, |
|
| 954 | + ); |
|
| 955 | + break; |
|
| 956 | + } |
|
| 957 | + // make sure we have some values before inserting them |
|
| 958 | + if (! empty($QSG_values)) { |
|
| 959 | + // insert system question |
|
| 960 | + $wpdb->insert( |
|
| 961 | + $table_name, |
|
| 962 | + $QSG_values, |
|
| 963 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 964 | + ); |
|
| 965 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 966 | + } |
|
| 967 | + } |
|
| 968 | + } |
|
| 969 | + // QUESTIONS |
|
| 970 | + global $wpdb; |
|
| 971 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 972 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 973 | + // what we have |
|
| 974 | + $questions = $wpdb->get_col($SQL); |
|
| 975 | + // what we should have |
|
| 976 | + $QST_systems = array( |
|
| 977 | + 'fname', |
|
| 978 | + 'lname', |
|
| 979 | + 'email', |
|
| 980 | + 'address', |
|
| 981 | + 'address2', |
|
| 982 | + 'city', |
|
| 983 | + 'country', |
|
| 984 | + 'state', |
|
| 985 | + 'zip', |
|
| 986 | + 'phone', |
|
| 987 | + ); |
|
| 988 | + $order_for_group_1 = 1; |
|
| 989 | + $order_for_group_2 = 1; |
|
| 990 | + // loop thru what we should have and compare to what we have |
|
| 991 | + foreach ($QST_systems as $QST_system) { |
|
| 992 | + // reset values array |
|
| 993 | + $QST_values = array(); |
|
| 994 | + // if we don't have what we should have |
|
| 995 | + if (! in_array($QST_system, $questions)) { |
|
| 996 | + // add it |
|
| 997 | + switch ($QST_system) { |
|
| 998 | + case 'fname': |
|
| 999 | + $QST_values = array( |
|
| 1000 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 1001 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 1002 | + 'QST_system' => 'fname', |
|
| 1003 | + 'QST_type' => 'TEXT', |
|
| 1004 | + 'QST_required' => 1, |
|
| 1005 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1006 | + 'QST_order' => 1, |
|
| 1007 | + 'QST_admin_only' => 0, |
|
| 1008 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1009 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1010 | + 'QST_deleted' => 0, |
|
| 1011 | + ); |
|
| 1012 | + break; |
|
| 1013 | + case 'lname': |
|
| 1014 | + $QST_values = array( |
|
| 1015 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 1016 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 1017 | + 'QST_system' => 'lname', |
|
| 1018 | + 'QST_type' => 'TEXT', |
|
| 1019 | + 'QST_required' => 1, |
|
| 1020 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1021 | + 'QST_order' => 2, |
|
| 1022 | + 'QST_admin_only' => 0, |
|
| 1023 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1024 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1025 | + 'QST_deleted' => 0, |
|
| 1026 | + ); |
|
| 1027 | + break; |
|
| 1028 | + case 'email': |
|
| 1029 | + $QST_values = array( |
|
| 1030 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 1031 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 1032 | + 'QST_system' => 'email', |
|
| 1033 | + 'QST_type' => 'EMAIL', |
|
| 1034 | + 'QST_required' => 1, |
|
| 1035 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1036 | + 'QST_order' => 3, |
|
| 1037 | + 'QST_admin_only' => 0, |
|
| 1038 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1039 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1040 | + 'QST_deleted' => 0, |
|
| 1041 | + ); |
|
| 1042 | + break; |
|
| 1043 | + case 'address': |
|
| 1044 | + $QST_values = array( |
|
| 1045 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 1046 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 1047 | + 'QST_system' => 'address', |
|
| 1048 | + 'QST_type' => 'TEXT', |
|
| 1049 | + 'QST_required' => 0, |
|
| 1050 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1051 | + 'QST_order' => 4, |
|
| 1052 | + 'QST_admin_only' => 0, |
|
| 1053 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1054 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1055 | + 'QST_deleted' => 0, |
|
| 1056 | + ); |
|
| 1057 | + break; |
|
| 1058 | + case 'address2': |
|
| 1059 | + $QST_values = array( |
|
| 1060 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 1061 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 1062 | + 'QST_system' => 'address2', |
|
| 1063 | + 'QST_type' => 'TEXT', |
|
| 1064 | + 'QST_required' => 0, |
|
| 1065 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1066 | + 'QST_order' => 5, |
|
| 1067 | + 'QST_admin_only' => 0, |
|
| 1068 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1069 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1070 | + 'QST_deleted' => 0, |
|
| 1071 | + ); |
|
| 1072 | + break; |
|
| 1073 | + case 'city': |
|
| 1074 | + $QST_values = array( |
|
| 1075 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1076 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1077 | + 'QST_system' => 'city', |
|
| 1078 | + 'QST_type' => 'TEXT', |
|
| 1079 | + 'QST_required' => 0, |
|
| 1080 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1081 | + 'QST_order' => 6, |
|
| 1082 | + 'QST_admin_only' => 0, |
|
| 1083 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1084 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1085 | + 'QST_deleted' => 0, |
|
| 1086 | + ); |
|
| 1087 | + break; |
|
| 1088 | + case 'country': |
|
| 1089 | + $QST_values = array( |
|
| 1090 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1091 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1092 | + 'QST_system' => 'country', |
|
| 1093 | + 'QST_type' => 'COUNTRY', |
|
| 1094 | + 'QST_required' => 0, |
|
| 1095 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1096 | + 'QST_order' => 7, |
|
| 1097 | + 'QST_admin_only' => 0, |
|
| 1098 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1099 | + 'QST_deleted' => 0, |
|
| 1100 | + ); |
|
| 1101 | + break; |
|
| 1102 | + case 'state': |
|
| 1103 | + $QST_values = array( |
|
| 1104 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1105 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1106 | + 'QST_system' => 'state', |
|
| 1107 | + 'QST_type' => 'STATE', |
|
| 1108 | + 'QST_required' => 0, |
|
| 1109 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1110 | + 'QST_order' => 8, |
|
| 1111 | + 'QST_admin_only' => 0, |
|
| 1112 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1113 | + 'QST_deleted' => 0, |
|
| 1114 | + ); |
|
| 1115 | + break; |
|
| 1116 | + case 'zip': |
|
| 1117 | + $QST_values = array( |
|
| 1118 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1119 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1120 | + 'QST_system' => 'zip', |
|
| 1121 | + 'QST_type' => 'TEXT', |
|
| 1122 | + 'QST_required' => 0, |
|
| 1123 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1124 | + 'QST_order' => 9, |
|
| 1125 | + 'QST_admin_only' => 0, |
|
| 1126 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1127 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1128 | + 'QST_deleted' => 0, |
|
| 1129 | + ); |
|
| 1130 | + break; |
|
| 1131 | + case 'phone': |
|
| 1132 | + $QST_values = array( |
|
| 1133 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1134 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1135 | + 'QST_system' => 'phone', |
|
| 1136 | + 'QST_type' => 'TEXT', |
|
| 1137 | + 'QST_required' => 0, |
|
| 1138 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1139 | + 'QST_order' => 10, |
|
| 1140 | + 'QST_admin_only' => 0, |
|
| 1141 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1142 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1143 | + 'QST_deleted' => 0, |
|
| 1144 | + ); |
|
| 1145 | + break; |
|
| 1146 | + } |
|
| 1147 | + if (! empty($QST_values)) { |
|
| 1148 | + // insert system question |
|
| 1149 | + $wpdb->insert( |
|
| 1150 | + $table_name, |
|
| 1151 | + $QST_values, |
|
| 1152 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1153 | + ); |
|
| 1154 | + $QST_ID = $wpdb->insert_id; |
|
| 1155 | + // QUESTION GROUP QUESTIONS |
|
| 1156 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1157 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1158 | + } else { |
|
| 1159 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1160 | + } |
|
| 1161 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1162 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1163 | + } else { |
|
| 1164 | + $id_col = EEM_Question_Group::instance() |
|
| 1165 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1166 | + if (is_array($id_col)) { |
|
| 1167 | + $QSG_ID = reset($id_col); |
|
| 1168 | + } else { |
|
| 1169 | + //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1170 | + EE_Log::instance()->log( |
|
| 1171 | + __FILE__, |
|
| 1172 | + __FUNCTION__, |
|
| 1173 | + sprintf( |
|
| 1174 | + __( |
|
| 1175 | + 'Could not associate question %1$s to a question group because no system question |
|
| 1176 | 1176 | group existed', |
| 1177 | - 'event_espresso' |
|
| 1178 | - ), |
|
| 1179 | - $QST_ID), |
|
| 1180 | - 'error'); |
|
| 1181 | - continue; |
|
| 1182 | - } |
|
| 1183 | - } |
|
| 1184 | - // add system questions to groups |
|
| 1185 | - $wpdb->insert( |
|
| 1186 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1187 | - array( |
|
| 1188 | - 'QSG_ID' => $QSG_ID, |
|
| 1189 | - 'QST_ID' => $QST_ID, |
|
| 1190 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1191 | - ), |
|
| 1192 | - array('%d', '%d', '%d') |
|
| 1193 | - ); |
|
| 1194 | - } |
|
| 1195 | - } |
|
| 1196 | - } |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - |
|
| 1200 | - /** |
|
| 1201 | - * Makes sure the default payment method (Invoice) is active. |
|
| 1202 | - * This used to be done automatically as part of constructing the old gateways config |
|
| 1203 | - * |
|
| 1204 | - * @throws \EE_Error |
|
| 1205 | - */ |
|
| 1206 | - public static function insert_default_payment_methods() |
|
| 1207 | - { |
|
| 1208 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1209 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1210 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1211 | - } else { |
|
| 1212 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1213 | - } |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - /** |
|
| 1217 | - * insert_default_status_codes |
|
| 1218 | - * |
|
| 1219 | - * @access public |
|
| 1220 | - * @static |
|
| 1221 | - * @return void |
|
| 1222 | - */ |
|
| 1223 | - public static function insert_default_status_codes() |
|
| 1224 | - { |
|
| 1225 | - |
|
| 1226 | - global $wpdb; |
|
| 1227 | - |
|
| 1228 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1229 | - |
|
| 1230 | - $table_name = EEM_Status::instance()->table(); |
|
| 1231 | - |
|
| 1232 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1233 | - $wpdb->query($SQL); |
|
| 1234 | - |
|
| 1235 | - $SQL = "INSERT INTO $table_name |
|
| 1177 | + 'event_espresso' |
|
| 1178 | + ), |
|
| 1179 | + $QST_ID), |
|
| 1180 | + 'error'); |
|
| 1181 | + continue; |
|
| 1182 | + } |
|
| 1183 | + } |
|
| 1184 | + // add system questions to groups |
|
| 1185 | + $wpdb->insert( |
|
| 1186 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1187 | + array( |
|
| 1188 | + 'QSG_ID' => $QSG_ID, |
|
| 1189 | + 'QST_ID' => $QST_ID, |
|
| 1190 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1191 | + ), |
|
| 1192 | + array('%d', '%d', '%d') |
|
| 1193 | + ); |
|
| 1194 | + } |
|
| 1195 | + } |
|
| 1196 | + } |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + |
|
| 1200 | + /** |
|
| 1201 | + * Makes sure the default payment method (Invoice) is active. |
|
| 1202 | + * This used to be done automatically as part of constructing the old gateways config |
|
| 1203 | + * |
|
| 1204 | + * @throws \EE_Error |
|
| 1205 | + */ |
|
| 1206 | + public static function insert_default_payment_methods() |
|
| 1207 | + { |
|
| 1208 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1209 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1210 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1211 | + } else { |
|
| 1212 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1213 | + } |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * insert_default_status_codes |
|
| 1218 | + * |
|
| 1219 | + * @access public |
|
| 1220 | + * @static |
|
| 1221 | + * @return void |
|
| 1222 | + */ |
|
| 1223 | + public static function insert_default_status_codes() |
|
| 1224 | + { |
|
| 1225 | + |
|
| 1226 | + global $wpdb; |
|
| 1227 | + |
|
| 1228 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1229 | + |
|
| 1230 | + $table_name = EEM_Status::instance()->table(); |
|
| 1231 | + |
|
| 1232 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1233 | + $wpdb->query($SQL); |
|
| 1234 | + |
|
| 1235 | + $SQL = "INSERT INTO $table_name |
|
| 1236 | 1236 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
| 1237 | 1237 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
| 1238 | 1238 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1272,521 +1272,521 @@ discard block |
||
| 1272 | 1272 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
| 1273 | 1273 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
| 1274 | 1274 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
| 1275 | - $wpdb->query($SQL); |
|
| 1276 | - |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * create_upload_directories |
|
| 1284 | - * Creates folders in the uploads directory to facilitate addons and templates |
|
| 1285 | - * |
|
| 1286 | - * @access public |
|
| 1287 | - * @static |
|
| 1288 | - * @return boolean success of verifying upload directories exist |
|
| 1289 | - */ |
|
| 1290 | - public static function create_upload_directories() |
|
| 1291 | - { |
|
| 1292 | - // Create the required folders |
|
| 1293 | - $folders = array( |
|
| 1294 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 1295 | - EVENT_ESPRESSO_GATEWAY_DIR, |
|
| 1296 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1297 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1298 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1299 | - ); |
|
| 1300 | - foreach ($folders as $folder) { |
|
| 1301 | - try { |
|
| 1302 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1303 | - @ chmod($folder, 0755); |
|
| 1304 | - } catch (EE_Error $e) { |
|
| 1305 | - EE_Error::add_error( |
|
| 1306 | - sprintf( |
|
| 1307 | - __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1308 | - $folder, |
|
| 1309 | - '<br />' . $e->getMessage() |
|
| 1310 | - ), |
|
| 1311 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1312 | - ); |
|
| 1313 | - //indicate we'll need to fix this later |
|
| 1314 | - update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1315 | - return false; |
|
| 1316 | - } |
|
| 1317 | - } |
|
| 1318 | - //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
| 1319 | - //is disabled, there might be activation errors recorded in there |
|
| 1320 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1321 | - //remember EE's folders are all good |
|
| 1322 | - delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1323 | - return true; |
|
| 1324 | - } |
|
| 1325 | - |
|
| 1326 | - /** |
|
| 1327 | - * Whether the upload directories need to be fixed or not. |
|
| 1328 | - * If EE is installed but filesystem access isn't initially available, |
|
| 1329 | - * we need to get the user's filesystem credentials and THEN create them, |
|
| 1330 | - * so there might be period of time when EE is installed but its |
|
| 1331 | - * upload directories aren't available. This indicates such a state |
|
| 1332 | - * |
|
| 1333 | - * @return boolean |
|
| 1334 | - */ |
|
| 1335 | - public static function upload_directories_incomplete() |
|
| 1336 | - { |
|
| 1337 | - return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - |
|
| 1341 | - /** |
|
| 1342 | - * generate_default_message_templates |
|
| 1343 | - * |
|
| 1344 | - * @static |
|
| 1345 | - * @throws EE_Error |
|
| 1346 | - * @return bool true means new templates were created. |
|
| 1347 | - * false means no templates were created. |
|
| 1348 | - * This is NOT an error flag. To check for errors you will want |
|
| 1349 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1350 | - */ |
|
| 1351 | - public static function generate_default_message_templates() |
|
| 1352 | - { |
|
| 1353 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1354 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1355 | - /* |
|
| 1275 | + $wpdb->query($SQL); |
|
| 1276 | + |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * create_upload_directories |
|
| 1284 | + * Creates folders in the uploads directory to facilitate addons and templates |
|
| 1285 | + * |
|
| 1286 | + * @access public |
|
| 1287 | + * @static |
|
| 1288 | + * @return boolean success of verifying upload directories exist |
|
| 1289 | + */ |
|
| 1290 | + public static function create_upload_directories() |
|
| 1291 | + { |
|
| 1292 | + // Create the required folders |
|
| 1293 | + $folders = array( |
|
| 1294 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 1295 | + EVENT_ESPRESSO_GATEWAY_DIR, |
|
| 1296 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1297 | + EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1298 | + EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1299 | + ); |
|
| 1300 | + foreach ($folders as $folder) { |
|
| 1301 | + try { |
|
| 1302 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1303 | + @ chmod($folder, 0755); |
|
| 1304 | + } catch (EE_Error $e) { |
|
| 1305 | + EE_Error::add_error( |
|
| 1306 | + sprintf( |
|
| 1307 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1308 | + $folder, |
|
| 1309 | + '<br />' . $e->getMessage() |
|
| 1310 | + ), |
|
| 1311 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1312 | + ); |
|
| 1313 | + //indicate we'll need to fix this later |
|
| 1314 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1315 | + return false; |
|
| 1316 | + } |
|
| 1317 | + } |
|
| 1318 | + //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
| 1319 | + //is disabled, there might be activation errors recorded in there |
|
| 1320 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1321 | + //remember EE's folders are all good |
|
| 1322 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1323 | + return true; |
|
| 1324 | + } |
|
| 1325 | + |
|
| 1326 | + /** |
|
| 1327 | + * Whether the upload directories need to be fixed or not. |
|
| 1328 | + * If EE is installed but filesystem access isn't initially available, |
|
| 1329 | + * we need to get the user's filesystem credentials and THEN create them, |
|
| 1330 | + * so there might be period of time when EE is installed but its |
|
| 1331 | + * upload directories aren't available. This indicates such a state |
|
| 1332 | + * |
|
| 1333 | + * @return boolean |
|
| 1334 | + */ |
|
| 1335 | + public static function upload_directories_incomplete() |
|
| 1336 | + { |
|
| 1337 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + |
|
| 1341 | + /** |
|
| 1342 | + * generate_default_message_templates |
|
| 1343 | + * |
|
| 1344 | + * @static |
|
| 1345 | + * @throws EE_Error |
|
| 1346 | + * @return bool true means new templates were created. |
|
| 1347 | + * false means no templates were created. |
|
| 1348 | + * This is NOT an error flag. To check for errors you will want |
|
| 1349 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1350 | + */ |
|
| 1351 | + public static function generate_default_message_templates() |
|
| 1352 | + { |
|
| 1353 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1354 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1355 | + /* |
|
| 1356 | 1356 | * This first method is taking care of ensuring any default messengers |
| 1357 | 1357 | * that should be made active and have templates generated are done. |
| 1358 | 1358 | */ |
| 1359 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1360 | - $message_resource_manager |
|
| 1361 | - ); |
|
| 1362 | - /** |
|
| 1363 | - * This method is verifying there are no NEW default message types |
|
| 1364 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1365 | - */ |
|
| 1366 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1367 | - $message_resource_manager |
|
| 1368 | - ); |
|
| 1369 | - //after all is done, let's persist these changes to the db. |
|
| 1370 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1371 | - $message_resource_manager->update_active_messengers_option(); |
|
| 1372 | - // will return true if either of these are true. Otherwise will return false. |
|
| 1373 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1380 | - * @return array|bool |
|
| 1381 | - * @throws \EE_Error |
|
| 1382 | - */ |
|
| 1383 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1384 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1385 | - ) { |
|
| 1386 | - /** @type EE_messenger[] $active_messengers */ |
|
| 1387 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1388 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1389 | - $templates_created = false; |
|
| 1390 | - foreach ($active_messengers as $active_messenger) { |
|
| 1391 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1392 | - $default_message_type_names_to_activate = array(); |
|
| 1393 | - // looping through each default message type reported by the messenger |
|
| 1394 | - // and setup the actual message types to activate. |
|
| 1395 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1396 | - // if already active or has already been activated before we skip |
|
| 1397 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1398 | - // we also skip if the message type is not installed. |
|
| 1399 | - if ( |
|
| 1400 | - $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1401 | - $default_message_type_name_for_messenger, |
|
| 1402 | - $active_messenger->name |
|
| 1403 | - ) |
|
| 1404 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1405 | - $active_messenger->name, |
|
| 1406 | - $default_message_type_name_for_messenger |
|
| 1407 | - ) |
|
| 1408 | - || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1409 | - ) { |
|
| 1410 | - continue; |
|
| 1411 | - } |
|
| 1412 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1413 | - } |
|
| 1414 | - //let's activate! |
|
| 1415 | - $message_resource_manager->ensure_message_types_are_active( |
|
| 1416 | - $default_message_type_names_to_activate, |
|
| 1417 | - $active_messenger->name, |
|
| 1418 | - false |
|
| 1419 | - ); |
|
| 1420 | - //activate the templates for these message types |
|
| 1421 | - if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1422 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1423 | - $active_messenger->name, |
|
| 1424 | - $default_message_type_names_for_messenger, |
|
| 1425 | - '', |
|
| 1426 | - true |
|
| 1427 | - ); |
|
| 1428 | - } |
|
| 1429 | - } |
|
| 1430 | - return $templates_created; |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - |
|
| 1434 | - |
|
| 1435 | - /** |
|
| 1436 | - * This will activate and generate default messengers and default message types for those messengers. |
|
| 1437 | - * |
|
| 1438 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1439 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1440 | - * False means that there were no templates generated |
|
| 1441 | - * (which could simply mean there are no default message types for a messenger). |
|
| 1442 | - * @throws EE_Error |
|
| 1443 | - */ |
|
| 1444 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1445 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1446 | - ) { |
|
| 1447 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1448 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1449 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1450 | - $templates_generated = false; |
|
| 1451 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1452 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1453 | - //verify the default message types match an installed message type. |
|
| 1454 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1455 | - if ( |
|
| 1456 | - ! isset($installed_message_types[$name]) |
|
| 1457 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1458 | - $name, |
|
| 1459 | - $messenger_to_generate->name |
|
| 1460 | - ) |
|
| 1461 | - ) { |
|
| 1462 | - unset($default_message_type_names_for_messenger[$key]); |
|
| 1463 | - } |
|
| 1464 | - } |
|
| 1465 | - // in previous iterations, the active_messengers option in the db |
|
| 1466 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1467 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1468 | - // passing off to create templates (after the refactor is done). |
|
| 1469 | - // @todo remove this comment when determined not necessary. |
|
| 1470 | - $message_resource_manager->activate_messenger( |
|
| 1471 | - $messenger_to_generate->name, |
|
| 1472 | - $default_message_type_names_for_messenger, |
|
| 1473 | - false |
|
| 1474 | - ); |
|
| 1475 | - //create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1476 | - if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1477 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1478 | - $messenger_to_generate->name, |
|
| 1479 | - $default_message_type_names_for_messenger, |
|
| 1480 | - '', |
|
| 1481 | - true |
|
| 1482 | - ); |
|
| 1483 | - } |
|
| 1484 | - } |
|
| 1485 | - return $templates_generated; |
|
| 1486 | - } |
|
| 1487 | - |
|
| 1488 | - |
|
| 1489 | - /** |
|
| 1490 | - * This returns the default messengers to generate templates for on activation of EE. |
|
| 1491 | - * It considers: |
|
| 1492 | - * - whether a messenger is already active in the db. |
|
| 1493 | - * - whether a messenger has been made active at any time in the past. |
|
| 1494 | - * |
|
| 1495 | - * @static |
|
| 1496 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1497 | - * @return EE_messenger[] |
|
| 1498 | - */ |
|
| 1499 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1500 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1501 | - ) { |
|
| 1502 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1503 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1504 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1505 | - |
|
| 1506 | - $messengers_to_generate = array(); |
|
| 1507 | - foreach ($installed_messengers as $installed_messenger) { |
|
| 1508 | - //if installed messenger is a messenger that should be activated on install |
|
| 1509 | - //and is not already active |
|
| 1510 | - //and has never been activated |
|
| 1511 | - if ( |
|
| 1512 | - ! $installed_messenger->activate_on_install |
|
| 1513 | - || isset($active_messengers[$installed_messenger->name]) |
|
| 1514 | - || isset($has_activated[$installed_messenger->name]) |
|
| 1515 | - ) { |
|
| 1516 | - continue; |
|
| 1517 | - } |
|
| 1518 | - $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1519 | - } |
|
| 1520 | - return $messengers_to_generate; |
|
| 1521 | - } |
|
| 1522 | - |
|
| 1523 | - |
|
| 1524 | - /** |
|
| 1525 | - * This simply validates active message types to ensure they actually match installed |
|
| 1526 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1527 | - * rows are set inactive. |
|
| 1528 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1529 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1530 | - * are still handled in here. |
|
| 1531 | - * |
|
| 1532 | - * @since 4.3.1 |
|
| 1533 | - * @return void |
|
| 1534 | - */ |
|
| 1535 | - public static function validate_messages_system() |
|
| 1536 | - { |
|
| 1537 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1538 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1539 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1540 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1541 | - } |
|
| 1542 | - |
|
| 1543 | - |
|
| 1544 | - /** |
|
| 1545 | - * create_no_ticket_prices_array |
|
| 1546 | - * |
|
| 1547 | - * @access public |
|
| 1548 | - * @static |
|
| 1549 | - * @return void |
|
| 1550 | - */ |
|
| 1551 | - public static function create_no_ticket_prices_array() |
|
| 1552 | - { |
|
| 1553 | - // this creates an array for tracking events that have no active ticket prices created |
|
| 1554 | - // this allows us to warn admins of the situation so that it can be corrected |
|
| 1555 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1556 | - if (! $espresso_no_ticket_prices) { |
|
| 1557 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1558 | - } |
|
| 1559 | - } |
|
| 1560 | - |
|
| 1561 | - |
|
| 1562 | - /** |
|
| 1563 | - * plugin_deactivation |
|
| 1564 | - * |
|
| 1565 | - * @access public |
|
| 1566 | - * @static |
|
| 1567 | - * @return void |
|
| 1568 | - */ |
|
| 1569 | - public static function plugin_deactivation() |
|
| 1570 | - { |
|
| 1571 | - } |
|
| 1572 | - |
|
| 1573 | - |
|
| 1574 | - /** |
|
| 1575 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1576 | - * (like post meta or term relations) |
|
| 1577 | - * |
|
| 1578 | - * @global wpdb $wpdb |
|
| 1579 | - * @throws \EE_Error |
|
| 1580 | - */ |
|
| 1581 | - public static function delete_all_espresso_cpt_data() |
|
| 1582 | - { |
|
| 1583 | - global $wpdb; |
|
| 1584 | - //get all the CPT post_types |
|
| 1585 | - $ee_post_types = array(); |
|
| 1586 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1587 | - if (method_exists($model_name, 'instance')) { |
|
| 1588 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1589 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1590 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1591 | - } |
|
| 1592 | - } |
|
| 1593 | - } |
|
| 1594 | - //get all our CPTs |
|
| 1595 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1596 | - $cpt_ids = $wpdb->get_col($query); |
|
| 1597 | - //delete each post meta and term relations too |
|
| 1598 | - foreach ($cpt_ids as $post_id) { |
|
| 1599 | - wp_delete_post($post_id, true); |
|
| 1600 | - } |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - /** |
|
| 1604 | - * Deletes all EE custom tables |
|
| 1605 | - * |
|
| 1606 | - * @return array |
|
| 1607 | - */ |
|
| 1608 | - public static function drop_espresso_tables() |
|
| 1609 | - { |
|
| 1610 | - $tables = array(); |
|
| 1611 | - // load registry |
|
| 1612 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1613 | - if (method_exists($model_name, 'instance')) { |
|
| 1614 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1615 | - if ($model_obj instanceof EEM_Base) { |
|
| 1616 | - foreach ($model_obj->get_tables() as $table) { |
|
| 1617 | - if (strpos($table->get_table_name(), 'esp_') |
|
| 1618 | - && |
|
| 1619 | - ( |
|
| 1620 | - is_main_site()//main site? nuke them all |
|
| 1621 | - || ! $table->is_global()//not main site,but not global either. nuke it |
|
| 1622 | - ) |
|
| 1623 | - ) { |
|
| 1624 | - $tables[] = $table->get_table_name(); |
|
| 1625 | - } |
|
| 1626 | - } |
|
| 1627 | - } |
|
| 1628 | - } |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - //there are some tables whose models were removed. |
|
| 1632 | - //they should be removed when removing all EE core's data |
|
| 1633 | - $tables_without_models = array( |
|
| 1634 | - 'esp_promotion', |
|
| 1635 | - 'esp_promotion_applied', |
|
| 1636 | - 'esp_promotion_object', |
|
| 1637 | - 'esp_promotion_rule', |
|
| 1638 | - 'esp_rule', |
|
| 1639 | - ); |
|
| 1640 | - foreach ($tables_without_models as $table) { |
|
| 1641 | - $tables[] = $table; |
|
| 1642 | - } |
|
| 1643 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1650 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1651 | - * Returns the list actually deleted |
|
| 1652 | - * |
|
| 1653 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1654 | - * @global WPDB $wpdb |
|
| 1655 | - * @param array $table_names |
|
| 1656 | - * @return array of table names which we deleted |
|
| 1657 | - */ |
|
| 1658 | - public static function drop_tables($table_names) |
|
| 1659 | - { |
|
| 1660 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1661 | - } |
|
| 1662 | - |
|
| 1663 | - |
|
| 1664 | - |
|
| 1665 | - /** |
|
| 1666 | - * plugin_uninstall |
|
| 1667 | - * |
|
| 1668 | - * @access public |
|
| 1669 | - * @static |
|
| 1670 | - * @param bool $remove_all |
|
| 1671 | - * @return void |
|
| 1672 | - */ |
|
| 1673 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1674 | - { |
|
| 1675 | - global $wpdb; |
|
| 1676 | - self::drop_espresso_tables(); |
|
| 1677 | - $wp_options_to_delete = array( |
|
| 1678 | - 'ee_no_ticket_prices' => true, |
|
| 1679 | - 'ee_active_messengers' => true, |
|
| 1680 | - 'ee_has_activated_messenger' => true, |
|
| 1681 | - 'ee_flush_rewrite_rules' => true, |
|
| 1682 | - 'ee_config' => false, |
|
| 1683 | - 'ee_data_migration_current_db_state' => true, |
|
| 1684 | - 'ee_data_migration_mapping_' => false, |
|
| 1685 | - 'ee_data_migration_script_' => false, |
|
| 1686 | - 'ee_data_migrations' => true, |
|
| 1687 | - 'ee_dms_map' => false, |
|
| 1688 | - 'ee_notices' => true, |
|
| 1689 | - 'lang_file_check_' => false, |
|
| 1690 | - 'ee_maintenance_mode' => true, |
|
| 1691 | - 'ee_ueip_optin' => true, |
|
| 1692 | - 'ee_ueip_has_notified' => true, |
|
| 1693 | - 'ee_plugin_activation_errors' => true, |
|
| 1694 | - 'ee_id_mapping_from' => false, |
|
| 1695 | - 'espresso_persistent_admin_notices' => true, |
|
| 1696 | - 'ee_encryption_key' => true, |
|
| 1697 | - 'pue_force_upgrade_' => false, |
|
| 1698 | - 'pue_json_error_' => false, |
|
| 1699 | - 'pue_install_key_' => false, |
|
| 1700 | - 'pue_verification_error_' => false, |
|
| 1701 | - 'pu_dismissed_upgrade_' => false, |
|
| 1702 | - 'external_updates-' => false, |
|
| 1703 | - 'ee_extra_data' => true, |
|
| 1704 | - 'ee_ssn_' => false, |
|
| 1705 | - 'ee_rss_' => false, |
|
| 1706 | - 'ee_rte_n_tx_' => false, |
|
| 1707 | - 'ee_pers_admin_notices' => true, |
|
| 1708 | - 'ee_job_parameters_' => false, |
|
| 1709 | - 'ee_upload_directories_incomplete' => true, |
|
| 1710 | - 'ee_verified_db_collations' => true, |
|
| 1711 | - ); |
|
| 1712 | - if (is_main_site()) { |
|
| 1713 | - $wp_options_to_delete['ee_network_config'] = true; |
|
| 1714 | - } |
|
| 1715 | - $undeleted_options = array(); |
|
| 1716 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1717 | - if ($no_wildcard) { |
|
| 1718 | - if ( ! delete_option($option_name)) { |
|
| 1719 | - $undeleted_options[] = $option_name; |
|
| 1720 | - } |
|
| 1721 | - } else { |
|
| 1722 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1723 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1724 | - if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1725 | - $undeleted_options[] = $option_name_from_wildcard; |
|
| 1726 | - } |
|
| 1727 | - } |
|
| 1728 | - } |
|
| 1729 | - } |
|
| 1730 | - //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1731 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1732 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1733 | - $db_update_sans_ee4 = array(); |
|
| 1734 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1735 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1736 | - $db_update_sans_ee4[$version] = $times_activated; |
|
| 1737 | - } |
|
| 1738 | - } |
|
| 1739 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1740 | - } |
|
| 1741 | - $errors = ''; |
|
| 1742 | - if ( ! empty($undeleted_options)) { |
|
| 1743 | - $errors .= sprintf( |
|
| 1744 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1745 | - '<br/>', |
|
| 1746 | - implode(',<br/>', $undeleted_options) |
|
| 1747 | - ); |
|
| 1748 | - } |
|
| 1749 | - if ( ! empty($errors)) { |
|
| 1750 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1751 | - } |
|
| 1752 | - } |
|
| 1753 | - |
|
| 1754 | - /** |
|
| 1755 | - * Gets the mysql error code from the last used query by wpdb |
|
| 1756 | - * |
|
| 1757 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1758 | - */ |
|
| 1759 | - public static function last_wpdb_error_code() |
|
| 1760 | - { |
|
| 1761 | - global $wpdb; |
|
| 1762 | - if ($wpdb->use_mysqli) { |
|
| 1763 | - return mysqli_errno($wpdb->dbh); |
|
| 1764 | - } else { |
|
| 1765 | - return mysql_errno($wpdb->dbh); |
|
| 1766 | - } |
|
| 1767 | - } |
|
| 1768 | - |
|
| 1769 | - /** |
|
| 1770 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1771 | - * |
|
| 1772 | - * @global wpdb $wpdb |
|
| 1773 | - * @deprecated instead use TableAnalysis::tableExists() |
|
| 1774 | - * @param string $table_name with or without $wpdb->prefix |
|
| 1775 | - * @return boolean |
|
| 1776 | - */ |
|
| 1777 | - public static function table_exists($table_name) |
|
| 1778 | - { |
|
| 1779 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1780 | - } |
|
| 1781 | - |
|
| 1782 | - /** |
|
| 1783 | - * Resets the cache on EEH_Activation |
|
| 1784 | - */ |
|
| 1785 | - public static function reset() |
|
| 1786 | - { |
|
| 1787 | - self::$_default_creator_id = null; |
|
| 1788 | - self::$_initialized_db_content_already_in_this_request = false; |
|
| 1789 | - } |
|
| 1359 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1360 | + $message_resource_manager |
|
| 1361 | + ); |
|
| 1362 | + /** |
|
| 1363 | + * This method is verifying there are no NEW default message types |
|
| 1364 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1365 | + */ |
|
| 1366 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1367 | + $message_resource_manager |
|
| 1368 | + ); |
|
| 1369 | + //after all is done, let's persist these changes to the db. |
|
| 1370 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1371 | + $message_resource_manager->update_active_messengers_option(); |
|
| 1372 | + // will return true if either of these are true. Otherwise will return false. |
|
| 1373 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1380 | + * @return array|bool |
|
| 1381 | + * @throws \EE_Error |
|
| 1382 | + */ |
|
| 1383 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1384 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1385 | + ) { |
|
| 1386 | + /** @type EE_messenger[] $active_messengers */ |
|
| 1387 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1388 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1389 | + $templates_created = false; |
|
| 1390 | + foreach ($active_messengers as $active_messenger) { |
|
| 1391 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1392 | + $default_message_type_names_to_activate = array(); |
|
| 1393 | + // looping through each default message type reported by the messenger |
|
| 1394 | + // and setup the actual message types to activate. |
|
| 1395 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1396 | + // if already active or has already been activated before we skip |
|
| 1397 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1398 | + // we also skip if the message type is not installed. |
|
| 1399 | + if ( |
|
| 1400 | + $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1401 | + $default_message_type_name_for_messenger, |
|
| 1402 | + $active_messenger->name |
|
| 1403 | + ) |
|
| 1404 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1405 | + $active_messenger->name, |
|
| 1406 | + $default_message_type_name_for_messenger |
|
| 1407 | + ) |
|
| 1408 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1409 | + ) { |
|
| 1410 | + continue; |
|
| 1411 | + } |
|
| 1412 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1413 | + } |
|
| 1414 | + //let's activate! |
|
| 1415 | + $message_resource_manager->ensure_message_types_are_active( |
|
| 1416 | + $default_message_type_names_to_activate, |
|
| 1417 | + $active_messenger->name, |
|
| 1418 | + false |
|
| 1419 | + ); |
|
| 1420 | + //activate the templates for these message types |
|
| 1421 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1422 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1423 | + $active_messenger->name, |
|
| 1424 | + $default_message_type_names_for_messenger, |
|
| 1425 | + '', |
|
| 1426 | + true |
|
| 1427 | + ); |
|
| 1428 | + } |
|
| 1429 | + } |
|
| 1430 | + return $templates_created; |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + |
|
| 1434 | + |
|
| 1435 | + /** |
|
| 1436 | + * This will activate and generate default messengers and default message types for those messengers. |
|
| 1437 | + * |
|
| 1438 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1439 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1440 | + * False means that there were no templates generated |
|
| 1441 | + * (which could simply mean there are no default message types for a messenger). |
|
| 1442 | + * @throws EE_Error |
|
| 1443 | + */ |
|
| 1444 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1445 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1446 | + ) { |
|
| 1447 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1448 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1449 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1450 | + $templates_generated = false; |
|
| 1451 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1452 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1453 | + //verify the default message types match an installed message type. |
|
| 1454 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1455 | + if ( |
|
| 1456 | + ! isset($installed_message_types[$name]) |
|
| 1457 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1458 | + $name, |
|
| 1459 | + $messenger_to_generate->name |
|
| 1460 | + ) |
|
| 1461 | + ) { |
|
| 1462 | + unset($default_message_type_names_for_messenger[$key]); |
|
| 1463 | + } |
|
| 1464 | + } |
|
| 1465 | + // in previous iterations, the active_messengers option in the db |
|
| 1466 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1467 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1468 | + // passing off to create templates (after the refactor is done). |
|
| 1469 | + // @todo remove this comment when determined not necessary. |
|
| 1470 | + $message_resource_manager->activate_messenger( |
|
| 1471 | + $messenger_to_generate->name, |
|
| 1472 | + $default_message_type_names_for_messenger, |
|
| 1473 | + false |
|
| 1474 | + ); |
|
| 1475 | + //create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1476 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1477 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1478 | + $messenger_to_generate->name, |
|
| 1479 | + $default_message_type_names_for_messenger, |
|
| 1480 | + '', |
|
| 1481 | + true |
|
| 1482 | + ); |
|
| 1483 | + } |
|
| 1484 | + } |
|
| 1485 | + return $templates_generated; |
|
| 1486 | + } |
|
| 1487 | + |
|
| 1488 | + |
|
| 1489 | + /** |
|
| 1490 | + * This returns the default messengers to generate templates for on activation of EE. |
|
| 1491 | + * It considers: |
|
| 1492 | + * - whether a messenger is already active in the db. |
|
| 1493 | + * - whether a messenger has been made active at any time in the past. |
|
| 1494 | + * |
|
| 1495 | + * @static |
|
| 1496 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1497 | + * @return EE_messenger[] |
|
| 1498 | + */ |
|
| 1499 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1500 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1501 | + ) { |
|
| 1502 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1503 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1504 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1505 | + |
|
| 1506 | + $messengers_to_generate = array(); |
|
| 1507 | + foreach ($installed_messengers as $installed_messenger) { |
|
| 1508 | + //if installed messenger is a messenger that should be activated on install |
|
| 1509 | + //and is not already active |
|
| 1510 | + //and has never been activated |
|
| 1511 | + if ( |
|
| 1512 | + ! $installed_messenger->activate_on_install |
|
| 1513 | + || isset($active_messengers[$installed_messenger->name]) |
|
| 1514 | + || isset($has_activated[$installed_messenger->name]) |
|
| 1515 | + ) { |
|
| 1516 | + continue; |
|
| 1517 | + } |
|
| 1518 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1519 | + } |
|
| 1520 | + return $messengers_to_generate; |
|
| 1521 | + } |
|
| 1522 | + |
|
| 1523 | + |
|
| 1524 | + /** |
|
| 1525 | + * This simply validates active message types to ensure they actually match installed |
|
| 1526 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1527 | + * rows are set inactive. |
|
| 1528 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1529 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1530 | + * are still handled in here. |
|
| 1531 | + * |
|
| 1532 | + * @since 4.3.1 |
|
| 1533 | + * @return void |
|
| 1534 | + */ |
|
| 1535 | + public static function validate_messages_system() |
|
| 1536 | + { |
|
| 1537 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1538 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1539 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1540 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1541 | + } |
|
| 1542 | + |
|
| 1543 | + |
|
| 1544 | + /** |
|
| 1545 | + * create_no_ticket_prices_array |
|
| 1546 | + * |
|
| 1547 | + * @access public |
|
| 1548 | + * @static |
|
| 1549 | + * @return void |
|
| 1550 | + */ |
|
| 1551 | + public static function create_no_ticket_prices_array() |
|
| 1552 | + { |
|
| 1553 | + // this creates an array for tracking events that have no active ticket prices created |
|
| 1554 | + // this allows us to warn admins of the situation so that it can be corrected |
|
| 1555 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1556 | + if (! $espresso_no_ticket_prices) { |
|
| 1557 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1558 | + } |
|
| 1559 | + } |
|
| 1560 | + |
|
| 1561 | + |
|
| 1562 | + /** |
|
| 1563 | + * plugin_deactivation |
|
| 1564 | + * |
|
| 1565 | + * @access public |
|
| 1566 | + * @static |
|
| 1567 | + * @return void |
|
| 1568 | + */ |
|
| 1569 | + public static function plugin_deactivation() |
|
| 1570 | + { |
|
| 1571 | + } |
|
| 1572 | + |
|
| 1573 | + |
|
| 1574 | + /** |
|
| 1575 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1576 | + * (like post meta or term relations) |
|
| 1577 | + * |
|
| 1578 | + * @global wpdb $wpdb |
|
| 1579 | + * @throws \EE_Error |
|
| 1580 | + */ |
|
| 1581 | + public static function delete_all_espresso_cpt_data() |
|
| 1582 | + { |
|
| 1583 | + global $wpdb; |
|
| 1584 | + //get all the CPT post_types |
|
| 1585 | + $ee_post_types = array(); |
|
| 1586 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1587 | + if (method_exists($model_name, 'instance')) { |
|
| 1588 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1589 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1590 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1591 | + } |
|
| 1592 | + } |
|
| 1593 | + } |
|
| 1594 | + //get all our CPTs |
|
| 1595 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1596 | + $cpt_ids = $wpdb->get_col($query); |
|
| 1597 | + //delete each post meta and term relations too |
|
| 1598 | + foreach ($cpt_ids as $post_id) { |
|
| 1599 | + wp_delete_post($post_id, true); |
|
| 1600 | + } |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + /** |
|
| 1604 | + * Deletes all EE custom tables |
|
| 1605 | + * |
|
| 1606 | + * @return array |
|
| 1607 | + */ |
|
| 1608 | + public static function drop_espresso_tables() |
|
| 1609 | + { |
|
| 1610 | + $tables = array(); |
|
| 1611 | + // load registry |
|
| 1612 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1613 | + if (method_exists($model_name, 'instance')) { |
|
| 1614 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1615 | + if ($model_obj instanceof EEM_Base) { |
|
| 1616 | + foreach ($model_obj->get_tables() as $table) { |
|
| 1617 | + if (strpos($table->get_table_name(), 'esp_') |
|
| 1618 | + && |
|
| 1619 | + ( |
|
| 1620 | + is_main_site()//main site? nuke them all |
|
| 1621 | + || ! $table->is_global()//not main site,but not global either. nuke it |
|
| 1622 | + ) |
|
| 1623 | + ) { |
|
| 1624 | + $tables[] = $table->get_table_name(); |
|
| 1625 | + } |
|
| 1626 | + } |
|
| 1627 | + } |
|
| 1628 | + } |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + //there are some tables whose models were removed. |
|
| 1632 | + //they should be removed when removing all EE core's data |
|
| 1633 | + $tables_without_models = array( |
|
| 1634 | + 'esp_promotion', |
|
| 1635 | + 'esp_promotion_applied', |
|
| 1636 | + 'esp_promotion_object', |
|
| 1637 | + 'esp_promotion_rule', |
|
| 1638 | + 'esp_rule', |
|
| 1639 | + ); |
|
| 1640 | + foreach ($tables_without_models as $table) { |
|
| 1641 | + $tables[] = $table; |
|
| 1642 | + } |
|
| 1643 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1650 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1651 | + * Returns the list actually deleted |
|
| 1652 | + * |
|
| 1653 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1654 | + * @global WPDB $wpdb |
|
| 1655 | + * @param array $table_names |
|
| 1656 | + * @return array of table names which we deleted |
|
| 1657 | + */ |
|
| 1658 | + public static function drop_tables($table_names) |
|
| 1659 | + { |
|
| 1660 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1661 | + } |
|
| 1662 | + |
|
| 1663 | + |
|
| 1664 | + |
|
| 1665 | + /** |
|
| 1666 | + * plugin_uninstall |
|
| 1667 | + * |
|
| 1668 | + * @access public |
|
| 1669 | + * @static |
|
| 1670 | + * @param bool $remove_all |
|
| 1671 | + * @return void |
|
| 1672 | + */ |
|
| 1673 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1674 | + { |
|
| 1675 | + global $wpdb; |
|
| 1676 | + self::drop_espresso_tables(); |
|
| 1677 | + $wp_options_to_delete = array( |
|
| 1678 | + 'ee_no_ticket_prices' => true, |
|
| 1679 | + 'ee_active_messengers' => true, |
|
| 1680 | + 'ee_has_activated_messenger' => true, |
|
| 1681 | + 'ee_flush_rewrite_rules' => true, |
|
| 1682 | + 'ee_config' => false, |
|
| 1683 | + 'ee_data_migration_current_db_state' => true, |
|
| 1684 | + 'ee_data_migration_mapping_' => false, |
|
| 1685 | + 'ee_data_migration_script_' => false, |
|
| 1686 | + 'ee_data_migrations' => true, |
|
| 1687 | + 'ee_dms_map' => false, |
|
| 1688 | + 'ee_notices' => true, |
|
| 1689 | + 'lang_file_check_' => false, |
|
| 1690 | + 'ee_maintenance_mode' => true, |
|
| 1691 | + 'ee_ueip_optin' => true, |
|
| 1692 | + 'ee_ueip_has_notified' => true, |
|
| 1693 | + 'ee_plugin_activation_errors' => true, |
|
| 1694 | + 'ee_id_mapping_from' => false, |
|
| 1695 | + 'espresso_persistent_admin_notices' => true, |
|
| 1696 | + 'ee_encryption_key' => true, |
|
| 1697 | + 'pue_force_upgrade_' => false, |
|
| 1698 | + 'pue_json_error_' => false, |
|
| 1699 | + 'pue_install_key_' => false, |
|
| 1700 | + 'pue_verification_error_' => false, |
|
| 1701 | + 'pu_dismissed_upgrade_' => false, |
|
| 1702 | + 'external_updates-' => false, |
|
| 1703 | + 'ee_extra_data' => true, |
|
| 1704 | + 'ee_ssn_' => false, |
|
| 1705 | + 'ee_rss_' => false, |
|
| 1706 | + 'ee_rte_n_tx_' => false, |
|
| 1707 | + 'ee_pers_admin_notices' => true, |
|
| 1708 | + 'ee_job_parameters_' => false, |
|
| 1709 | + 'ee_upload_directories_incomplete' => true, |
|
| 1710 | + 'ee_verified_db_collations' => true, |
|
| 1711 | + ); |
|
| 1712 | + if (is_main_site()) { |
|
| 1713 | + $wp_options_to_delete['ee_network_config'] = true; |
|
| 1714 | + } |
|
| 1715 | + $undeleted_options = array(); |
|
| 1716 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1717 | + if ($no_wildcard) { |
|
| 1718 | + if ( ! delete_option($option_name)) { |
|
| 1719 | + $undeleted_options[] = $option_name; |
|
| 1720 | + } |
|
| 1721 | + } else { |
|
| 1722 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1723 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1724 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1725 | + $undeleted_options[] = $option_name_from_wildcard; |
|
| 1726 | + } |
|
| 1727 | + } |
|
| 1728 | + } |
|
| 1729 | + } |
|
| 1730 | + //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1731 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1732 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1733 | + $db_update_sans_ee4 = array(); |
|
| 1734 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1735 | + if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1736 | + $db_update_sans_ee4[$version] = $times_activated; |
|
| 1737 | + } |
|
| 1738 | + } |
|
| 1739 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1740 | + } |
|
| 1741 | + $errors = ''; |
|
| 1742 | + if ( ! empty($undeleted_options)) { |
|
| 1743 | + $errors .= sprintf( |
|
| 1744 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1745 | + '<br/>', |
|
| 1746 | + implode(',<br/>', $undeleted_options) |
|
| 1747 | + ); |
|
| 1748 | + } |
|
| 1749 | + if ( ! empty($errors)) { |
|
| 1750 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1751 | + } |
|
| 1752 | + } |
|
| 1753 | + |
|
| 1754 | + /** |
|
| 1755 | + * Gets the mysql error code from the last used query by wpdb |
|
| 1756 | + * |
|
| 1757 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1758 | + */ |
|
| 1759 | + public static function last_wpdb_error_code() |
|
| 1760 | + { |
|
| 1761 | + global $wpdb; |
|
| 1762 | + if ($wpdb->use_mysqli) { |
|
| 1763 | + return mysqli_errno($wpdb->dbh); |
|
| 1764 | + } else { |
|
| 1765 | + return mysql_errno($wpdb->dbh); |
|
| 1766 | + } |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + /** |
|
| 1770 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1771 | + * |
|
| 1772 | + * @global wpdb $wpdb |
|
| 1773 | + * @deprecated instead use TableAnalysis::tableExists() |
|
| 1774 | + * @param string $table_name with or without $wpdb->prefix |
|
| 1775 | + * @return boolean |
|
| 1776 | + */ |
|
| 1777 | + public static function table_exists($table_name) |
|
| 1778 | + { |
|
| 1779 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1780 | + } |
|
| 1781 | + |
|
| 1782 | + /** |
|
| 1783 | + * Resets the cache on EEH_Activation |
|
| 1784 | + */ |
|
| 1785 | + public static function reset() |
|
| 1786 | + { |
|
| 1787 | + self::$_default_creator_id = null; |
|
| 1788 | + self::$_initialized_db_content_already_in_this_request = false; |
|
| 1789 | + } |
|
| 1790 | 1790 | } |
| 1791 | 1791 | // End of file EEH_Activation.helper.php |
| 1792 | 1792 | // Location: /helpers/EEH_Activation.core.php |
@@ -532,11 +532,11 @@ discard block |
||
| 532 | 532 | { |
| 533 | 533 | wp_register_style( |
| 534 | 534 | 'events-admin-css', |
| 535 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 535 | + EVENTS_ASSETS_URL.'events-admin-page.css', |
|
| 536 | 536 | array(), |
| 537 | 537 | EVENT_ESPRESSO_VERSION |
| 538 | 538 | ); |
| 539 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 539 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 540 | 540 | wp_enqueue_style('events-admin-css'); |
| 541 | 541 | wp_enqueue_style('ee-cat-admin'); |
| 542 | 542 | //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | //scripts |
| 545 | 545 | wp_register_script( |
| 546 | 546 | 'event_editor_js', |
| 547 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 547 | + EVENTS_ASSETS_URL.'event_editor.js', |
|
| 548 | 548 | array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
| 549 | 549 | EVENT_ESPRESSO_VERSION, |
| 550 | 550 | true |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | wp_enqueue_style('espresso-ui-theme'); |
| 577 | 577 | wp_register_style( |
| 578 | 578 | 'event-editor-css', |
| 579 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 579 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
| 580 | 580 | array('ee-admin-css'), |
| 581 | 581 | EVENT_ESPRESSO_VERSION |
| 582 | 582 | ); |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | //scripts |
| 585 | 585 | wp_register_script( |
| 586 | 586 | 'event-datetime-metabox', |
| 587 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 587 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js', |
|
| 588 | 588 | array('event_editor_js', 'ee-datepicker'), |
| 589 | 589 | EVENT_ESPRESSO_VERSION |
| 590 | 590 | ); |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
| 751 | 751 | 'event_espresso' |
| 752 | 752 | ), |
| 753 | - '<a href="' . admin_url('options-general.php') . '">', |
|
| 753 | + '<a href="'.admin_url('options-general.php').'">', |
|
| 754 | 754 | '</a>' |
| 755 | 755 | ), |
| 756 | 756 | __FILE__, |
@@ -820,31 +820,31 @@ discard block |
||
| 820 | 820 | $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
| 821 | 821 | $statuses = array( |
| 822 | 822 | 'sold_out_status' => array( |
| 823 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 823 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out, |
|
| 824 | 824 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
| 825 | 825 | ), |
| 826 | 826 | 'active_status' => array( |
| 827 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 827 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active, |
|
| 828 | 828 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
| 829 | 829 | ), |
| 830 | 830 | 'upcoming_status' => array( |
| 831 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 831 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming, |
|
| 832 | 832 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
| 833 | 833 | ), |
| 834 | 834 | 'postponed_status' => array( |
| 835 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 835 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed, |
|
| 836 | 836 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
| 837 | 837 | ), |
| 838 | 838 | 'cancelled_status' => array( |
| 839 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 839 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled, |
|
| 840 | 840 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
| 841 | 841 | ), |
| 842 | 842 | 'expired_status' => array( |
| 843 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 843 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired, |
|
| 844 | 844 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
| 845 | 845 | ), |
| 846 | 846 | 'inactive_status' => array( |
| 847 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 847 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive, |
|
| 848 | 848 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
| 849 | 849 | ), |
| 850 | 850 | ); |
@@ -908,7 +908,7 @@ discard block |
||
| 908 | 908 | { |
| 909 | 909 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 910 | 910 | $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
| 911 | - ? (array)$this->_template_args['after_list_table'] |
|
| 911 | + ? (array) $this->_template_args['after_list_table'] |
|
| 912 | 912 | : array(); |
| 913 | 913 | $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
| 914 | 914 | . EEH_Template::get_button_or_link( |
@@ -917,7 +917,7 @@ discard block |
||
| 917 | 917 | 'button' |
| 918 | 918 | ); |
| 919 | 919 | $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
| 920 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 920 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 921 | 921 | 'create_new', |
| 922 | 922 | 'add', |
| 923 | 923 | array(), |
@@ -1047,7 +1047,7 @@ discard block |
||
| 1047 | 1047 | */ |
| 1048 | 1048 | protected function _default_venue_update(\EE_Event $evtobj, $data) |
| 1049 | 1049 | { |
| 1050 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1050 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
| 1051 | 1051 | $venue_model = EE_Registry::instance()->load_model('Venue'); |
| 1052 | 1052 | $rows_affected = null; |
| 1053 | 1053 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
@@ -1171,7 +1171,7 @@ discard block |
||
| 1171 | 1171 | if (empty($tkt['TKT_start_date'])) { |
| 1172 | 1172 | //let's use now in the set timezone. |
| 1173 | 1173 | $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
| 1174 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1174 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]); |
|
| 1175 | 1175 | } |
| 1176 | 1176 | if (empty($tkt['TKT_end_date'])) { |
| 1177 | 1177 | //use the start date of the first datetime |
@@ -1460,7 +1460,7 @@ discard block |
||
| 1460 | 1460 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
| 1461 | 1461 | // load template |
| 1462 | 1462 | EEH_Template::display_template( |
| 1463 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1463 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', |
|
| 1464 | 1464 | $publish_box_extra_args |
| 1465 | 1465 | ); |
| 1466 | 1466 | } |
@@ -1587,7 +1587,7 @@ discard block |
||
| 1587 | 1587 | ); |
| 1588 | 1588 | $template = apply_filters( |
| 1589 | 1589 | 'FHEE__Events_Admin_Page__ticket_metabox__template', |
| 1590 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1590 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php' |
|
| 1591 | 1591 | ); |
| 1592 | 1592 | EEH_Template::display_template($template, $template_args); |
| 1593 | 1593 | } |
@@ -1606,7 +1606,7 @@ discard block |
||
| 1606 | 1606 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
| 1607 | 1607 | { |
| 1608 | 1608 | $template_args = array( |
| 1609 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1609 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
| 1610 | 1610 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
| 1611 | 1611 | : '', |
| 1612 | 1612 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
@@ -1660,7 +1660,7 @@ discard block |
||
| 1660 | 1660 | $template_args = array_merge($template_args, $price_args); |
| 1661 | 1661 | $template = apply_filters( |
| 1662 | 1662 | 'FHEE__Events_Admin_Page__get_ticket_row__template', |
| 1663 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1663 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', |
|
| 1664 | 1664 | $ticket |
| 1665 | 1665 | ); |
| 1666 | 1666 | return EEH_Template::display_template($template, $template_args, true); |
@@ -1712,7 +1712,7 @@ discard block |
||
| 1712 | 1712 | $default_reg_status_values |
| 1713 | 1713 | ); |
| 1714 | 1714 | EEH_Template::display_template( |
| 1715 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1715 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 1716 | 1716 | $template_args |
| 1717 | 1717 | ); |
| 1718 | 1718 | } |
@@ -1735,7 +1735,7 @@ discard block |
||
| 1735 | 1735 | { |
| 1736 | 1736 | $EEME = $this->_event_model(); |
| 1737 | 1737 | $offset = ($current_page - 1) * $per_page; |
| 1738 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1738 | + $limit = $count ? null : $offset.','.$per_page; |
|
| 1739 | 1739 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
| 1740 | 1740 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
| 1741 | 1741 | if (isset($this->_req_data['month_range'])) { |
@@ -1769,7 +1769,7 @@ discard block |
||
| 1769 | 1769 | $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
| 1770 | 1770 | if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
| 1771 | 1771 | $DateTime = new DateTime( |
| 1772 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1772 | + $year_r.'-'.$month_r.'-01 00:00:00', |
|
| 1773 | 1773 | new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
| 1774 | 1774 | ); |
| 1775 | 1775 | $start = $DateTime->format(implode(' ', $start_formats)); |
@@ -1815,7 +1815,7 @@ discard block |
||
| 1815 | 1815 | } |
| 1816 | 1816 | //search query handling |
| 1817 | 1817 | if (isset($this->_req_data['s'])) { |
| 1818 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1818 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 1819 | 1819 | $where['OR'] = array( |
| 1820 | 1820 | 'EVT_name' => array('LIKE', $search_string), |
| 1821 | 1821 | 'EVT_desc' => array('LIKE', $search_string), |
@@ -1949,7 +1949,7 @@ discard block |
||
| 1949 | 1949 | if ( ! empty($event_status)) { |
| 1950 | 1950 | $success = true; |
| 1951 | 1951 | //determine the event id and set to array. |
| 1952 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1952 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
| 1953 | 1953 | // loop thru events |
| 1954 | 1954 | foreach ($EVT_IDs as $EVT_ID) { |
| 1955 | 1955 | if ($EVT_ID = absint($EVT_ID)) { |
@@ -2097,7 +2097,7 @@ discard block |
||
| 2097 | 2097 | // get list of events with no prices |
| 2098 | 2098 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
| 2099 | 2099 | //determine the event id and set to array. |
| 2100 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2100 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
| 2101 | 2101 | // loop thru events |
| 2102 | 2102 | foreach ($EVT_IDs as $EVT_ID) { |
| 2103 | 2103 | $EVT_ID = absint($EVT_ID); |
@@ -2280,7 +2280,7 @@ discard block |
||
| 2280 | 2280 | $this->_set_add_edit_form_tags('update_default_event_settings'); |
| 2281 | 2281 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
| 2282 | 2282 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 2283 | - EVENTS_TEMPLATE_PATH . 'event_settings.template.php', |
|
| 2283 | + EVENTS_TEMPLATE_PATH.'event_settings.template.php', |
|
| 2284 | 2284 | $this->_template_args, |
| 2285 | 2285 | true |
| 2286 | 2286 | ); |
@@ -2325,10 +2325,10 @@ discard block |
||
| 2325 | 2325 | . 'caffeinated_template_features.jpg" alt="' |
| 2326 | 2326 | . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
| 2327 | 2327 | . '" />'; |
| 2328 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2328 | + $this->_template_args['preview_text'] = '<strong>'.esc_html__( |
|
| 2329 | 2329 | 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
| 2330 | 2330 | 'event_espresso' |
| 2331 | - ) . '</strong>'; |
|
| 2331 | + ).'</strong>'; |
|
| 2332 | 2332 | $this->display_admin_caf_preview_page('template_settings_tab'); |
| 2333 | 2333 | } |
| 2334 | 2334 | |
@@ -2377,7 +2377,7 @@ discard block |
||
| 2377 | 2377 | { |
| 2378 | 2378 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2379 | 2379 | $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
| 2380 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2380 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 2381 | 2381 | 'add_category', |
| 2382 | 2382 | 'add_category', |
| 2383 | 2383 | array(), |
@@ -2453,7 +2453,7 @@ discard block |
||
| 2453 | 2453 | 'disable' => '', |
| 2454 | 2454 | 'disabled_message' => false, |
| 2455 | 2455 | ); |
| 2456 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2456 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
| 2457 | 2457 | return EEH_Template::display_template($template, $template_args, true); |
| 2458 | 2458 | } |
| 2459 | 2459 | |
@@ -2461,8 +2461,8 @@ discard block |
||
| 2461 | 2461 | |
| 2462 | 2462 | protected function _delete_categories() |
| 2463 | 2463 | { |
| 2464 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2465 | - : (array)$this->_req_data['category_id']; |
|
| 2464 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
| 2465 | + : (array) $this->_req_data['category_id']; |
|
| 2466 | 2466 | foreach ($cat_ids as $cat_id) { |
| 2467 | 2467 | $this->_delete_category($cat_id); |
| 2468 | 2468 | } |
@@ -2563,7 +2563,7 @@ discard block |
||
| 2563 | 2563 | $limit = ($current_page - 1) * $per_page; |
| 2564 | 2564 | $where = array('taxonomy' => 'espresso_event_categories'); |
| 2565 | 2565 | if (isset($this->_req_data['s'])) { |
| 2566 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2566 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 2567 | 2567 | $where['OR'] = array( |
| 2568 | 2568 | 'Term.name' => array('LIKE', $sstr), |
| 2569 | 2569 | 'description' => array('LIKE', $sstr), |
@@ -2572,7 +2572,7 @@ discard block |
||
| 2572 | 2572 | $query_params = array( |
| 2573 | 2573 | $where, |
| 2574 | 2574 | 'order_by' => array($orderby => $order), |
| 2575 | - 'limit' => $limit . ',' . $per_page, |
|
| 2575 | + 'limit' => $limit.','.$per_page, |
|
| 2576 | 2576 | 'force_join' => array('Term'), |
| 2577 | 2577 | ); |
| 2578 | 2578 | $categories = $count |
@@ -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 | |
@@ -17,2576 +17,2576 @@ discard block |
||
| 17 | 17 | class Events_Admin_Page extends EE_Admin_Page_CPT |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * This will hold the event object for event_details screen. |
|
| 22 | - * |
|
| 23 | - * @access protected |
|
| 24 | - * @var EE_Event $_event |
|
| 25 | - */ |
|
| 26 | - protected $_event; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * This will hold the category object for category_details screen. |
|
| 31 | - * |
|
| 32 | - * @var stdClass $_category |
|
| 33 | - */ |
|
| 34 | - protected $_category; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * This will hold the event model instance |
|
| 39 | - * |
|
| 40 | - * @var EEM_Event $_event_model |
|
| 41 | - */ |
|
| 42 | - protected $_event_model; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var EE_Event |
|
| 48 | - */ |
|
| 49 | - protected $_cpt_model_obj = false; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - protected function _init_page_props() |
|
| 54 | - { |
|
| 55 | - $this->page_slug = EVENTS_PG_SLUG; |
|
| 56 | - $this->page_label = EVENTS_LABEL; |
|
| 57 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 58 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
| 59 | - $this->_cpt_model_names = array( |
|
| 60 | - 'create_new' => 'EEM_Event', |
|
| 61 | - 'edit' => 'EEM_Event', |
|
| 62 | - ); |
|
| 63 | - $this->_cpt_edit_routes = array( |
|
| 64 | - 'espresso_events' => 'edit', |
|
| 65 | - ); |
|
| 66 | - add_action( |
|
| 67 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 68 | - array($this, 'verify_event_edit') |
|
| 69 | - ); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - protected function _ajax_hooks() |
|
| 75 | - { |
|
| 76 | - //todo: all hooks for events ajax goes in here. |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - protected function _define_page_props() |
|
| 82 | - { |
|
| 83 | - $this->_admin_page_title = EVENTS_LABEL; |
|
| 84 | - $this->_labels = array( |
|
| 85 | - 'buttons' => array( |
|
| 86 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 87 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 88 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 89 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 90 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 91 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 92 | - ), |
|
| 93 | - 'editor_title' => array( |
|
| 94 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 95 | - ), |
|
| 96 | - 'publishbox' => array( |
|
| 97 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 98 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 99 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 100 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 101 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 102 | - ), |
|
| 103 | - ); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - protected function _set_page_routes() |
|
| 109 | - { |
|
| 110 | - //load formatter helper |
|
| 111 | - //load field generator helper |
|
| 112 | - //is there a evt_id in the request? |
|
| 113 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 114 | - ? $this->_req_data['EVT_ID'] : 0; |
|
| 115 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 116 | - $this->_page_routes = array( |
|
| 117 | - 'default' => array( |
|
| 118 | - 'func' => '_events_overview_list_table', |
|
| 119 | - 'capability' => 'ee_read_events', |
|
| 120 | - ), |
|
| 121 | - 'create_new' => array( |
|
| 122 | - 'func' => '_create_new_cpt_item', |
|
| 123 | - 'capability' => 'ee_edit_events', |
|
| 124 | - ), |
|
| 125 | - 'edit' => array( |
|
| 126 | - 'func' => '_edit_cpt_item', |
|
| 127 | - 'capability' => 'ee_edit_event', |
|
| 128 | - 'obj_id' => $evt_id, |
|
| 129 | - ), |
|
| 130 | - 'copy_event' => array( |
|
| 131 | - 'func' => '_copy_events', |
|
| 132 | - 'capability' => 'ee_edit_event', |
|
| 133 | - 'obj_id' => $evt_id, |
|
| 134 | - 'noheader' => true, |
|
| 135 | - ), |
|
| 136 | - 'trash_event' => array( |
|
| 137 | - 'func' => '_trash_or_restore_event', |
|
| 138 | - 'args' => array('event_status' => 'trash'), |
|
| 139 | - 'capability' => 'ee_delete_event', |
|
| 140 | - 'obj_id' => $evt_id, |
|
| 141 | - 'noheader' => true, |
|
| 142 | - ), |
|
| 143 | - 'trash_events' => array( |
|
| 144 | - 'func' => '_trash_or_restore_events', |
|
| 145 | - 'args' => array('event_status' => 'trash'), |
|
| 146 | - 'capability' => 'ee_delete_events', |
|
| 147 | - 'noheader' => true, |
|
| 148 | - ), |
|
| 149 | - 'restore_event' => array( |
|
| 150 | - 'func' => '_trash_or_restore_event', |
|
| 151 | - 'args' => array('event_status' => 'draft'), |
|
| 152 | - 'capability' => 'ee_delete_event', |
|
| 153 | - 'obj_id' => $evt_id, |
|
| 154 | - 'noheader' => true, |
|
| 155 | - ), |
|
| 156 | - 'restore_events' => array( |
|
| 157 | - 'func' => '_trash_or_restore_events', |
|
| 158 | - 'args' => array('event_status' => 'draft'), |
|
| 159 | - 'capability' => 'ee_delete_events', |
|
| 160 | - 'noheader' => true, |
|
| 161 | - ), |
|
| 162 | - 'delete_event' => array( |
|
| 163 | - 'func' => '_delete_event', |
|
| 164 | - 'capability' => 'ee_delete_event', |
|
| 165 | - 'obj_id' => $evt_id, |
|
| 166 | - 'noheader' => true, |
|
| 167 | - ), |
|
| 168 | - 'delete_events' => array( |
|
| 169 | - 'func' => '_delete_events', |
|
| 170 | - 'capability' => 'ee_delete_events', |
|
| 171 | - 'noheader' => true, |
|
| 172 | - ), |
|
| 173 | - 'view_report' => array( |
|
| 174 | - 'func' => '_view_report', |
|
| 175 | - 'capablity' => 'ee_edit_events', |
|
| 176 | - ), |
|
| 177 | - 'default_event_settings' => array( |
|
| 178 | - 'func' => '_default_event_settings', |
|
| 179 | - 'capability' => 'manage_options', |
|
| 180 | - ), |
|
| 181 | - 'update_default_event_settings' => array( |
|
| 182 | - 'func' => '_update_default_event_settings', |
|
| 183 | - 'capability' => 'manage_options', |
|
| 184 | - 'noheader' => true, |
|
| 185 | - ), |
|
| 186 | - 'template_settings' => array( |
|
| 187 | - 'func' => '_template_settings', |
|
| 188 | - 'capability' => 'manage_options', |
|
| 189 | - ), |
|
| 190 | - //event category tab related |
|
| 191 | - 'add_category' => array( |
|
| 192 | - 'func' => '_category_details', |
|
| 193 | - 'capability' => 'ee_edit_event_category', |
|
| 194 | - 'args' => array('add'), |
|
| 195 | - ), |
|
| 196 | - 'edit_category' => array( |
|
| 197 | - 'func' => '_category_details', |
|
| 198 | - 'capability' => 'ee_edit_event_category', |
|
| 199 | - 'args' => array('edit'), |
|
| 200 | - ), |
|
| 201 | - 'delete_categories' => array( |
|
| 202 | - 'func' => '_delete_categories', |
|
| 203 | - 'capability' => 'ee_delete_event_category', |
|
| 204 | - 'noheader' => true, |
|
| 205 | - ), |
|
| 206 | - 'delete_category' => array( |
|
| 207 | - 'func' => '_delete_categories', |
|
| 208 | - 'capability' => 'ee_delete_event_category', |
|
| 209 | - 'noheader' => true, |
|
| 210 | - ), |
|
| 211 | - 'insert_category' => array( |
|
| 212 | - 'func' => '_insert_or_update_category', |
|
| 213 | - 'args' => array('new_category' => true), |
|
| 214 | - 'capability' => 'ee_edit_event_category', |
|
| 215 | - 'noheader' => true, |
|
| 216 | - ), |
|
| 217 | - 'update_category' => array( |
|
| 218 | - 'func' => '_insert_or_update_category', |
|
| 219 | - 'args' => array('new_category' => false), |
|
| 220 | - 'capability' => 'ee_edit_event_category', |
|
| 221 | - 'noheader' => true, |
|
| 222 | - ), |
|
| 223 | - 'category_list' => array( |
|
| 224 | - 'func' => '_category_list_table', |
|
| 225 | - 'capability' => 'ee_manage_event_categories', |
|
| 226 | - ), |
|
| 227 | - ); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - protected function _set_page_config() |
|
| 233 | - { |
|
| 234 | - $this->_page_config = array( |
|
| 235 | - 'default' => array( |
|
| 236 | - 'nav' => array( |
|
| 237 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 238 | - 'order' => 10, |
|
| 239 | - ), |
|
| 240 | - 'list_table' => 'Events_Admin_List_Table', |
|
| 241 | - 'help_tabs' => array( |
|
| 242 | - 'events_overview_help_tab' => array( |
|
| 243 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 244 | - 'filename' => 'events_overview', |
|
| 245 | - ), |
|
| 246 | - 'events_overview_table_column_headings_help_tab' => array( |
|
| 247 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 248 | - 'filename' => 'events_overview_table_column_headings', |
|
| 249 | - ), |
|
| 250 | - 'events_overview_filters_help_tab' => array( |
|
| 251 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 252 | - 'filename' => 'events_overview_filters', |
|
| 253 | - ), |
|
| 254 | - 'events_overview_view_help_tab' => array( |
|
| 255 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 256 | - 'filename' => 'events_overview_views', |
|
| 257 | - ), |
|
| 258 | - 'events_overview_other_help_tab' => array( |
|
| 259 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 260 | - 'filename' => 'events_overview_other', |
|
| 261 | - ), |
|
| 262 | - ), |
|
| 263 | - 'help_tour' => array( |
|
| 264 | - 'Event_Overview_Help_Tour', |
|
| 265 | - //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 266 | - ), |
|
| 267 | - 'qtips' => array( |
|
| 268 | - 'EE_Event_List_Table_Tips', |
|
| 269 | - ), |
|
| 270 | - 'require_nonce' => false, |
|
| 271 | - ), |
|
| 272 | - 'create_new' => array( |
|
| 273 | - 'nav' => array( |
|
| 274 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 275 | - 'order' => 5, |
|
| 276 | - 'persistent' => false, |
|
| 277 | - ), |
|
| 278 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 279 | - 'help_tabs' => array( |
|
| 280 | - 'event_editor_help_tab' => array( |
|
| 281 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 282 | - 'filename' => 'event_editor', |
|
| 283 | - ), |
|
| 284 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 285 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 286 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 287 | - ), |
|
| 288 | - 'event_editor_venue_details_help_tab' => array( |
|
| 289 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 290 | - 'filename' => 'event_editor_venue_details', |
|
| 291 | - ), |
|
| 292 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 293 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 294 | - 'filename' => 'event_editor_event_datetimes', |
|
| 295 | - ), |
|
| 296 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 297 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 298 | - 'filename' => 'event_editor_event_tickets', |
|
| 299 | - ), |
|
| 300 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 301 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 302 | - 'filename' => 'event_editor_event_registration_options', |
|
| 303 | - ), |
|
| 304 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 305 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 306 | - 'filename' => 'event_editor_tags_categories', |
|
| 307 | - ), |
|
| 308 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 309 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 310 | - 'filename' => 'event_editor_questions_registrants', |
|
| 311 | - ), |
|
| 312 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 313 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 314 | - 'filename' => 'event_editor_save_new_event', |
|
| 315 | - ), |
|
| 316 | - 'event_editor_other_help_tab' => array( |
|
| 317 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 318 | - 'filename' => 'event_editor_other', |
|
| 319 | - ), |
|
| 320 | - ), |
|
| 321 | - 'help_tour' => array( |
|
| 322 | - 'Event_Editor_Help_Tour', |
|
| 323 | - ), |
|
| 324 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 325 | - 'require_nonce' => false, |
|
| 326 | - ), |
|
| 327 | - 'edit' => array( |
|
| 328 | - 'nav' => array( |
|
| 329 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 330 | - 'order' => 5, |
|
| 331 | - 'persistent' => false, |
|
| 332 | - 'url' => isset($this->_req_data['post']) |
|
| 333 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 334 | - array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 335 | - $this->_current_page_view_url |
|
| 336 | - ) |
|
| 337 | - : $this->_admin_base_url, |
|
| 338 | - ), |
|
| 339 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 340 | - 'help_tabs' => array( |
|
| 341 | - 'event_editor_help_tab' => array( |
|
| 342 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 343 | - 'filename' => 'event_editor', |
|
| 344 | - ), |
|
| 345 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 346 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 347 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 348 | - ), |
|
| 349 | - 'event_editor_venue_details_help_tab' => array( |
|
| 350 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 351 | - 'filename' => 'event_editor_venue_details', |
|
| 352 | - ), |
|
| 353 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 354 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 355 | - 'filename' => 'event_editor_event_datetimes', |
|
| 356 | - ), |
|
| 357 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 358 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 359 | - 'filename' => 'event_editor_event_tickets', |
|
| 360 | - ), |
|
| 361 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 362 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 363 | - 'filename' => 'event_editor_event_registration_options', |
|
| 364 | - ), |
|
| 365 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 366 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 367 | - 'filename' => 'event_editor_tags_categories', |
|
| 368 | - ), |
|
| 369 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 370 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 371 | - 'filename' => 'event_editor_questions_registrants', |
|
| 372 | - ), |
|
| 373 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 374 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 375 | - 'filename' => 'event_editor_save_new_event', |
|
| 376 | - ), |
|
| 377 | - 'event_editor_other_help_tab' => array( |
|
| 378 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 379 | - 'filename' => 'event_editor_other', |
|
| 380 | - ), |
|
| 381 | - ), |
|
| 382 | - /*'help_tour' => array( |
|
| 20 | + /** |
|
| 21 | + * This will hold the event object for event_details screen. |
|
| 22 | + * |
|
| 23 | + * @access protected |
|
| 24 | + * @var EE_Event $_event |
|
| 25 | + */ |
|
| 26 | + protected $_event; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * This will hold the category object for category_details screen. |
|
| 31 | + * |
|
| 32 | + * @var stdClass $_category |
|
| 33 | + */ |
|
| 34 | + protected $_category; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * This will hold the event model instance |
|
| 39 | + * |
|
| 40 | + * @var EEM_Event $_event_model |
|
| 41 | + */ |
|
| 42 | + protected $_event_model; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var EE_Event |
|
| 48 | + */ |
|
| 49 | + protected $_cpt_model_obj = false; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + protected function _init_page_props() |
|
| 54 | + { |
|
| 55 | + $this->page_slug = EVENTS_PG_SLUG; |
|
| 56 | + $this->page_label = EVENTS_LABEL; |
|
| 57 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 58 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
| 59 | + $this->_cpt_model_names = array( |
|
| 60 | + 'create_new' => 'EEM_Event', |
|
| 61 | + 'edit' => 'EEM_Event', |
|
| 62 | + ); |
|
| 63 | + $this->_cpt_edit_routes = array( |
|
| 64 | + 'espresso_events' => 'edit', |
|
| 65 | + ); |
|
| 66 | + add_action( |
|
| 67 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 68 | + array($this, 'verify_event_edit') |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + protected function _ajax_hooks() |
|
| 75 | + { |
|
| 76 | + //todo: all hooks for events ajax goes in here. |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + protected function _define_page_props() |
|
| 82 | + { |
|
| 83 | + $this->_admin_page_title = EVENTS_LABEL; |
|
| 84 | + $this->_labels = array( |
|
| 85 | + 'buttons' => array( |
|
| 86 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 87 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 88 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 89 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 90 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 91 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 92 | + ), |
|
| 93 | + 'editor_title' => array( |
|
| 94 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 95 | + ), |
|
| 96 | + 'publishbox' => array( |
|
| 97 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 98 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 99 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 100 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 101 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 102 | + ), |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + protected function _set_page_routes() |
|
| 109 | + { |
|
| 110 | + //load formatter helper |
|
| 111 | + //load field generator helper |
|
| 112 | + //is there a evt_id in the request? |
|
| 113 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 114 | + ? $this->_req_data['EVT_ID'] : 0; |
|
| 115 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 116 | + $this->_page_routes = array( |
|
| 117 | + 'default' => array( |
|
| 118 | + 'func' => '_events_overview_list_table', |
|
| 119 | + 'capability' => 'ee_read_events', |
|
| 120 | + ), |
|
| 121 | + 'create_new' => array( |
|
| 122 | + 'func' => '_create_new_cpt_item', |
|
| 123 | + 'capability' => 'ee_edit_events', |
|
| 124 | + ), |
|
| 125 | + 'edit' => array( |
|
| 126 | + 'func' => '_edit_cpt_item', |
|
| 127 | + 'capability' => 'ee_edit_event', |
|
| 128 | + 'obj_id' => $evt_id, |
|
| 129 | + ), |
|
| 130 | + 'copy_event' => array( |
|
| 131 | + 'func' => '_copy_events', |
|
| 132 | + 'capability' => 'ee_edit_event', |
|
| 133 | + 'obj_id' => $evt_id, |
|
| 134 | + 'noheader' => true, |
|
| 135 | + ), |
|
| 136 | + 'trash_event' => array( |
|
| 137 | + 'func' => '_trash_or_restore_event', |
|
| 138 | + 'args' => array('event_status' => 'trash'), |
|
| 139 | + 'capability' => 'ee_delete_event', |
|
| 140 | + 'obj_id' => $evt_id, |
|
| 141 | + 'noheader' => true, |
|
| 142 | + ), |
|
| 143 | + 'trash_events' => array( |
|
| 144 | + 'func' => '_trash_or_restore_events', |
|
| 145 | + 'args' => array('event_status' => 'trash'), |
|
| 146 | + 'capability' => 'ee_delete_events', |
|
| 147 | + 'noheader' => true, |
|
| 148 | + ), |
|
| 149 | + 'restore_event' => array( |
|
| 150 | + 'func' => '_trash_or_restore_event', |
|
| 151 | + 'args' => array('event_status' => 'draft'), |
|
| 152 | + 'capability' => 'ee_delete_event', |
|
| 153 | + 'obj_id' => $evt_id, |
|
| 154 | + 'noheader' => true, |
|
| 155 | + ), |
|
| 156 | + 'restore_events' => array( |
|
| 157 | + 'func' => '_trash_or_restore_events', |
|
| 158 | + 'args' => array('event_status' => 'draft'), |
|
| 159 | + 'capability' => 'ee_delete_events', |
|
| 160 | + 'noheader' => true, |
|
| 161 | + ), |
|
| 162 | + 'delete_event' => array( |
|
| 163 | + 'func' => '_delete_event', |
|
| 164 | + 'capability' => 'ee_delete_event', |
|
| 165 | + 'obj_id' => $evt_id, |
|
| 166 | + 'noheader' => true, |
|
| 167 | + ), |
|
| 168 | + 'delete_events' => array( |
|
| 169 | + 'func' => '_delete_events', |
|
| 170 | + 'capability' => 'ee_delete_events', |
|
| 171 | + 'noheader' => true, |
|
| 172 | + ), |
|
| 173 | + 'view_report' => array( |
|
| 174 | + 'func' => '_view_report', |
|
| 175 | + 'capablity' => 'ee_edit_events', |
|
| 176 | + ), |
|
| 177 | + 'default_event_settings' => array( |
|
| 178 | + 'func' => '_default_event_settings', |
|
| 179 | + 'capability' => 'manage_options', |
|
| 180 | + ), |
|
| 181 | + 'update_default_event_settings' => array( |
|
| 182 | + 'func' => '_update_default_event_settings', |
|
| 183 | + 'capability' => 'manage_options', |
|
| 184 | + 'noheader' => true, |
|
| 185 | + ), |
|
| 186 | + 'template_settings' => array( |
|
| 187 | + 'func' => '_template_settings', |
|
| 188 | + 'capability' => 'manage_options', |
|
| 189 | + ), |
|
| 190 | + //event category tab related |
|
| 191 | + 'add_category' => array( |
|
| 192 | + 'func' => '_category_details', |
|
| 193 | + 'capability' => 'ee_edit_event_category', |
|
| 194 | + 'args' => array('add'), |
|
| 195 | + ), |
|
| 196 | + 'edit_category' => array( |
|
| 197 | + 'func' => '_category_details', |
|
| 198 | + 'capability' => 'ee_edit_event_category', |
|
| 199 | + 'args' => array('edit'), |
|
| 200 | + ), |
|
| 201 | + 'delete_categories' => array( |
|
| 202 | + 'func' => '_delete_categories', |
|
| 203 | + 'capability' => 'ee_delete_event_category', |
|
| 204 | + 'noheader' => true, |
|
| 205 | + ), |
|
| 206 | + 'delete_category' => array( |
|
| 207 | + 'func' => '_delete_categories', |
|
| 208 | + 'capability' => 'ee_delete_event_category', |
|
| 209 | + 'noheader' => true, |
|
| 210 | + ), |
|
| 211 | + 'insert_category' => array( |
|
| 212 | + 'func' => '_insert_or_update_category', |
|
| 213 | + 'args' => array('new_category' => true), |
|
| 214 | + 'capability' => 'ee_edit_event_category', |
|
| 215 | + 'noheader' => true, |
|
| 216 | + ), |
|
| 217 | + 'update_category' => array( |
|
| 218 | + 'func' => '_insert_or_update_category', |
|
| 219 | + 'args' => array('new_category' => false), |
|
| 220 | + 'capability' => 'ee_edit_event_category', |
|
| 221 | + 'noheader' => true, |
|
| 222 | + ), |
|
| 223 | + 'category_list' => array( |
|
| 224 | + 'func' => '_category_list_table', |
|
| 225 | + 'capability' => 'ee_manage_event_categories', |
|
| 226 | + ), |
|
| 227 | + ); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + protected function _set_page_config() |
|
| 233 | + { |
|
| 234 | + $this->_page_config = array( |
|
| 235 | + 'default' => array( |
|
| 236 | + 'nav' => array( |
|
| 237 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 238 | + 'order' => 10, |
|
| 239 | + ), |
|
| 240 | + 'list_table' => 'Events_Admin_List_Table', |
|
| 241 | + 'help_tabs' => array( |
|
| 242 | + 'events_overview_help_tab' => array( |
|
| 243 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 244 | + 'filename' => 'events_overview', |
|
| 245 | + ), |
|
| 246 | + 'events_overview_table_column_headings_help_tab' => array( |
|
| 247 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 248 | + 'filename' => 'events_overview_table_column_headings', |
|
| 249 | + ), |
|
| 250 | + 'events_overview_filters_help_tab' => array( |
|
| 251 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 252 | + 'filename' => 'events_overview_filters', |
|
| 253 | + ), |
|
| 254 | + 'events_overview_view_help_tab' => array( |
|
| 255 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 256 | + 'filename' => 'events_overview_views', |
|
| 257 | + ), |
|
| 258 | + 'events_overview_other_help_tab' => array( |
|
| 259 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 260 | + 'filename' => 'events_overview_other', |
|
| 261 | + ), |
|
| 262 | + ), |
|
| 263 | + 'help_tour' => array( |
|
| 264 | + 'Event_Overview_Help_Tour', |
|
| 265 | + //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 266 | + ), |
|
| 267 | + 'qtips' => array( |
|
| 268 | + 'EE_Event_List_Table_Tips', |
|
| 269 | + ), |
|
| 270 | + 'require_nonce' => false, |
|
| 271 | + ), |
|
| 272 | + 'create_new' => array( |
|
| 273 | + 'nav' => array( |
|
| 274 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 275 | + 'order' => 5, |
|
| 276 | + 'persistent' => false, |
|
| 277 | + ), |
|
| 278 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 279 | + 'help_tabs' => array( |
|
| 280 | + 'event_editor_help_tab' => array( |
|
| 281 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 282 | + 'filename' => 'event_editor', |
|
| 283 | + ), |
|
| 284 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 285 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 286 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 287 | + ), |
|
| 288 | + 'event_editor_venue_details_help_tab' => array( |
|
| 289 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 290 | + 'filename' => 'event_editor_venue_details', |
|
| 291 | + ), |
|
| 292 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 293 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 294 | + 'filename' => 'event_editor_event_datetimes', |
|
| 295 | + ), |
|
| 296 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 297 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 298 | + 'filename' => 'event_editor_event_tickets', |
|
| 299 | + ), |
|
| 300 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 301 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 302 | + 'filename' => 'event_editor_event_registration_options', |
|
| 303 | + ), |
|
| 304 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 305 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 306 | + 'filename' => 'event_editor_tags_categories', |
|
| 307 | + ), |
|
| 308 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 309 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 310 | + 'filename' => 'event_editor_questions_registrants', |
|
| 311 | + ), |
|
| 312 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 313 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 314 | + 'filename' => 'event_editor_save_new_event', |
|
| 315 | + ), |
|
| 316 | + 'event_editor_other_help_tab' => array( |
|
| 317 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 318 | + 'filename' => 'event_editor_other', |
|
| 319 | + ), |
|
| 320 | + ), |
|
| 321 | + 'help_tour' => array( |
|
| 322 | + 'Event_Editor_Help_Tour', |
|
| 323 | + ), |
|
| 324 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 325 | + 'require_nonce' => false, |
|
| 326 | + ), |
|
| 327 | + 'edit' => array( |
|
| 328 | + 'nav' => array( |
|
| 329 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 330 | + 'order' => 5, |
|
| 331 | + 'persistent' => false, |
|
| 332 | + 'url' => isset($this->_req_data['post']) |
|
| 333 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 334 | + array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 335 | + $this->_current_page_view_url |
|
| 336 | + ) |
|
| 337 | + : $this->_admin_base_url, |
|
| 338 | + ), |
|
| 339 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 340 | + 'help_tabs' => array( |
|
| 341 | + 'event_editor_help_tab' => array( |
|
| 342 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 343 | + 'filename' => 'event_editor', |
|
| 344 | + ), |
|
| 345 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 346 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 347 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 348 | + ), |
|
| 349 | + 'event_editor_venue_details_help_tab' => array( |
|
| 350 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 351 | + 'filename' => 'event_editor_venue_details', |
|
| 352 | + ), |
|
| 353 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 354 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 355 | + 'filename' => 'event_editor_event_datetimes', |
|
| 356 | + ), |
|
| 357 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 358 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 359 | + 'filename' => 'event_editor_event_tickets', |
|
| 360 | + ), |
|
| 361 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 362 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 363 | + 'filename' => 'event_editor_event_registration_options', |
|
| 364 | + ), |
|
| 365 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 366 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 367 | + 'filename' => 'event_editor_tags_categories', |
|
| 368 | + ), |
|
| 369 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 370 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 371 | + 'filename' => 'event_editor_questions_registrants', |
|
| 372 | + ), |
|
| 373 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 374 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 375 | + 'filename' => 'event_editor_save_new_event', |
|
| 376 | + ), |
|
| 377 | + 'event_editor_other_help_tab' => array( |
|
| 378 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 379 | + 'filename' => 'event_editor_other', |
|
| 380 | + ), |
|
| 381 | + ), |
|
| 382 | + /*'help_tour' => array( |
|
| 383 | 383 | 'Event_Edit_Help_Tour' |
| 384 | 384 | ),*/ |
| 385 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 386 | - 'require_nonce' => false, |
|
| 387 | - ), |
|
| 388 | - 'default_event_settings' => array( |
|
| 389 | - 'nav' => array( |
|
| 390 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 391 | - 'order' => 40, |
|
| 392 | - ), |
|
| 393 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 394 | - 'labels' => array( |
|
| 395 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 396 | - ), |
|
| 397 | - 'help_tabs' => array( |
|
| 398 | - 'default_settings_help_tab' => array( |
|
| 399 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 400 | - 'filename' => 'events_default_settings', |
|
| 401 | - ), |
|
| 402 | - 'default_settings_status_help_tab' => array( |
|
| 403 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 404 | - 'filename' => 'events_default_settings_status', |
|
| 405 | - ), |
|
| 406 | - ), |
|
| 407 | - 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 408 | - 'require_nonce' => false, |
|
| 409 | - ), |
|
| 410 | - //template settings |
|
| 411 | - 'template_settings' => array( |
|
| 412 | - 'nav' => array( |
|
| 413 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 414 | - 'order' => 30, |
|
| 415 | - ), |
|
| 416 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 417 | - 'help_tabs' => array( |
|
| 418 | - 'general_settings_templates_help_tab' => array( |
|
| 419 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 420 | - 'filename' => 'general_settings_templates', |
|
| 421 | - ), |
|
| 422 | - ), |
|
| 423 | - 'help_tour' => array('Templates_Help_Tour'), |
|
| 424 | - 'require_nonce' => false, |
|
| 425 | - ), |
|
| 426 | - //event category stuff |
|
| 427 | - 'add_category' => array( |
|
| 428 | - 'nav' => array( |
|
| 429 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 430 | - 'order' => 15, |
|
| 431 | - 'persistent' => false, |
|
| 432 | - ), |
|
| 433 | - 'help_tabs' => array( |
|
| 434 | - 'add_category_help_tab' => array( |
|
| 435 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 436 | - 'filename' => 'events_add_category', |
|
| 437 | - ), |
|
| 438 | - ), |
|
| 439 | - 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 440 | - 'metaboxes' => array('_publish_post_box'), |
|
| 441 | - 'require_nonce' => false, |
|
| 442 | - ), |
|
| 443 | - 'edit_category' => array( |
|
| 444 | - 'nav' => array( |
|
| 445 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 446 | - 'order' => 15, |
|
| 447 | - 'persistent' => false, |
|
| 448 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 449 | - ? add_query_arg( |
|
| 450 | - array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 451 | - $this->_current_page_view_url |
|
| 452 | - ) |
|
| 453 | - : $this->_admin_base_url, |
|
| 454 | - ), |
|
| 455 | - 'help_tabs' => array( |
|
| 456 | - 'edit_category_help_tab' => array( |
|
| 457 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 458 | - 'filename' => 'events_edit_category', |
|
| 459 | - ), |
|
| 460 | - ), |
|
| 461 | - /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 462 | - 'metaboxes' => array('_publish_post_box'), |
|
| 463 | - 'require_nonce' => false, |
|
| 464 | - ), |
|
| 465 | - 'category_list' => array( |
|
| 466 | - 'nav' => array( |
|
| 467 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 468 | - 'order' => 20, |
|
| 469 | - ), |
|
| 470 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 471 | - 'help_tabs' => array( |
|
| 472 | - 'events_categories_help_tab' => array( |
|
| 473 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 474 | - 'filename' => 'events_categories', |
|
| 475 | - ), |
|
| 476 | - 'events_categories_table_column_headings_help_tab' => array( |
|
| 477 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 478 | - 'filename' => 'events_categories_table_column_headings', |
|
| 479 | - ), |
|
| 480 | - 'events_categories_view_help_tab' => array( |
|
| 481 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 482 | - 'filename' => 'events_categories_views', |
|
| 483 | - ), |
|
| 484 | - 'events_categories_other_help_tab' => array( |
|
| 485 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 486 | - 'filename' => 'events_categories_other', |
|
| 487 | - ), |
|
| 488 | - ), |
|
| 489 | - 'help_tour' => array( |
|
| 490 | - 'Event_Categories_Help_Tour', |
|
| 491 | - ), |
|
| 492 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 493 | - 'require_nonce' => false, |
|
| 494 | - ), |
|
| 495 | - ); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - protected function _add_screen_options() |
|
| 501 | - { |
|
| 502 | - //todo |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - protected function _add_screen_options_default() |
|
| 508 | - { |
|
| 509 | - $this->_per_page_screen_option(); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - protected function _add_screen_options_category_list() |
|
| 515 | - { |
|
| 516 | - $page_title = $this->_admin_page_title; |
|
| 517 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 518 | - $this->_per_page_screen_option(); |
|
| 519 | - $this->_admin_page_title = $page_title; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - protected function _add_feature_pointers() |
|
| 525 | - { |
|
| 526 | - //todo |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - public function load_scripts_styles() |
|
| 532 | - { |
|
| 533 | - wp_register_style( |
|
| 534 | - 'events-admin-css', |
|
| 535 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 536 | - array(), |
|
| 537 | - EVENT_ESPRESSO_VERSION |
|
| 538 | - ); |
|
| 539 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 540 | - wp_enqueue_style('events-admin-css'); |
|
| 541 | - wp_enqueue_style('ee-cat-admin'); |
|
| 542 | - //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 543 | - //registers for all views |
|
| 544 | - //scripts |
|
| 545 | - wp_register_script( |
|
| 546 | - 'event_editor_js', |
|
| 547 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 548 | - array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 549 | - EVENT_ESPRESSO_VERSION, |
|
| 550 | - true |
|
| 551 | - ); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * enqueuing scripts and styles specific to this view |
|
| 558 | - * |
|
| 559 | - * @return void |
|
| 560 | - */ |
|
| 561 | - public function load_scripts_styles_create_new() |
|
| 562 | - { |
|
| 563 | - $this->load_scripts_styles_edit(); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * enqueuing scripts and styles specific to this view |
|
| 570 | - * |
|
| 571 | - * @return void |
|
| 572 | - */ |
|
| 573 | - public function load_scripts_styles_edit() |
|
| 574 | - { |
|
| 575 | - //styles |
|
| 576 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 577 | - wp_register_style( |
|
| 578 | - 'event-editor-css', |
|
| 579 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 580 | - array('ee-admin-css'), |
|
| 581 | - EVENT_ESPRESSO_VERSION |
|
| 582 | - ); |
|
| 583 | - wp_enqueue_style('event-editor-css'); |
|
| 584 | - //scripts |
|
| 585 | - wp_register_script( |
|
| 586 | - 'event-datetime-metabox', |
|
| 587 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 588 | - array('event_editor_js', 'ee-datepicker'), |
|
| 589 | - EVENT_ESPRESSO_VERSION |
|
| 590 | - ); |
|
| 591 | - wp_enqueue_script('event-datetime-metabox'); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - public function load_scripts_styles_add_category() |
|
| 597 | - { |
|
| 598 | - $this->load_scripts_styles_edit_category(); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - public function load_scripts_styles_edit_category() |
|
| 604 | - { |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - |
|
| 609 | - protected function _set_list_table_views_category_list() |
|
| 610 | - { |
|
| 611 | - $this->_views = array( |
|
| 612 | - 'all' => array( |
|
| 613 | - 'slug' => 'all', |
|
| 614 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 615 | - 'count' => 0, |
|
| 616 | - 'bulk_action' => array( |
|
| 617 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 618 | - ), |
|
| 619 | - ), |
|
| 620 | - ); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - public function admin_init() |
|
| 626 | - { |
|
| 627 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 628 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 629 | - 'event_espresso' |
|
| 630 | - ); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - //nothing needed for events with these methods. |
|
| 636 | - public function admin_notices() |
|
| 637 | - { |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - |
|
| 642 | - public function admin_footer_scripts() |
|
| 643 | - { |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 650 | - * warning (via EE_Error::add_error()); |
|
| 651 | - * |
|
| 652 | - * @param EE_Event $event Event object |
|
| 653 | - * @access public |
|
| 654 | - * @return void |
|
| 655 | - */ |
|
| 656 | - public function verify_event_edit($event = null) |
|
| 657 | - { |
|
| 658 | - // no event? |
|
| 659 | - if (empty($event)) { |
|
| 660 | - // set event |
|
| 661 | - $event = $this->_cpt_model_obj; |
|
| 662 | - } |
|
| 663 | - // STILL no event? |
|
| 664 | - if (empty ($event)) { |
|
| 665 | - return; |
|
| 666 | - } |
|
| 667 | - $orig_status = $event->status(); |
|
| 668 | - // first check if event is active. |
|
| 669 | - if ( |
|
| 670 | - $orig_status === EEM_Event::cancelled |
|
| 671 | - || $orig_status === EEM_Event::postponed |
|
| 672 | - || $event->is_expired() |
|
| 673 | - || $event->is_inactive() |
|
| 674 | - ) { |
|
| 675 | - return; |
|
| 676 | - } |
|
| 677 | - //made it here so it IS active... next check that any of the tickets are sold. |
|
| 678 | - if ($event->is_sold_out(true)) { |
|
| 679 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 680 | - EE_Error::add_attention( |
|
| 681 | - sprintf( |
|
| 682 | - esc_html__( |
|
| 683 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 684 | - 'event_espresso' |
|
| 685 | - ), |
|
| 686 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 687 | - ) |
|
| 688 | - ); |
|
| 689 | - } |
|
| 690 | - return; |
|
| 691 | - } else if ($orig_status === EEM_Event::sold_out) { |
|
| 692 | - EE_Error::add_attention( |
|
| 693 | - sprintf( |
|
| 694 | - esc_html__( |
|
| 695 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 696 | - 'event_espresso' |
|
| 697 | - ), |
|
| 698 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 699 | - ) |
|
| 700 | - ); |
|
| 701 | - } |
|
| 702 | - //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 703 | - if ( ! $event->tickets_on_sale()) { |
|
| 704 | - return; |
|
| 705 | - } |
|
| 706 | - //made it here so show warning |
|
| 707 | - $this->_edit_event_warning(); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 714 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
| 715 | - * |
|
| 716 | - * @access protected |
|
| 717 | - * @return void |
|
| 718 | - */ |
|
| 719 | - protected function _edit_event_warning() |
|
| 720 | - { |
|
| 721 | - // we don't want to add warnings during these requests |
|
| 722 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 723 | - return; |
|
| 724 | - } |
|
| 725 | - EE_Error::add_attention( |
|
| 726 | - esc_html__( |
|
| 727 | - 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
| 728 | - 'event_espresso' |
|
| 729 | - ) |
|
| 730 | - ); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 737 | - * Otherwise, do the normal logic |
|
| 738 | - * |
|
| 739 | - * @return string |
|
| 740 | - * @throws \EE_Error |
|
| 741 | - */ |
|
| 742 | - protected function _create_new_cpt_item() |
|
| 743 | - { |
|
| 744 | - $gmt_offset = get_option('gmt_offset'); |
|
| 745 | - //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 746 | - if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
| 747 | - EE_Error::add_attention( |
|
| 748 | - sprintf( |
|
| 749 | - __( |
|
| 750 | - 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
|
| 751 | - 'event_espresso' |
|
| 752 | - ), |
|
| 753 | - '<a href="' . admin_url('options-general.php') . '">', |
|
| 754 | - '</a>' |
|
| 755 | - ), |
|
| 756 | - __FILE__, |
|
| 757 | - __FUNCTION__, |
|
| 758 | - __LINE__ |
|
| 759 | - ); |
|
| 760 | - } |
|
| 761 | - return parent::_create_new_cpt_item(); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - protected function _set_list_table_views_default() |
|
| 767 | - { |
|
| 768 | - $this->_views = array( |
|
| 769 | - 'all' => array( |
|
| 770 | - 'slug' => 'all', |
|
| 771 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 772 | - 'count' => 0, |
|
| 773 | - 'bulk_action' => array( |
|
| 774 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 775 | - ), |
|
| 776 | - ), |
|
| 777 | - 'draft' => array( |
|
| 778 | - 'slug' => 'draft', |
|
| 779 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 780 | - 'count' => 0, |
|
| 781 | - 'bulk_action' => array( |
|
| 782 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 783 | - ), |
|
| 784 | - ), |
|
| 785 | - ); |
|
| 786 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 787 | - $this->_views['trash'] = array( |
|
| 788 | - 'slug' => 'trash', |
|
| 789 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 790 | - 'count' => 0, |
|
| 791 | - 'bulk_action' => array( |
|
| 792 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 793 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 794 | - ), |
|
| 795 | - ); |
|
| 796 | - } |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * @return array |
|
| 803 | - */ |
|
| 804 | - protected function _event_legend_items() |
|
| 805 | - { |
|
| 806 | - $items = array( |
|
| 807 | - 'view_details' => array( |
|
| 808 | - 'class' => 'dashicons dashicons-search', |
|
| 809 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 810 | - ), |
|
| 811 | - 'edit_event' => array( |
|
| 812 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 813 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 814 | - ), |
|
| 815 | - 'view_attendees' => array( |
|
| 816 | - 'class' => 'dashicons dashicons-groups', |
|
| 817 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 818 | - ), |
|
| 819 | - ); |
|
| 820 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 821 | - $statuses = array( |
|
| 822 | - 'sold_out_status' => array( |
|
| 823 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 824 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 825 | - ), |
|
| 826 | - 'active_status' => array( |
|
| 827 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 828 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 829 | - ), |
|
| 830 | - 'upcoming_status' => array( |
|
| 831 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 832 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 833 | - ), |
|
| 834 | - 'postponed_status' => array( |
|
| 835 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 836 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 837 | - ), |
|
| 838 | - 'cancelled_status' => array( |
|
| 839 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 840 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 841 | - ), |
|
| 842 | - 'expired_status' => array( |
|
| 843 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 844 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 845 | - ), |
|
| 846 | - 'inactive_status' => array( |
|
| 847 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 848 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 849 | - ), |
|
| 850 | - ); |
|
| 851 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 852 | - return array_merge($items, $statuses); |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * _event_model |
|
| 859 | - * |
|
| 860 | - * @return EEM_Event |
|
| 861 | - */ |
|
| 862 | - private function _event_model() |
|
| 863 | - { |
|
| 864 | - if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 865 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 866 | - } |
|
| 867 | - return $this->_event_model; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - |
|
| 872 | - /** |
|
| 873 | - * Adds extra buttons to the WP CPT permalink field row. |
|
| 874 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 875 | - * |
|
| 876 | - * @param string $return the current html |
|
| 877 | - * @param int $id the post id for the page |
|
| 878 | - * @param string $new_title What the title is |
|
| 879 | - * @param string $new_slug what the slug is |
|
| 880 | - * @return string The new html string for the permalink area |
|
| 881 | - */ |
|
| 882 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 883 | - { |
|
| 884 | - //make sure this is only when editing |
|
| 885 | - if ( ! empty($id)) { |
|
| 886 | - $post = get_post($id); |
|
| 887 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 888 | - . esc_html__('Shortcode', 'event_espresso') |
|
| 889 | - . '</a> '; |
|
| 890 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 891 | - . $post->ID |
|
| 892 | - . ']">'; |
|
| 893 | - } |
|
| 894 | - return $return; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * _events_overview_list_table |
|
| 901 | - * This contains the logic for showing the events_overview list |
|
| 902 | - * |
|
| 903 | - * @access protected |
|
| 904 | - * @return void |
|
| 905 | - * @throws \EE_Error |
|
| 906 | - */ |
|
| 907 | - protected function _events_overview_list_table() |
|
| 908 | - { |
|
| 909 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 910 | - $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 911 | - ? (array)$this->_template_args['after_list_table'] |
|
| 912 | - : array(); |
|
| 913 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 914 | - . EEH_Template::get_button_or_link( |
|
| 915 | - get_post_type_archive_link('espresso_events'), |
|
| 916 | - esc_html__("View Event Archive Page", "event_espresso"), |
|
| 917 | - 'button' |
|
| 918 | - ); |
|
| 919 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 920 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 921 | - 'create_new', |
|
| 922 | - 'add', |
|
| 923 | - array(), |
|
| 924 | - 'add-new-h2' |
|
| 925 | - ); |
|
| 926 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - |
|
| 931 | - /** |
|
| 932 | - * this allows for extra misc actions in the default WP publish box |
|
| 933 | - * |
|
| 934 | - * @return void |
|
| 935 | - */ |
|
| 936 | - public function extra_misc_actions_publish_box() |
|
| 937 | - { |
|
| 938 | - $this->_generate_publish_box_extra_content(); |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - |
|
| 943 | - /** |
|
| 944 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 945 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 946 | - * data. |
|
| 947 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 948 | - * ALSO very important. When a post transitions from scheduled to published, the save_post action is fired but you |
|
| 949 | - * will NOT have any _POST data containing any extra info you may have from other meta saves. So MAKE sure that |
|
| 950 | - * you handle this accordingly. |
|
| 951 | - * |
|
| 952 | - * @access protected |
|
| 953 | - * @abstract |
|
| 954 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 955 | - * @param object $post The post object of the cpt that was saved. |
|
| 956 | - * @return void |
|
| 957 | - */ |
|
| 958 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 959 | - { |
|
| 960 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 961 | - //get out we're not processing an event save. |
|
| 962 | - return; |
|
| 963 | - } |
|
| 964 | - $event_values = array( |
|
| 965 | - 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 966 | - 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 967 | - 'EVT_additional_limit' => min( |
|
| 968 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 969 | - ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 970 | - ), |
|
| 971 | - 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 972 | - ? $this->_req_data['EVT_default_registration_status'] |
|
| 973 | - : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 974 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 975 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 976 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 977 | - ? $this->_req_data['timezone_string'] : null, |
|
| 978 | - 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 979 | - ? $this->_req_data['externalURL'] : null, |
|
| 980 | - 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 981 | - ? $this->_req_data['event_phone'] : null, |
|
| 982 | - ); |
|
| 983 | - //update event |
|
| 984 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 985 | - //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 986 | - $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
| 987 | - $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 988 | - //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 989 | - $event_update_callbacks = apply_filters( |
|
| 990 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 991 | - array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
| 992 | - ); |
|
| 993 | - $att_success = true; |
|
| 994 | - foreach ($event_update_callbacks as $e_callback) { |
|
| 995 | - $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
| 996 | - $att_success = ! $att_success ? $att_success |
|
| 997 | - : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
| 998 | - } |
|
| 999 | - //any errors? |
|
| 1000 | - if ($success && false === $att_success) { |
|
| 1001 | - EE_Error::add_error( |
|
| 1002 | - esc_html__( |
|
| 1003 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1004 | - 'event_espresso' |
|
| 1005 | - ), |
|
| 1006 | - __FILE__, |
|
| 1007 | - __FUNCTION__, |
|
| 1008 | - __LINE__ |
|
| 1009 | - ); |
|
| 1010 | - } else if ($success === false) { |
|
| 1011 | - EE_Error::add_error( |
|
| 1012 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1013 | - __FILE__, |
|
| 1014 | - __FUNCTION__, |
|
| 1015 | - __LINE__ |
|
| 1016 | - ); |
|
| 1017 | - } |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - |
|
| 1021 | - |
|
| 1022 | - /** |
|
| 1023 | - * @see parent::restore_item() |
|
| 1024 | - * @param int $post_id |
|
| 1025 | - * @param int $revision_id |
|
| 1026 | - */ |
|
| 1027 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1028 | - { |
|
| 1029 | - //copy existing event meta to new post |
|
| 1030 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1031 | - if ($post_evt instanceof EE_Event) { |
|
| 1032 | - //meta revision restore |
|
| 1033 | - $post_evt->restore_revision($revision_id); |
|
| 1034 | - //related objs restore |
|
| 1035 | - $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 1036 | - } |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - |
|
| 1040 | - |
|
| 1041 | - /** |
|
| 1042 | - * Attach the venue to the Event |
|
| 1043 | - * |
|
| 1044 | - * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1045 | - * @param array $data The request data from the form |
|
| 1046 | - * @return bool Success or fail. |
|
| 1047 | - */ |
|
| 1048 | - protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1049 | - { |
|
| 1050 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1051 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1052 | - $rows_affected = null; |
|
| 1053 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1054 | - // very important. If we don't have a venue name... |
|
| 1055 | - // then we'll get out because not necessary to create empty venue |
|
| 1056 | - if (empty($data['venue_title'])) { |
|
| 1057 | - return false; |
|
| 1058 | - } |
|
| 1059 | - $venue_array = array( |
|
| 1060 | - 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1061 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1062 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1063 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1064 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1065 | - : null, |
|
| 1066 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1067 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1068 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1069 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1070 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1071 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1072 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1073 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1074 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1075 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1076 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1077 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1078 | - 'status' => 'publish', |
|
| 1079 | - ); |
|
| 1080 | - //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1081 | - if ( ! empty($venue_id)) { |
|
| 1082 | - $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1083 | - $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1084 | - //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1085 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1086 | - return $rows_affected > 0 ? true : false; |
|
| 1087 | - } else { |
|
| 1088 | - //we insert the venue |
|
| 1089 | - $venue_id = $venue_model->insert($venue_array); |
|
| 1090 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1091 | - return ! empty($venue_id) ? true : false; |
|
| 1092 | - } |
|
| 1093 | - //when we have the ancestor come in it's already been handled by the revision save. |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - |
|
| 1097 | - |
|
| 1098 | - /** |
|
| 1099 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1100 | - * |
|
| 1101 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1102 | - * @param array $data The request data from the form |
|
| 1103 | - * @return array |
|
| 1104 | - */ |
|
| 1105 | - protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1106 | - { |
|
| 1107 | - $success = true; |
|
| 1108 | - $saved_dtt = null; |
|
| 1109 | - $saved_tickets = array(); |
|
| 1110 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1111 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1112 | - //trim all values to ensure any excess whitespace is removed. |
|
| 1113 | - $dtt = array_map('trim', $dtt); |
|
| 1114 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1115 | - : $dtt['DTT_EVT_start']; |
|
| 1116 | - $datetime_values = array( |
|
| 1117 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1118 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1119 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1120 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1121 | - 'DTT_order' => $row, |
|
| 1122 | - ); |
|
| 1123 | - //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1124 | - if ( ! empty($dtt['DTT_ID'])) { |
|
| 1125 | - $DTM = EE_Registry::instance() |
|
| 1126 | - ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1127 | - ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1128 | - $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1129 | - $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1130 | - foreach ($datetime_values as $field => $value) { |
|
| 1131 | - $DTM->set($field, $value); |
|
| 1132 | - } |
|
| 1133 | - //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1134 | - $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1135 | - } else { |
|
| 1136 | - $DTM = EE_Registry::instance()->load_class( |
|
| 1137 | - 'Datetime', |
|
| 1138 | - array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1139 | - false, |
|
| 1140 | - false |
|
| 1141 | - ); |
|
| 1142 | - foreach ($datetime_values as $field => $value) { |
|
| 1143 | - $DTM->set($field, $value); |
|
| 1144 | - } |
|
| 1145 | - } |
|
| 1146 | - $DTM->save(); |
|
| 1147 | - $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1148 | - //load DTT helper |
|
| 1149 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1150 | - if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1151 | - $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1152 | - $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1153 | - $DTT->save(); |
|
| 1154 | - } |
|
| 1155 | - //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1156 | - $saved_dtt = $DTT; |
|
| 1157 | - $success = ! $success ? $success : $DTT; |
|
| 1158 | - //if ANY of these updates fail then we want the appropriate global error message. |
|
| 1159 | - // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1160 | - } |
|
| 1161 | - //no dtts get deleted so we don't do any of that logic here. |
|
| 1162 | - //update tickets next |
|
| 1163 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1164 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1165 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1166 | - $update_prices = false; |
|
| 1167 | - $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1168 | - ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1169 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 1170 | - $tkt = array_map('trim', $tkt); |
|
| 1171 | - if (empty($tkt['TKT_start_date'])) { |
|
| 1172 | - //let's use now in the set timezone. |
|
| 1173 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1174 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1175 | - } |
|
| 1176 | - if (empty($tkt['TKT_end_date'])) { |
|
| 1177 | - //use the start date of the first datetime |
|
| 1178 | - $dtt = $evtobj->first_datetime(); |
|
| 1179 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1180 | - $incoming_date_formats[0], |
|
| 1181 | - $incoming_date_formats[1] |
|
| 1182 | - ); |
|
| 1183 | - } |
|
| 1184 | - $TKT_values = array( |
|
| 1185 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1186 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1187 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1188 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1189 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1190 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1191 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1192 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1193 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1194 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1195 | - 'TKT_row' => $row, |
|
| 1196 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1197 | - 'TKT_price' => $ticket_price, |
|
| 1198 | - ); |
|
| 1199 | - //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1200 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1201 | - $TKT_values['TKT_ID'] = 0; |
|
| 1202 | - $TKT_values['TKT_is_default'] = 0; |
|
| 1203 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1204 | - $update_prices = true; |
|
| 1205 | - } |
|
| 1206 | - //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1207 | - //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1208 | - //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1209 | - if ( ! empty($tkt['TKT_ID'])) { |
|
| 1210 | - $TKT = EE_Registry::instance() |
|
| 1211 | - ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1212 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1213 | - if ($TKT instanceof EE_Ticket) { |
|
| 1214 | - $ticket_sold = $TKT->count_related( |
|
| 1215 | - 'Registration', |
|
| 1216 | - array( |
|
| 1217 | - array( |
|
| 1218 | - 'STS_ID' => array( |
|
| 1219 | - 'NOT IN', |
|
| 1220 | - array(EEM_Registration::status_id_incomplete), |
|
| 1221 | - ), |
|
| 1222 | - ), |
|
| 1223 | - ) |
|
| 1224 | - ) > 0 ? true : false; |
|
| 1225 | - //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1226 | - $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1227 | - && ! $TKT->get( |
|
| 1228 | - 'TKT_deleted' |
|
| 1229 | - ) ? true : false; |
|
| 1230 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1231 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1232 | - //set new values |
|
| 1233 | - foreach ($TKT_values as $field => $value) { |
|
| 1234 | - if ($field == 'TKT_qty') { |
|
| 1235 | - $TKT->set_qty($value); |
|
| 1236 | - } else { |
|
| 1237 | - $TKT->set($field, $value); |
|
| 1238 | - } |
|
| 1239 | - } |
|
| 1240 | - //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1241 | - if ($create_new_TKT) { |
|
| 1242 | - //archive the old ticket first |
|
| 1243 | - $TKT->set('TKT_deleted', 1); |
|
| 1244 | - $TKT->save(); |
|
| 1245 | - //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1246 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1247 | - //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1248 | - $TKT = clone $TKT; |
|
| 1249 | - $TKT->set('TKT_ID', 0); |
|
| 1250 | - $TKT->set('TKT_deleted', 0); |
|
| 1251 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1252 | - $TKT->set('TKT_sold', 0); |
|
| 1253 | - //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1254 | - $update_prices = true; |
|
| 1255 | - } |
|
| 1256 | - //make sure price is set if it hasn't been already |
|
| 1257 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1258 | - } |
|
| 1259 | - } else { |
|
| 1260 | - //no TKT_id so a new TKT |
|
| 1261 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1262 | - $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1263 | - if ($TKT instanceof EE_Ticket) { |
|
| 1264 | - //need to reset values to properly account for the date formats |
|
| 1265 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1266 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1267 | - $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1268 | - //set new values |
|
| 1269 | - foreach ($TKT_values as $field => $value) { |
|
| 1270 | - if ($field == 'TKT_qty') { |
|
| 1271 | - $TKT->set_qty($value); |
|
| 1272 | - } else { |
|
| 1273 | - $TKT->set($field, $value); |
|
| 1274 | - } |
|
| 1275 | - } |
|
| 1276 | - $update_prices = true; |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - // cap ticket qty by datetime reg limits |
|
| 1280 | - $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1281 | - //update ticket. |
|
| 1282 | - $TKT->save(); |
|
| 1283 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1284 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1285 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1286 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1287 | - $TKT->save(); |
|
| 1288 | - } |
|
| 1289 | - //initially let's add the ticket to the dtt |
|
| 1290 | - $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1291 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1292 | - //add prices to ticket |
|
| 1293 | - $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1294 | - } |
|
| 1295 | - //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1296 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1297 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1298 | - foreach ($tickets_removed as $id) { |
|
| 1299 | - $id = absint($id); |
|
| 1300 | - //get the ticket for this id |
|
| 1301 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1302 | - //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1303 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1304 | - foreach ($dtts as $dtt) { |
|
| 1305 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1306 | - } |
|
| 1307 | - //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1308 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1309 | - //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1310 | - $tkt_to_remove->delete_permanently(); |
|
| 1311 | - } |
|
| 1312 | - return array($saved_dtt, $saved_tickets); |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - |
|
| 1316 | - |
|
| 1317 | - /** |
|
| 1318 | - * This attaches a list of given prices to a ticket. |
|
| 1319 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1320 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1321 | - * price info and prices are automatically "archived" via the ticket. |
|
| 1322 | - * |
|
| 1323 | - * @access private |
|
| 1324 | - * @param array $prices Array of prices from the form. |
|
| 1325 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1326 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1327 | - * @return void |
|
| 1328 | - */ |
|
| 1329 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1330 | - { |
|
| 1331 | - foreach ($prices as $row => $prc) { |
|
| 1332 | - $PRC_values = array( |
|
| 1333 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1334 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1335 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1336 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1337 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1338 | - 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
| 1339 | - 'PRC_order' => $row, |
|
| 1340 | - ); |
|
| 1341 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1342 | - $PRC_values['PRC_ID'] = 0; |
|
| 1343 | - $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1344 | - } else { |
|
| 1345 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1346 | - //update this price with new values |
|
| 1347 | - foreach ($PRC_values as $field => $newprc) { |
|
| 1348 | - $PRC->set($field, $newprc); |
|
| 1349 | - } |
|
| 1350 | - $PRC->save(); |
|
| 1351 | - } |
|
| 1352 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1353 | - } |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - |
|
| 1357 | - |
|
| 1358 | - /** |
|
| 1359 | - * Add in our autosave ajax handlers |
|
| 1360 | - * |
|
| 1361 | - * @return void |
|
| 1362 | - */ |
|
| 1363 | - protected function _ee_autosave_create_new() |
|
| 1364 | - { |
|
| 1365 | - // $this->_ee_autosave_edit(); |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - |
|
| 1370 | - protected function _ee_autosave_edit() |
|
| 1371 | - { |
|
| 1372 | - return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - |
|
| 1376 | - |
|
| 1377 | - /** |
|
| 1378 | - * _generate_publish_box_extra_content |
|
| 1379 | - * |
|
| 1380 | - * @access private |
|
| 1381 | - * @return void |
|
| 1382 | - */ |
|
| 1383 | - private function _generate_publish_box_extra_content() |
|
| 1384 | - { |
|
| 1385 | - //load formatter helper |
|
| 1386 | - //args for getting related registrations |
|
| 1387 | - $approved_query_args = array( |
|
| 1388 | - array( |
|
| 1389 | - 'REG_deleted' => 0, |
|
| 1390 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1391 | - ), |
|
| 1392 | - ); |
|
| 1393 | - $not_approved_query_args = array( |
|
| 1394 | - array( |
|
| 1395 | - 'REG_deleted' => 0, |
|
| 1396 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1397 | - ), |
|
| 1398 | - ); |
|
| 1399 | - $pending_payment_query_args = array( |
|
| 1400 | - array( |
|
| 1401 | - 'REG_deleted' => 0, |
|
| 1402 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1403 | - ), |
|
| 1404 | - ); |
|
| 1405 | - // publish box |
|
| 1406 | - $publish_box_extra_args = array( |
|
| 1407 | - 'view_approved_reg_url' => add_query_arg( |
|
| 1408 | - array( |
|
| 1409 | - 'action' => 'default', |
|
| 1410 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1411 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1412 | - ), |
|
| 1413 | - REG_ADMIN_URL |
|
| 1414 | - ), |
|
| 1415 | - 'view_not_approved_reg_url' => add_query_arg( |
|
| 1416 | - array( |
|
| 1417 | - 'action' => 'default', |
|
| 1418 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1419 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1420 | - ), |
|
| 1421 | - REG_ADMIN_URL |
|
| 1422 | - ), |
|
| 1423 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1424 | - array( |
|
| 1425 | - 'action' => 'default', |
|
| 1426 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1427 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1428 | - ), |
|
| 1429 | - REG_ADMIN_URL |
|
| 1430 | - ), |
|
| 1431 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1432 | - 'Registration', |
|
| 1433 | - $approved_query_args |
|
| 1434 | - ), |
|
| 1435 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1436 | - 'Registration', |
|
| 1437 | - $not_approved_query_args |
|
| 1438 | - ), |
|
| 1439 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1440 | - 'Registration', |
|
| 1441 | - $pending_payment_query_args |
|
| 1442 | - ), |
|
| 1443 | - 'misc_pub_section_class' => apply_filters( |
|
| 1444 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1445 | - 'misc-pub-section' |
|
| 1446 | - ), |
|
| 1447 | - //'email_attendees_url' => add_query_arg( |
|
| 1448 | - // array( |
|
| 1449 | - // 'event_admin_reports' => 'event_newsletter', |
|
| 1450 | - // 'event_id' => $this->_cpt_model_obj->id |
|
| 1451 | - // ), |
|
| 1452 | - // 'admin.php?page=espresso_registrations' |
|
| 1453 | - //), |
|
| 1454 | - ); |
|
| 1455 | - ob_start(); |
|
| 1456 | - do_action( |
|
| 1457 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1458 | - $this->_cpt_model_obj |
|
| 1459 | - ); |
|
| 1460 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1461 | - // load template |
|
| 1462 | - EEH_Template::display_template( |
|
| 1463 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1464 | - $publish_box_extra_args |
|
| 1465 | - ); |
|
| 1466 | - } |
|
| 1467 | - |
|
| 1468 | - |
|
| 1469 | - |
|
| 1470 | - /** |
|
| 1471 | - * This just returns whatever is set as the _event object property |
|
| 1472 | - * //todo this will become obsolete once the models are in place |
|
| 1473 | - * |
|
| 1474 | - * @return object |
|
| 1475 | - */ |
|
| 1476 | - public function get_event_object() |
|
| 1477 | - { |
|
| 1478 | - return $this->_cpt_model_obj; |
|
| 1479 | - } |
|
| 1480 | - |
|
| 1481 | - |
|
| 1482 | - |
|
| 1483 | - |
|
| 1484 | - /** METABOXES * */ |
|
| 1485 | - /** |
|
| 1486 | - * _register_event_editor_meta_boxes |
|
| 1487 | - * add all metaboxes related to the event_editor |
|
| 1488 | - * |
|
| 1489 | - * @return void |
|
| 1490 | - */ |
|
| 1491 | - protected function _register_event_editor_meta_boxes() |
|
| 1492 | - { |
|
| 1493 | - $this->verify_cpt_object(); |
|
| 1494 | - add_meta_box( |
|
| 1495 | - 'espresso_event_editor_tickets', |
|
| 1496 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1497 | - array($this, 'ticket_metabox'), |
|
| 1498 | - $this->page_slug, |
|
| 1499 | - 'normal', |
|
| 1500 | - 'high' |
|
| 1501 | - ); |
|
| 1502 | - add_meta_box( |
|
| 1503 | - 'espresso_event_editor_event_options', |
|
| 1504 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1505 | - array($this, 'registration_options_meta_box'), |
|
| 1506 | - $this->page_slug, |
|
| 1507 | - 'side', |
|
| 1508 | - 'default' |
|
| 1509 | - ); |
|
| 1510 | - // NOTE: if you're looking for other metaboxes in here, |
|
| 1511 | - // where a metabox has a related management page in the admin |
|
| 1512 | - // you will find it setup in the related management page's "_Hooks" file. |
|
| 1513 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1514 | - } |
|
| 1515 | - |
|
| 1516 | - |
|
| 1517 | - |
|
| 1518 | - public function ticket_metabox() |
|
| 1519 | - { |
|
| 1520 | - $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1521 | - //defaults for template args |
|
| 1522 | - $template_args = array( |
|
| 1523 | - 'existing_datetime_ids' => '', |
|
| 1524 | - 'event_datetime_help_link' => '', |
|
| 1525 | - 'ticket_options_help_link' => '', |
|
| 1526 | - 'time' => null, |
|
| 1527 | - 'ticket_rows' => '', |
|
| 1528 | - 'existing_ticket_ids' => '', |
|
| 1529 | - 'total_ticket_rows' => 1, |
|
| 1530 | - 'ticket_js_structure' => '', |
|
| 1531 | - 'trash_icon' => 'ee-lock-icon', |
|
| 1532 | - 'disabled' => '', |
|
| 1533 | - ); |
|
| 1534 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1535 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1536 | - /** |
|
| 1537 | - * 1. Start with retrieving Datetimes |
|
| 1538 | - * 2. Fore each datetime get related tickets |
|
| 1539 | - * 3. For each ticket get related prices |
|
| 1540 | - */ |
|
| 1541 | - $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1542 | - /** @type EE_Datetime $first_datetime */ |
|
| 1543 | - $first_datetime = reset($times); |
|
| 1544 | - //do we get related tickets? |
|
| 1545 | - if ($first_datetime instanceof EE_Datetime |
|
| 1546 | - && $first_datetime->ID() !== 0 |
|
| 1547 | - ) { |
|
| 1548 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1549 | - $template_args['time'] = $first_datetime; |
|
| 1550 | - $related_tickets = $first_datetime->tickets( |
|
| 1551 | - array( |
|
| 1552 | - array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1553 | - 'default_where_conditions' => 'none', |
|
| 1554 | - ) |
|
| 1555 | - ); |
|
| 1556 | - if ( ! empty($related_tickets)) { |
|
| 1557 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1558 | - $row = 0; |
|
| 1559 | - foreach ($related_tickets as $ticket) { |
|
| 1560 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1561 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1562 | - $row++; |
|
| 1563 | - } |
|
| 1564 | - } else { |
|
| 1565 | - $template_args['total_ticket_rows'] = 1; |
|
| 1566 | - /** @type EE_Ticket $ticket */ |
|
| 1567 | - $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1568 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1569 | - } |
|
| 1570 | - } else { |
|
| 1571 | - $template_args['time'] = $times[0]; |
|
| 1572 | - /** @type EE_Ticket $ticket */ |
|
| 1573 | - $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1574 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1575 | - // NOTE: we're just sending the first default row |
|
| 1576 | - // (decaf can't manage default tickets so this should be sufficient); |
|
| 1577 | - } |
|
| 1578 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1579 | - 'event_editor_event_datetimes_help_tab' |
|
| 1580 | - ); |
|
| 1581 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1582 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1583 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1584 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1585 | - EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1586 | - true |
|
| 1587 | - ); |
|
| 1588 | - $template = apply_filters( |
|
| 1589 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1590 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1591 | - ); |
|
| 1592 | - EEH_Template::display_template($template, $template_args); |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - |
|
| 1596 | - |
|
| 1597 | - /** |
|
| 1598 | - * Setup an individual ticket form for the decaf event editor page |
|
| 1599 | - * |
|
| 1600 | - * @access private |
|
| 1601 | - * @param EE_Ticket $ticket the ticket object |
|
| 1602 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1603 | - * @param int $row |
|
| 1604 | - * @return string generated html for the ticket row. |
|
| 1605 | - */ |
|
| 1606 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1607 | - { |
|
| 1608 | - $template_args = array( |
|
| 1609 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1610 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1611 | - : '', |
|
| 1612 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1613 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1614 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1615 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1616 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1617 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1618 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1619 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1620 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1621 | - 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1622 | - && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1623 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1624 | - 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1625 | - : ' disabled=disabled', |
|
| 1626 | - ); |
|
| 1627 | - $price = $ticket->ID() !== 0 |
|
| 1628 | - ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1629 | - : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1630 | - $price_args = array( |
|
| 1631 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1632 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1633 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1634 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1635 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1636 | - ); |
|
| 1637 | - //make sure we have default start and end dates if skeleton |
|
| 1638 | - //handle rows that should NOT be empty |
|
| 1639 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1640 | - //if empty then the start date will be now. |
|
| 1641 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1642 | - } |
|
| 1643 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1644 | - //get the earliest datetime (if present); |
|
| 1645 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1646 | - ? $this->_cpt_model_obj->get_first_related( |
|
| 1647 | - 'Datetime', |
|
| 1648 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1649 | - ) |
|
| 1650 | - : null; |
|
| 1651 | - if ( ! empty($earliest_dtt)) { |
|
| 1652 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1653 | - } else { |
|
| 1654 | - $template_args['TKT_end_date'] = date( |
|
| 1655 | - 'Y-m-d h:i a', |
|
| 1656 | - mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1657 | - ); |
|
| 1658 | - } |
|
| 1659 | - } |
|
| 1660 | - $template_args = array_merge($template_args, $price_args); |
|
| 1661 | - $template = apply_filters( |
|
| 1662 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1663 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1664 | - $ticket |
|
| 1665 | - ); |
|
| 1666 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1667 | - } |
|
| 1668 | - |
|
| 1669 | - |
|
| 1670 | - |
|
| 1671 | - public function registration_options_meta_box() |
|
| 1672 | - { |
|
| 1673 | - $yes_no_values = array( |
|
| 1674 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1675 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1676 | - ); |
|
| 1677 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1678 | - array( |
|
| 1679 | - EEM_Registration::status_id_cancelled, |
|
| 1680 | - EEM_Registration::status_id_declined, |
|
| 1681 | - EEM_Registration::status_id_incomplete, |
|
| 1682 | - ), |
|
| 1683 | - true |
|
| 1684 | - ); |
|
| 1685 | - //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1686 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1687 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1688 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1689 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1690 | - 'default_reg_status', |
|
| 1691 | - $default_reg_status_values, |
|
| 1692 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1693 | - ); |
|
| 1694 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1695 | - 'display_desc', |
|
| 1696 | - $yes_no_values, |
|
| 1697 | - $this->_cpt_model_obj->display_description() |
|
| 1698 | - ); |
|
| 1699 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1700 | - 'display_ticket_selector', |
|
| 1701 | - $yes_no_values, |
|
| 1702 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1703 | - '', |
|
| 1704 | - '', |
|
| 1705 | - false |
|
| 1706 | - ); |
|
| 1707 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1708 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1709 | - '', |
|
| 1710 | - $template_args, |
|
| 1711 | - $yes_no_values, |
|
| 1712 | - $default_reg_status_values |
|
| 1713 | - ); |
|
| 1714 | - EEH_Template::display_template( |
|
| 1715 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1716 | - $template_args |
|
| 1717 | - ); |
|
| 1718 | - } |
|
| 1719 | - |
|
| 1720 | - |
|
| 1721 | - |
|
| 1722 | - /** |
|
| 1723 | - * _get_events() |
|
| 1724 | - * This method simply returns all the events (for the given _view and paging) |
|
| 1725 | - * |
|
| 1726 | - * @access public |
|
| 1727 | - * @param int $per_page count of items per page (20 default); |
|
| 1728 | - * @param int $current_page what is the current page being viewed. |
|
| 1729 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1730 | - * If FALSE then we return an array of event objects |
|
| 1731 | - * that match the given _view and paging parameters. |
|
| 1732 | - * @return array an array of event objects. |
|
| 1733 | - */ |
|
| 1734 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1735 | - { |
|
| 1736 | - $EEME = $this->_event_model(); |
|
| 1737 | - $offset = ($current_page - 1) * $per_page; |
|
| 1738 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1739 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1740 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1741 | - if (isset($this->_req_data['month_range'])) { |
|
| 1742 | - $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1743 | - //simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1744 | - //where PHP doesn't know what to assume for date. |
|
| 1745 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1746 | - $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1747 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1748 | - } |
|
| 1749 | - $where = array(); |
|
| 1750 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1751 | - //determine what post_status our condition will have for the query. |
|
| 1752 | - switch ($status) { |
|
| 1753 | - case 'month' : |
|
| 1754 | - case 'today' : |
|
| 1755 | - case null : |
|
| 1756 | - case 'all' : |
|
| 1757 | - break; |
|
| 1758 | - case 'draft' : |
|
| 1759 | - $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1760 | - break; |
|
| 1761 | - default : |
|
| 1762 | - $where['status'] = $status; |
|
| 1763 | - } |
|
| 1764 | - //categories? |
|
| 1765 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1766 | - ? $this->_req_data['EVT_CAT'] : null; |
|
| 1767 | - if ( ! empty ($category)) { |
|
| 1768 | - $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1769 | - $where['Term_Taxonomy.term_id'] = $category; |
|
| 1770 | - } |
|
| 1771 | - //date where conditions |
|
| 1772 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1773 | - if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1774 | - $DateTime = new DateTime( |
|
| 1775 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1776 | - new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
| 1777 | - ); |
|
| 1778 | - $start = $DateTime->format(implode(' ', $start_formats)); |
|
| 1779 | - $end = $DateTime->setDate($year_r, $month_r, $DateTime |
|
| 1780 | - ->format('t'))->setTime(23, 59, 59) |
|
| 1781 | - ->format(implode(' ', $start_formats)); |
|
| 1782 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1783 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1784 | - $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1785 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1786 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1787 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1788 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1789 | - $now = date('Y-m-01'); |
|
| 1790 | - $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1791 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1792 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1793 | - ->setTime(23, 59, 59) |
|
| 1794 | - ->format(implode(' ', $start_formats)); |
|
| 1795 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1796 | - } |
|
| 1797 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1798 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1799 | - } else { |
|
| 1800 | - if ( ! isset($where['status'])) { |
|
| 1801 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1802 | - $where['OR'] = array( |
|
| 1803 | - 'status*restrict_private' => array('!=', 'private'), |
|
| 1804 | - 'AND' => array( |
|
| 1805 | - 'status*inclusive' => array('=', 'private'), |
|
| 1806 | - 'EVT_wp_user' => get_current_user_id(), |
|
| 1807 | - ), |
|
| 1808 | - ); |
|
| 1809 | - } |
|
| 1810 | - } |
|
| 1811 | - } |
|
| 1812 | - if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1813 | - if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1814 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1815 | - ) { |
|
| 1816 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1817 | - } |
|
| 1818 | - } |
|
| 1819 | - //search query handling |
|
| 1820 | - if (isset($this->_req_data['s'])) { |
|
| 1821 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1822 | - $where['OR'] = array( |
|
| 1823 | - 'EVT_name' => array('LIKE', $search_string), |
|
| 1824 | - 'EVT_desc' => array('LIKE', $search_string), |
|
| 1825 | - 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1826 | - ); |
|
| 1827 | - } |
|
| 1828 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1829 | - $query_params = apply_filters( |
|
| 1830 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1831 | - array( |
|
| 1832 | - $where, |
|
| 1833 | - 'limit' => $limit, |
|
| 1834 | - 'order_by' => $orderby, |
|
| 1835 | - 'order' => $order, |
|
| 1836 | - 'group_by' => 'EVT_ID', |
|
| 1837 | - ), |
|
| 1838 | - $this->_req_data |
|
| 1839 | - ); |
|
| 1840 | - //let's first check if we have special requests coming in. |
|
| 1841 | - if (isset($this->_req_data['active_status'])) { |
|
| 1842 | - switch ($this->_req_data['active_status']) { |
|
| 1843 | - case 'upcoming' : |
|
| 1844 | - return $EEME->get_upcoming_events($query_params, $count); |
|
| 1845 | - break; |
|
| 1846 | - case 'expired' : |
|
| 1847 | - return $EEME->get_expired_events($query_params, $count); |
|
| 1848 | - break; |
|
| 1849 | - case 'active' : |
|
| 1850 | - return $EEME->get_active_events($query_params, $count); |
|
| 1851 | - break; |
|
| 1852 | - case 'inactive' : |
|
| 1853 | - return $EEME->get_inactive_events($query_params, $count); |
|
| 1854 | - break; |
|
| 1855 | - } |
|
| 1856 | - } |
|
| 1857 | - $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1858 | - return $events; |
|
| 1859 | - } |
|
| 1860 | - |
|
| 1861 | - |
|
| 1862 | - |
|
| 1863 | - /** |
|
| 1864 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1865 | - * |
|
| 1866 | - * @param string $post_id |
|
| 1867 | - */ |
|
| 1868 | - public function trash_cpt_item($post_id) |
|
| 1869 | - { |
|
| 1870 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1871 | - $this->_trash_or_restore_event('trash', false); |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - |
|
| 1875 | - |
|
| 1876 | - /** |
|
| 1877 | - * @param string $post_id |
|
| 1878 | - */ |
|
| 1879 | - public function restore_cpt_item($post_id) |
|
| 1880 | - { |
|
| 1881 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1882 | - $this->_trash_or_restore_event('draft', false); |
|
| 1883 | - } |
|
| 1884 | - |
|
| 1885 | - |
|
| 1886 | - |
|
| 1887 | - /** |
|
| 1888 | - * @param string $post_id |
|
| 1889 | - */ |
|
| 1890 | - public function delete_cpt_item($post_id) |
|
| 1891 | - { |
|
| 1892 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1893 | - $this->_delete_event(false); |
|
| 1894 | - } |
|
| 1895 | - |
|
| 1896 | - |
|
| 1897 | - |
|
| 1898 | - /** |
|
| 1899 | - * _trash_or_restore_event |
|
| 1900 | - * |
|
| 1901 | - * @access protected |
|
| 1902 | - * @param string $event_status |
|
| 1903 | - * @param bool $redirect_after |
|
| 1904 | - */ |
|
| 1905 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1906 | - { |
|
| 1907 | - //determine the event id and set to array. |
|
| 1908 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1909 | - // loop thru events |
|
| 1910 | - if ($EVT_ID) { |
|
| 1911 | - // clean status |
|
| 1912 | - $event_status = sanitize_key($event_status); |
|
| 1913 | - // grab status |
|
| 1914 | - if ( ! empty($event_status)) { |
|
| 1915 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1916 | - } else { |
|
| 1917 | - $success = false; |
|
| 1918 | - $msg = esc_html__( |
|
| 1919 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1920 | - 'event_espresso' |
|
| 1921 | - ); |
|
| 1922 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1923 | - } |
|
| 1924 | - } else { |
|
| 1925 | - $success = false; |
|
| 1926 | - $msg = esc_html__( |
|
| 1927 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1928 | - 'event_espresso' |
|
| 1929 | - ); |
|
| 1930 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1931 | - } |
|
| 1932 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1933 | - if ($redirect_after) { |
|
| 1934 | - $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1935 | - } |
|
| 1936 | - } |
|
| 1937 | - |
|
| 1938 | - |
|
| 1939 | - |
|
| 1940 | - /** |
|
| 1941 | - * _trash_or_restore_events |
|
| 1942 | - * |
|
| 1943 | - * @access protected |
|
| 1944 | - * @param string $event_status |
|
| 1945 | - * @return void |
|
| 1946 | - */ |
|
| 1947 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
| 1948 | - { |
|
| 1949 | - // clean status |
|
| 1950 | - $event_status = sanitize_key($event_status); |
|
| 1951 | - // grab status |
|
| 1952 | - if ( ! empty($event_status)) { |
|
| 1953 | - $success = true; |
|
| 1954 | - //determine the event id and set to array. |
|
| 1955 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1956 | - // loop thru events |
|
| 1957 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 1958 | - if ($EVT_ID = absint($EVT_ID)) { |
|
| 1959 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1960 | - $success = $results !== false ? $success : false; |
|
| 1961 | - } else { |
|
| 1962 | - $msg = sprintf( |
|
| 1963 | - esc_html__( |
|
| 1964 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1965 | - 'event_espresso' |
|
| 1966 | - ), |
|
| 1967 | - $EVT_ID |
|
| 1968 | - ); |
|
| 1969 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1970 | - $success = false; |
|
| 1971 | - } |
|
| 1972 | - } |
|
| 1973 | - } else { |
|
| 1974 | - $success = false; |
|
| 1975 | - $msg = esc_html__( |
|
| 1976 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1977 | - 'event_espresso' |
|
| 1978 | - ); |
|
| 1979 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1980 | - } |
|
| 1981 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 1982 | - $success = $success ? 2 : false; |
|
| 1983 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1984 | - $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 1985 | - } |
|
| 1986 | - |
|
| 1987 | - |
|
| 1988 | - |
|
| 1989 | - /** |
|
| 1990 | - * _trash_or_restore_events |
|
| 1991 | - * |
|
| 1992 | - * @access private |
|
| 1993 | - * @param int $EVT_ID |
|
| 1994 | - * @param string $event_status |
|
| 1995 | - * @return bool |
|
| 1996 | - */ |
|
| 1997 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 1998 | - { |
|
| 1999 | - // grab event id |
|
| 2000 | - if ( ! $EVT_ID) { |
|
| 2001 | - $msg = esc_html__( |
|
| 2002 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2003 | - 'event_espresso' |
|
| 2004 | - ); |
|
| 2005 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2006 | - return false; |
|
| 2007 | - } |
|
| 2008 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2009 | - // clean status |
|
| 2010 | - $event_status = sanitize_key($event_status); |
|
| 2011 | - // grab status |
|
| 2012 | - if (empty($event_status)) { |
|
| 2013 | - $msg = esc_html__( |
|
| 2014 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2015 | - 'event_espresso' |
|
| 2016 | - ); |
|
| 2017 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2018 | - return false; |
|
| 2019 | - } |
|
| 2020 | - // was event trashed or restored ? |
|
| 2021 | - switch ($event_status) { |
|
| 2022 | - case 'draft' : |
|
| 2023 | - $action = 'restored from the trash'; |
|
| 2024 | - $hook = 'AHEE_event_restored_from_trash'; |
|
| 2025 | - break; |
|
| 2026 | - case 'trash' : |
|
| 2027 | - $action = 'moved to the trash'; |
|
| 2028 | - $hook = 'AHEE_event_moved_to_trash'; |
|
| 2029 | - break; |
|
| 2030 | - default : |
|
| 2031 | - $action = 'updated'; |
|
| 2032 | - $hook = false; |
|
| 2033 | - } |
|
| 2034 | - //use class to change status |
|
| 2035 | - $this->_cpt_model_obj->set_status($event_status); |
|
| 2036 | - $success = $this->_cpt_model_obj->save(); |
|
| 2037 | - if ($success === false) { |
|
| 2038 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2039 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2040 | - return false; |
|
| 2041 | - } |
|
| 2042 | - if ($hook) { |
|
| 2043 | - do_action($hook); |
|
| 2044 | - } |
|
| 2045 | - return true; |
|
| 2046 | - } |
|
| 2047 | - |
|
| 2048 | - |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * _delete_event |
|
| 2052 | - * |
|
| 2053 | - * @access protected |
|
| 2054 | - * @param bool $redirect_after |
|
| 2055 | - */ |
|
| 2056 | - protected function _delete_event($redirect_after = true) |
|
| 2057 | - { |
|
| 2058 | - //determine the event id and set to array. |
|
| 2059 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2060 | - $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2061 | - // loop thru events |
|
| 2062 | - if ($EVT_ID) { |
|
| 2063 | - $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2064 | - // get list of events with no prices |
|
| 2065 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2066 | - // remove this event from the list of events with no prices |
|
| 2067 | - if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
| 2068 | - unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2069 | - } |
|
| 2070 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2071 | - } else { |
|
| 2072 | - $success = false; |
|
| 2073 | - $msg = esc_html__( |
|
| 2074 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2075 | - 'event_espresso' |
|
| 2076 | - ); |
|
| 2077 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2078 | - } |
|
| 2079 | - if ($redirect_after) { |
|
| 2080 | - $this->_redirect_after_action( |
|
| 2081 | - $success, |
|
| 2082 | - 'Event', |
|
| 2083 | - 'deleted', |
|
| 2084 | - array('action' => 'default', 'status' => 'trash') |
|
| 2085 | - ); |
|
| 2086 | - } |
|
| 2087 | - } |
|
| 2088 | - |
|
| 2089 | - |
|
| 2090 | - |
|
| 2091 | - /** |
|
| 2092 | - * _delete_events |
|
| 2093 | - * |
|
| 2094 | - * @access protected |
|
| 2095 | - * @return void |
|
| 2096 | - */ |
|
| 2097 | - protected function _delete_events() |
|
| 2098 | - { |
|
| 2099 | - $success = true; |
|
| 2100 | - // get list of events with no prices |
|
| 2101 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2102 | - //determine the event id and set to array. |
|
| 2103 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2104 | - // loop thru events |
|
| 2105 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2106 | - $EVT_ID = absint($EVT_ID); |
|
| 2107 | - if ($EVT_ID) { |
|
| 2108 | - $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2109 | - $success = $results !== false ? $success : false; |
|
| 2110 | - // remove this event from the list of events with no prices |
|
| 2111 | - unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2112 | - } else { |
|
| 2113 | - $success = false; |
|
| 2114 | - $msg = esc_html__( |
|
| 2115 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2116 | - 'event_espresso' |
|
| 2117 | - ); |
|
| 2118 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2119 | - } |
|
| 2120 | - } |
|
| 2121 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2122 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2123 | - $success = $success ? 2 : false; |
|
| 2124 | - $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
| 2125 | - } |
|
| 2126 | - |
|
| 2127 | - |
|
| 2128 | - |
|
| 2129 | - /** |
|
| 2130 | - * _permanently_delete_event |
|
| 2131 | - * |
|
| 2132 | - * @access private |
|
| 2133 | - * @param int $EVT_ID |
|
| 2134 | - * @return bool |
|
| 2135 | - */ |
|
| 2136 | - private function _permanently_delete_event($EVT_ID = 0) |
|
| 2137 | - { |
|
| 2138 | - // grab event id |
|
| 2139 | - if ( ! $EVT_ID) { |
|
| 2140 | - $msg = esc_html__( |
|
| 2141 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2142 | - 'event_espresso' |
|
| 2143 | - ); |
|
| 2144 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2145 | - return false; |
|
| 2146 | - } |
|
| 2147 | - if ( |
|
| 2148 | - ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2149 | - || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2150 | - ) { |
|
| 2151 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2152 | - } |
|
| 2153 | - if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2154 | - return false; |
|
| 2155 | - } |
|
| 2156 | - //need to delete related tickets and prices first. |
|
| 2157 | - $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2158 | - foreach ($datetimes as $datetime) { |
|
| 2159 | - $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2160 | - $tickets = $datetime->get_many_related('Ticket'); |
|
| 2161 | - foreach ($tickets as $ticket) { |
|
| 2162 | - $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2163 | - $ticket->delete_related_permanently('Price'); |
|
| 2164 | - $ticket->delete_permanently(); |
|
| 2165 | - } |
|
| 2166 | - $datetime->delete(); |
|
| 2167 | - } |
|
| 2168 | - //what about related venues or terms? |
|
| 2169 | - $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2170 | - foreach ($venues as $venue) { |
|
| 2171 | - $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2172 | - } |
|
| 2173 | - //any attached question groups? |
|
| 2174 | - $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2175 | - if ( ! empty($question_groups)) { |
|
| 2176 | - foreach ($question_groups as $question_group) { |
|
| 2177 | - $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2178 | - } |
|
| 2179 | - } |
|
| 2180 | - //Message Template Groups |
|
| 2181 | - $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2182 | - /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2183 | - $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2184 | - foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2185 | - $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2186 | - } |
|
| 2187 | - $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2188 | - // did it all go as planned ? |
|
| 2189 | - if ($success) { |
|
| 2190 | - $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2191 | - EE_Error::add_success($msg); |
|
| 2192 | - } else { |
|
| 2193 | - $msg = sprintf( |
|
| 2194 | - esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2195 | - $EVT_ID |
|
| 2196 | - ); |
|
| 2197 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2198 | - return false; |
|
| 2199 | - } |
|
| 2200 | - do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2201 | - return true; |
|
| 2202 | - } |
|
| 2203 | - |
|
| 2204 | - |
|
| 2205 | - |
|
| 2206 | - /** |
|
| 2207 | - * get total number of events |
|
| 2208 | - * |
|
| 2209 | - * @access public |
|
| 2210 | - * @return int |
|
| 2211 | - */ |
|
| 2212 | - public function total_events() |
|
| 2213 | - { |
|
| 2214 | - $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2215 | - return $count; |
|
| 2216 | - } |
|
| 2217 | - |
|
| 2218 | - |
|
| 2219 | - |
|
| 2220 | - /** |
|
| 2221 | - * get total number of draft events |
|
| 2222 | - * |
|
| 2223 | - * @access public |
|
| 2224 | - * @return int |
|
| 2225 | - */ |
|
| 2226 | - public function total_events_draft() |
|
| 2227 | - { |
|
| 2228 | - $where = array( |
|
| 2229 | - 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2230 | - ); |
|
| 2231 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2232 | - return $count; |
|
| 2233 | - } |
|
| 2234 | - |
|
| 2235 | - |
|
| 2236 | - |
|
| 2237 | - /** |
|
| 2238 | - * get total number of trashed events |
|
| 2239 | - * |
|
| 2240 | - * @access public |
|
| 2241 | - * @return int |
|
| 2242 | - */ |
|
| 2243 | - public function total_trashed_events() |
|
| 2244 | - { |
|
| 2245 | - $where = array( |
|
| 2246 | - 'status' => 'trash', |
|
| 2247 | - ); |
|
| 2248 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2249 | - return $count; |
|
| 2250 | - } |
|
| 2251 | - |
|
| 2252 | - |
|
| 2253 | - |
|
| 2254 | - /** |
|
| 2255 | - * _default_event_settings |
|
| 2256 | - * This generates the Default Settings Tab |
|
| 2257 | - * |
|
| 2258 | - * @return void |
|
| 2259 | - */ |
|
| 2260 | - protected function _default_event_settings() |
|
| 2261 | - { |
|
| 2262 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
| 2263 | - $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array( |
|
| 2264 | - // exclude array |
|
| 2265 | - array( |
|
| 2266 | - EEM_Registration::status_id_cancelled, |
|
| 2267 | - EEM_Registration::status_id_declined, |
|
| 2268 | - EEM_Registration::status_id_incomplete, |
|
| 2269 | - EEM_Registration::status_id_wait_list, |
|
| 2270 | - ), |
|
| 2271 | - // translated |
|
| 2272 | - true |
|
| 2273 | - ); |
|
| 2274 | - $this->_template_args['default_reg_status'] = isset( |
|
| 2275 | - EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 2276 | - ) |
|
| 2277 | - && array_key_exists( |
|
| 2278 | - EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 2279 | - $this->_template_args['reg_status_array'] |
|
| 2280 | - ) |
|
| 2281 | - ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID) |
|
| 2282 | - : EEM_Registration::status_id_pending_payment; |
|
| 2283 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2284 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2285 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2286 | - EVENTS_TEMPLATE_PATH . 'event_settings.template.php', |
|
| 2287 | - $this->_template_args, |
|
| 2288 | - true |
|
| 2289 | - ); |
|
| 2290 | - $this->display_admin_page_with_sidebar(); |
|
| 2291 | - } |
|
| 2292 | - |
|
| 2293 | - |
|
| 2294 | - |
|
| 2295 | - /** |
|
| 2296 | - * _update_default_event_settings |
|
| 2297 | - * |
|
| 2298 | - * @access protected |
|
| 2299 | - * @return void |
|
| 2300 | - */ |
|
| 2301 | - protected function _update_default_event_settings() |
|
| 2302 | - { |
|
| 2303 | - EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status']) |
|
| 2304 | - ? sanitize_text_field($this->_req_data['default_reg_status']) |
|
| 2305 | - : EEM_Registration::status_id_pending_payment; |
|
| 2306 | - $what = 'Default Event Settings'; |
|
| 2307 | - $success = $this->_update_espresso_configuration( |
|
| 2308 | - $what, |
|
| 2309 | - EE_Config::instance(), |
|
| 2310 | - __FILE__, |
|
| 2311 | - __FUNCTION__, |
|
| 2312 | - __LINE__ |
|
| 2313 | - ); |
|
| 2314 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings')); |
|
| 2315 | - } |
|
| 2316 | - |
|
| 2317 | - |
|
| 2318 | - |
|
| 2319 | - /************* Templates *************/ |
|
| 2320 | - protected function _template_settings() |
|
| 2321 | - { |
|
| 2322 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2323 | - $this->_template_args['preview_img'] = '<img src="' |
|
| 2324 | - . EVENTS_ASSETS_URL |
|
| 2325 | - . DS |
|
| 2326 | - . 'images' |
|
| 2327 | - . DS |
|
| 2328 | - . 'caffeinated_template_features.jpg" alt="' |
|
| 2329 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2330 | - . '" />'; |
|
| 2331 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2332 | - 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2333 | - 'event_espresso' |
|
| 2334 | - ) . '</strong>'; |
|
| 2335 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2336 | - } |
|
| 2337 | - |
|
| 2338 | - |
|
| 2339 | - /** Event Category Stuff **/ |
|
| 2340 | - /** |
|
| 2341 | - * set the _category property with the category object for the loaded page. |
|
| 2342 | - * |
|
| 2343 | - * @access private |
|
| 2344 | - * @return void |
|
| 2345 | - */ |
|
| 2346 | - private function _set_category_object() |
|
| 2347 | - { |
|
| 2348 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2349 | - return; |
|
| 2350 | - } //already have the category object so get out. |
|
| 2351 | - //set default category object |
|
| 2352 | - $this->_set_empty_category_object(); |
|
| 2353 | - //only set if we've got an id |
|
| 2354 | - if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2355 | - return; |
|
| 2356 | - } |
|
| 2357 | - $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2358 | - $term = get_term($category_id, 'espresso_event_categories'); |
|
| 2359 | - if ( ! empty($term)) { |
|
| 2360 | - $this->_category->category_name = $term->name; |
|
| 2361 | - $this->_category->category_identifier = $term->slug; |
|
| 2362 | - $this->_category->category_desc = $term->description; |
|
| 2363 | - $this->_category->id = $term->term_id; |
|
| 2364 | - $this->_category->parent = $term->parent; |
|
| 2365 | - } |
|
| 2366 | - } |
|
| 2367 | - |
|
| 2368 | - |
|
| 2369 | - |
|
| 2370 | - private function _set_empty_category_object() |
|
| 2371 | - { |
|
| 2372 | - $this->_category = new stdClass(); |
|
| 2373 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2374 | - $this->_category->id = $this->_category->parent = 0; |
|
| 2375 | - } |
|
| 2376 | - |
|
| 2377 | - |
|
| 2378 | - |
|
| 2379 | - protected function _category_list_table() |
|
| 2380 | - { |
|
| 2381 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2382 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2383 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2384 | - 'add_category', |
|
| 2385 | - 'add_category', |
|
| 2386 | - array(), |
|
| 2387 | - 'add-new-h2' |
|
| 2388 | - ); |
|
| 2389 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 2390 | - } |
|
| 2391 | - |
|
| 2392 | - |
|
| 2393 | - |
|
| 2394 | - /** |
|
| 2395 | - * @param $view |
|
| 2396 | - */ |
|
| 2397 | - protected function _category_details($view) |
|
| 2398 | - { |
|
| 2399 | - //load formatter helper |
|
| 2400 | - //load field generator helper |
|
| 2401 | - $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2402 | - $this->_set_add_edit_form_tags($route); |
|
| 2403 | - $this->_set_category_object(); |
|
| 2404 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2405 | - $delete_action = 'delete_category'; |
|
| 2406 | - //custom redirect |
|
| 2407 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2408 | - array('action' => 'category_list'), |
|
| 2409 | - $this->_admin_base_url |
|
| 2410 | - ); |
|
| 2411 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2412 | - //take care of contents |
|
| 2413 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2414 | - $this->display_admin_page_with_sidebar(); |
|
| 2415 | - } |
|
| 2416 | - |
|
| 2417 | - |
|
| 2418 | - |
|
| 2419 | - /** |
|
| 2420 | - * @return mixed |
|
| 2421 | - */ |
|
| 2422 | - protected function _category_details_content() |
|
| 2423 | - { |
|
| 2424 | - $editor_args['category_desc'] = array( |
|
| 2425 | - 'type' => 'wp_editor', |
|
| 2426 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2427 | - 'class' => 'my_editor_custom', |
|
| 2428 | - 'wpeditor_args' => array('media_buttons' => false), |
|
| 2429 | - ); |
|
| 2430 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2431 | - $all_terms = get_terms( |
|
| 2432 | - array('espresso_event_categories'), |
|
| 2433 | - array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2434 | - ); |
|
| 2435 | - //setup category select for term parents. |
|
| 2436 | - $category_select_values[] = array( |
|
| 2437 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2438 | - 'id' => 0, |
|
| 2439 | - ); |
|
| 2440 | - foreach ($all_terms as $term) { |
|
| 2441 | - $category_select_values[] = array( |
|
| 2442 | - 'text' => $term->name, |
|
| 2443 | - 'id' => $term->term_id, |
|
| 2444 | - ); |
|
| 2445 | - } |
|
| 2446 | - $category_select = EEH_Form_Fields::select_input( |
|
| 2447 | - 'category_parent', |
|
| 2448 | - $category_select_values, |
|
| 2449 | - $this->_category->parent |
|
| 2450 | - ); |
|
| 2451 | - $template_args = array( |
|
| 2452 | - 'category' => $this->_category, |
|
| 2453 | - 'category_select' => $category_select, |
|
| 2454 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2455 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2456 | - 'disable' => '', |
|
| 2457 | - 'disabled_message' => false, |
|
| 2458 | - ); |
|
| 2459 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2460 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 2461 | - } |
|
| 2462 | - |
|
| 2463 | - |
|
| 2464 | - |
|
| 2465 | - protected function _delete_categories() |
|
| 2466 | - { |
|
| 2467 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2468 | - : (array)$this->_req_data['category_id']; |
|
| 2469 | - foreach ($cat_ids as $cat_id) { |
|
| 2470 | - $this->_delete_category($cat_id); |
|
| 2471 | - } |
|
| 2472 | - //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2473 | - $query_args = array( |
|
| 2474 | - 'action' => 'category_list', |
|
| 2475 | - ); |
|
| 2476 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2477 | - } |
|
| 2478 | - |
|
| 2479 | - |
|
| 2480 | - |
|
| 2481 | - /** |
|
| 2482 | - * @param $cat_id |
|
| 2483 | - */ |
|
| 2484 | - protected function _delete_category($cat_id) |
|
| 2485 | - { |
|
| 2486 | - $cat_id = absint($cat_id); |
|
| 2487 | - wp_delete_term($cat_id, 'espresso_event_categories'); |
|
| 2488 | - } |
|
| 2489 | - |
|
| 2490 | - |
|
| 2491 | - |
|
| 2492 | - /** |
|
| 2493 | - * @param $new_category |
|
| 2494 | - */ |
|
| 2495 | - protected function _insert_or_update_category($new_category) |
|
| 2496 | - { |
|
| 2497 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2498 | - $success = 0; //we already have a success message so lets not send another. |
|
| 2499 | - if ($cat_id) { |
|
| 2500 | - $query_args = array( |
|
| 2501 | - 'action' => 'edit_category', |
|
| 2502 | - 'EVT_CAT_ID' => $cat_id, |
|
| 2503 | - ); |
|
| 2504 | - } else { |
|
| 2505 | - $query_args = array('action' => 'add_category'); |
|
| 2506 | - } |
|
| 2507 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2508 | - } |
|
| 2509 | - |
|
| 2510 | - |
|
| 2511 | - |
|
| 2512 | - /** |
|
| 2513 | - * @param bool $update |
|
| 2514 | - * @return bool|mixed|string |
|
| 2515 | - */ |
|
| 2516 | - private function _insert_category($update = false) |
|
| 2517 | - { |
|
| 2518 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2519 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2520 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2521 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2522 | - if (empty($category_name)) { |
|
| 2523 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2524 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2525 | - return false; |
|
| 2526 | - } |
|
| 2527 | - $term_args = array( |
|
| 2528 | - 'name' => $category_name, |
|
| 2529 | - 'description' => $category_desc, |
|
| 2530 | - 'parent' => $category_parent, |
|
| 2531 | - ); |
|
| 2532 | - //was the category_identifier input disabled? |
|
| 2533 | - if (isset($this->_req_data['category_identifier'])) { |
|
| 2534 | - $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2535 | - } |
|
| 2536 | - $insert_ids = $update |
|
| 2537 | - ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
| 2538 | - : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
| 2539 | - if ( ! is_array($insert_ids)) { |
|
| 2540 | - $msg = esc_html__( |
|
| 2541 | - 'An error occurred and the category has not been saved to the database.', |
|
| 2542 | - 'event_espresso' |
|
| 2543 | - ); |
|
| 2544 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2545 | - } else { |
|
| 2546 | - $cat_id = $insert_ids['term_id']; |
|
| 2547 | - $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2548 | - EE_Error::add_success($msg); |
|
| 2549 | - } |
|
| 2550 | - return $cat_id; |
|
| 2551 | - } |
|
| 2552 | - |
|
| 2553 | - |
|
| 2554 | - |
|
| 2555 | - /** |
|
| 2556 | - * @param int $per_page |
|
| 2557 | - * @param int $current_page |
|
| 2558 | - * @param bool $count |
|
| 2559 | - * @return \EE_Base_Class[]|int |
|
| 2560 | - */ |
|
| 2561 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2562 | - { |
|
| 2563 | - //testing term stuff |
|
| 2564 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2565 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2566 | - $limit = ($current_page - 1) * $per_page; |
|
| 2567 | - $where = array('taxonomy' => 'espresso_event_categories'); |
|
| 2568 | - if (isset($this->_req_data['s'])) { |
|
| 2569 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2570 | - $where['OR'] = array( |
|
| 2571 | - 'Term.name' => array('LIKE', $sstr), |
|
| 2572 | - 'description' => array('LIKE', $sstr), |
|
| 2573 | - ); |
|
| 2574 | - } |
|
| 2575 | - $query_params = array( |
|
| 2576 | - $where, |
|
| 2577 | - 'order_by' => array($orderby => $order), |
|
| 2578 | - 'limit' => $limit . ',' . $per_page, |
|
| 2579 | - 'force_join' => array('Term'), |
|
| 2580 | - ); |
|
| 2581 | - $categories = $count |
|
| 2582 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2583 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2584 | - return $categories; |
|
| 2585 | - } |
|
| 2586 | - |
|
| 2587 | - |
|
| 2588 | - |
|
| 2589 | - /* end category stuff */ |
|
| 2590 | - /**************/ |
|
| 385 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 386 | + 'require_nonce' => false, |
|
| 387 | + ), |
|
| 388 | + 'default_event_settings' => array( |
|
| 389 | + 'nav' => array( |
|
| 390 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 391 | + 'order' => 40, |
|
| 392 | + ), |
|
| 393 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 394 | + 'labels' => array( |
|
| 395 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 396 | + ), |
|
| 397 | + 'help_tabs' => array( |
|
| 398 | + 'default_settings_help_tab' => array( |
|
| 399 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 400 | + 'filename' => 'events_default_settings', |
|
| 401 | + ), |
|
| 402 | + 'default_settings_status_help_tab' => array( |
|
| 403 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 404 | + 'filename' => 'events_default_settings_status', |
|
| 405 | + ), |
|
| 406 | + ), |
|
| 407 | + 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 408 | + 'require_nonce' => false, |
|
| 409 | + ), |
|
| 410 | + //template settings |
|
| 411 | + 'template_settings' => array( |
|
| 412 | + 'nav' => array( |
|
| 413 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 414 | + 'order' => 30, |
|
| 415 | + ), |
|
| 416 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 417 | + 'help_tabs' => array( |
|
| 418 | + 'general_settings_templates_help_tab' => array( |
|
| 419 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 420 | + 'filename' => 'general_settings_templates', |
|
| 421 | + ), |
|
| 422 | + ), |
|
| 423 | + 'help_tour' => array('Templates_Help_Tour'), |
|
| 424 | + 'require_nonce' => false, |
|
| 425 | + ), |
|
| 426 | + //event category stuff |
|
| 427 | + 'add_category' => array( |
|
| 428 | + 'nav' => array( |
|
| 429 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 430 | + 'order' => 15, |
|
| 431 | + 'persistent' => false, |
|
| 432 | + ), |
|
| 433 | + 'help_tabs' => array( |
|
| 434 | + 'add_category_help_tab' => array( |
|
| 435 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 436 | + 'filename' => 'events_add_category', |
|
| 437 | + ), |
|
| 438 | + ), |
|
| 439 | + 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 440 | + 'metaboxes' => array('_publish_post_box'), |
|
| 441 | + 'require_nonce' => false, |
|
| 442 | + ), |
|
| 443 | + 'edit_category' => array( |
|
| 444 | + 'nav' => array( |
|
| 445 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 446 | + 'order' => 15, |
|
| 447 | + 'persistent' => false, |
|
| 448 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 449 | + ? add_query_arg( |
|
| 450 | + array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 451 | + $this->_current_page_view_url |
|
| 452 | + ) |
|
| 453 | + : $this->_admin_base_url, |
|
| 454 | + ), |
|
| 455 | + 'help_tabs' => array( |
|
| 456 | + 'edit_category_help_tab' => array( |
|
| 457 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 458 | + 'filename' => 'events_edit_category', |
|
| 459 | + ), |
|
| 460 | + ), |
|
| 461 | + /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 462 | + 'metaboxes' => array('_publish_post_box'), |
|
| 463 | + 'require_nonce' => false, |
|
| 464 | + ), |
|
| 465 | + 'category_list' => array( |
|
| 466 | + 'nav' => array( |
|
| 467 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 468 | + 'order' => 20, |
|
| 469 | + ), |
|
| 470 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 471 | + 'help_tabs' => array( |
|
| 472 | + 'events_categories_help_tab' => array( |
|
| 473 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 474 | + 'filename' => 'events_categories', |
|
| 475 | + ), |
|
| 476 | + 'events_categories_table_column_headings_help_tab' => array( |
|
| 477 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 478 | + 'filename' => 'events_categories_table_column_headings', |
|
| 479 | + ), |
|
| 480 | + 'events_categories_view_help_tab' => array( |
|
| 481 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 482 | + 'filename' => 'events_categories_views', |
|
| 483 | + ), |
|
| 484 | + 'events_categories_other_help_tab' => array( |
|
| 485 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 486 | + 'filename' => 'events_categories_other', |
|
| 487 | + ), |
|
| 488 | + ), |
|
| 489 | + 'help_tour' => array( |
|
| 490 | + 'Event_Categories_Help_Tour', |
|
| 491 | + ), |
|
| 492 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 493 | + 'require_nonce' => false, |
|
| 494 | + ), |
|
| 495 | + ); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + protected function _add_screen_options() |
|
| 501 | + { |
|
| 502 | + //todo |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + protected function _add_screen_options_default() |
|
| 508 | + { |
|
| 509 | + $this->_per_page_screen_option(); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + protected function _add_screen_options_category_list() |
|
| 515 | + { |
|
| 516 | + $page_title = $this->_admin_page_title; |
|
| 517 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 518 | + $this->_per_page_screen_option(); |
|
| 519 | + $this->_admin_page_title = $page_title; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + protected function _add_feature_pointers() |
|
| 525 | + { |
|
| 526 | + //todo |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + public function load_scripts_styles() |
|
| 532 | + { |
|
| 533 | + wp_register_style( |
|
| 534 | + 'events-admin-css', |
|
| 535 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 536 | + array(), |
|
| 537 | + EVENT_ESPRESSO_VERSION |
|
| 538 | + ); |
|
| 539 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 540 | + wp_enqueue_style('events-admin-css'); |
|
| 541 | + wp_enqueue_style('ee-cat-admin'); |
|
| 542 | + //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 543 | + //registers for all views |
|
| 544 | + //scripts |
|
| 545 | + wp_register_script( |
|
| 546 | + 'event_editor_js', |
|
| 547 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 548 | + array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 549 | + EVENT_ESPRESSO_VERSION, |
|
| 550 | + true |
|
| 551 | + ); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * enqueuing scripts and styles specific to this view |
|
| 558 | + * |
|
| 559 | + * @return void |
|
| 560 | + */ |
|
| 561 | + public function load_scripts_styles_create_new() |
|
| 562 | + { |
|
| 563 | + $this->load_scripts_styles_edit(); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * enqueuing scripts and styles specific to this view |
|
| 570 | + * |
|
| 571 | + * @return void |
|
| 572 | + */ |
|
| 573 | + public function load_scripts_styles_edit() |
|
| 574 | + { |
|
| 575 | + //styles |
|
| 576 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 577 | + wp_register_style( |
|
| 578 | + 'event-editor-css', |
|
| 579 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 580 | + array('ee-admin-css'), |
|
| 581 | + EVENT_ESPRESSO_VERSION |
|
| 582 | + ); |
|
| 583 | + wp_enqueue_style('event-editor-css'); |
|
| 584 | + //scripts |
|
| 585 | + wp_register_script( |
|
| 586 | + 'event-datetime-metabox', |
|
| 587 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 588 | + array('event_editor_js', 'ee-datepicker'), |
|
| 589 | + EVENT_ESPRESSO_VERSION |
|
| 590 | + ); |
|
| 591 | + wp_enqueue_script('event-datetime-metabox'); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + public function load_scripts_styles_add_category() |
|
| 597 | + { |
|
| 598 | + $this->load_scripts_styles_edit_category(); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + public function load_scripts_styles_edit_category() |
|
| 604 | + { |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + |
|
| 609 | + protected function _set_list_table_views_category_list() |
|
| 610 | + { |
|
| 611 | + $this->_views = array( |
|
| 612 | + 'all' => array( |
|
| 613 | + 'slug' => 'all', |
|
| 614 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 615 | + 'count' => 0, |
|
| 616 | + 'bulk_action' => array( |
|
| 617 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 618 | + ), |
|
| 619 | + ), |
|
| 620 | + ); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + public function admin_init() |
|
| 626 | + { |
|
| 627 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 628 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 629 | + 'event_espresso' |
|
| 630 | + ); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + //nothing needed for events with these methods. |
|
| 636 | + public function admin_notices() |
|
| 637 | + { |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + |
|
| 642 | + public function admin_footer_scripts() |
|
| 643 | + { |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 650 | + * warning (via EE_Error::add_error()); |
|
| 651 | + * |
|
| 652 | + * @param EE_Event $event Event object |
|
| 653 | + * @access public |
|
| 654 | + * @return void |
|
| 655 | + */ |
|
| 656 | + public function verify_event_edit($event = null) |
|
| 657 | + { |
|
| 658 | + // no event? |
|
| 659 | + if (empty($event)) { |
|
| 660 | + // set event |
|
| 661 | + $event = $this->_cpt_model_obj; |
|
| 662 | + } |
|
| 663 | + // STILL no event? |
|
| 664 | + if (empty ($event)) { |
|
| 665 | + return; |
|
| 666 | + } |
|
| 667 | + $orig_status = $event->status(); |
|
| 668 | + // first check if event is active. |
|
| 669 | + if ( |
|
| 670 | + $orig_status === EEM_Event::cancelled |
|
| 671 | + || $orig_status === EEM_Event::postponed |
|
| 672 | + || $event->is_expired() |
|
| 673 | + || $event->is_inactive() |
|
| 674 | + ) { |
|
| 675 | + return; |
|
| 676 | + } |
|
| 677 | + //made it here so it IS active... next check that any of the tickets are sold. |
|
| 678 | + if ($event->is_sold_out(true)) { |
|
| 679 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 680 | + EE_Error::add_attention( |
|
| 681 | + sprintf( |
|
| 682 | + esc_html__( |
|
| 683 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 684 | + 'event_espresso' |
|
| 685 | + ), |
|
| 686 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 687 | + ) |
|
| 688 | + ); |
|
| 689 | + } |
|
| 690 | + return; |
|
| 691 | + } else if ($orig_status === EEM_Event::sold_out) { |
|
| 692 | + EE_Error::add_attention( |
|
| 693 | + sprintf( |
|
| 694 | + esc_html__( |
|
| 695 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 696 | + 'event_espresso' |
|
| 697 | + ), |
|
| 698 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 699 | + ) |
|
| 700 | + ); |
|
| 701 | + } |
|
| 702 | + //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 703 | + if ( ! $event->tickets_on_sale()) { |
|
| 704 | + return; |
|
| 705 | + } |
|
| 706 | + //made it here so show warning |
|
| 707 | + $this->_edit_event_warning(); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 714 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
| 715 | + * |
|
| 716 | + * @access protected |
|
| 717 | + * @return void |
|
| 718 | + */ |
|
| 719 | + protected function _edit_event_warning() |
|
| 720 | + { |
|
| 721 | + // we don't want to add warnings during these requests |
|
| 722 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 723 | + return; |
|
| 724 | + } |
|
| 725 | + EE_Error::add_attention( |
|
| 726 | + esc_html__( |
|
| 727 | + 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
| 728 | + 'event_espresso' |
|
| 729 | + ) |
|
| 730 | + ); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 737 | + * Otherwise, do the normal logic |
|
| 738 | + * |
|
| 739 | + * @return string |
|
| 740 | + * @throws \EE_Error |
|
| 741 | + */ |
|
| 742 | + protected function _create_new_cpt_item() |
|
| 743 | + { |
|
| 744 | + $gmt_offset = get_option('gmt_offset'); |
|
| 745 | + //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 746 | + if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
| 747 | + EE_Error::add_attention( |
|
| 748 | + sprintf( |
|
| 749 | + __( |
|
| 750 | + 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
|
| 751 | + 'event_espresso' |
|
| 752 | + ), |
|
| 753 | + '<a href="' . admin_url('options-general.php') . '">', |
|
| 754 | + '</a>' |
|
| 755 | + ), |
|
| 756 | + __FILE__, |
|
| 757 | + __FUNCTION__, |
|
| 758 | + __LINE__ |
|
| 759 | + ); |
|
| 760 | + } |
|
| 761 | + return parent::_create_new_cpt_item(); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + protected function _set_list_table_views_default() |
|
| 767 | + { |
|
| 768 | + $this->_views = array( |
|
| 769 | + 'all' => array( |
|
| 770 | + 'slug' => 'all', |
|
| 771 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 772 | + 'count' => 0, |
|
| 773 | + 'bulk_action' => array( |
|
| 774 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 775 | + ), |
|
| 776 | + ), |
|
| 777 | + 'draft' => array( |
|
| 778 | + 'slug' => 'draft', |
|
| 779 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 780 | + 'count' => 0, |
|
| 781 | + 'bulk_action' => array( |
|
| 782 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 783 | + ), |
|
| 784 | + ), |
|
| 785 | + ); |
|
| 786 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 787 | + $this->_views['trash'] = array( |
|
| 788 | + 'slug' => 'trash', |
|
| 789 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 790 | + 'count' => 0, |
|
| 791 | + 'bulk_action' => array( |
|
| 792 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 793 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 794 | + ), |
|
| 795 | + ); |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * @return array |
|
| 803 | + */ |
|
| 804 | + protected function _event_legend_items() |
|
| 805 | + { |
|
| 806 | + $items = array( |
|
| 807 | + 'view_details' => array( |
|
| 808 | + 'class' => 'dashicons dashicons-search', |
|
| 809 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 810 | + ), |
|
| 811 | + 'edit_event' => array( |
|
| 812 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 813 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 814 | + ), |
|
| 815 | + 'view_attendees' => array( |
|
| 816 | + 'class' => 'dashicons dashicons-groups', |
|
| 817 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 818 | + ), |
|
| 819 | + ); |
|
| 820 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 821 | + $statuses = array( |
|
| 822 | + 'sold_out_status' => array( |
|
| 823 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 824 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 825 | + ), |
|
| 826 | + 'active_status' => array( |
|
| 827 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 828 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 829 | + ), |
|
| 830 | + 'upcoming_status' => array( |
|
| 831 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 832 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 833 | + ), |
|
| 834 | + 'postponed_status' => array( |
|
| 835 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 836 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 837 | + ), |
|
| 838 | + 'cancelled_status' => array( |
|
| 839 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 840 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 841 | + ), |
|
| 842 | + 'expired_status' => array( |
|
| 843 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 844 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 845 | + ), |
|
| 846 | + 'inactive_status' => array( |
|
| 847 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 848 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 849 | + ), |
|
| 850 | + ); |
|
| 851 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 852 | + return array_merge($items, $statuses); |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * _event_model |
|
| 859 | + * |
|
| 860 | + * @return EEM_Event |
|
| 861 | + */ |
|
| 862 | + private function _event_model() |
|
| 863 | + { |
|
| 864 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 865 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 866 | + } |
|
| 867 | + return $this->_event_model; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + |
|
| 872 | + /** |
|
| 873 | + * Adds extra buttons to the WP CPT permalink field row. |
|
| 874 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 875 | + * |
|
| 876 | + * @param string $return the current html |
|
| 877 | + * @param int $id the post id for the page |
|
| 878 | + * @param string $new_title What the title is |
|
| 879 | + * @param string $new_slug what the slug is |
|
| 880 | + * @return string The new html string for the permalink area |
|
| 881 | + */ |
|
| 882 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 883 | + { |
|
| 884 | + //make sure this is only when editing |
|
| 885 | + if ( ! empty($id)) { |
|
| 886 | + $post = get_post($id); |
|
| 887 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 888 | + . esc_html__('Shortcode', 'event_espresso') |
|
| 889 | + . '</a> '; |
|
| 890 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 891 | + . $post->ID |
|
| 892 | + . ']">'; |
|
| 893 | + } |
|
| 894 | + return $return; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * _events_overview_list_table |
|
| 901 | + * This contains the logic for showing the events_overview list |
|
| 902 | + * |
|
| 903 | + * @access protected |
|
| 904 | + * @return void |
|
| 905 | + * @throws \EE_Error |
|
| 906 | + */ |
|
| 907 | + protected function _events_overview_list_table() |
|
| 908 | + { |
|
| 909 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 910 | + $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 911 | + ? (array)$this->_template_args['after_list_table'] |
|
| 912 | + : array(); |
|
| 913 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 914 | + . EEH_Template::get_button_or_link( |
|
| 915 | + get_post_type_archive_link('espresso_events'), |
|
| 916 | + esc_html__("View Event Archive Page", "event_espresso"), |
|
| 917 | + 'button' |
|
| 918 | + ); |
|
| 919 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 920 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 921 | + 'create_new', |
|
| 922 | + 'add', |
|
| 923 | + array(), |
|
| 924 | + 'add-new-h2' |
|
| 925 | + ); |
|
| 926 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + |
|
| 931 | + /** |
|
| 932 | + * this allows for extra misc actions in the default WP publish box |
|
| 933 | + * |
|
| 934 | + * @return void |
|
| 935 | + */ |
|
| 936 | + public function extra_misc_actions_publish_box() |
|
| 937 | + { |
|
| 938 | + $this->_generate_publish_box_extra_content(); |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + |
|
| 943 | + /** |
|
| 944 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 945 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 946 | + * data. |
|
| 947 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 948 | + * ALSO very important. When a post transitions from scheduled to published, the save_post action is fired but you |
|
| 949 | + * will NOT have any _POST data containing any extra info you may have from other meta saves. So MAKE sure that |
|
| 950 | + * you handle this accordingly. |
|
| 951 | + * |
|
| 952 | + * @access protected |
|
| 953 | + * @abstract |
|
| 954 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 955 | + * @param object $post The post object of the cpt that was saved. |
|
| 956 | + * @return void |
|
| 957 | + */ |
|
| 958 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 959 | + { |
|
| 960 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 961 | + //get out we're not processing an event save. |
|
| 962 | + return; |
|
| 963 | + } |
|
| 964 | + $event_values = array( |
|
| 965 | + 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 966 | + 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 967 | + 'EVT_additional_limit' => min( |
|
| 968 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 969 | + ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 970 | + ), |
|
| 971 | + 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 972 | + ? $this->_req_data['EVT_default_registration_status'] |
|
| 973 | + : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 974 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 975 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 976 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 977 | + ? $this->_req_data['timezone_string'] : null, |
|
| 978 | + 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 979 | + ? $this->_req_data['externalURL'] : null, |
|
| 980 | + 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 981 | + ? $this->_req_data['event_phone'] : null, |
|
| 982 | + ); |
|
| 983 | + //update event |
|
| 984 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 985 | + //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 986 | + $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
| 987 | + $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 988 | + //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 989 | + $event_update_callbacks = apply_filters( |
|
| 990 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 991 | + array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
| 992 | + ); |
|
| 993 | + $att_success = true; |
|
| 994 | + foreach ($event_update_callbacks as $e_callback) { |
|
| 995 | + $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
| 996 | + $att_success = ! $att_success ? $att_success |
|
| 997 | + : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
| 998 | + } |
|
| 999 | + //any errors? |
|
| 1000 | + if ($success && false === $att_success) { |
|
| 1001 | + EE_Error::add_error( |
|
| 1002 | + esc_html__( |
|
| 1003 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1004 | + 'event_espresso' |
|
| 1005 | + ), |
|
| 1006 | + __FILE__, |
|
| 1007 | + __FUNCTION__, |
|
| 1008 | + __LINE__ |
|
| 1009 | + ); |
|
| 1010 | + } else if ($success === false) { |
|
| 1011 | + EE_Error::add_error( |
|
| 1012 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1013 | + __FILE__, |
|
| 1014 | + __FUNCTION__, |
|
| 1015 | + __LINE__ |
|
| 1016 | + ); |
|
| 1017 | + } |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + |
|
| 1021 | + |
|
| 1022 | + /** |
|
| 1023 | + * @see parent::restore_item() |
|
| 1024 | + * @param int $post_id |
|
| 1025 | + * @param int $revision_id |
|
| 1026 | + */ |
|
| 1027 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1028 | + { |
|
| 1029 | + //copy existing event meta to new post |
|
| 1030 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1031 | + if ($post_evt instanceof EE_Event) { |
|
| 1032 | + //meta revision restore |
|
| 1033 | + $post_evt->restore_revision($revision_id); |
|
| 1034 | + //related objs restore |
|
| 1035 | + $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 1036 | + } |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + |
|
| 1040 | + |
|
| 1041 | + /** |
|
| 1042 | + * Attach the venue to the Event |
|
| 1043 | + * |
|
| 1044 | + * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1045 | + * @param array $data The request data from the form |
|
| 1046 | + * @return bool Success or fail. |
|
| 1047 | + */ |
|
| 1048 | + protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1049 | + { |
|
| 1050 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1051 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1052 | + $rows_affected = null; |
|
| 1053 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1054 | + // very important. If we don't have a venue name... |
|
| 1055 | + // then we'll get out because not necessary to create empty venue |
|
| 1056 | + if (empty($data['venue_title'])) { |
|
| 1057 | + return false; |
|
| 1058 | + } |
|
| 1059 | + $venue_array = array( |
|
| 1060 | + 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1061 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1062 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1063 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1064 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1065 | + : null, |
|
| 1066 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1067 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1068 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1069 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1070 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1071 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1072 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1073 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1074 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1075 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1076 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1077 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1078 | + 'status' => 'publish', |
|
| 1079 | + ); |
|
| 1080 | + //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1081 | + if ( ! empty($venue_id)) { |
|
| 1082 | + $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1083 | + $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1084 | + //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1085 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1086 | + return $rows_affected > 0 ? true : false; |
|
| 1087 | + } else { |
|
| 1088 | + //we insert the venue |
|
| 1089 | + $venue_id = $venue_model->insert($venue_array); |
|
| 1090 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1091 | + return ! empty($venue_id) ? true : false; |
|
| 1092 | + } |
|
| 1093 | + //when we have the ancestor come in it's already been handled by the revision save. |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + |
|
| 1097 | + |
|
| 1098 | + /** |
|
| 1099 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1100 | + * |
|
| 1101 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1102 | + * @param array $data The request data from the form |
|
| 1103 | + * @return array |
|
| 1104 | + */ |
|
| 1105 | + protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1106 | + { |
|
| 1107 | + $success = true; |
|
| 1108 | + $saved_dtt = null; |
|
| 1109 | + $saved_tickets = array(); |
|
| 1110 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1111 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1112 | + //trim all values to ensure any excess whitespace is removed. |
|
| 1113 | + $dtt = array_map('trim', $dtt); |
|
| 1114 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1115 | + : $dtt['DTT_EVT_start']; |
|
| 1116 | + $datetime_values = array( |
|
| 1117 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1118 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1119 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1120 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1121 | + 'DTT_order' => $row, |
|
| 1122 | + ); |
|
| 1123 | + //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1124 | + if ( ! empty($dtt['DTT_ID'])) { |
|
| 1125 | + $DTM = EE_Registry::instance() |
|
| 1126 | + ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1127 | + ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1128 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1129 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1130 | + foreach ($datetime_values as $field => $value) { |
|
| 1131 | + $DTM->set($field, $value); |
|
| 1132 | + } |
|
| 1133 | + //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1134 | + $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1135 | + } else { |
|
| 1136 | + $DTM = EE_Registry::instance()->load_class( |
|
| 1137 | + 'Datetime', |
|
| 1138 | + array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1139 | + false, |
|
| 1140 | + false |
|
| 1141 | + ); |
|
| 1142 | + foreach ($datetime_values as $field => $value) { |
|
| 1143 | + $DTM->set($field, $value); |
|
| 1144 | + } |
|
| 1145 | + } |
|
| 1146 | + $DTM->save(); |
|
| 1147 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1148 | + //load DTT helper |
|
| 1149 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1150 | + if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1151 | + $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1152 | + $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1153 | + $DTT->save(); |
|
| 1154 | + } |
|
| 1155 | + //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1156 | + $saved_dtt = $DTT; |
|
| 1157 | + $success = ! $success ? $success : $DTT; |
|
| 1158 | + //if ANY of these updates fail then we want the appropriate global error message. |
|
| 1159 | + // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1160 | + } |
|
| 1161 | + //no dtts get deleted so we don't do any of that logic here. |
|
| 1162 | + //update tickets next |
|
| 1163 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1164 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1165 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1166 | + $update_prices = false; |
|
| 1167 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1168 | + ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1169 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 1170 | + $tkt = array_map('trim', $tkt); |
|
| 1171 | + if (empty($tkt['TKT_start_date'])) { |
|
| 1172 | + //let's use now in the set timezone. |
|
| 1173 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1174 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1175 | + } |
|
| 1176 | + if (empty($tkt['TKT_end_date'])) { |
|
| 1177 | + //use the start date of the first datetime |
|
| 1178 | + $dtt = $evtobj->first_datetime(); |
|
| 1179 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1180 | + $incoming_date_formats[0], |
|
| 1181 | + $incoming_date_formats[1] |
|
| 1182 | + ); |
|
| 1183 | + } |
|
| 1184 | + $TKT_values = array( |
|
| 1185 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1186 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1187 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1188 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1189 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1190 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1191 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1192 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1193 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1194 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1195 | + 'TKT_row' => $row, |
|
| 1196 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1197 | + 'TKT_price' => $ticket_price, |
|
| 1198 | + ); |
|
| 1199 | + //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1200 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1201 | + $TKT_values['TKT_ID'] = 0; |
|
| 1202 | + $TKT_values['TKT_is_default'] = 0; |
|
| 1203 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1204 | + $update_prices = true; |
|
| 1205 | + } |
|
| 1206 | + //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1207 | + //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1208 | + //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1209 | + if ( ! empty($tkt['TKT_ID'])) { |
|
| 1210 | + $TKT = EE_Registry::instance() |
|
| 1211 | + ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1212 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1213 | + if ($TKT instanceof EE_Ticket) { |
|
| 1214 | + $ticket_sold = $TKT->count_related( |
|
| 1215 | + 'Registration', |
|
| 1216 | + array( |
|
| 1217 | + array( |
|
| 1218 | + 'STS_ID' => array( |
|
| 1219 | + 'NOT IN', |
|
| 1220 | + array(EEM_Registration::status_id_incomplete), |
|
| 1221 | + ), |
|
| 1222 | + ), |
|
| 1223 | + ) |
|
| 1224 | + ) > 0 ? true : false; |
|
| 1225 | + //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1226 | + $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1227 | + && ! $TKT->get( |
|
| 1228 | + 'TKT_deleted' |
|
| 1229 | + ) ? true : false; |
|
| 1230 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1231 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1232 | + //set new values |
|
| 1233 | + foreach ($TKT_values as $field => $value) { |
|
| 1234 | + if ($field == 'TKT_qty') { |
|
| 1235 | + $TKT->set_qty($value); |
|
| 1236 | + } else { |
|
| 1237 | + $TKT->set($field, $value); |
|
| 1238 | + } |
|
| 1239 | + } |
|
| 1240 | + //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1241 | + if ($create_new_TKT) { |
|
| 1242 | + //archive the old ticket first |
|
| 1243 | + $TKT->set('TKT_deleted', 1); |
|
| 1244 | + $TKT->save(); |
|
| 1245 | + //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1246 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1247 | + //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1248 | + $TKT = clone $TKT; |
|
| 1249 | + $TKT->set('TKT_ID', 0); |
|
| 1250 | + $TKT->set('TKT_deleted', 0); |
|
| 1251 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1252 | + $TKT->set('TKT_sold', 0); |
|
| 1253 | + //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1254 | + $update_prices = true; |
|
| 1255 | + } |
|
| 1256 | + //make sure price is set if it hasn't been already |
|
| 1257 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1258 | + } |
|
| 1259 | + } else { |
|
| 1260 | + //no TKT_id so a new TKT |
|
| 1261 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1262 | + $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1263 | + if ($TKT instanceof EE_Ticket) { |
|
| 1264 | + //need to reset values to properly account for the date formats |
|
| 1265 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1266 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1267 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1268 | + //set new values |
|
| 1269 | + foreach ($TKT_values as $field => $value) { |
|
| 1270 | + if ($field == 'TKT_qty') { |
|
| 1271 | + $TKT->set_qty($value); |
|
| 1272 | + } else { |
|
| 1273 | + $TKT->set($field, $value); |
|
| 1274 | + } |
|
| 1275 | + } |
|
| 1276 | + $update_prices = true; |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + // cap ticket qty by datetime reg limits |
|
| 1280 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1281 | + //update ticket. |
|
| 1282 | + $TKT->save(); |
|
| 1283 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1284 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1285 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1286 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1287 | + $TKT->save(); |
|
| 1288 | + } |
|
| 1289 | + //initially let's add the ticket to the dtt |
|
| 1290 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1291 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1292 | + //add prices to ticket |
|
| 1293 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1294 | + } |
|
| 1295 | + //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1296 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1297 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1298 | + foreach ($tickets_removed as $id) { |
|
| 1299 | + $id = absint($id); |
|
| 1300 | + //get the ticket for this id |
|
| 1301 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1302 | + //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1303 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1304 | + foreach ($dtts as $dtt) { |
|
| 1305 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1306 | + } |
|
| 1307 | + //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1308 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1309 | + //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1310 | + $tkt_to_remove->delete_permanently(); |
|
| 1311 | + } |
|
| 1312 | + return array($saved_dtt, $saved_tickets); |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + |
|
| 1316 | + |
|
| 1317 | + /** |
|
| 1318 | + * This attaches a list of given prices to a ticket. |
|
| 1319 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1320 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1321 | + * price info and prices are automatically "archived" via the ticket. |
|
| 1322 | + * |
|
| 1323 | + * @access private |
|
| 1324 | + * @param array $prices Array of prices from the form. |
|
| 1325 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1326 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1327 | + * @return void |
|
| 1328 | + */ |
|
| 1329 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1330 | + { |
|
| 1331 | + foreach ($prices as $row => $prc) { |
|
| 1332 | + $PRC_values = array( |
|
| 1333 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1334 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1335 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1336 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1337 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1338 | + 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
| 1339 | + 'PRC_order' => $row, |
|
| 1340 | + ); |
|
| 1341 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1342 | + $PRC_values['PRC_ID'] = 0; |
|
| 1343 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1344 | + } else { |
|
| 1345 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1346 | + //update this price with new values |
|
| 1347 | + foreach ($PRC_values as $field => $newprc) { |
|
| 1348 | + $PRC->set($field, $newprc); |
|
| 1349 | + } |
|
| 1350 | + $PRC->save(); |
|
| 1351 | + } |
|
| 1352 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1353 | + } |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + |
|
| 1357 | + |
|
| 1358 | + /** |
|
| 1359 | + * Add in our autosave ajax handlers |
|
| 1360 | + * |
|
| 1361 | + * @return void |
|
| 1362 | + */ |
|
| 1363 | + protected function _ee_autosave_create_new() |
|
| 1364 | + { |
|
| 1365 | + // $this->_ee_autosave_edit(); |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + |
|
| 1370 | + protected function _ee_autosave_edit() |
|
| 1371 | + { |
|
| 1372 | + return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + |
|
| 1376 | + |
|
| 1377 | + /** |
|
| 1378 | + * _generate_publish_box_extra_content |
|
| 1379 | + * |
|
| 1380 | + * @access private |
|
| 1381 | + * @return void |
|
| 1382 | + */ |
|
| 1383 | + private function _generate_publish_box_extra_content() |
|
| 1384 | + { |
|
| 1385 | + //load formatter helper |
|
| 1386 | + //args for getting related registrations |
|
| 1387 | + $approved_query_args = array( |
|
| 1388 | + array( |
|
| 1389 | + 'REG_deleted' => 0, |
|
| 1390 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1391 | + ), |
|
| 1392 | + ); |
|
| 1393 | + $not_approved_query_args = array( |
|
| 1394 | + array( |
|
| 1395 | + 'REG_deleted' => 0, |
|
| 1396 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1397 | + ), |
|
| 1398 | + ); |
|
| 1399 | + $pending_payment_query_args = array( |
|
| 1400 | + array( |
|
| 1401 | + 'REG_deleted' => 0, |
|
| 1402 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1403 | + ), |
|
| 1404 | + ); |
|
| 1405 | + // publish box |
|
| 1406 | + $publish_box_extra_args = array( |
|
| 1407 | + 'view_approved_reg_url' => add_query_arg( |
|
| 1408 | + array( |
|
| 1409 | + 'action' => 'default', |
|
| 1410 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1411 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1412 | + ), |
|
| 1413 | + REG_ADMIN_URL |
|
| 1414 | + ), |
|
| 1415 | + 'view_not_approved_reg_url' => add_query_arg( |
|
| 1416 | + array( |
|
| 1417 | + 'action' => 'default', |
|
| 1418 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1419 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1420 | + ), |
|
| 1421 | + REG_ADMIN_URL |
|
| 1422 | + ), |
|
| 1423 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1424 | + array( |
|
| 1425 | + 'action' => 'default', |
|
| 1426 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1427 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1428 | + ), |
|
| 1429 | + REG_ADMIN_URL |
|
| 1430 | + ), |
|
| 1431 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1432 | + 'Registration', |
|
| 1433 | + $approved_query_args |
|
| 1434 | + ), |
|
| 1435 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1436 | + 'Registration', |
|
| 1437 | + $not_approved_query_args |
|
| 1438 | + ), |
|
| 1439 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1440 | + 'Registration', |
|
| 1441 | + $pending_payment_query_args |
|
| 1442 | + ), |
|
| 1443 | + 'misc_pub_section_class' => apply_filters( |
|
| 1444 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1445 | + 'misc-pub-section' |
|
| 1446 | + ), |
|
| 1447 | + //'email_attendees_url' => add_query_arg( |
|
| 1448 | + // array( |
|
| 1449 | + // 'event_admin_reports' => 'event_newsletter', |
|
| 1450 | + // 'event_id' => $this->_cpt_model_obj->id |
|
| 1451 | + // ), |
|
| 1452 | + // 'admin.php?page=espresso_registrations' |
|
| 1453 | + //), |
|
| 1454 | + ); |
|
| 1455 | + ob_start(); |
|
| 1456 | + do_action( |
|
| 1457 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1458 | + $this->_cpt_model_obj |
|
| 1459 | + ); |
|
| 1460 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1461 | + // load template |
|
| 1462 | + EEH_Template::display_template( |
|
| 1463 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1464 | + $publish_box_extra_args |
|
| 1465 | + ); |
|
| 1466 | + } |
|
| 1467 | + |
|
| 1468 | + |
|
| 1469 | + |
|
| 1470 | + /** |
|
| 1471 | + * This just returns whatever is set as the _event object property |
|
| 1472 | + * //todo this will become obsolete once the models are in place |
|
| 1473 | + * |
|
| 1474 | + * @return object |
|
| 1475 | + */ |
|
| 1476 | + public function get_event_object() |
|
| 1477 | + { |
|
| 1478 | + return $this->_cpt_model_obj; |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + |
|
| 1482 | + |
|
| 1483 | + |
|
| 1484 | + /** METABOXES * */ |
|
| 1485 | + /** |
|
| 1486 | + * _register_event_editor_meta_boxes |
|
| 1487 | + * add all metaboxes related to the event_editor |
|
| 1488 | + * |
|
| 1489 | + * @return void |
|
| 1490 | + */ |
|
| 1491 | + protected function _register_event_editor_meta_boxes() |
|
| 1492 | + { |
|
| 1493 | + $this->verify_cpt_object(); |
|
| 1494 | + add_meta_box( |
|
| 1495 | + 'espresso_event_editor_tickets', |
|
| 1496 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1497 | + array($this, 'ticket_metabox'), |
|
| 1498 | + $this->page_slug, |
|
| 1499 | + 'normal', |
|
| 1500 | + 'high' |
|
| 1501 | + ); |
|
| 1502 | + add_meta_box( |
|
| 1503 | + 'espresso_event_editor_event_options', |
|
| 1504 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1505 | + array($this, 'registration_options_meta_box'), |
|
| 1506 | + $this->page_slug, |
|
| 1507 | + 'side', |
|
| 1508 | + 'default' |
|
| 1509 | + ); |
|
| 1510 | + // NOTE: if you're looking for other metaboxes in here, |
|
| 1511 | + // where a metabox has a related management page in the admin |
|
| 1512 | + // you will find it setup in the related management page's "_Hooks" file. |
|
| 1513 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1514 | + } |
|
| 1515 | + |
|
| 1516 | + |
|
| 1517 | + |
|
| 1518 | + public function ticket_metabox() |
|
| 1519 | + { |
|
| 1520 | + $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1521 | + //defaults for template args |
|
| 1522 | + $template_args = array( |
|
| 1523 | + 'existing_datetime_ids' => '', |
|
| 1524 | + 'event_datetime_help_link' => '', |
|
| 1525 | + 'ticket_options_help_link' => '', |
|
| 1526 | + 'time' => null, |
|
| 1527 | + 'ticket_rows' => '', |
|
| 1528 | + 'existing_ticket_ids' => '', |
|
| 1529 | + 'total_ticket_rows' => 1, |
|
| 1530 | + 'ticket_js_structure' => '', |
|
| 1531 | + 'trash_icon' => 'ee-lock-icon', |
|
| 1532 | + 'disabled' => '', |
|
| 1533 | + ); |
|
| 1534 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1535 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1536 | + /** |
|
| 1537 | + * 1. Start with retrieving Datetimes |
|
| 1538 | + * 2. Fore each datetime get related tickets |
|
| 1539 | + * 3. For each ticket get related prices |
|
| 1540 | + */ |
|
| 1541 | + $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1542 | + /** @type EE_Datetime $first_datetime */ |
|
| 1543 | + $first_datetime = reset($times); |
|
| 1544 | + //do we get related tickets? |
|
| 1545 | + if ($first_datetime instanceof EE_Datetime |
|
| 1546 | + && $first_datetime->ID() !== 0 |
|
| 1547 | + ) { |
|
| 1548 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1549 | + $template_args['time'] = $first_datetime; |
|
| 1550 | + $related_tickets = $first_datetime->tickets( |
|
| 1551 | + array( |
|
| 1552 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1553 | + 'default_where_conditions' => 'none', |
|
| 1554 | + ) |
|
| 1555 | + ); |
|
| 1556 | + if ( ! empty($related_tickets)) { |
|
| 1557 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1558 | + $row = 0; |
|
| 1559 | + foreach ($related_tickets as $ticket) { |
|
| 1560 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1561 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1562 | + $row++; |
|
| 1563 | + } |
|
| 1564 | + } else { |
|
| 1565 | + $template_args['total_ticket_rows'] = 1; |
|
| 1566 | + /** @type EE_Ticket $ticket */ |
|
| 1567 | + $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1568 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1569 | + } |
|
| 1570 | + } else { |
|
| 1571 | + $template_args['time'] = $times[0]; |
|
| 1572 | + /** @type EE_Ticket $ticket */ |
|
| 1573 | + $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1574 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1575 | + // NOTE: we're just sending the first default row |
|
| 1576 | + // (decaf can't manage default tickets so this should be sufficient); |
|
| 1577 | + } |
|
| 1578 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1579 | + 'event_editor_event_datetimes_help_tab' |
|
| 1580 | + ); |
|
| 1581 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1582 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1583 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1584 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1585 | + EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1586 | + true |
|
| 1587 | + ); |
|
| 1588 | + $template = apply_filters( |
|
| 1589 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1590 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1591 | + ); |
|
| 1592 | + EEH_Template::display_template($template, $template_args); |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + |
|
| 1596 | + |
|
| 1597 | + /** |
|
| 1598 | + * Setup an individual ticket form for the decaf event editor page |
|
| 1599 | + * |
|
| 1600 | + * @access private |
|
| 1601 | + * @param EE_Ticket $ticket the ticket object |
|
| 1602 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1603 | + * @param int $row |
|
| 1604 | + * @return string generated html for the ticket row. |
|
| 1605 | + */ |
|
| 1606 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1607 | + { |
|
| 1608 | + $template_args = array( |
|
| 1609 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1610 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1611 | + : '', |
|
| 1612 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1613 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1614 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1615 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1616 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1617 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1618 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1619 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1620 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1621 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1622 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1623 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1624 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1625 | + : ' disabled=disabled', |
|
| 1626 | + ); |
|
| 1627 | + $price = $ticket->ID() !== 0 |
|
| 1628 | + ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1629 | + : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1630 | + $price_args = array( |
|
| 1631 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1632 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1633 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1634 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1635 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1636 | + ); |
|
| 1637 | + //make sure we have default start and end dates if skeleton |
|
| 1638 | + //handle rows that should NOT be empty |
|
| 1639 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1640 | + //if empty then the start date will be now. |
|
| 1641 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1642 | + } |
|
| 1643 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1644 | + //get the earliest datetime (if present); |
|
| 1645 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1646 | + ? $this->_cpt_model_obj->get_first_related( |
|
| 1647 | + 'Datetime', |
|
| 1648 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1649 | + ) |
|
| 1650 | + : null; |
|
| 1651 | + if ( ! empty($earliest_dtt)) { |
|
| 1652 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1653 | + } else { |
|
| 1654 | + $template_args['TKT_end_date'] = date( |
|
| 1655 | + 'Y-m-d h:i a', |
|
| 1656 | + mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1657 | + ); |
|
| 1658 | + } |
|
| 1659 | + } |
|
| 1660 | + $template_args = array_merge($template_args, $price_args); |
|
| 1661 | + $template = apply_filters( |
|
| 1662 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1663 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1664 | + $ticket |
|
| 1665 | + ); |
|
| 1666 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1667 | + } |
|
| 1668 | + |
|
| 1669 | + |
|
| 1670 | + |
|
| 1671 | + public function registration_options_meta_box() |
|
| 1672 | + { |
|
| 1673 | + $yes_no_values = array( |
|
| 1674 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1675 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1676 | + ); |
|
| 1677 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1678 | + array( |
|
| 1679 | + EEM_Registration::status_id_cancelled, |
|
| 1680 | + EEM_Registration::status_id_declined, |
|
| 1681 | + EEM_Registration::status_id_incomplete, |
|
| 1682 | + ), |
|
| 1683 | + true |
|
| 1684 | + ); |
|
| 1685 | + //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1686 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1687 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1688 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1689 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1690 | + 'default_reg_status', |
|
| 1691 | + $default_reg_status_values, |
|
| 1692 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1693 | + ); |
|
| 1694 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1695 | + 'display_desc', |
|
| 1696 | + $yes_no_values, |
|
| 1697 | + $this->_cpt_model_obj->display_description() |
|
| 1698 | + ); |
|
| 1699 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1700 | + 'display_ticket_selector', |
|
| 1701 | + $yes_no_values, |
|
| 1702 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1703 | + '', |
|
| 1704 | + '', |
|
| 1705 | + false |
|
| 1706 | + ); |
|
| 1707 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1708 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1709 | + '', |
|
| 1710 | + $template_args, |
|
| 1711 | + $yes_no_values, |
|
| 1712 | + $default_reg_status_values |
|
| 1713 | + ); |
|
| 1714 | + EEH_Template::display_template( |
|
| 1715 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1716 | + $template_args |
|
| 1717 | + ); |
|
| 1718 | + } |
|
| 1719 | + |
|
| 1720 | + |
|
| 1721 | + |
|
| 1722 | + /** |
|
| 1723 | + * _get_events() |
|
| 1724 | + * This method simply returns all the events (for the given _view and paging) |
|
| 1725 | + * |
|
| 1726 | + * @access public |
|
| 1727 | + * @param int $per_page count of items per page (20 default); |
|
| 1728 | + * @param int $current_page what is the current page being viewed. |
|
| 1729 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1730 | + * If FALSE then we return an array of event objects |
|
| 1731 | + * that match the given _view and paging parameters. |
|
| 1732 | + * @return array an array of event objects. |
|
| 1733 | + */ |
|
| 1734 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1735 | + { |
|
| 1736 | + $EEME = $this->_event_model(); |
|
| 1737 | + $offset = ($current_page - 1) * $per_page; |
|
| 1738 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1739 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1740 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1741 | + if (isset($this->_req_data['month_range'])) { |
|
| 1742 | + $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1743 | + //simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1744 | + //where PHP doesn't know what to assume for date. |
|
| 1745 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1746 | + $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1747 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1748 | + } |
|
| 1749 | + $where = array(); |
|
| 1750 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1751 | + //determine what post_status our condition will have for the query. |
|
| 1752 | + switch ($status) { |
|
| 1753 | + case 'month' : |
|
| 1754 | + case 'today' : |
|
| 1755 | + case null : |
|
| 1756 | + case 'all' : |
|
| 1757 | + break; |
|
| 1758 | + case 'draft' : |
|
| 1759 | + $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1760 | + break; |
|
| 1761 | + default : |
|
| 1762 | + $where['status'] = $status; |
|
| 1763 | + } |
|
| 1764 | + //categories? |
|
| 1765 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1766 | + ? $this->_req_data['EVT_CAT'] : null; |
|
| 1767 | + if ( ! empty ($category)) { |
|
| 1768 | + $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1769 | + $where['Term_Taxonomy.term_id'] = $category; |
|
| 1770 | + } |
|
| 1771 | + //date where conditions |
|
| 1772 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1773 | + if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1774 | + $DateTime = new DateTime( |
|
| 1775 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1776 | + new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
| 1777 | + ); |
|
| 1778 | + $start = $DateTime->format(implode(' ', $start_formats)); |
|
| 1779 | + $end = $DateTime->setDate($year_r, $month_r, $DateTime |
|
| 1780 | + ->format('t'))->setTime(23, 59, 59) |
|
| 1781 | + ->format(implode(' ', $start_formats)); |
|
| 1782 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1783 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1784 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1785 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1786 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1787 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1788 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1789 | + $now = date('Y-m-01'); |
|
| 1790 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1791 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1792 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1793 | + ->setTime(23, 59, 59) |
|
| 1794 | + ->format(implode(' ', $start_formats)); |
|
| 1795 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1796 | + } |
|
| 1797 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1798 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1799 | + } else { |
|
| 1800 | + if ( ! isset($where['status'])) { |
|
| 1801 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1802 | + $where['OR'] = array( |
|
| 1803 | + 'status*restrict_private' => array('!=', 'private'), |
|
| 1804 | + 'AND' => array( |
|
| 1805 | + 'status*inclusive' => array('=', 'private'), |
|
| 1806 | + 'EVT_wp_user' => get_current_user_id(), |
|
| 1807 | + ), |
|
| 1808 | + ); |
|
| 1809 | + } |
|
| 1810 | + } |
|
| 1811 | + } |
|
| 1812 | + if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1813 | + if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1814 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1815 | + ) { |
|
| 1816 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1817 | + } |
|
| 1818 | + } |
|
| 1819 | + //search query handling |
|
| 1820 | + if (isset($this->_req_data['s'])) { |
|
| 1821 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1822 | + $where['OR'] = array( |
|
| 1823 | + 'EVT_name' => array('LIKE', $search_string), |
|
| 1824 | + 'EVT_desc' => array('LIKE', $search_string), |
|
| 1825 | + 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1826 | + ); |
|
| 1827 | + } |
|
| 1828 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1829 | + $query_params = apply_filters( |
|
| 1830 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1831 | + array( |
|
| 1832 | + $where, |
|
| 1833 | + 'limit' => $limit, |
|
| 1834 | + 'order_by' => $orderby, |
|
| 1835 | + 'order' => $order, |
|
| 1836 | + 'group_by' => 'EVT_ID', |
|
| 1837 | + ), |
|
| 1838 | + $this->_req_data |
|
| 1839 | + ); |
|
| 1840 | + //let's first check if we have special requests coming in. |
|
| 1841 | + if (isset($this->_req_data['active_status'])) { |
|
| 1842 | + switch ($this->_req_data['active_status']) { |
|
| 1843 | + case 'upcoming' : |
|
| 1844 | + return $EEME->get_upcoming_events($query_params, $count); |
|
| 1845 | + break; |
|
| 1846 | + case 'expired' : |
|
| 1847 | + return $EEME->get_expired_events($query_params, $count); |
|
| 1848 | + break; |
|
| 1849 | + case 'active' : |
|
| 1850 | + return $EEME->get_active_events($query_params, $count); |
|
| 1851 | + break; |
|
| 1852 | + case 'inactive' : |
|
| 1853 | + return $EEME->get_inactive_events($query_params, $count); |
|
| 1854 | + break; |
|
| 1855 | + } |
|
| 1856 | + } |
|
| 1857 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1858 | + return $events; |
|
| 1859 | + } |
|
| 1860 | + |
|
| 1861 | + |
|
| 1862 | + |
|
| 1863 | + /** |
|
| 1864 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1865 | + * |
|
| 1866 | + * @param string $post_id |
|
| 1867 | + */ |
|
| 1868 | + public function trash_cpt_item($post_id) |
|
| 1869 | + { |
|
| 1870 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1871 | + $this->_trash_or_restore_event('trash', false); |
|
| 1872 | + } |
|
| 1873 | + |
|
| 1874 | + |
|
| 1875 | + |
|
| 1876 | + /** |
|
| 1877 | + * @param string $post_id |
|
| 1878 | + */ |
|
| 1879 | + public function restore_cpt_item($post_id) |
|
| 1880 | + { |
|
| 1881 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1882 | + $this->_trash_or_restore_event('draft', false); |
|
| 1883 | + } |
|
| 1884 | + |
|
| 1885 | + |
|
| 1886 | + |
|
| 1887 | + /** |
|
| 1888 | + * @param string $post_id |
|
| 1889 | + */ |
|
| 1890 | + public function delete_cpt_item($post_id) |
|
| 1891 | + { |
|
| 1892 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1893 | + $this->_delete_event(false); |
|
| 1894 | + } |
|
| 1895 | + |
|
| 1896 | + |
|
| 1897 | + |
|
| 1898 | + /** |
|
| 1899 | + * _trash_or_restore_event |
|
| 1900 | + * |
|
| 1901 | + * @access protected |
|
| 1902 | + * @param string $event_status |
|
| 1903 | + * @param bool $redirect_after |
|
| 1904 | + */ |
|
| 1905 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1906 | + { |
|
| 1907 | + //determine the event id and set to array. |
|
| 1908 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1909 | + // loop thru events |
|
| 1910 | + if ($EVT_ID) { |
|
| 1911 | + // clean status |
|
| 1912 | + $event_status = sanitize_key($event_status); |
|
| 1913 | + // grab status |
|
| 1914 | + if ( ! empty($event_status)) { |
|
| 1915 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1916 | + } else { |
|
| 1917 | + $success = false; |
|
| 1918 | + $msg = esc_html__( |
|
| 1919 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1920 | + 'event_espresso' |
|
| 1921 | + ); |
|
| 1922 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1923 | + } |
|
| 1924 | + } else { |
|
| 1925 | + $success = false; |
|
| 1926 | + $msg = esc_html__( |
|
| 1927 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1928 | + 'event_espresso' |
|
| 1929 | + ); |
|
| 1930 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1931 | + } |
|
| 1932 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1933 | + if ($redirect_after) { |
|
| 1934 | + $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1935 | + } |
|
| 1936 | + } |
|
| 1937 | + |
|
| 1938 | + |
|
| 1939 | + |
|
| 1940 | + /** |
|
| 1941 | + * _trash_or_restore_events |
|
| 1942 | + * |
|
| 1943 | + * @access protected |
|
| 1944 | + * @param string $event_status |
|
| 1945 | + * @return void |
|
| 1946 | + */ |
|
| 1947 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
| 1948 | + { |
|
| 1949 | + // clean status |
|
| 1950 | + $event_status = sanitize_key($event_status); |
|
| 1951 | + // grab status |
|
| 1952 | + if ( ! empty($event_status)) { |
|
| 1953 | + $success = true; |
|
| 1954 | + //determine the event id and set to array. |
|
| 1955 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1956 | + // loop thru events |
|
| 1957 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 1958 | + if ($EVT_ID = absint($EVT_ID)) { |
|
| 1959 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1960 | + $success = $results !== false ? $success : false; |
|
| 1961 | + } else { |
|
| 1962 | + $msg = sprintf( |
|
| 1963 | + esc_html__( |
|
| 1964 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1965 | + 'event_espresso' |
|
| 1966 | + ), |
|
| 1967 | + $EVT_ID |
|
| 1968 | + ); |
|
| 1969 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1970 | + $success = false; |
|
| 1971 | + } |
|
| 1972 | + } |
|
| 1973 | + } else { |
|
| 1974 | + $success = false; |
|
| 1975 | + $msg = esc_html__( |
|
| 1976 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1977 | + 'event_espresso' |
|
| 1978 | + ); |
|
| 1979 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1980 | + } |
|
| 1981 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 1982 | + $success = $success ? 2 : false; |
|
| 1983 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1984 | + $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 1985 | + } |
|
| 1986 | + |
|
| 1987 | + |
|
| 1988 | + |
|
| 1989 | + /** |
|
| 1990 | + * _trash_or_restore_events |
|
| 1991 | + * |
|
| 1992 | + * @access private |
|
| 1993 | + * @param int $EVT_ID |
|
| 1994 | + * @param string $event_status |
|
| 1995 | + * @return bool |
|
| 1996 | + */ |
|
| 1997 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 1998 | + { |
|
| 1999 | + // grab event id |
|
| 2000 | + if ( ! $EVT_ID) { |
|
| 2001 | + $msg = esc_html__( |
|
| 2002 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2003 | + 'event_espresso' |
|
| 2004 | + ); |
|
| 2005 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2006 | + return false; |
|
| 2007 | + } |
|
| 2008 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2009 | + // clean status |
|
| 2010 | + $event_status = sanitize_key($event_status); |
|
| 2011 | + // grab status |
|
| 2012 | + if (empty($event_status)) { |
|
| 2013 | + $msg = esc_html__( |
|
| 2014 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2015 | + 'event_espresso' |
|
| 2016 | + ); |
|
| 2017 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2018 | + return false; |
|
| 2019 | + } |
|
| 2020 | + // was event trashed or restored ? |
|
| 2021 | + switch ($event_status) { |
|
| 2022 | + case 'draft' : |
|
| 2023 | + $action = 'restored from the trash'; |
|
| 2024 | + $hook = 'AHEE_event_restored_from_trash'; |
|
| 2025 | + break; |
|
| 2026 | + case 'trash' : |
|
| 2027 | + $action = 'moved to the trash'; |
|
| 2028 | + $hook = 'AHEE_event_moved_to_trash'; |
|
| 2029 | + break; |
|
| 2030 | + default : |
|
| 2031 | + $action = 'updated'; |
|
| 2032 | + $hook = false; |
|
| 2033 | + } |
|
| 2034 | + //use class to change status |
|
| 2035 | + $this->_cpt_model_obj->set_status($event_status); |
|
| 2036 | + $success = $this->_cpt_model_obj->save(); |
|
| 2037 | + if ($success === false) { |
|
| 2038 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2039 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2040 | + return false; |
|
| 2041 | + } |
|
| 2042 | + if ($hook) { |
|
| 2043 | + do_action($hook); |
|
| 2044 | + } |
|
| 2045 | + return true; |
|
| 2046 | + } |
|
| 2047 | + |
|
| 2048 | + |
|
| 2049 | + |
|
| 2050 | + /** |
|
| 2051 | + * _delete_event |
|
| 2052 | + * |
|
| 2053 | + * @access protected |
|
| 2054 | + * @param bool $redirect_after |
|
| 2055 | + */ |
|
| 2056 | + protected function _delete_event($redirect_after = true) |
|
| 2057 | + { |
|
| 2058 | + //determine the event id and set to array. |
|
| 2059 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2060 | + $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2061 | + // loop thru events |
|
| 2062 | + if ($EVT_ID) { |
|
| 2063 | + $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2064 | + // get list of events with no prices |
|
| 2065 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2066 | + // remove this event from the list of events with no prices |
|
| 2067 | + if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
| 2068 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2069 | + } |
|
| 2070 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2071 | + } else { |
|
| 2072 | + $success = false; |
|
| 2073 | + $msg = esc_html__( |
|
| 2074 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2075 | + 'event_espresso' |
|
| 2076 | + ); |
|
| 2077 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2078 | + } |
|
| 2079 | + if ($redirect_after) { |
|
| 2080 | + $this->_redirect_after_action( |
|
| 2081 | + $success, |
|
| 2082 | + 'Event', |
|
| 2083 | + 'deleted', |
|
| 2084 | + array('action' => 'default', 'status' => 'trash') |
|
| 2085 | + ); |
|
| 2086 | + } |
|
| 2087 | + } |
|
| 2088 | + |
|
| 2089 | + |
|
| 2090 | + |
|
| 2091 | + /** |
|
| 2092 | + * _delete_events |
|
| 2093 | + * |
|
| 2094 | + * @access protected |
|
| 2095 | + * @return void |
|
| 2096 | + */ |
|
| 2097 | + protected function _delete_events() |
|
| 2098 | + { |
|
| 2099 | + $success = true; |
|
| 2100 | + // get list of events with no prices |
|
| 2101 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2102 | + //determine the event id and set to array. |
|
| 2103 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2104 | + // loop thru events |
|
| 2105 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2106 | + $EVT_ID = absint($EVT_ID); |
|
| 2107 | + if ($EVT_ID) { |
|
| 2108 | + $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2109 | + $success = $results !== false ? $success : false; |
|
| 2110 | + // remove this event from the list of events with no prices |
|
| 2111 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2112 | + } else { |
|
| 2113 | + $success = false; |
|
| 2114 | + $msg = esc_html__( |
|
| 2115 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2116 | + 'event_espresso' |
|
| 2117 | + ); |
|
| 2118 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2119 | + } |
|
| 2120 | + } |
|
| 2121 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2122 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2123 | + $success = $success ? 2 : false; |
|
| 2124 | + $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
| 2125 | + } |
|
| 2126 | + |
|
| 2127 | + |
|
| 2128 | + |
|
| 2129 | + /** |
|
| 2130 | + * _permanently_delete_event |
|
| 2131 | + * |
|
| 2132 | + * @access private |
|
| 2133 | + * @param int $EVT_ID |
|
| 2134 | + * @return bool |
|
| 2135 | + */ |
|
| 2136 | + private function _permanently_delete_event($EVT_ID = 0) |
|
| 2137 | + { |
|
| 2138 | + // grab event id |
|
| 2139 | + if ( ! $EVT_ID) { |
|
| 2140 | + $msg = esc_html__( |
|
| 2141 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2142 | + 'event_espresso' |
|
| 2143 | + ); |
|
| 2144 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2145 | + return false; |
|
| 2146 | + } |
|
| 2147 | + if ( |
|
| 2148 | + ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2149 | + || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2150 | + ) { |
|
| 2151 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2152 | + } |
|
| 2153 | + if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2154 | + return false; |
|
| 2155 | + } |
|
| 2156 | + //need to delete related tickets and prices first. |
|
| 2157 | + $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2158 | + foreach ($datetimes as $datetime) { |
|
| 2159 | + $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2160 | + $tickets = $datetime->get_many_related('Ticket'); |
|
| 2161 | + foreach ($tickets as $ticket) { |
|
| 2162 | + $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2163 | + $ticket->delete_related_permanently('Price'); |
|
| 2164 | + $ticket->delete_permanently(); |
|
| 2165 | + } |
|
| 2166 | + $datetime->delete(); |
|
| 2167 | + } |
|
| 2168 | + //what about related venues or terms? |
|
| 2169 | + $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2170 | + foreach ($venues as $venue) { |
|
| 2171 | + $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2172 | + } |
|
| 2173 | + //any attached question groups? |
|
| 2174 | + $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2175 | + if ( ! empty($question_groups)) { |
|
| 2176 | + foreach ($question_groups as $question_group) { |
|
| 2177 | + $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2178 | + } |
|
| 2179 | + } |
|
| 2180 | + //Message Template Groups |
|
| 2181 | + $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2182 | + /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2183 | + $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2184 | + foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2185 | + $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2186 | + } |
|
| 2187 | + $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2188 | + // did it all go as planned ? |
|
| 2189 | + if ($success) { |
|
| 2190 | + $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2191 | + EE_Error::add_success($msg); |
|
| 2192 | + } else { |
|
| 2193 | + $msg = sprintf( |
|
| 2194 | + esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2195 | + $EVT_ID |
|
| 2196 | + ); |
|
| 2197 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2198 | + return false; |
|
| 2199 | + } |
|
| 2200 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2201 | + return true; |
|
| 2202 | + } |
|
| 2203 | + |
|
| 2204 | + |
|
| 2205 | + |
|
| 2206 | + /** |
|
| 2207 | + * get total number of events |
|
| 2208 | + * |
|
| 2209 | + * @access public |
|
| 2210 | + * @return int |
|
| 2211 | + */ |
|
| 2212 | + public function total_events() |
|
| 2213 | + { |
|
| 2214 | + $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2215 | + return $count; |
|
| 2216 | + } |
|
| 2217 | + |
|
| 2218 | + |
|
| 2219 | + |
|
| 2220 | + /** |
|
| 2221 | + * get total number of draft events |
|
| 2222 | + * |
|
| 2223 | + * @access public |
|
| 2224 | + * @return int |
|
| 2225 | + */ |
|
| 2226 | + public function total_events_draft() |
|
| 2227 | + { |
|
| 2228 | + $where = array( |
|
| 2229 | + 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2230 | + ); |
|
| 2231 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2232 | + return $count; |
|
| 2233 | + } |
|
| 2234 | + |
|
| 2235 | + |
|
| 2236 | + |
|
| 2237 | + /** |
|
| 2238 | + * get total number of trashed events |
|
| 2239 | + * |
|
| 2240 | + * @access public |
|
| 2241 | + * @return int |
|
| 2242 | + */ |
|
| 2243 | + public function total_trashed_events() |
|
| 2244 | + { |
|
| 2245 | + $where = array( |
|
| 2246 | + 'status' => 'trash', |
|
| 2247 | + ); |
|
| 2248 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2249 | + return $count; |
|
| 2250 | + } |
|
| 2251 | + |
|
| 2252 | + |
|
| 2253 | + |
|
| 2254 | + /** |
|
| 2255 | + * _default_event_settings |
|
| 2256 | + * This generates the Default Settings Tab |
|
| 2257 | + * |
|
| 2258 | + * @return void |
|
| 2259 | + */ |
|
| 2260 | + protected function _default_event_settings() |
|
| 2261 | + { |
|
| 2262 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
| 2263 | + $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array( |
|
| 2264 | + // exclude array |
|
| 2265 | + array( |
|
| 2266 | + EEM_Registration::status_id_cancelled, |
|
| 2267 | + EEM_Registration::status_id_declined, |
|
| 2268 | + EEM_Registration::status_id_incomplete, |
|
| 2269 | + EEM_Registration::status_id_wait_list, |
|
| 2270 | + ), |
|
| 2271 | + // translated |
|
| 2272 | + true |
|
| 2273 | + ); |
|
| 2274 | + $this->_template_args['default_reg_status'] = isset( |
|
| 2275 | + EE_Registry::instance()->CFG->registration->default_STS_ID |
|
| 2276 | + ) |
|
| 2277 | + && array_key_exists( |
|
| 2278 | + EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 2279 | + $this->_template_args['reg_status_array'] |
|
| 2280 | + ) |
|
| 2281 | + ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID) |
|
| 2282 | + : EEM_Registration::status_id_pending_payment; |
|
| 2283 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2284 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2285 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2286 | + EVENTS_TEMPLATE_PATH . 'event_settings.template.php', |
|
| 2287 | + $this->_template_args, |
|
| 2288 | + true |
|
| 2289 | + ); |
|
| 2290 | + $this->display_admin_page_with_sidebar(); |
|
| 2291 | + } |
|
| 2292 | + |
|
| 2293 | + |
|
| 2294 | + |
|
| 2295 | + /** |
|
| 2296 | + * _update_default_event_settings |
|
| 2297 | + * |
|
| 2298 | + * @access protected |
|
| 2299 | + * @return void |
|
| 2300 | + */ |
|
| 2301 | + protected function _update_default_event_settings() |
|
| 2302 | + { |
|
| 2303 | + EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status']) |
|
| 2304 | + ? sanitize_text_field($this->_req_data['default_reg_status']) |
|
| 2305 | + : EEM_Registration::status_id_pending_payment; |
|
| 2306 | + $what = 'Default Event Settings'; |
|
| 2307 | + $success = $this->_update_espresso_configuration( |
|
| 2308 | + $what, |
|
| 2309 | + EE_Config::instance(), |
|
| 2310 | + __FILE__, |
|
| 2311 | + __FUNCTION__, |
|
| 2312 | + __LINE__ |
|
| 2313 | + ); |
|
| 2314 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings')); |
|
| 2315 | + } |
|
| 2316 | + |
|
| 2317 | + |
|
| 2318 | + |
|
| 2319 | + /************* Templates *************/ |
|
| 2320 | + protected function _template_settings() |
|
| 2321 | + { |
|
| 2322 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2323 | + $this->_template_args['preview_img'] = '<img src="' |
|
| 2324 | + . EVENTS_ASSETS_URL |
|
| 2325 | + . DS |
|
| 2326 | + . 'images' |
|
| 2327 | + . DS |
|
| 2328 | + . 'caffeinated_template_features.jpg" alt="' |
|
| 2329 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2330 | + . '" />'; |
|
| 2331 | + $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2332 | + 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2333 | + 'event_espresso' |
|
| 2334 | + ) . '</strong>'; |
|
| 2335 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2336 | + } |
|
| 2337 | + |
|
| 2338 | + |
|
| 2339 | + /** Event Category Stuff **/ |
|
| 2340 | + /** |
|
| 2341 | + * set the _category property with the category object for the loaded page. |
|
| 2342 | + * |
|
| 2343 | + * @access private |
|
| 2344 | + * @return void |
|
| 2345 | + */ |
|
| 2346 | + private function _set_category_object() |
|
| 2347 | + { |
|
| 2348 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2349 | + return; |
|
| 2350 | + } //already have the category object so get out. |
|
| 2351 | + //set default category object |
|
| 2352 | + $this->_set_empty_category_object(); |
|
| 2353 | + //only set if we've got an id |
|
| 2354 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2355 | + return; |
|
| 2356 | + } |
|
| 2357 | + $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2358 | + $term = get_term($category_id, 'espresso_event_categories'); |
|
| 2359 | + if ( ! empty($term)) { |
|
| 2360 | + $this->_category->category_name = $term->name; |
|
| 2361 | + $this->_category->category_identifier = $term->slug; |
|
| 2362 | + $this->_category->category_desc = $term->description; |
|
| 2363 | + $this->_category->id = $term->term_id; |
|
| 2364 | + $this->_category->parent = $term->parent; |
|
| 2365 | + } |
|
| 2366 | + } |
|
| 2367 | + |
|
| 2368 | + |
|
| 2369 | + |
|
| 2370 | + private function _set_empty_category_object() |
|
| 2371 | + { |
|
| 2372 | + $this->_category = new stdClass(); |
|
| 2373 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2374 | + $this->_category->id = $this->_category->parent = 0; |
|
| 2375 | + } |
|
| 2376 | + |
|
| 2377 | + |
|
| 2378 | + |
|
| 2379 | + protected function _category_list_table() |
|
| 2380 | + { |
|
| 2381 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2382 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2383 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2384 | + 'add_category', |
|
| 2385 | + 'add_category', |
|
| 2386 | + array(), |
|
| 2387 | + 'add-new-h2' |
|
| 2388 | + ); |
|
| 2389 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 2390 | + } |
|
| 2391 | + |
|
| 2392 | + |
|
| 2393 | + |
|
| 2394 | + /** |
|
| 2395 | + * @param $view |
|
| 2396 | + */ |
|
| 2397 | + protected function _category_details($view) |
|
| 2398 | + { |
|
| 2399 | + //load formatter helper |
|
| 2400 | + //load field generator helper |
|
| 2401 | + $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2402 | + $this->_set_add_edit_form_tags($route); |
|
| 2403 | + $this->_set_category_object(); |
|
| 2404 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2405 | + $delete_action = 'delete_category'; |
|
| 2406 | + //custom redirect |
|
| 2407 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2408 | + array('action' => 'category_list'), |
|
| 2409 | + $this->_admin_base_url |
|
| 2410 | + ); |
|
| 2411 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2412 | + //take care of contents |
|
| 2413 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2414 | + $this->display_admin_page_with_sidebar(); |
|
| 2415 | + } |
|
| 2416 | + |
|
| 2417 | + |
|
| 2418 | + |
|
| 2419 | + /** |
|
| 2420 | + * @return mixed |
|
| 2421 | + */ |
|
| 2422 | + protected function _category_details_content() |
|
| 2423 | + { |
|
| 2424 | + $editor_args['category_desc'] = array( |
|
| 2425 | + 'type' => 'wp_editor', |
|
| 2426 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2427 | + 'class' => 'my_editor_custom', |
|
| 2428 | + 'wpeditor_args' => array('media_buttons' => false), |
|
| 2429 | + ); |
|
| 2430 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2431 | + $all_terms = get_terms( |
|
| 2432 | + array('espresso_event_categories'), |
|
| 2433 | + array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2434 | + ); |
|
| 2435 | + //setup category select for term parents. |
|
| 2436 | + $category_select_values[] = array( |
|
| 2437 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2438 | + 'id' => 0, |
|
| 2439 | + ); |
|
| 2440 | + foreach ($all_terms as $term) { |
|
| 2441 | + $category_select_values[] = array( |
|
| 2442 | + 'text' => $term->name, |
|
| 2443 | + 'id' => $term->term_id, |
|
| 2444 | + ); |
|
| 2445 | + } |
|
| 2446 | + $category_select = EEH_Form_Fields::select_input( |
|
| 2447 | + 'category_parent', |
|
| 2448 | + $category_select_values, |
|
| 2449 | + $this->_category->parent |
|
| 2450 | + ); |
|
| 2451 | + $template_args = array( |
|
| 2452 | + 'category' => $this->_category, |
|
| 2453 | + 'category_select' => $category_select, |
|
| 2454 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2455 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2456 | + 'disable' => '', |
|
| 2457 | + 'disabled_message' => false, |
|
| 2458 | + ); |
|
| 2459 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2460 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 2461 | + } |
|
| 2462 | + |
|
| 2463 | + |
|
| 2464 | + |
|
| 2465 | + protected function _delete_categories() |
|
| 2466 | + { |
|
| 2467 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2468 | + : (array)$this->_req_data['category_id']; |
|
| 2469 | + foreach ($cat_ids as $cat_id) { |
|
| 2470 | + $this->_delete_category($cat_id); |
|
| 2471 | + } |
|
| 2472 | + //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2473 | + $query_args = array( |
|
| 2474 | + 'action' => 'category_list', |
|
| 2475 | + ); |
|
| 2476 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2477 | + } |
|
| 2478 | + |
|
| 2479 | + |
|
| 2480 | + |
|
| 2481 | + /** |
|
| 2482 | + * @param $cat_id |
|
| 2483 | + */ |
|
| 2484 | + protected function _delete_category($cat_id) |
|
| 2485 | + { |
|
| 2486 | + $cat_id = absint($cat_id); |
|
| 2487 | + wp_delete_term($cat_id, 'espresso_event_categories'); |
|
| 2488 | + } |
|
| 2489 | + |
|
| 2490 | + |
|
| 2491 | + |
|
| 2492 | + /** |
|
| 2493 | + * @param $new_category |
|
| 2494 | + */ |
|
| 2495 | + protected function _insert_or_update_category($new_category) |
|
| 2496 | + { |
|
| 2497 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2498 | + $success = 0; //we already have a success message so lets not send another. |
|
| 2499 | + if ($cat_id) { |
|
| 2500 | + $query_args = array( |
|
| 2501 | + 'action' => 'edit_category', |
|
| 2502 | + 'EVT_CAT_ID' => $cat_id, |
|
| 2503 | + ); |
|
| 2504 | + } else { |
|
| 2505 | + $query_args = array('action' => 'add_category'); |
|
| 2506 | + } |
|
| 2507 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2508 | + } |
|
| 2509 | + |
|
| 2510 | + |
|
| 2511 | + |
|
| 2512 | + /** |
|
| 2513 | + * @param bool $update |
|
| 2514 | + * @return bool|mixed|string |
|
| 2515 | + */ |
|
| 2516 | + private function _insert_category($update = false) |
|
| 2517 | + { |
|
| 2518 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2519 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2520 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2521 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2522 | + if (empty($category_name)) { |
|
| 2523 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2524 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2525 | + return false; |
|
| 2526 | + } |
|
| 2527 | + $term_args = array( |
|
| 2528 | + 'name' => $category_name, |
|
| 2529 | + 'description' => $category_desc, |
|
| 2530 | + 'parent' => $category_parent, |
|
| 2531 | + ); |
|
| 2532 | + //was the category_identifier input disabled? |
|
| 2533 | + if (isset($this->_req_data['category_identifier'])) { |
|
| 2534 | + $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2535 | + } |
|
| 2536 | + $insert_ids = $update |
|
| 2537 | + ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
| 2538 | + : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
| 2539 | + if ( ! is_array($insert_ids)) { |
|
| 2540 | + $msg = esc_html__( |
|
| 2541 | + 'An error occurred and the category has not been saved to the database.', |
|
| 2542 | + 'event_espresso' |
|
| 2543 | + ); |
|
| 2544 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2545 | + } else { |
|
| 2546 | + $cat_id = $insert_ids['term_id']; |
|
| 2547 | + $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2548 | + EE_Error::add_success($msg); |
|
| 2549 | + } |
|
| 2550 | + return $cat_id; |
|
| 2551 | + } |
|
| 2552 | + |
|
| 2553 | + |
|
| 2554 | + |
|
| 2555 | + /** |
|
| 2556 | + * @param int $per_page |
|
| 2557 | + * @param int $current_page |
|
| 2558 | + * @param bool $count |
|
| 2559 | + * @return \EE_Base_Class[]|int |
|
| 2560 | + */ |
|
| 2561 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2562 | + { |
|
| 2563 | + //testing term stuff |
|
| 2564 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2565 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2566 | + $limit = ($current_page - 1) * $per_page; |
|
| 2567 | + $where = array('taxonomy' => 'espresso_event_categories'); |
|
| 2568 | + if (isset($this->_req_data['s'])) { |
|
| 2569 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2570 | + $where['OR'] = array( |
|
| 2571 | + 'Term.name' => array('LIKE', $sstr), |
|
| 2572 | + 'description' => array('LIKE', $sstr), |
|
| 2573 | + ); |
|
| 2574 | + } |
|
| 2575 | + $query_params = array( |
|
| 2576 | + $where, |
|
| 2577 | + 'order_by' => array($orderby => $order), |
|
| 2578 | + 'limit' => $limit . ',' . $per_page, |
|
| 2579 | + 'force_join' => array('Term'), |
|
| 2580 | + ); |
|
| 2581 | + $categories = $count |
|
| 2582 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2583 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2584 | + return $categories; |
|
| 2585 | + } |
|
| 2586 | + |
|
| 2587 | + |
|
| 2588 | + |
|
| 2589 | + /* end category stuff */ |
|
| 2590 | + /**************/ |
|
| 2591 | 2591 | } |
| 2592 | 2592 | //end class Events_Admin_Page |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | global $wp_version; |
| 45 | 45 | wp_register_script( |
| 46 | 46 | 'eejs-core', |
| 47 | - EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
| 47 | + EE_PLUGIN_DIR_URL.'core/services/assets/core_assets/eejs-core.js', |
|
| 48 | 48 | array(), |
| 49 | 49 | espresso_version(), |
| 50 | 50 | true |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | //js.api |
| 55 | 55 | wp_register_script( |
| 56 | 56 | 'eejs-api', |
| 57 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 57 | + EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js', |
|
| 58 | 58 | array('underscore', 'eejs-core'), |
| 59 | 59 | espresso_version(), |
| 60 | 60 | true |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | public function addTemplate($template_reference, $template_content) |
| 146 | 146 | { |
| 147 | - if (! isset($this->jsdata['templates'])) { |
|
| 147 | + if ( ! isset($this->jsdata['templates'])) { |
|
| 148 | 148 | $this->jsdata['templates'] = array(); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -16,233 +16,233 @@ |
||
| 16 | 16 | class Registry |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - protected $jsdata = array(); |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Registry constructor. |
|
| 28 | - * Hooking into WP actions for script registry. |
|
| 29 | - */ |
|
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 100); |
|
| 33 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 100); |
|
| 34 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 35 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Callback for the WP script actions. |
|
| 41 | - * Used to register globally accessible core scripts. |
|
| 42 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 43 | - */ |
|
| 44 | - public function scripts() |
|
| 45 | - { |
|
| 46 | - global $wp_version; |
|
| 47 | - wp_register_script( |
|
| 48 | - 'eejs-core', |
|
| 49 | - EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
| 50 | - array(), |
|
| 51 | - espresso_version(), |
|
| 52 | - true |
|
| 53 | - ); |
|
| 54 | - //only run this if WordPress 4.4.0 > is in use. |
|
| 55 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 56 | - //js.api |
|
| 57 | - wp_register_script( |
|
| 58 | - 'eejs-api', |
|
| 59 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 60 | - array('underscore', 'eejs-core'), |
|
| 61 | - espresso_version(), |
|
| 62 | - true |
|
| 63 | - ); |
|
| 64 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Call back for the script print in frontend and backend. |
|
| 71 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hookpoint. |
|
| 72 | - * @since 4.9.31.rc.015 |
|
| 73 | - */ |
|
| 74 | - public function enqueueData() |
|
| 75 | - { |
|
| 76 | - wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Used to add data to eejs.data object. |
|
| 82 | - * |
|
| 83 | - * Note: Overriding existing data is not allowed. |
|
| 84 | - * |
|
| 85 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 86 | - * If the data you add is something like this: |
|
| 87 | - * |
|
| 88 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 89 | - * |
|
| 90 | - * It will be exposed in the page source as: |
|
| 91 | - * |
|
| 92 | - * eejs.data.my_plugin_data.foo == gar |
|
| 93 | - * |
|
| 94 | - * @param string $key Key used to access your data |
|
| 95 | - * @param string|array $value Value to attach to key |
|
| 96 | - * @throws InvalidArgumentException |
|
| 97 | - */ |
|
| 98 | - public function addData($key, $value) |
|
| 99 | - { |
|
| 100 | - if ($this->verifyDataNotExisting($key)) { |
|
| 101 | - $this->jsdata[$key] = $value; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 108 | - * elements in an array. |
|
| 109 | - * |
|
| 110 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 111 | - * |
|
| 112 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript object |
|
| 113 | - * like this, |
|
| 114 | - * |
|
| 115 | - * eejs.data.test = [ |
|
| 116 | - * my_data, |
|
| 117 | - * ] |
|
| 118 | - * |
|
| 119 | - * If there has already been a scalar value attached to the data object given key, then |
|
| 120 | - * this will throw an exception. |
|
| 121 | - * |
|
| 122 | - * @param string $key Key to attach data to. |
|
| 123 | - * @param string|array $value Value being registered. |
|
| 124 | - * @throws InvalidArgumentException |
|
| 125 | - */ |
|
| 126 | - public function pushData($key, $value) |
|
| 127 | - { |
|
| 128 | - if (isset($this->jsdata[$key]) |
|
| 129 | - && ! is_array($this->jsdata[$key]) |
|
| 130 | - ) { |
|
| 131 | - throw new invalidArgumentException( |
|
| 132 | - sprintf( |
|
| 133 | - __( |
|
| 134 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 19 | + /** |
|
| 20 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + protected $jsdata = array(); |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Registry constructor. |
|
| 28 | + * Hooking into WP actions for script registry. |
|
| 29 | + */ |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 100); |
|
| 33 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 100); |
|
| 34 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 35 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Callback for the WP script actions. |
|
| 41 | + * Used to register globally accessible core scripts. |
|
| 42 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
| 43 | + */ |
|
| 44 | + public function scripts() |
|
| 45 | + { |
|
| 46 | + global $wp_version; |
|
| 47 | + wp_register_script( |
|
| 48 | + 'eejs-core', |
|
| 49 | + EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
| 50 | + array(), |
|
| 51 | + espresso_version(), |
|
| 52 | + true |
|
| 53 | + ); |
|
| 54 | + //only run this if WordPress 4.4.0 > is in use. |
|
| 55 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
| 56 | + //js.api |
|
| 57 | + wp_register_script( |
|
| 58 | + 'eejs-api', |
|
| 59 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
| 60 | + array('underscore', 'eejs-core'), |
|
| 61 | + espresso_version(), |
|
| 62 | + true |
|
| 63 | + ); |
|
| 64 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Call back for the script print in frontend and backend. |
|
| 71 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hookpoint. |
|
| 72 | + * @since 4.9.31.rc.015 |
|
| 73 | + */ |
|
| 74 | + public function enqueueData() |
|
| 75 | + { |
|
| 76 | + wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Used to add data to eejs.data object. |
|
| 82 | + * |
|
| 83 | + * Note: Overriding existing data is not allowed. |
|
| 84 | + * |
|
| 85 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
| 86 | + * If the data you add is something like this: |
|
| 87 | + * |
|
| 88 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
| 89 | + * |
|
| 90 | + * It will be exposed in the page source as: |
|
| 91 | + * |
|
| 92 | + * eejs.data.my_plugin_data.foo == gar |
|
| 93 | + * |
|
| 94 | + * @param string $key Key used to access your data |
|
| 95 | + * @param string|array $value Value to attach to key |
|
| 96 | + * @throws InvalidArgumentException |
|
| 97 | + */ |
|
| 98 | + public function addData($key, $value) |
|
| 99 | + { |
|
| 100 | + if ($this->verifyDataNotExisting($key)) { |
|
| 101 | + $this->jsdata[$key] = $value; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
| 108 | + * elements in an array. |
|
| 109 | + * |
|
| 110 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
| 111 | + * |
|
| 112 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript object |
|
| 113 | + * like this, |
|
| 114 | + * |
|
| 115 | + * eejs.data.test = [ |
|
| 116 | + * my_data, |
|
| 117 | + * ] |
|
| 118 | + * |
|
| 119 | + * If there has already been a scalar value attached to the data object given key, then |
|
| 120 | + * this will throw an exception. |
|
| 121 | + * |
|
| 122 | + * @param string $key Key to attach data to. |
|
| 123 | + * @param string|array $value Value being registered. |
|
| 124 | + * @throws InvalidArgumentException |
|
| 125 | + */ |
|
| 126 | + public function pushData($key, $value) |
|
| 127 | + { |
|
| 128 | + if (isset($this->jsdata[$key]) |
|
| 129 | + && ! is_array($this->jsdata[$key]) |
|
| 130 | + ) { |
|
| 131 | + throw new invalidArgumentException( |
|
| 132 | + sprintf( |
|
| 133 | + __( |
|
| 134 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
| 135 | 135 | push values to this data element when it is an array.', |
| 136 | - 'event_espresso' |
|
| 137 | - ), |
|
| 138 | - $key, |
|
| 139 | - __METHOD__ |
|
| 140 | - ) |
|
| 141 | - ); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $this->jsdata[$key][] = $value; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Used to set content used by javascript for a template. |
|
| 150 | - * Note: Overrides of existing registered templates are not allowed. |
|
| 151 | - * |
|
| 152 | - * @param string $template_reference |
|
| 153 | - * @param string $template_content |
|
| 154 | - * @throws InvalidArgumentException |
|
| 155 | - */ |
|
| 156 | - public function addTemplate($template_reference, $template_content) |
|
| 157 | - { |
|
| 158 | - if (! isset($this->jsdata['templates'])) { |
|
| 159 | - $this->jsdata['templates'] = array(); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - //no overrides allowed. |
|
| 163 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 164 | - throw new invalidArgumentException( |
|
| 165 | - sprintf( |
|
| 166 | - __( |
|
| 167 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 168 | - 'event_espresso' |
|
| 169 | - ), |
|
| 170 | - $template_reference |
|
| 171 | - ) |
|
| 172 | - ); |
|
| 173 | - } else { |
|
| 174 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Retrieve the template content already registered for the given reference. |
|
| 181 | - * @param string $template_reference |
|
| 182 | - * @return string |
|
| 183 | - */ |
|
| 184 | - public function getTemplate($template_reference) |
|
| 185 | - { |
|
| 186 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 187 | - ? $this->jsdata['templates'][$template_reference] |
|
| 188 | - : ''; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Retrieve registered data. |
|
| 194 | - * |
|
| 195 | - * @param string $key Name of key to attach data to. |
|
| 196 | - * @return mixed If there is no for the given key, then false is returned. |
|
| 197 | - */ |
|
| 198 | - public function getData($key) |
|
| 199 | - { |
|
| 200 | - return isset($this->jsdata[$key]) |
|
| 201 | - ? $this->jsdata[$key] |
|
| 202 | - : false; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Verifies whether the given data exists already on the jsdata array. |
|
| 210 | - * |
|
| 211 | - * Overriding data is not allowed. |
|
| 212 | - * |
|
| 213 | - * @param string $key Index for data. |
|
| 214 | - * @return bool If valid then return true. |
|
| 215 | - * @throws InvalidArgumentException if data already exists. |
|
| 216 | - */ |
|
| 217 | - protected function verifyDataNotExisting($key) |
|
| 218 | - { |
|
| 219 | - if (isset($this->jsdata[$key])) { |
|
| 220 | - if (is_array($this->jsdata[$key])) { |
|
| 221 | - throw new InvalidArgumentException( |
|
| 222 | - sprintf( |
|
| 223 | - __( |
|
| 224 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
| 136 | + 'event_espresso' |
|
| 137 | + ), |
|
| 138 | + $key, |
|
| 139 | + __METHOD__ |
|
| 140 | + ) |
|
| 141 | + ); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $this->jsdata[$key][] = $value; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Used to set content used by javascript for a template. |
|
| 150 | + * Note: Overrides of existing registered templates are not allowed. |
|
| 151 | + * |
|
| 152 | + * @param string $template_reference |
|
| 153 | + * @param string $template_content |
|
| 154 | + * @throws InvalidArgumentException |
|
| 155 | + */ |
|
| 156 | + public function addTemplate($template_reference, $template_content) |
|
| 157 | + { |
|
| 158 | + if (! isset($this->jsdata['templates'])) { |
|
| 159 | + $this->jsdata['templates'] = array(); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + //no overrides allowed. |
|
| 163 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
| 164 | + throw new invalidArgumentException( |
|
| 165 | + sprintf( |
|
| 166 | + __( |
|
| 167 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
| 168 | + 'event_espresso' |
|
| 169 | + ), |
|
| 170 | + $template_reference |
|
| 171 | + ) |
|
| 172 | + ); |
|
| 173 | + } else { |
|
| 174 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Retrieve the template content already registered for the given reference. |
|
| 181 | + * @param string $template_reference |
|
| 182 | + * @return string |
|
| 183 | + */ |
|
| 184 | + public function getTemplate($template_reference) |
|
| 185 | + { |
|
| 186 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
| 187 | + ? $this->jsdata['templates'][$template_reference] |
|
| 188 | + : ''; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Retrieve registered data. |
|
| 194 | + * |
|
| 195 | + * @param string $key Name of key to attach data to. |
|
| 196 | + * @return mixed If there is no for the given key, then false is returned. |
|
| 197 | + */ |
|
| 198 | + public function getData($key) |
|
| 199 | + { |
|
| 200 | + return isset($this->jsdata[$key]) |
|
| 201 | + ? $this->jsdata[$key] |
|
| 202 | + : false; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Verifies whether the given data exists already on the jsdata array. |
|
| 210 | + * |
|
| 211 | + * Overriding data is not allowed. |
|
| 212 | + * |
|
| 213 | + * @param string $key Index for data. |
|
| 214 | + * @return bool If valid then return true. |
|
| 215 | + * @throws InvalidArgumentException if data already exists. |
|
| 216 | + */ |
|
| 217 | + protected function verifyDataNotExisting($key) |
|
| 218 | + { |
|
| 219 | + if (isset($this->jsdata[$key])) { |
|
| 220 | + if (is_array($this->jsdata[$key])) { |
|
| 221 | + throw new InvalidArgumentException( |
|
| 222 | + sprintf( |
|
| 223 | + __( |
|
| 224 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
| 225 | 225 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
| 226 | 226 | %2$s method to push your value to the array.', |
| 227 | - 'event_espresso' |
|
| 228 | - ), |
|
| 229 | - $key, |
|
| 230 | - 'pushData()' |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 233 | - } else { |
|
| 234 | - throw new InvalidArgumentException( |
|
| 235 | - sprintf( |
|
| 236 | - __( |
|
| 237 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 227 | + 'event_espresso' |
|
| 228 | + ), |
|
| 229 | + $key, |
|
| 230 | + 'pushData()' |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | + } else { |
|
| 234 | + throw new InvalidArgumentException( |
|
| 235 | + sprintf( |
|
| 236 | + __( |
|
| 237 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
| 238 | 238 | allowed. Consider attaching your value to a different key', |
| 239 | - 'event_espresso' |
|
| 240 | - ), |
|
| 241 | - $key |
|
| 242 | - ) |
|
| 243 | - ); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - return true; |
|
| 247 | - } |
|
| 239 | + 'event_espresso' |
|
| 240 | + ), |
|
| 241 | + $key |
|
| 242 | + ) |
|
| 243 | + ); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + return true; |
|
| 247 | + } |
|
| 248 | 248 | } |