@@ -17,135 +17,135 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | abstract class JobHandlerFile extends JobHandler |
| 19 | 19 | { |
| 20 | - // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
| 21 | - const temp_folder_name = 'batch_temp_folder'; |
|
| 20 | + // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
| 21 | + const temp_folder_name = 'batch_temp_folder'; |
|
| 22 | 22 | |
| 23 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
| 24 | - /** |
|
| 25 | - * @var \EEHI_File |
|
| 26 | - */ |
|
| 27 | - protected $_file_helper = null; |
|
| 23 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
| 24 | + /** |
|
| 25 | + * @var \EEHI_File |
|
| 26 | + */ |
|
| 27 | + protected $_file_helper = null; |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * JobHandlerFile constructor. |
|
| 32 | - * |
|
| 33 | - * @param \EEHI_File|null $file_helper |
|
| 34 | - */ |
|
| 35 | - public function __construct(\EEHI_File $file_helper = null) |
|
| 36 | - { |
|
| 37 | - if (! $file_helper) { |
|
| 38 | - $this->_file_helper = new EEH_File(); |
|
| 39 | - } |
|
| 40 | - } |
|
| 30 | + /** |
|
| 31 | + * JobHandlerFile constructor. |
|
| 32 | + * |
|
| 33 | + * @param \EEHI_File|null $file_helper |
|
| 34 | + */ |
|
| 35 | + public function __construct(\EEHI_File $file_helper = null) |
|
| 36 | + { |
|
| 37 | + if (! $file_helper) { |
|
| 38 | + $this->_file_helper = new EEH_File(); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 43 | - /** |
|
| 44 | - * Creates a file |
|
| 45 | - * |
|
| 46 | - * @param string $job_id |
|
| 47 | - * @param string $filename |
|
| 48 | - * @param string $filetype |
|
| 49 | - * @param string $bom initial content to place in the file. |
|
| 50 | - * @return string |
|
| 51 | - * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException |
|
| 52 | - */ |
|
| 53 | - public function create_file_from_job_with_name( |
|
| 54 | - $job_id, |
|
| 55 | - $filename, |
|
| 56 | - $filetype = 'application/ms-excel', |
|
| 57 | - $bom = "\xEF\xBB\xBF" |
|
| 58 | - ) { |
|
| 59 | - $filepath = ''; |
|
| 60 | - try { |
|
| 61 | - $base_folder = $this->get_base_folder(); |
|
| 62 | - $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
| 63 | - $base_folder . JobHandlerFile::temp_folder_name |
|
| 64 | - ); |
|
| 65 | - if ($success) { |
|
| 66 | - $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
| 67 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id |
|
| 68 | - ); |
|
| 69 | - } |
|
| 70 | - if ($success) { |
|
| 71 | - $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename; |
|
| 72 | - $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
|
| 73 | - } |
|
| 74 | - // let's add the .htaccess file so safari will open the file properly |
|
| 75 | - if ($success) { |
|
| 76 | - $extension = EEH_File::get_file_extension($filepath); |
|
| 77 | - EEH_File::write_to_file( |
|
| 78 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess', |
|
| 79 | - 'AddType ' . $filetype . ' ' . $extension, |
|
| 80 | - '.htaccess' |
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - /** |
|
| 84 | - * Filters what initial content will be added to the file. |
|
| 85 | - * @param string $return_value. By default it's whatever was pased into |
|
| 86 | - * JobHandlerFile::create_file_from_job_with_name() |
|
| 87 | - * @param string $filename |
|
| 88 | - * @param string $filetype default 'application/ms-excel' |
|
| 89 | - * @param string $filepath |
|
| 90 | - */ |
|
| 91 | - EEH_File::write_to_file( |
|
| 92 | - $filepath, |
|
| 93 | - apply_filters( |
|
| 94 | - 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
| 95 | - $bom, |
|
| 96 | - $filename, |
|
| 97 | - $filetype, |
|
| 98 | - $filepath |
|
| 99 | - ) |
|
| 100 | - ); |
|
| 101 | - // those methods normally fail with an exception, but if not, let's do it |
|
| 102 | - if (! $success) { |
|
| 103 | - throw new \EE_Error(esc_html__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
|
| 104 | - } |
|
| 105 | - } catch (\EE_Error $e) { |
|
| 106 | - throw new BatchRequestException( |
|
| 107 | - sprintf( |
|
| 108 | - // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment |
|
| 109 | - esc_html__('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'), |
|
| 110 | - $job_id, |
|
| 111 | - $e->getMessage() |
|
| 112 | - ), |
|
| 113 | - 500, |
|
| 114 | - $e |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - return $filepath; |
|
| 118 | - } |
|
| 42 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 43 | + /** |
|
| 44 | + * Creates a file |
|
| 45 | + * |
|
| 46 | + * @param string $job_id |
|
| 47 | + * @param string $filename |
|
| 48 | + * @param string $filetype |
|
| 49 | + * @param string $bom initial content to place in the file. |
|
| 50 | + * @return string |
|
| 51 | + * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException |
|
| 52 | + */ |
|
| 53 | + public function create_file_from_job_with_name( |
|
| 54 | + $job_id, |
|
| 55 | + $filename, |
|
| 56 | + $filetype = 'application/ms-excel', |
|
| 57 | + $bom = "\xEF\xBB\xBF" |
|
| 58 | + ) { |
|
| 59 | + $filepath = ''; |
|
| 60 | + try { |
|
| 61 | + $base_folder = $this->get_base_folder(); |
|
| 62 | + $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
| 63 | + $base_folder . JobHandlerFile::temp_folder_name |
|
| 64 | + ); |
|
| 65 | + if ($success) { |
|
| 66 | + $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
| 67 | + $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | + if ($success) { |
|
| 71 | + $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename; |
|
| 72 | + $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
|
| 73 | + } |
|
| 74 | + // let's add the .htaccess file so safari will open the file properly |
|
| 75 | + if ($success) { |
|
| 76 | + $extension = EEH_File::get_file_extension($filepath); |
|
| 77 | + EEH_File::write_to_file( |
|
| 78 | + $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess', |
|
| 79 | + 'AddType ' . $filetype . ' ' . $extension, |
|
| 80 | + '.htaccess' |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + /** |
|
| 84 | + * Filters what initial content will be added to the file. |
|
| 85 | + * @param string $return_value. By default it's whatever was pased into |
|
| 86 | + * JobHandlerFile::create_file_from_job_with_name() |
|
| 87 | + * @param string $filename |
|
| 88 | + * @param string $filetype default 'application/ms-excel' |
|
| 89 | + * @param string $filepath |
|
| 90 | + */ |
|
| 91 | + EEH_File::write_to_file( |
|
| 92 | + $filepath, |
|
| 93 | + apply_filters( |
|
| 94 | + 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
| 95 | + $bom, |
|
| 96 | + $filename, |
|
| 97 | + $filetype, |
|
| 98 | + $filepath |
|
| 99 | + ) |
|
| 100 | + ); |
|
| 101 | + // those methods normally fail with an exception, but if not, let's do it |
|
| 102 | + if (! $success) { |
|
| 103 | + throw new \EE_Error(esc_html__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
|
| 104 | + } |
|
| 105 | + } catch (\EE_Error $e) { |
|
| 106 | + throw new BatchRequestException( |
|
| 107 | + sprintf( |
|
| 108 | + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment |
|
| 109 | + esc_html__('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'), |
|
| 110 | + $job_id, |
|
| 111 | + $e->getMessage() |
|
| 112 | + ), |
|
| 113 | + 500, |
|
| 114 | + $e |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + return $filepath; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Gets the URL to download the file |
|
| 122 | - * |
|
| 123 | - * @param string $filepath |
|
| 124 | - * @return string url to file |
|
| 125 | - */ |
|
| 126 | - public function get_url_to_file($filepath) |
|
| 127 | - { |
|
| 128 | - return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath); |
|
| 129 | - } |
|
| 120 | + /** |
|
| 121 | + * Gets the URL to download the file |
|
| 122 | + * |
|
| 123 | + * @param string $filepath |
|
| 124 | + * @return string url to file |
|
| 125 | + */ |
|
| 126 | + public function get_url_to_file($filepath) |
|
| 127 | + { |
|
| 128 | + return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * Gets the folder which will contain the "batch_temp_folder" |
|
| 133 | - * |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - public function get_base_folder() |
|
| 137 | - { |
|
| 138 | - return apply_filters( |
|
| 139 | - 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder', |
|
| 140 | - EVENT_ESPRESSO_UPLOAD_DIR |
|
| 141 | - ); |
|
| 142 | - } |
|
| 131 | + /** |
|
| 132 | + * Gets the folder which will contain the "batch_temp_folder" |
|
| 133 | + * |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + public function get_base_folder() |
|
| 137 | + { |
|
| 138 | + return apply_filters( |
|
| 139 | + 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder', |
|
| 140 | + EVENT_ESPRESSO_UPLOAD_DIR |
|
| 141 | + ); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - public function get_base_url() |
|
| 145 | - { |
|
| 146 | - return apply_filters( |
|
| 147 | - 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url', |
|
| 148 | - EVENT_ESPRESSO_UPLOAD_URL |
|
| 149 | - ); |
|
| 150 | - } |
|
| 144 | + public function get_base_url() |
|
| 145 | + { |
|
| 146 | + return apply_filters( |
|
| 147 | + 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url', |
|
| 148 | + EVENT_ESPRESSO_UPLOAD_URL |
|
| 149 | + ); |
|
| 150 | + } |
|
| 151 | 151 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function __construct(\EEHI_File $file_helper = null) |
| 36 | 36 | { |
| 37 | - if (! $file_helper) { |
|
| 37 | + if ( ! $file_helper) { |
|
| 38 | 38 | $this->_file_helper = new EEH_File(); |
| 39 | 39 | } |
| 40 | 40 | } |
@@ -60,23 +60,23 @@ discard block |
||
| 60 | 60 | try { |
| 61 | 61 | $base_folder = $this->get_base_folder(); |
| 62 | 62 | $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
| 63 | - $base_folder . JobHandlerFile::temp_folder_name |
|
| 63 | + $base_folder.JobHandlerFile::temp_folder_name |
|
| 64 | 64 | ); |
| 65 | 65 | if ($success) { |
| 66 | 66 | $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
| 67 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id |
|
| 67 | + $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id |
|
| 68 | 68 | ); |
| 69 | 69 | } |
| 70 | 70 | if ($success) { |
| 71 | - $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename; |
|
| 71 | + $filepath = $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id.'/'.$filename; |
|
| 72 | 72 | $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
| 73 | 73 | } |
| 74 | 74 | // let's add the .htaccess file so safari will open the file properly |
| 75 | 75 | if ($success) { |
| 76 | 76 | $extension = EEH_File::get_file_extension($filepath); |
| 77 | 77 | EEH_File::write_to_file( |
| 78 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess', |
|
| 79 | - 'AddType ' . $filetype . ' ' . $extension, |
|
| 78 | + $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id.'/.htaccess', |
|
| 79 | + 'AddType '.$filetype.' '.$extension, |
|
| 80 | 80 | '.htaccess' |
| 81 | 81 | ); |
| 82 | 82 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | ) |
| 100 | 100 | ); |
| 101 | 101 | // those methods normally fail with an exception, but if not, let's do it |
| 102 | - if (! $success) { |
|
| 102 | + if ( ! $success) { |
|
| 103 | 103 | throw new \EE_Error(esc_html__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
| 104 | 104 | } |
| 105 | 105 | } catch (\EE_Error $e) { |
@@ -25,215 +25,215 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class BatchRequestProcessor |
| 27 | 27 | { |
| 28 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
| 29 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
| 30 | - /** |
|
| 31 | - * Current job's ID (if assigned) |
|
| 32 | - * |
|
| 33 | - * @var string|null |
|
| 34 | - */ |
|
| 35 | - protected $_job_id; |
|
| 28 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
| 29 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
| 30 | + /** |
|
| 31 | + * Current job's ID (if assigned) |
|
| 32 | + * |
|
| 33 | + * @var string|null |
|
| 34 | + */ |
|
| 35 | + protected $_job_id; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Current job's parameters |
|
| 39 | - * |
|
| 40 | - * @var JobParameters|null |
|
| 41 | - */ |
|
| 42 | - protected $_job_parameters; |
|
| 43 | - /** |
|
| 44 | - * @var LoaderInterface |
|
| 45 | - */ |
|
| 46 | - private $loader; |
|
| 37 | + /** |
|
| 38 | + * Current job's parameters |
|
| 39 | + * |
|
| 40 | + * @var JobParameters|null |
|
| 41 | + */ |
|
| 42 | + protected $_job_parameters; |
|
| 43 | + /** |
|
| 44 | + * @var LoaderInterface |
|
| 45 | + */ |
|
| 46 | + private $loader; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * BatchRequestProcessor constructor. |
|
| 50 | - * @param LoaderInterface $loader |
|
| 51 | - */ |
|
| 52 | - public function __construct(LoaderInterface $loader) |
|
| 53 | - { |
|
| 54 | - $this->loader = $loader; |
|
| 55 | - } |
|
| 56 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 57 | - /** |
|
| 58 | - * Creates a job for the specified batch handler class (which should be autoloaded) |
|
| 59 | - * and the specified request data |
|
| 60 | - * |
|
| 61 | - * @param string $batch_job_handler_class of an auto-loaded class implementing JobHandlerInterface |
|
| 62 | - * @param array $request_data to be used by the batch job handler |
|
| 63 | - * @return JobStepResponse |
|
| 64 | - */ |
|
| 65 | - public function create_job($batch_job_handler_class, $request_data) |
|
| 66 | - { |
|
| 67 | - try { |
|
| 68 | - $this->_job_id = wp_generate_password(15, false); |
|
| 69 | - $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
|
| 70 | - $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
|
| 71 | - $response = $obj->create_job($this->_job_parameters); |
|
| 72 | - if (! $response instanceof JobStepResponse) { |
|
| 73 | - throw new BatchRequestException( |
|
| 74 | - sprintf( |
|
| 75 | - esc_html__( |
|
| 76 | - 'The class implementing JobHandlerInterface did not return a JobStepResponse when create_job was called with %1$s. It needs to return one or throw an Exception', |
|
| 77 | - 'event_espresso' |
|
| 78 | - ), |
|
| 79 | - wp_json_encode($request_data) |
|
| 80 | - ) |
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - $success = $this->_job_parameters->save(true); |
|
| 84 | - if (! $success) { |
|
| 85 | - throw new BatchRequestException( |
|
| 86 | - sprintf( |
|
| 87 | - esc_html__( |
|
| 88 | - 'Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s', |
|
| 89 | - 'event_espresso' |
|
| 90 | - ), |
|
| 91 | - $this->_job_id, |
|
| 92 | - wp_json_encode($request_data) |
|
| 93 | - ) |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - } catch (\Exception $e) { |
|
| 97 | - $response = $this->_get_error_response($e, 'create_job'); |
|
| 98 | - } |
|
| 99 | - return $response; |
|
| 100 | - } |
|
| 48 | + /** |
|
| 49 | + * BatchRequestProcessor constructor. |
|
| 50 | + * @param LoaderInterface $loader |
|
| 51 | + */ |
|
| 52 | + public function __construct(LoaderInterface $loader) |
|
| 53 | + { |
|
| 54 | + $this->loader = $loader; |
|
| 55 | + } |
|
| 56 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 57 | + /** |
|
| 58 | + * Creates a job for the specified batch handler class (which should be autoloaded) |
|
| 59 | + * and the specified request data |
|
| 60 | + * |
|
| 61 | + * @param string $batch_job_handler_class of an auto-loaded class implementing JobHandlerInterface |
|
| 62 | + * @param array $request_data to be used by the batch job handler |
|
| 63 | + * @return JobStepResponse |
|
| 64 | + */ |
|
| 65 | + public function create_job($batch_job_handler_class, $request_data) |
|
| 66 | + { |
|
| 67 | + try { |
|
| 68 | + $this->_job_id = wp_generate_password(15, false); |
|
| 69 | + $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
|
| 70 | + $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
|
| 71 | + $response = $obj->create_job($this->_job_parameters); |
|
| 72 | + if (! $response instanceof JobStepResponse) { |
|
| 73 | + throw new BatchRequestException( |
|
| 74 | + sprintf( |
|
| 75 | + esc_html__( |
|
| 76 | + 'The class implementing JobHandlerInterface did not return a JobStepResponse when create_job was called with %1$s. It needs to return one or throw an Exception', |
|
| 77 | + 'event_espresso' |
|
| 78 | + ), |
|
| 79 | + wp_json_encode($request_data) |
|
| 80 | + ) |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + $success = $this->_job_parameters->save(true); |
|
| 84 | + if (! $success) { |
|
| 85 | + throw new BatchRequestException( |
|
| 86 | + sprintf( |
|
| 87 | + esc_html__( |
|
| 88 | + 'Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s', |
|
| 89 | + 'event_espresso' |
|
| 90 | + ), |
|
| 91 | + $this->_job_id, |
|
| 92 | + wp_json_encode($request_data) |
|
| 93 | + ) |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + } catch (\Exception $e) { |
|
| 97 | + $response = $this->_get_error_response($e, 'create_job'); |
|
| 98 | + } |
|
| 99 | + return $response; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Retrieves the job's arguments |
|
| 105 | - * |
|
| 106 | - * @param string $job_id |
|
| 107 | - * @param int $batch_size |
|
| 108 | - * @return JobStepResponse |
|
| 109 | - */ |
|
| 110 | - public function continue_job($job_id, $batch_size = 50) |
|
| 111 | - { |
|
| 112 | - try { |
|
| 113 | - $this->_job_id = $job_id; |
|
| 114 | - $batch_size = defined('EE_BATCHRUNNER_BATCH_SIZE') ? EE_BATCHRUNNER_BATCH_SIZE : $batch_size; |
|
| 115 | - // get the corresponding WordPress option for the job |
|
| 116 | - $this->_job_parameters = JobParameters::load($this->_job_id); |
|
| 117 | - $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
|
| 118 | - // continue it |
|
| 119 | - $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
|
| 120 | - if (! $response instanceof JobStepResponse) { |
|
| 121 | - throw new BatchRequestException( |
|
| 122 | - sprintf( |
|
| 123 | - esc_html__( |
|
| 124 | - 'The class implementing JobHandlerInterface did not return a JobStepResponse when continue_job was called with job %1$s. It needs to return one or throw an Exception', |
|
| 125 | - 'event_espresso' |
|
| 126 | - ), |
|
| 127 | - $this->_job_id |
|
| 128 | - ) |
|
| 129 | - ); |
|
| 130 | - } |
|
| 131 | - $this->_job_parameters->save(); |
|
| 132 | - } catch (\Exception $e) { |
|
| 133 | - $response = $this->_get_error_response($e, 'continue_job'); |
|
| 134 | - } |
|
| 135 | - return $response; |
|
| 136 | - } |
|
| 103 | + /** |
|
| 104 | + * Retrieves the job's arguments |
|
| 105 | + * |
|
| 106 | + * @param string $job_id |
|
| 107 | + * @param int $batch_size |
|
| 108 | + * @return JobStepResponse |
|
| 109 | + */ |
|
| 110 | + public function continue_job($job_id, $batch_size = 50) |
|
| 111 | + { |
|
| 112 | + try { |
|
| 113 | + $this->_job_id = $job_id; |
|
| 114 | + $batch_size = defined('EE_BATCHRUNNER_BATCH_SIZE') ? EE_BATCHRUNNER_BATCH_SIZE : $batch_size; |
|
| 115 | + // get the corresponding WordPress option for the job |
|
| 116 | + $this->_job_parameters = JobParameters::load($this->_job_id); |
|
| 117 | + $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
|
| 118 | + // continue it |
|
| 119 | + $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
|
| 120 | + if (! $response instanceof JobStepResponse) { |
|
| 121 | + throw new BatchRequestException( |
|
| 122 | + sprintf( |
|
| 123 | + esc_html__( |
|
| 124 | + 'The class implementing JobHandlerInterface did not return a JobStepResponse when continue_job was called with job %1$s. It needs to return one or throw an Exception', |
|
| 125 | + 'event_espresso' |
|
| 126 | + ), |
|
| 127 | + $this->_job_id |
|
| 128 | + ) |
|
| 129 | + ); |
|
| 130 | + } |
|
| 131 | + $this->_job_parameters->save(); |
|
| 132 | + } catch (\Exception $e) { |
|
| 133 | + $response = $this->_get_error_response($e, 'continue_job'); |
|
| 134 | + } |
|
| 135 | + return $response; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Instantiates an object of type $classname, which implements |
|
| 141 | - * JobHandlerInterface |
|
| 142 | - * |
|
| 143 | - * @param string $classname |
|
| 144 | - * @return JobHandlerInterface |
|
| 145 | - * @throws BatchRequestException |
|
| 146 | - */ |
|
| 147 | - public function instantiate_batch_job_handler_from_classname($classname) |
|
| 148 | - { |
|
| 149 | - if (! class_exists($classname)) { |
|
| 150 | - throw new BatchRequestException( |
|
| 151 | - sprintf( |
|
| 152 | - esc_html__( |
|
| 153 | - 'The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.', |
|
| 154 | - 'event_espresso' |
|
| 155 | - ), |
|
| 156 | - $classname |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 159 | - } |
|
| 160 | - $obj = $this->loader->getNew($classname); |
|
| 161 | - if (! $obj instanceof JobHandlerInterface) { |
|
| 162 | - throw new BatchRequestException( |
|
| 163 | - sprintf( |
|
| 164 | - esc_html__( |
|
| 165 | - 'The class %1$s does not implement JobHandlerInterface and so could not be used for running a job', |
|
| 166 | - 'event_espresso' |
|
| 167 | - ), |
|
| 168 | - $classname |
|
| 169 | - ) |
|
| 170 | - ); |
|
| 171 | - } |
|
| 172 | - return $obj; |
|
| 173 | - } |
|
| 139 | + /** |
|
| 140 | + * Instantiates an object of type $classname, which implements |
|
| 141 | + * JobHandlerInterface |
|
| 142 | + * |
|
| 143 | + * @param string $classname |
|
| 144 | + * @return JobHandlerInterface |
|
| 145 | + * @throws BatchRequestException |
|
| 146 | + */ |
|
| 147 | + public function instantiate_batch_job_handler_from_classname($classname) |
|
| 148 | + { |
|
| 149 | + if (! class_exists($classname)) { |
|
| 150 | + throw new BatchRequestException( |
|
| 151 | + sprintf( |
|
| 152 | + esc_html__( |
|
| 153 | + 'The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.', |
|
| 154 | + 'event_espresso' |
|
| 155 | + ), |
|
| 156 | + $classname |
|
| 157 | + ) |
|
| 158 | + ); |
|
| 159 | + } |
|
| 160 | + $obj = $this->loader->getNew($classname); |
|
| 161 | + if (! $obj instanceof JobHandlerInterface) { |
|
| 162 | + throw new BatchRequestException( |
|
| 163 | + sprintf( |
|
| 164 | + esc_html__( |
|
| 165 | + 'The class %1$s does not implement JobHandlerInterface and so could not be used for running a job', |
|
| 166 | + 'event_espresso' |
|
| 167 | + ), |
|
| 168 | + $classname |
|
| 169 | + ) |
|
| 170 | + ); |
|
| 171 | + } |
|
| 172 | + return $obj; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Forces a job to be cleaned up |
|
| 178 | - * |
|
| 179 | - * @param string $job_id |
|
| 180 | - * @return JobStepResponse |
|
| 181 | - * @throws BatchRequestException |
|
| 182 | - */ |
|
| 183 | - public function cleanup_job($job_id) |
|
| 184 | - { |
|
| 185 | - try { |
|
| 186 | - $this->_job_id = $job_id; |
|
| 187 | - $job_parameters = JobParameters::load($this->_job_id); |
|
| 188 | - $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
|
| 189 | - // continue it |
|
| 190 | - $response = $handler_obj->cleanup_job($job_parameters); |
|
| 191 | - if (! $response instanceof JobStepResponse) { |
|
| 192 | - throw new BatchRequestException( |
|
| 193 | - sprintf( |
|
| 194 | - esc_html__( |
|
| 195 | - 'The class implementing JobHandlerInterface did not return a JobStepResponse when cleanup_job was called with job %1$s. It needs to return one or throw an Exception', |
|
| 196 | - 'event_espresso' |
|
| 197 | - ), |
|
| 198 | - $this->_job_id |
|
| 199 | - ) |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - $job_parameters->set_status(JobParameters::status_cleaned_up); |
|
| 203 | - $job_parameters->delete(); |
|
| 204 | - return $response; |
|
| 205 | - } catch (\Exception $e) { |
|
| 206 | - $response = $this->_get_error_response($e, 'cleanup_job'); |
|
| 207 | - } |
|
| 208 | - return $response; |
|
| 209 | - } |
|
| 176 | + /** |
|
| 177 | + * Forces a job to be cleaned up |
|
| 178 | + * |
|
| 179 | + * @param string $job_id |
|
| 180 | + * @return JobStepResponse |
|
| 181 | + * @throws BatchRequestException |
|
| 182 | + */ |
|
| 183 | + public function cleanup_job($job_id) |
|
| 184 | + { |
|
| 185 | + try { |
|
| 186 | + $this->_job_id = $job_id; |
|
| 187 | + $job_parameters = JobParameters::load($this->_job_id); |
|
| 188 | + $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
|
| 189 | + // continue it |
|
| 190 | + $response = $handler_obj->cleanup_job($job_parameters); |
|
| 191 | + if (! $response instanceof JobStepResponse) { |
|
| 192 | + throw new BatchRequestException( |
|
| 193 | + sprintf( |
|
| 194 | + esc_html__( |
|
| 195 | + 'The class implementing JobHandlerInterface did not return a JobStepResponse when cleanup_job was called with job %1$s. It needs to return one or throw an Exception', |
|
| 196 | + 'event_espresso' |
|
| 197 | + ), |
|
| 198 | + $this->_job_id |
|
| 199 | + ) |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + $job_parameters->set_status(JobParameters::status_cleaned_up); |
|
| 203 | + $job_parameters->delete(); |
|
| 204 | + return $response; |
|
| 205 | + } catch (\Exception $e) { |
|
| 206 | + $response = $this->_get_error_response($e, 'cleanup_job'); |
|
| 207 | + } |
|
| 208 | + return $response; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * Creates a valid JobStepResponse object from an exception and method name. |
|
| 214 | - * |
|
| 215 | - * @param \Exception $exception |
|
| 216 | - * @param string $method_name |
|
| 217 | - * @return JobStepResponse |
|
| 218 | - */ |
|
| 219 | - protected function _get_error_response(\Exception $exception, $method_name) |
|
| 220 | - { |
|
| 221 | - if (! $this->_job_parameters instanceof JobParameters) { |
|
| 222 | - $this->_job_parameters = new JobParameters($this->_job_id, esc_html__('__Unknown__', 'event_espresso'), array()); |
|
| 223 | - } |
|
| 224 | - $this->_job_parameters->set_status(JobParameters::status_error); |
|
| 225 | - return new JobStepResponse( |
|
| 226 | - $this->_job_parameters, |
|
| 227 | - sprintf( |
|
| 228 | - esc_html__( |
|
| 229 | - 'An exception of type %1$s occurred while running %2$s. Its message was %3$s and had trace %4$s', |
|
| 230 | - 'event_espresso' |
|
| 231 | - ), |
|
| 232 | - get_class($exception), |
|
| 233 | - 'BatchRunner::' . $method_name . '()', |
|
| 234 | - $exception->getMessage(), |
|
| 235 | - $exception->getTraceAsString() |
|
| 236 | - ) |
|
| 237 | - ); |
|
| 238 | - } |
|
| 212 | + /** |
|
| 213 | + * Creates a valid JobStepResponse object from an exception and method name. |
|
| 214 | + * |
|
| 215 | + * @param \Exception $exception |
|
| 216 | + * @param string $method_name |
|
| 217 | + * @return JobStepResponse |
|
| 218 | + */ |
|
| 219 | + protected function _get_error_response(\Exception $exception, $method_name) |
|
| 220 | + { |
|
| 221 | + if (! $this->_job_parameters instanceof JobParameters) { |
|
| 222 | + $this->_job_parameters = new JobParameters($this->_job_id, esc_html__('__Unknown__', 'event_espresso'), array()); |
|
| 223 | + } |
|
| 224 | + $this->_job_parameters->set_status(JobParameters::status_error); |
|
| 225 | + return new JobStepResponse( |
|
| 226 | + $this->_job_parameters, |
|
| 227 | + sprintf( |
|
| 228 | + esc_html__( |
|
| 229 | + 'An exception of type %1$s occurred while running %2$s. Its message was %3$s and had trace %4$s', |
|
| 230 | + 'event_espresso' |
|
| 231 | + ), |
|
| 232 | + get_class($exception), |
|
| 233 | + 'BatchRunner::' . $method_name . '()', |
|
| 234 | + $exception->getMessage(), |
|
| 235 | + $exception->getTraceAsString() |
|
| 236 | + ) |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | 239 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $obj = $this->instantiate_batch_job_handler_from_classname($batch_job_handler_class); |
| 70 | 70 | $this->_job_parameters = new JobParameters($this->_job_id, $batch_job_handler_class, $request_data); |
| 71 | 71 | $response = $obj->create_job($this->_job_parameters); |
| 72 | - if (! $response instanceof JobStepResponse) { |
|
| 72 | + if ( ! $response instanceof JobStepResponse) { |
|
| 73 | 73 | throw new BatchRequestException( |
| 74 | 74 | sprintf( |
| 75 | 75 | esc_html__( |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | ); |
| 82 | 82 | } |
| 83 | 83 | $success = $this->_job_parameters->save(true); |
| 84 | - if (! $success) { |
|
| 84 | + if ( ! $success) { |
|
| 85 | 85 | throw new BatchRequestException( |
| 86 | 86 | sprintf( |
| 87 | 87 | esc_html__( |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $handler_obj = $this->instantiate_batch_job_handler_from_classname($this->_job_parameters->classname()); |
| 118 | 118 | // continue it |
| 119 | 119 | $response = $handler_obj->continue_job($this->_job_parameters, $batch_size); |
| 120 | - if (! $response instanceof JobStepResponse) { |
|
| 120 | + if ( ! $response instanceof JobStepResponse) { |
|
| 121 | 121 | throw new BatchRequestException( |
| 122 | 122 | sprintf( |
| 123 | 123 | esc_html__( |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | public function instantiate_batch_job_handler_from_classname($classname) |
| 148 | 148 | { |
| 149 | - if (! class_exists($classname)) { |
|
| 149 | + if ( ! class_exists($classname)) { |
|
| 150 | 150 | throw new BatchRequestException( |
| 151 | 151 | sprintf( |
| 152 | 152 | esc_html__( |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | ); |
| 159 | 159 | } |
| 160 | 160 | $obj = $this->loader->getNew($classname); |
| 161 | - if (! $obj instanceof JobHandlerInterface) { |
|
| 161 | + if ( ! $obj instanceof JobHandlerInterface) { |
|
| 162 | 162 | throw new BatchRequestException( |
| 163 | 163 | sprintf( |
| 164 | 164 | esc_html__( |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $handler_obj = $this->instantiate_batch_job_handler_from_classname($job_parameters->classname()); |
| 189 | 189 | // continue it |
| 190 | 190 | $response = $handler_obj->cleanup_job($job_parameters); |
| 191 | - if (! $response instanceof JobStepResponse) { |
|
| 191 | + if ( ! $response instanceof JobStepResponse) { |
|
| 192 | 192 | throw new BatchRequestException( |
| 193 | 193 | sprintf( |
| 194 | 194 | esc_html__( |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | protected function _get_error_response(\Exception $exception, $method_name) |
| 220 | 220 | { |
| 221 | - if (! $this->_job_parameters instanceof JobParameters) { |
|
| 221 | + if ( ! $this->_job_parameters instanceof JobParameters) { |
|
| 222 | 222 | $this->_job_parameters = new JobParameters($this->_job_id, esc_html__('__Unknown__', 'event_espresso'), array()); |
| 223 | 223 | } |
| 224 | 224 | $this->_job_parameters->set_status(JobParameters::status_error); |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | 'event_espresso' |
| 231 | 231 | ), |
| 232 | 232 | get_class($exception), |
| 233 | - 'BatchRunner::' . $method_name . '()', |
|
| 233 | + 'BatchRunner::'.$method_name.'()', |
|
| 234 | 234 | $exception->getMessage(), |
| 235 | 235 | $exception->getTraceAsString() |
| 236 | 236 | ) |
@@ -207,7 +207,7 @@ |
||
| 207 | 207 | { |
| 208 | 208 | foreach ($this->_qtipsa as $qt) { |
| 209 | 209 | // make sure we have what we need. |
| 210 | - if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) { |
|
| 210 | + if ( ! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) { |
|
| 211 | 211 | throw new EE_Error( |
| 212 | 212 | sprintf( |
| 213 | 213 | esc_html__( |
@@ -14,235 +14,235 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | abstract class EE_Qtip_Config extends EE_Base |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * This will hold the qtips setup array (setup by children) |
|
| 19 | - * |
|
| 20 | - * @access protected |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - protected $_qtipsa; |
|
| 17 | + /** |
|
| 18 | + * This will hold the qtips setup array (setup by children) |
|
| 19 | + * |
|
| 20 | + * @access protected |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + protected $_qtipsa; |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * This holds the constructed EE_Qtip objects |
|
| 28 | - * |
|
| 29 | - * @access protected |
|
| 30 | - * @var EE_Qtip |
|
| 31 | - */ |
|
| 32 | - protected $_qtips; |
|
| 26 | + /** |
|
| 27 | + * This holds the constructed EE_Qtip objects |
|
| 28 | + * |
|
| 29 | + * @access protected |
|
| 30 | + * @var EE_Qtip |
|
| 31 | + */ |
|
| 32 | + protected $_qtips; |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * an array of default options for instantiated qtip js objects |
|
| 37 | - * |
|
| 38 | - * @access protected |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - protected $_default_options; |
|
| 35 | + /** |
|
| 36 | + * an array of default options for instantiated qtip js objects |
|
| 37 | + * |
|
| 38 | + * @access protected |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + protected $_default_options; |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * constructor |
|
| 46 | - * |
|
| 47 | - * @access public |
|
| 48 | - */ |
|
| 49 | - public function __construct() |
|
| 50 | - { |
|
| 51 | - $this->_qtipsa = $this->_qtips = array(); |
|
| 52 | - $this->_set_default_options(); |
|
| 53 | - $this->_set_tips_array(); |
|
| 54 | - $this->_construct_tips(); |
|
| 55 | - } |
|
| 44 | + /** |
|
| 45 | + * constructor |
|
| 46 | + * |
|
| 47 | + * @access public |
|
| 48 | + */ |
|
| 49 | + public function __construct() |
|
| 50 | + { |
|
| 51 | + $this->_qtipsa = $this->_qtips = array(); |
|
| 52 | + $this->_set_default_options(); |
|
| 53 | + $this->_set_tips_array(); |
|
| 54 | + $this->_construct_tips(); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Children define this method and its purpose is to setup the $_qtipsa property. The format of this property is: |
|
| 60 | - * |
|
| 61 | - * $qtipsa = array( |
|
| 62 | - * 0 => array( |
|
| 63 | - * 'content_id' => 'some_unique_id_for_referencing_content', //just the string |
|
| 64 | - * 'content' => 'html/text content for the qtip', |
|
| 65 | - * 'target' => '#target-element', //use the same schema as jQuery selectors. This will match what the |
|
| 66 | - * target is for the qTip in the dom (i.e. if class then '.some-class'). |
|
| 67 | - * 'options' => array() //use this to override any of the default options for this specific qtip. |
|
| 68 | - * ) |
|
| 69 | - * ); |
|
| 70 | - * |
|
| 71 | - * @abstract |
|
| 72 | - * @access protected |
|
| 73 | - * @return void |
|
| 74 | - */ |
|
| 75 | - abstract protected function _set_tips_array(); |
|
| 58 | + /** |
|
| 59 | + * Children define this method and its purpose is to setup the $_qtipsa property. The format of this property is: |
|
| 60 | + * |
|
| 61 | + * $qtipsa = array( |
|
| 62 | + * 0 => array( |
|
| 63 | + * 'content_id' => 'some_unique_id_for_referencing_content', //just the string |
|
| 64 | + * 'content' => 'html/text content for the qtip', |
|
| 65 | + * 'target' => '#target-element', //use the same schema as jQuery selectors. This will match what the |
|
| 66 | + * target is for the qTip in the dom (i.e. if class then '.some-class'). |
|
| 67 | + * 'options' => array() //use this to override any of the default options for this specific qtip. |
|
| 68 | + * ) |
|
| 69 | + * ); |
|
| 70 | + * |
|
| 71 | + * @abstract |
|
| 72 | + * @access protected |
|
| 73 | + * @return void |
|
| 74 | + */ |
|
| 75 | + abstract protected function _set_tips_array(); |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * all the default options for the qtip js are defined here. Children class can override the defaults for all the |
|
| 80 | - * qtips defined in their config OR just leave it and have the parent default options apply. |
|
| 81 | - * |
|
| 82 | - * commented out options are there for reference so you know which can be defined by the child. |
|
| 83 | - * |
|
| 84 | - * Note: children do NOT have to define all these options. Just define the ones to override. |
|
| 85 | - * |
|
| 86 | - * @link http://qtip2.com/options |
|
| 87 | - * |
|
| 88 | - * @access protected |
|
| 89 | - * @return void |
|
| 90 | - */ |
|
| 91 | - protected function _set_default_options() |
|
| 92 | - { |
|
| 93 | - $this->_default_options = array( |
|
| 94 | - // 'id' => 'unique_id_referncing_qtip_instance', |
|
| 95 | - 'prerender' => false, |
|
| 96 | - // increases page load if true, |
|
| 97 | - 'suppress' => true, |
|
| 98 | - // whether default browser tooltips are suppressed. |
|
| 99 | - 'content' => array( |
|
| 100 | - 'button' => false, |
|
| 101 | - // what you want for the close button text/link. |
|
| 102 | - 'title' => true, |
|
| 103 | - // Options: "string", true. If TRUE then the title attribute of the target will be used (if available). If "string" then we'll use that as the title. |
|
| 104 | - 'clone' => true, |
|
| 105 | - // Options: true|false. if true then the text will be cloned from the content instead of removed from the dom. |
|
| 106 | - ), |
|
| 107 | - 'show_only_once' => false, |
|
| 108 | - // this is NOT a qtip2 library option, but is something added for EE specific use. If set to true, this means that this particular tooltip will only show ONCE for the user and then a cookie will be saved so that it doesn't show again (after exit). |
|
| 109 | - 'position' => array( |
|
| 110 | - 'my' => 'top left', |
|
| 111 | - // top left || top center || top right || right top || right center || right bottom || bottom right || bottom center || bottom left || left bottom || left center || left top |
|
| 112 | - 'at' => 'bottom right', |
|
| 113 | - // same options as above. |
|
| 114 | - 'target' => 'event', |
|
| 115 | - // if u use jQuery::#selector, js will parse to a jQuery selector || 'mouse' (at mouse cursor position) || 'event' (position at target that triggered the tooltip), or an array containing an absolute x/y position on page. |
|
| 116 | - 'container' => false, |
|
| 117 | - // what HTML element the tooltip is appended to (it's containing element). jquery object. Use 'jQuery::#selector' and js will parse' |
|
| 118 | - 'viewport' => true, |
|
| 119 | - // @link http://qtip2.com/plugins#viewport |
|
| 120 | - 'adjust' => array( |
|
| 121 | - 'x' => 0, |
|
| 122 | - // adjust position on x axis by 0 pixels. |
|
| 123 | - 'y' => 0, |
|
| 124 | - // adjust position on y axis by 0 pixels. |
|
| 125 | - 'mouse' => true, |
|
| 126 | - // when position['target'] is set to 'mouse', tooltip will follow mouse when hovering over the target. False, stops following. |
|
| 127 | - 'resize' => true, |
|
| 128 | - // adjust tooltip position when window is resized. |
|
| 129 | - 'scroll' => true, |
|
| 130 | - // position of tooltip adjusted when window (or position.container) is scrolled. |
|
| 131 | - 'method' => 'flipinvert', |
|
| 132 | - // @link http://qtip2.com/plugins#viewport |
|
| 133 | - ), |
|
| 134 | - ), |
|
| 135 | - 'show' => array( |
|
| 136 | - 'event' => 'mouseenter', |
|
| 137 | - // what event triggers tooltip to be shown. Any jQuery standard event or custom events can be used. space separated events provide multiple triggers. |
|
| 138 | - 'target' => false, |
|
| 139 | - // options jQuery::#selector|false. Used to indicate which html element will trigger show event. When false, the element the qtip() method was called upon is used. |
|
| 140 | - 'delay' => 90, |
|
| 141 | - // time in millisecons by which to delay showing of tooltip. |
|
| 142 | - 'solo' => false, |
|
| 143 | - // determines whether tooltip will hid all others when triggered. Options: true (hide all) || false (ignore) || string (parent selector for which qtips get hidden) |
|
| 144 | - 'modal' => array( |
|
| 145 | - 'on' => false, // does tooltip trigger modal? |
|
| 146 | - 'blur' => true, // does clicking on the dimmed background hide the tooltip and remove the dim? |
|
| 147 | - 'escape' => true, // hitting escape key hide the tooltip and cancel modal |
|
| 148 | - 'stealfocus' => true, // can users focus on inputs and elelments outside of tooltip when modal on? |
|
| 149 | - ), |
|
| 150 | - ), |
|
| 151 | - 'hide' => array( |
|
| 152 | - 'event' => 'mouseleave', |
|
| 153 | - // similar as what you do for show.event. |
|
| 154 | - 'target' => false, |
|
| 155 | - // Options jQuery::#selector. which html element will trigger hide event. When false, the element the .qtip() method was called upon is used. |
|
| 156 | - 'delay' => 0, |
|
| 157 | - // set time in milliseconds for delaying the hide of the tooltip |
|
| 158 | - 'inactive' => false, |
|
| 159 | - // if integer, time in millisecons in which the tooltip should be hidden if remains inactive (not interacted with) |
|
| 160 | - 'fixed' => false, |
|
| 161 | - // when set to true, the tooltip will not hide if moused over. |
|
| 162 | - 'leave' => 'window', |
|
| 163 | - // specify whether the tooltip will hide when leaving the window it's conained within. |
|
| 164 | - 'distance' => false, |
|
| 165 | - // if integer, distance in pixels that the tooltip hides when the mouse is moved from the point it triggered the tooltip. |
|
| 166 | - ), |
|
| 167 | - 'style' => array( |
|
| 168 | - 'classes' => 'qtip-tipsy', |
|
| 169 | - // Options "string", false. A space separated string containing all class names which should be added ot the main qTip element. See options for styles in comment block at end of this class. |
|
| 170 | - 'def' => true, |
|
| 171 | - // set to false and the default qtip class does not get applied |
|
| 172 | - 'widget' => false, |
|
| 173 | - // whether ui-widget classes of the themeroller UI styles are applied to tooltip. |
|
| 174 | - 'width' => false, |
|
| 175 | - // Options: "string", integer, false. with this you can override all applied CSS width styles for tooltip. Can be any valid width CSS value. (does not override min/max width styles) |
|
| 176 | - 'height' => false, |
|
| 177 | - // same as above except applies to height. |
|
| 178 | - 'tip' => array( |
|
| 179 | - 'corner' => true, |
|
| 180 | - // where in relation to the tooltip the speech bubble tip is applied. Options: true, "corner string" (see position), false. true inherits |
|
| 181 | - 'mimic' => false, |
|
| 182 | - // see documentation @link http://qtip2.com/plugins#tips |
|
| 183 | - 'border' => true, |
|
| 184 | - // Options: true, integer. determines the width of the border that surrounds the tip element. True inherits from tooltip. |
|
| 185 | - 'width' => 6, |
|
| 186 | - // width of rendered tip in pixels in relation to the side of the tooltip the tip is on. |
|
| 187 | - 'height' => 6, |
|
| 188 | - // works the same as tip.width |
|
| 189 | - 'offset' => 0, |
|
| 190 | - // use to set the offset of the tip in relation to its corner position. |
|
| 191 | - ), |
|
| 192 | - ), |
|
| 78 | + /** |
|
| 79 | + * all the default options for the qtip js are defined here. Children class can override the defaults for all the |
|
| 80 | + * qtips defined in their config OR just leave it and have the parent default options apply. |
|
| 81 | + * |
|
| 82 | + * commented out options are there for reference so you know which can be defined by the child. |
|
| 83 | + * |
|
| 84 | + * Note: children do NOT have to define all these options. Just define the ones to override. |
|
| 85 | + * |
|
| 86 | + * @link http://qtip2.com/options |
|
| 87 | + * |
|
| 88 | + * @access protected |
|
| 89 | + * @return void |
|
| 90 | + */ |
|
| 91 | + protected function _set_default_options() |
|
| 92 | + { |
|
| 93 | + $this->_default_options = array( |
|
| 94 | + // 'id' => 'unique_id_referncing_qtip_instance', |
|
| 95 | + 'prerender' => false, |
|
| 96 | + // increases page load if true, |
|
| 97 | + 'suppress' => true, |
|
| 98 | + // whether default browser tooltips are suppressed. |
|
| 99 | + 'content' => array( |
|
| 100 | + 'button' => false, |
|
| 101 | + // what you want for the close button text/link. |
|
| 102 | + 'title' => true, |
|
| 103 | + // Options: "string", true. If TRUE then the title attribute of the target will be used (if available). If "string" then we'll use that as the title. |
|
| 104 | + 'clone' => true, |
|
| 105 | + // Options: true|false. if true then the text will be cloned from the content instead of removed from the dom. |
|
| 106 | + ), |
|
| 107 | + 'show_only_once' => false, |
|
| 108 | + // this is NOT a qtip2 library option, but is something added for EE specific use. If set to true, this means that this particular tooltip will only show ONCE for the user and then a cookie will be saved so that it doesn't show again (after exit). |
|
| 109 | + 'position' => array( |
|
| 110 | + 'my' => 'top left', |
|
| 111 | + // top left || top center || top right || right top || right center || right bottom || bottom right || bottom center || bottom left || left bottom || left center || left top |
|
| 112 | + 'at' => 'bottom right', |
|
| 113 | + // same options as above. |
|
| 114 | + 'target' => 'event', |
|
| 115 | + // if u use jQuery::#selector, js will parse to a jQuery selector || 'mouse' (at mouse cursor position) || 'event' (position at target that triggered the tooltip), or an array containing an absolute x/y position on page. |
|
| 116 | + 'container' => false, |
|
| 117 | + // what HTML element the tooltip is appended to (it's containing element). jquery object. Use 'jQuery::#selector' and js will parse' |
|
| 118 | + 'viewport' => true, |
|
| 119 | + // @link http://qtip2.com/plugins#viewport |
|
| 120 | + 'adjust' => array( |
|
| 121 | + 'x' => 0, |
|
| 122 | + // adjust position on x axis by 0 pixels. |
|
| 123 | + 'y' => 0, |
|
| 124 | + // adjust position on y axis by 0 pixels. |
|
| 125 | + 'mouse' => true, |
|
| 126 | + // when position['target'] is set to 'mouse', tooltip will follow mouse when hovering over the target. False, stops following. |
|
| 127 | + 'resize' => true, |
|
| 128 | + // adjust tooltip position when window is resized. |
|
| 129 | + 'scroll' => true, |
|
| 130 | + // position of tooltip adjusted when window (or position.container) is scrolled. |
|
| 131 | + 'method' => 'flipinvert', |
|
| 132 | + // @link http://qtip2.com/plugins#viewport |
|
| 133 | + ), |
|
| 134 | + ), |
|
| 135 | + 'show' => array( |
|
| 136 | + 'event' => 'mouseenter', |
|
| 137 | + // what event triggers tooltip to be shown. Any jQuery standard event or custom events can be used. space separated events provide multiple triggers. |
|
| 138 | + 'target' => false, |
|
| 139 | + // options jQuery::#selector|false. Used to indicate which html element will trigger show event. When false, the element the qtip() method was called upon is used. |
|
| 140 | + 'delay' => 90, |
|
| 141 | + // time in millisecons by which to delay showing of tooltip. |
|
| 142 | + 'solo' => false, |
|
| 143 | + // determines whether tooltip will hid all others when triggered. Options: true (hide all) || false (ignore) || string (parent selector for which qtips get hidden) |
|
| 144 | + 'modal' => array( |
|
| 145 | + 'on' => false, // does tooltip trigger modal? |
|
| 146 | + 'blur' => true, // does clicking on the dimmed background hide the tooltip and remove the dim? |
|
| 147 | + 'escape' => true, // hitting escape key hide the tooltip and cancel modal |
|
| 148 | + 'stealfocus' => true, // can users focus on inputs and elelments outside of tooltip when modal on? |
|
| 149 | + ), |
|
| 150 | + ), |
|
| 151 | + 'hide' => array( |
|
| 152 | + 'event' => 'mouseleave', |
|
| 153 | + // similar as what you do for show.event. |
|
| 154 | + 'target' => false, |
|
| 155 | + // Options jQuery::#selector. which html element will trigger hide event. When false, the element the .qtip() method was called upon is used. |
|
| 156 | + 'delay' => 0, |
|
| 157 | + // set time in milliseconds for delaying the hide of the tooltip |
|
| 158 | + 'inactive' => false, |
|
| 159 | + // if integer, time in millisecons in which the tooltip should be hidden if remains inactive (not interacted with) |
|
| 160 | + 'fixed' => false, |
|
| 161 | + // when set to true, the tooltip will not hide if moused over. |
|
| 162 | + 'leave' => 'window', |
|
| 163 | + // specify whether the tooltip will hide when leaving the window it's conained within. |
|
| 164 | + 'distance' => false, |
|
| 165 | + // if integer, distance in pixels that the tooltip hides when the mouse is moved from the point it triggered the tooltip. |
|
| 166 | + ), |
|
| 167 | + 'style' => array( |
|
| 168 | + 'classes' => 'qtip-tipsy', |
|
| 169 | + // Options "string", false. A space separated string containing all class names which should be added ot the main qTip element. See options for styles in comment block at end of this class. |
|
| 170 | + 'def' => true, |
|
| 171 | + // set to false and the default qtip class does not get applied |
|
| 172 | + 'widget' => false, |
|
| 173 | + // whether ui-widget classes of the themeroller UI styles are applied to tooltip. |
|
| 174 | + 'width' => false, |
|
| 175 | + // Options: "string", integer, false. with this you can override all applied CSS width styles for tooltip. Can be any valid width CSS value. (does not override min/max width styles) |
|
| 176 | + 'height' => false, |
|
| 177 | + // same as above except applies to height. |
|
| 178 | + 'tip' => array( |
|
| 179 | + 'corner' => true, |
|
| 180 | + // where in relation to the tooltip the speech bubble tip is applied. Options: true, "corner string" (see position), false. true inherits |
|
| 181 | + 'mimic' => false, |
|
| 182 | + // see documentation @link http://qtip2.com/plugins#tips |
|
| 183 | + 'border' => true, |
|
| 184 | + // Options: true, integer. determines the width of the border that surrounds the tip element. True inherits from tooltip. |
|
| 185 | + 'width' => 6, |
|
| 186 | + // width of rendered tip in pixels in relation to the side of the tooltip the tip is on. |
|
| 187 | + 'height' => 6, |
|
| 188 | + // works the same as tip.width |
|
| 189 | + 'offset' => 0, |
|
| 190 | + // use to set the offset of the tip in relation to its corner position. |
|
| 191 | + ), |
|
| 192 | + ), |
|
| 193 | 193 | |
| 194 | - ); |
|
| 195 | - } |
|
| 194 | + ); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * This takes the set $_qtipsa array property and loops through it to set the EE_Qtip objects and assign them to |
|
| 200 | - * the $_qtips property |
|
| 201 | - * |
|
| 202 | - * @access protected |
|
| 203 | - * @return void |
|
| 204 | - */ |
|
| 205 | - protected function _construct_tips() |
|
| 206 | - { |
|
| 207 | - foreach ($this->_qtipsa as $qt) { |
|
| 208 | - // make sure we have what we need. |
|
| 209 | - if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) { |
|
| 210 | - throw new EE_Error( |
|
| 211 | - sprintf( |
|
| 212 | - esc_html__( |
|
| 213 | - 'There is something wrong with the _qtipsa property setup for the %s qtip config class. The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.', |
|
| 214 | - 'event_espresso' |
|
| 215 | - ), |
|
| 216 | - get_class($this), |
|
| 217 | - var_export($qt, true) |
|
| 218 | - ) |
|
| 219 | - ); |
|
| 220 | - } |
|
| 198 | + /** |
|
| 199 | + * This takes the set $_qtipsa array property and loops through it to set the EE_Qtip objects and assign them to |
|
| 200 | + * the $_qtips property |
|
| 201 | + * |
|
| 202 | + * @access protected |
|
| 203 | + * @return void |
|
| 204 | + */ |
|
| 205 | + protected function _construct_tips() |
|
| 206 | + { |
|
| 207 | + foreach ($this->_qtipsa as $qt) { |
|
| 208 | + // make sure we have what we need. |
|
| 209 | + if (! isset($qt['content_id']) || ! isset($qt['target']) || ! isset($qt['content'])) { |
|
| 210 | + throw new EE_Error( |
|
| 211 | + sprintf( |
|
| 212 | + esc_html__( |
|
| 213 | + 'There is something wrong with the _qtipsa property setup for the %s qtip config class. The dump of the current array index is: %s.<br /><br />Please check that it is setup correctly.', |
|
| 214 | + 'event_espresso' |
|
| 215 | + ), |
|
| 216 | + get_class($this), |
|
| 217 | + var_export($qt, true) |
|
| 218 | + ) |
|
| 219 | + ); |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - // make sure the options include defaults and just override via set config. |
|
| 223 | - $options_override = isset($qt['options']) ? (array) $qt['options'] : array(); |
|
| 224 | - $options = array_merge($this->_default_options, $options_override); |
|
| 225 | - $setup = array( |
|
| 226 | - 'content_id' => $qt['content_id'], |
|
| 227 | - 'options' => $options, |
|
| 228 | - 'target' => $qt['target'], |
|
| 229 | - 'content' => $qt['content'], |
|
| 230 | - ); |
|
| 231 | - $this->_qtips[] = new EE_Qtip($setup); |
|
| 232 | - } |
|
| 233 | - } |
|
| 222 | + // make sure the options include defaults and just override via set config. |
|
| 223 | + $options_override = isset($qt['options']) ? (array) $qt['options'] : array(); |
|
| 224 | + $options = array_merge($this->_default_options, $options_override); |
|
| 225 | + $setup = array( |
|
| 226 | + 'content_id' => $qt['content_id'], |
|
| 227 | + 'options' => $options, |
|
| 228 | + 'target' => $qt['target'], |
|
| 229 | + 'content' => $qt['content'], |
|
| 230 | + ); |
|
| 231 | + $this->_qtips[] = new EE_Qtip($setup); |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * return the _qtips property contents |
|
| 238 | - * |
|
| 239 | - * @access public |
|
| 240 | - * @return EE_Qtip[] |
|
| 241 | - */ |
|
| 242 | - public function get_tips() |
|
| 243 | - { |
|
| 244 | - return $this->_qtips; |
|
| 245 | - } |
|
| 236 | + /** |
|
| 237 | + * return the _qtips property contents |
|
| 238 | + * |
|
| 239 | + * @access public |
|
| 240 | + * @return EE_Qtip[] |
|
| 241 | + */ |
|
| 242 | + public function get_tips() |
|
| 243 | + { |
|
| 244 | + return $this->_qtips; |
|
| 245 | + } |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // class names you can use for tooltip styles |
@@ -294,17 +294,17 @@ discard block |
||
| 294 | 294 | */ |
| 295 | 295 | class EE_Qtip extends EE_Base |
| 296 | 296 | { |
| 297 | - public $content_id; |
|
| 298 | - public $options; |
|
| 299 | - public $target; |
|
| 300 | - public $content; |
|
| 297 | + public $content_id; |
|
| 298 | + public $options; |
|
| 299 | + public $target; |
|
| 300 | + public $content; |
|
| 301 | 301 | |
| 302 | - public function __construct($setup_array) |
|
| 303 | - { |
|
| 304 | - foreach ($setup_array as $prop => $value) { |
|
| 305 | - if (EEH_Class_Tools::has_property($this, $prop)) { |
|
| 306 | - $this->{$prop} = $value; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - } |
|
| 302 | + public function __construct($setup_array) |
|
| 303 | + { |
|
| 304 | + foreach ($setup_array as $prop => $value) { |
|
| 305 | + if (EEH_Class_Tools::has_property($this, $prop)) { |
|
| 306 | + $this->{$prop} = $value; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | 310 | } |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // make sure we don't register twice |
| 122 | - if (isset(self::$_registry[ $identifier ])) { |
|
| 122 | + if (isset(self::$_registry[$identifier])) { |
|
| 123 | 123 | return; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // make sure variation ref is unique. |
| 127 | - if (isset(self::$_registry[ $identifier ])) { |
|
| 128 | - $identifier = uniqid() . '_' . $identifier; |
|
| 127 | + if (isset(self::$_registry[$identifier])) { |
|
| 128 | + $identifier = uniqid().'_'.$identifier; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
| 159 | 159 | $validated = self::_verify_variations($identifier, $validated); |
| 160 | - self::$_registry[ $identifier ] = $validated; |
|
| 160 | + self::$_registry[$identifier] = $validated; |
|
| 161 | 161 | |
| 162 | 162 | add_filter( |
| 163 | 163 | 'FHEE__EE_Messages_Template_Pack__get_variations', |
@@ -210,8 +210,8 @@ discard block |
||
| 210 | 210 | foreach ($messenger as $message_type => $variations) { |
| 211 | 211 | foreach ($variations as $slug => $label) { |
| 212 | 212 | foreach (self::$_registry as $registered_var => $reg_settings) { |
| 213 | - if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
| 214 | - unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
| 213 | + if (isset($reg_settings['variations'][$template_pack][$messenger][$message_type][$slug])) { |
|
| 214 | + unset($validated_variations['variations'][$template_pack][$messenger][$message_type][$slug]); |
|
| 215 | 215 | EE_Error::add_error( |
| 216 | 216 | sprintf( |
| 217 | 217 | esc_html__( |
@@ -263,10 +263,10 @@ discard block |
||
| 263 | 263 | // so let's loop through our registered variations and then pull any details matching the request. |
| 264 | 264 | foreach (self::$_registry as $registry_settings) { |
| 265 | 265 | $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
| 266 | - $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
| 266 | + $file_string = $messenger.'_'.$type.'_'.$variation.$file_extension; |
|
| 267 | 267 | // see if this file exists |
| 268 | - if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
| 269 | - return $base . $file_string; |
|
| 268 | + if (is_readable($registry_settings['base_path'].$file_string)) { |
|
| 269 | + return $base.$file_string; |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | |
@@ -307,16 +307,16 @@ discard block |
||
| 307 | 307 | return array_merge($registry_settings['variations'], $variations); |
| 308 | 308 | } |
| 309 | 309 | if (empty($message_type)) { |
| 310 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
| 310 | + if ( ! empty($registry_settings['variations'][$template_pack->dbref][$messenger])) { |
|
| 311 | 311 | return array_merge( |
| 312 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
| 312 | + $registry_settings['variations'][$template_pack->dbref][$messenger], |
|
| 313 | 313 | $variations |
| 314 | 314 | ); |
| 315 | 315 | } |
| 316 | 316 | } else { |
| 317 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
| 317 | + if ( ! empty($registry_settings['variations'][$template_pack->dbref][$messenger][$message_type])) { |
|
| 318 | 318 | return array_merge( |
| 319 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
| 319 | + $registry_settings['variations'][$template_pack->dbref][$messenger][$message_type], |
|
| 320 | 320 | $variations |
| 321 | 321 | ); |
| 322 | 322 | } |
@@ -337,6 +337,6 @@ discard block |
||
| 337 | 337 | */ |
| 338 | 338 | public static function deregister($identifier = '') |
| 339 | 339 | { |
| 340 | - unset(self::$_registry[ $identifier ]); |
|
| 340 | + unset(self::$_registry[$identifier]); |
|
| 341 | 341 | } |
| 342 | 342 | } |
@@ -10,332 +10,332 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class EE_Register_Messages_Template_Variations implements EEI_Plugin_API |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Holds values for registered variations |
|
| 15 | - * |
|
| 16 | - * @since 4.5.0 |
|
| 17 | - * |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - protected static $_registry = []; |
|
| 13 | + /** |
|
| 14 | + * Holds values for registered variations |
|
| 15 | + * |
|
| 16 | + * @since 4.5.0 |
|
| 17 | + * |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + protected static $_registry = []; |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Used to register new variations |
|
| 25 | - * |
|
| 26 | - * Variations are attached to template packs and do not typically change any structural layout but merely tweak the |
|
| 27 | - * style of the layout. The most commonly known variation is css. CSS does not affect html structure just the |
|
| 28 | - * style of existing structure. |
|
| 29 | - * |
|
| 30 | - * It's important to remember that when variation files are loaded, the file structure looked for is: |
|
| 31 | - * '{$messenger}_{$messenger_variation_type}_{$variation_slug}.{$extension}'. |
|
| 32 | - * |
|
| 33 | - * - Every variation applies to specific messengers. That's why the variation file includes the messenger name |
|
| 34 | - * it. This ensures that if a template pack the variation is registered with supports multiple variations that |
|
| 35 | - * you can have the correct variation loaded. |
|
| 36 | - * - EE_messengers also implicitly define variation "types" which typically are the context in which a specific |
|
| 37 | - * variation is loaded. For instance the email messenger has: 'inline', which is the css added inline to the |
|
| 38 | - * email templates; 'preview', which is the same css only customized for when emails are previewed; and |
|
| 39 | - * 'wpeditor', which is the same css only customized so that it works with the wpeditor fields for templates to |
|
| 40 | - * give a accurate representation of the style in the wysiwyg editor. This means that for each variation, if |
|
| 41 | - * you want it to be accurately represented in various template contexts you need to have that relevant |
|
| 42 | - * variation file available. |
|
| 43 | - * - $variation_slug is simply the variation slug for that variation. |
|
| 44 | - * - $extension = whatever the extension is for the variation used for the messenger calling it. In MOST cases |
|
| 45 | - * messenger variations are .css files. Note: if your file names are not formatted correctly then they will NOT |
|
| 46 | - * be loaded. The EE messages template pack system will fallback to corresponding default template pack for the |
|
| 47 | - * given messenger or as a last resort (i.e. no default variation for the given messenger) will not load any |
|
| 48 | - * variation (so the template pack would be unstyled) |
|
| 49 | - * |
|
| 50 | - * @see /core/libraries/messages/defaults/default/variations/* for example variation files for the email and html |
|
| 51 | - * messengers. |
|
| 52 | - * |
|
| 53 | - * @param string $identifier unique reference used to describe this variation registry. If |
|
| 54 | - * this ISN'T unique then this method will make it unique (and it |
|
| 55 | - * becomes harder to deregister). |
|
| 56 | - * @param array $setup_args { |
|
| 57 | - * an array of required values for registering the variations. |
|
| 58 | - * @type array $variations { |
|
| 59 | - * An array indexed by template_pack->dbref. and values are an array |
|
| 60 | - * indexed by messenger name and values are an array indexed by |
|
| 61 | - * message_type and values are an array indexed by variation_slug |
|
| 62 | - * and value is the localized label for the variation. Note this |
|
| 63 | - * api reserves the "default" variation name for the default |
|
| 64 | - * template pack so you can't register a default variation. Also, |
|
| 65 | - * try to use unique variation slugs to reference your variations |
|
| 66 | - * because this api checks if any existing variations are in place |
|
| 67 | - * with that name. If there are then subsequent variations for that |
|
| 68 | - * template pack with that same name will fail to register with a |
|
| 69 | - * persistent notice put up for the user. Required. |
|
| 70 | - * 'default' => array( |
|
| 71 | - * 'email' => array( |
|
| 72 | - * 'registration_approved' => array( |
|
| 73 | - * my_ee_addon_blue_lagoon' => esc_html__('Blue Lagoon', |
|
| 74 | - * 'text_domain'), |
|
| 75 | - * 'my_ee_addon_red_sunset' => esc_html__('Red Sunset', |
|
| 76 | - * 'text_domain') |
|
| 77 | - * ) |
|
| 78 | - * ) |
|
| 79 | - * ) |
|
| 80 | - * } |
|
| 81 | - * @type string $base_path The base path for where all your variations are found. Although |
|
| 82 | - * the full path to your variation files should include |
|
| 83 | - * '/variations/' in it, do not include the |
|
| 84 | - * 'variations/' in this. Required. |
|
| 85 | - * @type string $base_url The base url for where all your variations are found. See note |
|
| 86 | - * above about the 'variations/' string. Required. |
|
| 87 | - * } |
|
| 88 | - * } |
|
| 89 | - * |
|
| 90 | - * @throws EE_Error |
|
| 91 | - * @return void |
|
| 92 | - */ |
|
| 93 | - public static function register($identifier = '', array $setup_args = []) |
|
| 94 | - { |
|
| 23 | + /** |
|
| 24 | + * Used to register new variations |
|
| 25 | + * |
|
| 26 | + * Variations are attached to template packs and do not typically change any structural layout but merely tweak the |
|
| 27 | + * style of the layout. The most commonly known variation is css. CSS does not affect html structure just the |
|
| 28 | + * style of existing structure. |
|
| 29 | + * |
|
| 30 | + * It's important to remember that when variation files are loaded, the file structure looked for is: |
|
| 31 | + * '{$messenger}_{$messenger_variation_type}_{$variation_slug}.{$extension}'. |
|
| 32 | + * |
|
| 33 | + * - Every variation applies to specific messengers. That's why the variation file includes the messenger name |
|
| 34 | + * it. This ensures that if a template pack the variation is registered with supports multiple variations that |
|
| 35 | + * you can have the correct variation loaded. |
|
| 36 | + * - EE_messengers also implicitly define variation "types" which typically are the context in which a specific |
|
| 37 | + * variation is loaded. For instance the email messenger has: 'inline', which is the css added inline to the |
|
| 38 | + * email templates; 'preview', which is the same css only customized for when emails are previewed; and |
|
| 39 | + * 'wpeditor', which is the same css only customized so that it works with the wpeditor fields for templates to |
|
| 40 | + * give a accurate representation of the style in the wysiwyg editor. This means that for each variation, if |
|
| 41 | + * you want it to be accurately represented in various template contexts you need to have that relevant |
|
| 42 | + * variation file available. |
|
| 43 | + * - $variation_slug is simply the variation slug for that variation. |
|
| 44 | + * - $extension = whatever the extension is for the variation used for the messenger calling it. In MOST cases |
|
| 45 | + * messenger variations are .css files. Note: if your file names are not formatted correctly then they will NOT |
|
| 46 | + * be loaded. The EE messages template pack system will fallback to corresponding default template pack for the |
|
| 47 | + * given messenger or as a last resort (i.e. no default variation for the given messenger) will not load any |
|
| 48 | + * variation (so the template pack would be unstyled) |
|
| 49 | + * |
|
| 50 | + * @see /core/libraries/messages/defaults/default/variations/* for example variation files for the email and html |
|
| 51 | + * messengers. |
|
| 52 | + * |
|
| 53 | + * @param string $identifier unique reference used to describe this variation registry. If |
|
| 54 | + * this ISN'T unique then this method will make it unique (and it |
|
| 55 | + * becomes harder to deregister). |
|
| 56 | + * @param array $setup_args { |
|
| 57 | + * an array of required values for registering the variations. |
|
| 58 | + * @type array $variations { |
|
| 59 | + * An array indexed by template_pack->dbref. and values are an array |
|
| 60 | + * indexed by messenger name and values are an array indexed by |
|
| 61 | + * message_type and values are an array indexed by variation_slug |
|
| 62 | + * and value is the localized label for the variation. Note this |
|
| 63 | + * api reserves the "default" variation name for the default |
|
| 64 | + * template pack so you can't register a default variation. Also, |
|
| 65 | + * try to use unique variation slugs to reference your variations |
|
| 66 | + * because this api checks if any existing variations are in place |
|
| 67 | + * with that name. If there are then subsequent variations for that |
|
| 68 | + * template pack with that same name will fail to register with a |
|
| 69 | + * persistent notice put up for the user. Required. |
|
| 70 | + * 'default' => array( |
|
| 71 | + * 'email' => array( |
|
| 72 | + * 'registration_approved' => array( |
|
| 73 | + * my_ee_addon_blue_lagoon' => esc_html__('Blue Lagoon', |
|
| 74 | + * 'text_domain'), |
|
| 75 | + * 'my_ee_addon_red_sunset' => esc_html__('Red Sunset', |
|
| 76 | + * 'text_domain') |
|
| 77 | + * ) |
|
| 78 | + * ) |
|
| 79 | + * ) |
|
| 80 | + * } |
|
| 81 | + * @type string $base_path The base path for where all your variations are found. Although |
|
| 82 | + * the full path to your variation files should include |
|
| 83 | + * '/variations/' in it, do not include the |
|
| 84 | + * 'variations/' in this. Required. |
|
| 85 | + * @type string $base_url The base url for where all your variations are found. See note |
|
| 86 | + * above about the 'variations/' string. Required. |
|
| 87 | + * } |
|
| 88 | + * } |
|
| 89 | + * |
|
| 90 | + * @throws EE_Error |
|
| 91 | + * @return void |
|
| 92 | + */ |
|
| 93 | + public static function register($identifier = '', array $setup_args = []) |
|
| 94 | + { |
|
| 95 | 95 | |
| 96 | - // check for required params |
|
| 97 | - if (empty($identifier)) { |
|
| 98 | - throw new EE_Error( |
|
| 99 | - esc_html__( |
|
| 100 | - 'In order to register variations for a EE_Message_Template_Pack, you must include a value to reference the variations being registered', |
|
| 101 | - 'event_espresso' |
|
| 102 | - ) |
|
| 103 | - ); |
|
| 104 | - } |
|
| 96 | + // check for required params |
|
| 97 | + if (empty($identifier)) { |
|
| 98 | + throw new EE_Error( |
|
| 99 | + esc_html__( |
|
| 100 | + 'In order to register variations for a EE_Message_Template_Pack, you must include a value to reference the variations being registered', |
|
| 101 | + 'event_espresso' |
|
| 102 | + ) |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - if ( |
|
| 107 | - ! is_array($setup_args) |
|
| 108 | - || empty($setup_args['variations']) |
|
| 109 | - || empty($setup_args['base_path']) |
|
| 110 | - || empty($setup_args['base_url']) |
|
| 111 | - ) { |
|
| 112 | - throw new EE_Error( |
|
| 113 | - esc_html__( |
|
| 114 | - 'In order to register variations for a EE_Message_Template_Pack, you must include an array containing the following keys: "variations", "base_path", "base_url", "extension"', |
|
| 115 | - 'event_espresso' |
|
| 116 | - ) |
|
| 117 | - ); |
|
| 118 | - } |
|
| 106 | + if ( |
|
| 107 | + ! is_array($setup_args) |
|
| 108 | + || empty($setup_args['variations']) |
|
| 109 | + || empty($setup_args['base_path']) |
|
| 110 | + || empty($setup_args['base_url']) |
|
| 111 | + ) { |
|
| 112 | + throw new EE_Error( |
|
| 113 | + esc_html__( |
|
| 114 | + 'In order to register variations for a EE_Message_Template_Pack, you must include an array containing the following keys: "variations", "base_path", "base_url", "extension"', |
|
| 115 | + 'event_espresso' |
|
| 116 | + ) |
|
| 117 | + ); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - // make sure we don't register twice |
|
| 121 | - if (isset(self::$_registry[ $identifier ])) { |
|
| 122 | - return; |
|
| 123 | - } |
|
| 120 | + // make sure we don't register twice |
|
| 121 | + if (isset(self::$_registry[ $identifier ])) { |
|
| 122 | + return; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - // make sure variation ref is unique. |
|
| 126 | - if (isset(self::$_registry[ $identifier ])) { |
|
| 127 | - $identifier = uniqid() . '_' . $identifier; |
|
| 128 | - } |
|
| 125 | + // make sure variation ref is unique. |
|
| 126 | + if (isset(self::$_registry[ $identifier ])) { |
|
| 127 | + $identifier = uniqid() . '_' . $identifier; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | |
| 131 | - // make sure this was called in the right place! |
|
| 132 | - if ( |
|
| 133 | - ! did_action('EE_Brewing_Regular___messages_caf') |
|
| 134 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
| 135 | - ) { |
|
| 136 | - EE_Error::doing_it_wrong( |
|
| 137 | - __METHOD__, |
|
| 138 | - sprintf( |
|
| 139 | - esc_html__( |
|
| 140 | - 'Messages Templates Variations given the reference "%s" has been attempted to be registered with the EE Messages Template Pack System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
| 141 | - 'event_espresso' |
|
| 142 | - ), |
|
| 143 | - $identifier |
|
| 144 | - ), |
|
| 145 | - '4.5.0' |
|
| 146 | - ); |
|
| 147 | - } |
|
| 131 | + // make sure this was called in the right place! |
|
| 132 | + if ( |
|
| 133 | + ! did_action('EE_Brewing_Regular___messages_caf') |
|
| 134 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
| 135 | + ) { |
|
| 136 | + EE_Error::doing_it_wrong( |
|
| 137 | + __METHOD__, |
|
| 138 | + sprintf( |
|
| 139 | + esc_html__( |
|
| 140 | + 'Messages Templates Variations given the reference "%s" has been attempted to be registered with the EE Messages Template Pack System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
| 141 | + 'event_espresso' |
|
| 142 | + ), |
|
| 143 | + $identifier |
|
| 144 | + ), |
|
| 145 | + '4.5.0' |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - // validate/sanitize incoming args. |
|
| 150 | - $validated = [ |
|
| 151 | - 'variations' => (array) $setup_args['variations'], |
|
| 152 | - 'base_path' => (string) $setup_args['base_path'], |
|
| 153 | - 'base_url' => (string) $setup_args['base_url'], |
|
| 154 | - ]; |
|
| 149 | + // validate/sanitize incoming args. |
|
| 150 | + $validated = [ |
|
| 151 | + 'variations' => (array) $setup_args['variations'], |
|
| 152 | + 'base_path' => (string) $setup_args['base_path'], |
|
| 153 | + 'base_url' => (string) $setup_args['base_url'], |
|
| 154 | + ]; |
|
| 155 | 155 | |
| 156 | 156 | |
| 157 | - // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
|
| 158 | - $validated = self::_verify_variations($identifier, $validated); |
|
| 159 | - self::$_registry[ $identifier ] = $validated; |
|
| 157 | + // check that no reserved variation names are in use and also checks if there are already existing variation names for a given template pack. The former will throw an error. The latter will remove the conflicting variation name but still register the others and will add EE_Error notice. |
|
| 158 | + $validated = self::_verify_variations($identifier, $validated); |
|
| 159 | + self::$_registry[ $identifier ] = $validated; |
|
| 160 | 160 | |
| 161 | - add_filter( |
|
| 162 | - 'FHEE__EE_Messages_Template_Pack__get_variations', |
|
| 163 | - ['EE_Register_Messages_Template_Variations', 'get_variations'], |
|
| 164 | - 10, |
|
| 165 | - 4 |
|
| 166 | - ); |
|
| 167 | - add_filter( |
|
| 168 | - 'FHEE__EE_Messages_Template_Pack__get_variation', |
|
| 169 | - ['EE_Register_Messages_Template_Variations', 'get_variation'], |
|
| 170 | - 10, |
|
| 171 | - 8 |
|
| 172 | - ); |
|
| 173 | - } |
|
| 161 | + add_filter( |
|
| 162 | + 'FHEE__EE_Messages_Template_Pack__get_variations', |
|
| 163 | + ['EE_Register_Messages_Template_Variations', 'get_variations'], |
|
| 164 | + 10, |
|
| 165 | + 4 |
|
| 166 | + ); |
|
| 167 | + add_filter( |
|
| 168 | + 'FHEE__EE_Messages_Template_Pack__get_variation', |
|
| 169 | + ['EE_Register_Messages_Template_Variations', 'get_variation'], |
|
| 170 | + 10, |
|
| 171 | + 8 |
|
| 172 | + ); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Cycles through the variations registered and makes sure there are no reserved variations being registered which |
|
| 178 | - * throws an error. Also checks if there is already a |
|
| 179 | - * |
|
| 180 | - * @param string $identifier the reference for the variations being registered |
|
| 181 | - * @param array $validated_variations The variations setup array that's being registered (and verified). |
|
| 182 | - * @return array |
|
| 183 | - * @throws EE_Error |
|
| 184 | - * @since 4.5.0 |
|
| 185 | - * |
|
| 186 | - */ |
|
| 187 | - private static function _verify_variations($identifier, array $validated_variations) |
|
| 188 | - { |
|
| 189 | - foreach (self::$_registry as $settings) { |
|
| 190 | - foreach ($settings['variations'] as $messenger) { |
|
| 191 | - foreach ($messenger as $all_variations) { |
|
| 192 | - if (isset($all_variations['default'])) { |
|
| 193 | - throw new EE_Error( |
|
| 194 | - sprintf( |
|
| 195 | - esc_html__( |
|
| 196 | - 'Variations registered through the EE_Register_Messages_Template_Variations api cannot override the default variation for the default template. Please check the code registering variations with this reference, "%s" and modify.', |
|
| 197 | - 'event_espresso' |
|
| 198 | - ), |
|
| 199 | - $identifier |
|
| 200 | - ) |
|
| 201 | - ); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 176 | + /** |
|
| 177 | + * Cycles through the variations registered and makes sure there are no reserved variations being registered which |
|
| 178 | + * throws an error. Also checks if there is already a |
|
| 179 | + * |
|
| 180 | + * @param string $identifier the reference for the variations being registered |
|
| 181 | + * @param array $validated_variations The variations setup array that's being registered (and verified). |
|
| 182 | + * @return array |
|
| 183 | + * @throws EE_Error |
|
| 184 | + * @since 4.5.0 |
|
| 185 | + * |
|
| 186 | + */ |
|
| 187 | + private static function _verify_variations($identifier, array $validated_variations) |
|
| 188 | + { |
|
| 189 | + foreach (self::$_registry as $settings) { |
|
| 190 | + foreach ($settings['variations'] as $messenger) { |
|
| 191 | + foreach ($messenger as $all_variations) { |
|
| 192 | + if (isset($all_variations['default'])) { |
|
| 193 | + throw new EE_Error( |
|
| 194 | + sprintf( |
|
| 195 | + esc_html__( |
|
| 196 | + 'Variations registered through the EE_Register_Messages_Template_Variations api cannot override the default variation for the default template. Please check the code registering variations with this reference, "%s" and modify.', |
|
| 197 | + 'event_espresso' |
|
| 198 | + ), |
|
| 199 | + $identifier |
|
| 200 | + ) |
|
| 201 | + ); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - // is there already a variation registered with a given variation slug? |
|
| 208 | - foreach ($validated_variations['variations'] as $template_pack => $messenger) { |
|
| 209 | - foreach ($messenger as $message_type => $variations) { |
|
| 210 | - foreach ($variations as $slug => $label) { |
|
| 211 | - foreach (self::$_registry as $registered_var => $reg_settings) { |
|
| 212 | - if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
| 213 | - unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
| 214 | - EE_Error::add_error( |
|
| 215 | - sprintf( |
|
| 216 | - esc_html__( |
|
| 217 | - 'Unable to register the %s variation for the %s template pack with the %s messenger and %s message_type because a variation with this slug was already registered for this template pack and messenger and message type by an addon using this key %s.', |
|
| 218 | - 'event_espresso' |
|
| 219 | - ), |
|
| 220 | - $label, |
|
| 221 | - $template_pack, |
|
| 222 | - $messenger, |
|
| 223 | - $message_type, |
|
| 224 | - $registered_var |
|
| 225 | - ) |
|
| 226 | - ); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - return $validated_variations; |
|
| 233 | - } |
|
| 207 | + // is there already a variation registered with a given variation slug? |
|
| 208 | + foreach ($validated_variations['variations'] as $template_pack => $messenger) { |
|
| 209 | + foreach ($messenger as $message_type => $variations) { |
|
| 210 | + foreach ($variations as $slug => $label) { |
|
| 211 | + foreach (self::$_registry as $registered_var => $reg_settings) { |
|
| 212 | + if (isset($reg_settings['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ])) { |
|
| 213 | + unset($validated_variations['variations'][ $template_pack ][ $messenger ][ $message_type ][ $slug ]); |
|
| 214 | + EE_Error::add_error( |
|
| 215 | + sprintf( |
|
| 216 | + esc_html__( |
|
| 217 | + 'Unable to register the %s variation for the %s template pack with the %s messenger and %s message_type because a variation with this slug was already registered for this template pack and messenger and message type by an addon using this key %s.', |
|
| 218 | + 'event_espresso' |
|
| 219 | + ), |
|
| 220 | + $label, |
|
| 221 | + $template_pack, |
|
| 222 | + $messenger, |
|
| 223 | + $message_type, |
|
| 224 | + $registered_var |
|
| 225 | + ) |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + return $validated_variations; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * Callback for the FHEE__EE_Messages_Template_Pack__get_variation filter to ensure registered variations are used. |
|
| 238 | - * |
|
| 239 | - * @param string $variation_path The path generated for the current variation |
|
| 240 | - * @param string $messenger The messenger the variation is for |
|
| 241 | - * @param string $message_type EE_message_type->name |
|
| 242 | - * @param string $type The type of variation being requested |
|
| 243 | - * @param string $variation The slug for the variation being requested |
|
| 244 | - * @param string $file_extension What the file extension is for the variation |
|
| 245 | - * @param bool $url Whether url or path is being returned. |
|
| 246 | - * @param EE_Messages_Template_Pack $template_pack |
|
| 247 | - * |
|
| 248 | - * @return string The path to the requested variation. |
|
| 249 | - * @since 4.5.0 |
|
| 250 | - * |
|
| 251 | - */ |
|
| 252 | - public static function get_variation( |
|
| 253 | - $variation_path, |
|
| 254 | - $messenger, |
|
| 255 | - $message_type, |
|
| 256 | - $type, |
|
| 257 | - $variation, |
|
| 258 | - $file_extension, |
|
| 259 | - $url, |
|
| 260 | - EE_Messages_Template_Pack $template_pack |
|
| 261 | - ) { |
|
| 262 | - // so let's loop through our registered variations and then pull any details matching the request. |
|
| 263 | - foreach (self::$_registry as $registry_settings) { |
|
| 264 | - $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
|
| 265 | - $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
| 266 | - // see if this file exists |
|
| 267 | - if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
| 268 | - return $base . $file_string; |
|
| 269 | - } |
|
| 270 | - } |
|
| 236 | + /** |
|
| 237 | + * Callback for the FHEE__EE_Messages_Template_Pack__get_variation filter to ensure registered variations are used. |
|
| 238 | + * |
|
| 239 | + * @param string $variation_path The path generated for the current variation |
|
| 240 | + * @param string $messenger The messenger the variation is for |
|
| 241 | + * @param string $message_type EE_message_type->name |
|
| 242 | + * @param string $type The type of variation being requested |
|
| 243 | + * @param string $variation The slug for the variation being requested |
|
| 244 | + * @param string $file_extension What the file extension is for the variation |
|
| 245 | + * @param bool $url Whether url or path is being returned. |
|
| 246 | + * @param EE_Messages_Template_Pack $template_pack |
|
| 247 | + * |
|
| 248 | + * @return string The path to the requested variation. |
|
| 249 | + * @since 4.5.0 |
|
| 250 | + * |
|
| 251 | + */ |
|
| 252 | + public static function get_variation( |
|
| 253 | + $variation_path, |
|
| 254 | + $messenger, |
|
| 255 | + $message_type, |
|
| 256 | + $type, |
|
| 257 | + $variation, |
|
| 258 | + $file_extension, |
|
| 259 | + $url, |
|
| 260 | + EE_Messages_Template_Pack $template_pack |
|
| 261 | + ) { |
|
| 262 | + // so let's loop through our registered variations and then pull any details matching the request. |
|
| 263 | + foreach (self::$_registry as $registry_settings) { |
|
| 264 | + $base = $url ? $registry_settings['base_url'] : $registry_settings['base_path']; |
|
| 265 | + $file_string = $messenger . '_' . $type . '_' . $variation . $file_extension; |
|
| 266 | + // see if this file exists |
|
| 267 | + if (is_readable($registry_settings['base_path'] . $file_string)) { |
|
| 268 | + return $base . $file_string; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - // no match |
|
| 273 | - return $variation_path; |
|
| 274 | - } |
|
| 272 | + // no match |
|
| 273 | + return $variation_path; |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * callback for the FHEE__EE_Messages_Template_Pack__get_variations filter. |
|
| 279 | - * |
|
| 280 | - * |
|
| 281 | - * @param array $variations The original contents for the template pack variations property. |
|
| 282 | - * @param string $messenger The messenger requesting the variations. |
|
| 283 | - * @param string $message_type |
|
| 284 | - * @param EE_Messages_Template_Pack $template_pack |
|
| 285 | - * |
|
| 286 | - * @return array new variations array (or existing one if nothing registered) |
|
| 287 | - * @since 4.5.0 |
|
| 288 | - * |
|
| 289 | - * @see $_variation property definition in EE_Messages_Template_Pack |
|
| 290 | - */ |
|
| 291 | - public static function get_variations( |
|
| 292 | - array $variations, |
|
| 293 | - $messenger, |
|
| 294 | - $message_type, |
|
| 295 | - EE_Messages_Template_Pack $template_pack |
|
| 296 | - ) { |
|
| 297 | - // first let's check if we even have registered variations and get out early. |
|
| 298 | - if (empty(self::$_registry)) { |
|
| 299 | - return $variations; |
|
| 300 | - } |
|
| 277 | + /** |
|
| 278 | + * callback for the FHEE__EE_Messages_Template_Pack__get_variations filter. |
|
| 279 | + * |
|
| 280 | + * |
|
| 281 | + * @param array $variations The original contents for the template pack variations property. |
|
| 282 | + * @param string $messenger The messenger requesting the variations. |
|
| 283 | + * @param string $message_type |
|
| 284 | + * @param EE_Messages_Template_Pack $template_pack |
|
| 285 | + * |
|
| 286 | + * @return array new variations array (or existing one if nothing registered) |
|
| 287 | + * @since 4.5.0 |
|
| 288 | + * |
|
| 289 | + * @see $_variation property definition in EE_Messages_Template_Pack |
|
| 290 | + */ |
|
| 291 | + public static function get_variations( |
|
| 292 | + array $variations, |
|
| 293 | + $messenger, |
|
| 294 | + $message_type, |
|
| 295 | + EE_Messages_Template_Pack $template_pack |
|
| 296 | + ) { |
|
| 297 | + // first let's check if we even have registered variations and get out early. |
|
| 298 | + if (empty(self::$_registry)) { |
|
| 299 | + return $variations; |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - // do we have any new variations for the given messenger, $message_type, and template packs |
|
| 303 | - foreach (self::$_registry as $registry_settings) { |
|
| 304 | - // allow for different conditions. |
|
| 305 | - if (empty($messenger)) { |
|
| 306 | - return array_merge($registry_settings['variations'], $variations); |
|
| 307 | - } |
|
| 308 | - if (empty($message_type)) { |
|
| 309 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
| 310 | - return array_merge( |
|
| 311 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
| 312 | - $variations |
|
| 313 | - ); |
|
| 314 | - } |
|
| 315 | - } else { |
|
| 316 | - if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
| 317 | - return array_merge( |
|
| 318 | - $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
| 319 | - $variations |
|
| 320 | - ); |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - return $variations; |
|
| 325 | - } |
|
| 302 | + // do we have any new variations for the given messenger, $message_type, and template packs |
|
| 303 | + foreach (self::$_registry as $registry_settings) { |
|
| 304 | + // allow for different conditions. |
|
| 305 | + if (empty($messenger)) { |
|
| 306 | + return array_merge($registry_settings['variations'], $variations); |
|
| 307 | + } |
|
| 308 | + if (empty($message_type)) { |
|
| 309 | + if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ])) { |
|
| 310 | + return array_merge( |
|
| 311 | + $registry_settings['variations'][ $template_pack->dbref ][ $messenger ], |
|
| 312 | + $variations |
|
| 313 | + ); |
|
| 314 | + } |
|
| 315 | + } else { |
|
| 316 | + if (! empty($registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ])) { |
|
| 317 | + return array_merge( |
|
| 318 | + $registry_settings['variations'][ $template_pack->dbref ][ $messenger ][ $message_type ], |
|
| 319 | + $variations |
|
| 320 | + ); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + return $variations; |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | 327 | |
| 328 | - /** |
|
| 329 | - * This deregisters a variation set that was previously registered with the given slug. |
|
| 330 | - * |
|
| 331 | - * @param string $identifier The name for the variation set that was previously registered. |
|
| 332 | - * |
|
| 333 | - * @return void |
|
| 334 | - * @since 4.5.0 |
|
| 335 | - * |
|
| 336 | - */ |
|
| 337 | - public static function deregister($identifier = '') |
|
| 338 | - { |
|
| 339 | - unset(self::$_registry[ $identifier ]); |
|
| 340 | - } |
|
| 328 | + /** |
|
| 329 | + * This deregisters a variation set that was previously registered with the given slug. |
|
| 330 | + * |
|
| 331 | + * @param string $identifier The name for the variation set that was previously registered. |
|
| 332 | + * |
|
| 333 | + * @return void |
|
| 334 | + * @since 4.5.0 |
|
| 335 | + * |
|
| 336 | + */ |
|
| 337 | + public static function deregister($identifier = '') |
|
| 338 | + { |
|
| 339 | + unset(self::$_registry[ $identifier ]); |
|
| 340 | + } |
|
| 341 | 341 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | ); |
| 66 | 66 | } |
| 67 | 67 | // make sure we don't register twice |
| 68 | - if (isset(self::$_registry[ $identifier ])) { |
|
| 68 | + if (isset(self::$_registry[$identifier])) { |
|
| 69 | 69 | return; |
| 70 | 70 | } |
| 71 | 71 | // make sure this is not registered too late or too early. |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | ); |
| 87 | 87 | } |
| 88 | 88 | // some preliminary sanitization and setting to the $_registry property |
| 89 | - self::$_registry[ $identifier ] = [ |
|
| 89 | + self::$_registry[$identifier] = [ |
|
| 90 | 90 | 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
| 91 | 91 | ? $setup_args['capabilities'] |
| 92 | 92 | : [], |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | { |
| 136 | 136 | // loop through and instantiate cap maps. |
| 137 | 137 | foreach (self::$_registry as $identifier => $setup) { |
| 138 | - if (! isset($setup['cap_maps'])) { |
|
| 138 | + if ( ! isset($setup['cap_maps'])) { |
|
| 139 | 139 | continue; |
| 140 | 140 | } |
| 141 | 141 | foreach ($setup['cap_maps'] as $cap_class => $args) { |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | if (is_numeric($cap_class)) { |
| 166 | 166 | $cap_class = key($args); |
| 167 | - $args = $args[ $cap_class ]; |
|
| 167 | + $args = $args[$cap_class]; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - if (! class_exists($cap_class)) { |
|
| 170 | + if ( ! class_exists($cap_class)) { |
|
| 171 | 171 | throw new EE_Error( |
| 172 | 172 | sprintf( |
| 173 | 173 | esc_html__( |
@@ -205,17 +205,17 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | public static function deregister($identifier = '') |
| 207 | 207 | { |
| 208 | - if (! empty(self::$_registry[ $identifier ])) { |
|
| 209 | - if (! empty(self::$_registry[ $identifier ]['caps'])) { |
|
| 208 | + if ( ! empty(self::$_registry[$identifier])) { |
|
| 209 | + if ( ! empty(self::$_registry[$identifier]['caps'])) { |
|
| 210 | 210 | // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
| 211 | - $caps_to_remove = self::$_registry[ $identifier ]['caps']; |
|
| 211 | + $caps_to_remove = self::$_registry[$identifier]['caps']; |
|
| 212 | 212 | if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
| 213 | 213 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
| 214 | 214 | $capabilities->removeCaps($caps_to_remove); |
| 215 | 215 | } else { |
| 216 | 216 | add_action( |
| 217 | 217 | 'AHEE__EE_System__core_loaded_and_ready', |
| 218 | - function () use ($caps_to_remove) { |
|
| 218 | + function() use ($caps_to_remove) { |
|
| 219 | 219 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
| 220 | 220 | $capabilities->removeCaps($caps_to_remove); |
| 221 | 221 | } |
@@ -223,6 +223,6 @@ discard block |
||
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | - unset(self::$_registry[ $identifier ]); |
|
| 226 | + unset(self::$_registry[$identifier]); |
|
| 227 | 227 | } |
| 228 | 228 | } |
@@ -14,214 +14,214 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EE_Register_Capabilities implements EEI_Plugin_API |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Holds the settings for a specific registration. |
|
| 19 | - * |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected static $_registry = []; |
|
| 17 | + /** |
|
| 18 | + * Holds the settings for a specific registration. |
|
| 19 | + * |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected static $_registry = []; |
|
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Used to register capability items with EE core. |
|
| 27 | - * |
|
| 28 | - * @param string $identifier usually will be a class name |
|
| 29 | - * that references capability |
|
| 30 | - * related items setup for |
|
| 31 | - * something. |
|
| 32 | - * @param array $setup_args { |
|
| 33 | - * An array of items related to |
|
| 34 | - * registering capabilities. |
|
| 35 | - * @type array $capabilities An array mapping capability |
|
| 36 | - * strings to core WP Role. |
|
| 37 | - * Something like: array( |
|
| 38 | - * 'administrator' => array( |
|
| 39 | - * 'read_cap', 'edit_cap', |
|
| 40 | - * 'delete_cap'), |
|
| 41 | - * 'author' => |
|
| 42 | - * array( 'read_cap' ) |
|
| 43 | - * ). |
|
| 44 | - * @type array $capability_maps EE_Meta_Capability_Map[] |
|
| 45 | - * @return void |
|
| 46 | - * @throws EE_Error |
|
| 47 | - * @since 4.5.0 |
|
| 48 | - * @see EE_Capabilities.php for php docs on these objects. |
|
| 49 | - * Should be indexed by the |
|
| 50 | - * classname for the capability |
|
| 51 | - * map and values representing |
|
| 52 | - * the arguments for the map. |
|
| 53 | - * } |
|
| 54 | - */ |
|
| 55 | - public static function register($identifier = '', array $setup_args = []) |
|
| 56 | - { |
|
| 57 | - // required fields MUST be present, so let's make sure they are. |
|
| 58 | - if ($identifier === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
| 59 | - throw new EE_Error( |
|
| 60 | - esc_html__( |
|
| 61 | - 'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
| 62 | - 'event_espresso' |
|
| 63 | - ) |
|
| 64 | - ); |
|
| 65 | - } |
|
| 66 | - // make sure we don't register twice |
|
| 67 | - if (isset(self::$_registry[ $identifier ])) { |
|
| 68 | - return; |
|
| 69 | - } |
|
| 70 | - // make sure this is not registered too late or too early. |
|
| 71 | - if ( |
|
| 72 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 73 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 74 | - ) { |
|
| 75 | - EE_Error::doing_it_wrong( |
|
| 76 | - __METHOD__, |
|
| 77 | - sprintf( |
|
| 78 | - esc_html__( |
|
| 79 | - '%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - $identifier |
|
| 83 | - ), |
|
| 84 | - '4.5.0' |
|
| 85 | - ); |
|
| 86 | - } |
|
| 87 | - // some preliminary sanitization and setting to the $_registry property |
|
| 88 | - self::$_registry[ $identifier ] = [ |
|
| 89 | - 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
|
| 90 | - ? $setup_args['capabilities'] |
|
| 91 | - : [], |
|
| 92 | - 'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : [], |
|
| 93 | - ]; |
|
| 94 | - // set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
| 95 | - add_filter( |
|
| 96 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 97 | - ['EE_Register_Capabilities', 'register_capabilities'] |
|
| 98 | - ); |
|
| 99 | - // add filter for cap maps |
|
| 100 | - add_filter( |
|
| 101 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 102 | - ['EE_Register_Capabilities', 'register_cap_maps'] |
|
| 103 | - ); |
|
| 104 | - } |
|
| 25 | + /** |
|
| 26 | + * Used to register capability items with EE core. |
|
| 27 | + * |
|
| 28 | + * @param string $identifier usually will be a class name |
|
| 29 | + * that references capability |
|
| 30 | + * related items setup for |
|
| 31 | + * something. |
|
| 32 | + * @param array $setup_args { |
|
| 33 | + * An array of items related to |
|
| 34 | + * registering capabilities. |
|
| 35 | + * @type array $capabilities An array mapping capability |
|
| 36 | + * strings to core WP Role. |
|
| 37 | + * Something like: array( |
|
| 38 | + * 'administrator' => array( |
|
| 39 | + * 'read_cap', 'edit_cap', |
|
| 40 | + * 'delete_cap'), |
|
| 41 | + * 'author' => |
|
| 42 | + * array( 'read_cap' ) |
|
| 43 | + * ). |
|
| 44 | + * @type array $capability_maps EE_Meta_Capability_Map[] |
|
| 45 | + * @return void |
|
| 46 | + * @throws EE_Error |
|
| 47 | + * @since 4.5.0 |
|
| 48 | + * @see EE_Capabilities.php for php docs on these objects. |
|
| 49 | + * Should be indexed by the |
|
| 50 | + * classname for the capability |
|
| 51 | + * map and values representing |
|
| 52 | + * the arguments for the map. |
|
| 53 | + * } |
|
| 54 | + */ |
|
| 55 | + public static function register($identifier = '', array $setup_args = []) |
|
| 56 | + { |
|
| 57 | + // required fields MUST be present, so let's make sure they are. |
|
| 58 | + if ($identifier === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
| 59 | + throw new EE_Error( |
|
| 60 | + esc_html__( |
|
| 61 | + 'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
| 62 | + 'event_espresso' |
|
| 63 | + ) |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | + // make sure we don't register twice |
|
| 67 | + if (isset(self::$_registry[ $identifier ])) { |
|
| 68 | + return; |
|
| 69 | + } |
|
| 70 | + // make sure this is not registered too late or too early. |
|
| 71 | + if ( |
|
| 72 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 73 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 74 | + ) { |
|
| 75 | + EE_Error::doing_it_wrong( |
|
| 76 | + __METHOD__, |
|
| 77 | + sprintf( |
|
| 78 | + esc_html__( |
|
| 79 | + '%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + $identifier |
|
| 83 | + ), |
|
| 84 | + '4.5.0' |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | + // some preliminary sanitization and setting to the $_registry property |
|
| 88 | + self::$_registry[ $identifier ] = [ |
|
| 89 | + 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
|
| 90 | + ? $setup_args['capabilities'] |
|
| 91 | + : [], |
|
| 92 | + 'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : [], |
|
| 93 | + ]; |
|
| 94 | + // set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
| 95 | + add_filter( |
|
| 96 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 97 | + ['EE_Register_Capabilities', 'register_capabilities'] |
|
| 98 | + ); |
|
| 99 | + // add filter for cap maps |
|
| 100 | + add_filter( |
|
| 101 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 102 | + ['EE_Register_Capabilities', 'register_cap_maps'] |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
| 109 | - * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
| 110 | - * registration ensures that new capabilities are added to existing roles. |
|
| 111 | - * |
|
| 112 | - * @param array $incoming_caps The original caps map. |
|
| 113 | - * @return array merged in new caps. |
|
| 114 | - */ |
|
| 115 | - public static function register_capabilities(array $incoming_caps) |
|
| 116 | - { |
|
| 117 | - foreach (self::$_registry as $caps_and_cap_map) { |
|
| 118 | - $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
| 119 | - } |
|
| 120 | - return $incoming_caps; |
|
| 121 | - } |
|
| 107 | + /** |
|
| 108 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
| 109 | + * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
| 110 | + * registration ensures that new capabilities are added to existing roles. |
|
| 111 | + * |
|
| 112 | + * @param array $incoming_caps The original caps map. |
|
| 113 | + * @return array merged in new caps. |
|
| 114 | + */ |
|
| 115 | + public static function register_capabilities(array $incoming_caps) |
|
| 116 | + { |
|
| 117 | + foreach (self::$_registry as $caps_and_cap_map) { |
|
| 118 | + $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
| 119 | + } |
|
| 120 | + return $incoming_caps; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
| 126 | - * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
| 127 | - * |
|
| 128 | - * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
| 129 | - * @return EE_Meta_Capability_Map[] |
|
| 130 | - * @throws EE_Error |
|
| 131 | - * @since 4.5.0 |
|
| 132 | - */ |
|
| 133 | - public static function register_cap_maps(array $cap_maps) |
|
| 134 | - { |
|
| 135 | - // loop through and instantiate cap maps. |
|
| 136 | - foreach (self::$_registry as $identifier => $setup) { |
|
| 137 | - if (! isset($setup['cap_maps'])) { |
|
| 138 | - continue; |
|
| 139 | - } |
|
| 140 | - foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
| 124 | + /** |
|
| 125 | + * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
| 126 | + * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
| 127 | + * |
|
| 128 | + * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
| 129 | + * @return EE_Meta_Capability_Map[] |
|
| 130 | + * @throws EE_Error |
|
| 131 | + * @since 4.5.0 |
|
| 132 | + */ |
|
| 133 | + public static function register_cap_maps(array $cap_maps) |
|
| 134 | + { |
|
| 135 | + // loop through and instantiate cap maps. |
|
| 136 | + foreach (self::$_registry as $identifier => $setup) { |
|
| 137 | + if (! isset($setup['cap_maps'])) { |
|
| 138 | + continue; |
|
| 139 | + } |
|
| 140 | + foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * account for cases where capability maps may be indexed |
|
| 144 | - * numerically to allow for the same map class to be utilized |
|
| 145 | - * In those cases, maps will be setup in an array like: |
|
| 146 | - * array( |
|
| 147 | - * 0 => array( 'EE_Meta_Capability' => array( |
|
| 148 | - * 'ee_edit_cap', array( 'Object_Name', |
|
| 149 | - * 'ee_edit_published_cap', |
|
| 150 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
| 151 | - * ) ) |
|
| 152 | - * 1 => ... |
|
| 153 | - * ) |
|
| 154 | - * instead of: |
|
| 155 | - * array( |
|
| 156 | - * 'EE_Meta_Capability' => array( |
|
| 157 | - * 'ee_edit_cap', array( 'Object_Name', |
|
| 158 | - * 'ee_edit_published_cap', |
|
| 159 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
| 160 | - * ), |
|
| 161 | - * ... |
|
| 162 | - * ) |
|
| 163 | - */ |
|
| 164 | - if (is_numeric($cap_class)) { |
|
| 165 | - $cap_class = key($args); |
|
| 166 | - $args = $args[ $cap_class ]; |
|
| 167 | - } |
|
| 142 | + /** |
|
| 143 | + * account for cases where capability maps may be indexed |
|
| 144 | + * numerically to allow for the same map class to be utilized |
|
| 145 | + * In those cases, maps will be setup in an array like: |
|
| 146 | + * array( |
|
| 147 | + * 0 => array( 'EE_Meta_Capability' => array( |
|
| 148 | + * 'ee_edit_cap', array( 'Object_Name', |
|
| 149 | + * 'ee_edit_published_cap', |
|
| 150 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
| 151 | + * ) ) |
|
| 152 | + * 1 => ... |
|
| 153 | + * ) |
|
| 154 | + * instead of: |
|
| 155 | + * array( |
|
| 156 | + * 'EE_Meta_Capability' => array( |
|
| 157 | + * 'ee_edit_cap', array( 'Object_Name', |
|
| 158 | + * 'ee_edit_published_cap', |
|
| 159 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
| 160 | + * ), |
|
| 161 | + * ... |
|
| 162 | + * ) |
|
| 163 | + */ |
|
| 164 | + if (is_numeric($cap_class)) { |
|
| 165 | + $cap_class = key($args); |
|
| 166 | + $args = $args[ $cap_class ]; |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - if (! class_exists($cap_class)) { |
|
| 170 | - throw new EE_Error( |
|
| 171 | - sprintf( |
|
| 172 | - esc_html__( |
|
| 173 | - 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
| 174 | - 'event_espresso' |
|
| 175 | - ), |
|
| 176 | - $identifier |
|
| 177 | - ) |
|
| 178 | - ); |
|
| 179 | - } |
|
| 169 | + if (! class_exists($cap_class)) { |
|
| 170 | + throw new EE_Error( |
|
| 171 | + sprintf( |
|
| 172 | + esc_html__( |
|
| 173 | + 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
| 174 | + 'event_espresso' |
|
| 175 | + ), |
|
| 176 | + $identifier |
|
| 177 | + ) |
|
| 178 | + ); |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - if (count($args) !== 2) { |
|
| 182 | - throw new EE_Error( |
|
| 183 | - sprintf( |
|
| 184 | - esc_html__( |
|
| 185 | - 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
| 186 | - 'event_espresso' |
|
| 187 | - ), |
|
| 188 | - $identifier |
|
| 189 | - ) |
|
| 190 | - ); |
|
| 191 | - } |
|
| 192 | - $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - return $cap_maps; |
|
| 196 | - } |
|
| 181 | + if (count($args) !== 2) { |
|
| 182 | + throw new EE_Error( |
|
| 183 | + sprintf( |
|
| 184 | + esc_html__( |
|
| 185 | + 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
| 186 | + 'event_espresso' |
|
| 187 | + ), |
|
| 188 | + $identifier |
|
| 189 | + ) |
|
| 190 | + ); |
|
| 191 | + } |
|
| 192 | + $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + return $cap_maps; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * @param string $identifier |
|
| 201 | - * @throws InvalidArgumentException |
|
| 202 | - * @throws InvalidDataTypeException |
|
| 203 | - * @throws InvalidInterfaceException |
|
| 204 | - */ |
|
| 205 | - public static function deregister($identifier = '') |
|
| 206 | - { |
|
| 207 | - if (! empty(self::$_registry[ $identifier ])) { |
|
| 208 | - if (! empty(self::$_registry[ $identifier ]['caps'])) { |
|
| 209 | - // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
|
| 210 | - $caps_to_remove = self::$_registry[ $identifier ]['caps']; |
|
| 211 | - if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
|
| 212 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
| 213 | - $capabilities->removeCaps($caps_to_remove); |
|
| 214 | - } else { |
|
| 215 | - add_action( |
|
| 216 | - 'AHEE__EE_System__core_loaded_and_ready', |
|
| 217 | - function () use ($caps_to_remove) { |
|
| 218 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
| 219 | - $capabilities->removeCaps($caps_to_remove); |
|
| 220 | - } |
|
| 221 | - ); |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - unset(self::$_registry[ $identifier ]); |
|
| 226 | - } |
|
| 199 | + /** |
|
| 200 | + * @param string $identifier |
|
| 201 | + * @throws InvalidArgumentException |
|
| 202 | + * @throws InvalidDataTypeException |
|
| 203 | + * @throws InvalidInterfaceException |
|
| 204 | + */ |
|
| 205 | + public static function deregister($identifier = '') |
|
| 206 | + { |
|
| 207 | + if (! empty(self::$_registry[ $identifier ])) { |
|
| 208 | + if (! empty(self::$_registry[ $identifier ]['caps'])) { |
|
| 209 | + // if it's too early to remove capabilities, wait to do this until core is loaded and ready |
|
| 210 | + $caps_to_remove = self::$_registry[ $identifier ]['caps']; |
|
| 211 | + if (did_action('AHEE__EE_System__core_loaded_and_ready')) { |
|
| 212 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
| 213 | + $capabilities->removeCaps($caps_to_remove); |
|
| 214 | + } else { |
|
| 215 | + add_action( |
|
| 216 | + 'AHEE__EE_System__core_loaded_and_ready', |
|
| 217 | + function () use ($caps_to_remove) { |
|
| 218 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
| 219 | + $capabilities->removeCaps($caps_to_remove); |
|
| 220 | + } |
|
| 221 | + ); |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + unset(self::$_registry[ $identifier ]); |
|
| 226 | + } |
|
| 227 | 227 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // make sure we don't register twice |
| 59 | - if (isset(self::$_ee_config_registry[ $identifier ])) { |
|
| 59 | + if (isset(self::$_ee_config_registry[$identifier])) { |
|
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | ); |
| 77 | 77 | } |
| 78 | 78 | // add incoming stuff to our registry property |
| 79 | - self::$_ee_config_registry[ $identifier ] = [ |
|
| 79 | + self::$_ee_config_registry[$identifier] = [ |
|
| 80 | 80 | 'section' => $setup_args['config_section'], |
| 81 | 81 | 'name' => $setup_args['config_name'], |
| 82 | 82 | ]; |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | { |
| 100 | 100 | foreach (self::$_ee_config_registry as $identifier => $settings) { |
| 101 | 101 | // first some validation of our incoming class_name. We'll throw an error early if its' not registered correctly |
| 102 | - if (! class_exists($identifier)) { |
|
| 102 | + if ( ! class_exists($identifier)) { |
|
| 103 | 103 | throw new EE_Error( |
| 104 | 104 | sprintf( |
| 105 | 105 | esc_html__( |
@@ -120,6 +120,6 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public static function deregister($identifier = '') |
| 122 | 122 | { |
| 123 | - unset(self::$_ee_config_registry[ $identifier ]); |
|
| 123 | + unset(self::$_ee_config_registry[$identifier]); |
|
| 124 | 124 | } |
| 125 | 125 | } |
@@ -11,114 +11,114 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class EE_Register_Config implements EEI_Plugin_API |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Holds registered EE_Config items |
|
| 16 | - * |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - protected static $_ee_config_registry = []; |
|
| 14 | + /** |
|
| 15 | + * Holds registered EE_Config items |
|
| 16 | + * |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + protected static $_ee_config_registry = []; |
|
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Handles registering the new config with the EE_Config::instance()->addons property |
|
| 24 | - * |
|
| 25 | - * @param string $identifier The name of the Config class being registered. |
|
| 26 | - * Note this class must extend EE_Config Base and must have |
|
| 27 | - * already been registered with an autoloader. |
|
| 28 | - * @param array $setup_args { |
|
| 29 | - * |
|
| 30 | - * @type string $config_name Optional. by default the new config will be registered to |
|
| 31 | - * EE_Config::instance()->addons->{config_class}, but supplying a "config_name" will set the property name |
|
| 32 | - * that this variable is accessible by. ie: EE_Config::instance()->addons->{config_name} |
|
| 33 | - * } |
|
| 34 | - * @return void |
|
| 35 | - * @throws EE_Error |
|
| 36 | - * |
|
| 37 | - * @since 4.3.0 |
|
| 38 | - */ |
|
| 39 | - public static function register($identifier = '', array $setup_args = []) |
|
| 40 | - { |
|
| 22 | + /** |
|
| 23 | + * Handles registering the new config with the EE_Config::instance()->addons property |
|
| 24 | + * |
|
| 25 | + * @param string $identifier The name of the Config class being registered. |
|
| 26 | + * Note this class must extend EE_Config Base and must have |
|
| 27 | + * already been registered with an autoloader. |
|
| 28 | + * @param array $setup_args { |
|
| 29 | + * |
|
| 30 | + * @type string $config_name Optional. by default the new config will be registered to |
|
| 31 | + * EE_Config::instance()->addons->{config_class}, but supplying a "config_name" will set the property name |
|
| 32 | + * that this variable is accessible by. ie: EE_Config::instance()->addons->{config_name} |
|
| 33 | + * } |
|
| 34 | + * @return void |
|
| 35 | + * @throws EE_Error |
|
| 36 | + * |
|
| 37 | + * @since 4.3.0 |
|
| 38 | + */ |
|
| 39 | + public static function register($identifier = '', array $setup_args = []) |
|
| 40 | + { |
|
| 41 | 41 | |
| 42 | - $setup_args['config_name'] = isset($setup_args['config_name']) && ! empty($setup_args['config_name']) |
|
| 43 | - ? $setup_args['config_name'] : $identifier; |
|
| 44 | - $setup_args['config_section'] = isset($setup_args['config_section']) && ! empty($setup_args['config_section']) |
|
| 45 | - ? $setup_args['config_section'] : 'addons'; |
|
| 42 | + $setup_args['config_name'] = isset($setup_args['config_name']) && ! empty($setup_args['config_name']) |
|
| 43 | + ? $setup_args['config_name'] : $identifier; |
|
| 44 | + $setup_args['config_section'] = isset($setup_args['config_section']) && ! empty($setup_args['config_section']) |
|
| 45 | + ? $setup_args['config_section'] : 'addons'; |
|
| 46 | 46 | |
| 47 | - // required fields MUST be present, so let's make sure they are. |
|
| 48 | - if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['config_name'])) { |
|
| 49 | - throw new EE_Error( |
|
| 50 | - esc_html__( |
|
| 51 | - 'In order to register a Config Class with EE_Register_Config::register(), you must include a "config_class" (the actual class name for this config class). As well, you can supply an array containing the following keys: "config_section" the main section of the config object the settings will be saved under (by default the new config will be registered under EE_Config::instance()->modules or EE_Config::instance()->addons depending on what type of class is calling this), "config_name" (by default the new config will be registered to EE_Config::instance()->{config_section}->{config_class}, but supplying a "config_name" will set the property name that this variable is accessible by. ie: EE_Config::instance()->{config_section}->{config_name})', |
|
| 52 | - 'event_espresso' |
|
| 53 | - ) |
|
| 54 | - ); |
|
| 55 | - } |
|
| 47 | + // required fields MUST be present, so let's make sure they are. |
|
| 48 | + if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['config_name'])) { |
|
| 49 | + throw new EE_Error( |
|
| 50 | + esc_html__( |
|
| 51 | + 'In order to register a Config Class with EE_Register_Config::register(), you must include a "config_class" (the actual class name for this config class). As well, you can supply an array containing the following keys: "config_section" the main section of the config object the settings will be saved under (by default the new config will be registered under EE_Config::instance()->modules or EE_Config::instance()->addons depending on what type of class is calling this), "config_name" (by default the new config will be registered to EE_Config::instance()->{config_section}->{config_class}, but supplying a "config_name" will set the property name that this variable is accessible by. ie: EE_Config::instance()->{config_section}->{config_name})', |
|
| 52 | + 'event_espresso' |
|
| 53 | + ) |
|
| 54 | + ); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - // make sure we don't register twice |
|
| 58 | - if (isset(self::$_ee_config_registry[ $identifier ])) { |
|
| 59 | - return; |
|
| 60 | - } |
|
| 57 | + // make sure we don't register twice |
|
| 58 | + if (isset(self::$_ee_config_registry[ $identifier ])) { |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - // first find out if this happened too late. |
|
| 64 | - if (did_action('AHEE__EE_System__load_core_configuration__begin')) { |
|
| 65 | - EE_Error::doing_it_wrong( |
|
| 66 | - __METHOD__, |
|
| 67 | - sprintf( |
|
| 68 | - esc_html__( |
|
| 69 | - 'An attempt to register "%s" as an EE_Config object has failed because it was not registered at the correct hookpoint. Please register before the "AHEE__EE_System__load_core_configuration__begin" hook has fired', |
|
| 70 | - 'event_espresso' |
|
| 71 | - ), |
|
| 72 | - $setup_args['config_name'] |
|
| 73 | - ), |
|
| 74 | - '4.3' |
|
| 75 | - ); |
|
| 76 | - } |
|
| 77 | - // add incoming stuff to our registry property |
|
| 78 | - self::$_ee_config_registry[ $identifier ] = [ |
|
| 79 | - 'section' => $setup_args['config_section'], |
|
| 80 | - 'name' => $setup_args['config_name'], |
|
| 81 | - ]; |
|
| 63 | + // first find out if this happened too late. |
|
| 64 | + if (did_action('AHEE__EE_System__load_core_configuration__begin')) { |
|
| 65 | + EE_Error::doing_it_wrong( |
|
| 66 | + __METHOD__, |
|
| 67 | + sprintf( |
|
| 68 | + esc_html__( |
|
| 69 | + 'An attempt to register "%s" as an EE_Config object has failed because it was not registered at the correct hookpoint. Please register before the "AHEE__EE_System__load_core_configuration__begin" hook has fired', |
|
| 70 | + 'event_espresso' |
|
| 71 | + ), |
|
| 72 | + $setup_args['config_name'] |
|
| 73 | + ), |
|
| 74 | + '4.3' |
|
| 75 | + ); |
|
| 76 | + } |
|
| 77 | + // add incoming stuff to our registry property |
|
| 78 | + self::$_ee_config_registry[ $identifier ] = [ |
|
| 79 | + 'section' => $setup_args['config_section'], |
|
| 80 | + 'name' => $setup_args['config_name'], |
|
| 81 | + ]; |
|
| 82 | 82 | |
| 83 | - add_action('AHEE__EE_Config___load_core_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
| 84 | - add_action('AHEE__EE_Config__update_espresso_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
| 85 | - } |
|
| 83 | + add_action('AHEE__EE_Config___load_core_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
| 84 | + add_action('AHEE__EE_Config__update_espresso_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Callback for the AHEE__EE_Config___load_core_config__end hook. |
|
| 90 | - * basically just calls EE_Config->get_config() which will take care of loading or creating our config object for us |
|
| 91 | - * |
|
| 92 | - * @param EE_Config $EE_Config |
|
| 93 | - * @return void |
|
| 94 | - * @throws EE_Error |
|
| 95 | - * @since 4.3.0 |
|
| 96 | - */ |
|
| 97 | - public static function set_config(EE_Config $EE_Config) |
|
| 98 | - { |
|
| 99 | - foreach (self::$_ee_config_registry as $identifier => $settings) { |
|
| 100 | - // first some validation of our incoming class_name. We'll throw an error early if its' not registered correctly |
|
| 101 | - if (! class_exists($identifier)) { |
|
| 102 | - throw new EE_Error( |
|
| 103 | - sprintf( |
|
| 104 | - esc_html__( |
|
| 105 | - 'The "%s" config class can not be registered with EE_Config because it does not exist. Verify that an autoloader has been set for this class', |
|
| 106 | - 'event_espresso' |
|
| 107 | - ), |
|
| 108 | - $identifier |
|
| 109 | - ) |
|
| 110 | - ); |
|
| 111 | - } |
|
| 112 | - $EE_Config->get_config($settings['section'], $settings['name'], $identifier); |
|
| 113 | - } |
|
| 114 | - } |
|
| 88 | + /** |
|
| 89 | + * Callback for the AHEE__EE_Config___load_core_config__end hook. |
|
| 90 | + * basically just calls EE_Config->get_config() which will take care of loading or creating our config object for us |
|
| 91 | + * |
|
| 92 | + * @param EE_Config $EE_Config |
|
| 93 | + * @return void |
|
| 94 | + * @throws EE_Error |
|
| 95 | + * @since 4.3.0 |
|
| 96 | + */ |
|
| 97 | + public static function set_config(EE_Config $EE_Config) |
|
| 98 | + { |
|
| 99 | + foreach (self::$_ee_config_registry as $identifier => $settings) { |
|
| 100 | + // first some validation of our incoming class_name. We'll throw an error early if its' not registered correctly |
|
| 101 | + if (! class_exists($identifier)) { |
|
| 102 | + throw new EE_Error( |
|
| 103 | + sprintf( |
|
| 104 | + esc_html__( |
|
| 105 | + 'The "%s" config class can not be registered with EE_Config because it does not exist. Verify that an autoloader has been set for this class', |
|
| 106 | + 'event_espresso' |
|
| 107 | + ), |
|
| 108 | + $identifier |
|
| 109 | + ) |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | + $EE_Config->get_config($settings['section'], $settings['name'], $identifier); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @param string $identifier |
|
| 119 | - */ |
|
| 120 | - public static function deregister($identifier = '') |
|
| 121 | - { |
|
| 122 | - unset(self::$_ee_config_registry[ $identifier ]); |
|
| 123 | - } |
|
| 117 | + /** |
|
| 118 | + * @param string $identifier |
|
| 119 | + */ |
|
| 120 | + public static function deregister($identifier = '') |
|
| 121 | + { |
|
| 122 | + unset(self::$_ee_config_registry[ $identifier ]); |
|
| 123 | + } |
|
| 124 | 124 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function __construct() |
| 73 | 73 | { |
| 74 | - if (! $this->_model_name_extended) { |
|
| 74 | + if ( ! $this->_model_name_extended) { |
|
| 75 | 75 | throw new EE_Error( |
| 76 | 76 | esc_html__( |
| 77 | 77 | "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | ) |
| 80 | 80 | ); |
| 81 | 81 | } |
| 82 | - $construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end'; |
|
| 82 | + $construct_end_action = 'AHEE__EEM_'.$this->_model_name_extended.'__construct__end'; |
|
| 83 | 83 | if (did_action($construct_end_action)) { |
| 84 | 84 | throw new EE_Error( |
| 85 | 85 | sprintf( |
@@ -94,15 +94,15 @@ discard block |
||
| 94 | 94 | ); |
| 95 | 95 | } |
| 96 | 96 | add_filter( |
| 97 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
| 97 | + 'FHEE__EEM_'.$this->_model_name_extended.'__construct__tables', |
|
| 98 | 98 | array($this, 'add_extra_tables_on_filter') |
| 99 | 99 | ); |
| 100 | 100 | add_filter( |
| 101 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
| 101 | + 'FHEE__EEM_'.$this->_model_name_extended.'__construct__fields', |
|
| 102 | 102 | array($this, 'add_extra_fields_on_filter') |
| 103 | 103 | ); |
| 104 | 104 | add_filter( |
| 105 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
| 105 | + 'FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations', |
|
| 106 | 106 | array($this, 'add_extra_relations_on_filter') |
| 107 | 107 | ); |
| 108 | 108 | $this->_register_extending_methods(); |
@@ -127,12 +127,12 @@ discard block |
||
| 127 | 127 | { |
| 128 | 128 | if ($this->_extra_fields) { |
| 129 | 129 | foreach ($this->_extra_fields as $table_alias => $fields) { |
| 130 | - if (! isset($existing_fields[ $table_alias ])) { |
|
| 131 | - $existing_fields[ $table_alias ] = array(); |
|
| 130 | + if ( ! isset($existing_fields[$table_alias])) { |
|
| 131 | + $existing_fields[$table_alias] = array(); |
|
| 132 | 132 | } |
| 133 | - $existing_fields[ $table_alias ] = array_merge( |
|
| 134 | - (array) $existing_fields[ $table_alias ], |
|
| 135 | - $this->_extra_fields[ $table_alias ] |
|
| 133 | + $existing_fields[$table_alias] = array_merge( |
|
| 134 | + (array) $existing_fields[$table_alias], |
|
| 135 | + $this->_extra_fields[$table_alias] |
|
| 136 | 136 | ); |
| 137 | 137 | } |
| 138 | 138 | } |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
| 164 | 164 | add_filter( |
| 165 | 165 | $callback_name, |
| 166 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
| 166 | + array($this, self::dynamic_callback_method_prefix.$method_name_on_model), |
|
| 167 | 167 | 10, |
| 168 | 168 | 10 |
| 169 | 169 | ); |
@@ -178,15 +178,15 @@ discard block |
||
| 178 | 178 | public function deregister() |
| 179 | 179 | { |
| 180 | 180 | remove_filter( |
| 181 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
| 181 | + 'FHEE__EEM_'.$this->_model_name_extended.'__construct__tables', |
|
| 182 | 182 | array($this, 'add_extra_tables_on_filter') |
| 183 | 183 | ); |
| 184 | 184 | remove_filter( |
| 185 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
| 185 | + 'FHEE__EEM_'.$this->_model_name_extended.'__construct__fields', |
|
| 186 | 186 | array($this, 'add_extra_fields_on_filter') |
| 187 | 187 | ); |
| 188 | 188 | remove_filter( |
| 189 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
| 189 | + 'FHEE__EEM_'.$this->_model_name_extended.'__construct__model_relations', |
|
| 190 | 190 | array($this, 'add_extra_relations_on_filter') |
| 191 | 191 | ); |
| 192 | 192 | $all_methods = get_class_methods(get_class($this)); |
@@ -196,13 +196,13 @@ discard block |
||
| 196 | 196 | $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
| 197 | 197 | remove_filter( |
| 198 | 198 | $callback_name, |
| 199 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
| 199 | + array($this, self::dynamic_callback_method_prefix.$method_name_on_model), |
|
| 200 | 200 | 10 |
| 201 | 201 | ); |
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | /** @var EEM_Base $model_to_reset */ |
| 205 | - $model_to_reset = 'EEM_' . $this->_model_name_extended; |
|
| 205 | + $model_to_reset = 'EEM_'.$this->_model_name_extended; |
|
| 206 | 206 | if (class_exists($model_to_reset)) { |
| 207 | 207 | $model_to_reset::reset(); |
| 208 | 208 | } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
| 225 | 225 | $this->_ = $model_called; |
| 226 | 226 | // phpcs:enable |
| 227 | - $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
| 227 | + $extending_method = self::extending_method_prefix.$method_called_on_model; |
|
| 228 | 228 | if (method_exists($this, $extending_method)) { |
| 229 | 229 | return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model); |
| 230 | 230 | } else { |
@@ -43,211 +43,211 @@ |
||
| 43 | 43 | */ |
| 44 | 44 | abstract class EEME_Base |
| 45 | 45 | { |
| 46 | - const extending_method_prefix = 'ext_'; |
|
| 47 | - const dynamic_callback_method_prefix = 'dynamic_callback_method_'; |
|
| 48 | - |
|
| 49 | - protected $_extra_tables = array(); |
|
| 50 | - protected $_extra_fields = array(); |
|
| 51 | - protected $_extra_relations = array(); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * The model name that is extended (not classname) |
|
| 55 | - * |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 58 | - protected $_model_name_extended = null; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * The model this extends |
|
| 62 | - * |
|
| 63 | - * @var EEM_Base |
|
| 64 | - */ |
|
| 65 | - protected $_ = null; |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @throws \EE_Error |
|
| 70 | - */ |
|
| 71 | - public function __construct() |
|
| 72 | - { |
|
| 73 | - if (! $this->_model_name_extended) { |
|
| 74 | - throw new EE_Error( |
|
| 75 | - esc_html__( |
|
| 76 | - "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
|
| 77 | - "event_espresso" |
|
| 78 | - ) |
|
| 79 | - ); |
|
| 80 | - } |
|
| 81 | - $construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end'; |
|
| 82 | - if (did_action($construct_end_action)) { |
|
| 83 | - throw new EE_Error( |
|
| 84 | - sprintf( |
|
| 85 | - esc_html__( |
|
| 86 | - "Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired", |
|
| 87 | - "event_espresso" |
|
| 88 | - ), |
|
| 89 | - get_class($this), |
|
| 90 | - $this->_model_name_extended, |
|
| 91 | - $construct_end_action |
|
| 92 | - ) |
|
| 93 | - ); |
|
| 94 | - } |
|
| 95 | - add_filter( |
|
| 96 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
| 97 | - array($this, 'add_extra_tables_on_filter') |
|
| 98 | - ); |
|
| 99 | - add_filter( |
|
| 100 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
| 101 | - array($this, 'add_extra_fields_on_filter') |
|
| 102 | - ); |
|
| 103 | - add_filter( |
|
| 104 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
| 105 | - array($this, 'add_extra_relations_on_filter') |
|
| 106 | - ); |
|
| 107 | - $this->_register_extending_methods(); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param array $existing_tables |
|
| 113 | - * @return array |
|
| 114 | - */ |
|
| 115 | - public function add_extra_tables_on_filter($existing_tables) |
|
| 116 | - { |
|
| 117 | - return array_merge((array) $existing_tables, $this->_extra_tables); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @param array $existing_fields |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - public function add_extra_fields_on_filter($existing_fields) |
|
| 126 | - { |
|
| 127 | - if ($this->_extra_fields) { |
|
| 128 | - foreach ($this->_extra_fields as $table_alias => $fields) { |
|
| 129 | - if (! isset($existing_fields[ $table_alias ])) { |
|
| 130 | - $existing_fields[ $table_alias ] = array(); |
|
| 131 | - } |
|
| 132 | - $existing_fields[ $table_alias ] = array_merge( |
|
| 133 | - (array) $existing_fields[ $table_alias ], |
|
| 134 | - $this->_extra_fields[ $table_alias ] |
|
| 135 | - ); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - return $existing_fields; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param array $existing_relations |
|
| 144 | - * @return array |
|
| 145 | - */ |
|
| 146 | - public function add_extra_relations_on_filter($existing_relations) |
|
| 147 | - { |
|
| 148 | - return array_merge((array) $existing_relations, $this->_extra_relations); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
|
| 154 | - * model extended. (Internally uses filters, and the __call magic method) |
|
| 155 | - */ |
|
| 156 | - protected function _register_extending_methods() |
|
| 157 | - { |
|
| 158 | - $all_methods = get_class_methods(get_class($this)); |
|
| 159 | - foreach ($all_methods as $method_name) { |
|
| 160 | - if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
| 161 | - $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
| 162 | - $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
| 163 | - add_filter( |
|
| 164 | - $callback_name, |
|
| 165 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
| 166 | - 10, |
|
| 167 | - 10 |
|
| 168 | - ); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
|
| 175 | - * model extended. (Internally uses filters, and the __call magic method) |
|
| 176 | - */ |
|
| 177 | - public function deregister() |
|
| 178 | - { |
|
| 179 | - remove_filter( |
|
| 180 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
| 181 | - array($this, 'add_extra_tables_on_filter') |
|
| 182 | - ); |
|
| 183 | - remove_filter( |
|
| 184 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
| 185 | - array($this, 'add_extra_fields_on_filter') |
|
| 186 | - ); |
|
| 187 | - remove_filter( |
|
| 188 | - 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
| 189 | - array($this, 'add_extra_relations_on_filter') |
|
| 190 | - ); |
|
| 191 | - $all_methods = get_class_methods(get_class($this)); |
|
| 192 | - foreach ($all_methods as $method_name) { |
|
| 193 | - if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
| 194 | - $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
| 195 | - $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
| 196 | - remove_filter( |
|
| 197 | - $callback_name, |
|
| 198 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
| 199 | - 10 |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - /** @var EEM_Base $model_to_reset */ |
|
| 204 | - $model_to_reset = 'EEM_' . $this->_model_name_extended; |
|
| 205 | - if (class_exists($model_to_reset)) { |
|
| 206 | - $model_to_reset::reset(); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @param string $callback_method_name |
|
| 213 | - * @param array $args |
|
| 214 | - * @return mixed |
|
| 215 | - * @throws EE_Error |
|
| 216 | - */ |
|
| 217 | - public function __call($callback_method_name, $args) |
|
| 218 | - { |
|
| 219 | - if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
| 220 | - // it's a dynamic callback for a method name |
|
| 221 | - $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
|
| 222 | - list($original_return_val, $model_called, $args_provided_to_method_on_model) = (array) $args; |
|
| 223 | - // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
|
| 224 | - $this->_ = $model_called; |
|
| 225 | - // phpcs:enable |
|
| 226 | - $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
| 227 | - if (method_exists($this, $extending_method)) { |
|
| 228 | - return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model); |
|
| 229 | - } else { |
|
| 230 | - throw new EE_Error( |
|
| 231 | - sprintf( |
|
| 232 | - esc_html__( |
|
| 233 | - "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", |
|
| 234 | - "event_espresso" |
|
| 235 | - ), |
|
| 236 | - $this->_model_name_extended, |
|
| 237 | - get_class($this), |
|
| 238 | - $extending_method, |
|
| 239 | - $extending_method |
|
| 240 | - ) |
|
| 241 | - ); |
|
| 242 | - } |
|
| 243 | - } else { |
|
| 244 | - throw new EE_Error( |
|
| 245 | - sprintf( |
|
| 246 | - esc_html__("There is no method named '%s' on '%s'", "event_espresso"), |
|
| 247 | - $callback_method_name, |
|
| 248 | - get_class($this) |
|
| 249 | - ) |
|
| 250 | - ); |
|
| 251 | - } |
|
| 252 | - } |
|
| 46 | + const extending_method_prefix = 'ext_'; |
|
| 47 | + const dynamic_callback_method_prefix = 'dynamic_callback_method_'; |
|
| 48 | + |
|
| 49 | + protected $_extra_tables = array(); |
|
| 50 | + protected $_extra_fields = array(); |
|
| 51 | + protected $_extra_relations = array(); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * The model name that is extended (not classname) |
|
| 55 | + * |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | + protected $_model_name_extended = null; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * The model this extends |
|
| 62 | + * |
|
| 63 | + * @var EEM_Base |
|
| 64 | + */ |
|
| 65 | + protected $_ = null; |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @throws \EE_Error |
|
| 70 | + */ |
|
| 71 | + public function __construct() |
|
| 72 | + { |
|
| 73 | + if (! $this->_model_name_extended) { |
|
| 74 | + throw new EE_Error( |
|
| 75 | + esc_html__( |
|
| 76 | + "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
|
| 77 | + "event_espresso" |
|
| 78 | + ) |
|
| 79 | + ); |
|
| 80 | + } |
|
| 81 | + $construct_end_action = 'AHEE__EEM_' . $this->_model_name_extended . '__construct__end'; |
|
| 82 | + if (did_action($construct_end_action)) { |
|
| 83 | + throw new EE_Error( |
|
| 84 | + sprintf( |
|
| 85 | + esc_html__( |
|
| 86 | + "Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired", |
|
| 87 | + "event_espresso" |
|
| 88 | + ), |
|
| 89 | + get_class($this), |
|
| 90 | + $this->_model_name_extended, |
|
| 91 | + $construct_end_action |
|
| 92 | + ) |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | + add_filter( |
|
| 96 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
| 97 | + array($this, 'add_extra_tables_on_filter') |
|
| 98 | + ); |
|
| 99 | + add_filter( |
|
| 100 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
| 101 | + array($this, 'add_extra_fields_on_filter') |
|
| 102 | + ); |
|
| 103 | + add_filter( |
|
| 104 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
| 105 | + array($this, 'add_extra_relations_on_filter') |
|
| 106 | + ); |
|
| 107 | + $this->_register_extending_methods(); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param array $existing_tables |
|
| 113 | + * @return array |
|
| 114 | + */ |
|
| 115 | + public function add_extra_tables_on_filter($existing_tables) |
|
| 116 | + { |
|
| 117 | + return array_merge((array) $existing_tables, $this->_extra_tables); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @param array $existing_fields |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + public function add_extra_fields_on_filter($existing_fields) |
|
| 126 | + { |
|
| 127 | + if ($this->_extra_fields) { |
|
| 128 | + foreach ($this->_extra_fields as $table_alias => $fields) { |
|
| 129 | + if (! isset($existing_fields[ $table_alias ])) { |
|
| 130 | + $existing_fields[ $table_alias ] = array(); |
|
| 131 | + } |
|
| 132 | + $existing_fields[ $table_alias ] = array_merge( |
|
| 133 | + (array) $existing_fields[ $table_alias ], |
|
| 134 | + $this->_extra_fields[ $table_alias ] |
|
| 135 | + ); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + return $existing_fields; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param array $existing_relations |
|
| 144 | + * @return array |
|
| 145 | + */ |
|
| 146 | + public function add_extra_relations_on_filter($existing_relations) |
|
| 147 | + { |
|
| 148 | + return array_merge((array) $existing_relations, $this->_extra_relations); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
|
| 154 | + * model extended. (Internally uses filters, and the __call magic method) |
|
| 155 | + */ |
|
| 156 | + protected function _register_extending_methods() |
|
| 157 | + { |
|
| 158 | + $all_methods = get_class_methods(get_class($this)); |
|
| 159 | + foreach ($all_methods as $method_name) { |
|
| 160 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
| 161 | + $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
| 162 | + $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
| 163 | + add_filter( |
|
| 164 | + $callback_name, |
|
| 165 | + array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
| 166 | + 10, |
|
| 167 | + 10 |
|
| 168 | + ); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
|
| 175 | + * model extended. (Internally uses filters, and the __call magic method) |
|
| 176 | + */ |
|
| 177 | + public function deregister() |
|
| 178 | + { |
|
| 179 | + remove_filter( |
|
| 180 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__tables', |
|
| 181 | + array($this, 'add_extra_tables_on_filter') |
|
| 182 | + ); |
|
| 183 | + remove_filter( |
|
| 184 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__fields', |
|
| 185 | + array($this, 'add_extra_fields_on_filter') |
|
| 186 | + ); |
|
| 187 | + remove_filter( |
|
| 188 | + 'FHEE__EEM_' . $this->_model_name_extended . '__construct__model_relations', |
|
| 189 | + array($this, 'add_extra_relations_on_filter') |
|
| 190 | + ); |
|
| 191 | + $all_methods = get_class_methods(get_class($this)); |
|
| 192 | + foreach ($all_methods as $method_name) { |
|
| 193 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
| 194 | + $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
| 195 | + $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
| 196 | + remove_filter( |
|
| 197 | + $callback_name, |
|
| 198 | + array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
| 199 | + 10 |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + /** @var EEM_Base $model_to_reset */ |
|
| 204 | + $model_to_reset = 'EEM_' . $this->_model_name_extended; |
|
| 205 | + if (class_exists($model_to_reset)) { |
|
| 206 | + $model_to_reset::reset(); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @param string $callback_method_name |
|
| 213 | + * @param array $args |
|
| 214 | + * @return mixed |
|
| 215 | + * @throws EE_Error |
|
| 216 | + */ |
|
| 217 | + public function __call($callback_method_name, $args) |
|
| 218 | + { |
|
| 219 | + if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
| 220 | + // it's a dynamic callback for a method name |
|
| 221 | + $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
|
| 222 | + list($original_return_val, $model_called, $args_provided_to_method_on_model) = (array) $args; |
|
| 223 | + // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
|
| 224 | + $this->_ = $model_called; |
|
| 225 | + // phpcs:enable |
|
| 226 | + $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
| 227 | + if (method_exists($this, $extending_method)) { |
|
| 228 | + return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model); |
|
| 229 | + } else { |
|
| 230 | + throw new EE_Error( |
|
| 231 | + sprintf( |
|
| 232 | + esc_html__( |
|
| 233 | + "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", |
|
| 234 | + "event_espresso" |
|
| 235 | + ), |
|
| 236 | + $this->_model_name_extended, |
|
| 237 | + get_class($this), |
|
| 238 | + $extending_method, |
|
| 239 | + $extending_method |
|
| 240 | + ) |
|
| 241 | + ); |
|
| 242 | + } |
|
| 243 | + } else { |
|
| 244 | + throw new EE_Error( |
|
| 245 | + sprintf( |
|
| 246 | + esc_html__("There is no method named '%s' on '%s'", "event_espresso"), |
|
| 247 | + $callback_method_name, |
|
| 248 | + get_class($this) |
|
| 249 | + ) |
|
| 250 | + ); |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | 253 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | public function __construct() |
| 51 | 51 | { |
| 52 | - if (! $this->_model_name_extended) { |
|
| 52 | + if ( ! $this->_model_name_extended) { |
|
| 53 | 53 | throw new EE_Error( |
| 54 | 54 | sprintf( |
| 55 | 55 | esc_html__( |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | ) |
| 60 | 60 | ); |
| 61 | 61 | } |
| 62 | - if (did_action('AHEE__EE_' . $this->_model_name_extended . '__construct__end')) { |
|
| 62 | + if (did_action('AHEE__EE_'.$this->_model_name_extended.'__construct__end')) { |
|
| 63 | 63 | throw new EE_Error( |
| 64 | 64 | sprintf( |
| 65 | 65 | esc_html__( |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model"; |
| 88 | 88 | add_filter( |
| 89 | 89 | $callback_name, |
| 90 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
| 90 | + array($this, self::dynamic_callback_method_prefix.$method_name_on_model), |
|
| 91 | 91 | 10, |
| 92 | 92 | 10 |
| 93 | 93 | ); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model"; |
| 109 | 109 | remove_filter( |
| 110 | 110 | $callback_name, |
| 111 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
| 111 | + array($this, self::dynamic_callback_method_prefix.$method_name_on_model), |
|
| 112 | 112 | 10 |
| 113 | 113 | ); |
| 114 | 114 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $this->_ = $model_called; |
| 128 | 128 | // phpcs:enable |
| 129 | 129 | $args_provided_to_method_on_model = $args[2]; |
| 130 | - $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
| 130 | + $extending_method = self::extending_method_prefix.$method_called_on_model; |
|
| 131 | 131 | if (method_exists($this, $extending_method)) { |
| 132 | 132 | return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model); |
| 133 | 133 | } else { |
@@ -31,126 +31,126 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class EEE_Base_Class |
| 33 | 33 | { |
| 34 | - const extending_method_prefix = 'ext_'; |
|
| 35 | - const dynamic_callback_method_prefix = 'dynamic_callback_method_'; |
|
| 36 | - /** |
|
| 37 | - * The model name that is extended (not classname) |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $_model_name_extended = null; |
|
| 42 | - /** |
|
| 43 | - * The model this extends |
|
| 44 | - * |
|
| 45 | - * @var EE_Base_Class |
|
| 46 | - */ |
|
| 47 | - protected $_ = null; |
|
| 34 | + const extending_method_prefix = 'ext_'; |
|
| 35 | + const dynamic_callback_method_prefix = 'dynamic_callback_method_'; |
|
| 36 | + /** |
|
| 37 | + * The model name that is extended (not classname) |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $_model_name_extended = null; |
|
| 42 | + /** |
|
| 43 | + * The model this extends |
|
| 44 | + * |
|
| 45 | + * @var EE_Base_Class |
|
| 46 | + */ |
|
| 47 | + protected $_ = null; |
|
| 48 | 48 | |
| 49 | - public function __construct() |
|
| 50 | - { |
|
| 51 | - if (! $this->_model_name_extended) { |
|
| 52 | - throw new EE_Error( |
|
| 53 | - sprintf( |
|
| 54 | - esc_html__( |
|
| 55 | - "When declaring a class extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
|
| 56 | - "event_espresso" |
|
| 57 | - ) |
|
| 58 | - ) |
|
| 59 | - ); |
|
| 60 | - } |
|
| 61 | - if (did_action('AHEE__EE_' . $this->_model_name_extended . '__construct__end')) { |
|
| 62 | - throw new EE_Error( |
|
| 63 | - sprintf( |
|
| 64 | - esc_html__( |
|
| 65 | - "Hooked in model object extension '%s' too late! The model object %s has already been used!", |
|
| 66 | - "event_espresso" |
|
| 67 | - ), |
|
| 68 | - get_class($this), |
|
| 69 | - $this->_model_name_extended |
|
| 70 | - ) |
|
| 71 | - ); |
|
| 72 | - } |
|
| 73 | - $this->_register_extending_methods(); |
|
| 74 | - } |
|
| 49 | + public function __construct() |
|
| 50 | + { |
|
| 51 | + if (! $this->_model_name_extended) { |
|
| 52 | + throw new EE_Error( |
|
| 53 | + sprintf( |
|
| 54 | + esc_html__( |
|
| 55 | + "When declaring a class extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
|
| 56 | + "event_espresso" |
|
| 57 | + ) |
|
| 58 | + ) |
|
| 59 | + ); |
|
| 60 | + } |
|
| 61 | + if (did_action('AHEE__EE_' . $this->_model_name_extended . '__construct__end')) { |
|
| 62 | + throw new EE_Error( |
|
| 63 | + sprintf( |
|
| 64 | + esc_html__( |
|
| 65 | + "Hooked in model object extension '%s' too late! The model object %s has already been used!", |
|
| 66 | + "event_espresso" |
|
| 67 | + ), |
|
| 68 | + get_class($this), |
|
| 69 | + $this->_model_name_extended |
|
| 70 | + ) |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | + $this->_register_extending_methods(); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
|
| 78 | - * model extended. (Internally uses filters, and the __call magic method) |
|
| 79 | - */ |
|
| 80 | - protected function _register_extending_methods() |
|
| 81 | - { |
|
| 82 | - $all_methods = get_class_methods(get_class($this)); |
|
| 83 | - foreach ($all_methods as $method_name) { |
|
| 84 | - if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
| 85 | - $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
| 86 | - $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model"; |
|
| 87 | - add_filter( |
|
| 88 | - $callback_name, |
|
| 89 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
| 90 | - 10, |
|
| 91 | - 10 |
|
| 92 | - ); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 76 | + /** |
|
| 77 | + * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
|
| 78 | + * model extended. (Internally uses filters, and the __call magic method) |
|
| 79 | + */ |
|
| 80 | + protected function _register_extending_methods() |
|
| 81 | + { |
|
| 82 | + $all_methods = get_class_methods(get_class($this)); |
|
| 83 | + foreach ($all_methods as $method_name) { |
|
| 84 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
| 85 | + $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
| 86 | + $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model"; |
|
| 87 | + add_filter( |
|
| 88 | + $callback_name, |
|
| 89 | + array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
| 90 | + 10, |
|
| 91 | + 10 |
|
| 92 | + ); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
|
| 99 | - * model extended. (Internally uses filters, and the __call magic method) |
|
| 100 | - */ |
|
| 101 | - public function deregister() |
|
| 102 | - { |
|
| 103 | - $all_methods = get_class_methods(get_class($this)); |
|
| 104 | - foreach ($all_methods as $method_name) { |
|
| 105 | - if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
| 106 | - $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
| 107 | - $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model"; |
|
| 108 | - remove_filter( |
|
| 109 | - $callback_name, |
|
| 110 | - array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
| 111 | - 10 |
|
| 112 | - ); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 97 | + /** |
|
| 98 | + * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
|
| 99 | + * model extended. (Internally uses filters, and the __call magic method) |
|
| 100 | + */ |
|
| 101 | + public function deregister() |
|
| 102 | + { |
|
| 103 | + $all_methods = get_class_methods(get_class($this)); |
|
| 104 | + foreach ($all_methods as $method_name) { |
|
| 105 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
| 106 | + $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
| 107 | + $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model"; |
|
| 108 | + remove_filter( |
|
| 109 | + $callback_name, |
|
| 110 | + array($this, self::dynamic_callback_method_prefix . $method_name_on_model), |
|
| 111 | + 10 |
|
| 112 | + ); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | - public function __call($callback_method_name, $args) |
|
| 119 | - { |
|
| 120 | - if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
| 121 | - // it's a dynamic callback for a method name |
|
| 122 | - $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
|
| 123 | - $original_return_val = $args[0]; |
|
| 124 | - $model_called = $args[1]; |
|
| 125 | - // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
|
| 126 | - $this->_ = $model_called; |
|
| 127 | - // phpcs:enable |
|
| 128 | - $args_provided_to_method_on_model = $args[2]; |
|
| 129 | - $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
| 130 | - if (method_exists($this, $extending_method)) { |
|
| 131 | - return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model); |
|
| 132 | - } else { |
|
| 133 | - throw new EE_Error( |
|
| 134 | - sprintf( |
|
| 135 | - esc_html__( |
|
| 136 | - "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", |
|
| 137 | - "event_espresso" |
|
| 138 | - ), |
|
| 139 | - $this->_model_name_extended, |
|
| 140 | - get_class($this), |
|
| 141 | - $extending_method, |
|
| 142 | - $extending_method |
|
| 143 | - ) |
|
| 144 | - ); |
|
| 145 | - } |
|
| 146 | - } else { |
|
| 147 | - throw new EE_Error( |
|
| 148 | - sprintf( |
|
| 149 | - esc_html__("There is no method named '%s' on '%s'", "event_espresso"), |
|
| 150 | - $callback_method_name, |
|
| 151 | - get_class($this) |
|
| 152 | - ) |
|
| 153 | - ); |
|
| 154 | - } |
|
| 155 | - } |
|
| 118 | + public function __call($callback_method_name, $args) |
|
| 119 | + { |
|
| 120 | + if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
| 121 | + // it's a dynamic callback for a method name |
|
| 122 | + $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
|
| 123 | + $original_return_val = $args[0]; |
|
| 124 | + $model_called = $args[1]; |
|
| 125 | + // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
|
| 126 | + $this->_ = $model_called; |
|
| 127 | + // phpcs:enable |
|
| 128 | + $args_provided_to_method_on_model = $args[2]; |
|
| 129 | + $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
| 130 | + if (method_exists($this, $extending_method)) { |
|
| 131 | + return call_user_func_array(array($this, $extending_method), $args_provided_to_method_on_model); |
|
| 132 | + } else { |
|
| 133 | + throw new EE_Error( |
|
| 134 | + sprintf( |
|
| 135 | + esc_html__( |
|
| 136 | + "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", |
|
| 137 | + "event_espresso" |
|
| 138 | + ), |
|
| 139 | + $this->_model_name_extended, |
|
| 140 | + get_class($this), |
|
| 141 | + $extending_method, |
|
| 142 | + $extending_method |
|
| 143 | + ) |
|
| 144 | + ); |
|
| 145 | + } |
|
| 146 | + } else { |
|
| 147 | + throw new EE_Error( |
|
| 148 | + sprintf( |
|
| 149 | + esc_html__("There is no method named '%s' on '%s'", "event_espresso"), |
|
| 150 | + $callback_method_name, |
|
| 151 | + get_class($this) |
|
| 152 | + ) |
|
| 153 | + ); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -70,15 +70,15 @@ discard block |
||
| 70 | 70 | // offsets: 0 . 1 . 2 . 3 . 4 |
| 71 | 71 | $version_parts = explode('.', $min_core_version); |
| 72 | 72 | // check they specified the micro version (after 2nd period) |
| 73 | - if (! isset($version_parts[2])) { |
|
| 73 | + if ( ! isset($version_parts[2])) { |
|
| 74 | 74 | $version_parts[2] = '0'; |
| 75 | 75 | } |
| 76 | 76 | // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
| 77 | 77 | // soon we can assume that's 'rc', but this current version is 'alpha' |
| 78 | - if (! isset($version_parts[3])) { |
|
| 78 | + if ( ! isset($version_parts[3])) { |
|
| 79 | 79 | $version_parts[3] = 'dev'; |
| 80 | 80 | } |
| 81 | - if (! isset($version_parts[4])) { |
|
| 81 | + if ( ! isset($version_parts[4])) { |
|
| 82 | 82 | $version_parts[4] = '000'; |
| 83 | 83 | } |
| 84 | 84 | return implode('.', $version_parts); |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
| 266 | 266 | // does this addon work with this version of core or WordPress ? |
| 267 | 267 | // does this addon work with this version of core or WordPress ? |
| 268 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 268 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 269 | 269 | return; |
| 270 | 270 | } |
| 271 | 271 | // register namespaces |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | ) |
| 330 | 330 | ); |
| 331 | 331 | } |
| 332 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 332 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 333 | 333 | throw new EE_Error( |
| 334 | 334 | sprintf( |
| 335 | 335 | esc_html__( |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | ); |
| 342 | 342 | } |
| 343 | 343 | // check that addon has not already been registered with that name |
| 344 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 344 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 345 | 345 | throw new EE_Error( |
| 346 | 346 | sprintf( |
| 347 | 347 | esc_html__( |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
| 374 | 374 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
| 375 | 375 | ? $class_name |
| 376 | - : 'EE_' . $class_name; |
|
| 376 | + : 'EE_'.$class_name; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | |
@@ -539,9 +539,9 @@ discard block |
||
| 539 | 539 | $incompatibility_message = ''; |
| 540 | 540 | // check whether this addon version is compatible with EE core |
| 541 | 541 | if ( |
| 542 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 542 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 543 | 543 | && ! self::_meets_min_core_version_requirement( |
| 544 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 544 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 545 | 545 | $addon_settings['version'] |
| 546 | 546 | ) |
| 547 | 547 | ) { |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | ), |
| 553 | 553 | $addon_name, |
| 554 | 554 | '<br />', |
| 555 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 555 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 556 | 556 | '<span style="font-weight: bold; color: #D54E21;">', |
| 557 | 557 | '</span><br />' |
| 558 | 558 | ); |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | '</span><br />' |
| 585 | 585 | ); |
| 586 | 586 | } |
| 587 | - if (! empty($incompatibility_message)) { |
|
| 587 | + if ( ! empty($incompatibility_message)) { |
|
| 588 | 588 | // remove 'activate' from the REQUEST |
| 589 | 589 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
| 590 | 590 | /** @var RequestInterface $request */ |
@@ -614,11 +614,11 @@ discard block |
||
| 614 | 614 | */ |
| 615 | 615 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
| 616 | 616 | { |
| 617 | - if (! empty($setup_args['pue_options'])) { |
|
| 618 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 617 | + if ( ! empty($setup_args['pue_options'])) { |
|
| 618 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
| 619 | 619 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
| 620 | 620 | ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
| 621 | - : 'espresso_' . strtolower($class_name), |
|
| 621 | + : 'espresso_'.strtolower($class_name), |
|
| 622 | 622 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
| 623 | 623 | ? (string) $setup_args['pue_options']['plugin_basename'] |
| 624 | 624 | : plugin_basename($setup_args['main_file_path']), |
@@ -677,12 +677,12 @@ discard block |
||
| 677 | 677 | // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
| 678 | 678 | // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
| 679 | 679 | if ( |
| 680 | - ! isset(self::$_settings[ $addon_name ]) |
|
| 681 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 682 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 680 | + ! isset(self::$_settings[$addon_name]) |
|
| 681 | + || (isset(self::$_settings[$addon_name]) |
|
| 682 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 683 | 683 | ) |
| 684 | 684 | ) { |
| 685 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 685 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 686 | 686 | $addon = self::_load_and_init_addon_class($addon_name); |
| 687 | 687 | $addon->set_activation_indicator_option(); |
| 688 | 688 | // dont bother setting up the rest of the addon. |
@@ -708,10 +708,10 @@ discard block |
||
| 708 | 708 | ); |
| 709 | 709 | } |
| 710 | 710 | // make sure addon settings are set correctly without overwriting anything existing |
| 711 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 712 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 711 | + if (isset(self::$_settings[$addon_name])) { |
|
| 712 | + self::$_settings[$addon_name] += $addon_settings; |
|
| 713 | 713 | } else { |
| 714 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 714 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 715 | 715 | } |
| 716 | 716 | return false; |
| 717 | 717 | } |
@@ -724,13 +724,13 @@ discard block |
||
| 724 | 724 | */ |
| 725 | 725 | private static function _setup_autoloaders($addon_name) |
| 726 | 726 | { |
| 727 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 727 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 728 | 728 | // setup autoloader for single file |
| 729 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 729 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 730 | 730 | } |
| 731 | 731 | // setup autoloaders for folders |
| 732 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 733 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 732 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 733 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 734 | 734 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
| 735 | 735 | } |
| 736 | 736 | } |
@@ -748,27 +748,27 @@ discard block |
||
| 748 | 748 | { |
| 749 | 749 | // register new models |
| 750 | 750 | if ( |
| 751 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 752 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 751 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 752 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 753 | 753 | ) { |
| 754 | 754 | EE_Register_Model::register( |
| 755 | 755 | $addon_name, |
| 756 | 756 | array( |
| 757 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 758 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 757 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 758 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 759 | 759 | ) |
| 760 | 760 | ); |
| 761 | 761 | } |
| 762 | 762 | // register model extensions |
| 763 | 763 | if ( |
| 764 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 765 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 764 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 765 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 766 | 766 | ) { |
| 767 | 767 | EE_Register_Model_Extensions::register( |
| 768 | 768 | $addon_name, |
| 769 | 769 | array( |
| 770 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 771 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 770 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 771 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 772 | 772 | ) |
| 773 | 773 | ); |
| 774 | 774 | } |
@@ -783,10 +783,10 @@ discard block |
||
| 783 | 783 | private static function _register_data_migration_scripts($addon_name) |
| 784 | 784 | { |
| 785 | 785 | // setup DMS |
| 786 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 786 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 787 | 787 | EE_Register_Data_Migration_Scripts::register( |
| 788 | 788 | $addon_name, |
| 789 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 789 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 790 | 790 | ); |
| 791 | 791 | } |
| 792 | 792 | } |
@@ -800,12 +800,12 @@ discard block |
||
| 800 | 800 | private static function _register_config($addon_name) |
| 801 | 801 | { |
| 802 | 802 | // if config_class is present let's register config. |
| 803 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 803 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 804 | 804 | EE_Register_Config::register( |
| 805 | - self::$_settings[ $addon_name ]['config_class'], |
|
| 805 | + self::$_settings[$addon_name]['config_class'], |
|
| 806 | 806 | array( |
| 807 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 808 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 807 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 808 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 809 | 809 | ) |
| 810 | 810 | ); |
| 811 | 811 | } |
@@ -819,10 +819,10 @@ discard block |
||
| 819 | 819 | */ |
| 820 | 820 | private static function _register_admin_pages($addon_name) |
| 821 | 821 | { |
| 822 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 822 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 823 | 823 | EE_Register_Admin_Page::register( |
| 824 | 824 | $addon_name, |
| 825 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 825 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 826 | 826 | ); |
| 827 | 827 | } |
| 828 | 828 | } |
@@ -835,10 +835,10 @@ discard block |
||
| 835 | 835 | */ |
| 836 | 836 | private static function _register_modules($addon_name) |
| 837 | 837 | { |
| 838 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 838 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 839 | 839 | EE_Register_Module::register( |
| 840 | 840 | $addon_name, |
| 841 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 841 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 842 | 842 | ); |
| 843 | 843 | } |
| 844 | 844 | } |
@@ -852,16 +852,16 @@ discard block |
||
| 852 | 852 | private static function _register_shortcodes($addon_name) |
| 853 | 853 | { |
| 854 | 854 | if ( |
| 855 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 856 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 855 | + ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 856 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 857 | 857 | ) { |
| 858 | 858 | EE_Register_Shortcode::register( |
| 859 | 859 | $addon_name, |
| 860 | 860 | array( |
| 861 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 862 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] : array(), |
|
| 863 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 864 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(), |
|
| 861 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 862 | + ? self::$_settings[$addon_name]['shortcode_paths'] : array(), |
|
| 863 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 864 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] : array(), |
|
| 865 | 865 | ) |
| 866 | 866 | ); |
| 867 | 867 | } |
@@ -875,10 +875,10 @@ discard block |
||
| 875 | 875 | */ |
| 876 | 876 | private static function _register_widgets($addon_name) |
| 877 | 877 | { |
| 878 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 878 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 879 | 879 | EE_Register_Widget::register( |
| 880 | 880 | $addon_name, |
| 881 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 881 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 882 | 882 | ); |
| 883 | 883 | } |
| 884 | 884 | } |
@@ -891,12 +891,12 @@ discard block |
||
| 891 | 891 | */ |
| 892 | 892 | private static function _register_capabilities($addon_name) |
| 893 | 893 | { |
| 894 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 894 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 895 | 895 | EE_Register_Capabilities::register( |
| 896 | 896 | $addon_name, |
| 897 | 897 | array( |
| 898 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 899 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 898 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 899 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 900 | 900 | ) |
| 901 | 901 | ); |
| 902 | 902 | } |
@@ -909,7 +909,7 @@ discard block |
||
| 909 | 909 | */ |
| 910 | 910 | private static function _register_message_types($addon_name) |
| 911 | 911 | { |
| 912 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 912 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 913 | 913 | add_action( |
| 914 | 914 | 'EE_Brewing_Regular___messages_caf', |
| 915 | 915 | array('EE_Register_Addon', 'register_message_types') |
@@ -926,15 +926,15 @@ discard block |
||
| 926 | 926 | private static function _register_custom_post_types($addon_name) |
| 927 | 927 | { |
| 928 | 928 | if ( |
| 929 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 930 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 929 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 930 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 931 | 931 | ) { |
| 932 | 932 | EE_Register_CPT::register( |
| 933 | 933 | $addon_name, |
| 934 | 934 | array( |
| 935 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 936 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 937 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 935 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 936 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 937 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 938 | 938 | ) |
| 939 | 939 | ); |
| 940 | 940 | } |
@@ -952,10 +952,10 @@ discard block |
||
| 952 | 952 | */ |
| 953 | 953 | private static function _register_payment_methods($addon_name) |
| 954 | 954 | { |
| 955 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 955 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 956 | 956 | EE_Register_Payment_Method::register( |
| 957 | 957 | $addon_name, |
| 958 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 958 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 959 | 959 | ); |
| 960 | 960 | } |
| 961 | 961 | } |
@@ -971,10 +971,10 @@ discard block |
||
| 971 | 971 | */ |
| 972 | 972 | private static function registerPrivacyPolicies($addon_name) |
| 973 | 973 | { |
| 974 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
| 974 | + if ( ! empty(self::$_settings[$addon_name]['privacy_policies'])) { |
|
| 975 | 975 | EE_Register_Privacy_Policy::register( |
| 976 | 976 | $addon_name, |
| 977 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
| 977 | + self::$_settings[$addon_name]['privacy_policies'] |
|
| 978 | 978 | ); |
| 979 | 979 | } |
| 980 | 980 | } |
@@ -986,10 +986,10 @@ discard block |
||
| 986 | 986 | */ |
| 987 | 987 | private static function registerPersonalDataExporters($addon_name) |
| 988 | 988 | { |
| 989 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
| 989 | + if ( ! empty(self::$_settings[$addon_name]['personal_data_exporters'])) { |
|
| 990 | 990 | EE_Register_Personal_Data_Eraser::register( |
| 991 | 991 | $addon_name, |
| 992 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
| 992 | + self::$_settings[$addon_name]['personal_data_exporters'] |
|
| 993 | 993 | ); |
| 994 | 994 | } |
| 995 | 995 | } |
@@ -1001,10 +1001,10 @@ discard block |
||
| 1001 | 1001 | */ |
| 1002 | 1002 | private static function registerPersonalDataErasers($addon_name) |
| 1003 | 1003 | { |
| 1004 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
| 1004 | + if ( ! empty(self::$_settings[$addon_name]['personal_data_erasers'])) { |
|
| 1005 | 1005 | EE_Register_Personal_Data_Eraser::register( |
| 1006 | 1006 | $addon_name, |
| 1007 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
| 1007 | + self::$_settings[$addon_name]['personal_data_erasers'] |
|
| 1008 | 1008 | ); |
| 1009 | 1009 | } |
| 1010 | 1010 | } |
@@ -1022,10 +1022,10 @@ discard block |
||
| 1022 | 1022 | private static function _load_and_init_addon_class($addon_name) |
| 1023 | 1023 | { |
| 1024 | 1024 | $addon = LoaderFactory::getLoader()->getShared( |
| 1025 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 1025 | + self::$_settings[$addon_name]['class_name'], |
|
| 1026 | 1026 | array('EE_Registry::create(addon)' => true) |
| 1027 | 1027 | ); |
| 1028 | - if (! $addon instanceof EE_Addon) { |
|
| 1028 | + if ( ! $addon instanceof EE_Addon) { |
|
| 1029 | 1029 | throw new DomainException( |
| 1030 | 1030 | sprintf( |
| 1031 | 1031 | esc_html__( |
@@ -1044,28 +1044,28 @@ discard block |
||
| 1044 | 1044 | EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
| 1045 | 1045 | |
| 1046 | 1046 | $addon->set_name($addon_name); |
| 1047 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 1048 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 1049 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 1050 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 1051 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 1052 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 1053 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 1054 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 1055 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 1056 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 1047 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 1048 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 1049 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 1050 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 1051 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 1052 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 1053 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 1054 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 1055 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 1056 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 1057 | 1057 | // setup the add-on's pue_slug if we have one. |
| 1058 | - if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
| 1059 | - $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
| 1058 | + if ( ! empty(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug'])) { |
|
| 1059 | + $addon->setPueSlug(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug']); |
|
| 1060 | 1060 | } |
| 1061 | 1061 | // unfortunately this can't be hooked in upon construction, |
| 1062 | 1062 | // because we don't have the plugin's mainfile path upon construction. |
| 1063 | 1063 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
| 1064 | 1064 | // call any additional admin_callback functions during load_admin_controller hook |
| 1065 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 1065 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 1066 | 1066 | add_action( |
| 1067 | 1067 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
| 1068 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 1068 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 1069 | 1069 | ); |
| 1070 | 1070 | } |
| 1071 | 1071 | return $addon; |
@@ -1081,19 +1081,19 @@ discard block |
||
| 1081 | 1081 | { |
| 1082 | 1082 | if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
| 1083 | 1083 | // using supplied Domain object |
| 1084 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
| 1085 | - ? self::$_settings[ $addon_name ]['domain'] |
|
| 1084 | + $domain = self::$_settings[$addon_name]['domain'] instanceof DomainInterface |
|
| 1085 | + ? self::$_settings[$addon_name]['domain'] |
|
| 1086 | 1086 | : null; |
| 1087 | 1087 | // or construct one using Domain FQCN |
| 1088 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
| 1088 | + if ($domain === null && self::$_settings[$addon_name]['domain_fqcn'] !== '') { |
|
| 1089 | 1089 | $domain = LoaderFactory::getLoader()->getShared( |
| 1090 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 1090 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
| 1091 | 1091 | [ |
| 1092 | 1092 | new EventEspresso\core\domain\values\FilePath( |
| 1093 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
| 1093 | + self::$_settings[$addon_name]['main_file_path'] |
|
| 1094 | 1094 | ), |
| 1095 | 1095 | EventEspresso\core\domain\values\Version::fromString( |
| 1096 | - self::$_settings[ $addon_name ]['version'] |
|
| 1096 | + self::$_settings[$addon_name]['version'] |
|
| 1097 | 1097 | ), |
| 1098 | 1098 | ] |
| 1099 | 1099 | ); |
@@ -1116,11 +1116,11 @@ discard block |
||
| 1116 | 1116 | public static function load_pue_update() |
| 1117 | 1117 | { |
| 1118 | 1118 | // load PUE client |
| 1119 | - require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
| 1119 | + require_once EE_THIRD_PARTY.'pue/pue-client.php'; |
|
| 1120 | 1120 | $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
| 1121 | 1121 | // cycle thru settings |
| 1122 | 1122 | foreach (self::$_settings as $settings) { |
| 1123 | - if (! empty($settings['pue_options'])) { |
|
| 1123 | + if ( ! empty($settings['pue_options'])) { |
|
| 1124 | 1124 | // initiate the class and start the plugin update engine! |
| 1125 | 1125 | new PluginUpdateEngineChecker( |
| 1126 | 1126 | // host file URL |
@@ -1128,7 +1128,7 @@ discard block |
||
| 1128 | 1128 | // plugin slug(s) |
| 1129 | 1129 | array( |
| 1130 | 1130 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
| 1131 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1131 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
| 1132 | 1132 | ), |
| 1133 | 1133 | // options |
| 1134 | 1134 | array( |
@@ -1157,7 +1157,7 @@ discard block |
||
| 1157 | 1157 | public static function register_message_types() |
| 1158 | 1158 | { |
| 1159 | 1159 | foreach (self::$_settings as $settings) { |
| 1160 | - if (! empty($settings['message_types'])) { |
|
| 1160 | + if ( ! empty($settings['message_types'])) { |
|
| 1161 | 1161 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
| 1162 | 1162 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
| 1163 | 1163 | } |
@@ -1178,74 +1178,74 @@ discard block |
||
| 1178 | 1178 | */ |
| 1179 | 1179 | public static function deregister($addon_name = '') |
| 1180 | 1180 | { |
| 1181 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1181 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
| 1182 | 1182 | try { |
| 1183 | 1183 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
| 1184 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1185 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1184 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 1185 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1186 | 1186 | // setup DMS |
| 1187 | 1187 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
| 1188 | 1188 | } |
| 1189 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1189 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1190 | 1190 | // register admin page |
| 1191 | 1191 | EE_Register_Admin_Page::deregister($addon_name); |
| 1192 | 1192 | } |
| 1193 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1193 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1194 | 1194 | // add to list of modules to be registered |
| 1195 | 1195 | EE_Register_Module::deregister($addon_name); |
| 1196 | 1196 | } |
| 1197 | 1197 | if ( |
| 1198 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1199 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1198 | + ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1199 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 1200 | 1200 | ) { |
| 1201 | 1201 | // add to list of shortcodes to be registered |
| 1202 | 1202 | EE_Register_Shortcode::deregister($addon_name); |
| 1203 | 1203 | } |
| 1204 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1204 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1205 | 1205 | // if config_class present let's register config. |
| 1206 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1206 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1207 | 1207 | } |
| 1208 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1208 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1209 | 1209 | // add to list of widgets to be registered |
| 1210 | 1210 | EE_Register_Widget::deregister($addon_name); |
| 1211 | 1211 | } |
| 1212 | 1212 | if ( |
| 1213 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1214 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1213 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1214 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1215 | 1215 | ) { |
| 1216 | 1216 | // add to list of shortcodes to be registered |
| 1217 | 1217 | EE_Register_Model::deregister($addon_name); |
| 1218 | 1218 | } |
| 1219 | 1219 | if ( |
| 1220 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1221 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1220 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1221 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1222 | 1222 | ) { |
| 1223 | 1223 | // add to list of shortcodes to be registered |
| 1224 | 1224 | EE_Register_Model_Extensions::deregister($addon_name); |
| 1225 | 1225 | } |
| 1226 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1227 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
| 1226 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1227 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 1228 | 1228 | EE_Register_Message_Type::deregister($message_type); |
| 1229 | 1229 | } |
| 1230 | 1230 | } |
| 1231 | 1231 | // deregister capabilities for addon |
| 1232 | 1232 | if ( |
| 1233 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1234 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1233 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1234 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1235 | 1235 | ) { |
| 1236 | 1236 | EE_Register_Capabilities::deregister($addon_name); |
| 1237 | 1237 | } |
| 1238 | 1238 | // deregister custom_post_types for addon |
| 1239 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1239 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1240 | 1240 | EE_Register_CPT::deregister($addon_name); |
| 1241 | 1241 | } |
| 1242 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1242 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1243 | 1243 | EE_Register_Payment_Method::deregister($addon_name); |
| 1244 | 1244 | } |
| 1245 | 1245 | $addon = EE_Registry::instance()->getAddon($class_name); |
| 1246 | 1246 | if ($addon instanceof EE_Addon) { |
| 1247 | 1247 | remove_action( |
| 1248 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1248 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
| 1249 | 1249 | array($addon, 'deactivation') |
| 1250 | 1250 | ); |
| 1251 | 1251 | remove_action( |
@@ -1269,7 +1269,7 @@ discard block |
||
| 1269 | 1269 | } catch (Exception $e) { |
| 1270 | 1270 | new ExceptionLogger($e); |
| 1271 | 1271 | } |
| 1272 | - unset(self::$_settings[ $addon_name ]); |
|
| 1272 | + unset(self::$_settings[$addon_name]); |
|
| 1273 | 1273 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
| 1274 | 1274 | } |
| 1275 | 1275 | } |
@@ -22,1254 +22,1254 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class EE_Register_Addon implements EEI_Plugin_API |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * possibly truncated version of the EE core version string |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected static $_core_version = ''; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Holds values for registered addons |
|
| 34 | - * |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - protected static $_settings = array(); |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
| 41 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 42 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 43 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
| 44 | - * EE core with knowledge of ALL the addons out there. |
|
| 45 | - * If you want NO versions of an addon to run with a certain version of core, |
|
| 46 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 47 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 48 | - * minimum plugin version. |
|
| 49 | - * @access protected |
|
| 50 | - */ |
|
| 51 | - protected static $_incompatible_addons = array( |
|
| 52 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 53 | - 'Promotions' => '1.0.0.rc.084', |
|
| 54 | - ); |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 59 | - * not just '4.3.0'. |
|
| 60 | - * So if the addon developer doesn't provide that full version string, |
|
| 61 | - * fill in the blanks for them |
|
| 62 | - * |
|
| 63 | - * @param string $min_core_version |
|
| 64 | - * @return string always like '4.3.0.rc.000' |
|
| 65 | - */ |
|
| 66 | - protected static function _effective_version($min_core_version) |
|
| 67 | - { |
|
| 68 | - // versions: 4 . 3 . 1 . p . 123 |
|
| 69 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 70 | - $version_parts = explode('.', $min_core_version); |
|
| 71 | - // check they specified the micro version (after 2nd period) |
|
| 72 | - if (! isset($version_parts[2])) { |
|
| 73 | - $version_parts[2] = '0'; |
|
| 74 | - } |
|
| 75 | - // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 76 | - // soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 77 | - if (! isset($version_parts[3])) { |
|
| 78 | - $version_parts[3] = 'dev'; |
|
| 79 | - } |
|
| 80 | - if (! isset($version_parts[4])) { |
|
| 81 | - $version_parts[4] = '000'; |
|
| 82 | - } |
|
| 83 | - return implode('.', $version_parts); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Returns whether or not the min core version requirement of the addon is met |
|
| 89 | - * |
|
| 90 | - * @param string $min_core_version the minimum core version required by the addon |
|
| 91 | - * @param string $actual_core_version the actual core version, optional |
|
| 92 | - * @return boolean |
|
| 93 | - */ |
|
| 94 | - public static function _meets_min_core_version_requirement( |
|
| 95 | - $min_core_version, |
|
| 96 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 97 | - ) { |
|
| 98 | - return version_compare( |
|
| 99 | - self::_effective_version($actual_core_version), |
|
| 100 | - self::_effective_version($min_core_version), |
|
| 101 | - '>=' |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Method for registering new EE_Addons. |
|
| 108 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 109 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 110 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 111 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 112 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 113 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 114 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 115 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
| 116 | - * |
|
| 117 | - * @since 4.3.0 |
|
| 118 | - * @param string $addon_name [Required] the EE_Addon's name. |
|
| 119 | - * @param array $setup_args { |
|
| 120 | - * An array of arguments provided for registering |
|
| 121 | - * the message type. |
|
| 122 | - * @type string $class_name the addon's main file name. |
|
| 123 | - * If left blank, generated from the addon name, |
|
| 124 | - * changes something like "calendar" to |
|
| 125 | - * "EE_Calendar" |
|
| 126 | - * @type string $min_core_version the minimum version of EE Core that the |
|
| 127 | - * addon will work with. eg "4.8.1.rc.084" |
|
| 128 | - * @type string $version the "software" version for the addon. eg |
|
| 129 | - * "1.0.0.p" for a first stable release, or |
|
| 130 | - * "1.0.0.rc.043" for a version in progress |
|
| 131 | - * @type string $main_file_path the full server path to the main file |
|
| 132 | - * loaded directly by WP |
|
| 133 | - * @type DomainInterface $domain child class of |
|
| 134 | - * EventEspresso\core\domain\DomainBase |
|
| 135 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
| 136 | - * for the addon's Domain class |
|
| 137 | - * (see EventEspresso\core\domain\Domain) |
|
| 138 | - * @type string $admin_path full server path to the folder where the |
|
| 139 | - * addon\'s admin files reside |
|
| 140 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
| 141 | - * first invoked, can be used for hooking into |
|
| 142 | - * any admin page |
|
| 143 | - * @type string $config_section the section name for this addon's |
|
| 144 | - * configuration settings section |
|
| 145 | - * (defaults to "addons") |
|
| 146 | - * @type string $config_class the class name for this addon's |
|
| 147 | - * configuration settings object |
|
| 148 | - * @type string $config_name the class name for this addon's |
|
| 149 | - * configuration settings object |
|
| 150 | - * @type string $autoloader_paths [Required] an array of class names and the full |
|
| 151 | - * server paths to those files. |
|
| 152 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
| 153 | - * folders containing classes that might be |
|
| 154 | - * invoked by the addon |
|
| 155 | - * @type string $dms_paths [Required] an array of full server paths to |
|
| 156 | - * folders that contain data migration scripts. |
|
| 157 | - * The key should be the EE_Addon class name that |
|
| 158 | - * this set of data migration scripts belongs to. |
|
| 159 | - * If the EE_Addon class is namespaced, then this |
|
| 160 | - * needs to be the Fully Qualified Class Name |
|
| 161 | - * @type string $module_paths an array of full server paths to any |
|
| 162 | - * EED_Modules used by the addon |
|
| 163 | - * @type string $shortcode_paths an array of full server paths to folders |
|
| 164 | - * that contain EES_Shortcodes |
|
| 165 | - * @type string $widget_paths an array of full server paths to folders |
|
| 166 | - * that contain WP_Widgets |
|
| 167 | - * @type string $pue_options |
|
| 168 | - * @type array $capabilities an array indexed by role name |
|
| 169 | - * (i.e administrator,author ) and the values |
|
| 170 | - * are an array of caps to add to the role. |
|
| 171 | - * 'administrator' => array( |
|
| 172 | - * 'read_addon', |
|
| 173 | - * 'edit_addon', |
|
| 174 | - * etc. |
|
| 175 | - * ). |
|
| 176 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 177 | - * for any addons that need to register any |
|
| 178 | - * special meta mapped capabilities. Should |
|
| 179 | - * be indexed where the key is the |
|
| 180 | - * EE_Meta_Capability_Map class name and the |
|
| 181 | - * values are the arguments sent to the class. |
|
| 182 | - * @type array $model_paths array of folders containing DB models |
|
| 183 | - * @see EE_Register_Model |
|
| 184 | - * @type array $class_paths array of folders containing DB classes |
|
| 185 | - * @see EE_Register_Model |
|
| 186 | - * @type array $model_extension_paths array of folders containing DB model |
|
| 187 | - * extensions |
|
| 188 | - * @see EE_Register_Model_Extension |
|
| 189 | - * @type array $class_extension_paths array of folders containing DB class |
|
| 190 | - * extensions |
|
| 191 | - * @see EE_Register_Model_Extension |
|
| 192 | - * @type array message_types { |
|
| 193 | - * An array of message types with the key as |
|
| 194 | - * the message type name and the values as |
|
| 195 | - * below: |
|
| 196 | - * @type string $mtfilename [Required] The filename of the message type |
|
| 197 | - * being registered. This will be the main |
|
| 198 | - * EE_{Message Type Name}_message_type class. |
|
| 199 | - * for example: |
|
| 200 | - * EE_Declined_Registration_message_type.class.php |
|
| 201 | - * @type array $autoloadpaths [Required] An array of paths to add to the |
|
| 202 | - * messages autoloader for the new message type. |
|
| 203 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 204 | - * type should activate with. Each value in |
|
| 205 | - * the |
|
| 206 | - * array |
|
| 207 | - * should match the name property of a |
|
| 208 | - * EE_messenger. Optional. |
|
| 209 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 210 | - * type should validate with. Each value in |
|
| 211 | - * the |
|
| 212 | - * array |
|
| 213 | - * should match the name property of an |
|
| 214 | - * EE_messenger. |
|
| 215 | - * Optional. |
|
| 216 | - * } |
|
| 217 | - * @type array $custom_post_types |
|
| 218 | - * @type array $custom_taxonomies |
|
| 219 | - * @type array $payment_method_paths each element is the folder containing the |
|
| 220 | - * EE_PMT_Base child class |
|
| 221 | - * (eg, |
|
| 222 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 223 | - * which contains the files |
|
| 224 | - * EE_PMT_Payomatic.pm.php) |
|
| 225 | - * @type array $default_terms |
|
| 226 | - * @type array $namespace { |
|
| 227 | - * An array with two items for registering the |
|
| 228 | - * addon's namespace. (If, for some reason, you |
|
| 229 | - * require additional namespaces, |
|
| 230 | - * use |
|
| 231 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 232 | - * directly) |
|
| 233 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 234 | - * @type string $FQNS the namespace prefix |
|
| 235 | - * @type string $DIR a base directory for class files in the |
|
| 236 | - * namespace. |
|
| 237 | - * } |
|
| 238 | - * } |
|
| 239 | - * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
| 240 | - * privacy policy classes) or FQCNs (specific |
|
| 241 | - * classnames of privacy policy classes) |
|
| 242 | - * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
| 243 | - * privacy policy classes) or FQCNs (specific |
|
| 244 | - * classnames of privacy policy classes) |
|
| 245 | - * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
| 246 | - * privacy policy classes) or FQCNs (specific |
|
| 247 | - * classnames of privacy policy classes) |
|
| 248 | - * @return void |
|
| 249 | - * @throws DomainException |
|
| 250 | - * @throws EE_Error |
|
| 251 | - * @throws InvalidArgumentException |
|
| 252 | - * @throws InvalidDataTypeException |
|
| 253 | - * @throws InvalidInterfaceException |
|
| 254 | - */ |
|
| 255 | - public static function register($addon_name = '', array $setup_args = array()) |
|
| 256 | - { |
|
| 257 | - // required fields MUST be present, so let's make sure they are. |
|
| 258 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 259 | - // get class name for addon |
|
| 260 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 261 | - // setup $_settings array from incoming values. |
|
| 262 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 263 | - // setup PUE |
|
| 264 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 265 | - // does this addon work with this version of core or WordPress ? |
|
| 266 | - // does this addon work with this version of core or WordPress ? |
|
| 267 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 268 | - return; |
|
| 269 | - } |
|
| 270 | - // register namespaces |
|
| 271 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 272 | - // check if this is an activation request |
|
| 273 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 274 | - // dont bother setting up the rest of the addon atm |
|
| 275 | - return; |
|
| 276 | - } |
|
| 277 | - // we need cars |
|
| 278 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 279 | - // register new models and extensions |
|
| 280 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 281 | - // setup DMS |
|
| 282 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 283 | - // if config_class is present let's register config. |
|
| 284 | - EE_Register_Addon::_register_config($addon_name); |
|
| 285 | - // register admin pages |
|
| 286 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 287 | - // add to list of modules to be registered |
|
| 288 | - EE_Register_Addon::_register_modules($addon_name); |
|
| 289 | - // add to list of shortcodes to be registered |
|
| 290 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 291 | - // add to list of widgets to be registered |
|
| 292 | - EE_Register_Addon::_register_widgets($addon_name); |
|
| 293 | - // register capability related stuff. |
|
| 294 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
| 295 | - // any message type to register? |
|
| 296 | - EE_Register_Addon::_register_message_types($addon_name); |
|
| 297 | - // any custom post type/ custom capabilities or default terms to register |
|
| 298 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 299 | - // and any payment methods |
|
| 300 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 301 | - // and privacy policy generators |
|
| 302 | - EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
| 303 | - // and privacy policy generators |
|
| 304 | - EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
| 305 | - // and privacy policy generators |
|
| 306 | - EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
| 307 | - // load and instantiate main addon class |
|
| 308 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 309 | - // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 310 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * @param string $addon_name |
|
| 316 | - * @param array $setup_args |
|
| 317 | - * @return void |
|
| 318 | - * @throws EE_Error |
|
| 319 | - */ |
|
| 320 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
| 321 | - { |
|
| 322 | - // required fields MUST be present, so let's make sure they are. |
|
| 323 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 324 | - throw new EE_Error( |
|
| 325 | - esc_html__( |
|
| 326 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 327 | - 'event_espresso' |
|
| 328 | - ) |
|
| 329 | - ); |
|
| 330 | - } |
|
| 331 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 332 | - throw new EE_Error( |
|
| 333 | - sprintf( |
|
| 334 | - esc_html__( |
|
| 335 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 336 | - 'event_espresso' |
|
| 337 | - ), |
|
| 338 | - implode(',', array_keys($setup_args)) |
|
| 339 | - ) |
|
| 340 | - ); |
|
| 341 | - } |
|
| 342 | - // check that addon has not already been registered with that name |
|
| 343 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 344 | - throw new EE_Error( |
|
| 345 | - sprintf( |
|
| 346 | - esc_html__( |
|
| 347 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 348 | - 'event_espresso' |
|
| 349 | - ), |
|
| 350 | - $addon_name |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * @param string $addon_name |
|
| 359 | - * @param array $setup_args |
|
| 360 | - * @return string |
|
| 361 | - */ |
|
| 362 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
| 363 | - { |
|
| 364 | - if (empty($setup_args['class_name'])) { |
|
| 365 | - // generate one by first separating name with spaces |
|
| 366 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 367 | - // capitalize, then replace spaces with underscores |
|
| 368 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 369 | - } else { |
|
| 370 | - $class_name = $setup_args['class_name']; |
|
| 371 | - } |
|
| 372 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 373 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 374 | - ? $class_name |
|
| 375 | - : 'EE_' . $class_name; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * @param string $class_name |
|
| 381 | - * @param array $setup_args |
|
| 382 | - * @return array |
|
| 383 | - */ |
|
| 384 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
| 385 | - { |
|
| 386 | - // setup $_settings array from incoming values. |
|
| 387 | - $addon_settings = array( |
|
| 388 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 389 | - 'class_name' => $class_name, |
|
| 390 | - // the addon slug for use in URLs, etc |
|
| 391 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 392 | - ? (string) $setup_args['plugin_slug'] |
|
| 393 | - : '', |
|
| 394 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 395 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 396 | - ? (string) $setup_args['plugin_action_slug'] |
|
| 397 | - : '', |
|
| 398 | - // the "software" version for the addon |
|
| 399 | - 'version' => isset($setup_args['version']) |
|
| 400 | - ? (string) $setup_args['version'] |
|
| 401 | - : '', |
|
| 402 | - // the minimum version of EE Core that the addon will work with |
|
| 403 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 404 | - ? (string) $setup_args['min_core_version'] |
|
| 405 | - : '', |
|
| 406 | - // the minimum version of WordPress that the addon will work with |
|
| 407 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 408 | - ? (string) $setup_args['min_wp_version'] |
|
| 409 | - : EE_MIN_WP_VER_REQUIRED, |
|
| 410 | - // full server path to main file (file loaded directly by WP) |
|
| 411 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 412 | - ? (string) $setup_args['main_file_path'] |
|
| 413 | - : '', |
|
| 414 | - // instance of \EventEspresso\core\domain\DomainInterface |
|
| 415 | - 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
| 416 | - ? $setup_args['domain'] |
|
| 417 | - : null, |
|
| 418 | - // Fully Qualified Class Name for the addon's Domain class |
|
| 419 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 420 | - ? (string) $setup_args['domain_fqcn'] |
|
| 421 | - : '', |
|
| 422 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 423 | - 'admin_path' => isset($setup_args['admin_path']) |
|
| 424 | - ? (string) $setup_args['admin_path'] : '', |
|
| 425 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 426 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 427 | - ? (string) $setup_args['admin_callback'] |
|
| 428 | - : '', |
|
| 429 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 430 | - 'config_section' => isset($setup_args['config_section']) |
|
| 431 | - ? (string) $setup_args['config_section'] |
|
| 432 | - : 'addons', |
|
| 433 | - // the class name for this addon's configuration settings object |
|
| 434 | - 'config_class' => isset($setup_args['config_class']) |
|
| 435 | - ? (string) $setup_args['config_class'] : '', |
|
| 436 | - // the name given to the config for this addons' configuration settings object (optional) |
|
| 437 | - 'config_name' => isset($setup_args['config_name']) |
|
| 438 | - ? (string) $setup_args['config_name'] : '', |
|
| 439 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 440 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 441 | - ? (array) $setup_args['autoloader_paths'] |
|
| 442 | - : array(), |
|
| 443 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 444 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 445 | - ? (array) $setup_args['autoloader_folders'] |
|
| 446 | - : array(), |
|
| 447 | - // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
| 448 | - // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
| 449 | - // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 450 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 451 | - ? (array) $setup_args['dms_paths'] |
|
| 452 | - : array(), |
|
| 453 | - // array of full server paths to any EED_Modules used by the addon |
|
| 454 | - 'module_paths' => isset($setup_args['module_paths']) |
|
| 455 | - ? (array) $setup_args['module_paths'] |
|
| 456 | - : array(), |
|
| 457 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
| 458 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 459 | - ? (array) $setup_args['shortcode_paths'] |
|
| 460 | - : array(), |
|
| 461 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 462 | - ? (array) $setup_args['shortcode_fqcns'] |
|
| 463 | - : array(), |
|
| 464 | - // array of full server paths to any WP_Widgets used by the addon |
|
| 465 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 466 | - ? (array) $setup_args['widget_paths'] |
|
| 467 | - : array(), |
|
| 468 | - // array of PUE options used by the addon |
|
| 469 | - 'pue_options' => isset($setup_args['pue_options']) |
|
| 470 | - ? (array) $setup_args['pue_options'] |
|
| 471 | - : array(), |
|
| 472 | - 'message_types' => isset($setup_args['message_types']) |
|
| 473 | - ? (array) $setup_args['message_types'] |
|
| 474 | - : array(), |
|
| 475 | - 'capabilities' => isset($setup_args['capabilities']) |
|
| 476 | - ? (array) $setup_args['capabilities'] |
|
| 477 | - : array(), |
|
| 478 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 479 | - ? (array) $setup_args['capability_maps'] |
|
| 480 | - : array(), |
|
| 481 | - 'model_paths' => isset($setup_args['model_paths']) |
|
| 482 | - ? (array) $setup_args['model_paths'] |
|
| 483 | - : array(), |
|
| 484 | - 'class_paths' => isset($setup_args['class_paths']) |
|
| 485 | - ? (array) $setup_args['class_paths'] |
|
| 486 | - : array(), |
|
| 487 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 488 | - ? (array) $setup_args['model_extension_paths'] |
|
| 489 | - : array(), |
|
| 490 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 491 | - ? (array) $setup_args['class_extension_paths'] |
|
| 492 | - : array(), |
|
| 493 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 494 | - ? (array) $setup_args['custom_post_types'] |
|
| 495 | - : array(), |
|
| 496 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 497 | - ? (array) $setup_args['custom_taxonomies'] |
|
| 498 | - : array(), |
|
| 499 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 500 | - ? (array) $setup_args['payment_method_paths'] |
|
| 501 | - : array(), |
|
| 502 | - 'default_terms' => isset($setup_args['default_terms']) |
|
| 503 | - ? (array) $setup_args['default_terms'] |
|
| 504 | - : array(), |
|
| 505 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 506 | - // that can be used for adding upgrading/marketing info |
|
| 507 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) ? $setup_args['plugins_page_row'] : '', |
|
| 508 | - 'namespace' => isset( |
|
| 509 | - $setup_args['namespace']['FQNS'], |
|
| 510 | - $setup_args['namespace']['DIR'] |
|
| 511 | - ) |
|
| 512 | - ? (array) $setup_args['namespace'] |
|
| 513 | - : array(), |
|
| 514 | - 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
| 515 | - ? (array) $setup_args['privacy_policies'] |
|
| 516 | - : '', |
|
| 517 | - ); |
|
| 518 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 519 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 520 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 521 | - && ! empty($addon_settings['admin_path']) |
|
| 522 | - ? $addon_settings['plugin_slug'] |
|
| 523 | - : $addon_settings['plugin_action_slug']; |
|
| 524 | - // full server path to main file (file loaded directly by WP) |
|
| 525 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 526 | - return $addon_settings; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * @param string $addon_name |
|
| 532 | - * @param array $addon_settings |
|
| 533 | - * @return boolean |
|
| 534 | - */ |
|
| 535 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 536 | - { |
|
| 537 | - global $wp_version; |
|
| 538 | - $incompatibility_message = ''; |
|
| 539 | - // check whether this addon version is compatible with EE core |
|
| 540 | - if ( |
|
| 541 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 542 | - && ! self::_meets_min_core_version_requirement( |
|
| 543 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 544 | - $addon_settings['version'] |
|
| 545 | - ) |
|
| 546 | - ) { |
|
| 547 | - $incompatibility_message = sprintf( |
|
| 548 | - esc_html__( |
|
| 549 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.', |
|
| 550 | - 'event_espresso' |
|
| 551 | - ), |
|
| 552 | - $addon_name, |
|
| 553 | - '<br />', |
|
| 554 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 555 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 556 | - '</span><br />' |
|
| 557 | - ); |
|
| 558 | - } elseif ( |
|
| 559 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 560 | - ) { |
|
| 561 | - $incompatibility_message = sprintf( |
|
| 562 | - esc_html__( |
|
| 563 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 564 | - 'event_espresso' |
|
| 565 | - ), |
|
| 566 | - $addon_name, |
|
| 567 | - self::_effective_version($addon_settings['min_core_version']), |
|
| 568 | - self::_effective_version(espresso_version()), |
|
| 569 | - '<br />', |
|
| 570 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 571 | - '</span><br />' |
|
| 572 | - ); |
|
| 573 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 574 | - $incompatibility_message = sprintf( |
|
| 575 | - esc_html__( |
|
| 576 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 577 | - 'event_espresso' |
|
| 578 | - ), |
|
| 579 | - $addon_name, |
|
| 580 | - $addon_settings['min_wp_version'], |
|
| 581 | - '<br />', |
|
| 582 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 583 | - '</span><br />' |
|
| 584 | - ); |
|
| 585 | - } |
|
| 586 | - if (! empty($incompatibility_message)) { |
|
| 587 | - // remove 'activate' from the REQUEST |
|
| 588 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 589 | - /** @var RequestInterface $request */ |
|
| 590 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 591 | - $request->unSetRequestParam('activate', true); |
|
| 592 | - if (current_user_can('activate_plugins')) { |
|
| 593 | - // show an error message indicating the plugin didn't activate properly |
|
| 594 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 595 | - } |
|
| 596 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 597 | - return false; |
|
| 598 | - } |
|
| 599 | - // addon IS compatible |
|
| 600 | - return true; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * if plugin update engine is being used for auto-updates, |
|
| 606 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
| 607 | - * (not needed if PUE is not being used) |
|
| 608 | - * |
|
| 609 | - * @param string $addon_name |
|
| 610 | - * @param string $class_name |
|
| 611 | - * @param array $setup_args |
|
| 612 | - * @return void |
|
| 613 | - */ |
|
| 614 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 615 | - { |
|
| 616 | - if (! empty($setup_args['pue_options'])) { |
|
| 617 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 618 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 619 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 620 | - : 'espresso_' . strtolower($class_name), |
|
| 621 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 622 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 623 | - : plugin_basename($setup_args['main_file_path']), |
|
| 624 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 625 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 626 | - : '24', |
|
| 627 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 628 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 629 | - : false, |
|
| 630 | - ); |
|
| 631 | - add_action( |
|
| 632 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 633 | - array('EE_Register_Addon', 'load_pue_update') |
|
| 634 | - ); |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 641 | - * |
|
| 642 | - * @param array $addon_settings |
|
| 643 | - * @return void |
|
| 644 | - */ |
|
| 645 | - private static function _setup_namespaces(array $addon_settings) |
|
| 646 | - { |
|
| 647 | - // |
|
| 648 | - if ( |
|
| 649 | - isset( |
|
| 650 | - $addon_settings['namespace']['FQNS'], |
|
| 651 | - $addon_settings['namespace']['DIR'] |
|
| 652 | - ) |
|
| 653 | - ) { |
|
| 654 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 655 | - $addon_settings['namespace']['FQNS'], |
|
| 656 | - $addon_settings['namespace']['DIR'] |
|
| 657 | - ); |
|
| 658 | - } |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - |
|
| 662 | - /** |
|
| 663 | - * @param string $addon_name |
|
| 664 | - * @param array $addon_settings |
|
| 665 | - * @return bool |
|
| 666 | - * @throws InvalidArgumentException |
|
| 667 | - * @throws InvalidDataTypeException |
|
| 668 | - * @throws InvalidInterfaceException |
|
| 669 | - */ |
|
| 670 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
| 671 | - { |
|
| 672 | - // this is an activation request |
|
| 673 | - if (did_action('activate_plugin')) { |
|
| 674 | - // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 675 | - // (as the newly-activated addon wasn't around the first time addons were registered). |
|
| 676 | - // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 677 | - // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 678 | - if ( |
|
| 679 | - ! isset(self::$_settings[ $addon_name ]) |
|
| 680 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 681 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 682 | - ) |
|
| 683 | - ) { |
|
| 684 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 685 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
| 686 | - $addon->set_activation_indicator_option(); |
|
| 687 | - // dont bother setting up the rest of the addon. |
|
| 688 | - // we know it was just activated and the request will end soon |
|
| 689 | - } |
|
| 690 | - return true; |
|
| 691 | - } |
|
| 692 | - // make sure this was called in the right place! |
|
| 693 | - if ( |
|
| 694 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 695 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 696 | - ) { |
|
| 697 | - EE_Error::doing_it_wrong( |
|
| 698 | - __METHOD__, |
|
| 699 | - sprintf( |
|
| 700 | - esc_html__( |
|
| 701 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 702 | - 'event_espresso' |
|
| 703 | - ), |
|
| 704 | - $addon_name |
|
| 705 | - ), |
|
| 706 | - '4.3.0' |
|
| 707 | - ); |
|
| 708 | - } |
|
| 709 | - // make sure addon settings are set correctly without overwriting anything existing |
|
| 710 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 711 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 712 | - } else { |
|
| 713 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 714 | - } |
|
| 715 | - return false; |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * @param string $addon_name |
|
| 721 | - * @return void |
|
| 722 | - * @throws EE_Error |
|
| 723 | - */ |
|
| 724 | - private static function _setup_autoloaders($addon_name) |
|
| 725 | - { |
|
| 726 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 727 | - // setup autoloader for single file |
|
| 728 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 729 | - } |
|
| 730 | - // setup autoloaders for folders |
|
| 731 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 732 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 733 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * register new models and extensions |
|
| 741 | - * |
|
| 742 | - * @param string $addon_name |
|
| 743 | - * @return void |
|
| 744 | - * @throws EE_Error |
|
| 745 | - */ |
|
| 746 | - private static function _register_models_and_extensions($addon_name) |
|
| 747 | - { |
|
| 748 | - // register new models |
|
| 749 | - if ( |
|
| 750 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 751 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 752 | - ) { |
|
| 753 | - EE_Register_Model::register( |
|
| 754 | - $addon_name, |
|
| 755 | - array( |
|
| 756 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 757 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 758 | - ) |
|
| 759 | - ); |
|
| 760 | - } |
|
| 761 | - // register model extensions |
|
| 762 | - if ( |
|
| 763 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 764 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 765 | - ) { |
|
| 766 | - EE_Register_Model_Extensions::register( |
|
| 767 | - $addon_name, |
|
| 768 | - array( |
|
| 769 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 770 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 771 | - ) |
|
| 772 | - ); |
|
| 773 | - } |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - |
|
| 777 | - /** |
|
| 778 | - * @param string $addon_name |
|
| 779 | - * @return void |
|
| 780 | - * @throws EE_Error |
|
| 781 | - */ |
|
| 782 | - private static function _register_data_migration_scripts($addon_name) |
|
| 783 | - { |
|
| 784 | - // setup DMS |
|
| 785 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 786 | - EE_Register_Data_Migration_Scripts::register( |
|
| 787 | - $addon_name, |
|
| 788 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 789 | - ); |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - /** |
|
| 795 | - * @param string $addon_name |
|
| 796 | - * @return void |
|
| 797 | - * @throws EE_Error |
|
| 798 | - */ |
|
| 799 | - private static function _register_config($addon_name) |
|
| 800 | - { |
|
| 801 | - // if config_class is present let's register config. |
|
| 802 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 803 | - EE_Register_Config::register( |
|
| 804 | - self::$_settings[ $addon_name ]['config_class'], |
|
| 805 | - array( |
|
| 806 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 807 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 808 | - ) |
|
| 809 | - ); |
|
| 810 | - } |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * @param string $addon_name |
|
| 816 | - * @return void |
|
| 817 | - * @throws EE_Error |
|
| 818 | - */ |
|
| 819 | - private static function _register_admin_pages($addon_name) |
|
| 820 | - { |
|
| 821 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 822 | - EE_Register_Admin_Page::register( |
|
| 823 | - $addon_name, |
|
| 824 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 825 | - ); |
|
| 826 | - } |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - |
|
| 830 | - /** |
|
| 831 | - * @param string $addon_name |
|
| 832 | - * @return void |
|
| 833 | - * @throws EE_Error |
|
| 834 | - */ |
|
| 835 | - private static function _register_modules($addon_name) |
|
| 836 | - { |
|
| 837 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 838 | - EE_Register_Module::register( |
|
| 839 | - $addon_name, |
|
| 840 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 841 | - ); |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * @param string $addon_name |
|
| 848 | - * @return void |
|
| 849 | - * @throws EE_Error |
|
| 850 | - */ |
|
| 851 | - private static function _register_shortcodes($addon_name) |
|
| 852 | - { |
|
| 853 | - if ( |
|
| 854 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 855 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 856 | - ) { |
|
| 857 | - EE_Register_Shortcode::register( |
|
| 858 | - $addon_name, |
|
| 859 | - array( |
|
| 860 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 861 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] : array(), |
|
| 862 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 863 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(), |
|
| 864 | - ) |
|
| 865 | - ); |
|
| 866 | - } |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * @param string $addon_name |
|
| 872 | - * @return void |
|
| 873 | - * @throws EE_Error |
|
| 874 | - */ |
|
| 875 | - private static function _register_widgets($addon_name) |
|
| 876 | - { |
|
| 877 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 878 | - EE_Register_Widget::register( |
|
| 879 | - $addon_name, |
|
| 880 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 881 | - ); |
|
| 882 | - } |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - |
|
| 886 | - /** |
|
| 887 | - * @param string $addon_name |
|
| 888 | - * @return void |
|
| 889 | - * @throws EE_Error |
|
| 890 | - */ |
|
| 891 | - private static function _register_capabilities($addon_name) |
|
| 892 | - { |
|
| 893 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 894 | - EE_Register_Capabilities::register( |
|
| 895 | - $addon_name, |
|
| 896 | - array( |
|
| 897 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 898 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 899 | - ) |
|
| 900 | - ); |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - |
|
| 905 | - /** |
|
| 906 | - * @param string $addon_name |
|
| 907 | - * @return void |
|
| 908 | - */ |
|
| 909 | - private static function _register_message_types($addon_name) |
|
| 910 | - { |
|
| 911 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 912 | - add_action( |
|
| 913 | - 'EE_Brewing_Regular___messages_caf', |
|
| 914 | - array('EE_Register_Addon', 'register_message_types') |
|
| 915 | - ); |
|
| 916 | - } |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * @param string $addon_name |
|
| 922 | - * @return void |
|
| 923 | - * @throws EE_Error |
|
| 924 | - */ |
|
| 925 | - private static function _register_custom_post_types($addon_name) |
|
| 926 | - { |
|
| 927 | - if ( |
|
| 928 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 929 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 930 | - ) { |
|
| 931 | - EE_Register_CPT::register( |
|
| 932 | - $addon_name, |
|
| 933 | - array( |
|
| 934 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 935 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 936 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 937 | - ) |
|
| 938 | - ); |
|
| 939 | - } |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - |
|
| 943 | - /** |
|
| 944 | - * @param string $addon_name |
|
| 945 | - * @return void |
|
| 946 | - * @throws InvalidArgumentException |
|
| 947 | - * @throws InvalidInterfaceException |
|
| 948 | - * @throws InvalidDataTypeException |
|
| 949 | - * @throws DomainException |
|
| 950 | - * @throws EE_Error |
|
| 951 | - */ |
|
| 952 | - private static function _register_payment_methods($addon_name) |
|
| 953 | - { |
|
| 954 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 955 | - EE_Register_Payment_Method::register( |
|
| 956 | - $addon_name, |
|
| 957 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 958 | - ); |
|
| 959 | - } |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - |
|
| 963 | - /** |
|
| 964 | - * @param string $addon_name |
|
| 965 | - * @return void |
|
| 966 | - * @throws InvalidArgumentException |
|
| 967 | - * @throws InvalidInterfaceException |
|
| 968 | - * @throws InvalidDataTypeException |
|
| 969 | - * @throws DomainException |
|
| 970 | - */ |
|
| 971 | - private static function registerPrivacyPolicies($addon_name) |
|
| 972 | - { |
|
| 973 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
| 974 | - EE_Register_Privacy_Policy::register( |
|
| 975 | - $addon_name, |
|
| 976 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
| 977 | - ); |
|
| 978 | - } |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * @param string $addon_name |
|
| 984 | - * @return void |
|
| 985 | - */ |
|
| 986 | - private static function registerPersonalDataExporters($addon_name) |
|
| 987 | - { |
|
| 988 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
| 989 | - EE_Register_Personal_Data_Eraser::register( |
|
| 990 | - $addon_name, |
|
| 991 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
| 992 | - ); |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - |
|
| 996 | - |
|
| 997 | - /** |
|
| 998 | - * @param string $addon_name |
|
| 999 | - * @return void |
|
| 1000 | - */ |
|
| 1001 | - private static function registerPersonalDataErasers($addon_name) |
|
| 1002 | - { |
|
| 1003 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
| 1004 | - EE_Register_Personal_Data_Eraser::register( |
|
| 1005 | - $addon_name, |
|
| 1006 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
| 1007 | - ); |
|
| 1008 | - } |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - |
|
| 1012 | - /** |
|
| 1013 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 1014 | - * |
|
| 1015 | - * @param string $addon_name |
|
| 1016 | - * @return EE_Addon |
|
| 1017 | - * @throws InvalidArgumentException |
|
| 1018 | - * @throws InvalidInterfaceException |
|
| 1019 | - * @throws InvalidDataTypeException |
|
| 1020 | - */ |
|
| 1021 | - private static function _load_and_init_addon_class($addon_name) |
|
| 1022 | - { |
|
| 1023 | - $addon = LoaderFactory::getLoader()->getShared( |
|
| 1024 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 1025 | - array('EE_Registry::create(addon)' => true) |
|
| 1026 | - ); |
|
| 1027 | - if (! $addon instanceof EE_Addon) { |
|
| 1028 | - throw new DomainException( |
|
| 1029 | - sprintf( |
|
| 1030 | - esc_html__( |
|
| 1031 | - 'Failed to instantiate the %1$s class. PLease check that the class exists.', |
|
| 1032 | - 'event_espresso' |
|
| 1033 | - ), |
|
| 1034 | - $addon_name |
|
| 1035 | - ) |
|
| 1036 | - ); |
|
| 1037 | - } |
|
| 1038 | - // setter inject dep map if required |
|
| 1039 | - if ($addon->dependencyMap() === null) { |
|
| 1040 | - $addon->setDependencyMap(LoaderFactory::getLoader()->getShared('EE_Dependency_Map')); |
|
| 1041 | - } |
|
| 1042 | - // setter inject domain if required |
|
| 1043 | - EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
|
| 1044 | - |
|
| 1045 | - $addon->set_name($addon_name); |
|
| 1046 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 1047 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 1048 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 1049 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 1050 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 1051 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 1052 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 1053 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 1054 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 1055 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 1056 | - // setup the add-on's pue_slug if we have one. |
|
| 1057 | - if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
| 1058 | - $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
| 1059 | - } |
|
| 1060 | - // unfortunately this can't be hooked in upon construction, |
|
| 1061 | - // because we don't have the plugin's mainfile path upon construction. |
|
| 1062 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 1063 | - // call any additional admin_callback functions during load_admin_controller hook |
|
| 1064 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 1065 | - add_action( |
|
| 1066 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 1067 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 1068 | - ); |
|
| 1069 | - } |
|
| 1070 | - return $addon; |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - |
|
| 1074 | - /** |
|
| 1075 | - * @param string $addon_name |
|
| 1076 | - * @param EE_Addon $addon |
|
| 1077 | - * @since 4.10.13.p |
|
| 1078 | - */ |
|
| 1079 | - private static function injectAddonDomain($addon_name, EE_Addon $addon) |
|
| 1080 | - { |
|
| 1081 | - if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
|
| 1082 | - // using supplied Domain object |
|
| 1083 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
| 1084 | - ? self::$_settings[ $addon_name ]['domain'] |
|
| 1085 | - : null; |
|
| 1086 | - // or construct one using Domain FQCN |
|
| 1087 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
| 1088 | - $domain = LoaderFactory::getLoader()->getShared( |
|
| 1089 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 1090 | - [ |
|
| 1091 | - new EventEspresso\core\domain\values\FilePath( |
|
| 1092 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
| 1093 | - ), |
|
| 1094 | - EventEspresso\core\domain\values\Version::fromString( |
|
| 1095 | - self::$_settings[ $addon_name ]['version'] |
|
| 1096 | - ), |
|
| 1097 | - ] |
|
| 1098 | - ); |
|
| 1099 | - } |
|
| 1100 | - if ($domain instanceof DomainInterface) { |
|
| 1101 | - $addon->setDomain($domain); |
|
| 1102 | - } |
|
| 1103 | - } |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - |
|
| 1107 | - /** |
|
| 1108 | - * load_pue_update - Update notifications |
|
| 1109 | - * |
|
| 1110 | - * @return void |
|
| 1111 | - * @throws InvalidArgumentException |
|
| 1112 | - * @throws InvalidDataTypeException |
|
| 1113 | - * @throws InvalidInterfaceException |
|
| 1114 | - */ |
|
| 1115 | - public static function load_pue_update() |
|
| 1116 | - { |
|
| 1117 | - // load PUE client |
|
| 1118 | - require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
| 1119 | - $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
| 1120 | - // cycle thru settings |
|
| 1121 | - foreach (self::$_settings as $settings) { |
|
| 1122 | - if (! empty($settings['pue_options'])) { |
|
| 1123 | - // initiate the class and start the plugin update engine! |
|
| 1124 | - new PluginUpdateEngineChecker( |
|
| 1125 | - // host file URL |
|
| 1126 | - $license_server, |
|
| 1127 | - // plugin slug(s) |
|
| 1128 | - array( |
|
| 1129 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 1130 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1131 | - ), |
|
| 1132 | - // options |
|
| 1133 | - array( |
|
| 1134 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1135 | - 'lang_domain' => 'event_espresso', |
|
| 1136 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1137 | - 'option_key' => 'ee_site_license_key', |
|
| 1138 | - 'options_page_slug' => 'event_espresso', |
|
| 1139 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1140 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1141 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1142 | - ) |
|
| 1143 | - ); |
|
| 1144 | - } |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - /** |
|
| 1150 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1151 | - * |
|
| 1152 | - * @since 4.4.0 |
|
| 1153 | - * @return void |
|
| 1154 | - * @throws EE_Error |
|
| 1155 | - */ |
|
| 1156 | - public static function register_message_types() |
|
| 1157 | - { |
|
| 1158 | - foreach (self::$_settings as $settings) { |
|
| 1159 | - if (! empty($settings['message_types'])) { |
|
| 1160 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1161 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1162 | - } |
|
| 1163 | - } |
|
| 1164 | - } |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - |
|
| 1168 | - /** |
|
| 1169 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1170 | - * |
|
| 1171 | - * @param string $addon_name the name for the addon that was previously registered |
|
| 1172 | - * @throws DomainException |
|
| 1173 | - * @throws InvalidArgumentException |
|
| 1174 | - * @throws InvalidDataTypeException |
|
| 1175 | - * @throws InvalidInterfaceException |
|
| 1176 | - *@since 4.3.0 |
|
| 1177 | - */ |
|
| 1178 | - public static function deregister($addon_name = '') |
|
| 1179 | - { |
|
| 1180 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1181 | - try { |
|
| 1182 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1183 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1184 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1185 | - // setup DMS |
|
| 1186 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1187 | - } |
|
| 1188 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1189 | - // register admin page |
|
| 1190 | - EE_Register_Admin_Page::deregister($addon_name); |
|
| 1191 | - } |
|
| 1192 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1193 | - // add to list of modules to be registered |
|
| 1194 | - EE_Register_Module::deregister($addon_name); |
|
| 1195 | - } |
|
| 1196 | - if ( |
|
| 1197 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1198 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1199 | - ) { |
|
| 1200 | - // add to list of shortcodes to be registered |
|
| 1201 | - EE_Register_Shortcode::deregister($addon_name); |
|
| 1202 | - } |
|
| 1203 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1204 | - // if config_class present let's register config. |
|
| 1205 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1206 | - } |
|
| 1207 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1208 | - // add to list of widgets to be registered |
|
| 1209 | - EE_Register_Widget::deregister($addon_name); |
|
| 1210 | - } |
|
| 1211 | - if ( |
|
| 1212 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1213 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1214 | - ) { |
|
| 1215 | - // add to list of shortcodes to be registered |
|
| 1216 | - EE_Register_Model::deregister($addon_name); |
|
| 1217 | - } |
|
| 1218 | - if ( |
|
| 1219 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1220 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1221 | - ) { |
|
| 1222 | - // add to list of shortcodes to be registered |
|
| 1223 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1224 | - } |
|
| 1225 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1226 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
| 1227 | - EE_Register_Message_Type::deregister($message_type); |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - // deregister capabilities for addon |
|
| 1231 | - if ( |
|
| 1232 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1233 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1234 | - ) { |
|
| 1235 | - EE_Register_Capabilities::deregister($addon_name); |
|
| 1236 | - } |
|
| 1237 | - // deregister custom_post_types for addon |
|
| 1238 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1239 | - EE_Register_CPT::deregister($addon_name); |
|
| 1240 | - } |
|
| 1241 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1242 | - EE_Register_Payment_Method::deregister($addon_name); |
|
| 1243 | - } |
|
| 1244 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1245 | - if ($addon instanceof EE_Addon) { |
|
| 1246 | - remove_action( |
|
| 1247 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1248 | - array($addon, 'deactivation') |
|
| 1249 | - ); |
|
| 1250 | - remove_action( |
|
| 1251 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1252 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1253 | - ); |
|
| 1254 | - // remove `after_registration` call |
|
| 1255 | - remove_action( |
|
| 1256 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1257 | - array($addon, 'after_registration'), |
|
| 1258 | - 999 |
|
| 1259 | - ); |
|
| 1260 | - } |
|
| 1261 | - EE_Registry::instance()->removeAddon($class_name); |
|
| 1262 | - LoaderFactory::getLoader()->remove($class_name); |
|
| 1263 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
| 1264 | - // the add-on was not yet registered in the registry, |
|
| 1265 | - // so RegistryContainer::__get() throws this exception. |
|
| 1266 | - // also no need to worry about this or log it, |
|
| 1267 | - // it's ok to deregister an add-on before its registered in the registry |
|
| 1268 | - } catch (Exception $e) { |
|
| 1269 | - new ExceptionLogger($e); |
|
| 1270 | - } |
|
| 1271 | - unset(self::$_settings[ $addon_name ]); |
|
| 1272 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1273 | - } |
|
| 1274 | - } |
|
| 25 | + /** |
|
| 26 | + * possibly truncated version of the EE core version string |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected static $_core_version = ''; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Holds values for registered addons |
|
| 34 | + * |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + protected static $_settings = array(); |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
| 41 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 42 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 43 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
| 44 | + * EE core with knowledge of ALL the addons out there. |
|
| 45 | + * If you want NO versions of an addon to run with a certain version of core, |
|
| 46 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 47 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 48 | + * minimum plugin version. |
|
| 49 | + * @access protected |
|
| 50 | + */ |
|
| 51 | + protected static $_incompatible_addons = array( |
|
| 52 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 53 | + 'Promotions' => '1.0.0.rc.084', |
|
| 54 | + ); |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 59 | + * not just '4.3.0'. |
|
| 60 | + * So if the addon developer doesn't provide that full version string, |
|
| 61 | + * fill in the blanks for them |
|
| 62 | + * |
|
| 63 | + * @param string $min_core_version |
|
| 64 | + * @return string always like '4.3.0.rc.000' |
|
| 65 | + */ |
|
| 66 | + protected static function _effective_version($min_core_version) |
|
| 67 | + { |
|
| 68 | + // versions: 4 . 3 . 1 . p . 123 |
|
| 69 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 70 | + $version_parts = explode('.', $min_core_version); |
|
| 71 | + // check they specified the micro version (after 2nd period) |
|
| 72 | + if (! isset($version_parts[2])) { |
|
| 73 | + $version_parts[2] = '0'; |
|
| 74 | + } |
|
| 75 | + // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 76 | + // soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 77 | + if (! isset($version_parts[3])) { |
|
| 78 | + $version_parts[3] = 'dev'; |
|
| 79 | + } |
|
| 80 | + if (! isset($version_parts[4])) { |
|
| 81 | + $version_parts[4] = '000'; |
|
| 82 | + } |
|
| 83 | + return implode('.', $version_parts); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Returns whether or not the min core version requirement of the addon is met |
|
| 89 | + * |
|
| 90 | + * @param string $min_core_version the minimum core version required by the addon |
|
| 91 | + * @param string $actual_core_version the actual core version, optional |
|
| 92 | + * @return boolean |
|
| 93 | + */ |
|
| 94 | + public static function _meets_min_core_version_requirement( |
|
| 95 | + $min_core_version, |
|
| 96 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 97 | + ) { |
|
| 98 | + return version_compare( |
|
| 99 | + self::_effective_version($actual_core_version), |
|
| 100 | + self::_effective_version($min_core_version), |
|
| 101 | + '>=' |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Method for registering new EE_Addons. |
|
| 108 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 109 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 110 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 111 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 112 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 113 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 114 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 115 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
| 116 | + * |
|
| 117 | + * @since 4.3.0 |
|
| 118 | + * @param string $addon_name [Required] the EE_Addon's name. |
|
| 119 | + * @param array $setup_args { |
|
| 120 | + * An array of arguments provided for registering |
|
| 121 | + * the message type. |
|
| 122 | + * @type string $class_name the addon's main file name. |
|
| 123 | + * If left blank, generated from the addon name, |
|
| 124 | + * changes something like "calendar" to |
|
| 125 | + * "EE_Calendar" |
|
| 126 | + * @type string $min_core_version the minimum version of EE Core that the |
|
| 127 | + * addon will work with. eg "4.8.1.rc.084" |
|
| 128 | + * @type string $version the "software" version for the addon. eg |
|
| 129 | + * "1.0.0.p" for a first stable release, or |
|
| 130 | + * "1.0.0.rc.043" for a version in progress |
|
| 131 | + * @type string $main_file_path the full server path to the main file |
|
| 132 | + * loaded directly by WP |
|
| 133 | + * @type DomainInterface $domain child class of |
|
| 134 | + * EventEspresso\core\domain\DomainBase |
|
| 135 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
| 136 | + * for the addon's Domain class |
|
| 137 | + * (see EventEspresso\core\domain\Domain) |
|
| 138 | + * @type string $admin_path full server path to the folder where the |
|
| 139 | + * addon\'s admin files reside |
|
| 140 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
| 141 | + * first invoked, can be used for hooking into |
|
| 142 | + * any admin page |
|
| 143 | + * @type string $config_section the section name for this addon's |
|
| 144 | + * configuration settings section |
|
| 145 | + * (defaults to "addons") |
|
| 146 | + * @type string $config_class the class name for this addon's |
|
| 147 | + * configuration settings object |
|
| 148 | + * @type string $config_name the class name for this addon's |
|
| 149 | + * configuration settings object |
|
| 150 | + * @type string $autoloader_paths [Required] an array of class names and the full |
|
| 151 | + * server paths to those files. |
|
| 152 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
| 153 | + * folders containing classes that might be |
|
| 154 | + * invoked by the addon |
|
| 155 | + * @type string $dms_paths [Required] an array of full server paths to |
|
| 156 | + * folders that contain data migration scripts. |
|
| 157 | + * The key should be the EE_Addon class name that |
|
| 158 | + * this set of data migration scripts belongs to. |
|
| 159 | + * If the EE_Addon class is namespaced, then this |
|
| 160 | + * needs to be the Fully Qualified Class Name |
|
| 161 | + * @type string $module_paths an array of full server paths to any |
|
| 162 | + * EED_Modules used by the addon |
|
| 163 | + * @type string $shortcode_paths an array of full server paths to folders |
|
| 164 | + * that contain EES_Shortcodes |
|
| 165 | + * @type string $widget_paths an array of full server paths to folders |
|
| 166 | + * that contain WP_Widgets |
|
| 167 | + * @type string $pue_options |
|
| 168 | + * @type array $capabilities an array indexed by role name |
|
| 169 | + * (i.e administrator,author ) and the values |
|
| 170 | + * are an array of caps to add to the role. |
|
| 171 | + * 'administrator' => array( |
|
| 172 | + * 'read_addon', |
|
| 173 | + * 'edit_addon', |
|
| 174 | + * etc. |
|
| 175 | + * ). |
|
| 176 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 177 | + * for any addons that need to register any |
|
| 178 | + * special meta mapped capabilities. Should |
|
| 179 | + * be indexed where the key is the |
|
| 180 | + * EE_Meta_Capability_Map class name and the |
|
| 181 | + * values are the arguments sent to the class. |
|
| 182 | + * @type array $model_paths array of folders containing DB models |
|
| 183 | + * @see EE_Register_Model |
|
| 184 | + * @type array $class_paths array of folders containing DB classes |
|
| 185 | + * @see EE_Register_Model |
|
| 186 | + * @type array $model_extension_paths array of folders containing DB model |
|
| 187 | + * extensions |
|
| 188 | + * @see EE_Register_Model_Extension |
|
| 189 | + * @type array $class_extension_paths array of folders containing DB class |
|
| 190 | + * extensions |
|
| 191 | + * @see EE_Register_Model_Extension |
|
| 192 | + * @type array message_types { |
|
| 193 | + * An array of message types with the key as |
|
| 194 | + * the message type name and the values as |
|
| 195 | + * below: |
|
| 196 | + * @type string $mtfilename [Required] The filename of the message type |
|
| 197 | + * being registered. This will be the main |
|
| 198 | + * EE_{Message Type Name}_message_type class. |
|
| 199 | + * for example: |
|
| 200 | + * EE_Declined_Registration_message_type.class.php |
|
| 201 | + * @type array $autoloadpaths [Required] An array of paths to add to the |
|
| 202 | + * messages autoloader for the new message type. |
|
| 203 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 204 | + * type should activate with. Each value in |
|
| 205 | + * the |
|
| 206 | + * array |
|
| 207 | + * should match the name property of a |
|
| 208 | + * EE_messenger. Optional. |
|
| 209 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 210 | + * type should validate with. Each value in |
|
| 211 | + * the |
|
| 212 | + * array |
|
| 213 | + * should match the name property of an |
|
| 214 | + * EE_messenger. |
|
| 215 | + * Optional. |
|
| 216 | + * } |
|
| 217 | + * @type array $custom_post_types |
|
| 218 | + * @type array $custom_taxonomies |
|
| 219 | + * @type array $payment_method_paths each element is the folder containing the |
|
| 220 | + * EE_PMT_Base child class |
|
| 221 | + * (eg, |
|
| 222 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 223 | + * which contains the files |
|
| 224 | + * EE_PMT_Payomatic.pm.php) |
|
| 225 | + * @type array $default_terms |
|
| 226 | + * @type array $namespace { |
|
| 227 | + * An array with two items for registering the |
|
| 228 | + * addon's namespace. (If, for some reason, you |
|
| 229 | + * require additional namespaces, |
|
| 230 | + * use |
|
| 231 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 232 | + * directly) |
|
| 233 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 234 | + * @type string $FQNS the namespace prefix |
|
| 235 | + * @type string $DIR a base directory for class files in the |
|
| 236 | + * namespace. |
|
| 237 | + * } |
|
| 238 | + * } |
|
| 239 | + * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
| 240 | + * privacy policy classes) or FQCNs (specific |
|
| 241 | + * classnames of privacy policy classes) |
|
| 242 | + * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
| 243 | + * privacy policy classes) or FQCNs (specific |
|
| 244 | + * classnames of privacy policy classes) |
|
| 245 | + * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
| 246 | + * privacy policy classes) or FQCNs (specific |
|
| 247 | + * classnames of privacy policy classes) |
|
| 248 | + * @return void |
|
| 249 | + * @throws DomainException |
|
| 250 | + * @throws EE_Error |
|
| 251 | + * @throws InvalidArgumentException |
|
| 252 | + * @throws InvalidDataTypeException |
|
| 253 | + * @throws InvalidInterfaceException |
|
| 254 | + */ |
|
| 255 | + public static function register($addon_name = '', array $setup_args = array()) |
|
| 256 | + { |
|
| 257 | + // required fields MUST be present, so let's make sure they are. |
|
| 258 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 259 | + // get class name for addon |
|
| 260 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 261 | + // setup $_settings array from incoming values. |
|
| 262 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 263 | + // setup PUE |
|
| 264 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 265 | + // does this addon work with this version of core or WordPress ? |
|
| 266 | + // does this addon work with this version of core or WordPress ? |
|
| 267 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 268 | + return; |
|
| 269 | + } |
|
| 270 | + // register namespaces |
|
| 271 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 272 | + // check if this is an activation request |
|
| 273 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 274 | + // dont bother setting up the rest of the addon atm |
|
| 275 | + return; |
|
| 276 | + } |
|
| 277 | + // we need cars |
|
| 278 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 279 | + // register new models and extensions |
|
| 280 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 281 | + // setup DMS |
|
| 282 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 283 | + // if config_class is present let's register config. |
|
| 284 | + EE_Register_Addon::_register_config($addon_name); |
|
| 285 | + // register admin pages |
|
| 286 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 287 | + // add to list of modules to be registered |
|
| 288 | + EE_Register_Addon::_register_modules($addon_name); |
|
| 289 | + // add to list of shortcodes to be registered |
|
| 290 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 291 | + // add to list of widgets to be registered |
|
| 292 | + EE_Register_Addon::_register_widgets($addon_name); |
|
| 293 | + // register capability related stuff. |
|
| 294 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
| 295 | + // any message type to register? |
|
| 296 | + EE_Register_Addon::_register_message_types($addon_name); |
|
| 297 | + // any custom post type/ custom capabilities or default terms to register |
|
| 298 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 299 | + // and any payment methods |
|
| 300 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 301 | + // and privacy policy generators |
|
| 302 | + EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
| 303 | + // and privacy policy generators |
|
| 304 | + EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
| 305 | + // and privacy policy generators |
|
| 306 | + EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
| 307 | + // load and instantiate main addon class |
|
| 308 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 309 | + // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 310 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * @param string $addon_name |
|
| 316 | + * @param array $setup_args |
|
| 317 | + * @return void |
|
| 318 | + * @throws EE_Error |
|
| 319 | + */ |
|
| 320 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
| 321 | + { |
|
| 322 | + // required fields MUST be present, so let's make sure they are. |
|
| 323 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 324 | + throw new EE_Error( |
|
| 325 | + esc_html__( |
|
| 326 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 327 | + 'event_espresso' |
|
| 328 | + ) |
|
| 329 | + ); |
|
| 330 | + } |
|
| 331 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 332 | + throw new EE_Error( |
|
| 333 | + sprintf( |
|
| 334 | + esc_html__( |
|
| 335 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 336 | + 'event_espresso' |
|
| 337 | + ), |
|
| 338 | + implode(',', array_keys($setup_args)) |
|
| 339 | + ) |
|
| 340 | + ); |
|
| 341 | + } |
|
| 342 | + // check that addon has not already been registered with that name |
|
| 343 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 344 | + throw new EE_Error( |
|
| 345 | + sprintf( |
|
| 346 | + esc_html__( |
|
| 347 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 348 | + 'event_espresso' |
|
| 349 | + ), |
|
| 350 | + $addon_name |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * @param string $addon_name |
|
| 359 | + * @param array $setup_args |
|
| 360 | + * @return string |
|
| 361 | + */ |
|
| 362 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
| 363 | + { |
|
| 364 | + if (empty($setup_args['class_name'])) { |
|
| 365 | + // generate one by first separating name with spaces |
|
| 366 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 367 | + // capitalize, then replace spaces with underscores |
|
| 368 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 369 | + } else { |
|
| 370 | + $class_name = $setup_args['class_name']; |
|
| 371 | + } |
|
| 372 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 373 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 374 | + ? $class_name |
|
| 375 | + : 'EE_' . $class_name; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * @param string $class_name |
|
| 381 | + * @param array $setup_args |
|
| 382 | + * @return array |
|
| 383 | + */ |
|
| 384 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
| 385 | + { |
|
| 386 | + // setup $_settings array from incoming values. |
|
| 387 | + $addon_settings = array( |
|
| 388 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 389 | + 'class_name' => $class_name, |
|
| 390 | + // the addon slug for use in URLs, etc |
|
| 391 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 392 | + ? (string) $setup_args['plugin_slug'] |
|
| 393 | + : '', |
|
| 394 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 395 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 396 | + ? (string) $setup_args['plugin_action_slug'] |
|
| 397 | + : '', |
|
| 398 | + // the "software" version for the addon |
|
| 399 | + 'version' => isset($setup_args['version']) |
|
| 400 | + ? (string) $setup_args['version'] |
|
| 401 | + : '', |
|
| 402 | + // the minimum version of EE Core that the addon will work with |
|
| 403 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 404 | + ? (string) $setup_args['min_core_version'] |
|
| 405 | + : '', |
|
| 406 | + // the minimum version of WordPress that the addon will work with |
|
| 407 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 408 | + ? (string) $setup_args['min_wp_version'] |
|
| 409 | + : EE_MIN_WP_VER_REQUIRED, |
|
| 410 | + // full server path to main file (file loaded directly by WP) |
|
| 411 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 412 | + ? (string) $setup_args['main_file_path'] |
|
| 413 | + : '', |
|
| 414 | + // instance of \EventEspresso\core\domain\DomainInterface |
|
| 415 | + 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
| 416 | + ? $setup_args['domain'] |
|
| 417 | + : null, |
|
| 418 | + // Fully Qualified Class Name for the addon's Domain class |
|
| 419 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 420 | + ? (string) $setup_args['domain_fqcn'] |
|
| 421 | + : '', |
|
| 422 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 423 | + 'admin_path' => isset($setup_args['admin_path']) |
|
| 424 | + ? (string) $setup_args['admin_path'] : '', |
|
| 425 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 426 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 427 | + ? (string) $setup_args['admin_callback'] |
|
| 428 | + : '', |
|
| 429 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 430 | + 'config_section' => isset($setup_args['config_section']) |
|
| 431 | + ? (string) $setup_args['config_section'] |
|
| 432 | + : 'addons', |
|
| 433 | + // the class name for this addon's configuration settings object |
|
| 434 | + 'config_class' => isset($setup_args['config_class']) |
|
| 435 | + ? (string) $setup_args['config_class'] : '', |
|
| 436 | + // the name given to the config for this addons' configuration settings object (optional) |
|
| 437 | + 'config_name' => isset($setup_args['config_name']) |
|
| 438 | + ? (string) $setup_args['config_name'] : '', |
|
| 439 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 440 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 441 | + ? (array) $setup_args['autoloader_paths'] |
|
| 442 | + : array(), |
|
| 443 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 444 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 445 | + ? (array) $setup_args['autoloader_folders'] |
|
| 446 | + : array(), |
|
| 447 | + // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
| 448 | + // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
| 449 | + // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 450 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 451 | + ? (array) $setup_args['dms_paths'] |
|
| 452 | + : array(), |
|
| 453 | + // array of full server paths to any EED_Modules used by the addon |
|
| 454 | + 'module_paths' => isset($setup_args['module_paths']) |
|
| 455 | + ? (array) $setup_args['module_paths'] |
|
| 456 | + : array(), |
|
| 457 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
| 458 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 459 | + ? (array) $setup_args['shortcode_paths'] |
|
| 460 | + : array(), |
|
| 461 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 462 | + ? (array) $setup_args['shortcode_fqcns'] |
|
| 463 | + : array(), |
|
| 464 | + // array of full server paths to any WP_Widgets used by the addon |
|
| 465 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 466 | + ? (array) $setup_args['widget_paths'] |
|
| 467 | + : array(), |
|
| 468 | + // array of PUE options used by the addon |
|
| 469 | + 'pue_options' => isset($setup_args['pue_options']) |
|
| 470 | + ? (array) $setup_args['pue_options'] |
|
| 471 | + : array(), |
|
| 472 | + 'message_types' => isset($setup_args['message_types']) |
|
| 473 | + ? (array) $setup_args['message_types'] |
|
| 474 | + : array(), |
|
| 475 | + 'capabilities' => isset($setup_args['capabilities']) |
|
| 476 | + ? (array) $setup_args['capabilities'] |
|
| 477 | + : array(), |
|
| 478 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 479 | + ? (array) $setup_args['capability_maps'] |
|
| 480 | + : array(), |
|
| 481 | + 'model_paths' => isset($setup_args['model_paths']) |
|
| 482 | + ? (array) $setup_args['model_paths'] |
|
| 483 | + : array(), |
|
| 484 | + 'class_paths' => isset($setup_args['class_paths']) |
|
| 485 | + ? (array) $setup_args['class_paths'] |
|
| 486 | + : array(), |
|
| 487 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 488 | + ? (array) $setup_args['model_extension_paths'] |
|
| 489 | + : array(), |
|
| 490 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 491 | + ? (array) $setup_args['class_extension_paths'] |
|
| 492 | + : array(), |
|
| 493 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 494 | + ? (array) $setup_args['custom_post_types'] |
|
| 495 | + : array(), |
|
| 496 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 497 | + ? (array) $setup_args['custom_taxonomies'] |
|
| 498 | + : array(), |
|
| 499 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 500 | + ? (array) $setup_args['payment_method_paths'] |
|
| 501 | + : array(), |
|
| 502 | + 'default_terms' => isset($setup_args['default_terms']) |
|
| 503 | + ? (array) $setup_args['default_terms'] |
|
| 504 | + : array(), |
|
| 505 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 506 | + // that can be used for adding upgrading/marketing info |
|
| 507 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) ? $setup_args['plugins_page_row'] : '', |
|
| 508 | + 'namespace' => isset( |
|
| 509 | + $setup_args['namespace']['FQNS'], |
|
| 510 | + $setup_args['namespace']['DIR'] |
|
| 511 | + ) |
|
| 512 | + ? (array) $setup_args['namespace'] |
|
| 513 | + : array(), |
|
| 514 | + 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
| 515 | + ? (array) $setup_args['privacy_policies'] |
|
| 516 | + : '', |
|
| 517 | + ); |
|
| 518 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 519 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 520 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 521 | + && ! empty($addon_settings['admin_path']) |
|
| 522 | + ? $addon_settings['plugin_slug'] |
|
| 523 | + : $addon_settings['plugin_action_slug']; |
|
| 524 | + // full server path to main file (file loaded directly by WP) |
|
| 525 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 526 | + return $addon_settings; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * @param string $addon_name |
|
| 532 | + * @param array $addon_settings |
|
| 533 | + * @return boolean |
|
| 534 | + */ |
|
| 535 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 536 | + { |
|
| 537 | + global $wp_version; |
|
| 538 | + $incompatibility_message = ''; |
|
| 539 | + // check whether this addon version is compatible with EE core |
|
| 540 | + if ( |
|
| 541 | + isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 542 | + && ! self::_meets_min_core_version_requirement( |
|
| 543 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 544 | + $addon_settings['version'] |
|
| 545 | + ) |
|
| 546 | + ) { |
|
| 547 | + $incompatibility_message = sprintf( |
|
| 548 | + esc_html__( |
|
| 549 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.', |
|
| 550 | + 'event_espresso' |
|
| 551 | + ), |
|
| 552 | + $addon_name, |
|
| 553 | + '<br />', |
|
| 554 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 555 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 556 | + '</span><br />' |
|
| 557 | + ); |
|
| 558 | + } elseif ( |
|
| 559 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 560 | + ) { |
|
| 561 | + $incompatibility_message = sprintf( |
|
| 562 | + esc_html__( |
|
| 563 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 564 | + 'event_espresso' |
|
| 565 | + ), |
|
| 566 | + $addon_name, |
|
| 567 | + self::_effective_version($addon_settings['min_core_version']), |
|
| 568 | + self::_effective_version(espresso_version()), |
|
| 569 | + '<br />', |
|
| 570 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 571 | + '</span><br />' |
|
| 572 | + ); |
|
| 573 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 574 | + $incompatibility_message = sprintf( |
|
| 575 | + esc_html__( |
|
| 576 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 577 | + 'event_espresso' |
|
| 578 | + ), |
|
| 579 | + $addon_name, |
|
| 580 | + $addon_settings['min_wp_version'], |
|
| 581 | + '<br />', |
|
| 582 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 583 | + '</span><br />' |
|
| 584 | + ); |
|
| 585 | + } |
|
| 586 | + if (! empty($incompatibility_message)) { |
|
| 587 | + // remove 'activate' from the REQUEST |
|
| 588 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 589 | + /** @var RequestInterface $request */ |
|
| 590 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 591 | + $request->unSetRequestParam('activate', true); |
|
| 592 | + if (current_user_can('activate_plugins')) { |
|
| 593 | + // show an error message indicating the plugin didn't activate properly |
|
| 594 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 595 | + } |
|
| 596 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 597 | + return false; |
|
| 598 | + } |
|
| 599 | + // addon IS compatible |
|
| 600 | + return true; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * if plugin update engine is being used for auto-updates, |
|
| 606 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
| 607 | + * (not needed if PUE is not being used) |
|
| 608 | + * |
|
| 609 | + * @param string $addon_name |
|
| 610 | + * @param string $class_name |
|
| 611 | + * @param array $setup_args |
|
| 612 | + * @return void |
|
| 613 | + */ |
|
| 614 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 615 | + { |
|
| 616 | + if (! empty($setup_args['pue_options'])) { |
|
| 617 | + self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 618 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 619 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 620 | + : 'espresso_' . strtolower($class_name), |
|
| 621 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 622 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 623 | + : plugin_basename($setup_args['main_file_path']), |
|
| 624 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 625 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 626 | + : '24', |
|
| 627 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 628 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 629 | + : false, |
|
| 630 | + ); |
|
| 631 | + add_action( |
|
| 632 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 633 | + array('EE_Register_Addon', 'load_pue_update') |
|
| 634 | + ); |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 641 | + * |
|
| 642 | + * @param array $addon_settings |
|
| 643 | + * @return void |
|
| 644 | + */ |
|
| 645 | + private static function _setup_namespaces(array $addon_settings) |
|
| 646 | + { |
|
| 647 | + // |
|
| 648 | + if ( |
|
| 649 | + isset( |
|
| 650 | + $addon_settings['namespace']['FQNS'], |
|
| 651 | + $addon_settings['namespace']['DIR'] |
|
| 652 | + ) |
|
| 653 | + ) { |
|
| 654 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 655 | + $addon_settings['namespace']['FQNS'], |
|
| 656 | + $addon_settings['namespace']['DIR'] |
|
| 657 | + ); |
|
| 658 | + } |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + |
|
| 662 | + /** |
|
| 663 | + * @param string $addon_name |
|
| 664 | + * @param array $addon_settings |
|
| 665 | + * @return bool |
|
| 666 | + * @throws InvalidArgumentException |
|
| 667 | + * @throws InvalidDataTypeException |
|
| 668 | + * @throws InvalidInterfaceException |
|
| 669 | + */ |
|
| 670 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
| 671 | + { |
|
| 672 | + // this is an activation request |
|
| 673 | + if (did_action('activate_plugin')) { |
|
| 674 | + // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 675 | + // (as the newly-activated addon wasn't around the first time addons were registered). |
|
| 676 | + // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 677 | + // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 678 | + if ( |
|
| 679 | + ! isset(self::$_settings[ $addon_name ]) |
|
| 680 | + || (isset(self::$_settings[ $addon_name ]) |
|
| 681 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 682 | + ) |
|
| 683 | + ) { |
|
| 684 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 685 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
| 686 | + $addon->set_activation_indicator_option(); |
|
| 687 | + // dont bother setting up the rest of the addon. |
|
| 688 | + // we know it was just activated and the request will end soon |
|
| 689 | + } |
|
| 690 | + return true; |
|
| 691 | + } |
|
| 692 | + // make sure this was called in the right place! |
|
| 693 | + if ( |
|
| 694 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 695 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 696 | + ) { |
|
| 697 | + EE_Error::doing_it_wrong( |
|
| 698 | + __METHOD__, |
|
| 699 | + sprintf( |
|
| 700 | + esc_html__( |
|
| 701 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 702 | + 'event_espresso' |
|
| 703 | + ), |
|
| 704 | + $addon_name |
|
| 705 | + ), |
|
| 706 | + '4.3.0' |
|
| 707 | + ); |
|
| 708 | + } |
|
| 709 | + // make sure addon settings are set correctly without overwriting anything existing |
|
| 710 | + if (isset(self::$_settings[ $addon_name ])) { |
|
| 711 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
| 712 | + } else { |
|
| 713 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 714 | + } |
|
| 715 | + return false; |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * @param string $addon_name |
|
| 721 | + * @return void |
|
| 722 | + * @throws EE_Error |
|
| 723 | + */ |
|
| 724 | + private static function _setup_autoloaders($addon_name) |
|
| 725 | + { |
|
| 726 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 727 | + // setup autoloader for single file |
|
| 728 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 729 | + } |
|
| 730 | + // setup autoloaders for folders |
|
| 731 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 732 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 733 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * register new models and extensions |
|
| 741 | + * |
|
| 742 | + * @param string $addon_name |
|
| 743 | + * @return void |
|
| 744 | + * @throws EE_Error |
|
| 745 | + */ |
|
| 746 | + private static function _register_models_and_extensions($addon_name) |
|
| 747 | + { |
|
| 748 | + // register new models |
|
| 749 | + if ( |
|
| 750 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 751 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 752 | + ) { |
|
| 753 | + EE_Register_Model::register( |
|
| 754 | + $addon_name, |
|
| 755 | + array( |
|
| 756 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 757 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 758 | + ) |
|
| 759 | + ); |
|
| 760 | + } |
|
| 761 | + // register model extensions |
|
| 762 | + if ( |
|
| 763 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 764 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 765 | + ) { |
|
| 766 | + EE_Register_Model_Extensions::register( |
|
| 767 | + $addon_name, |
|
| 768 | + array( |
|
| 769 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 770 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 771 | + ) |
|
| 772 | + ); |
|
| 773 | + } |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + |
|
| 777 | + /** |
|
| 778 | + * @param string $addon_name |
|
| 779 | + * @return void |
|
| 780 | + * @throws EE_Error |
|
| 781 | + */ |
|
| 782 | + private static function _register_data_migration_scripts($addon_name) |
|
| 783 | + { |
|
| 784 | + // setup DMS |
|
| 785 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 786 | + EE_Register_Data_Migration_Scripts::register( |
|
| 787 | + $addon_name, |
|
| 788 | + array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 789 | + ); |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + /** |
|
| 795 | + * @param string $addon_name |
|
| 796 | + * @return void |
|
| 797 | + * @throws EE_Error |
|
| 798 | + */ |
|
| 799 | + private static function _register_config($addon_name) |
|
| 800 | + { |
|
| 801 | + // if config_class is present let's register config. |
|
| 802 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 803 | + EE_Register_Config::register( |
|
| 804 | + self::$_settings[ $addon_name ]['config_class'], |
|
| 805 | + array( |
|
| 806 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 807 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 808 | + ) |
|
| 809 | + ); |
|
| 810 | + } |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * @param string $addon_name |
|
| 816 | + * @return void |
|
| 817 | + * @throws EE_Error |
|
| 818 | + */ |
|
| 819 | + private static function _register_admin_pages($addon_name) |
|
| 820 | + { |
|
| 821 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 822 | + EE_Register_Admin_Page::register( |
|
| 823 | + $addon_name, |
|
| 824 | + array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 825 | + ); |
|
| 826 | + } |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + |
|
| 830 | + /** |
|
| 831 | + * @param string $addon_name |
|
| 832 | + * @return void |
|
| 833 | + * @throws EE_Error |
|
| 834 | + */ |
|
| 835 | + private static function _register_modules($addon_name) |
|
| 836 | + { |
|
| 837 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 838 | + EE_Register_Module::register( |
|
| 839 | + $addon_name, |
|
| 840 | + array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 841 | + ); |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * @param string $addon_name |
|
| 848 | + * @return void |
|
| 849 | + * @throws EE_Error |
|
| 850 | + */ |
|
| 851 | + private static function _register_shortcodes($addon_name) |
|
| 852 | + { |
|
| 853 | + if ( |
|
| 854 | + ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 855 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 856 | + ) { |
|
| 857 | + EE_Register_Shortcode::register( |
|
| 858 | + $addon_name, |
|
| 859 | + array( |
|
| 860 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 861 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] : array(), |
|
| 862 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 863 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] : array(), |
|
| 864 | + ) |
|
| 865 | + ); |
|
| 866 | + } |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * @param string $addon_name |
|
| 872 | + * @return void |
|
| 873 | + * @throws EE_Error |
|
| 874 | + */ |
|
| 875 | + private static function _register_widgets($addon_name) |
|
| 876 | + { |
|
| 877 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 878 | + EE_Register_Widget::register( |
|
| 879 | + $addon_name, |
|
| 880 | + array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 881 | + ); |
|
| 882 | + } |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + |
|
| 886 | + /** |
|
| 887 | + * @param string $addon_name |
|
| 888 | + * @return void |
|
| 889 | + * @throws EE_Error |
|
| 890 | + */ |
|
| 891 | + private static function _register_capabilities($addon_name) |
|
| 892 | + { |
|
| 893 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 894 | + EE_Register_Capabilities::register( |
|
| 895 | + $addon_name, |
|
| 896 | + array( |
|
| 897 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 898 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 899 | + ) |
|
| 900 | + ); |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + |
|
| 905 | + /** |
|
| 906 | + * @param string $addon_name |
|
| 907 | + * @return void |
|
| 908 | + */ |
|
| 909 | + private static function _register_message_types($addon_name) |
|
| 910 | + { |
|
| 911 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 912 | + add_action( |
|
| 913 | + 'EE_Brewing_Regular___messages_caf', |
|
| 914 | + array('EE_Register_Addon', 'register_message_types') |
|
| 915 | + ); |
|
| 916 | + } |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * @param string $addon_name |
|
| 922 | + * @return void |
|
| 923 | + * @throws EE_Error |
|
| 924 | + */ |
|
| 925 | + private static function _register_custom_post_types($addon_name) |
|
| 926 | + { |
|
| 927 | + if ( |
|
| 928 | + ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 929 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 930 | + ) { |
|
| 931 | + EE_Register_CPT::register( |
|
| 932 | + $addon_name, |
|
| 933 | + array( |
|
| 934 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 935 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 936 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 937 | + ) |
|
| 938 | + ); |
|
| 939 | + } |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + |
|
| 943 | + /** |
|
| 944 | + * @param string $addon_name |
|
| 945 | + * @return void |
|
| 946 | + * @throws InvalidArgumentException |
|
| 947 | + * @throws InvalidInterfaceException |
|
| 948 | + * @throws InvalidDataTypeException |
|
| 949 | + * @throws DomainException |
|
| 950 | + * @throws EE_Error |
|
| 951 | + */ |
|
| 952 | + private static function _register_payment_methods($addon_name) |
|
| 953 | + { |
|
| 954 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 955 | + EE_Register_Payment_Method::register( |
|
| 956 | + $addon_name, |
|
| 957 | + array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 958 | + ); |
|
| 959 | + } |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + |
|
| 963 | + /** |
|
| 964 | + * @param string $addon_name |
|
| 965 | + * @return void |
|
| 966 | + * @throws InvalidArgumentException |
|
| 967 | + * @throws InvalidInterfaceException |
|
| 968 | + * @throws InvalidDataTypeException |
|
| 969 | + * @throws DomainException |
|
| 970 | + */ |
|
| 971 | + private static function registerPrivacyPolicies($addon_name) |
|
| 972 | + { |
|
| 973 | + if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
| 974 | + EE_Register_Privacy_Policy::register( |
|
| 975 | + $addon_name, |
|
| 976 | + self::$_settings[ $addon_name ]['privacy_policies'] |
|
| 977 | + ); |
|
| 978 | + } |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * @param string $addon_name |
|
| 984 | + * @return void |
|
| 985 | + */ |
|
| 986 | + private static function registerPersonalDataExporters($addon_name) |
|
| 987 | + { |
|
| 988 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
| 989 | + EE_Register_Personal_Data_Eraser::register( |
|
| 990 | + $addon_name, |
|
| 991 | + self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
| 992 | + ); |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + |
|
| 996 | + |
|
| 997 | + /** |
|
| 998 | + * @param string $addon_name |
|
| 999 | + * @return void |
|
| 1000 | + */ |
|
| 1001 | + private static function registerPersonalDataErasers($addon_name) |
|
| 1002 | + { |
|
| 1003 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
| 1004 | + EE_Register_Personal_Data_Eraser::register( |
|
| 1005 | + $addon_name, |
|
| 1006 | + self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
| 1007 | + ); |
|
| 1008 | + } |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + |
|
| 1012 | + /** |
|
| 1013 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 1014 | + * |
|
| 1015 | + * @param string $addon_name |
|
| 1016 | + * @return EE_Addon |
|
| 1017 | + * @throws InvalidArgumentException |
|
| 1018 | + * @throws InvalidInterfaceException |
|
| 1019 | + * @throws InvalidDataTypeException |
|
| 1020 | + */ |
|
| 1021 | + private static function _load_and_init_addon_class($addon_name) |
|
| 1022 | + { |
|
| 1023 | + $addon = LoaderFactory::getLoader()->getShared( |
|
| 1024 | + self::$_settings[ $addon_name ]['class_name'], |
|
| 1025 | + array('EE_Registry::create(addon)' => true) |
|
| 1026 | + ); |
|
| 1027 | + if (! $addon instanceof EE_Addon) { |
|
| 1028 | + throw new DomainException( |
|
| 1029 | + sprintf( |
|
| 1030 | + esc_html__( |
|
| 1031 | + 'Failed to instantiate the %1$s class. PLease check that the class exists.', |
|
| 1032 | + 'event_espresso' |
|
| 1033 | + ), |
|
| 1034 | + $addon_name |
|
| 1035 | + ) |
|
| 1036 | + ); |
|
| 1037 | + } |
|
| 1038 | + // setter inject dep map if required |
|
| 1039 | + if ($addon->dependencyMap() === null) { |
|
| 1040 | + $addon->setDependencyMap(LoaderFactory::getLoader()->getShared('EE_Dependency_Map')); |
|
| 1041 | + } |
|
| 1042 | + // setter inject domain if required |
|
| 1043 | + EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
|
| 1044 | + |
|
| 1045 | + $addon->set_name($addon_name); |
|
| 1046 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 1047 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 1048 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 1049 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 1050 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 1051 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 1052 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 1053 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 1054 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 1055 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 1056 | + // setup the add-on's pue_slug if we have one. |
|
| 1057 | + if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
| 1058 | + $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
| 1059 | + } |
|
| 1060 | + // unfortunately this can't be hooked in upon construction, |
|
| 1061 | + // because we don't have the plugin's mainfile path upon construction. |
|
| 1062 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 1063 | + // call any additional admin_callback functions during load_admin_controller hook |
|
| 1064 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 1065 | + add_action( |
|
| 1066 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 1067 | + array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 1068 | + ); |
|
| 1069 | + } |
|
| 1070 | + return $addon; |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + |
|
| 1074 | + /** |
|
| 1075 | + * @param string $addon_name |
|
| 1076 | + * @param EE_Addon $addon |
|
| 1077 | + * @since 4.10.13.p |
|
| 1078 | + */ |
|
| 1079 | + private static function injectAddonDomain($addon_name, EE_Addon $addon) |
|
| 1080 | + { |
|
| 1081 | + if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
|
| 1082 | + // using supplied Domain object |
|
| 1083 | + $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
| 1084 | + ? self::$_settings[ $addon_name ]['domain'] |
|
| 1085 | + : null; |
|
| 1086 | + // or construct one using Domain FQCN |
|
| 1087 | + if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
| 1088 | + $domain = LoaderFactory::getLoader()->getShared( |
|
| 1089 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 1090 | + [ |
|
| 1091 | + new EventEspresso\core\domain\values\FilePath( |
|
| 1092 | + self::$_settings[ $addon_name ]['main_file_path'] |
|
| 1093 | + ), |
|
| 1094 | + EventEspresso\core\domain\values\Version::fromString( |
|
| 1095 | + self::$_settings[ $addon_name ]['version'] |
|
| 1096 | + ), |
|
| 1097 | + ] |
|
| 1098 | + ); |
|
| 1099 | + } |
|
| 1100 | + if ($domain instanceof DomainInterface) { |
|
| 1101 | + $addon->setDomain($domain); |
|
| 1102 | + } |
|
| 1103 | + } |
|
| 1104 | + } |
|
| 1105 | + |
|
| 1106 | + |
|
| 1107 | + /** |
|
| 1108 | + * load_pue_update - Update notifications |
|
| 1109 | + * |
|
| 1110 | + * @return void |
|
| 1111 | + * @throws InvalidArgumentException |
|
| 1112 | + * @throws InvalidDataTypeException |
|
| 1113 | + * @throws InvalidInterfaceException |
|
| 1114 | + */ |
|
| 1115 | + public static function load_pue_update() |
|
| 1116 | + { |
|
| 1117 | + // load PUE client |
|
| 1118 | + require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
| 1119 | + $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
| 1120 | + // cycle thru settings |
|
| 1121 | + foreach (self::$_settings as $settings) { |
|
| 1122 | + if (! empty($settings['pue_options'])) { |
|
| 1123 | + // initiate the class and start the plugin update engine! |
|
| 1124 | + new PluginUpdateEngineChecker( |
|
| 1125 | + // host file URL |
|
| 1126 | + $license_server, |
|
| 1127 | + // plugin slug(s) |
|
| 1128 | + array( |
|
| 1129 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 1130 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1131 | + ), |
|
| 1132 | + // options |
|
| 1133 | + array( |
|
| 1134 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1135 | + 'lang_domain' => 'event_espresso', |
|
| 1136 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1137 | + 'option_key' => 'ee_site_license_key', |
|
| 1138 | + 'options_page_slug' => 'event_espresso', |
|
| 1139 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1140 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1141 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1142 | + ) |
|
| 1143 | + ); |
|
| 1144 | + } |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + /** |
|
| 1150 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1151 | + * |
|
| 1152 | + * @since 4.4.0 |
|
| 1153 | + * @return void |
|
| 1154 | + * @throws EE_Error |
|
| 1155 | + */ |
|
| 1156 | + public static function register_message_types() |
|
| 1157 | + { |
|
| 1158 | + foreach (self::$_settings as $settings) { |
|
| 1159 | + if (! empty($settings['message_types'])) { |
|
| 1160 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1161 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1162 | + } |
|
| 1163 | + } |
|
| 1164 | + } |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + |
|
| 1168 | + /** |
|
| 1169 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1170 | + * |
|
| 1171 | + * @param string $addon_name the name for the addon that was previously registered |
|
| 1172 | + * @throws DomainException |
|
| 1173 | + * @throws InvalidArgumentException |
|
| 1174 | + * @throws InvalidDataTypeException |
|
| 1175 | + * @throws InvalidInterfaceException |
|
| 1176 | + *@since 4.3.0 |
|
| 1177 | + */ |
|
| 1178 | + public static function deregister($addon_name = '') |
|
| 1179 | + { |
|
| 1180 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1181 | + try { |
|
| 1182 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1183 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1184 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1185 | + // setup DMS |
|
| 1186 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1187 | + } |
|
| 1188 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1189 | + // register admin page |
|
| 1190 | + EE_Register_Admin_Page::deregister($addon_name); |
|
| 1191 | + } |
|
| 1192 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1193 | + // add to list of modules to be registered |
|
| 1194 | + EE_Register_Module::deregister($addon_name); |
|
| 1195 | + } |
|
| 1196 | + if ( |
|
| 1197 | + ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1198 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1199 | + ) { |
|
| 1200 | + // add to list of shortcodes to be registered |
|
| 1201 | + EE_Register_Shortcode::deregister($addon_name); |
|
| 1202 | + } |
|
| 1203 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1204 | + // if config_class present let's register config. |
|
| 1205 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1206 | + } |
|
| 1207 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1208 | + // add to list of widgets to be registered |
|
| 1209 | + EE_Register_Widget::deregister($addon_name); |
|
| 1210 | + } |
|
| 1211 | + if ( |
|
| 1212 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1213 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1214 | + ) { |
|
| 1215 | + // add to list of shortcodes to be registered |
|
| 1216 | + EE_Register_Model::deregister($addon_name); |
|
| 1217 | + } |
|
| 1218 | + if ( |
|
| 1219 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1220 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1221 | + ) { |
|
| 1222 | + // add to list of shortcodes to be registered |
|
| 1223 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1224 | + } |
|
| 1225 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1226 | + foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
| 1227 | + EE_Register_Message_Type::deregister($message_type); |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + // deregister capabilities for addon |
|
| 1231 | + if ( |
|
| 1232 | + ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1233 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1234 | + ) { |
|
| 1235 | + EE_Register_Capabilities::deregister($addon_name); |
|
| 1236 | + } |
|
| 1237 | + // deregister custom_post_types for addon |
|
| 1238 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1239 | + EE_Register_CPT::deregister($addon_name); |
|
| 1240 | + } |
|
| 1241 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1242 | + EE_Register_Payment_Method::deregister($addon_name); |
|
| 1243 | + } |
|
| 1244 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1245 | + if ($addon instanceof EE_Addon) { |
|
| 1246 | + remove_action( |
|
| 1247 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1248 | + array($addon, 'deactivation') |
|
| 1249 | + ); |
|
| 1250 | + remove_action( |
|
| 1251 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1252 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1253 | + ); |
|
| 1254 | + // remove `after_registration` call |
|
| 1255 | + remove_action( |
|
| 1256 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1257 | + array($addon, 'after_registration'), |
|
| 1258 | + 999 |
|
| 1259 | + ); |
|
| 1260 | + } |
|
| 1261 | + EE_Registry::instance()->removeAddon($class_name); |
|
| 1262 | + LoaderFactory::getLoader()->remove($class_name); |
|
| 1263 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
| 1264 | + // the add-on was not yet registered in the registry, |
|
| 1265 | + // so RegistryContainer::__get() throws this exception. |
|
| 1266 | + // also no need to worry about this or log it, |
|
| 1267 | + // it's ok to deregister an add-on before its registered in the registry |
|
| 1268 | + } catch (Exception $e) { |
|
| 1269 | + new ExceptionLogger($e); |
|
| 1270 | + } |
|
| 1271 | + unset(self::$_settings[ $addon_name ]); |
|
| 1272 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1273 | + } |
|
| 1274 | + } |
|
| 1275 | 1275 | } |