@@ -15,112 +15,112 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class EE_Question_List_Shortcodes extends EE_Shortcodes |
| 17 | 17 | { |
| 18 | - public function __construct() |
|
| 19 | - { |
|
| 20 | - parent::__construct(); |
|
| 21 | - } |
|
| 18 | + public function __construct() |
|
| 19 | + { |
|
| 20 | + parent::__construct(); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - protected function _init_props() |
|
| 25 | - { |
|
| 26 | - $this->label = esc_html__('Questions and Answers Shortcodes', 'event_espresso'); |
|
| 27 | - $this->description = esc_html__('All shortcodes related to custom questions and answers', 'event_espresso'); |
|
| 28 | - $this->_shortcodes = [ |
|
| 29 | - '[QUESTION_LIST]' => esc_html__( |
|
| 30 | - 'This is used to indicate where you want the list of questions and answers to show for the registrant. You place this within the "[attendee_list]" field.', |
|
| 31 | - 'event_espresso' |
|
| 32 | - ), |
|
| 33 | - ]; |
|
| 34 | - } |
|
| 24 | + protected function _init_props() |
|
| 25 | + { |
|
| 26 | + $this->label = esc_html__('Questions and Answers Shortcodes', 'event_espresso'); |
|
| 27 | + $this->description = esc_html__('All shortcodes related to custom questions and answers', 'event_espresso'); |
|
| 28 | + $this->_shortcodes = [ |
|
| 29 | + '[QUESTION_LIST]' => esc_html__( |
|
| 30 | + 'This is used to indicate where you want the list of questions and answers to show for the registrant. You place this within the "[attendee_list]" field.', |
|
| 31 | + 'event_espresso' |
|
| 32 | + ), |
|
| 33 | + ]; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param string $shortcode |
|
| 39 | - * @return string |
|
| 40 | - * @throws EE_Error |
|
| 41 | - * @throws ReflectionException |
|
| 42 | - */ |
|
| 43 | - protected function _parser($shortcode) |
|
| 44 | - { |
|
| 45 | - if ($shortcode == '[QUESTION_LIST]') { |
|
| 46 | - return $this->_get_question_list(); |
|
| 47 | - } |
|
| 48 | - return ''; |
|
| 49 | - } |
|
| 37 | + /** |
|
| 38 | + * @param string $shortcode |
|
| 39 | + * @return string |
|
| 40 | + * @throws EE_Error |
|
| 41 | + * @throws ReflectionException |
|
| 42 | + */ |
|
| 43 | + protected function _parser($shortcode) |
|
| 44 | + { |
|
| 45 | + if ($shortcode == '[QUESTION_LIST]') { |
|
| 46 | + return $this->_get_question_list(); |
|
| 47 | + } |
|
| 48 | + return ''; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return string |
|
| 54 | - * @throws EE_Error |
|
| 55 | - * @throws ReflectionException |
|
| 56 | - */ |
|
| 57 | - protected function _get_question_list() |
|
| 58 | - { |
|
| 59 | - $this->_validate_list_requirements(); |
|
| 52 | + /** |
|
| 53 | + * @return string |
|
| 54 | + * @throws EE_Error |
|
| 55 | + * @throws ReflectionException |
|
| 56 | + */ |
|
| 57 | + protected function _get_question_list() |
|
| 58 | + { |
|
| 59 | + $this->_validate_list_requirements(); |
|
| 60 | 60 | |
| 61 | - // for when [QUESTION_LIST] is used in the [attendee_list] field. |
|
| 62 | - if ($this->_data['data'] instanceof EE_Registration) { |
|
| 63 | - return $this->_get_question_answer_list_for_attendee(); |
|
| 64 | - } |
|
| 61 | + // for when [QUESTION_LIST] is used in the [attendee_list] field. |
|
| 62 | + if ($this->_data['data'] instanceof EE_Registration) { |
|
| 63 | + return $this->_get_question_answer_list_for_attendee(); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - // for when [QUESTION_LIST] is used in the main content field. |
|
| 67 | - if ( |
|
| 68 | - $this->_data['data'] instanceof EE_Messages_Addressee |
|
| 69 | - && $this->_data['data']->reg_obj instanceof EE_Registration |
|
| 70 | - ) { |
|
| 71 | - return $this->_get_question_answer_list_for_attendee($this->_data['data']->reg_obj); |
|
| 72 | - } |
|
| 73 | - return ''; |
|
| 74 | - } |
|
| 66 | + // for when [QUESTION_LIST] is used in the main content field. |
|
| 67 | + if ( |
|
| 68 | + $this->_data['data'] instanceof EE_Messages_Addressee |
|
| 69 | + && $this->_data['data']->reg_obj instanceof EE_Registration |
|
| 70 | + ) { |
|
| 71 | + return $this->_get_question_answer_list_for_attendee($this->_data['data']->reg_obj); |
|
| 72 | + } |
|
| 73 | + return ''; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Note when we parse the "[question_list]" shortcode for attendees we're actually going to retrieve the list of |
|
| 79 | - * answers for that attendee since that is what we really need (we can derive the questions from the answers); |
|
| 80 | - * |
|
| 81 | - * @param null $reg_obj |
|
| 82 | - * @return string parsed template. |
|
| 83 | - * @throws EE_Error |
|
| 84 | - * @throws ReflectionException |
|
| 85 | - */ |
|
| 86 | - private function _get_question_answer_list_for_attendee($reg_obj = null) |
|
| 87 | - { |
|
| 88 | - $valid_shortcodes = ['question']; |
|
| 89 | - $reg_obj = $reg_obj instanceof EE_Registration |
|
| 90 | - ? $reg_obj |
|
| 91 | - : $this->_data['data']; |
|
| 92 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['question_list']) |
|
| 93 | - ? $this->_data['template']['question_list'] |
|
| 94 | - : ''; |
|
| 95 | - $template = empty($template) && isset($this->_extra_data['template']['question_list']) |
|
| 96 | - ? $this->_extra_data['template']['question_list'] |
|
| 97 | - : $template; |
|
| 98 | - $ans_result = ''; |
|
| 99 | - $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
| 100 | - ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
| 101 | - : []; |
|
| 102 | - $questions = ! empty($this->_extra_data['data']->questions) |
|
| 103 | - ? $this->_extra_data['data']->questions |
|
| 104 | - : []; |
|
| 105 | - foreach ($answers as $answer) { |
|
| 106 | - // first see if the question is in our $questions array. If not then try to get from answer object |
|
| 107 | - $question = isset($questions[ $answer->ID() ]) |
|
| 108 | - ? $questions[ $answer->ID() ] |
|
| 109 | - : null; |
|
| 110 | - $question = ! $question instanceof EE_Question |
|
| 111 | - ? $answer->question() |
|
| 112 | - : $question; |
|
| 113 | - if ($question instanceof EE_Question and $question->admin_only()) { |
|
| 114 | - continue; |
|
| 115 | - } |
|
| 116 | - $ans_result .= $this->_shortcode_helper->parse_question_list_template( |
|
| 117 | - $template, |
|
| 118 | - $answer, |
|
| 119 | - $valid_shortcodes, |
|
| 120 | - $this->_extra_data |
|
| 121 | - ); |
|
| 122 | - } |
|
| 77 | + /** |
|
| 78 | + * Note when we parse the "[question_list]" shortcode for attendees we're actually going to retrieve the list of |
|
| 79 | + * answers for that attendee since that is what we really need (we can derive the questions from the answers); |
|
| 80 | + * |
|
| 81 | + * @param null $reg_obj |
|
| 82 | + * @return string parsed template. |
|
| 83 | + * @throws EE_Error |
|
| 84 | + * @throws ReflectionException |
|
| 85 | + */ |
|
| 86 | + private function _get_question_answer_list_for_attendee($reg_obj = null) |
|
| 87 | + { |
|
| 88 | + $valid_shortcodes = ['question']; |
|
| 89 | + $reg_obj = $reg_obj instanceof EE_Registration |
|
| 90 | + ? $reg_obj |
|
| 91 | + : $this->_data['data']; |
|
| 92 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['question_list']) |
|
| 93 | + ? $this->_data['template']['question_list'] |
|
| 94 | + : ''; |
|
| 95 | + $template = empty($template) && isset($this->_extra_data['template']['question_list']) |
|
| 96 | + ? $this->_extra_data['template']['question_list'] |
|
| 97 | + : $template; |
|
| 98 | + $ans_result = ''; |
|
| 99 | + $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
| 100 | + ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
| 101 | + : []; |
|
| 102 | + $questions = ! empty($this->_extra_data['data']->questions) |
|
| 103 | + ? $this->_extra_data['data']->questions |
|
| 104 | + : []; |
|
| 105 | + foreach ($answers as $answer) { |
|
| 106 | + // first see if the question is in our $questions array. If not then try to get from answer object |
|
| 107 | + $question = isset($questions[ $answer->ID() ]) |
|
| 108 | + ? $questions[ $answer->ID() ] |
|
| 109 | + : null; |
|
| 110 | + $question = ! $question instanceof EE_Question |
|
| 111 | + ? $answer->question() |
|
| 112 | + : $question; |
|
| 113 | + if ($question instanceof EE_Question and $question->admin_only()) { |
|
| 114 | + continue; |
|
| 115 | + } |
|
| 116 | + $ans_result .= $this->_shortcode_helper->parse_question_list_template( |
|
| 117 | + $template, |
|
| 118 | + $answer, |
|
| 119 | + $valid_shortcodes, |
|
| 120 | + $this->_extra_data |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - return $ans_result; |
|
| 125 | - } |
|
| 124 | + return $ans_result; |
|
| 125 | + } |
|
| 126 | 126 | } |
@@ -37,138 +37,138 @@ |
||
| 37 | 37 | * @since 4.0 |
| 38 | 38 | */ |
| 39 | 39 | if (function_exists('espresso_version')) { |
| 40 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 41 | - /** |
|
| 42 | - * espresso_duplicate_plugin_error |
|
| 43 | - * displays if more than one version of EE is activated at the same time. |
|
| 44 | - */ |
|
| 45 | - function espresso_duplicate_plugin_error() |
|
| 46 | - { |
|
| 47 | - ?> |
|
| 40 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 41 | + /** |
|
| 42 | + * espresso_duplicate_plugin_error |
|
| 43 | + * displays if more than one version of EE is activated at the same time. |
|
| 44 | + */ |
|
| 45 | + function espresso_duplicate_plugin_error() |
|
| 46 | + { |
|
| 47 | + ?> |
|
| 48 | 48 | <div class="error"> |
| 49 | 49 | <p> |
| 50 | 50 | <?php |
| 51 | - echo esc_html__( |
|
| 52 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 53 | - 'event_espresso' |
|
| 54 | - ); ?> |
|
| 51 | + echo esc_html__( |
|
| 52 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 53 | + 'event_espresso' |
|
| 54 | + ); ?> |
|
| 55 | 55 | </p> |
| 56 | 56 | </div> |
| 57 | 57 | <?php |
| 58 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 58 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | 62 | } else { |
| 63 | - define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); |
|
| 64 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 65 | - /** |
|
| 66 | - * espresso_minimum_php_version_error |
|
| 67 | - * |
|
| 68 | - * @return void |
|
| 69 | - */ |
|
| 70 | - function espresso_minimum_php_version_error() |
|
| 71 | - { |
|
| 72 | - ?> |
|
| 63 | + define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); |
|
| 64 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 65 | + /** |
|
| 66 | + * espresso_minimum_php_version_error |
|
| 67 | + * |
|
| 68 | + * @return void |
|
| 69 | + */ |
|
| 70 | + function espresso_minimum_php_version_error() |
|
| 71 | + { |
|
| 72 | + ?> |
|
| 73 | 73 | <div class="error"> |
| 74 | 74 | <p> |
| 75 | 75 | <?php |
| 76 | - printf( |
|
| 77 | - esc_html__( |
|
| 78 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 79 | - 'event_espresso' |
|
| 80 | - ), |
|
| 81 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 82 | - PHP_VERSION, |
|
| 83 | - '<br/>', |
|
| 84 | - '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>' |
|
| 85 | - ); |
|
| 86 | - ?> |
|
| 76 | + printf( |
|
| 77 | + esc_html__( |
|
| 78 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 79 | + 'event_espresso' |
|
| 80 | + ), |
|
| 81 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 82 | + PHP_VERSION, |
|
| 83 | + '<br/>', |
|
| 84 | + '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>' |
|
| 85 | + ); |
|
| 86 | + ?> |
|
| 87 | 87 | </p> |
| 88 | 88 | </div> |
| 89 | 89 | <?php |
| 90 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 91 | - } |
|
| 90 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 94 | - } else { |
|
| 95 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 93 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 94 | + } else { |
|
| 95 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 96 | 96 | |
| 97 | - require_once __DIR__ . '/vendor/autoload.php'; |
|
| 97 | + require_once __DIR__ . '/vendor/autoload.php'; |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * espresso_version |
|
| 101 | - * Returns the plugin version |
|
| 102 | - * |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - function espresso_version(): string |
|
| 106 | - { |
|
| 107 | - return apply_filters('FHEE__espresso__espresso_version', '5.0.21.rc.000'); |
|
| 108 | - } |
|
| 99 | + /** |
|
| 100 | + * espresso_version |
|
| 101 | + * Returns the plugin version |
|
| 102 | + * |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + function espresso_version(): string |
|
| 106 | + { |
|
| 107 | + return apply_filters('FHEE__espresso__espresso_version', '5.0.21.rc.000'); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * espresso_plugin_activation |
|
| 112 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 113 | - */ |
|
| 114 | - function espresso_plugin_activation() |
|
| 115 | - { |
|
| 116 | - update_option('ee_espresso_activation', true); |
|
| 117 | - update_option('event-espresso-core_allow_tracking', 'no'); |
|
| 118 | - update_option('event-espresso-core_tracking_notice', 'hide'); |
|
| 119 | - // Run WP GraphQL activation callback |
|
| 120 | - espressoLoadWpGraphQL(); |
|
| 121 | - graphql_activation_callback(); |
|
| 122 | - } |
|
| 110 | + /** |
|
| 111 | + * espresso_plugin_activation |
|
| 112 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 113 | + */ |
|
| 114 | + function espresso_plugin_activation() |
|
| 115 | + { |
|
| 116 | + update_option('ee_espresso_activation', true); |
|
| 117 | + update_option('event-espresso-core_allow_tracking', 'no'); |
|
| 118 | + update_option('event-espresso-core_tracking_notice', 'hide'); |
|
| 119 | + // Run WP GraphQL activation callback |
|
| 120 | + espressoLoadWpGraphQL(); |
|
| 121 | + graphql_activation_callback(); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 124 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * espresso_plugin_deactivation |
|
| 128 | - */ |
|
| 129 | - function espresso_plugin_deactivation() |
|
| 130 | - { |
|
| 131 | - // Run WP GraphQL deactivation callback |
|
| 132 | - espressoLoadWpGraphQL(); |
|
| 133 | - graphql_deactivation_callback(); |
|
| 134 | - delete_option('event-espresso-core_allow_tracking'); |
|
| 135 | - delete_option('event-espresso-core_tracking_notice'); |
|
| 136 | - } |
|
| 137 | - register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
| 126 | + /** |
|
| 127 | + * espresso_plugin_deactivation |
|
| 128 | + */ |
|
| 129 | + function espresso_plugin_deactivation() |
|
| 130 | + { |
|
| 131 | + // Run WP GraphQL deactivation callback |
|
| 132 | + espressoLoadWpGraphQL(); |
|
| 133 | + graphql_deactivation_callback(); |
|
| 134 | + delete_option('event-espresso-core_allow_tracking'); |
|
| 135 | + delete_option('event-espresso-core_tracking_notice'); |
|
| 136 | + } |
|
| 137 | + register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
| 138 | 138 | |
| 139 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 140 | - bootstrap_espresso(); |
|
| 141 | - } |
|
| 139 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 140 | + bootstrap_espresso(); |
|
| 141 | + } |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | if (! function_exists('espresso_deactivate_plugin')) { |
| 145 | - /** |
|
| 146 | - * deactivate_plugin |
|
| 147 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 148 | - * |
|
| 149 | - * @access public |
|
| 150 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 151 | - * @return void |
|
| 152 | - */ |
|
| 153 | - function espresso_deactivate_plugin(string $plugin_basename = '') |
|
| 154 | - { |
|
| 155 | - if (! function_exists('deactivate_plugins')) { |
|
| 156 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 157 | - } |
|
| 158 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 159 | - deactivate_plugins($plugin_basename); |
|
| 160 | - } |
|
| 145 | + /** |
|
| 146 | + * deactivate_plugin |
|
| 147 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 148 | + * |
|
| 149 | + * @access public |
|
| 150 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 151 | + * @return void |
|
| 152 | + */ |
|
| 153 | + function espresso_deactivate_plugin(string $plugin_basename = '') |
|
| 154 | + { |
|
| 155 | + if (! function_exists('deactivate_plugins')) { |
|
| 156 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 157 | + } |
|
| 158 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 159 | + deactivate_plugins($plugin_basename); |
|
| 160 | + } |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
| 164 | 164 | if (! function_exists('espressoLoadWpGraphQL')) { |
| 165 | - function espressoLoadWpGraphQL() |
|
| 166 | - { |
|
| 167 | - if ( |
|
| 168 | - ! class_exists('WPGraphQL') |
|
| 169 | - && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php') |
|
| 170 | - ) { |
|
| 171 | - require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php'; |
|
| 172 | - } |
|
| 173 | - } |
|
| 165 | + function espressoLoadWpGraphQL() |
|
| 166 | + { |
|
| 167 | + if ( |
|
| 168 | + ! class_exists('WPGraphQL') |
|
| 169 | + && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php') |
|
| 170 | + ) { |
|
| 171 | + require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php'; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -27,827 +27,827 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class EE_Registration_Processor extends EE_Processor_Base |
| 29 | 29 | { |
| 30 | - /** |
|
| 31 | - * @var EE_Registration_Processor $_instance |
|
| 32 | - * @access private |
|
| 33 | - */ |
|
| 34 | - private static $_instance; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * initial reg status at the beginning of this request. |
|
| 38 | - * indexed by registration ID |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - protected $_old_reg_status = []; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * reg status at the end of the request after all processing. |
|
| 46 | - * indexed by registration ID |
|
| 47 | - * |
|
| 48 | - * @var array |
|
| 49 | - */ |
|
| 50 | - protected $_new_reg_status = []; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * amounts paid at the end of the request after all processing. |
|
| 54 | - * indexed by registration ID |
|
| 55 | - * |
|
| 56 | - * @var array |
|
| 57 | - */ |
|
| 58 | - protected static $_amount_paid = []; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Cache of the reg final price for registrations corresponding to a ticket line item |
|
| 62 | - * |
|
| 63 | - * @deprecated |
|
| 64 | - * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value |
|
| 65 | - */ |
|
| 66 | - protected $_reg_final_price_per_tkt_line_item; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var RequestInterface $request |
|
| 70 | - */ |
|
| 71 | - protected $request; |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @singleton method used to instantiate class object |
|
| 76 | - * @param RequestInterface|null $request |
|
| 77 | - * @return EE_Registration_Processor instance |
|
| 78 | - * @throws InvalidArgumentException |
|
| 79 | - * @throws InvalidInterfaceException |
|
| 80 | - * @throws InvalidDataTypeException |
|
| 81 | - */ |
|
| 82 | - public static function instance(RequestInterface $request = null) |
|
| 83 | - { |
|
| 84 | - // check if class object is instantiated |
|
| 85 | - if (! self::$_instance instanceof EE_Registration_Processor) { |
|
| 86 | - if (! $request instanceof RequestInterface) { |
|
| 87 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
| 88 | - } |
|
| 89 | - self::$_instance = new self($request); |
|
| 90 | - } |
|
| 91 | - return self::$_instance; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * EE_Registration_Processor constructor. |
|
| 97 | - * |
|
| 98 | - * @param RequestInterface $request |
|
| 99 | - */ |
|
| 100 | - public function __construct(RequestInterface $request) |
|
| 101 | - { |
|
| 102 | - $this->request = $request; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @param int $REG_ID |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public function old_reg_status($REG_ID) |
|
| 111 | - { |
|
| 112 | - return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param int $REG_ID |
|
| 118 | - * @param string $old_reg_status |
|
| 119 | - */ |
|
| 120 | - public function set_old_reg_status($REG_ID, $old_reg_status) |
|
| 121 | - { |
|
| 122 | - // only set the first time |
|
| 123 | - if (! isset($this->_old_reg_status[ $REG_ID ])) { |
|
| 124 | - $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @param int $REG_ID |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 133 | - public function new_reg_status($REG_ID) |
|
| 134 | - { |
|
| 135 | - return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param int $REG_ID |
|
| 141 | - * @param string $new_reg_status |
|
| 142 | - */ |
|
| 143 | - public function set_new_reg_status($REG_ID, $new_reg_status) |
|
| 144 | - { |
|
| 145 | - $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * reg_status_updated |
|
| 151 | - * |
|
| 152 | - * @param int $REG_ID |
|
| 153 | - * @return bool |
|
| 154 | - */ |
|
| 155 | - public function reg_status_updated($REG_ID) |
|
| 156 | - { |
|
| 157 | - return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @param EE_Registration $registration |
|
| 163 | - * @throws EE_Error |
|
| 164 | - * @throws EntityNotFoundException |
|
| 165 | - * @throws InvalidArgumentException |
|
| 166 | - * @throws InvalidDataTypeException |
|
| 167 | - * @throws InvalidInterfaceException |
|
| 168 | - * @throws ReflectionException |
|
| 169 | - * @throws RuntimeException |
|
| 170 | - */ |
|
| 171 | - public function update_registration_status_and_trigger_notifications(EE_Registration $registration) |
|
| 172 | - { |
|
| 173 | - $this->toggle_incomplete_registration_status_to_default( |
|
| 174 | - $registration, |
|
| 175 | - false, |
|
| 176 | - new Context( |
|
| 177 | - __METHOD__, |
|
| 178 | - esc_html__( |
|
| 179 | - 'Executed when the registration status is updated during the registration process just prior to triggering notifications.', |
|
| 180 | - 'event_espresso' |
|
| 181 | - ) |
|
| 182 | - ) |
|
| 183 | - ); |
|
| 184 | - $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
| 185 | - $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
| 186 | - $registration->save(); |
|
| 187 | - // trigger notifications |
|
| 188 | - $this->trigger_registration_update_notifications($registration); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * manually_update_registration_status |
|
| 194 | - * |
|
| 195 | - * @access public |
|
| 196 | - * @param EE_Registration $registration |
|
| 197 | - * @param string $new_reg_status |
|
| 198 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 199 | - * to client code |
|
| 200 | - * @return bool |
|
| 201 | - * @throws EE_Error |
|
| 202 | - * @throws EntityNotFoundException |
|
| 203 | - * @throws InvalidArgumentException |
|
| 204 | - * @throws InvalidDataTypeException |
|
| 205 | - * @throws InvalidInterfaceException |
|
| 206 | - * @throws ReflectionException |
|
| 207 | - * @throws RuntimeException |
|
| 208 | - */ |
|
| 209 | - public function manually_update_registration_status( |
|
| 210 | - EE_Registration $registration, |
|
| 211 | - $new_reg_status = '', |
|
| 212 | - $save = true |
|
| 213 | - ) { |
|
| 214 | - // set initial REG_Status |
|
| 215 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
| 216 | - // set incoming REG_Status |
|
| 217 | - $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
| 218 | - // toggle reg status but only if it has changed and the user can do so |
|
| 219 | - if ( |
|
| 220 | - $this->reg_status_updated($registration->ID()) |
|
| 221 | - && ( |
|
| 222 | - (! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
| 223 | - || EE_Registry::instance()->CAP->current_user_can( |
|
| 224 | - 'ee_edit_registration', |
|
| 225 | - 'toggle_registration_status', |
|
| 226 | - $registration->ID() |
|
| 227 | - ) |
|
| 228 | - ) |
|
| 229 | - ) { |
|
| 230 | - // change status to new value |
|
| 231 | - $updated = $registration->set_status( |
|
| 232 | - $this->new_reg_status($registration->ID()), |
|
| 233 | - false, |
|
| 234 | - new Context( |
|
| 235 | - __METHOD__, |
|
| 236 | - esc_html__( |
|
| 237 | - 'Executed when the registration status is manually updated during the reg process.', |
|
| 238 | - 'event_espresso' |
|
| 239 | - ) |
|
| 240 | - ) |
|
| 241 | - ); |
|
| 242 | - if ($updated && $save) { |
|
| 243 | - $registration->save(); |
|
| 244 | - } |
|
| 245 | - return true; |
|
| 246 | - } |
|
| 247 | - return false; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * toggle_incomplete_registration_status_to_default |
|
| 253 | - * changes any incomplete registrations to either the event or global default registration status |
|
| 254 | - * |
|
| 255 | - * @access public |
|
| 256 | - * @param EE_Registration $registration |
|
| 257 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave |
|
| 258 | - * that up to client code |
|
| 259 | - * @param ContextInterface|null $context |
|
| 260 | - * @return void |
|
| 261 | - * @throws EE_Error |
|
| 262 | - * @throws InvalidArgumentException |
|
| 263 | - * @throws ReflectionException |
|
| 264 | - * @throws RuntimeException |
|
| 265 | - * @throws EntityNotFoundException |
|
| 266 | - * @throws InvalidDataTypeException |
|
| 267 | - * @throws InvalidInterfaceException |
|
| 268 | - */ |
|
| 269 | - public function toggle_incomplete_registration_status_to_default( |
|
| 270 | - EE_Registration $registration, |
|
| 271 | - $save = true, |
|
| 272 | - ?ContextInterface $context = null |
|
| 273 | - ) { |
|
| 274 | - $existing_reg_status = $registration->status_ID(); |
|
| 275 | - // set initial REG_Status |
|
| 276 | - $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
| 277 | - // is the registration currently incomplete ? |
|
| 278 | - if ($registration->status_ID() === RegStatus::INCOMPLETE) { |
|
| 279 | - // grab default reg status for the event, if set |
|
| 280 | - $event_default_registration_status = $registration->defaultRegistrationStatus(); |
|
| 281 | - // if no default reg status is set for the event, then use the global value |
|
| 282 | - $STS_ID = ! empty($event_default_registration_status) |
|
| 283 | - ? $event_default_registration_status |
|
| 284 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 285 | - // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
|
| 286 | - $STS_ID = $STS_ID === RegStatus::APPROVED |
|
| 287 | - ? RegStatus::PENDING_PAYMENT |
|
| 288 | - : $STS_ID; |
|
| 289 | - // set incoming REG_Status |
|
| 290 | - $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
| 291 | - $context = $context instanceof ContextInterface |
|
| 292 | - ? $context |
|
| 293 | - : new Context( |
|
| 294 | - __METHOD__, |
|
| 295 | - esc_html__( |
|
| 296 | - 'Executed when the registration status is updated to the default reg status during the registration process.', |
|
| 297 | - 'event_espresso' |
|
| 298 | - ) |
|
| 299 | - ); |
|
| 300 | - $registration->set_status($STS_ID, false, $context); |
|
| 301 | - if ($save) { |
|
| 302 | - $registration->save(); |
|
| 303 | - } |
|
| 304 | - // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
| 305 | - if (! EE_Processor_Base::$IPN) { |
|
| 306 | - // otherwise, send out notifications |
|
| 307 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
| 308 | - } |
|
| 309 | - // DEBUG LOG |
|
| 310 | - // $this->log( |
|
| 311 | - // __CLASS__, |
|
| 312 | - // __FUNCTION__, |
|
| 313 | - // __LINE__, |
|
| 314 | - // $registration->transaction(), |
|
| 315 | - // array( |
|
| 316 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
| 317 | - // 'deliver_notifications' => has_filter( |
|
| 318 | - // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
| 319 | - // ), |
|
| 320 | - // ) |
|
| 321 | - // ); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * toggle_registration_status_for_default_approved_events |
|
| 328 | - * |
|
| 329 | - * @access public |
|
| 330 | - * @param EE_Registration $registration |
|
| 331 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 332 | - * to client code |
|
| 333 | - * @return bool |
|
| 334 | - * @throws EE_Error |
|
| 335 | - * @throws EntityNotFoundException |
|
| 336 | - * @throws InvalidArgumentException |
|
| 337 | - * @throws InvalidDataTypeException |
|
| 338 | - * @throws InvalidInterfaceException |
|
| 339 | - * @throws ReflectionException |
|
| 340 | - * @throws RuntimeException |
|
| 341 | - */ |
|
| 342 | - public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true) |
|
| 343 | - { |
|
| 344 | - $reg_status = $registration->status_ID(); |
|
| 345 | - // set initial REG_Status |
|
| 346 | - $this->set_old_reg_status($registration->ID(), $reg_status); |
|
| 347 | - // if not already, toggle reg status to approved IF the event default reg status is approved |
|
| 348 | - // ( as long as the registration wasn't cancelled or declined at some point ) |
|
| 349 | - if ( |
|
| 350 | - $reg_status !== RegStatus::CANCELLED |
|
| 351 | - && $reg_status !== RegStatus::DECLINED |
|
| 352 | - && $reg_status !== RegStatus::APPROVED |
|
| 353 | - && $registration->defaultRegistrationStatus() === RegStatus::APPROVED |
|
| 354 | - ) { |
|
| 355 | - // set incoming REG_Status |
|
| 356 | - $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
|
| 357 | - // toggle status to approved |
|
| 358 | - $registration->set_status( |
|
| 359 | - RegStatus::APPROVED, |
|
| 360 | - false, |
|
| 361 | - new Context( |
|
| 362 | - __METHOD__, |
|
| 363 | - esc_html__( |
|
| 364 | - 'Executed when the registration status is updated for events with a default reg status of RegStatus::APPROVED.', |
|
| 365 | - 'event_espresso' |
|
| 366 | - ) |
|
| 367 | - ) |
|
| 368 | - ); |
|
| 369 | - if ($save) { |
|
| 370 | - $registration->save(); |
|
| 371 | - } |
|
| 372 | - // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
| 373 | - if (! EE_Processor_Base::$IPN) { |
|
| 374 | - // otherwise, send out notifications |
|
| 375 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
| 376 | - } |
|
| 377 | - // DEBUG LOG |
|
| 378 | - // $this->log( |
|
| 379 | - // __CLASS__, |
|
| 380 | - // __FUNCTION__, |
|
| 381 | - // __LINE__, |
|
| 382 | - // $registration->transaction(), |
|
| 383 | - // array( |
|
| 384 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
| 385 | - // 'deliver_notifications' => has_filter( |
|
| 386 | - // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
| 387 | - // ), |
|
| 388 | - // ) |
|
| 389 | - // ); |
|
| 390 | - return true; |
|
| 391 | - } |
|
| 392 | - return false; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * toggle_registration_statuses_if_no_monies_owing |
|
| 398 | - * |
|
| 399 | - * @access public |
|
| 400 | - * @param EE_Registration $registration |
|
| 401 | - * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 402 | - * to client code |
|
| 403 | - * @param array $additional_details |
|
| 404 | - * @return bool |
|
| 405 | - * @throws EE_Error |
|
| 406 | - * @throws EntityNotFoundException |
|
| 407 | - * @throws InvalidArgumentException |
|
| 408 | - * @throws InvalidDataTypeException |
|
| 409 | - * @throws InvalidInterfaceException |
|
| 410 | - * @throws ReflectionException |
|
| 411 | - * @throws RuntimeException |
|
| 412 | - */ |
|
| 413 | - public function toggle_registration_status_if_no_monies_owing( |
|
| 414 | - EE_Registration $registration, |
|
| 415 | - $save = true, |
|
| 416 | - array $additional_details = [] |
|
| 417 | - ) { |
|
| 418 | - // set initial REG_Status |
|
| 419 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
| 420 | - // was a payment just made ? |
|
| 421 | - $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
| 422 | - && $additional_details['payment_updates'] |
|
| 423 | - && $additional_details['last_payment'] instanceof EE_Payment |
|
| 424 | - ? $additional_details['last_payment'] |
|
| 425 | - : null; |
|
| 426 | - $total_paid = array_sum(self::$_amount_paid); |
|
| 427 | - // toggle reg status to approved IF |
|
| 428 | - if ( |
|
| 30 | + /** |
|
| 31 | + * @var EE_Registration_Processor $_instance |
|
| 32 | + * @access private |
|
| 33 | + */ |
|
| 34 | + private static $_instance; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * initial reg status at the beginning of this request. |
|
| 38 | + * indexed by registration ID |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + protected $_old_reg_status = []; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * reg status at the end of the request after all processing. |
|
| 46 | + * indexed by registration ID |
|
| 47 | + * |
|
| 48 | + * @var array |
|
| 49 | + */ |
|
| 50 | + protected $_new_reg_status = []; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * amounts paid at the end of the request after all processing. |
|
| 54 | + * indexed by registration ID |
|
| 55 | + * |
|
| 56 | + * @var array |
|
| 57 | + */ |
|
| 58 | + protected static $_amount_paid = []; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Cache of the reg final price for registrations corresponding to a ticket line item |
|
| 62 | + * |
|
| 63 | + * @deprecated |
|
| 64 | + * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value |
|
| 65 | + */ |
|
| 66 | + protected $_reg_final_price_per_tkt_line_item; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var RequestInterface $request |
|
| 70 | + */ |
|
| 71 | + protected $request; |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @singleton method used to instantiate class object |
|
| 76 | + * @param RequestInterface|null $request |
|
| 77 | + * @return EE_Registration_Processor instance |
|
| 78 | + * @throws InvalidArgumentException |
|
| 79 | + * @throws InvalidInterfaceException |
|
| 80 | + * @throws InvalidDataTypeException |
|
| 81 | + */ |
|
| 82 | + public static function instance(RequestInterface $request = null) |
|
| 83 | + { |
|
| 84 | + // check if class object is instantiated |
|
| 85 | + if (! self::$_instance instanceof EE_Registration_Processor) { |
|
| 86 | + if (! $request instanceof RequestInterface) { |
|
| 87 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
| 88 | + } |
|
| 89 | + self::$_instance = new self($request); |
|
| 90 | + } |
|
| 91 | + return self::$_instance; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * EE_Registration_Processor constructor. |
|
| 97 | + * |
|
| 98 | + * @param RequestInterface $request |
|
| 99 | + */ |
|
| 100 | + public function __construct(RequestInterface $request) |
|
| 101 | + { |
|
| 102 | + $this->request = $request; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @param int $REG_ID |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public function old_reg_status($REG_ID) |
|
| 111 | + { |
|
| 112 | + return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param int $REG_ID |
|
| 118 | + * @param string $old_reg_status |
|
| 119 | + */ |
|
| 120 | + public function set_old_reg_status($REG_ID, $old_reg_status) |
|
| 121 | + { |
|
| 122 | + // only set the first time |
|
| 123 | + if (! isset($this->_old_reg_status[ $REG_ID ])) { |
|
| 124 | + $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @param int $REG_ID |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | + public function new_reg_status($REG_ID) |
|
| 134 | + { |
|
| 135 | + return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param int $REG_ID |
|
| 141 | + * @param string $new_reg_status |
|
| 142 | + */ |
|
| 143 | + public function set_new_reg_status($REG_ID, $new_reg_status) |
|
| 144 | + { |
|
| 145 | + $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * reg_status_updated |
|
| 151 | + * |
|
| 152 | + * @param int $REG_ID |
|
| 153 | + * @return bool |
|
| 154 | + */ |
|
| 155 | + public function reg_status_updated($REG_ID) |
|
| 156 | + { |
|
| 157 | + return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @param EE_Registration $registration |
|
| 163 | + * @throws EE_Error |
|
| 164 | + * @throws EntityNotFoundException |
|
| 165 | + * @throws InvalidArgumentException |
|
| 166 | + * @throws InvalidDataTypeException |
|
| 167 | + * @throws InvalidInterfaceException |
|
| 168 | + * @throws ReflectionException |
|
| 169 | + * @throws RuntimeException |
|
| 170 | + */ |
|
| 171 | + public function update_registration_status_and_trigger_notifications(EE_Registration $registration) |
|
| 172 | + { |
|
| 173 | + $this->toggle_incomplete_registration_status_to_default( |
|
| 174 | + $registration, |
|
| 175 | + false, |
|
| 176 | + new Context( |
|
| 177 | + __METHOD__, |
|
| 178 | + esc_html__( |
|
| 179 | + 'Executed when the registration status is updated during the registration process just prior to triggering notifications.', |
|
| 180 | + 'event_espresso' |
|
| 181 | + ) |
|
| 182 | + ) |
|
| 183 | + ); |
|
| 184 | + $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
| 185 | + $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
| 186 | + $registration->save(); |
|
| 187 | + // trigger notifications |
|
| 188 | + $this->trigger_registration_update_notifications($registration); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * manually_update_registration_status |
|
| 194 | + * |
|
| 195 | + * @access public |
|
| 196 | + * @param EE_Registration $registration |
|
| 197 | + * @param string $new_reg_status |
|
| 198 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 199 | + * to client code |
|
| 200 | + * @return bool |
|
| 201 | + * @throws EE_Error |
|
| 202 | + * @throws EntityNotFoundException |
|
| 203 | + * @throws InvalidArgumentException |
|
| 204 | + * @throws InvalidDataTypeException |
|
| 205 | + * @throws InvalidInterfaceException |
|
| 206 | + * @throws ReflectionException |
|
| 207 | + * @throws RuntimeException |
|
| 208 | + */ |
|
| 209 | + public function manually_update_registration_status( |
|
| 210 | + EE_Registration $registration, |
|
| 211 | + $new_reg_status = '', |
|
| 212 | + $save = true |
|
| 213 | + ) { |
|
| 214 | + // set initial REG_Status |
|
| 215 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
| 216 | + // set incoming REG_Status |
|
| 217 | + $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
| 218 | + // toggle reg status but only if it has changed and the user can do so |
|
| 219 | + if ( |
|
| 220 | + $this->reg_status_updated($registration->ID()) |
|
| 221 | + && ( |
|
| 222 | + (! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
| 223 | + || EE_Registry::instance()->CAP->current_user_can( |
|
| 224 | + 'ee_edit_registration', |
|
| 225 | + 'toggle_registration_status', |
|
| 226 | + $registration->ID() |
|
| 227 | + ) |
|
| 228 | + ) |
|
| 229 | + ) { |
|
| 230 | + // change status to new value |
|
| 231 | + $updated = $registration->set_status( |
|
| 232 | + $this->new_reg_status($registration->ID()), |
|
| 233 | + false, |
|
| 234 | + new Context( |
|
| 235 | + __METHOD__, |
|
| 236 | + esc_html__( |
|
| 237 | + 'Executed when the registration status is manually updated during the reg process.', |
|
| 238 | + 'event_espresso' |
|
| 239 | + ) |
|
| 240 | + ) |
|
| 241 | + ); |
|
| 242 | + if ($updated && $save) { |
|
| 243 | + $registration->save(); |
|
| 244 | + } |
|
| 245 | + return true; |
|
| 246 | + } |
|
| 247 | + return false; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * toggle_incomplete_registration_status_to_default |
|
| 253 | + * changes any incomplete registrations to either the event or global default registration status |
|
| 254 | + * |
|
| 255 | + * @access public |
|
| 256 | + * @param EE_Registration $registration |
|
| 257 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave |
|
| 258 | + * that up to client code |
|
| 259 | + * @param ContextInterface|null $context |
|
| 260 | + * @return void |
|
| 261 | + * @throws EE_Error |
|
| 262 | + * @throws InvalidArgumentException |
|
| 263 | + * @throws ReflectionException |
|
| 264 | + * @throws RuntimeException |
|
| 265 | + * @throws EntityNotFoundException |
|
| 266 | + * @throws InvalidDataTypeException |
|
| 267 | + * @throws InvalidInterfaceException |
|
| 268 | + */ |
|
| 269 | + public function toggle_incomplete_registration_status_to_default( |
|
| 270 | + EE_Registration $registration, |
|
| 271 | + $save = true, |
|
| 272 | + ?ContextInterface $context = null |
|
| 273 | + ) { |
|
| 274 | + $existing_reg_status = $registration->status_ID(); |
|
| 275 | + // set initial REG_Status |
|
| 276 | + $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
| 277 | + // is the registration currently incomplete ? |
|
| 278 | + if ($registration->status_ID() === RegStatus::INCOMPLETE) { |
|
| 279 | + // grab default reg status for the event, if set |
|
| 280 | + $event_default_registration_status = $registration->defaultRegistrationStatus(); |
|
| 281 | + // if no default reg status is set for the event, then use the global value |
|
| 282 | + $STS_ID = ! empty($event_default_registration_status) |
|
| 283 | + ? $event_default_registration_status |
|
| 284 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 285 | + // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
|
| 286 | + $STS_ID = $STS_ID === RegStatus::APPROVED |
|
| 287 | + ? RegStatus::PENDING_PAYMENT |
|
| 288 | + : $STS_ID; |
|
| 289 | + // set incoming REG_Status |
|
| 290 | + $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
| 291 | + $context = $context instanceof ContextInterface |
|
| 292 | + ? $context |
|
| 293 | + : new Context( |
|
| 294 | + __METHOD__, |
|
| 295 | + esc_html__( |
|
| 296 | + 'Executed when the registration status is updated to the default reg status during the registration process.', |
|
| 297 | + 'event_espresso' |
|
| 298 | + ) |
|
| 299 | + ); |
|
| 300 | + $registration->set_status($STS_ID, false, $context); |
|
| 301 | + if ($save) { |
|
| 302 | + $registration->save(); |
|
| 303 | + } |
|
| 304 | + // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
| 305 | + if (! EE_Processor_Base::$IPN) { |
|
| 306 | + // otherwise, send out notifications |
|
| 307 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
| 308 | + } |
|
| 309 | + // DEBUG LOG |
|
| 310 | + // $this->log( |
|
| 311 | + // __CLASS__, |
|
| 312 | + // __FUNCTION__, |
|
| 313 | + // __LINE__, |
|
| 314 | + // $registration->transaction(), |
|
| 315 | + // array( |
|
| 316 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
| 317 | + // 'deliver_notifications' => has_filter( |
|
| 318 | + // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
| 319 | + // ), |
|
| 320 | + // ) |
|
| 321 | + // ); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * toggle_registration_status_for_default_approved_events |
|
| 328 | + * |
|
| 329 | + * @access public |
|
| 330 | + * @param EE_Registration $registration |
|
| 331 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 332 | + * to client code |
|
| 333 | + * @return bool |
|
| 334 | + * @throws EE_Error |
|
| 335 | + * @throws EntityNotFoundException |
|
| 336 | + * @throws InvalidArgumentException |
|
| 337 | + * @throws InvalidDataTypeException |
|
| 338 | + * @throws InvalidInterfaceException |
|
| 339 | + * @throws ReflectionException |
|
| 340 | + * @throws RuntimeException |
|
| 341 | + */ |
|
| 342 | + public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true) |
|
| 343 | + { |
|
| 344 | + $reg_status = $registration->status_ID(); |
|
| 345 | + // set initial REG_Status |
|
| 346 | + $this->set_old_reg_status($registration->ID(), $reg_status); |
|
| 347 | + // if not already, toggle reg status to approved IF the event default reg status is approved |
|
| 348 | + // ( as long as the registration wasn't cancelled or declined at some point ) |
|
| 349 | + if ( |
|
| 350 | + $reg_status !== RegStatus::CANCELLED |
|
| 351 | + && $reg_status !== RegStatus::DECLINED |
|
| 352 | + && $reg_status !== RegStatus::APPROVED |
|
| 353 | + && $registration->defaultRegistrationStatus() === RegStatus::APPROVED |
|
| 354 | + ) { |
|
| 355 | + // set incoming REG_Status |
|
| 356 | + $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
|
| 357 | + // toggle status to approved |
|
| 358 | + $registration->set_status( |
|
| 359 | + RegStatus::APPROVED, |
|
| 360 | + false, |
|
| 361 | + new Context( |
|
| 362 | + __METHOD__, |
|
| 363 | + esc_html__( |
|
| 364 | + 'Executed when the registration status is updated for events with a default reg status of RegStatus::APPROVED.', |
|
| 365 | + 'event_espresso' |
|
| 366 | + ) |
|
| 367 | + ) |
|
| 368 | + ); |
|
| 369 | + if ($save) { |
|
| 370 | + $registration->save(); |
|
| 371 | + } |
|
| 372 | + // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
| 373 | + if (! EE_Processor_Base::$IPN) { |
|
| 374 | + // otherwise, send out notifications |
|
| 375 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
| 376 | + } |
|
| 377 | + // DEBUG LOG |
|
| 378 | + // $this->log( |
|
| 379 | + // __CLASS__, |
|
| 380 | + // __FUNCTION__, |
|
| 381 | + // __LINE__, |
|
| 382 | + // $registration->transaction(), |
|
| 383 | + // array( |
|
| 384 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
| 385 | + // 'deliver_notifications' => has_filter( |
|
| 386 | + // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
| 387 | + // ), |
|
| 388 | + // ) |
|
| 389 | + // ); |
|
| 390 | + return true; |
|
| 391 | + } |
|
| 392 | + return false; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * toggle_registration_statuses_if_no_monies_owing |
|
| 398 | + * |
|
| 399 | + * @access public |
|
| 400 | + * @param EE_Registration $registration |
|
| 401 | + * @param bool $save TRUE will save the registration if the status is updated, FALSE will leave that up |
|
| 402 | + * to client code |
|
| 403 | + * @param array $additional_details |
|
| 404 | + * @return bool |
|
| 405 | + * @throws EE_Error |
|
| 406 | + * @throws EntityNotFoundException |
|
| 407 | + * @throws InvalidArgumentException |
|
| 408 | + * @throws InvalidDataTypeException |
|
| 409 | + * @throws InvalidInterfaceException |
|
| 410 | + * @throws ReflectionException |
|
| 411 | + * @throws RuntimeException |
|
| 412 | + */ |
|
| 413 | + public function toggle_registration_status_if_no_monies_owing( |
|
| 414 | + EE_Registration $registration, |
|
| 415 | + $save = true, |
|
| 416 | + array $additional_details = [] |
|
| 417 | + ) { |
|
| 418 | + // set initial REG_Status |
|
| 419 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
| 420 | + // was a payment just made ? |
|
| 421 | + $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
| 422 | + && $additional_details['payment_updates'] |
|
| 423 | + && $additional_details['last_payment'] instanceof EE_Payment |
|
| 424 | + ? $additional_details['last_payment'] |
|
| 425 | + : null; |
|
| 426 | + $total_paid = array_sum(self::$_amount_paid); |
|
| 427 | + // toggle reg status to approved IF |
|
| 428 | + if ( |
|
| 429 | 429 | // REG status is pending payment |
| 430 | - $registration->status_ID() === RegStatus::PENDING_PAYMENT |
|
| 431 | - // AND no monies are owing |
|
| 432 | - && ( |
|
| 433 | - ( |
|
| 434 | - $registration->transaction()->is_completed() |
|
| 435 | - || $registration->transaction()->is_overpaid() |
|
| 436 | - || $registration->transaction()->is_free() |
|
| 437 | - || apply_filters( |
|
| 438 | - 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', |
|
| 439 | - false, |
|
| 440 | - $registration |
|
| 441 | - ) |
|
| 442 | - ) |
|
| 443 | - || ( |
|
| 444 | - $payment instanceof EE_Payment && $payment->is_approved() |
|
| 445 | - && // this specific registration has not yet been paid for |
|
| 446 | - ! isset(self::$_amount_paid[ $registration->ID() ]) |
|
| 447 | - && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
|
| 448 | - $payment->amount() - $total_paid >= $registration->final_price() |
|
| 449 | - ) |
|
| 450 | - ) |
|
| 451 | - ) { |
|
| 452 | - // mark as paid |
|
| 453 | - self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
| 454 | - // track new REG_Status |
|
| 455 | - $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
|
| 456 | - // toggle status to approved |
|
| 457 | - $registration->set_status( |
|
| 458 | - RegStatus::APPROVED, |
|
| 459 | - false, |
|
| 460 | - new Context( |
|
| 461 | - __METHOD__, |
|
| 462 | - esc_html__( |
|
| 463 | - 'Executed when the registration status is updated to RegStatus::APPROVED when no monies are owing.', |
|
| 464 | - 'event_espresso' |
|
| 465 | - ) |
|
| 466 | - ) |
|
| 467 | - ); |
|
| 468 | - if ($save) { |
|
| 469 | - $registration->save(); |
|
| 470 | - } |
|
| 471 | - // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
| 472 | - if (! EE_Processor_Base::$IPN) { |
|
| 473 | - // otherwise, send out notifications |
|
| 474 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
| 475 | - } |
|
| 476 | - // DEBUG LOG |
|
| 477 | - // $this->log( |
|
| 478 | - // __CLASS__, |
|
| 479 | - // __FUNCTION__, |
|
| 480 | - // __LINE__, |
|
| 481 | - // $registration->transaction(), |
|
| 482 | - // array( |
|
| 483 | - // 'IPN' => EE_Processor_Base::$IPN, |
|
| 484 | - // 'deliver_notifications' => has_filter( |
|
| 485 | - // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
| 486 | - // ), |
|
| 487 | - // ) |
|
| 488 | - // ); |
|
| 489 | - return true; |
|
| 490 | - } |
|
| 491 | - return false; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * registration_status_changed |
|
| 497 | - * |
|
| 498 | - * @access public |
|
| 499 | - * @param EE_Registration $registration |
|
| 500 | - * @param array $additional_details |
|
| 501 | - * @return void |
|
| 502 | - */ |
|
| 503 | - public function trigger_registration_update_notifications($registration, array $additional_details = []) |
|
| 504 | - { |
|
| 505 | - try { |
|
| 506 | - if (! $registration instanceof EE_Registration) { |
|
| 507 | - throw new EE_Error( |
|
| 508 | - esc_html__('An invalid registration was received.', 'event_espresso') |
|
| 509 | - ); |
|
| 510 | - } |
|
| 511 | - // EE_Registry::instance()->load_helper('Debug_Tools'); |
|
| 512 | - // EEH_Debug_Tools::log( |
|
| 513 | - // __CLASS__, |
|
| 514 | - // __FUNCTION__, |
|
| 515 | - // __LINE__, |
|
| 516 | - // array($registration->transaction(), $additional_details), |
|
| 517 | - // false, |
|
| 518 | - // 'EE_Transaction: ' . $registration->transaction()->ID() |
|
| 519 | - // ); |
|
| 520 | - if ( |
|
| 521 | - ! $this->request->getRequestParam('non_primary_reg_notification', 0, 'int') |
|
| 522 | - && ! $registration->is_primary_registrant() |
|
| 523 | - ) { |
|
| 524 | - return; |
|
| 525 | - } |
|
| 526 | - do_action( |
|
| 527 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 528 | - $registration, |
|
| 529 | - $additional_details |
|
| 530 | - ); |
|
| 531 | - } catch (Exception $e) { |
|
| 532 | - EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * sets reg status based either on passed param or on transaction status and event pre-approval setting |
|
| 539 | - * |
|
| 540 | - * @param EE_Registration $registration |
|
| 541 | - * @param array $additional_details |
|
| 542 | - * @return bool |
|
| 543 | - * @throws EE_Error |
|
| 544 | - * @throws EntityNotFoundException |
|
| 545 | - * @throws InvalidArgumentException |
|
| 546 | - * @throws InvalidDataTypeException |
|
| 547 | - * @throws InvalidInterfaceException |
|
| 548 | - * @throws ReflectionException |
|
| 549 | - * @throws RuntimeException |
|
| 550 | - */ |
|
| 551 | - public function update_registration_after_checkout_or_payment( |
|
| 552 | - EE_Registration $registration, |
|
| 553 | - array $additional_details = [] |
|
| 554 | - ) { |
|
| 555 | - // set initial REG_Status |
|
| 556 | - $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
| 557 | - // if the registration status gets updated, then save the registration |
|
| 558 | - if ( |
|
| 559 | - $this->toggle_registration_status_for_default_approved_events($registration, false) |
|
| 560 | - || $this->toggle_registration_status_if_no_monies_owing( |
|
| 561 | - $registration, |
|
| 562 | - false, |
|
| 563 | - $additional_details |
|
| 564 | - ) |
|
| 565 | - ) { |
|
| 566 | - $registration->save(); |
|
| 567 | - } |
|
| 568 | - // set new REG_Status |
|
| 569 | - $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
| 570 | - return $this->reg_status_updated($registration->ID()) |
|
| 571 | - && $this->new_reg_status($registration->ID()) === RegStatus::APPROVED; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Updates the registration' final prices based on the current line item tree (taking into account |
|
| 577 | - * discounts, taxes, and other line items unrelated to tickets.) |
|
| 578 | - * |
|
| 579 | - * @param EE_Transaction $transaction |
|
| 580 | - * @param boolean $save_regs whether to immediately save registrations in this function or not |
|
| 581 | - * @return void |
|
| 582 | - * @throws EE_Error |
|
| 583 | - * @throws InvalidArgumentException |
|
| 584 | - * @throws InvalidDataTypeException |
|
| 585 | - * @throws InvalidInterfaceException |
|
| 586 | - * @throws RuntimeException |
|
| 587 | - * @throws ReflectionException |
|
| 588 | - */ |
|
| 589 | - public function update_registration_final_prices($transaction, $save_regs = true) |
|
| 590 | - { |
|
| 591 | - $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
| 592 | - $transaction->total_line_item() |
|
| 593 | - ); |
|
| 594 | - foreach ($transaction->registrations() as $registration) { |
|
| 595 | - /** @var EE_Line_Item $line_item */ |
|
| 596 | - $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
| 597 | - if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) { |
|
| 598 | - $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]); |
|
| 599 | - if ($save_regs) { |
|
| 600 | - $registration->save(); |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - // and make sure there's no rounding problem |
|
| 605 | - $this->fix_reg_final_price_rounding_issue($transaction); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * Makes sure there is no rounding errors for the REG_final_prices. |
|
| 611 | - * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them, |
|
| 612 | - * they will each be for $0.99333333, which gets rounded to $1 again. |
|
| 613 | - * So the transaction total will be $2.99, but each registration will be for $1, |
|
| 614 | - * so if each registrant paid individually they will have overpaid by $0.01. |
|
| 615 | - * So in order to overcome this, we check for any difference, and if there is a difference |
|
| 616 | - * we just grab one registrant at random and make them responsible for it. |
|
| 617 | - * This should be used after setting REG_final_prices (it's done automatically as part of |
|
| 618 | - * EE_Registration_Processor::update_registration_final_prices()) |
|
| 619 | - * |
|
| 620 | - * @param EE_Transaction $transaction |
|
| 621 | - * @return bool success verifying that there is NO difference after this method is done |
|
| 622 | - * @throws EE_Error |
|
| 623 | - * @throws InvalidArgumentException |
|
| 624 | - * @throws InvalidDataTypeException |
|
| 625 | - * @throws InvalidInterfaceException |
|
| 626 | - * @throws ReflectionException |
|
| 627 | - */ |
|
| 628 | - public function fix_reg_final_price_rounding_issue($transaction) |
|
| 629 | - { |
|
| 630 | - $reg_final_price_sum = EEM_Registration::instance()->sum( |
|
| 631 | - [ |
|
| 632 | - [ |
|
| 633 | - 'TXN_ID' => $transaction->ID(), |
|
| 634 | - ], |
|
| 635 | - ], |
|
| 636 | - 'REG_final_price' |
|
| 637 | - ); |
|
| 638 | - $diff = $transaction->total() - $reg_final_price_sum; |
|
| 639 | - // ok then, just grab one of the registrations |
|
| 640 | - if ($diff !== 0.0) { |
|
| 641 | - $a_reg = EEM_Registration::instance()->get_one( |
|
| 642 | - [ |
|
| 643 | - [ |
|
| 644 | - 'TXN_ID' => $transaction->ID(), |
|
| 645 | - ], |
|
| 646 | - ] |
|
| 647 | - ); |
|
| 648 | - return $a_reg instanceof EE_Registration |
|
| 649 | - && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]); |
|
| 650 | - } |
|
| 651 | - return true; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - /** |
|
| 656 | - * update_registration_after_being_canceled_or_declined |
|
| 657 | - * |
|
| 658 | - * @param EE_Registration $registration |
|
| 659 | - * @param array $closed_reg_statuses |
|
| 660 | - * @param bool $update_reg |
|
| 661 | - * @return bool |
|
| 662 | - * @throws EE_Error |
|
| 663 | - * @throws RuntimeException |
|
| 664 | - * @throws ReflectionException |
|
| 665 | - */ |
|
| 666 | - public function update_registration_after_being_canceled_or_declined( |
|
| 667 | - EE_Registration $registration, |
|
| 668 | - array $closed_reg_statuses = [], |
|
| 669 | - $update_reg = true |
|
| 670 | - ) { |
|
| 671 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
| 672 | - $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
| 673 | - ? $closed_reg_statuses |
|
| 674 | - : EEM_Registration::closed_reg_statuses(); |
|
| 675 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
| 676 | - return false; |
|
| 677 | - } |
|
| 678 | - // release a reserved ticket by decrementing ticket and datetime reserved values |
|
| 679 | - $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__); |
|
| 680 | - $registration->set_final_price(0); |
|
| 681 | - if ($update_reg) { |
|
| 682 | - $registration->save(); |
|
| 683 | - } |
|
| 684 | - return true; |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * update_canceled_or_declined_registration_after_being_reinstated |
|
| 690 | - * |
|
| 691 | - * @param EE_Registration $registration |
|
| 692 | - * @param array $closed_reg_statuses |
|
| 693 | - * @param bool $update_reg |
|
| 694 | - * @return bool |
|
| 695 | - * @throws EE_Error |
|
| 696 | - * @throws RuntimeException |
|
| 697 | - * @throws ReflectionException |
|
| 698 | - */ |
|
| 699 | - public function update_canceled_or_declined_registration_after_being_reinstated( |
|
| 700 | - EE_Registration $registration, |
|
| 701 | - array $closed_reg_statuses = [], |
|
| 702 | - $update_reg = true |
|
| 703 | - ) { |
|
| 704 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
| 705 | - $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
| 706 | - : EEM_Registration::closed_reg_statuses(); |
|
| 707 | - if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
| 708 | - return false; |
|
| 709 | - } |
|
| 710 | - $ticket = $registration->ticket(); |
|
| 711 | - if (! $ticket instanceof EE_Ticket) { |
|
| 712 | - throw new EE_Error( |
|
| 713 | - sprintf( |
|
| 714 | - esc_html__( |
|
| 715 | - 'The Ticket for Registration %1$d was not found or is invalid.', |
|
| 716 | - 'event_espresso' |
|
| 717 | - ), |
|
| 718 | - $registration->ticket_ID() |
|
| 719 | - ) |
|
| 720 | - ); |
|
| 721 | - } |
|
| 722 | - $registration->set_final_price($ticket->price()); |
|
| 723 | - if ($update_reg) { |
|
| 724 | - $registration->save(); |
|
| 725 | - } |
|
| 726 | - return true; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * generate_ONE_registration_from_line_item |
|
| 732 | - * Although a ticket line item may have a quantity greater than 1, |
|
| 733 | - * this method will ONLY CREATE ONE REGISTRATION !!! |
|
| 734 | - * Regardless of the ticket line item quantity. |
|
| 735 | - * This means that any code calling this method is responsible for ensuring |
|
| 736 | - * that the final registration count matches the ticket line item quantity. |
|
| 737 | - * This was done to make it easier to match the number of registrations |
|
| 738 | - * to the number of tickets in the cart, when the cart has been edited |
|
| 739 | - * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass |
|
| 740 | - * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets. |
|
| 741 | - * |
|
| 742 | - * @param EE_Line_Item $line_item |
|
| 743 | - * @param EE_Transaction $transaction |
|
| 744 | - * @param int $att_nmbr |
|
| 745 | - * @param int $total_ticket_count |
|
| 746 | - * @return EE_Registration | null |
|
| 747 | - * @throws OutOfRangeException |
|
| 748 | - * @throws UnexpectedEntityException |
|
| 749 | - * @throws EE_Error |
|
| 750 | - * @throws ReflectionException |
|
| 751 | - * @deprecated |
|
| 752 | - * @since 4.9.1 |
|
| 753 | - */ |
|
| 754 | - public function generate_ONE_registration_from_line_item( |
|
| 755 | - EE_Line_Item $line_item, |
|
| 756 | - EE_Transaction $transaction, |
|
| 757 | - $att_nmbr = 1, |
|
| 758 | - $total_ticket_count = 1 |
|
| 759 | - ) { |
|
| 760 | - EE_Error::doing_it_wrong( |
|
| 761 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 762 | - sprintf( |
|
| 763 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 764 | - '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
|
| 765 | - ), |
|
| 766 | - '4.9.1', |
|
| 767 | - '5.0.0' |
|
| 768 | - ); |
|
| 769 | - // grab the related ticket object for this line_item |
|
| 770 | - $ticket = $line_item->ticket(); |
|
| 771 | - if (! $ticket instanceof EE_Ticket) { |
|
| 772 | - EE_Error::add_error( |
|
| 773 | - sprintf( |
|
| 774 | - esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
| 775 | - $line_item->ID() |
|
| 776 | - ), |
|
| 777 | - __FILE__, |
|
| 778 | - __FUNCTION__, |
|
| 779 | - __LINE__ |
|
| 780 | - ); |
|
| 781 | - return null; |
|
| 782 | - } |
|
| 783 | - $registration_service = new CreateRegistrationService(); |
|
| 784 | - // then generate a new registration from that |
|
| 785 | - return $registration_service->create( |
|
| 786 | - $ticket->get_related_event(), |
|
| 787 | - $transaction, |
|
| 788 | - $ticket, |
|
| 789 | - $line_item, |
|
| 790 | - $att_nmbr, |
|
| 791 | - $total_ticket_count |
|
| 792 | - ); |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * generates reg_url_link |
|
| 798 | - * |
|
| 799 | - * @param int $att_nmbr |
|
| 800 | - * @param EE_Line_Item | string $item |
|
| 801 | - * @return RegUrlLink |
|
| 802 | - * @throws InvalidArgumentException |
|
| 803 | - * @deprecated |
|
| 804 | - * @since 4.9.1 |
|
| 805 | - */ |
|
| 806 | - public function generate_reg_url_link($att_nmbr, $item) |
|
| 807 | - { |
|
| 808 | - EE_Error::doing_it_wrong( |
|
| 809 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 810 | - sprintf( |
|
| 811 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 812 | - 'EventEspresso\core\domain\entities\RegUrlLink' |
|
| 813 | - ), |
|
| 814 | - '4.9.1', |
|
| 815 | - '5.0.0' |
|
| 816 | - ); |
|
| 817 | - return new RegUrlLink($att_nmbr, $item); |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * generates reg code |
|
| 823 | - * |
|
| 824 | - * @param EE_Registration $registration |
|
| 825 | - * @return RegCode |
|
| 826 | - * @throws EE_Error |
|
| 827 | - * @throws EntityNotFoundException |
|
| 828 | - * @throws InvalidArgumentException |
|
| 829 | - * @since 4.9.1 |
|
| 830 | - * @deprecated |
|
| 831 | - */ |
|
| 832 | - public function generate_reg_code(EE_Registration $registration) |
|
| 833 | - { |
|
| 834 | - EE_Error::doing_it_wrong( |
|
| 835 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 836 | - sprintf( |
|
| 837 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 838 | - 'EventEspresso\core\domain\entities\RegCode' |
|
| 839 | - ), |
|
| 840 | - '4.9.1', |
|
| 841 | - '5.0.0' |
|
| 842 | - ); |
|
| 843 | - return apply_filters( |
|
| 844 | - 'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code', |
|
| 845 | - new RegCode( |
|
| 846 | - RegUrlLink::fromRegistration($registration), |
|
| 847 | - $registration->transaction(), |
|
| 848 | - $registration->ticket() |
|
| 849 | - ), |
|
| 850 | - $registration |
|
| 851 | - ); |
|
| 852 | - } |
|
| 430 | + $registration->status_ID() === RegStatus::PENDING_PAYMENT |
|
| 431 | + // AND no monies are owing |
|
| 432 | + && ( |
|
| 433 | + ( |
|
| 434 | + $registration->transaction()->is_completed() |
|
| 435 | + || $registration->transaction()->is_overpaid() |
|
| 436 | + || $registration->transaction()->is_free() |
|
| 437 | + || apply_filters( |
|
| 438 | + 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', |
|
| 439 | + false, |
|
| 440 | + $registration |
|
| 441 | + ) |
|
| 442 | + ) |
|
| 443 | + || ( |
|
| 444 | + $payment instanceof EE_Payment && $payment->is_approved() |
|
| 445 | + && // this specific registration has not yet been paid for |
|
| 446 | + ! isset(self::$_amount_paid[ $registration->ID() ]) |
|
| 447 | + && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
|
| 448 | + $payment->amount() - $total_paid >= $registration->final_price() |
|
| 449 | + ) |
|
| 450 | + ) |
|
| 451 | + ) { |
|
| 452 | + // mark as paid |
|
| 453 | + self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
| 454 | + // track new REG_Status |
|
| 455 | + $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
|
| 456 | + // toggle status to approved |
|
| 457 | + $registration->set_status( |
|
| 458 | + RegStatus::APPROVED, |
|
| 459 | + false, |
|
| 460 | + new Context( |
|
| 461 | + __METHOD__, |
|
| 462 | + esc_html__( |
|
| 463 | + 'Executed when the registration status is updated to RegStatus::APPROVED when no monies are owing.', |
|
| 464 | + 'event_espresso' |
|
| 465 | + ) |
|
| 466 | + ) |
|
| 467 | + ); |
|
| 468 | + if ($save) { |
|
| 469 | + $registration->save(); |
|
| 470 | + } |
|
| 471 | + // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
|
| 472 | + if (! EE_Processor_Base::$IPN) { |
|
| 473 | + // otherwise, send out notifications |
|
| 474 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
| 475 | + } |
|
| 476 | + // DEBUG LOG |
|
| 477 | + // $this->log( |
|
| 478 | + // __CLASS__, |
|
| 479 | + // __FUNCTION__, |
|
| 480 | + // __LINE__, |
|
| 481 | + // $registration->transaction(), |
|
| 482 | + // array( |
|
| 483 | + // 'IPN' => EE_Processor_Base::$IPN, |
|
| 484 | + // 'deliver_notifications' => has_filter( |
|
| 485 | + // 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
| 486 | + // ), |
|
| 487 | + // ) |
|
| 488 | + // ); |
|
| 489 | + return true; |
|
| 490 | + } |
|
| 491 | + return false; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * registration_status_changed |
|
| 497 | + * |
|
| 498 | + * @access public |
|
| 499 | + * @param EE_Registration $registration |
|
| 500 | + * @param array $additional_details |
|
| 501 | + * @return void |
|
| 502 | + */ |
|
| 503 | + public function trigger_registration_update_notifications($registration, array $additional_details = []) |
|
| 504 | + { |
|
| 505 | + try { |
|
| 506 | + if (! $registration instanceof EE_Registration) { |
|
| 507 | + throw new EE_Error( |
|
| 508 | + esc_html__('An invalid registration was received.', 'event_espresso') |
|
| 509 | + ); |
|
| 510 | + } |
|
| 511 | + // EE_Registry::instance()->load_helper('Debug_Tools'); |
|
| 512 | + // EEH_Debug_Tools::log( |
|
| 513 | + // __CLASS__, |
|
| 514 | + // __FUNCTION__, |
|
| 515 | + // __LINE__, |
|
| 516 | + // array($registration->transaction(), $additional_details), |
|
| 517 | + // false, |
|
| 518 | + // 'EE_Transaction: ' . $registration->transaction()->ID() |
|
| 519 | + // ); |
|
| 520 | + if ( |
|
| 521 | + ! $this->request->getRequestParam('non_primary_reg_notification', 0, 'int') |
|
| 522 | + && ! $registration->is_primary_registrant() |
|
| 523 | + ) { |
|
| 524 | + return; |
|
| 525 | + } |
|
| 526 | + do_action( |
|
| 527 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 528 | + $registration, |
|
| 529 | + $additional_details |
|
| 530 | + ); |
|
| 531 | + } catch (Exception $e) { |
|
| 532 | + EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * sets reg status based either on passed param or on transaction status and event pre-approval setting |
|
| 539 | + * |
|
| 540 | + * @param EE_Registration $registration |
|
| 541 | + * @param array $additional_details |
|
| 542 | + * @return bool |
|
| 543 | + * @throws EE_Error |
|
| 544 | + * @throws EntityNotFoundException |
|
| 545 | + * @throws InvalidArgumentException |
|
| 546 | + * @throws InvalidDataTypeException |
|
| 547 | + * @throws InvalidInterfaceException |
|
| 548 | + * @throws ReflectionException |
|
| 549 | + * @throws RuntimeException |
|
| 550 | + */ |
|
| 551 | + public function update_registration_after_checkout_or_payment( |
|
| 552 | + EE_Registration $registration, |
|
| 553 | + array $additional_details = [] |
|
| 554 | + ) { |
|
| 555 | + // set initial REG_Status |
|
| 556 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
| 557 | + // if the registration status gets updated, then save the registration |
|
| 558 | + if ( |
|
| 559 | + $this->toggle_registration_status_for_default_approved_events($registration, false) |
|
| 560 | + || $this->toggle_registration_status_if_no_monies_owing( |
|
| 561 | + $registration, |
|
| 562 | + false, |
|
| 563 | + $additional_details |
|
| 564 | + ) |
|
| 565 | + ) { |
|
| 566 | + $registration->save(); |
|
| 567 | + } |
|
| 568 | + // set new REG_Status |
|
| 569 | + $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
| 570 | + return $this->reg_status_updated($registration->ID()) |
|
| 571 | + && $this->new_reg_status($registration->ID()) === RegStatus::APPROVED; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Updates the registration' final prices based on the current line item tree (taking into account |
|
| 577 | + * discounts, taxes, and other line items unrelated to tickets.) |
|
| 578 | + * |
|
| 579 | + * @param EE_Transaction $transaction |
|
| 580 | + * @param boolean $save_regs whether to immediately save registrations in this function or not |
|
| 581 | + * @return void |
|
| 582 | + * @throws EE_Error |
|
| 583 | + * @throws InvalidArgumentException |
|
| 584 | + * @throws InvalidDataTypeException |
|
| 585 | + * @throws InvalidInterfaceException |
|
| 586 | + * @throws RuntimeException |
|
| 587 | + * @throws ReflectionException |
|
| 588 | + */ |
|
| 589 | + public function update_registration_final_prices($transaction, $save_regs = true) |
|
| 590 | + { |
|
| 591 | + $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
|
| 592 | + $transaction->total_line_item() |
|
| 593 | + ); |
|
| 594 | + foreach ($transaction->registrations() as $registration) { |
|
| 595 | + /** @var EE_Line_Item $line_item */ |
|
| 596 | + $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
| 597 | + if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) { |
|
| 598 | + $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]); |
|
| 599 | + if ($save_regs) { |
|
| 600 | + $registration->save(); |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + // and make sure there's no rounding problem |
|
| 605 | + $this->fix_reg_final_price_rounding_issue($transaction); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * Makes sure there is no rounding errors for the REG_final_prices. |
|
| 611 | + * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them, |
|
| 612 | + * they will each be for $0.99333333, which gets rounded to $1 again. |
|
| 613 | + * So the transaction total will be $2.99, but each registration will be for $1, |
|
| 614 | + * so if each registrant paid individually they will have overpaid by $0.01. |
|
| 615 | + * So in order to overcome this, we check for any difference, and if there is a difference |
|
| 616 | + * we just grab one registrant at random and make them responsible for it. |
|
| 617 | + * This should be used after setting REG_final_prices (it's done automatically as part of |
|
| 618 | + * EE_Registration_Processor::update_registration_final_prices()) |
|
| 619 | + * |
|
| 620 | + * @param EE_Transaction $transaction |
|
| 621 | + * @return bool success verifying that there is NO difference after this method is done |
|
| 622 | + * @throws EE_Error |
|
| 623 | + * @throws InvalidArgumentException |
|
| 624 | + * @throws InvalidDataTypeException |
|
| 625 | + * @throws InvalidInterfaceException |
|
| 626 | + * @throws ReflectionException |
|
| 627 | + */ |
|
| 628 | + public function fix_reg_final_price_rounding_issue($transaction) |
|
| 629 | + { |
|
| 630 | + $reg_final_price_sum = EEM_Registration::instance()->sum( |
|
| 631 | + [ |
|
| 632 | + [ |
|
| 633 | + 'TXN_ID' => $transaction->ID(), |
|
| 634 | + ], |
|
| 635 | + ], |
|
| 636 | + 'REG_final_price' |
|
| 637 | + ); |
|
| 638 | + $diff = $transaction->total() - $reg_final_price_sum; |
|
| 639 | + // ok then, just grab one of the registrations |
|
| 640 | + if ($diff !== 0.0) { |
|
| 641 | + $a_reg = EEM_Registration::instance()->get_one( |
|
| 642 | + [ |
|
| 643 | + [ |
|
| 644 | + 'TXN_ID' => $transaction->ID(), |
|
| 645 | + ], |
|
| 646 | + ] |
|
| 647 | + ); |
|
| 648 | + return $a_reg instanceof EE_Registration |
|
| 649 | + && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]); |
|
| 650 | + } |
|
| 651 | + return true; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + /** |
|
| 656 | + * update_registration_after_being_canceled_or_declined |
|
| 657 | + * |
|
| 658 | + * @param EE_Registration $registration |
|
| 659 | + * @param array $closed_reg_statuses |
|
| 660 | + * @param bool $update_reg |
|
| 661 | + * @return bool |
|
| 662 | + * @throws EE_Error |
|
| 663 | + * @throws RuntimeException |
|
| 664 | + * @throws ReflectionException |
|
| 665 | + */ |
|
| 666 | + public function update_registration_after_being_canceled_or_declined( |
|
| 667 | + EE_Registration $registration, |
|
| 668 | + array $closed_reg_statuses = [], |
|
| 669 | + $update_reg = true |
|
| 670 | + ) { |
|
| 671 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
| 672 | + $closed_reg_statuses = ! empty($closed_reg_statuses) |
|
| 673 | + ? $closed_reg_statuses |
|
| 674 | + : EEM_Registration::closed_reg_statuses(); |
|
| 675 | + if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
| 676 | + return false; |
|
| 677 | + } |
|
| 678 | + // release a reserved ticket by decrementing ticket and datetime reserved values |
|
| 679 | + $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__); |
|
| 680 | + $registration->set_final_price(0); |
|
| 681 | + if ($update_reg) { |
|
| 682 | + $registration->save(); |
|
| 683 | + } |
|
| 684 | + return true; |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * update_canceled_or_declined_registration_after_being_reinstated |
|
| 690 | + * |
|
| 691 | + * @param EE_Registration $registration |
|
| 692 | + * @param array $closed_reg_statuses |
|
| 693 | + * @param bool $update_reg |
|
| 694 | + * @return bool |
|
| 695 | + * @throws EE_Error |
|
| 696 | + * @throws RuntimeException |
|
| 697 | + * @throws ReflectionException |
|
| 698 | + */ |
|
| 699 | + public function update_canceled_or_declined_registration_after_being_reinstated( |
|
| 700 | + EE_Registration $registration, |
|
| 701 | + array $closed_reg_statuses = [], |
|
| 702 | + $update_reg = true |
|
| 703 | + ) { |
|
| 704 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
| 705 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
| 706 | + : EEM_Registration::closed_reg_statuses(); |
|
| 707 | + if (in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
| 708 | + return false; |
|
| 709 | + } |
|
| 710 | + $ticket = $registration->ticket(); |
|
| 711 | + if (! $ticket instanceof EE_Ticket) { |
|
| 712 | + throw new EE_Error( |
|
| 713 | + sprintf( |
|
| 714 | + esc_html__( |
|
| 715 | + 'The Ticket for Registration %1$d was not found or is invalid.', |
|
| 716 | + 'event_espresso' |
|
| 717 | + ), |
|
| 718 | + $registration->ticket_ID() |
|
| 719 | + ) |
|
| 720 | + ); |
|
| 721 | + } |
|
| 722 | + $registration->set_final_price($ticket->price()); |
|
| 723 | + if ($update_reg) { |
|
| 724 | + $registration->save(); |
|
| 725 | + } |
|
| 726 | + return true; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * generate_ONE_registration_from_line_item |
|
| 732 | + * Although a ticket line item may have a quantity greater than 1, |
|
| 733 | + * this method will ONLY CREATE ONE REGISTRATION !!! |
|
| 734 | + * Regardless of the ticket line item quantity. |
|
| 735 | + * This means that any code calling this method is responsible for ensuring |
|
| 736 | + * that the final registration count matches the ticket line item quantity. |
|
| 737 | + * This was done to make it easier to match the number of registrations |
|
| 738 | + * to the number of tickets in the cart, when the cart has been edited |
|
| 739 | + * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass |
|
| 740 | + * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets. |
|
| 741 | + * |
|
| 742 | + * @param EE_Line_Item $line_item |
|
| 743 | + * @param EE_Transaction $transaction |
|
| 744 | + * @param int $att_nmbr |
|
| 745 | + * @param int $total_ticket_count |
|
| 746 | + * @return EE_Registration | null |
|
| 747 | + * @throws OutOfRangeException |
|
| 748 | + * @throws UnexpectedEntityException |
|
| 749 | + * @throws EE_Error |
|
| 750 | + * @throws ReflectionException |
|
| 751 | + * @deprecated |
|
| 752 | + * @since 4.9.1 |
|
| 753 | + */ |
|
| 754 | + public function generate_ONE_registration_from_line_item( |
|
| 755 | + EE_Line_Item $line_item, |
|
| 756 | + EE_Transaction $transaction, |
|
| 757 | + $att_nmbr = 1, |
|
| 758 | + $total_ticket_count = 1 |
|
| 759 | + ) { |
|
| 760 | + EE_Error::doing_it_wrong( |
|
| 761 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 762 | + sprintf( |
|
| 763 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 764 | + '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
|
| 765 | + ), |
|
| 766 | + '4.9.1', |
|
| 767 | + '5.0.0' |
|
| 768 | + ); |
|
| 769 | + // grab the related ticket object for this line_item |
|
| 770 | + $ticket = $line_item->ticket(); |
|
| 771 | + if (! $ticket instanceof EE_Ticket) { |
|
| 772 | + EE_Error::add_error( |
|
| 773 | + sprintf( |
|
| 774 | + esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
| 775 | + $line_item->ID() |
|
| 776 | + ), |
|
| 777 | + __FILE__, |
|
| 778 | + __FUNCTION__, |
|
| 779 | + __LINE__ |
|
| 780 | + ); |
|
| 781 | + return null; |
|
| 782 | + } |
|
| 783 | + $registration_service = new CreateRegistrationService(); |
|
| 784 | + // then generate a new registration from that |
|
| 785 | + return $registration_service->create( |
|
| 786 | + $ticket->get_related_event(), |
|
| 787 | + $transaction, |
|
| 788 | + $ticket, |
|
| 789 | + $line_item, |
|
| 790 | + $att_nmbr, |
|
| 791 | + $total_ticket_count |
|
| 792 | + ); |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * generates reg_url_link |
|
| 798 | + * |
|
| 799 | + * @param int $att_nmbr |
|
| 800 | + * @param EE_Line_Item | string $item |
|
| 801 | + * @return RegUrlLink |
|
| 802 | + * @throws InvalidArgumentException |
|
| 803 | + * @deprecated |
|
| 804 | + * @since 4.9.1 |
|
| 805 | + */ |
|
| 806 | + public function generate_reg_url_link($att_nmbr, $item) |
|
| 807 | + { |
|
| 808 | + EE_Error::doing_it_wrong( |
|
| 809 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 810 | + sprintf( |
|
| 811 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 812 | + 'EventEspresso\core\domain\entities\RegUrlLink' |
|
| 813 | + ), |
|
| 814 | + '4.9.1', |
|
| 815 | + '5.0.0' |
|
| 816 | + ); |
|
| 817 | + return new RegUrlLink($att_nmbr, $item); |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * generates reg code |
|
| 823 | + * |
|
| 824 | + * @param EE_Registration $registration |
|
| 825 | + * @return RegCode |
|
| 826 | + * @throws EE_Error |
|
| 827 | + * @throws EntityNotFoundException |
|
| 828 | + * @throws InvalidArgumentException |
|
| 829 | + * @since 4.9.1 |
|
| 830 | + * @deprecated |
|
| 831 | + */ |
|
| 832 | + public function generate_reg_code(EE_Registration $registration) |
|
| 833 | + { |
|
| 834 | + EE_Error::doing_it_wrong( |
|
| 835 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 836 | + sprintf( |
|
| 837 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 838 | + 'EventEspresso\core\domain\entities\RegCode' |
|
| 839 | + ), |
|
| 840 | + '4.9.1', |
|
| 841 | + '5.0.0' |
|
| 842 | + ); |
|
| 843 | + return apply_filters( |
|
| 844 | + 'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code', |
|
| 845 | + new RegCode( |
|
| 846 | + RegUrlLink::fromRegistration($registration), |
|
| 847 | + $registration->transaction(), |
|
| 848 | + $registration->ticket() |
|
| 849 | + ), |
|
| 850 | + $registration |
|
| 851 | + ); |
|
| 852 | + } |
|
| 853 | 853 | } |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | public static function instance(RequestInterface $request = null) |
| 83 | 83 | { |
| 84 | 84 | // check if class object is instantiated |
| 85 | - if (! self::$_instance instanceof EE_Registration_Processor) { |
|
| 86 | - if (! $request instanceof RequestInterface) { |
|
| 85 | + if ( ! self::$_instance instanceof EE_Registration_Processor) { |
|
| 86 | + if ( ! $request instanceof RequestInterface) { |
|
| 87 | 87 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
| 88 | 88 | } |
| 89 | 89 | self::$_instance = new self($request); |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function old_reg_status($REG_ID) |
| 111 | 111 | { |
| 112 | - return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null; |
|
| 112 | + return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | public function set_old_reg_status($REG_ID, $old_reg_status) |
| 121 | 121 | { |
| 122 | 122 | // only set the first time |
| 123 | - if (! isset($this->_old_reg_status[ $REG_ID ])) { |
|
| 124 | - $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
| 123 | + if ( ! isset($this->_old_reg_status[$REG_ID])) { |
|
| 124 | + $this->_old_reg_status[$REG_ID] = $old_reg_status; |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | public function new_reg_status($REG_ID) |
| 134 | 134 | { |
| 135 | - return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null; |
|
| 135 | + return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public function set_new_reg_status($REG_ID, $new_reg_status) |
| 144 | 144 | { |
| 145 | - $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
| 145 | + $this->_new_reg_status[$REG_ID] = $new_reg_status; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | if ( |
| 220 | 220 | $this->reg_status_updated($registration->ID()) |
| 221 | 221 | && ( |
| 222 | - (! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
| 222 | + ( ! $this->request->isAdmin() || $this->request->isFrontAjax()) |
|
| 223 | 223 | || EE_Registry::instance()->CAP->current_user_can( |
| 224 | 224 | 'ee_edit_registration', |
| 225 | 225 | 'toggle_registration_status', |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | $registration->save(); |
| 303 | 303 | } |
| 304 | 304 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
| 305 | - if (! EE_Processor_Base::$IPN) { |
|
| 305 | + if ( ! EE_Processor_Base::$IPN) { |
|
| 306 | 306 | // otherwise, send out notifications |
| 307 | 307 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
| 308 | 308 | } |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | $registration->save(); |
| 371 | 371 | } |
| 372 | 372 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
| 373 | - if (! EE_Processor_Base::$IPN) { |
|
| 373 | + if ( ! EE_Processor_Base::$IPN) { |
|
| 374 | 374 | // otherwise, send out notifications |
| 375 | 375 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
| 376 | 376 | } |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | // set initial REG_Status |
| 419 | 419 | $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
| 420 | 420 | // was a payment just made ? |
| 421 | - $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
| 421 | + $payment = isset($additional_details['payment_updates'], $additional_details['last_payment']) |
|
| 422 | 422 | && $additional_details['payment_updates'] |
| 423 | 423 | && $additional_details['last_payment'] instanceof EE_Payment |
| 424 | 424 | ? $additional_details['last_payment'] |
@@ -443,14 +443,14 @@ discard block |
||
| 443 | 443 | || ( |
| 444 | 444 | $payment instanceof EE_Payment && $payment->is_approved() |
| 445 | 445 | && // this specific registration has not yet been paid for |
| 446 | - ! isset(self::$_amount_paid[ $registration->ID() ]) |
|
| 446 | + ! isset(self::$_amount_paid[$registration->ID()]) |
|
| 447 | 447 | && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
| 448 | 448 | $payment->amount() - $total_paid >= $registration->final_price() |
| 449 | 449 | ) |
| 450 | 450 | ) |
| 451 | 451 | ) { |
| 452 | 452 | // mark as paid |
| 453 | - self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
| 453 | + self::$_amount_paid[$registration->ID()] = $registration->final_price(); |
|
| 454 | 454 | // track new REG_Status |
| 455 | 455 | $this->set_new_reg_status($registration->ID(), RegStatus::APPROVED); |
| 456 | 456 | // toggle status to approved |
@@ -469,7 +469,7 @@ discard block |
||
| 469 | 469 | $registration->save(); |
| 470 | 470 | } |
| 471 | 471 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
| 472 | - if (! EE_Processor_Base::$IPN) { |
|
| 472 | + if ( ! EE_Processor_Base::$IPN) { |
|
| 473 | 473 | // otherwise, send out notifications |
| 474 | 474 | add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
| 475 | 475 | } |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | public function trigger_registration_update_notifications($registration, array $additional_details = []) |
| 504 | 504 | { |
| 505 | 505 | try { |
| 506 | - if (! $registration instanceof EE_Registration) { |
|
| 506 | + if ( ! $registration instanceof EE_Registration) { |
|
| 507 | 507 | throw new EE_Error( |
| 508 | 508 | esc_html__('An invalid registration was received.', 'event_espresso') |
| 509 | 509 | ); |
@@ -594,8 +594,8 @@ discard block |
||
| 594 | 594 | foreach ($transaction->registrations() as $registration) { |
| 595 | 595 | /** @var EE_Line_Item $line_item */ |
| 596 | 596 | $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
| 597 | - if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) { |
|
| 598 | - $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]); |
|
| 597 | + if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) { |
|
| 598 | + $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]); |
|
| 599 | 599 | if ($save_regs) { |
| 600 | 600 | $registration->save(); |
| 601 | 601 | } |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | ], |
| 636 | 636 | 'REG_final_price' |
| 637 | 637 | ); |
| 638 | - $diff = $transaction->total() - $reg_final_price_sum; |
|
| 638 | + $diff = $transaction->total() - $reg_final_price_sum; |
|
| 639 | 639 | // ok then, just grab one of the registrations |
| 640 | 640 | if ($diff !== 0.0) { |
| 641 | 641 | $a_reg = EEM_Registration::instance()->get_one( |
@@ -672,11 +672,11 @@ discard block |
||
| 672 | 672 | $closed_reg_statuses = ! empty($closed_reg_statuses) |
| 673 | 673 | ? $closed_reg_statuses |
| 674 | 674 | : EEM_Registration::closed_reg_statuses(); |
| 675 | - if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
| 675 | + if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) { |
|
| 676 | 676 | return false; |
| 677 | 677 | } |
| 678 | 678 | // release a reserved ticket by decrementing ticket and datetime reserved values |
| 679 | - $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__); |
|
| 679 | + $registration->release_reserved_ticket(true, 'RegProcessor:'.__LINE__); |
|
| 680 | 680 | $registration->set_final_price(0); |
| 681 | 681 | if ($update_reg) { |
| 682 | 682 | $registration->save(); |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | return false; |
| 709 | 709 | } |
| 710 | 710 | $ticket = $registration->ticket(); |
| 711 | - if (! $ticket instanceof EE_Ticket) { |
|
| 711 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 712 | 712 | throw new EE_Error( |
| 713 | 713 | sprintf( |
| 714 | 714 | esc_html__( |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | $total_ticket_count = 1 |
| 759 | 759 | ) { |
| 760 | 760 | EE_Error::doing_it_wrong( |
| 761 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 761 | + __CLASS__.'::'.__FUNCTION__, |
|
| 762 | 762 | sprintf( |
| 763 | 763 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
| 764 | 764 | '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()' |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | ); |
| 769 | 769 | // grab the related ticket object for this line_item |
| 770 | 770 | $ticket = $line_item->ticket(); |
| 771 | - if (! $ticket instanceof EE_Ticket) { |
|
| 771 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 772 | 772 | EE_Error::add_error( |
| 773 | 773 | sprintf( |
| 774 | 774 | esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | public function generate_reg_url_link($att_nmbr, $item) |
| 807 | 807 | { |
| 808 | 808 | EE_Error::doing_it_wrong( |
| 809 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 809 | + __CLASS__.'::'.__FUNCTION__, |
|
| 810 | 810 | sprintf( |
| 811 | 811 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
| 812 | 812 | 'EventEspresso\core\domain\entities\RegUrlLink' |
@@ -832,7 +832,7 @@ discard block |
||
| 832 | 832 | public function generate_reg_code(EE_Registration $registration) |
| 833 | 833 | { |
| 834 | 834 | EE_Error::doing_it_wrong( |
| 835 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 835 | + __CLASS__.'::'.__FUNCTION__, |
|
| 836 | 836 | sprintf( |
| 837 | 837 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
| 838 | 838 | 'EventEspresso\core\domain\entities\RegCode' |
@@ -24,991 +24,991 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | final class EE_Admin implements InterminableInterface |
| 26 | 26 | { |
| 27 | - private static ?EE_Admin $_instance = null; |
|
| 28 | - |
|
| 29 | - private ?PersistentAdminNoticeManager $persistent_admin_notice_manager = null; |
|
| 30 | - |
|
| 31 | - protected LoaderInterface $loader; |
|
| 32 | - |
|
| 33 | - protected RequestInterface $request; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @singleton method used to instantiate class object |
|
| 38 | - * @param LoaderInterface|null $loader |
|
| 39 | - * @param RequestInterface|null $request |
|
| 40 | - * @return EE_Admin|null |
|
| 41 | - * @throws EE_Error |
|
| 42 | - */ |
|
| 43 | - public static function instance(?LoaderInterface $loader = null, ?RequestInterface $request = null): ?EE_Admin |
|
| 44 | - { |
|
| 45 | - // check if class object is instantiated |
|
| 46 | - if (! EE_Admin::$_instance instanceof EE_Admin) { |
|
| 47 | - EE_Admin::$_instance = new EE_Admin($loader, $request); |
|
| 48 | - } |
|
| 49 | - return EE_Admin::$_instance; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @return EE_Admin|null |
|
| 55 | - * @throws EE_Error |
|
| 56 | - */ |
|
| 57 | - public static function reset(): ?EE_Admin |
|
| 58 | - { |
|
| 59 | - EE_Admin::$_instance = null; |
|
| 60 | - $loader = LoaderFactory::getLoader(); |
|
| 61 | - $request = $loader->getShared('EventEspresso\core\services\request\Request'); |
|
| 62 | - return EE_Admin::instance($loader, $request); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param LoaderInterface $loader |
|
| 68 | - * @param RequestInterface $request |
|
| 69 | - * @throws EE_Error |
|
| 70 | - * @throws InvalidDataTypeException |
|
| 71 | - * @throws InvalidInterfaceException |
|
| 72 | - * @throws InvalidArgumentException |
|
| 73 | - */ |
|
| 74 | - protected function __construct(LoaderInterface $loader, RequestInterface $request) |
|
| 75 | - { |
|
| 76 | - $this->loader = $loader; |
|
| 77 | - $this->request = $request; |
|
| 78 | - // define global EE_Admin constants |
|
| 79 | - $this->_define_all_constants(); |
|
| 80 | - // set autoloaders for our admin page classes based on included path information |
|
| 81 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 82 | - // reset Environment config (we only do this on admin page loads); |
|
| 83 | - EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 84 | - // load EE_Request_Handler early |
|
| 85 | - add_action('AHEE__EE_System__initialize_last', [$this, 'init']); |
|
| 86 | - add_action('admin_init', [$this, 'admin_init'], 100); |
|
| 87 | - if (! $this->request->isAjax()) { |
|
| 88 | - // admin hooks |
|
| 89 | - add_action('admin_notices', [$this, 'display_admin_notices']); |
|
| 90 | - add_action('network_admin_notices', [$this, 'display_admin_notices']); |
|
| 91 | - add_filter('pre_update_option', [$this, 'check_for_invalid_datetime_formats'], 100, 2); |
|
| 92 | - add_filter('plugin_action_links', [$this, 'filter_plugin_actions'], 10, 2); |
|
| 93 | - add_filter('admin_footer_text', [$this, 'espresso_admin_footer']); |
|
| 94 | - add_action('display_post_states', [$this, 'displayStateForCriticalPages'], 10, 2); |
|
| 95 | - add_filter('plugin_row_meta', [$this, 'addLinksToPluginRowMeta'], 10, 2); |
|
| 96 | - } |
|
| 97 | - do_action('AHEE__EE_Admin__loaded'); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * _define_all_constants |
|
| 103 | - * define constants that are set globally for all admin pages |
|
| 104 | - * |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - private function _define_all_constants() |
|
| 108 | - { |
|
| 109 | - if (! defined('EE_ADMIN_URL')) { |
|
| 110 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 111 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 112 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/'); |
|
| 113 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 114 | - define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * filter_plugin_actions - adds links to the Plugins page listing |
|
| 121 | - * |
|
| 122 | - * @param array $links |
|
| 123 | - * @param string $plugin |
|
| 124 | - * @return array |
|
| 125 | - */ |
|
| 126 | - public function filter_plugin_actions($links, $plugin) |
|
| 127 | - { |
|
| 128 | - // set $main_file in stone |
|
| 129 | - static $main_file; |
|
| 130 | - // if $main_file is not set yet |
|
| 131 | - if (! $main_file) { |
|
| 132 | - $main_file = EE_PLUGIN_BASENAME; |
|
| 133 | - } |
|
| 134 | - if ($plugin === $main_file) { |
|
| 135 | - // compare current plugin to this one |
|
| 136 | - if (MaintenanceStatus::isFullSite()) { |
|
| 137 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
| 138 | - . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
| 139 | - . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
| 140 | - . '</a>'; |
|
| 141 | - array_unshift($links, $maintenance_link); |
|
| 142 | - } else { |
|
| 143 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
| 144 | - . esc_html__('Settings', 'event_espresso') |
|
| 145 | - . '</a>'; |
|
| 146 | - $events_link = '<a href="admin.php?page=espresso_events">' |
|
| 147 | - . esc_html__('Events', 'event_espresso') |
|
| 148 | - . '</a>'; |
|
| 149 | - // add before other links |
|
| 150 | - array_unshift($links, $org_settings_link, $events_link); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - return $links; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * hide_admin_pages_except_maintenance_mode |
|
| 159 | - * |
|
| 160 | - * @param array $admin_page_folder_names |
|
| 161 | - * @return array |
|
| 162 | - */ |
|
| 163 | - public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = []) |
|
| 164 | - { |
|
| 165 | - return [ |
|
| 166 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance/', |
|
| 167 | - 'about' => EE_ADMIN_PAGES . 'about/', |
|
| 168 | - 'support' => EE_ADMIN_PAGES . 'support/', |
|
| 169 | - ]; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 175 | - * EE_Front_Controller's init phases have run |
|
| 176 | - * |
|
| 177 | - * @return void |
|
| 178 | - * @throws EE_Error |
|
| 179 | - * @throws InvalidArgumentException |
|
| 180 | - * @throws InvalidDataTypeException |
|
| 181 | - * @throws InvalidInterfaceException |
|
| 182 | - * @throws ReflectionException |
|
| 183 | - * @throws ServiceNotFoundException |
|
| 184 | - */ |
|
| 185 | - public function init() |
|
| 186 | - { |
|
| 187 | - // only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 188 | - if (DbStatus::isOnline()) { |
|
| 189 | - $this->initModelsReady(); |
|
| 190 | - } |
|
| 191 | - // run the admin page factory but ONLY if: |
|
| 192 | - // - it is a regular non ajax admin request |
|
| 193 | - // - we are doing an ee admin ajax request |
|
| 194 | - if ($this->request->isAdmin() || $this->request->isAdminAjax() || $this->request->isActivation()) { |
|
| 195 | - try { |
|
| 196 | - // this loads the controller for the admin pages which will setup routing etc |
|
| 197 | - $admin_page_loader = $this->loader->getShared('EE_Admin_Page_Loader', [$this->loader]); |
|
| 198 | - /** @var EE_Admin_Page_Loader $admin_page_loader */ |
|
| 199 | - $admin_page_loader->init(); |
|
| 200 | - } catch (EE_Error $e) { |
|
| 201 | - $e->get_error(); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - if ($this->request->isAjax()) { |
|
| 205 | - return; |
|
| 206 | - } |
|
| 207 | - add_filter('content_save_pre', [$this, 'its_eSpresso']); |
|
| 208 | - // make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 209 | - add_action('admin_head', [$this, 'enable_hidden_ee_nav_menu_metaboxes']); |
|
| 210 | - add_action('admin_head', [$this, 'register_custom_nav_menu_boxes']); |
|
| 211 | - // exclude EE critical pages from all nav menus and wp_list_pages |
|
| 212 | - add_filter('nav_menu_meta_box_object', [$this, 'remove_pages_from_nav_menu']); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Gets the loader (and if it wasn't previously set, sets it) |
|
| 218 | - * |
|
| 219 | - * @return LoaderInterface |
|
| 220 | - * @throws InvalidArgumentException |
|
| 221 | - * @throws InvalidDataTypeException |
|
| 222 | - * @throws InvalidInterfaceException |
|
| 223 | - */ |
|
| 224 | - protected function getLoader() |
|
| 225 | - { |
|
| 226 | - return $this->loader; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Method that's fired on admin requests (including admin ajax) but only when the models are usable |
|
| 232 | - * (ie, the site isn't in maintenance mode) |
|
| 233 | - * |
|
| 234 | - * @return void |
|
| 235 | - * @throws EE_Error |
|
| 236 | - * @since 4.9.63.p |
|
| 237 | - */ |
|
| 238 | - protected function initModelsReady() |
|
| 239 | - { |
|
| 240 | - // ok so we want to enable the entire admin |
|
| 241 | - $this->persistent_admin_notice_manager = $this->loader->getShared( |
|
| 242 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 243 | - ); |
|
| 244 | - $this->persistent_admin_notice_manager->setReturnUrl( |
|
| 245 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 246 | - [ |
|
| 247 | - 'page' => $this->request->getRequestParam('page', ''), |
|
| 248 | - 'action' => $this->request->getRequestParam('action', ''), |
|
| 249 | - ], |
|
| 250 | - EE_ADMIN_URL |
|
| 251 | - ) |
|
| 252 | - ); |
|
| 253 | - $this->maybeSetDatetimeWarningNotice(); |
|
| 254 | - // at a glance dashboard widget |
|
| 255 | - add_filter('dashboard_glance_items', [$this, 'dashboard_glance_items']); |
|
| 256 | - // filter for get_edit_post_link used on comments for custom post types |
|
| 257 | - add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 2); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * get_persistent_admin_notices |
|
| 263 | - * |
|
| 264 | - * @access public |
|
| 265 | - * @return void |
|
| 266 | - * @throws EE_Error |
|
| 267 | - * @throws InvalidArgumentException |
|
| 268 | - * @throws InvalidDataTypeException |
|
| 269 | - * @throws InvalidInterfaceException |
|
| 270 | - * @throws ReflectionException |
|
| 271 | - */ |
|
| 272 | - public function maybeSetDatetimeWarningNotice() |
|
| 273 | - { |
|
| 274 | - // add dismissible notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
| 275 | - // @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
| 276 | - // with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
| 277 | - // this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
| 278 | - if ( |
|
| 279 | - apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true) |
|
| 280 | - && ! get_option('timezone_string') |
|
| 281 | - && EEM_Event::instance()->count() > 0 |
|
| 282 | - ) { |
|
| 283 | - new PersistentAdminNotice( |
|
| 284 | - 'datetime_fix_notice', |
|
| 285 | - sprintf( |
|
| 286 | - esc_html__( |
|
| 287 | - '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
| 288 | - 'event_espresso' |
|
| 289 | - ), |
|
| 290 | - '<strong>', |
|
| 291 | - '</strong>', |
|
| 292 | - '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
| 293 | - '</a>', |
|
| 294 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 295 | - [ |
|
| 296 | - 'page' => 'espresso_maintenance_settings', |
|
| 297 | - 'action' => 'datetime_tools', |
|
| 298 | - ], |
|
| 299 | - admin_url('admin.php') |
|
| 300 | - ) . '">' |
|
| 301 | - ), |
|
| 302 | - false, |
|
| 303 | - 'manage_options', |
|
| 304 | - 'datetime_fix_persistent_notice' |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 312 | - * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 313 | - * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 314 | - * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 315 | - * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 316 | - * |
|
| 317 | - * @param WP_Post $post_type WP post type object |
|
| 318 | - * @return WP_Post |
|
| 319 | - * @throws InvalidArgumentException |
|
| 320 | - * @throws InvalidDataTypeException |
|
| 321 | - * @throws InvalidInterfaceException |
|
| 322 | - */ |
|
| 323 | - public function remove_pages_from_nav_menu($post_type) |
|
| 324 | - { |
|
| 325 | - // if this isn't the "pages" post type let's get out |
|
| 326 | - if ($post_type->name !== 'page') { |
|
| 327 | - return $post_type; |
|
| 328 | - } |
|
| 329 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 330 | - $post_type->_default_query = [ |
|
| 331 | - 'post__not_in' => $critical_pages, |
|
| 332 | - ]; |
|
| 333 | - return $post_type; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * WP by default only shows three metaboxes in "nav-menus.php" for first times users. |
|
| 339 | - * We want to make sure our metaboxes get shown as well |
|
| 340 | - * |
|
| 341 | - * @return void |
|
| 342 | - */ |
|
| 343 | - public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 344 | - { |
|
| 345 | - global $wp_meta_boxes, $pagenow; |
|
| 346 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 347 | - return; |
|
| 348 | - } |
|
| 349 | - $user = wp_get_current_user(); |
|
| 350 | - // has this been done yet? |
|
| 351 | - if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 352 | - return; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 356 | - $initial_meta_boxes = apply_filters( |
|
| 357 | - 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 358 | - [ |
|
| 359 | - 'nav-menu-theme-locations', |
|
| 360 | - 'add-page', |
|
| 361 | - 'add-custom-links', |
|
| 362 | - 'add-category', |
|
| 363 | - 'add-espresso_events', |
|
| 364 | - 'add-espresso_venues', |
|
| 365 | - 'add-espresso_event_categories', |
|
| 366 | - 'add-espresso_venue_categories', |
|
| 367 | - 'add-post-type-post', |
|
| 368 | - 'add-post-type-page', |
|
| 369 | - ] |
|
| 370 | - ); |
|
| 371 | - |
|
| 372 | - if (is_array($hidden_meta_boxes)) { |
|
| 373 | - foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 374 | - if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
|
| 375 | - unset($hidden_meta_boxes[ $key ]); |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 380 | - update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 386 | - * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 387 | - * |
|
| 388 | - * @return void |
|
| 389 | - * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 390 | - * addons etc. |
|
| 391 | - */ |
|
| 392 | - public function register_custom_nav_menu_boxes() |
|
| 393 | - { |
|
| 394 | - add_meta_box( |
|
| 395 | - 'add-extra-nav-menu-pages', |
|
| 396 | - esc_html__('Event Espresso Pages', 'event_espresso'), |
|
| 397 | - [$this, 'ee_cpt_archive_pages'], |
|
| 398 | - 'nav-menus', |
|
| 399 | - 'side', |
|
| 400 | - 'core' |
|
| 401 | - ); |
|
| 402 | - add_filter( |
|
| 403 | - "postbox_classes_nav-menus_add-extra-nav-menu-pages", |
|
| 404 | - function ($classes) { |
|
| 405 | - $classes[] = 'ee-admin-container'; |
|
| 406 | - return $classes; |
|
| 407 | - } |
|
| 408 | - ); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 414 | - * |
|
| 415 | - * @param string $link the original link generated by wp |
|
| 416 | - * @param int $id post id |
|
| 417 | - * @return string the (maybe) modified link |
|
| 418 | - * @since 4.3.0 |
|
| 419 | - */ |
|
| 420 | - public function modify_edit_post_link($link, $id) |
|
| 421 | - { |
|
| 422 | - if (! $post = get_post($id)) { |
|
| 423 | - return $link; |
|
| 424 | - } |
|
| 425 | - if ($post->post_type === EspressoPostType::ATTENDEES) { |
|
| 426 | - $query_args = [ |
|
| 427 | - 'action' => 'edit_attendee', |
|
| 428 | - 'post' => $id, |
|
| 429 | - ]; |
|
| 430 | - return EEH_URL::add_query_args_and_nonce( |
|
| 431 | - $query_args, |
|
| 432 | - admin_url('admin.php?page=espresso_registrations') |
|
| 433 | - ); |
|
| 434 | - } |
|
| 435 | - return $link; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - public function ee_cpt_archive_pages() |
|
| 440 | - { |
|
| 441 | - global $nav_menu_selected_id; |
|
| 442 | - $removed_args = [ |
|
| 443 | - 'action', |
|
| 444 | - 'customlink-tab', |
|
| 445 | - 'edit-menu-item', |
|
| 446 | - 'menu-item', |
|
| 447 | - 'page-tab', |
|
| 448 | - '_wpnonce', |
|
| 449 | - ]; |
|
| 450 | - $nav_tab_link = $nav_menu_selected_id |
|
| 451 | - ? esc_url( |
|
| 452 | - add_query_arg( |
|
| 453 | - 'extra-nav-menu-pages-tab', |
|
| 454 | - 'event-archives', |
|
| 455 | - remove_query_arg($removed_args) |
|
| 456 | - ) |
|
| 457 | - ) |
|
| 458 | - : ''; |
|
| 459 | - $select_all_link = esc_url( |
|
| 460 | - add_query_arg( |
|
| 461 | - [ |
|
| 462 | - 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 463 | - 'selectall' => 1, |
|
| 464 | - ], |
|
| 465 | - remove_query_arg($removed_args) |
|
| 466 | - ) |
|
| 467 | - ); |
|
| 468 | - $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 469 | - $args['walker'] = new Walker_Nav_Menu_Checklist(false); |
|
| 470 | - $nav_menu_pages_items = walk_nav_menu_tree( |
|
| 471 | - array_map( |
|
| 472 | - [$this, '_setup_extra_nav_menu_pages_items'], |
|
| 473 | - $pages |
|
| 474 | - ), |
|
| 475 | - 0, |
|
| 476 | - (object) $args |
|
| 477 | - ); |
|
| 478 | - EEH_Template::display_template( |
|
| 479 | - EE_ADMIN_TEMPLATE . 'cpt_archive_page.template.php', |
|
| 480 | - [ |
|
| 481 | - 'nav_menu_selected_id' => $nav_menu_selected_id, |
|
| 482 | - 'nav_menu_pages_items' => $nav_menu_pages_items, |
|
| 483 | - 'nav_tab_link' => $nav_tab_link, |
|
| 484 | - 'select_all_link' => $select_all_link, |
|
| 485 | - ] |
|
| 486 | - ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * Returns an array of event archive nav items. |
|
| 492 | - * |
|
| 493 | - * @return array |
|
| 494 | - * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 495 | - * method we use for getting the extra nav menu items |
|
| 496 | - */ |
|
| 497 | - private function _get_extra_nav_menu_pages_items() |
|
| 498 | - { |
|
| 499 | - $menuitems[] = [ |
|
| 500 | - 'title' => esc_html__('Event List', 'event_espresso'), |
|
| 501 | - 'url' => get_post_type_archive_link(EspressoPostType::EVENTS), |
|
| 502 | - 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
| 503 | - ]; |
|
| 504 | - return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 510 | - * the properties and converts it to the menu item object. |
|
| 511 | - * |
|
| 512 | - * @param $menu_item_values |
|
| 513 | - * @return stdClass |
|
| 514 | - * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 515 | - */ |
|
| 516 | - private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 517 | - { |
|
| 518 | - $menu_item = new stdClass(); |
|
| 519 | - $keys = [ |
|
| 520 | - 'ID' => 0, |
|
| 521 | - 'db_id' => 0, |
|
| 522 | - 'menu_item_parent' => 0, |
|
| 523 | - 'object_id' => -1, |
|
| 524 | - 'post_parent' => 0, |
|
| 525 | - 'type' => 'custom', |
|
| 526 | - 'object' => '', |
|
| 527 | - 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
| 528 | - 'title' => '', |
|
| 529 | - 'url' => '', |
|
| 530 | - 'target' => '', |
|
| 531 | - 'attr_title' => '', |
|
| 532 | - 'description' => '', |
|
| 533 | - 'classes' => [], |
|
| 534 | - 'xfn' => '', |
|
| 535 | - ]; |
|
| 536 | - foreach ($keys as $key => $value) { |
|
| 537 | - $menu_item->{$key} = $menu_item_values[ $key ] ?? $value; |
|
| 538 | - } |
|
| 539 | - return $menu_item; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * admin_init |
|
| 545 | - * |
|
| 546 | - * @return void |
|
| 547 | - * @throws InvalidArgumentException |
|
| 548 | - * @throws InvalidDataTypeException |
|
| 549 | - * @throws InvalidInterfaceException |
|
| 550 | - */ |
|
| 551 | - public function admin_init() |
|
| 552 | - { |
|
| 553 | - /** |
|
| 554 | - * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 555 | - * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 556 | - * - check if doing post processing. |
|
| 557 | - * - check if doing post processing of one of EE CPTs |
|
| 558 | - * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 559 | - */ |
|
| 560 | - $action = $this->request->getRequestParam('action'); |
|
| 561 | - $post_type = $this->request->getRequestParam('post_type'); |
|
| 562 | - if ($post_type && $action === 'editpost') { |
|
| 563 | - /** @var CustomPostTypeDefinitions $custom_post_types */ |
|
| 564 | - $custom_post_types = $this->loader->getShared(CustomPostTypeDefinitions::class); |
|
| 565 | - $custom_post_types->getCustomPostTypeModels($post_type); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - if (! $this->request->isAjax()) { |
|
| 570 | - /** |
|
| 571 | - * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 572 | - * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
| 573 | - * Pages" tab in the EE General Settings Admin page. |
|
| 574 | - * This is for user-proofing. |
|
| 575 | - */ |
|
| 576 | - add_filter('wp_dropdown_pages', [$this, 'modify_dropdown_pages']); |
|
| 577 | - if (DbStatus::isOnline()) { |
|
| 578 | - $this->adminInitModelsReady(); |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Runs on admin_init but only if models are usable (ie, we're not in maintenance mode) |
|
| 586 | - */ |
|
| 587 | - protected function adminInitModelsReady() |
|
| 588 | - { |
|
| 589 | - if (function_exists('wp_add_privacy_policy_content')) { |
|
| 590 | - $this->loader->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager'); |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 597 | - * |
|
| 598 | - * @param string $output Current output. |
|
| 599 | - * @return string |
|
| 600 | - * @throws InvalidArgumentException |
|
| 601 | - * @throws InvalidDataTypeException |
|
| 602 | - * @throws InvalidInterfaceException |
|
| 603 | - */ |
|
| 604 | - public function modify_dropdown_pages($output) |
|
| 605 | - { |
|
| 606 | - // get critical pages |
|
| 607 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 608 | - |
|
| 609 | - // split current output by line break for easier parsing. |
|
| 610 | - $split_output = explode("\n", $output); |
|
| 611 | - |
|
| 612 | - // loop through to remove any critical pages from the array. |
|
| 613 | - foreach ($critical_pages as $page_id) { |
|
| 614 | - $needle = 'value="' . $page_id . '"'; |
|
| 615 | - foreach ($split_output as $key => $haystack) { |
|
| 616 | - if (strpos($haystack, $needle) !== false) { |
|
| 617 | - unset($split_output[ $key ]); |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - } |
|
| 621 | - // replace output with the new contents |
|
| 622 | - return implode("\n", $split_output); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * display_admin_notices |
|
| 628 | - * |
|
| 629 | - * @return void |
|
| 630 | - */ |
|
| 631 | - public function display_admin_notices() |
|
| 632 | - { |
|
| 633 | - echo EE_Error::get_notices(); // already escaped |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * @param array $elements |
|
| 639 | - * @return array |
|
| 640 | - * @throws EE_Error |
|
| 641 | - * @throws InvalidArgumentException |
|
| 642 | - * @throws InvalidDataTypeException |
|
| 643 | - * @throws InvalidInterfaceException |
|
| 644 | - * @throws ReflectionException |
|
| 645 | - */ |
|
| 646 | - public function dashboard_glance_items($elements) |
|
| 647 | - { |
|
| 648 | - $elements = is_array($elements) ? $elements : [$elements]; |
|
| 649 | - $events = EEM_Event::instance()->count(); |
|
| 650 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 651 | - ['page' => 'espresso_events'], |
|
| 652 | - admin_url('admin.php') |
|
| 653 | - ); |
|
| 654 | - $items['events']['text'] = sprintf( |
|
| 655 | - esc_html( |
|
| 656 | - _n('%s Event', '%s Events', $events, 'event_espresso') |
|
| 657 | - ), |
|
| 658 | - number_format_i18n($events) |
|
| 659 | - ); |
|
| 660 | - $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
| 661 | - $registrations = EEM_Registration::instance()->count( |
|
| 662 | - [ |
|
| 663 | - [ |
|
| 664 | - 'STS_ID' => ['!=', RegStatus::INCOMPLETE], |
|
| 665 | - ], |
|
| 666 | - ] |
|
| 667 | - ); |
|
| 668 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 669 | - ['page' => 'espresso_registrations'], |
|
| 670 | - admin_url('admin.php') |
|
| 671 | - ); |
|
| 672 | - $items['registrations']['text'] = sprintf( |
|
| 673 | - esc_html( |
|
| 674 | - _n('%s Registration', '%s Registrations', $registrations, 'event_espresso') |
|
| 675 | - ), |
|
| 676 | - number_format_i18n($registrations) |
|
| 677 | - ); |
|
| 678 | - $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
| 679 | - |
|
| 680 | - $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 681 | - |
|
| 682 | - foreach ($items as $type => $item_properties) { |
|
| 683 | - $elements[] = sprintf( |
|
| 684 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 685 | - $item_properties['url'], |
|
| 686 | - $item_properties['title'], |
|
| 687 | - $item_properties['text'] |
|
| 688 | - ); |
|
| 689 | - } |
|
| 690 | - return $elements; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * check_for_invalid_datetime_formats |
|
| 696 | - * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 697 | - * their selected format can be parsed by PHP |
|
| 698 | - * |
|
| 699 | - * @param $value |
|
| 700 | - * @param $option |
|
| 701 | - * @return string |
|
| 702 | - */ |
|
| 703 | - public function check_for_invalid_datetime_formats($value, $option) |
|
| 704 | - { |
|
| 705 | - // check for date_format or time_format |
|
| 706 | - switch ($option) { |
|
| 707 | - case 'date_format': |
|
| 708 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 709 | - break; |
|
| 710 | - case 'time_format': |
|
| 711 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 712 | - break; |
|
| 713 | - default: |
|
| 714 | - $date_time_format = false; |
|
| 715 | - } |
|
| 716 | - // do we have a date_time format to check ? |
|
| 717 | - if ($date_time_format) { |
|
| 718 | - $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 719 | - |
|
| 720 | - if (is_array($error_msg)) { |
|
| 721 | - $msg = '<p>' |
|
| 722 | - . sprintf( |
|
| 723 | - esc_html__( |
|
| 724 | - 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 725 | - 'event_espresso' |
|
| 726 | - ), |
|
| 727 | - date($date_time_format), |
|
| 728 | - $date_time_format |
|
| 729 | - ) |
|
| 730 | - . '</p><p><ul>'; |
|
| 731 | - |
|
| 732 | - |
|
| 733 | - foreach ($error_msg as $error) { |
|
| 734 | - $msg .= '<li>' . $error . '</li>'; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - $msg .= '</ul></p><p>' |
|
| 738 | - . sprintf( |
|
| 739 | - esc_html__( |
|
| 740 | - '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 741 | - 'event_espresso' |
|
| 742 | - ), |
|
| 743 | - '<span style="color:#D54E21;">', |
|
| 744 | - '</span>' |
|
| 745 | - ) |
|
| 746 | - . '</p>'; |
|
| 747 | - |
|
| 748 | - // trigger WP settings error |
|
| 749 | - add_settings_error( |
|
| 750 | - 'date_format', |
|
| 751 | - 'date_format', |
|
| 752 | - $msg |
|
| 753 | - ); |
|
| 754 | - |
|
| 755 | - // set format to something valid |
|
| 756 | - switch ($option) { |
|
| 757 | - case 'date_format': |
|
| 758 | - $value = 'F j, Y'; |
|
| 759 | - break; |
|
| 760 | - case 'time_format': |
|
| 761 | - $value = 'g:i a'; |
|
| 762 | - break; |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - } |
|
| 766 | - return $value; |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 772 | - * |
|
| 773 | - * @param $content |
|
| 774 | - * @return string |
|
| 775 | - */ |
|
| 776 | - public function its_eSpresso($content) |
|
| 777 | - { |
|
| 778 | - return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - |
|
| 782 | - /** |
|
| 783 | - * espresso_admin_footer |
|
| 784 | - * |
|
| 785 | - * @return string |
|
| 786 | - */ |
|
| 787 | - public function espresso_admin_footer() |
|
| 788 | - { |
|
| 789 | - return EEH_Template::powered_by_event_espresso('aln-cntr', '', ['utm_content' => 'admin_footer']); |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * Hooks into the "post states" filter in a wp post type list table. |
|
| 795 | - * |
|
| 796 | - * @param array $post_states |
|
| 797 | - * @param WP_Post $post |
|
| 798 | - * @return array |
|
| 799 | - * @throws InvalidArgumentException |
|
| 800 | - * @throws InvalidDataTypeException |
|
| 801 | - * @throws InvalidInterfaceException |
|
| 802 | - */ |
|
| 803 | - public function displayStateForCriticalPages($post_states, $post) |
|
| 804 | - { |
|
| 805 | - $post_states = (array) $post_states; |
|
| 806 | - if (! $post instanceof WP_Post || $post->post_type !== 'page') { |
|
| 807 | - return $post_states; |
|
| 808 | - } |
|
| 809 | - /** @var EE_Core_Config $config */ |
|
| 810 | - $config = $this->loader->getShared('EE_Config')->core; |
|
| 811 | - if (in_array($post->ID, $config->get_critical_pages_array(), true)) { |
|
| 812 | - $post_states[] = sprintf( |
|
| 813 | - /* Translators: Using company name - Event Espresso Critical Page */ |
|
| 814 | - esc_html__('%s Critical Page', 'event_espresso'), |
|
| 815 | - 'Event Espresso' |
|
| 816 | - ); |
|
| 817 | - } |
|
| 818 | - return $post_states; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - /** |
|
| 823 | - * Show documentation links on the plugins page |
|
| 824 | - * |
|
| 825 | - * @param mixed $meta Plugin Row Meta |
|
| 826 | - * @param mixed $file Plugin Base file |
|
| 827 | - * @return array |
|
| 828 | - */ |
|
| 829 | - public function addLinksToPluginRowMeta($meta, $file) |
|
| 830 | - { |
|
| 831 | - if (EE_PLUGIN_BASENAME === $file) { |
|
| 832 | - $row_meta = [ |
|
| 833 | - 'docs' => '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4"' |
|
| 834 | - . ' aria-label="' |
|
| 835 | - . esc_attr__('View Event Espresso documentation', 'event_espresso') |
|
| 836 | - . '">' |
|
| 837 | - . esc_html__('Docs', 'event_espresso') |
|
| 838 | - . '</a>', |
|
| 839 | - 'api' => '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API"' |
|
| 840 | - . ' aria-label="' |
|
| 841 | - . esc_attr__('View Event Espresso API docs', 'event_espresso') |
|
| 842 | - . '">' |
|
| 843 | - . esc_html__('API docs', 'event_espresso') |
|
| 844 | - . '</a>', |
|
| 845 | - ]; |
|
| 846 | - return array_merge($meta, $row_meta); |
|
| 847 | - } |
|
| 848 | - return (array) $meta; |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - /**************************************************************************************/ |
|
| 852 | - /************************************* DEPRECATED *************************************/ |
|
| 853 | - /**************************************************************************************/ |
|
| 854 | - |
|
| 855 | - |
|
| 856 | - /** |
|
| 857 | - * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 858 | - * EE_Admin_Page route is called. |
|
| 859 | - * |
|
| 860 | - * @return void |
|
| 861 | - */ |
|
| 862 | - public function route_admin_request() |
|
| 863 | - { |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - |
|
| 867 | - /** |
|
| 868 | - * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 869 | - * |
|
| 870 | - * @return void |
|
| 871 | - */ |
|
| 872 | - public function wp_loaded() |
|
| 873 | - { |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - |
|
| 877 | - /** |
|
| 878 | - * static method for registering ee admin page. |
|
| 879 | - * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 880 | - * |
|
| 881 | - * @param $page_basename |
|
| 882 | - * @param $page_path |
|
| 883 | - * @param array $config |
|
| 884 | - * @return void |
|
| 885 | - * @throws EE_Error |
|
| 886 | - * @see EE_Register_Admin_Page::register() |
|
| 887 | - * @since 4.3.0 |
|
| 888 | - * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 889 | - */ |
|
| 890 | - public static function register_ee_admin_page($page_basename, $page_path, $config = []) |
|
| 891 | - { |
|
| 892 | - EE_Error::doing_it_wrong( |
|
| 893 | - __METHOD__, |
|
| 894 | - sprintf( |
|
| 895 | - esc_html__( |
|
| 896 | - 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 897 | - 'event_espresso' |
|
| 898 | - ), |
|
| 899 | - $page_basename |
|
| 900 | - ), |
|
| 901 | - '4.3' |
|
| 902 | - ); |
|
| 903 | - if (class_exists('EE_Register_Admin_Page')) { |
|
| 904 | - $config['page_path'] = $page_path; |
|
| 905 | - } |
|
| 906 | - EE_Register_Admin_Page::register($page_basename, $config); |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * @param int $post_ID |
|
| 912 | - * @param WP_Post $post |
|
| 913 | - * @return void |
|
| 914 | - * @deprecated 4.8.41 |
|
| 915 | - */ |
|
| 916 | - public static function parse_post_content_on_save($post_ID, $post) |
|
| 917 | - { |
|
| 918 | - EE_Error::doing_it_wrong( |
|
| 919 | - __METHOD__, |
|
| 920 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 921 | - '4.8.41' |
|
| 922 | - ); |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * @param $option |
|
| 928 | - * @param $old_value |
|
| 929 | - * @param $value |
|
| 930 | - * @return void |
|
| 931 | - * @deprecated 4.8.41 |
|
| 932 | - */ |
|
| 933 | - public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 934 | - { |
|
| 935 | - EE_Error::doing_it_wrong( |
|
| 936 | - __METHOD__, |
|
| 937 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 938 | - '4.8.41' |
|
| 939 | - ); |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - |
|
| 943 | - /** |
|
| 944 | - * @return void |
|
| 945 | - * @deprecated 4.9.27 |
|
| 946 | - */ |
|
| 947 | - public function get_persistent_admin_notices() |
|
| 948 | - { |
|
| 949 | - EE_Error::doing_it_wrong( |
|
| 950 | - __METHOD__, |
|
| 951 | - sprintf( |
|
| 952 | - esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 953 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 954 | - ), |
|
| 955 | - '4.9.27' |
|
| 956 | - ); |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - |
|
| 960 | - /** |
|
| 961 | - * @throws InvalidInterfaceException |
|
| 962 | - * @throws InvalidDataTypeException |
|
| 963 | - * @throws DomainException |
|
| 964 | - * @deprecated 4.9.27 |
|
| 965 | - */ |
|
| 966 | - public function dismiss_ee_nag_notice_callback() |
|
| 967 | - { |
|
| 968 | - EE_Error::doing_it_wrong( |
|
| 969 | - __METHOD__, |
|
| 970 | - sprintf( |
|
| 971 | - esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 972 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 973 | - ), |
|
| 974 | - '4.9.27' |
|
| 975 | - ); |
|
| 976 | - $this->persistent_admin_notice_manager->dismissNotice(); |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - |
|
| 980 | - /** |
|
| 981 | - * @return void |
|
| 982 | - * @deprecated 5.0.0.p |
|
| 983 | - */ |
|
| 984 | - public function enqueue_admin_scripts() |
|
| 985 | - { |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - |
|
| 989 | - |
|
| 990 | - /** |
|
| 991 | - * @return RequestInterface |
|
| 992 | - * @deprecated 5.0.0.p |
|
| 993 | - */ |
|
| 994 | - public function get_request() |
|
| 995 | - { |
|
| 996 | - EE_Error::doing_it_wrong( |
|
| 997 | - __METHOD__, |
|
| 998 | - sprintf( |
|
| 999 | - esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1000 | - 'EventEspresso\core\services\request\Request' |
|
| 1001 | - ), |
|
| 1002 | - '5.0.0.p' |
|
| 1003 | - ); |
|
| 1004 | - return $this->request; |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - |
|
| 1008 | - /** |
|
| 1009 | - * @deprecated 5.0.0.p |
|
| 1010 | - */ |
|
| 1011 | - public function hookIntoWpPluginsPage() |
|
| 1012 | - { |
|
| 1013 | - } |
|
| 27 | + private static ?EE_Admin $_instance = null; |
|
| 28 | + |
|
| 29 | + private ?PersistentAdminNoticeManager $persistent_admin_notice_manager = null; |
|
| 30 | + |
|
| 31 | + protected LoaderInterface $loader; |
|
| 32 | + |
|
| 33 | + protected RequestInterface $request; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @singleton method used to instantiate class object |
|
| 38 | + * @param LoaderInterface|null $loader |
|
| 39 | + * @param RequestInterface|null $request |
|
| 40 | + * @return EE_Admin|null |
|
| 41 | + * @throws EE_Error |
|
| 42 | + */ |
|
| 43 | + public static function instance(?LoaderInterface $loader = null, ?RequestInterface $request = null): ?EE_Admin |
|
| 44 | + { |
|
| 45 | + // check if class object is instantiated |
|
| 46 | + if (! EE_Admin::$_instance instanceof EE_Admin) { |
|
| 47 | + EE_Admin::$_instance = new EE_Admin($loader, $request); |
|
| 48 | + } |
|
| 49 | + return EE_Admin::$_instance; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @return EE_Admin|null |
|
| 55 | + * @throws EE_Error |
|
| 56 | + */ |
|
| 57 | + public static function reset(): ?EE_Admin |
|
| 58 | + { |
|
| 59 | + EE_Admin::$_instance = null; |
|
| 60 | + $loader = LoaderFactory::getLoader(); |
|
| 61 | + $request = $loader->getShared('EventEspresso\core\services\request\Request'); |
|
| 62 | + return EE_Admin::instance($loader, $request); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param LoaderInterface $loader |
|
| 68 | + * @param RequestInterface $request |
|
| 69 | + * @throws EE_Error |
|
| 70 | + * @throws InvalidDataTypeException |
|
| 71 | + * @throws InvalidInterfaceException |
|
| 72 | + * @throws InvalidArgumentException |
|
| 73 | + */ |
|
| 74 | + protected function __construct(LoaderInterface $loader, RequestInterface $request) |
|
| 75 | + { |
|
| 76 | + $this->loader = $loader; |
|
| 77 | + $this->request = $request; |
|
| 78 | + // define global EE_Admin constants |
|
| 79 | + $this->_define_all_constants(); |
|
| 80 | + // set autoloaders for our admin page classes based on included path information |
|
| 81 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 82 | + // reset Environment config (we only do this on admin page loads); |
|
| 83 | + EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 84 | + // load EE_Request_Handler early |
|
| 85 | + add_action('AHEE__EE_System__initialize_last', [$this, 'init']); |
|
| 86 | + add_action('admin_init', [$this, 'admin_init'], 100); |
|
| 87 | + if (! $this->request->isAjax()) { |
|
| 88 | + // admin hooks |
|
| 89 | + add_action('admin_notices', [$this, 'display_admin_notices']); |
|
| 90 | + add_action('network_admin_notices', [$this, 'display_admin_notices']); |
|
| 91 | + add_filter('pre_update_option', [$this, 'check_for_invalid_datetime_formats'], 100, 2); |
|
| 92 | + add_filter('plugin_action_links', [$this, 'filter_plugin_actions'], 10, 2); |
|
| 93 | + add_filter('admin_footer_text', [$this, 'espresso_admin_footer']); |
|
| 94 | + add_action('display_post_states', [$this, 'displayStateForCriticalPages'], 10, 2); |
|
| 95 | + add_filter('plugin_row_meta', [$this, 'addLinksToPluginRowMeta'], 10, 2); |
|
| 96 | + } |
|
| 97 | + do_action('AHEE__EE_Admin__loaded'); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * _define_all_constants |
|
| 103 | + * define constants that are set globally for all admin pages |
|
| 104 | + * |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + private function _define_all_constants() |
|
| 108 | + { |
|
| 109 | + if (! defined('EE_ADMIN_URL')) { |
|
| 110 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 111 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 112 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/'); |
|
| 113 | + define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 114 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * filter_plugin_actions - adds links to the Plugins page listing |
|
| 121 | + * |
|
| 122 | + * @param array $links |
|
| 123 | + * @param string $plugin |
|
| 124 | + * @return array |
|
| 125 | + */ |
|
| 126 | + public function filter_plugin_actions($links, $plugin) |
|
| 127 | + { |
|
| 128 | + // set $main_file in stone |
|
| 129 | + static $main_file; |
|
| 130 | + // if $main_file is not set yet |
|
| 131 | + if (! $main_file) { |
|
| 132 | + $main_file = EE_PLUGIN_BASENAME; |
|
| 133 | + } |
|
| 134 | + if ($plugin === $main_file) { |
|
| 135 | + // compare current plugin to this one |
|
| 136 | + if (MaintenanceStatus::isFullSite()) { |
|
| 137 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
| 138 | + . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
| 139 | + . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
| 140 | + . '</a>'; |
|
| 141 | + array_unshift($links, $maintenance_link); |
|
| 142 | + } else { |
|
| 143 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
| 144 | + . esc_html__('Settings', 'event_espresso') |
|
| 145 | + . '</a>'; |
|
| 146 | + $events_link = '<a href="admin.php?page=espresso_events">' |
|
| 147 | + . esc_html__('Events', 'event_espresso') |
|
| 148 | + . '</a>'; |
|
| 149 | + // add before other links |
|
| 150 | + array_unshift($links, $org_settings_link, $events_link); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + return $links; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * hide_admin_pages_except_maintenance_mode |
|
| 159 | + * |
|
| 160 | + * @param array $admin_page_folder_names |
|
| 161 | + * @return array |
|
| 162 | + */ |
|
| 163 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = []) |
|
| 164 | + { |
|
| 165 | + return [ |
|
| 166 | + 'maintenance' => EE_ADMIN_PAGES . 'maintenance/', |
|
| 167 | + 'about' => EE_ADMIN_PAGES . 'about/', |
|
| 168 | + 'support' => EE_ADMIN_PAGES . 'support/', |
|
| 169 | + ]; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 175 | + * EE_Front_Controller's init phases have run |
|
| 176 | + * |
|
| 177 | + * @return void |
|
| 178 | + * @throws EE_Error |
|
| 179 | + * @throws InvalidArgumentException |
|
| 180 | + * @throws InvalidDataTypeException |
|
| 181 | + * @throws InvalidInterfaceException |
|
| 182 | + * @throws ReflectionException |
|
| 183 | + * @throws ServiceNotFoundException |
|
| 184 | + */ |
|
| 185 | + public function init() |
|
| 186 | + { |
|
| 187 | + // only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 188 | + if (DbStatus::isOnline()) { |
|
| 189 | + $this->initModelsReady(); |
|
| 190 | + } |
|
| 191 | + // run the admin page factory but ONLY if: |
|
| 192 | + // - it is a regular non ajax admin request |
|
| 193 | + // - we are doing an ee admin ajax request |
|
| 194 | + if ($this->request->isAdmin() || $this->request->isAdminAjax() || $this->request->isActivation()) { |
|
| 195 | + try { |
|
| 196 | + // this loads the controller for the admin pages which will setup routing etc |
|
| 197 | + $admin_page_loader = $this->loader->getShared('EE_Admin_Page_Loader', [$this->loader]); |
|
| 198 | + /** @var EE_Admin_Page_Loader $admin_page_loader */ |
|
| 199 | + $admin_page_loader->init(); |
|
| 200 | + } catch (EE_Error $e) { |
|
| 201 | + $e->get_error(); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + if ($this->request->isAjax()) { |
|
| 205 | + return; |
|
| 206 | + } |
|
| 207 | + add_filter('content_save_pre', [$this, 'its_eSpresso']); |
|
| 208 | + // make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 209 | + add_action('admin_head', [$this, 'enable_hidden_ee_nav_menu_metaboxes']); |
|
| 210 | + add_action('admin_head', [$this, 'register_custom_nav_menu_boxes']); |
|
| 211 | + // exclude EE critical pages from all nav menus and wp_list_pages |
|
| 212 | + add_filter('nav_menu_meta_box_object', [$this, 'remove_pages_from_nav_menu']); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Gets the loader (and if it wasn't previously set, sets it) |
|
| 218 | + * |
|
| 219 | + * @return LoaderInterface |
|
| 220 | + * @throws InvalidArgumentException |
|
| 221 | + * @throws InvalidDataTypeException |
|
| 222 | + * @throws InvalidInterfaceException |
|
| 223 | + */ |
|
| 224 | + protected function getLoader() |
|
| 225 | + { |
|
| 226 | + return $this->loader; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Method that's fired on admin requests (including admin ajax) but only when the models are usable |
|
| 232 | + * (ie, the site isn't in maintenance mode) |
|
| 233 | + * |
|
| 234 | + * @return void |
|
| 235 | + * @throws EE_Error |
|
| 236 | + * @since 4.9.63.p |
|
| 237 | + */ |
|
| 238 | + protected function initModelsReady() |
|
| 239 | + { |
|
| 240 | + // ok so we want to enable the entire admin |
|
| 241 | + $this->persistent_admin_notice_manager = $this->loader->getShared( |
|
| 242 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 243 | + ); |
|
| 244 | + $this->persistent_admin_notice_manager->setReturnUrl( |
|
| 245 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 246 | + [ |
|
| 247 | + 'page' => $this->request->getRequestParam('page', ''), |
|
| 248 | + 'action' => $this->request->getRequestParam('action', ''), |
|
| 249 | + ], |
|
| 250 | + EE_ADMIN_URL |
|
| 251 | + ) |
|
| 252 | + ); |
|
| 253 | + $this->maybeSetDatetimeWarningNotice(); |
|
| 254 | + // at a glance dashboard widget |
|
| 255 | + add_filter('dashboard_glance_items', [$this, 'dashboard_glance_items']); |
|
| 256 | + // filter for get_edit_post_link used on comments for custom post types |
|
| 257 | + add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 2); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * get_persistent_admin_notices |
|
| 263 | + * |
|
| 264 | + * @access public |
|
| 265 | + * @return void |
|
| 266 | + * @throws EE_Error |
|
| 267 | + * @throws InvalidArgumentException |
|
| 268 | + * @throws InvalidDataTypeException |
|
| 269 | + * @throws InvalidInterfaceException |
|
| 270 | + * @throws ReflectionException |
|
| 271 | + */ |
|
| 272 | + public function maybeSetDatetimeWarningNotice() |
|
| 273 | + { |
|
| 274 | + // add dismissible notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
| 275 | + // @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
| 276 | + // with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
| 277 | + // this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
| 278 | + if ( |
|
| 279 | + apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true) |
|
| 280 | + && ! get_option('timezone_string') |
|
| 281 | + && EEM_Event::instance()->count() > 0 |
|
| 282 | + ) { |
|
| 283 | + new PersistentAdminNotice( |
|
| 284 | + 'datetime_fix_notice', |
|
| 285 | + sprintf( |
|
| 286 | + esc_html__( |
|
| 287 | + '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
| 288 | + 'event_espresso' |
|
| 289 | + ), |
|
| 290 | + '<strong>', |
|
| 291 | + '</strong>', |
|
| 292 | + '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
| 293 | + '</a>', |
|
| 294 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 295 | + [ |
|
| 296 | + 'page' => 'espresso_maintenance_settings', |
|
| 297 | + 'action' => 'datetime_tools', |
|
| 298 | + ], |
|
| 299 | + admin_url('admin.php') |
|
| 300 | + ) . '">' |
|
| 301 | + ), |
|
| 302 | + false, |
|
| 303 | + 'manage_options', |
|
| 304 | + 'datetime_fix_persistent_notice' |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 312 | + * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 313 | + * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 314 | + * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 315 | + * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 316 | + * |
|
| 317 | + * @param WP_Post $post_type WP post type object |
|
| 318 | + * @return WP_Post |
|
| 319 | + * @throws InvalidArgumentException |
|
| 320 | + * @throws InvalidDataTypeException |
|
| 321 | + * @throws InvalidInterfaceException |
|
| 322 | + */ |
|
| 323 | + public function remove_pages_from_nav_menu($post_type) |
|
| 324 | + { |
|
| 325 | + // if this isn't the "pages" post type let's get out |
|
| 326 | + if ($post_type->name !== 'page') { |
|
| 327 | + return $post_type; |
|
| 328 | + } |
|
| 329 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 330 | + $post_type->_default_query = [ |
|
| 331 | + 'post__not_in' => $critical_pages, |
|
| 332 | + ]; |
|
| 333 | + return $post_type; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * WP by default only shows three metaboxes in "nav-menus.php" for first times users. |
|
| 339 | + * We want to make sure our metaboxes get shown as well |
|
| 340 | + * |
|
| 341 | + * @return void |
|
| 342 | + */ |
|
| 343 | + public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 344 | + { |
|
| 345 | + global $wp_meta_boxes, $pagenow; |
|
| 346 | + if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 347 | + return; |
|
| 348 | + } |
|
| 349 | + $user = wp_get_current_user(); |
|
| 350 | + // has this been done yet? |
|
| 351 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 352 | + return; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 356 | + $initial_meta_boxes = apply_filters( |
|
| 357 | + 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 358 | + [ |
|
| 359 | + 'nav-menu-theme-locations', |
|
| 360 | + 'add-page', |
|
| 361 | + 'add-custom-links', |
|
| 362 | + 'add-category', |
|
| 363 | + 'add-espresso_events', |
|
| 364 | + 'add-espresso_venues', |
|
| 365 | + 'add-espresso_event_categories', |
|
| 366 | + 'add-espresso_venue_categories', |
|
| 367 | + 'add-post-type-post', |
|
| 368 | + 'add-post-type-page', |
|
| 369 | + ] |
|
| 370 | + ); |
|
| 371 | + |
|
| 372 | + if (is_array($hidden_meta_boxes)) { |
|
| 373 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 374 | + if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
|
| 375 | + unset($hidden_meta_boxes[ $key ]); |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 380 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 386 | + * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 387 | + * |
|
| 388 | + * @return void |
|
| 389 | + * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 390 | + * addons etc. |
|
| 391 | + */ |
|
| 392 | + public function register_custom_nav_menu_boxes() |
|
| 393 | + { |
|
| 394 | + add_meta_box( |
|
| 395 | + 'add-extra-nav-menu-pages', |
|
| 396 | + esc_html__('Event Espresso Pages', 'event_espresso'), |
|
| 397 | + [$this, 'ee_cpt_archive_pages'], |
|
| 398 | + 'nav-menus', |
|
| 399 | + 'side', |
|
| 400 | + 'core' |
|
| 401 | + ); |
|
| 402 | + add_filter( |
|
| 403 | + "postbox_classes_nav-menus_add-extra-nav-menu-pages", |
|
| 404 | + function ($classes) { |
|
| 405 | + $classes[] = 'ee-admin-container'; |
|
| 406 | + return $classes; |
|
| 407 | + } |
|
| 408 | + ); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 414 | + * |
|
| 415 | + * @param string $link the original link generated by wp |
|
| 416 | + * @param int $id post id |
|
| 417 | + * @return string the (maybe) modified link |
|
| 418 | + * @since 4.3.0 |
|
| 419 | + */ |
|
| 420 | + public function modify_edit_post_link($link, $id) |
|
| 421 | + { |
|
| 422 | + if (! $post = get_post($id)) { |
|
| 423 | + return $link; |
|
| 424 | + } |
|
| 425 | + if ($post->post_type === EspressoPostType::ATTENDEES) { |
|
| 426 | + $query_args = [ |
|
| 427 | + 'action' => 'edit_attendee', |
|
| 428 | + 'post' => $id, |
|
| 429 | + ]; |
|
| 430 | + return EEH_URL::add_query_args_and_nonce( |
|
| 431 | + $query_args, |
|
| 432 | + admin_url('admin.php?page=espresso_registrations') |
|
| 433 | + ); |
|
| 434 | + } |
|
| 435 | + return $link; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + public function ee_cpt_archive_pages() |
|
| 440 | + { |
|
| 441 | + global $nav_menu_selected_id; |
|
| 442 | + $removed_args = [ |
|
| 443 | + 'action', |
|
| 444 | + 'customlink-tab', |
|
| 445 | + 'edit-menu-item', |
|
| 446 | + 'menu-item', |
|
| 447 | + 'page-tab', |
|
| 448 | + '_wpnonce', |
|
| 449 | + ]; |
|
| 450 | + $nav_tab_link = $nav_menu_selected_id |
|
| 451 | + ? esc_url( |
|
| 452 | + add_query_arg( |
|
| 453 | + 'extra-nav-menu-pages-tab', |
|
| 454 | + 'event-archives', |
|
| 455 | + remove_query_arg($removed_args) |
|
| 456 | + ) |
|
| 457 | + ) |
|
| 458 | + : ''; |
|
| 459 | + $select_all_link = esc_url( |
|
| 460 | + add_query_arg( |
|
| 461 | + [ |
|
| 462 | + 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 463 | + 'selectall' => 1, |
|
| 464 | + ], |
|
| 465 | + remove_query_arg($removed_args) |
|
| 466 | + ) |
|
| 467 | + ); |
|
| 468 | + $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 469 | + $args['walker'] = new Walker_Nav_Menu_Checklist(false); |
|
| 470 | + $nav_menu_pages_items = walk_nav_menu_tree( |
|
| 471 | + array_map( |
|
| 472 | + [$this, '_setup_extra_nav_menu_pages_items'], |
|
| 473 | + $pages |
|
| 474 | + ), |
|
| 475 | + 0, |
|
| 476 | + (object) $args |
|
| 477 | + ); |
|
| 478 | + EEH_Template::display_template( |
|
| 479 | + EE_ADMIN_TEMPLATE . 'cpt_archive_page.template.php', |
|
| 480 | + [ |
|
| 481 | + 'nav_menu_selected_id' => $nav_menu_selected_id, |
|
| 482 | + 'nav_menu_pages_items' => $nav_menu_pages_items, |
|
| 483 | + 'nav_tab_link' => $nav_tab_link, |
|
| 484 | + 'select_all_link' => $select_all_link, |
|
| 485 | + ] |
|
| 486 | + ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * Returns an array of event archive nav items. |
|
| 492 | + * |
|
| 493 | + * @return array |
|
| 494 | + * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 495 | + * method we use for getting the extra nav menu items |
|
| 496 | + */ |
|
| 497 | + private function _get_extra_nav_menu_pages_items() |
|
| 498 | + { |
|
| 499 | + $menuitems[] = [ |
|
| 500 | + 'title' => esc_html__('Event List', 'event_espresso'), |
|
| 501 | + 'url' => get_post_type_archive_link(EspressoPostType::EVENTS), |
|
| 502 | + 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
| 503 | + ]; |
|
| 504 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 510 | + * the properties and converts it to the menu item object. |
|
| 511 | + * |
|
| 512 | + * @param $menu_item_values |
|
| 513 | + * @return stdClass |
|
| 514 | + * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 515 | + */ |
|
| 516 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 517 | + { |
|
| 518 | + $menu_item = new stdClass(); |
|
| 519 | + $keys = [ |
|
| 520 | + 'ID' => 0, |
|
| 521 | + 'db_id' => 0, |
|
| 522 | + 'menu_item_parent' => 0, |
|
| 523 | + 'object_id' => -1, |
|
| 524 | + 'post_parent' => 0, |
|
| 525 | + 'type' => 'custom', |
|
| 526 | + 'object' => '', |
|
| 527 | + 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
| 528 | + 'title' => '', |
|
| 529 | + 'url' => '', |
|
| 530 | + 'target' => '', |
|
| 531 | + 'attr_title' => '', |
|
| 532 | + 'description' => '', |
|
| 533 | + 'classes' => [], |
|
| 534 | + 'xfn' => '', |
|
| 535 | + ]; |
|
| 536 | + foreach ($keys as $key => $value) { |
|
| 537 | + $menu_item->{$key} = $menu_item_values[ $key ] ?? $value; |
|
| 538 | + } |
|
| 539 | + return $menu_item; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * admin_init |
|
| 545 | + * |
|
| 546 | + * @return void |
|
| 547 | + * @throws InvalidArgumentException |
|
| 548 | + * @throws InvalidDataTypeException |
|
| 549 | + * @throws InvalidInterfaceException |
|
| 550 | + */ |
|
| 551 | + public function admin_init() |
|
| 552 | + { |
|
| 553 | + /** |
|
| 554 | + * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 555 | + * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 556 | + * - check if doing post processing. |
|
| 557 | + * - check if doing post processing of one of EE CPTs |
|
| 558 | + * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 559 | + */ |
|
| 560 | + $action = $this->request->getRequestParam('action'); |
|
| 561 | + $post_type = $this->request->getRequestParam('post_type'); |
|
| 562 | + if ($post_type && $action === 'editpost') { |
|
| 563 | + /** @var CustomPostTypeDefinitions $custom_post_types */ |
|
| 564 | + $custom_post_types = $this->loader->getShared(CustomPostTypeDefinitions::class); |
|
| 565 | + $custom_post_types->getCustomPostTypeModels($post_type); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + if (! $this->request->isAjax()) { |
|
| 570 | + /** |
|
| 571 | + * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 572 | + * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
| 573 | + * Pages" tab in the EE General Settings Admin page. |
|
| 574 | + * This is for user-proofing. |
|
| 575 | + */ |
|
| 576 | + add_filter('wp_dropdown_pages', [$this, 'modify_dropdown_pages']); |
|
| 577 | + if (DbStatus::isOnline()) { |
|
| 578 | + $this->adminInitModelsReady(); |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * Runs on admin_init but only if models are usable (ie, we're not in maintenance mode) |
|
| 586 | + */ |
|
| 587 | + protected function adminInitModelsReady() |
|
| 588 | + { |
|
| 589 | + if (function_exists('wp_add_privacy_policy_content')) { |
|
| 590 | + $this->loader->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager'); |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 597 | + * |
|
| 598 | + * @param string $output Current output. |
|
| 599 | + * @return string |
|
| 600 | + * @throws InvalidArgumentException |
|
| 601 | + * @throws InvalidDataTypeException |
|
| 602 | + * @throws InvalidInterfaceException |
|
| 603 | + */ |
|
| 604 | + public function modify_dropdown_pages($output) |
|
| 605 | + { |
|
| 606 | + // get critical pages |
|
| 607 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 608 | + |
|
| 609 | + // split current output by line break for easier parsing. |
|
| 610 | + $split_output = explode("\n", $output); |
|
| 611 | + |
|
| 612 | + // loop through to remove any critical pages from the array. |
|
| 613 | + foreach ($critical_pages as $page_id) { |
|
| 614 | + $needle = 'value="' . $page_id . '"'; |
|
| 615 | + foreach ($split_output as $key => $haystack) { |
|
| 616 | + if (strpos($haystack, $needle) !== false) { |
|
| 617 | + unset($split_output[ $key ]); |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + } |
|
| 621 | + // replace output with the new contents |
|
| 622 | + return implode("\n", $split_output); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * display_admin_notices |
|
| 628 | + * |
|
| 629 | + * @return void |
|
| 630 | + */ |
|
| 631 | + public function display_admin_notices() |
|
| 632 | + { |
|
| 633 | + echo EE_Error::get_notices(); // already escaped |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * @param array $elements |
|
| 639 | + * @return array |
|
| 640 | + * @throws EE_Error |
|
| 641 | + * @throws InvalidArgumentException |
|
| 642 | + * @throws InvalidDataTypeException |
|
| 643 | + * @throws InvalidInterfaceException |
|
| 644 | + * @throws ReflectionException |
|
| 645 | + */ |
|
| 646 | + public function dashboard_glance_items($elements) |
|
| 647 | + { |
|
| 648 | + $elements = is_array($elements) ? $elements : [$elements]; |
|
| 649 | + $events = EEM_Event::instance()->count(); |
|
| 650 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 651 | + ['page' => 'espresso_events'], |
|
| 652 | + admin_url('admin.php') |
|
| 653 | + ); |
|
| 654 | + $items['events']['text'] = sprintf( |
|
| 655 | + esc_html( |
|
| 656 | + _n('%s Event', '%s Events', $events, 'event_espresso') |
|
| 657 | + ), |
|
| 658 | + number_format_i18n($events) |
|
| 659 | + ); |
|
| 660 | + $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
| 661 | + $registrations = EEM_Registration::instance()->count( |
|
| 662 | + [ |
|
| 663 | + [ |
|
| 664 | + 'STS_ID' => ['!=', RegStatus::INCOMPLETE], |
|
| 665 | + ], |
|
| 666 | + ] |
|
| 667 | + ); |
|
| 668 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 669 | + ['page' => 'espresso_registrations'], |
|
| 670 | + admin_url('admin.php') |
|
| 671 | + ); |
|
| 672 | + $items['registrations']['text'] = sprintf( |
|
| 673 | + esc_html( |
|
| 674 | + _n('%s Registration', '%s Registrations', $registrations, 'event_espresso') |
|
| 675 | + ), |
|
| 676 | + number_format_i18n($registrations) |
|
| 677 | + ); |
|
| 678 | + $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
| 679 | + |
|
| 680 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 681 | + |
|
| 682 | + foreach ($items as $type => $item_properties) { |
|
| 683 | + $elements[] = sprintf( |
|
| 684 | + '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 685 | + $item_properties['url'], |
|
| 686 | + $item_properties['title'], |
|
| 687 | + $item_properties['text'] |
|
| 688 | + ); |
|
| 689 | + } |
|
| 690 | + return $elements; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * check_for_invalid_datetime_formats |
|
| 696 | + * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 697 | + * their selected format can be parsed by PHP |
|
| 698 | + * |
|
| 699 | + * @param $value |
|
| 700 | + * @param $option |
|
| 701 | + * @return string |
|
| 702 | + */ |
|
| 703 | + public function check_for_invalid_datetime_formats($value, $option) |
|
| 704 | + { |
|
| 705 | + // check for date_format or time_format |
|
| 706 | + switch ($option) { |
|
| 707 | + case 'date_format': |
|
| 708 | + $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 709 | + break; |
|
| 710 | + case 'time_format': |
|
| 711 | + $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 712 | + break; |
|
| 713 | + default: |
|
| 714 | + $date_time_format = false; |
|
| 715 | + } |
|
| 716 | + // do we have a date_time format to check ? |
|
| 717 | + if ($date_time_format) { |
|
| 718 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 719 | + |
|
| 720 | + if (is_array($error_msg)) { |
|
| 721 | + $msg = '<p>' |
|
| 722 | + . sprintf( |
|
| 723 | + esc_html__( |
|
| 724 | + 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 725 | + 'event_espresso' |
|
| 726 | + ), |
|
| 727 | + date($date_time_format), |
|
| 728 | + $date_time_format |
|
| 729 | + ) |
|
| 730 | + . '</p><p><ul>'; |
|
| 731 | + |
|
| 732 | + |
|
| 733 | + foreach ($error_msg as $error) { |
|
| 734 | + $msg .= '<li>' . $error . '</li>'; |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + $msg .= '</ul></p><p>' |
|
| 738 | + . sprintf( |
|
| 739 | + esc_html__( |
|
| 740 | + '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 741 | + 'event_espresso' |
|
| 742 | + ), |
|
| 743 | + '<span style="color:#D54E21;">', |
|
| 744 | + '</span>' |
|
| 745 | + ) |
|
| 746 | + . '</p>'; |
|
| 747 | + |
|
| 748 | + // trigger WP settings error |
|
| 749 | + add_settings_error( |
|
| 750 | + 'date_format', |
|
| 751 | + 'date_format', |
|
| 752 | + $msg |
|
| 753 | + ); |
|
| 754 | + |
|
| 755 | + // set format to something valid |
|
| 756 | + switch ($option) { |
|
| 757 | + case 'date_format': |
|
| 758 | + $value = 'F j, Y'; |
|
| 759 | + break; |
|
| 760 | + case 'time_format': |
|
| 761 | + $value = 'g:i a'; |
|
| 762 | + break; |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + } |
|
| 766 | + return $value; |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 772 | + * |
|
| 773 | + * @param $content |
|
| 774 | + * @return string |
|
| 775 | + */ |
|
| 776 | + public function its_eSpresso($content) |
|
| 777 | + { |
|
| 778 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + |
|
| 782 | + /** |
|
| 783 | + * espresso_admin_footer |
|
| 784 | + * |
|
| 785 | + * @return string |
|
| 786 | + */ |
|
| 787 | + public function espresso_admin_footer() |
|
| 788 | + { |
|
| 789 | + return EEH_Template::powered_by_event_espresso('aln-cntr', '', ['utm_content' => 'admin_footer']); |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * Hooks into the "post states" filter in a wp post type list table. |
|
| 795 | + * |
|
| 796 | + * @param array $post_states |
|
| 797 | + * @param WP_Post $post |
|
| 798 | + * @return array |
|
| 799 | + * @throws InvalidArgumentException |
|
| 800 | + * @throws InvalidDataTypeException |
|
| 801 | + * @throws InvalidInterfaceException |
|
| 802 | + */ |
|
| 803 | + public function displayStateForCriticalPages($post_states, $post) |
|
| 804 | + { |
|
| 805 | + $post_states = (array) $post_states; |
|
| 806 | + if (! $post instanceof WP_Post || $post->post_type !== 'page') { |
|
| 807 | + return $post_states; |
|
| 808 | + } |
|
| 809 | + /** @var EE_Core_Config $config */ |
|
| 810 | + $config = $this->loader->getShared('EE_Config')->core; |
|
| 811 | + if (in_array($post->ID, $config->get_critical_pages_array(), true)) { |
|
| 812 | + $post_states[] = sprintf( |
|
| 813 | + /* Translators: Using company name - Event Espresso Critical Page */ |
|
| 814 | + esc_html__('%s Critical Page', 'event_espresso'), |
|
| 815 | + 'Event Espresso' |
|
| 816 | + ); |
|
| 817 | + } |
|
| 818 | + return $post_states; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + /** |
|
| 823 | + * Show documentation links on the plugins page |
|
| 824 | + * |
|
| 825 | + * @param mixed $meta Plugin Row Meta |
|
| 826 | + * @param mixed $file Plugin Base file |
|
| 827 | + * @return array |
|
| 828 | + */ |
|
| 829 | + public function addLinksToPluginRowMeta($meta, $file) |
|
| 830 | + { |
|
| 831 | + if (EE_PLUGIN_BASENAME === $file) { |
|
| 832 | + $row_meta = [ |
|
| 833 | + 'docs' => '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4"' |
|
| 834 | + . ' aria-label="' |
|
| 835 | + . esc_attr__('View Event Espresso documentation', 'event_espresso') |
|
| 836 | + . '">' |
|
| 837 | + . esc_html__('Docs', 'event_espresso') |
|
| 838 | + . '</a>', |
|
| 839 | + 'api' => '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API"' |
|
| 840 | + . ' aria-label="' |
|
| 841 | + . esc_attr__('View Event Espresso API docs', 'event_espresso') |
|
| 842 | + . '">' |
|
| 843 | + . esc_html__('API docs', 'event_espresso') |
|
| 844 | + . '</a>', |
|
| 845 | + ]; |
|
| 846 | + return array_merge($meta, $row_meta); |
|
| 847 | + } |
|
| 848 | + return (array) $meta; |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + /**************************************************************************************/ |
|
| 852 | + /************************************* DEPRECATED *************************************/ |
|
| 853 | + /**************************************************************************************/ |
|
| 854 | + |
|
| 855 | + |
|
| 856 | + /** |
|
| 857 | + * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 858 | + * EE_Admin_Page route is called. |
|
| 859 | + * |
|
| 860 | + * @return void |
|
| 861 | + */ |
|
| 862 | + public function route_admin_request() |
|
| 863 | + { |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + |
|
| 867 | + /** |
|
| 868 | + * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 869 | + * |
|
| 870 | + * @return void |
|
| 871 | + */ |
|
| 872 | + public function wp_loaded() |
|
| 873 | + { |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + |
|
| 877 | + /** |
|
| 878 | + * static method for registering ee admin page. |
|
| 879 | + * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 880 | + * |
|
| 881 | + * @param $page_basename |
|
| 882 | + * @param $page_path |
|
| 883 | + * @param array $config |
|
| 884 | + * @return void |
|
| 885 | + * @throws EE_Error |
|
| 886 | + * @see EE_Register_Admin_Page::register() |
|
| 887 | + * @since 4.3.0 |
|
| 888 | + * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 889 | + */ |
|
| 890 | + public static function register_ee_admin_page($page_basename, $page_path, $config = []) |
|
| 891 | + { |
|
| 892 | + EE_Error::doing_it_wrong( |
|
| 893 | + __METHOD__, |
|
| 894 | + sprintf( |
|
| 895 | + esc_html__( |
|
| 896 | + 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 897 | + 'event_espresso' |
|
| 898 | + ), |
|
| 899 | + $page_basename |
|
| 900 | + ), |
|
| 901 | + '4.3' |
|
| 902 | + ); |
|
| 903 | + if (class_exists('EE_Register_Admin_Page')) { |
|
| 904 | + $config['page_path'] = $page_path; |
|
| 905 | + } |
|
| 906 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * @param int $post_ID |
|
| 912 | + * @param WP_Post $post |
|
| 913 | + * @return void |
|
| 914 | + * @deprecated 4.8.41 |
|
| 915 | + */ |
|
| 916 | + public static function parse_post_content_on_save($post_ID, $post) |
|
| 917 | + { |
|
| 918 | + EE_Error::doing_it_wrong( |
|
| 919 | + __METHOD__, |
|
| 920 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 921 | + '4.8.41' |
|
| 922 | + ); |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * @param $option |
|
| 928 | + * @param $old_value |
|
| 929 | + * @param $value |
|
| 930 | + * @return void |
|
| 931 | + * @deprecated 4.8.41 |
|
| 932 | + */ |
|
| 933 | + public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 934 | + { |
|
| 935 | + EE_Error::doing_it_wrong( |
|
| 936 | + __METHOD__, |
|
| 937 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 938 | + '4.8.41' |
|
| 939 | + ); |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + |
|
| 943 | + /** |
|
| 944 | + * @return void |
|
| 945 | + * @deprecated 4.9.27 |
|
| 946 | + */ |
|
| 947 | + public function get_persistent_admin_notices() |
|
| 948 | + { |
|
| 949 | + EE_Error::doing_it_wrong( |
|
| 950 | + __METHOD__, |
|
| 951 | + sprintf( |
|
| 952 | + esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 953 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 954 | + ), |
|
| 955 | + '4.9.27' |
|
| 956 | + ); |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + |
|
| 960 | + /** |
|
| 961 | + * @throws InvalidInterfaceException |
|
| 962 | + * @throws InvalidDataTypeException |
|
| 963 | + * @throws DomainException |
|
| 964 | + * @deprecated 4.9.27 |
|
| 965 | + */ |
|
| 966 | + public function dismiss_ee_nag_notice_callback() |
|
| 967 | + { |
|
| 968 | + EE_Error::doing_it_wrong( |
|
| 969 | + __METHOD__, |
|
| 970 | + sprintf( |
|
| 971 | + esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 972 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 973 | + ), |
|
| 974 | + '4.9.27' |
|
| 975 | + ); |
|
| 976 | + $this->persistent_admin_notice_manager->dismissNotice(); |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + |
|
| 980 | + /** |
|
| 981 | + * @return void |
|
| 982 | + * @deprecated 5.0.0.p |
|
| 983 | + */ |
|
| 984 | + public function enqueue_admin_scripts() |
|
| 985 | + { |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + |
|
| 989 | + |
|
| 990 | + /** |
|
| 991 | + * @return RequestInterface |
|
| 992 | + * @deprecated 5.0.0.p |
|
| 993 | + */ |
|
| 994 | + public function get_request() |
|
| 995 | + { |
|
| 996 | + EE_Error::doing_it_wrong( |
|
| 997 | + __METHOD__, |
|
| 998 | + sprintf( |
|
| 999 | + esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
| 1000 | + 'EventEspresso\core\services\request\Request' |
|
| 1001 | + ), |
|
| 1002 | + '5.0.0.p' |
|
| 1003 | + ); |
|
| 1004 | + return $this->request; |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + |
|
| 1008 | + /** |
|
| 1009 | + * @deprecated 5.0.0.p |
|
| 1010 | + */ |
|
| 1011 | + public function hookIntoWpPluginsPage() |
|
| 1012 | + { |
|
| 1013 | + } |
|
| 1014 | 1014 | } |
@@ -18,443 +18,443 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class EE_Admin_Page_Loader |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var AdminMenuManager $menu_manager |
|
| 23 | - */ |
|
| 24 | - protected $menu_manager; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var LoaderInterface $loader |
|
| 28 | - */ |
|
| 29 | - protected $loader; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * _installed_pages |
|
| 33 | - * objects for page_init objects detected and loaded |
|
| 34 | - * |
|
| 35 | - * @access private |
|
| 36 | - * @var EE_Admin_Page_Init[] |
|
| 37 | - */ |
|
| 38 | - private $_installed_pages = []; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * this is used to hold the registry of menu slugs for all the installed admin pages |
|
| 43 | - * |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - private $_menu_slugs = []; |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * _caffeinated_extends |
|
| 51 | - * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
| 52 | - * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
| 53 | - * |
|
| 54 | - * @var array |
|
| 55 | - */ |
|
| 56 | - private $_caffeinated_extends = []; |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
| 61 | - * pages. |
|
| 62 | - * |
|
| 63 | - * @var string |
|
| 64 | - */ |
|
| 65 | - public $hook_file; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var bool |
|
| 69 | - * @since 5.0.0.p |
|
| 70 | - */ |
|
| 71 | - private bool $full_site_maintenance = false; |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @throws InvalidArgumentException |
|
| 76 | - * @throws InvalidDataTypeException |
|
| 77 | - * @throws InvalidInterfaceException |
|
| 78 | - */ |
|
| 79 | - public function __construct(?LoaderInterface $loader) |
|
| 80 | - { |
|
| 81 | - $this->loader = $loader instanceof LoaderInterface ? $loader : LoaderFactory::getLoader(); |
|
| 82 | - $this->menu_manager = $this->loader->getShared(AdminMenuManager::class); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @throws EE_Error |
|
| 88 | - * @throws ReflectionException |
|
| 89 | - * @since 5.0.0.p |
|
| 90 | - */ |
|
| 91 | - public function init() |
|
| 92 | - { |
|
| 93 | - $this->menu_manager->initialize(); |
|
| 94 | - $this->full_site_maintenance = MaintenanceStatus::isFullSite(); |
|
| 95 | - // let's do a scan and see what installed pages we have |
|
| 96 | - $this->findAndLoadAdminPages(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
| 102 | - * files in the caffeinated folder. |
|
| 103 | - * |
|
| 104 | - * @access private |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - private function defineCaffeinatedConstants() |
|
| 108 | - { |
|
| 109 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
| 110 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
| 111 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
| 112 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
| 113 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
| 114 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
| 115 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * This just gets the list of installed EE_Admin_pages. |
|
| 122 | - * |
|
| 123 | - * @access private |
|
| 124 | - * @return void |
|
| 125 | - * @throws EE_Error |
|
| 126 | - * @throws InvalidArgumentException |
|
| 127 | - * @throws InvalidDataTypeException |
|
| 128 | - * @throws InvalidInterfaceException |
|
| 129 | - * @throws ReflectionException |
|
| 130 | - */ |
|
| 131 | - private function findAndLoadAdminPages() |
|
| 132 | - { |
|
| 133 | - $admin_pages = $this->findAdminPages(); |
|
| 134 | - // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
| 135 | - $admin_pages = $this->findCaffeinatedAdminPages($admin_pages); |
|
| 136 | - // then extensions and hooks, although they don't get added to the admin pages array |
|
| 137 | - $this->findAdminPageExtensions(); |
|
| 138 | - $this->findAdminPageHooks(); |
|
| 139 | - // allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
| 140 | - // loop through admin pages and setup the $_installed_pages array. |
|
| 141 | - $hooks_ref = []; |
|
| 142 | - $menu_pages = []; |
|
| 143 | - foreach ($admin_pages as $page => $path) { |
|
| 144 | - // don't load the page init class IF IT's ALREADY LOADED !!! |
|
| 145 | - if ( |
|
| 146 | - isset($this->_installed_pages[ $page ]) |
|
| 147 | - && $this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init |
|
| 148 | - ) { |
|
| 149 | - continue; |
|
| 150 | - } |
|
| 151 | - // build list of installed pages |
|
| 152 | - $admin_page_init = $this->loadAdminPageInit($page); |
|
| 153 | - $this->_installed_pages[ $page ] = $admin_page_init; |
|
| 154 | - $admin_menu = $this->menu_manager->getAdminMenu($admin_page_init); |
|
| 155 | - $admin_page_init->setCapability($admin_menu->capability(), $admin_menu->menuSlug()); |
|
| 156 | - // skip if in full maintenance mode and maintenance_mode_parent is NOT set |
|
| 157 | - if ($this->full_site_maintenance && ! $admin_menu->maintenanceModeParent()) { |
|
| 158 | - unset($admin_pages[ $page ]); |
|
| 159 | - continue; |
|
| 160 | - } |
|
| 161 | - $menu_slug = $admin_menu->menuSlug(); |
|
| 162 | - $this->_menu_slugs[ $menu_slug ] = $page; |
|
| 163 | - $menu_pages[ $menu_slug ] = $admin_page_init; |
|
| 164 | - // now that we've got the admin_init objects... |
|
| 165 | - // lets see if there are any caffeinated pages extending the originals. |
|
| 166 | - // If there are then let's hook into the init admin filter and load our extend instead. |
|
| 167 | - // Set flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
| 168 | - $extended_hooks = $admin_page_init->register_hooks( |
|
| 169 | - $this->loadCaffeinatedExtensions($admin_page_init, $page, $menu_slug) |
|
| 170 | - ); |
|
| 171 | - $hooks_ref += $extended_hooks; |
|
| 172 | - } |
|
| 173 | - // the hooks_ref is all the pages where we have $extended _Hooks files |
|
| 174 | - // that will extend a class in a different folder. |
|
| 175 | - // So we want to make sure we load the file for the parent. |
|
| 176 | - // first make sure we've got unique values |
|
| 177 | - $hooks_ref = array_unique($hooks_ref); |
|
| 178 | - // now let's loop and require! |
|
| 179 | - foreach ($hooks_ref as $path) { |
|
| 180 | - require_once($path); |
|
| 181 | - } |
|
| 182 | - // make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
| 183 | - global $ee_menu_slugs; |
|
| 184 | - $ee_menu_slugs = $this->_menu_slugs; |
|
| 185 | - // we need to loop again to run any early code |
|
| 186 | - foreach ($this->_installed_pages as $page) { |
|
| 187 | - $page->do_initial_loads(); |
|
| 188 | - } |
|
| 189 | - $this->menu_manager->setInstalledPages($menu_pages); |
|
| 190 | - do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @return array |
|
| 196 | - * @throws EE_Error |
|
| 197 | - * @since 5.0.0.p |
|
| 198 | - */ |
|
| 199 | - private function findAdminPages(): array |
|
| 200 | - { |
|
| 201 | - |
|
| 202 | - // grab everything in the admin core directory |
|
| 203 | - $admin_page_folders = $this->findAdminPageFolders(EE_ADMIN_PAGES . '*'); |
|
| 204 | - $admin_page_folders = apply_filters( |
|
| 205 | - 'FHEE__EE_Admin_Page_Loader__findAdminPages__admin_page_folders', |
|
| 206 | - $admin_page_folders |
|
| 207 | - ); |
|
| 208 | - if (! empty($admin_page_folders)) { |
|
| 209 | - return $admin_page_folders; |
|
| 210 | - } |
|
| 211 | - $error_msg = esc_html__( |
|
| 212 | - 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
| 213 | - 'event_espresso' |
|
| 214 | - ); |
|
| 215 | - $error_msg .= '||'; |
|
| 216 | - $error_msg .= sprintf( |
|
| 217 | - esc_html__( |
|
| 218 | - 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
| 219 | - 'event_espresso' |
|
| 220 | - ), |
|
| 221 | - EE_ADMIN_PAGES |
|
| 222 | - ); |
|
| 223 | - throw new RuntimeException($error_msg); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * get_admin_page_object |
|
| 229 | - * |
|
| 230 | - * @param string $page_slug |
|
| 231 | - * @return EE_Admin_Page |
|
| 232 | - */ |
|
| 233 | - public function get_admin_page_object(string $page_slug = ''): ?EE_Admin_Page |
|
| 234 | - { |
|
| 235 | - return isset($this->_installed_pages[ $page_slug ]) |
|
| 236 | - && $this->_installed_pages[ $page_slug ] instanceof EE_Admin_Page_Init |
|
| 237 | - ? $this->_installed_pages[ $page_slug ]->loaded_page_object() |
|
| 238 | - : null; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * generates an "Admin Page Init" class based on the directory name |
|
| 244 | - * |
|
| 245 | - * @param string $dir_name |
|
| 246 | - * @return string |
|
| 247 | - */ |
|
| 248 | - private function getClassnameForAdminPageInit(string $dir_name = ''): string |
|
| 249 | - { |
|
| 250 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
| 251 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * _load_admin_page |
|
| 257 | - * Loads and instantiates page_init object for a single EE_admin page. |
|
| 258 | - * |
|
| 259 | - * @param string $page page_reference |
|
| 260 | - * @return EE_Admin_Page_Init |
|
| 261 | - * @throws EE_Error |
|
| 262 | - */ |
|
| 263 | - private function loadAdminPageInit(string $page = ''): EE_Admin_Page_Init |
|
| 264 | - { |
|
| 265 | - $class_name = $this->getClassnameForAdminPageInit($page); |
|
| 266 | - if (class_exists($class_name)) { |
|
| 267 | - $admin_page_init = $this->loader->getShared($class_name); |
|
| 268 | - // verify returned object |
|
| 269 | - if ($admin_page_init instanceof EE_Admin_Page_Init) { |
|
| 270 | - return $admin_page_init; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - $error_msg = sprintf( |
|
| 274 | - esc_html__('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
| 275 | - $page |
|
| 276 | - ); |
|
| 277 | - $error_msg .= '||'; // separates public from developer messages |
|
| 278 | - $error_msg .= "\r\n"; |
|
| 279 | - $error_msg .= sprintf( |
|
| 280 | - esc_html__('There is no Init class in place for the %s admin page.', 'event_espresso'), |
|
| 281 | - $page |
|
| 282 | - ); |
|
| 283 | - $error_msg .= '<br />'; |
|
| 284 | - $error_msg .= sprintf( |
|
| 285 | - esc_html__( |
|
| 286 | - 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 287 | - 'event_espresso' |
|
| 288 | - ), |
|
| 289 | - '<strong>' . $class_name . '</strong>' |
|
| 290 | - ); |
|
| 291 | - throw new EE_Error($error_msg); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
| 297 | - * In this method there are three checks being done: |
|
| 298 | - * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $admin_pages |
|
| 299 | - * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
| 300 | - * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
| 301 | - * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
| 302 | - * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
| 303 | - * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
| 304 | - * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
| 305 | - * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
| 306 | - * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
| 307 | - * admin_pages) |
|
| 308 | - * |
|
| 309 | - * @param array $admin_pages the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
| 310 | - * loaded. |
|
| 311 | - * @return array |
|
| 312 | - * @throws EE_Error |
|
| 313 | - */ |
|
| 314 | - private function findCaffeinatedAdminPages(array $admin_pages): array |
|
| 315 | - { |
|
| 316 | - // first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
| 317 | - if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin')) { |
|
| 318 | - return $admin_pages; |
|
| 319 | - } |
|
| 320 | - $this->defineCaffeinatedConstants(); |
|
| 321 | - |
|
| 322 | - $exclude = ['tickets']; |
|
| 323 | - $feature = $this->loader->getShared(FeatureFlags::class); |
|
| 324 | - if (! $feature->allowed('use_edd_plugin_licensing')) { |
|
| 325 | - $exclude[] = 'license_keys'; |
|
| 326 | - } |
|
| 327 | - // okay let's setup an "New" pages first (we'll return installed refs later) |
|
| 328 | - $admin_pages += $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'new/*', $exclude); |
|
| 329 | - |
|
| 330 | - return apply_filters( |
|
| 331 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
| 332 | - $admin_pages |
|
| 333 | - ); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * @throws EE_Error |
|
| 339 | - * @since 5.0.0.p |
|
| 340 | - */ |
|
| 341 | - private function findAdminPageExtensions() |
|
| 342 | - { |
|
| 343 | - // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array |
|
| 344 | - // (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
| 345 | - $extensions = $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'extend/*'); |
|
| 346 | - if ($extensions) { |
|
| 347 | - foreach ($extensions as $folder => $extension) { |
|
| 348 | - // convert lowercase_snake_case to Uppercase_Snake_Case |
|
| 349 | - $filename = str_replace(' ', '_', ucwords(str_replace('_', ' ', $folder))); |
|
| 350 | - $filename = "Extend_{$filename}_Admin_Page"; |
|
| 351 | - $filepath = EE_CORE_CAF_ADMIN . "extend/$folder/$filename.core.php"; |
|
| 352 | - // save filename and filepath for later |
|
| 353 | - $this->_caffeinated_extends[ $folder ]['path'] = str_replace(['\\', '/'], '/', $filepath); |
|
| 354 | - $this->_caffeinated_extends[ $folder ]['admin_page'] = $filename; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - $this->_caffeinated_extends = apply_filters( |
|
| 358 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
| 359 | - $this->_caffeinated_extends |
|
| 360 | - ); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - private function loadCaffeinatedExtensions( |
|
| 365 | - EE_Admin_Page_Init $admin_page_init, |
|
| 366 | - string $page, |
|
| 367 | - string $menu_slug |
|
| 368 | - ): bool { |
|
| 369 | - if (! isset($this->_caffeinated_extends[ $page ])) { |
|
| 370 | - return false; |
|
| 371 | - } |
|
| 372 | - $admin_page_name = $admin_page_init->get_admin_page_name(); |
|
| 373 | - $caf_path = $this->_caffeinated_extends[ $page ]['path']; |
|
| 374 | - $caf_admin_page = $this->_caffeinated_extends[ $page ]['admin_page']; |
|
| 375 | - add_filter( |
|
| 376 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_$admin_page_name", |
|
| 377 | - static function ($path_to_file) use ($caf_path) { |
|
| 378 | - return $caf_path; |
|
| 379 | - } |
|
| 380 | - ); |
|
| 381 | - add_filter( |
|
| 382 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_$admin_page_name", |
|
| 383 | - static function ($admin_page) use ($caf_admin_page) { |
|
| 384 | - return $caf_admin_page; |
|
| 385 | - } |
|
| 386 | - ); |
|
| 387 | - return true; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * @throws EE_Error |
|
| 393 | - * @since 5.0.0.p |
|
| 394 | - */ |
|
| 395 | - private function findAdminPageHooks() |
|
| 396 | - { |
|
| 397 | - // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
| 398 | - $ee_admin_hooks = []; |
|
| 399 | - $admin_page_hooks = $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'hooks/*.class.php', [], 0, false); |
|
| 400 | - if ($admin_page_hooks) { |
|
| 401 | - foreach ($admin_page_hooks as $hook) { |
|
| 402 | - if (is_readable($hook)) { |
|
| 403 | - require_once $hook; |
|
| 404 | - $classname = str_replace([EE_CORE_CAF_ADMIN . 'hooks/', '.class.php'], '', $hook); |
|
| 405 | - if (class_exists($classname)) { |
|
| 406 | - $ee_admin_hooks[] = $this->loader->getShared($classname); |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * _default_header_link |
|
| 417 | - * This is just a dummy method to use with header submenu items |
|
| 418 | - * |
|
| 419 | - * @return bool false |
|
| 420 | - */ |
|
| 421 | - public function _default_header_link(): bool |
|
| 422 | - { |
|
| 423 | - return false; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * @param string $path |
|
| 429 | - * @param int $flags |
|
| 430 | - * @param array $exclude |
|
| 431 | - * @param bool $register_autoloaders |
|
| 432 | - * @return array |
|
| 433 | - * @throws EE_Error |
|
| 434 | - * @since 5.0.0.p |
|
| 435 | - */ |
|
| 436 | - private function findAdminPageFolders( |
|
| 437 | - string $path, |
|
| 438 | - array $exclude = [], |
|
| 439 | - int $flags = GLOB_ONLYDIR, |
|
| 440 | - bool $register_autoloaders = true |
|
| 441 | - ): array { |
|
| 442 | - $folders = []; |
|
| 443 | - $subfolders = glob($path, $flags); |
|
| 444 | - if ($subfolders) { |
|
| 445 | - foreach ($subfolders as $admin_screen) { |
|
| 446 | - $admin_screen_name = basename($admin_screen); |
|
| 447 | - // files and anything in the exclude array need not apply |
|
| 448 | - if (! in_array($admin_screen_name, $exclude, true)) { |
|
| 449 | - // these folders represent the different EE admin pages |
|
| 450 | - $folders[ $admin_screen_name ] = $admin_screen; |
|
| 451 | - if ($register_autoloaders) { |
|
| 452 | - // set autoloaders for our admin page classes based on included path information |
|
| 453 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($admin_screen); |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - return $folders; |
|
| 459 | - } |
|
| 21 | + /** |
|
| 22 | + * @var AdminMenuManager $menu_manager |
|
| 23 | + */ |
|
| 24 | + protected $menu_manager; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var LoaderInterface $loader |
|
| 28 | + */ |
|
| 29 | + protected $loader; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * _installed_pages |
|
| 33 | + * objects for page_init objects detected and loaded |
|
| 34 | + * |
|
| 35 | + * @access private |
|
| 36 | + * @var EE_Admin_Page_Init[] |
|
| 37 | + */ |
|
| 38 | + private $_installed_pages = []; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * this is used to hold the registry of menu slugs for all the installed admin pages |
|
| 43 | + * |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + private $_menu_slugs = []; |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * _caffeinated_extends |
|
| 51 | + * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
| 52 | + * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
| 53 | + * |
|
| 54 | + * @var array |
|
| 55 | + */ |
|
| 56 | + private $_caffeinated_extends = []; |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
| 61 | + * pages. |
|
| 62 | + * |
|
| 63 | + * @var string |
|
| 64 | + */ |
|
| 65 | + public $hook_file; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var bool |
|
| 69 | + * @since 5.0.0.p |
|
| 70 | + */ |
|
| 71 | + private bool $full_site_maintenance = false; |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @throws InvalidArgumentException |
|
| 76 | + * @throws InvalidDataTypeException |
|
| 77 | + * @throws InvalidInterfaceException |
|
| 78 | + */ |
|
| 79 | + public function __construct(?LoaderInterface $loader) |
|
| 80 | + { |
|
| 81 | + $this->loader = $loader instanceof LoaderInterface ? $loader : LoaderFactory::getLoader(); |
|
| 82 | + $this->menu_manager = $this->loader->getShared(AdminMenuManager::class); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @throws EE_Error |
|
| 88 | + * @throws ReflectionException |
|
| 89 | + * @since 5.0.0.p |
|
| 90 | + */ |
|
| 91 | + public function init() |
|
| 92 | + { |
|
| 93 | + $this->menu_manager->initialize(); |
|
| 94 | + $this->full_site_maintenance = MaintenanceStatus::isFullSite(); |
|
| 95 | + // let's do a scan and see what installed pages we have |
|
| 96 | + $this->findAndLoadAdminPages(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
| 102 | + * files in the caffeinated folder. |
|
| 103 | + * |
|
| 104 | + * @access private |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + private function defineCaffeinatedConstants() |
|
| 108 | + { |
|
| 109 | + if (! defined('EE_CORE_CAF_ADMIN')) { |
|
| 110 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
| 111 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
| 112 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
| 113 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
| 114 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
| 115 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * This just gets the list of installed EE_Admin_pages. |
|
| 122 | + * |
|
| 123 | + * @access private |
|
| 124 | + * @return void |
|
| 125 | + * @throws EE_Error |
|
| 126 | + * @throws InvalidArgumentException |
|
| 127 | + * @throws InvalidDataTypeException |
|
| 128 | + * @throws InvalidInterfaceException |
|
| 129 | + * @throws ReflectionException |
|
| 130 | + */ |
|
| 131 | + private function findAndLoadAdminPages() |
|
| 132 | + { |
|
| 133 | + $admin_pages = $this->findAdminPages(); |
|
| 134 | + // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
| 135 | + $admin_pages = $this->findCaffeinatedAdminPages($admin_pages); |
|
| 136 | + // then extensions and hooks, although they don't get added to the admin pages array |
|
| 137 | + $this->findAdminPageExtensions(); |
|
| 138 | + $this->findAdminPageHooks(); |
|
| 139 | + // allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
| 140 | + // loop through admin pages and setup the $_installed_pages array. |
|
| 141 | + $hooks_ref = []; |
|
| 142 | + $menu_pages = []; |
|
| 143 | + foreach ($admin_pages as $page => $path) { |
|
| 144 | + // don't load the page init class IF IT's ALREADY LOADED !!! |
|
| 145 | + if ( |
|
| 146 | + isset($this->_installed_pages[ $page ]) |
|
| 147 | + && $this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init |
|
| 148 | + ) { |
|
| 149 | + continue; |
|
| 150 | + } |
|
| 151 | + // build list of installed pages |
|
| 152 | + $admin_page_init = $this->loadAdminPageInit($page); |
|
| 153 | + $this->_installed_pages[ $page ] = $admin_page_init; |
|
| 154 | + $admin_menu = $this->menu_manager->getAdminMenu($admin_page_init); |
|
| 155 | + $admin_page_init->setCapability($admin_menu->capability(), $admin_menu->menuSlug()); |
|
| 156 | + // skip if in full maintenance mode and maintenance_mode_parent is NOT set |
|
| 157 | + if ($this->full_site_maintenance && ! $admin_menu->maintenanceModeParent()) { |
|
| 158 | + unset($admin_pages[ $page ]); |
|
| 159 | + continue; |
|
| 160 | + } |
|
| 161 | + $menu_slug = $admin_menu->menuSlug(); |
|
| 162 | + $this->_menu_slugs[ $menu_slug ] = $page; |
|
| 163 | + $menu_pages[ $menu_slug ] = $admin_page_init; |
|
| 164 | + // now that we've got the admin_init objects... |
|
| 165 | + // lets see if there are any caffeinated pages extending the originals. |
|
| 166 | + // If there are then let's hook into the init admin filter and load our extend instead. |
|
| 167 | + // Set flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
| 168 | + $extended_hooks = $admin_page_init->register_hooks( |
|
| 169 | + $this->loadCaffeinatedExtensions($admin_page_init, $page, $menu_slug) |
|
| 170 | + ); |
|
| 171 | + $hooks_ref += $extended_hooks; |
|
| 172 | + } |
|
| 173 | + // the hooks_ref is all the pages where we have $extended _Hooks files |
|
| 174 | + // that will extend a class in a different folder. |
|
| 175 | + // So we want to make sure we load the file for the parent. |
|
| 176 | + // first make sure we've got unique values |
|
| 177 | + $hooks_ref = array_unique($hooks_ref); |
|
| 178 | + // now let's loop and require! |
|
| 179 | + foreach ($hooks_ref as $path) { |
|
| 180 | + require_once($path); |
|
| 181 | + } |
|
| 182 | + // make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
| 183 | + global $ee_menu_slugs; |
|
| 184 | + $ee_menu_slugs = $this->_menu_slugs; |
|
| 185 | + // we need to loop again to run any early code |
|
| 186 | + foreach ($this->_installed_pages as $page) { |
|
| 187 | + $page->do_initial_loads(); |
|
| 188 | + } |
|
| 189 | + $this->menu_manager->setInstalledPages($menu_pages); |
|
| 190 | + do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @return array |
|
| 196 | + * @throws EE_Error |
|
| 197 | + * @since 5.0.0.p |
|
| 198 | + */ |
|
| 199 | + private function findAdminPages(): array |
|
| 200 | + { |
|
| 201 | + |
|
| 202 | + // grab everything in the admin core directory |
|
| 203 | + $admin_page_folders = $this->findAdminPageFolders(EE_ADMIN_PAGES . '*'); |
|
| 204 | + $admin_page_folders = apply_filters( |
|
| 205 | + 'FHEE__EE_Admin_Page_Loader__findAdminPages__admin_page_folders', |
|
| 206 | + $admin_page_folders |
|
| 207 | + ); |
|
| 208 | + if (! empty($admin_page_folders)) { |
|
| 209 | + return $admin_page_folders; |
|
| 210 | + } |
|
| 211 | + $error_msg = esc_html__( |
|
| 212 | + 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
| 213 | + 'event_espresso' |
|
| 214 | + ); |
|
| 215 | + $error_msg .= '||'; |
|
| 216 | + $error_msg .= sprintf( |
|
| 217 | + esc_html__( |
|
| 218 | + 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
| 219 | + 'event_espresso' |
|
| 220 | + ), |
|
| 221 | + EE_ADMIN_PAGES |
|
| 222 | + ); |
|
| 223 | + throw new RuntimeException($error_msg); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * get_admin_page_object |
|
| 229 | + * |
|
| 230 | + * @param string $page_slug |
|
| 231 | + * @return EE_Admin_Page |
|
| 232 | + */ |
|
| 233 | + public function get_admin_page_object(string $page_slug = ''): ?EE_Admin_Page |
|
| 234 | + { |
|
| 235 | + return isset($this->_installed_pages[ $page_slug ]) |
|
| 236 | + && $this->_installed_pages[ $page_slug ] instanceof EE_Admin_Page_Init |
|
| 237 | + ? $this->_installed_pages[ $page_slug ]->loaded_page_object() |
|
| 238 | + : null; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * generates an "Admin Page Init" class based on the directory name |
|
| 244 | + * |
|
| 245 | + * @param string $dir_name |
|
| 246 | + * @return string |
|
| 247 | + */ |
|
| 248 | + private function getClassnameForAdminPageInit(string $dir_name = ''): string |
|
| 249 | + { |
|
| 250 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
| 251 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * _load_admin_page |
|
| 257 | + * Loads and instantiates page_init object for a single EE_admin page. |
|
| 258 | + * |
|
| 259 | + * @param string $page page_reference |
|
| 260 | + * @return EE_Admin_Page_Init |
|
| 261 | + * @throws EE_Error |
|
| 262 | + */ |
|
| 263 | + private function loadAdminPageInit(string $page = ''): EE_Admin_Page_Init |
|
| 264 | + { |
|
| 265 | + $class_name = $this->getClassnameForAdminPageInit($page); |
|
| 266 | + if (class_exists($class_name)) { |
|
| 267 | + $admin_page_init = $this->loader->getShared($class_name); |
|
| 268 | + // verify returned object |
|
| 269 | + if ($admin_page_init instanceof EE_Admin_Page_Init) { |
|
| 270 | + return $admin_page_init; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + $error_msg = sprintf( |
|
| 274 | + esc_html__('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
| 275 | + $page |
|
| 276 | + ); |
|
| 277 | + $error_msg .= '||'; // separates public from developer messages |
|
| 278 | + $error_msg .= "\r\n"; |
|
| 279 | + $error_msg .= sprintf( |
|
| 280 | + esc_html__('There is no Init class in place for the %s admin page.', 'event_espresso'), |
|
| 281 | + $page |
|
| 282 | + ); |
|
| 283 | + $error_msg .= '<br />'; |
|
| 284 | + $error_msg .= sprintf( |
|
| 285 | + esc_html__( |
|
| 286 | + 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
| 287 | + 'event_espresso' |
|
| 288 | + ), |
|
| 289 | + '<strong>' . $class_name . '</strong>' |
|
| 290 | + ); |
|
| 291 | + throw new EE_Error($error_msg); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
| 297 | + * In this method there are three checks being done: |
|
| 298 | + * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $admin_pages |
|
| 299 | + * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
| 300 | + * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
| 301 | + * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
| 302 | + * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
| 303 | + * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
| 304 | + * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
| 305 | + * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
| 306 | + * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
| 307 | + * admin_pages) |
|
| 308 | + * |
|
| 309 | + * @param array $admin_pages the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
| 310 | + * loaded. |
|
| 311 | + * @return array |
|
| 312 | + * @throws EE_Error |
|
| 313 | + */ |
|
| 314 | + private function findCaffeinatedAdminPages(array $admin_pages): array |
|
| 315 | + { |
|
| 316 | + // first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
| 317 | + if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin')) { |
|
| 318 | + return $admin_pages; |
|
| 319 | + } |
|
| 320 | + $this->defineCaffeinatedConstants(); |
|
| 321 | + |
|
| 322 | + $exclude = ['tickets']; |
|
| 323 | + $feature = $this->loader->getShared(FeatureFlags::class); |
|
| 324 | + if (! $feature->allowed('use_edd_plugin_licensing')) { |
|
| 325 | + $exclude[] = 'license_keys'; |
|
| 326 | + } |
|
| 327 | + // okay let's setup an "New" pages first (we'll return installed refs later) |
|
| 328 | + $admin_pages += $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'new/*', $exclude); |
|
| 329 | + |
|
| 330 | + return apply_filters( |
|
| 331 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
| 332 | + $admin_pages |
|
| 333 | + ); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * @throws EE_Error |
|
| 339 | + * @since 5.0.0.p |
|
| 340 | + */ |
|
| 341 | + private function findAdminPageExtensions() |
|
| 342 | + { |
|
| 343 | + // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array |
|
| 344 | + // (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
| 345 | + $extensions = $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'extend/*'); |
|
| 346 | + if ($extensions) { |
|
| 347 | + foreach ($extensions as $folder => $extension) { |
|
| 348 | + // convert lowercase_snake_case to Uppercase_Snake_Case |
|
| 349 | + $filename = str_replace(' ', '_', ucwords(str_replace('_', ' ', $folder))); |
|
| 350 | + $filename = "Extend_{$filename}_Admin_Page"; |
|
| 351 | + $filepath = EE_CORE_CAF_ADMIN . "extend/$folder/$filename.core.php"; |
|
| 352 | + // save filename and filepath for later |
|
| 353 | + $this->_caffeinated_extends[ $folder ]['path'] = str_replace(['\\', '/'], '/', $filepath); |
|
| 354 | + $this->_caffeinated_extends[ $folder ]['admin_page'] = $filename; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + $this->_caffeinated_extends = apply_filters( |
|
| 358 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
| 359 | + $this->_caffeinated_extends |
|
| 360 | + ); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + private function loadCaffeinatedExtensions( |
|
| 365 | + EE_Admin_Page_Init $admin_page_init, |
|
| 366 | + string $page, |
|
| 367 | + string $menu_slug |
|
| 368 | + ): bool { |
|
| 369 | + if (! isset($this->_caffeinated_extends[ $page ])) { |
|
| 370 | + return false; |
|
| 371 | + } |
|
| 372 | + $admin_page_name = $admin_page_init->get_admin_page_name(); |
|
| 373 | + $caf_path = $this->_caffeinated_extends[ $page ]['path']; |
|
| 374 | + $caf_admin_page = $this->_caffeinated_extends[ $page ]['admin_page']; |
|
| 375 | + add_filter( |
|
| 376 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_$admin_page_name", |
|
| 377 | + static function ($path_to_file) use ($caf_path) { |
|
| 378 | + return $caf_path; |
|
| 379 | + } |
|
| 380 | + ); |
|
| 381 | + add_filter( |
|
| 382 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_$admin_page_name", |
|
| 383 | + static function ($admin_page) use ($caf_admin_page) { |
|
| 384 | + return $caf_admin_page; |
|
| 385 | + } |
|
| 386 | + ); |
|
| 387 | + return true; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * @throws EE_Error |
|
| 393 | + * @since 5.0.0.p |
|
| 394 | + */ |
|
| 395 | + private function findAdminPageHooks() |
|
| 396 | + { |
|
| 397 | + // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
| 398 | + $ee_admin_hooks = []; |
|
| 399 | + $admin_page_hooks = $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'hooks/*.class.php', [], 0, false); |
|
| 400 | + if ($admin_page_hooks) { |
|
| 401 | + foreach ($admin_page_hooks as $hook) { |
|
| 402 | + if (is_readable($hook)) { |
|
| 403 | + require_once $hook; |
|
| 404 | + $classname = str_replace([EE_CORE_CAF_ADMIN . 'hooks/', '.class.php'], '', $hook); |
|
| 405 | + if (class_exists($classname)) { |
|
| 406 | + $ee_admin_hooks[] = $this->loader->getShared($classname); |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * _default_header_link |
|
| 417 | + * This is just a dummy method to use with header submenu items |
|
| 418 | + * |
|
| 419 | + * @return bool false |
|
| 420 | + */ |
|
| 421 | + public function _default_header_link(): bool |
|
| 422 | + { |
|
| 423 | + return false; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * @param string $path |
|
| 429 | + * @param int $flags |
|
| 430 | + * @param array $exclude |
|
| 431 | + * @param bool $register_autoloaders |
|
| 432 | + * @return array |
|
| 433 | + * @throws EE_Error |
|
| 434 | + * @since 5.0.0.p |
|
| 435 | + */ |
|
| 436 | + private function findAdminPageFolders( |
|
| 437 | + string $path, |
|
| 438 | + array $exclude = [], |
|
| 439 | + int $flags = GLOB_ONLYDIR, |
|
| 440 | + bool $register_autoloaders = true |
|
| 441 | + ): array { |
|
| 442 | + $folders = []; |
|
| 443 | + $subfolders = glob($path, $flags); |
|
| 444 | + if ($subfolders) { |
|
| 445 | + foreach ($subfolders as $admin_screen) { |
|
| 446 | + $admin_screen_name = basename($admin_screen); |
|
| 447 | + // files and anything in the exclude array need not apply |
|
| 448 | + if (! in_array($admin_screen_name, $exclude, true)) { |
|
| 449 | + // these folders represent the different EE admin pages |
|
| 450 | + $folders[ $admin_screen_name ] = $admin_screen; |
|
| 451 | + if ($register_autoloaders) { |
|
| 452 | + // set autoloaders for our admin page classes based on included path information |
|
| 453 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($admin_screen); |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + return $folders; |
|
| 459 | + } |
|
| 460 | 460 | } |
@@ -106,13 +106,13 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | private function defineCaffeinatedConstants() |
| 108 | 108 | { |
| 109 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
| 110 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
| 111 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
| 112 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
| 113 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
| 114 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
| 115 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
| 109 | + if ( ! defined('EE_CORE_CAF_ADMIN')) { |
|
| 110 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/'); |
|
| 111 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/'); |
|
| 112 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/'); |
|
| 113 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/'); |
|
| 114 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/'); |
|
| 115 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/'); |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
@@ -143,24 +143,24 @@ discard block |
||
| 143 | 143 | foreach ($admin_pages as $page => $path) { |
| 144 | 144 | // don't load the page init class IF IT's ALREADY LOADED !!! |
| 145 | 145 | if ( |
| 146 | - isset($this->_installed_pages[ $page ]) |
|
| 147 | - && $this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init |
|
| 146 | + isset($this->_installed_pages[$page]) |
|
| 147 | + && $this->_installed_pages[$page] instanceof EE_Admin_Page_Init |
|
| 148 | 148 | ) { |
| 149 | 149 | continue; |
| 150 | 150 | } |
| 151 | 151 | // build list of installed pages |
| 152 | 152 | $admin_page_init = $this->loadAdminPageInit($page); |
| 153 | - $this->_installed_pages[ $page ] = $admin_page_init; |
|
| 153 | + $this->_installed_pages[$page] = $admin_page_init; |
|
| 154 | 154 | $admin_menu = $this->menu_manager->getAdminMenu($admin_page_init); |
| 155 | 155 | $admin_page_init->setCapability($admin_menu->capability(), $admin_menu->menuSlug()); |
| 156 | 156 | // skip if in full maintenance mode and maintenance_mode_parent is NOT set |
| 157 | 157 | if ($this->full_site_maintenance && ! $admin_menu->maintenanceModeParent()) { |
| 158 | - unset($admin_pages[ $page ]); |
|
| 158 | + unset($admin_pages[$page]); |
|
| 159 | 159 | continue; |
| 160 | 160 | } |
| 161 | 161 | $menu_slug = $admin_menu->menuSlug(); |
| 162 | - $this->_menu_slugs[ $menu_slug ] = $page; |
|
| 163 | - $menu_pages[ $menu_slug ] = $admin_page_init; |
|
| 162 | + $this->_menu_slugs[$menu_slug] = $page; |
|
| 163 | + $menu_pages[$menu_slug] = $admin_page_init; |
|
| 164 | 164 | // now that we've got the admin_init objects... |
| 165 | 165 | // lets see if there are any caffeinated pages extending the originals. |
| 166 | 166 | // If there are then let's hook into the init admin filter and load our extend instead. |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | $extended_hooks = $admin_page_init->register_hooks( |
| 169 | 169 | $this->loadCaffeinatedExtensions($admin_page_init, $page, $menu_slug) |
| 170 | 170 | ); |
| 171 | - $hooks_ref += $extended_hooks; |
|
| 171 | + $hooks_ref += $extended_hooks; |
|
| 172 | 172 | } |
| 173 | 173 | // the hooks_ref is all the pages where we have $extended _Hooks files |
| 174 | 174 | // that will extend a class in a different folder. |
@@ -200,12 +200,12 @@ discard block |
||
| 200 | 200 | { |
| 201 | 201 | |
| 202 | 202 | // grab everything in the admin core directory |
| 203 | - $admin_page_folders = $this->findAdminPageFolders(EE_ADMIN_PAGES . '*'); |
|
| 203 | + $admin_page_folders = $this->findAdminPageFolders(EE_ADMIN_PAGES.'*'); |
|
| 204 | 204 | $admin_page_folders = apply_filters( |
| 205 | 205 | 'FHEE__EE_Admin_Page_Loader__findAdminPages__admin_page_folders', |
| 206 | 206 | $admin_page_folders |
| 207 | 207 | ); |
| 208 | - if (! empty($admin_page_folders)) { |
|
| 208 | + if ( ! empty($admin_page_folders)) { |
|
| 209 | 209 | return $admin_page_folders; |
| 210 | 210 | } |
| 211 | 211 | $error_msg = esc_html__( |
@@ -232,9 +232,9 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | public function get_admin_page_object(string $page_slug = ''): ?EE_Admin_Page |
| 234 | 234 | { |
| 235 | - return isset($this->_installed_pages[ $page_slug ]) |
|
| 236 | - && $this->_installed_pages[ $page_slug ] instanceof EE_Admin_Page_Init |
|
| 237 | - ? $this->_installed_pages[ $page_slug ]->loaded_page_object() |
|
| 235 | + return isset($this->_installed_pages[$page_slug]) |
|
| 236 | + && $this->_installed_pages[$page_slug] instanceof EE_Admin_Page_Init |
|
| 237 | + ? $this->_installed_pages[$page_slug]->loaded_page_object() |
|
| 238 | 238 | : null; |
| 239 | 239 | } |
| 240 | 240 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | private function getClassnameForAdminPageInit(string $dir_name = ''): string |
| 249 | 249 | { |
| 250 | 250 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
| 251 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
| 251 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init'; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
| 287 | 287 | 'event_espresso' |
| 288 | 288 | ), |
| 289 | - '<strong>' . $class_name . '</strong>' |
|
| 289 | + '<strong>'.$class_name.'</strong>' |
|
| 290 | 290 | ); |
| 291 | 291 | throw new EE_Error($error_msg); |
| 292 | 292 | } |
@@ -314,18 +314,18 @@ discard block |
||
| 314 | 314 | private function findCaffeinatedAdminPages(array $admin_pages): array |
| 315 | 315 | { |
| 316 | 316 | // first let's check if there IS a caffeinated folder. If there is not then lets get out. |
| 317 | - if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin')) { |
|
| 317 | + if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated/admin')) { |
|
| 318 | 318 | return $admin_pages; |
| 319 | 319 | } |
| 320 | 320 | $this->defineCaffeinatedConstants(); |
| 321 | 321 | |
| 322 | 322 | $exclude = ['tickets']; |
| 323 | 323 | $feature = $this->loader->getShared(FeatureFlags::class); |
| 324 | - if (! $feature->allowed('use_edd_plugin_licensing')) { |
|
| 324 | + if ( ! $feature->allowed('use_edd_plugin_licensing')) { |
|
| 325 | 325 | $exclude[] = 'license_keys'; |
| 326 | 326 | } |
| 327 | 327 | // okay let's setup an "New" pages first (we'll return installed refs later) |
| 328 | - $admin_pages += $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'new/*', $exclude); |
|
| 328 | + $admin_pages += $this->findAdminPageFolders(EE_CORE_CAF_ADMIN.'new/*', $exclude); |
|
| 329 | 329 | |
| 330 | 330 | return apply_filters( |
| 331 | 331 | 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
@@ -342,16 +342,16 @@ discard block |
||
| 342 | 342 | { |
| 343 | 343 | // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array |
| 344 | 344 | // (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
| 345 | - $extensions = $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'extend/*'); |
|
| 345 | + $extensions = $this->findAdminPageFolders(EE_CORE_CAF_ADMIN.'extend/*'); |
|
| 346 | 346 | if ($extensions) { |
| 347 | 347 | foreach ($extensions as $folder => $extension) { |
| 348 | 348 | // convert lowercase_snake_case to Uppercase_Snake_Case |
| 349 | 349 | $filename = str_replace(' ', '_', ucwords(str_replace('_', ' ', $folder))); |
| 350 | 350 | $filename = "Extend_{$filename}_Admin_Page"; |
| 351 | - $filepath = EE_CORE_CAF_ADMIN . "extend/$folder/$filename.core.php"; |
|
| 351 | + $filepath = EE_CORE_CAF_ADMIN."extend/$folder/$filename.core.php"; |
|
| 352 | 352 | // save filename and filepath for later |
| 353 | - $this->_caffeinated_extends[ $folder ]['path'] = str_replace(['\\', '/'], '/', $filepath); |
|
| 354 | - $this->_caffeinated_extends[ $folder ]['admin_page'] = $filename; |
|
| 353 | + $this->_caffeinated_extends[$folder]['path'] = str_replace(['\\', '/'], '/', $filepath); |
|
| 354 | + $this->_caffeinated_extends[$folder]['admin_page'] = $filename; |
|
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | $this->_caffeinated_extends = apply_filters( |
@@ -366,21 +366,21 @@ discard block |
||
| 366 | 366 | string $page, |
| 367 | 367 | string $menu_slug |
| 368 | 368 | ): bool { |
| 369 | - if (! isset($this->_caffeinated_extends[ $page ])) { |
|
| 369 | + if ( ! isset($this->_caffeinated_extends[$page])) { |
|
| 370 | 370 | return false; |
| 371 | 371 | } |
| 372 | 372 | $admin_page_name = $admin_page_init->get_admin_page_name(); |
| 373 | - $caf_path = $this->_caffeinated_extends[ $page ]['path']; |
|
| 374 | - $caf_admin_page = $this->_caffeinated_extends[ $page ]['admin_page']; |
|
| 373 | + $caf_path = $this->_caffeinated_extends[$page]['path']; |
|
| 374 | + $caf_admin_page = $this->_caffeinated_extends[$page]['admin_page']; |
|
| 375 | 375 | add_filter( |
| 376 | 376 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_$admin_page_name", |
| 377 | - static function ($path_to_file) use ($caf_path) { |
|
| 377 | + static function($path_to_file) use ($caf_path) { |
|
| 378 | 378 | return $caf_path; |
| 379 | 379 | } |
| 380 | 380 | ); |
| 381 | 381 | add_filter( |
| 382 | 382 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_$admin_page_name", |
| 383 | - static function ($admin_page) use ($caf_admin_page) { |
|
| 383 | + static function($admin_page) use ($caf_admin_page) { |
|
| 384 | 384 | return $caf_admin_page; |
| 385 | 385 | } |
| 386 | 386 | ); |
@@ -396,12 +396,12 @@ discard block |
||
| 396 | 396 | { |
| 397 | 397 | // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
| 398 | 398 | $ee_admin_hooks = []; |
| 399 | - $admin_page_hooks = $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'hooks/*.class.php', [], 0, false); |
|
| 399 | + $admin_page_hooks = $this->findAdminPageFolders(EE_CORE_CAF_ADMIN.'hooks/*.class.php', [], 0, false); |
|
| 400 | 400 | if ($admin_page_hooks) { |
| 401 | 401 | foreach ($admin_page_hooks as $hook) { |
| 402 | 402 | if (is_readable($hook)) { |
| 403 | 403 | require_once $hook; |
| 404 | - $classname = str_replace([EE_CORE_CAF_ADMIN . 'hooks/', '.class.php'], '', $hook); |
|
| 404 | + $classname = str_replace([EE_CORE_CAF_ADMIN.'hooks/', '.class.php'], '', $hook); |
|
| 405 | 405 | if (class_exists($classname)) { |
| 406 | 406 | $ee_admin_hooks[] = $this->loader->getShared($classname); |
| 407 | 407 | } |
@@ -445,9 +445,9 @@ discard block |
||
| 445 | 445 | foreach ($subfolders as $admin_screen) { |
| 446 | 446 | $admin_screen_name = basename($admin_screen); |
| 447 | 447 | // files and anything in the exclude array need not apply |
| 448 | - if (! in_array($admin_screen_name, $exclude, true)) { |
|
| 448 | + if ( ! in_array($admin_screen_name, $exclude, true)) { |
|
| 449 | 449 | // these folders represent the different EE admin pages |
| 450 | - $folders[ $admin_screen_name ] = $admin_screen; |
|
| 450 | + $folders[$admin_screen_name] = $admin_screen; |
|
| 451 | 451 | if ($register_autoloaders) { |
| 452 | 452 | // set autoloaders for our admin page classes based on included path information |
| 453 | 453 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($admin_screen); |
@@ -17,16 +17,16 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class URLValidator |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Returns whether the URL is valid |
|
| 22 | - * @since 4.9.68.p |
|
| 23 | - * @param $url |
|
| 24 | - * @return bool |
|
| 25 | - */ |
|
| 26 | - public function isValid($url): bool |
|
| 27 | - { |
|
| 28 | - return esc_url_raw($url) === $url; |
|
| 29 | - } |
|
| 20 | + /** |
|
| 21 | + * Returns whether the URL is valid |
|
| 22 | + * @since 4.9.68.p |
|
| 23 | + * @param $url |
|
| 24 | + * @return bool |
|
| 25 | + */ |
|
| 26 | + public function isValid($url): bool |
|
| 27 | + { |
|
| 28 | + return esc_url_raw($url) === $url; |
|
| 29 | + } |
|
| 30 | 30 | } |
| 31 | 31 | // End of file URLValidator.php |
| 32 | 32 | // Location: ${NAMESPACE}/URLValidator.php |
@@ -25,151 +25,151 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class CreateRegistrationCommand extends Command implements CommandRequiresCapCheckInterface |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * @var EE_Transaction $transaction |
|
| 30 | - */ |
|
| 31 | - private $transaction; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var EE_Ticket $ticket |
|
| 35 | - */ |
|
| 36 | - private $ticket; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var EE_Line_Item $ticket_line_item |
|
| 40 | - */ |
|
| 41 | - private $ticket_line_item; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var int $reg_count |
|
| 45 | - */ |
|
| 46 | - private $reg_count; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var int $reg_group_size |
|
| 50 | - */ |
|
| 51 | - private $reg_group_size; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var string $reg_status |
|
| 55 | - */ |
|
| 56 | - private $reg_status; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var EE_Registration $registration |
|
| 60 | - */ |
|
| 61 | - protected $registration; |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * CreateRegistrationCommand constructor. |
|
| 66 | - * |
|
| 67 | - * @param EE_Transaction $transaction |
|
| 68 | - * @param EE_Line_Item $ticket_line_item |
|
| 69 | - * @param int $reg_count |
|
| 70 | - * @param int $reg_group_size |
|
| 71 | - * @param string $reg_status |
|
| 72 | - * @throws InvalidEntityException |
|
| 73 | - */ |
|
| 74 | - public function __construct( |
|
| 75 | - EE_Transaction $transaction, |
|
| 76 | - EE_Line_Item $ticket_line_item, |
|
| 77 | - $reg_count = 1, |
|
| 78 | - $reg_group_size = 0, |
|
| 79 | - $reg_status = RegStatus::INCOMPLETE |
|
| 80 | - ) { |
|
| 81 | - // grab the related ticket object for this line_item |
|
| 82 | - $this->ticket = $ticket_line_item->ticket(); |
|
| 83 | - if (! $this->ticket instanceof EE_Ticket) { |
|
| 84 | - throw new InvalidEntityException( |
|
| 85 | - is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
| 86 | - 'EE_Ticket', |
|
| 87 | - sprintf( |
|
| 88 | - esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
| 89 | - $ticket_line_item->ID() |
|
| 90 | - ) |
|
| 91 | - ); |
|
| 92 | - } |
|
| 93 | - $this->transaction = $transaction; |
|
| 94 | - $this->ticket_line_item = $ticket_line_item; |
|
| 95 | - $this->reg_count = absint($reg_count); |
|
| 96 | - $this->reg_group_size = absint($reg_group_size); |
|
| 97 | - $this->reg_status = $reg_status; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return CapCheckInterface |
|
| 103 | - * @throws InvalidDataTypeException |
|
| 104 | - */ |
|
| 105 | - public function getCapCheck() |
|
| 106 | - { |
|
| 107 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
| 108 | - return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
|
| 109 | - } |
|
| 110 | - return $this->cap_check; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @return EE_Transaction |
|
| 116 | - */ |
|
| 117 | - public function transaction() |
|
| 118 | - { |
|
| 119 | - return $this->transaction; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @return EE_Ticket |
|
| 125 | - */ |
|
| 126 | - public function ticket() |
|
| 127 | - { |
|
| 128 | - return $this->ticket; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @return EE_Line_Item |
|
| 134 | - */ |
|
| 135 | - public function ticketLineItem() |
|
| 136 | - { |
|
| 137 | - return $this->ticket_line_item; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @return int |
|
| 143 | - */ |
|
| 144 | - public function regCount() |
|
| 145 | - { |
|
| 146 | - return $this->reg_count; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @return int |
|
| 152 | - */ |
|
| 153 | - public function regGroupSize() |
|
| 154 | - { |
|
| 155 | - return $this->reg_group_size; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return string |
|
| 161 | - */ |
|
| 162 | - public function regStatus() |
|
| 163 | - { |
|
| 164 | - return $this->reg_status; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @return EE_Registration |
|
| 170 | - */ |
|
| 171 | - public function registration() |
|
| 172 | - { |
|
| 173 | - return $this->registration; |
|
| 174 | - } |
|
| 28 | + /** |
|
| 29 | + * @var EE_Transaction $transaction |
|
| 30 | + */ |
|
| 31 | + private $transaction; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var EE_Ticket $ticket |
|
| 35 | + */ |
|
| 36 | + private $ticket; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var EE_Line_Item $ticket_line_item |
|
| 40 | + */ |
|
| 41 | + private $ticket_line_item; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var int $reg_count |
|
| 45 | + */ |
|
| 46 | + private $reg_count; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var int $reg_group_size |
|
| 50 | + */ |
|
| 51 | + private $reg_group_size; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var string $reg_status |
|
| 55 | + */ |
|
| 56 | + private $reg_status; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var EE_Registration $registration |
|
| 60 | + */ |
|
| 61 | + protected $registration; |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * CreateRegistrationCommand constructor. |
|
| 66 | + * |
|
| 67 | + * @param EE_Transaction $transaction |
|
| 68 | + * @param EE_Line_Item $ticket_line_item |
|
| 69 | + * @param int $reg_count |
|
| 70 | + * @param int $reg_group_size |
|
| 71 | + * @param string $reg_status |
|
| 72 | + * @throws InvalidEntityException |
|
| 73 | + */ |
|
| 74 | + public function __construct( |
|
| 75 | + EE_Transaction $transaction, |
|
| 76 | + EE_Line_Item $ticket_line_item, |
|
| 77 | + $reg_count = 1, |
|
| 78 | + $reg_group_size = 0, |
|
| 79 | + $reg_status = RegStatus::INCOMPLETE |
|
| 80 | + ) { |
|
| 81 | + // grab the related ticket object for this line_item |
|
| 82 | + $this->ticket = $ticket_line_item->ticket(); |
|
| 83 | + if (! $this->ticket instanceof EE_Ticket) { |
|
| 84 | + throw new InvalidEntityException( |
|
| 85 | + is_object($this->ticket) ? get_class($this->ticket) : gettype($this->ticket), |
|
| 86 | + 'EE_Ticket', |
|
| 87 | + sprintf( |
|
| 88 | + esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'), |
|
| 89 | + $ticket_line_item->ID() |
|
| 90 | + ) |
|
| 91 | + ); |
|
| 92 | + } |
|
| 93 | + $this->transaction = $transaction; |
|
| 94 | + $this->ticket_line_item = $ticket_line_item; |
|
| 95 | + $this->reg_count = absint($reg_count); |
|
| 96 | + $this->reg_group_size = absint($reg_group_size); |
|
| 97 | + $this->reg_status = $reg_status; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return CapCheckInterface |
|
| 103 | + * @throws InvalidDataTypeException |
|
| 104 | + */ |
|
| 105 | + public function getCapCheck() |
|
| 106 | + { |
|
| 107 | + if (! $this->cap_check instanceof CapCheckInterface) { |
|
| 108 | + return new CapCheck('ee_edit_registrations', 'create_new_registration'); |
|
| 109 | + } |
|
| 110 | + return $this->cap_check; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @return EE_Transaction |
|
| 116 | + */ |
|
| 117 | + public function transaction() |
|
| 118 | + { |
|
| 119 | + return $this->transaction; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @return EE_Ticket |
|
| 125 | + */ |
|
| 126 | + public function ticket() |
|
| 127 | + { |
|
| 128 | + return $this->ticket; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @return EE_Line_Item |
|
| 134 | + */ |
|
| 135 | + public function ticketLineItem() |
|
| 136 | + { |
|
| 137 | + return $this->ticket_line_item; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @return int |
|
| 143 | + */ |
|
| 144 | + public function regCount() |
|
| 145 | + { |
|
| 146 | + return $this->reg_count; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @return int |
|
| 152 | + */ |
|
| 153 | + public function regGroupSize() |
|
| 154 | + { |
|
| 155 | + return $this->reg_group_size; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return string |
|
| 161 | + */ |
|
| 162 | + public function regStatus() |
|
| 163 | + { |
|
| 164 | + return $this->reg_status; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @return EE_Registration |
|
| 170 | + */ |
|
| 171 | + public function registration() |
|
| 172 | + { |
|
| 173 | + return $this->registration; |
|
| 174 | + } |
|
| 175 | 175 | } |
@@ -4,26 +4,26 @@ |
||
| 4 | 4 | |
| 5 | 5 | class DataMigrationApi |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * path to DMS folder |
|
| 9 | - */ |
|
| 10 | - private string $data_migration_scripts = ''; |
|
| 7 | + /** |
|
| 8 | + * path to DMS folder |
|
| 9 | + */ |
|
| 10 | + private string $data_migration_scripts = ''; |
|
| 11 | 11 | |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @return string |
|
| 15 | - */ |
|
| 16 | - public function dataMigrationScripts(): string |
|
| 17 | - { |
|
| 18 | - return $this->data_migration_scripts; |
|
| 19 | - } |
|
| 13 | + /** |
|
| 14 | + * @return string |
|
| 15 | + */ |
|
| 16 | + public function dataMigrationScripts(): string |
|
| 17 | + { |
|
| 18 | + return $this->data_migration_scripts; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param string $data_migration_scripts |
|
| 24 | - */ |
|
| 25 | - public function addDataMigrationScripts(string $data_migration_scripts): void |
|
| 26 | - { |
|
| 27 | - $this->data_migration_scripts = $data_migration_scripts; |
|
| 28 | - } |
|
| 22 | + /** |
|
| 23 | + * @param string $data_migration_scripts |
|
| 24 | + */ |
|
| 25 | + public function addDataMigrationScripts(string $data_migration_scripts): void |
|
| 26 | + { |
|
| 27 | + $this->data_migration_scripts = $data_migration_scripts; |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -4,95 +4,95 @@ |
||
| 4 | 4 | |
| 5 | 5 | class LegacyModelApi |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * path to EE_* entity classes |
|
| 9 | - */ |
|
| 10 | - private string $entity_classes = ''; |
|
| 11 | - |
|
| 12 | - /** |
|
| 13 | - * path to EEM_* entity model classes |
|
| 14 | - */ |
|
| 15 | - private string $entity_models = ''; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * path to EEE_* entity class extensions |
|
| 19 | - */ |
|
| 20 | - private string $entity_class_extensions = ''; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * path to EEME_* entity model class extensions |
|
| 24 | - */ |
|
| 25 | - private string $entity_model_extensions = ''; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @return string |
|
| 30 | - */ |
|
| 31 | - public function entityClasses(): string |
|
| 32 | - { |
|
| 33 | - return $this->entity_classes; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param string $entity_classes |
|
| 39 | - */ |
|
| 40 | - public function addEntityClasses(string $entity_classes): void |
|
| 41 | - { |
|
| 42 | - $this->entity_classes = $entity_classes; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public function entityModels(): string |
|
| 50 | - { |
|
| 51 | - return $this->entity_models; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param string $entity_models |
|
| 57 | - */ |
|
| 58 | - public function addEntityModels(string $entity_models): void |
|
| 59 | - { |
|
| 60 | - $this->entity_models = $entity_models; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public function entityClassExtensions(): string |
|
| 68 | - { |
|
| 69 | - return $this->entity_class_extensions; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param string $entity_class_extensions |
|
| 75 | - */ |
|
| 76 | - public function addEntityClassExtensions(string $entity_class_extensions): void |
|
| 77 | - { |
|
| 78 | - $this->entity_class_extensions = $entity_class_extensions; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function entityModelExtensions(): string |
|
| 86 | - { |
|
| 87 | - return $this->entity_model_extensions; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param string $entity_model_extensions |
|
| 93 | - */ |
|
| 94 | - public function addEntityModelExtensions(string $entity_model_extensions): void |
|
| 95 | - { |
|
| 96 | - $this->entity_model_extensions = $entity_model_extensions; |
|
| 97 | - } |
|
| 7 | + /** |
|
| 8 | + * path to EE_* entity classes |
|
| 9 | + */ |
|
| 10 | + private string $entity_classes = ''; |
|
| 11 | + |
|
| 12 | + /** |
|
| 13 | + * path to EEM_* entity model classes |
|
| 14 | + */ |
|
| 15 | + private string $entity_models = ''; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * path to EEE_* entity class extensions |
|
| 19 | + */ |
|
| 20 | + private string $entity_class_extensions = ''; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * path to EEME_* entity model class extensions |
|
| 24 | + */ |
|
| 25 | + private string $entity_model_extensions = ''; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 31 | + public function entityClasses(): string |
|
| 32 | + { |
|
| 33 | + return $this->entity_classes; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param string $entity_classes |
|
| 39 | + */ |
|
| 40 | + public function addEntityClasses(string $entity_classes): void |
|
| 41 | + { |
|
| 42 | + $this->entity_classes = $entity_classes; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public function entityModels(): string |
|
| 50 | + { |
|
| 51 | + return $this->entity_models; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param string $entity_models |
|
| 57 | + */ |
|
| 58 | + public function addEntityModels(string $entity_models): void |
|
| 59 | + { |
|
| 60 | + $this->entity_models = $entity_models; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public function entityClassExtensions(): string |
|
| 68 | + { |
|
| 69 | + return $this->entity_class_extensions; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param string $entity_class_extensions |
|
| 75 | + */ |
|
| 76 | + public function addEntityClassExtensions(string $entity_class_extensions): void |
|
| 77 | + { |
|
| 78 | + $this->entity_class_extensions = $entity_class_extensions; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function entityModelExtensions(): string |
|
| 86 | + { |
|
| 87 | + return $this->entity_model_extensions; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @param string $entity_model_extensions |
|
| 93 | + */ |
|
| 94 | + public function addEntityModelExtensions(string $entity_model_extensions): void |
|
| 95 | + { |
|
| 96 | + $this->entity_model_extensions = $entity_model_extensions; |
|
| 97 | + } |
|
| 98 | 98 | } |