@@ -12,38 +12,38 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class AddressFormatter |
| 14 | 14 | { |
| 15 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 16 | - /** |
|
| 17 | - * @param string $address |
|
| 18 | - * @param string $address2 |
|
| 19 | - * @param string $city |
|
| 20 | - * @param string $state |
|
| 21 | - * @param string $zip |
|
| 22 | - * @param string $country |
|
| 23 | - * @param string $formatted_address |
|
| 24 | - * @param string $sub |
|
| 25 | - * @return string |
|
| 26 | - */ |
|
| 27 | - protected function parse_formatted_address( |
|
| 28 | - string $address, |
|
| 29 | - string $address2, |
|
| 30 | - string $city, |
|
| 31 | - string $state, |
|
| 32 | - string $zip, |
|
| 33 | - string $country, |
|
| 34 | - string $formatted_address, |
|
| 35 | - string $sub |
|
| 36 | - ) : string { |
|
| 37 | - // swap address part placeholders for the real text |
|
| 38 | - $formatted_address = str_replace( |
|
| 39 | - // find |
|
| 40 | - array('{address}', '{address2}', '{city}', '{state}', '{zip}', '{country}'), |
|
| 41 | - // replace |
|
| 42 | - array($address, $address2, $city, $state, $zip, $country), |
|
| 43 | - // string |
|
| 44 | - $formatted_address |
|
| 45 | - ); |
|
| 46 | - // remove placeholder from start and end, reduce repeating placeholders to singles, then replace with HTML line breaks |
|
| 47 | - return preg_replace('/%+/', $sub, trim($formatted_address, '%')); |
|
| 48 | - } |
|
| 15 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 16 | + /** |
|
| 17 | + * @param string $address |
|
| 18 | + * @param string $address2 |
|
| 19 | + * @param string $city |
|
| 20 | + * @param string $state |
|
| 21 | + * @param string $zip |
|
| 22 | + * @param string $country |
|
| 23 | + * @param string $formatted_address |
|
| 24 | + * @param string $sub |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + protected function parse_formatted_address( |
|
| 28 | + string $address, |
|
| 29 | + string $address2, |
|
| 30 | + string $city, |
|
| 31 | + string $state, |
|
| 32 | + string $zip, |
|
| 33 | + string $country, |
|
| 34 | + string $formatted_address, |
|
| 35 | + string $sub |
|
| 36 | + ) : string { |
|
| 37 | + // swap address part placeholders for the real text |
|
| 38 | + $formatted_address = str_replace( |
|
| 39 | + // find |
|
| 40 | + array('{address}', '{address2}', '{city}', '{state}', '{zip}', '{country}'), |
|
| 41 | + // replace |
|
| 42 | + array($address, $address2, $city, $state, $zip, $country), |
|
| 43 | + // string |
|
| 44 | + $formatted_address |
|
| 45 | + ); |
|
| 46 | + // remove placeholder from start and end, reduce repeating placeholders to singles, then replace with HTML line breaks |
|
| 47 | + return preg_replace('/%+/', $sub, trim($formatted_address, '%')); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -15,45 +15,45 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class MultiLineAddressFormatter extends AddressFormatter implements EEI_Address_Formatter |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @param string $address |
|
| 20 | - * @param string $address2 |
|
| 21 | - * @param string $city |
|
| 22 | - * @param string $state |
|
| 23 | - * @param string $zip |
|
| 24 | - * @param string $country |
|
| 25 | - * @param string $CNT_ISO |
|
| 26 | - * @return string |
|
| 27 | - */ |
|
| 28 | - public function format( |
|
| 29 | - string $address, |
|
| 30 | - string $address2, |
|
| 31 | - string $city, |
|
| 32 | - string $state, |
|
| 33 | - string $zip, |
|
| 34 | - string $country, |
|
| 35 | - string $CNT_ISO |
|
| 36 | - ): string { |
|
| 37 | - $address_formats = apply_filters( |
|
| 38 | - 'FHEE__EE_MultiLine_Address_Formatter__address_formats', |
|
| 39 | - array( |
|
| 40 | - 'CA' => "{address}%{address2}%{city}%{state}%{country}%{zip}", |
|
| 41 | - 'GB' => "{address}%{address2}%{city}%{state}%{zip}%{country}", |
|
| 42 | - 'US' => "{address}%{address2}%{city}%{state}%{zip}%{country}", |
|
| 43 | - 'ZZ' => "{address}%{address2}%{city}%{state}%{zip}%{country}", |
|
| 44 | - ) |
|
| 45 | - ); |
|
| 46 | - // if the incoming country has a set format, use that, else use the default |
|
| 47 | - $formatted_address = $address_formats[ $CNT_ISO ] ?? $address_formats['ZZ']; |
|
| 48 | - return $this->parse_formatted_address( |
|
| 49 | - $address, |
|
| 50 | - $address2, |
|
| 51 | - $city, |
|
| 52 | - $state, |
|
| 53 | - $zip, |
|
| 54 | - $country, |
|
| 55 | - $formatted_address, |
|
| 56 | - '<br />' |
|
| 57 | - ); |
|
| 58 | - } |
|
| 18 | + /** |
|
| 19 | + * @param string $address |
|
| 20 | + * @param string $address2 |
|
| 21 | + * @param string $city |
|
| 22 | + * @param string $state |
|
| 23 | + * @param string $zip |
|
| 24 | + * @param string $country |
|
| 25 | + * @param string $CNT_ISO |
|
| 26 | + * @return string |
|
| 27 | + */ |
|
| 28 | + public function format( |
|
| 29 | + string $address, |
|
| 30 | + string $address2, |
|
| 31 | + string $city, |
|
| 32 | + string $state, |
|
| 33 | + string $zip, |
|
| 34 | + string $country, |
|
| 35 | + string $CNT_ISO |
|
| 36 | + ): string { |
|
| 37 | + $address_formats = apply_filters( |
|
| 38 | + 'FHEE__EE_MultiLine_Address_Formatter__address_formats', |
|
| 39 | + array( |
|
| 40 | + 'CA' => "{address}%{address2}%{city}%{state}%{country}%{zip}", |
|
| 41 | + 'GB' => "{address}%{address2}%{city}%{state}%{zip}%{country}", |
|
| 42 | + 'US' => "{address}%{address2}%{city}%{state}%{zip}%{country}", |
|
| 43 | + 'ZZ' => "{address}%{address2}%{city}%{state}%{zip}%{country}", |
|
| 44 | + ) |
|
| 45 | + ); |
|
| 46 | + // if the incoming country has a set format, use that, else use the default |
|
| 47 | + $formatted_address = $address_formats[ $CNT_ISO ] ?? $address_formats['ZZ']; |
|
| 48 | + return $this->parse_formatted_address( |
|
| 49 | + $address, |
|
| 50 | + $address2, |
|
| 51 | + $city, |
|
| 52 | + $state, |
|
| 53 | + $zip, |
|
| 54 | + $country, |
|
| 55 | + $formatted_address, |
|
| 56 | + '<br />' |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | ) |
| 45 | 45 | ); |
| 46 | 46 | // if the incoming country has a set format, use that, else use the default |
| 47 | - $formatted_address = $address_formats[ $CNT_ISO ] ?? $address_formats['ZZ']; |
|
| 47 | + $formatted_address = $address_formats[$CNT_ISO] ?? $address_formats['ZZ']; |
|
| 48 | 48 | return $this->parse_formatted_address( |
| 49 | 49 | $address, |
| 50 | 50 | $address2, |
@@ -12,25 +12,25 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class NullAddressFormatter implements \EEI_Address_Formatter |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @param string $address |
|
| 17 | - * @param string $address2 |
|
| 18 | - * @param string $city |
|
| 19 | - * @param string $state |
|
| 20 | - * @param string $zip |
|
| 21 | - * @param string $country |
|
| 22 | - * @param string $CNT_ISO |
|
| 23 | - * @return null |
|
| 24 | - */ |
|
| 25 | - public function format( |
|
| 26 | - string $address, |
|
| 27 | - string $address2, |
|
| 28 | - string $city, |
|
| 29 | - string $state, |
|
| 30 | - string $zip, |
|
| 31 | - string $country, |
|
| 32 | - string $CNT_ISO |
|
| 33 | - ): ?string { |
|
| 34 | - return null; |
|
| 35 | - } |
|
| 15 | + /** |
|
| 16 | + * @param string $address |
|
| 17 | + * @param string $address2 |
|
| 18 | + * @param string $city |
|
| 19 | + * @param string $state |
|
| 20 | + * @param string $zip |
|
| 21 | + * @param string $country |
|
| 22 | + * @param string $CNT_ISO |
|
| 23 | + * @return null |
|
| 24 | + */ |
|
| 25 | + public function format( |
|
| 26 | + string $address, |
|
| 27 | + string $address2, |
|
| 28 | + string $city, |
|
| 29 | + string $state, |
|
| 30 | + string $zip, |
|
| 31 | + string $country, |
|
| 32 | + string $CNT_ISO |
|
| 33 | + ): ?string { |
|
| 34 | + return null; |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -24,246 +24,246 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class CountrySubRegionDao |
| 26 | 26 | { |
| 27 | - const REPO_URL = 'https://raw.githubusercontent.com/eventespresso/countries-and-subregions/master/'; |
|
| 27 | + const REPO_URL = 'https://raw.githubusercontent.com/eventespresso/countries-and-subregions/master/'; |
|
| 28 | 28 | |
| 29 | - const OPTION_NAME_COUNTRY_DATA_VERSION = 'espresso-country-sub-region-data-version'; |
|
| 29 | + const OPTION_NAME_COUNTRY_DATA_VERSION = 'espresso-country-sub-region-data-version'; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var EEM_State $state_model |
|
| 33 | - */ |
|
| 34 | - private $state_model; |
|
| 31 | + /** |
|
| 32 | + * @var EEM_State $state_model |
|
| 33 | + */ |
|
| 34 | + private $state_model; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var JsonValidator $json_validator |
|
| 38 | - */ |
|
| 39 | - private $json_validator; |
|
| 36 | + /** |
|
| 37 | + * @var JsonValidator $json_validator |
|
| 38 | + */ |
|
| 39 | + private $json_validator; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var string $data_version |
|
| 43 | - */ |
|
| 44 | - private $data_version; |
|
| 41 | + /** |
|
| 42 | + * @var string $data_version |
|
| 43 | + */ |
|
| 44 | + private $data_version; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var array $countries |
|
| 48 | - */ |
|
| 49 | - private $countries = array(); |
|
| 46 | + /** |
|
| 47 | + * @var array $countries |
|
| 48 | + */ |
|
| 49 | + private $countries = array(); |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * CountrySubRegionDao constructor. |
|
| 54 | - * |
|
| 55 | - * @param EEM_State $state_model |
|
| 56 | - * @param JsonValidator $json_validator |
|
| 57 | - */ |
|
| 58 | - public function __construct(EEM_State $state_model, JsonValidator $json_validator) |
|
| 59 | - { |
|
| 60 | - $this->state_model = $state_model; |
|
| 61 | - $this->json_validator = $json_validator; |
|
| 62 | - } |
|
| 52 | + /** |
|
| 53 | + * CountrySubRegionDao constructor. |
|
| 54 | + * |
|
| 55 | + * @param EEM_State $state_model |
|
| 56 | + * @param JsonValidator $json_validator |
|
| 57 | + */ |
|
| 58 | + public function __construct(EEM_State $state_model, JsonValidator $json_validator) |
|
| 59 | + { |
|
| 60 | + $this->state_model = $state_model; |
|
| 61 | + $this->json_validator = $json_validator; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param EE_Country $country_object |
|
| 67 | - * @return bool |
|
| 68 | - * @throws EE_Error |
|
| 69 | - * @throws InvalidArgumentException |
|
| 70 | - * @throws InvalidDataTypeException |
|
| 71 | - * @throws InvalidInterfaceException |
|
| 72 | - * @throws ReflectionException |
|
| 73 | - */ |
|
| 74 | - public function saveCountrySubRegions(EE_Country $country_object): bool |
|
| 75 | - { |
|
| 76 | - $CNT_ISO = $country_object->ID(); |
|
| 77 | - $has_sub_regions = $this->state_model->count(array(array('Country.CNT_ISO' => $CNT_ISO))); |
|
| 78 | - $data = new stdClass(); |
|
| 79 | - if (empty($this->countries)) { |
|
| 80 | - $this->data_version = $this->getCountrySubRegionDataVersion(); |
|
| 81 | - $data = $this->retrieveJsonData(self::REPO_URL . 'countries.json'); |
|
| 82 | - } |
|
| 83 | - if (empty($data)) { |
|
| 84 | - EE_Error::add_error( |
|
| 85 | - 'Country Subregion Data could not be retrieved', |
|
| 86 | - __FILE__, |
|
| 87 | - __METHOD__, |
|
| 88 | - __LINE__ |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - if ( |
|
| 92 | - ! $has_sub_regions |
|
| 93 | - || (isset($data->version) && version_compare($data->version, $this->data_version)) |
|
| 94 | - ) { |
|
| 95 | - if ( |
|
| 96 | - isset($data->countries) |
|
| 97 | - && $this->processCountryData($CNT_ISO, $data->countries) > 0 |
|
| 98 | - ) { |
|
| 99 | - $this->countries = $data->countries; |
|
| 100 | - $this->updateCountrySubRegionDataVersion($data->version); |
|
| 101 | - return true; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - return false; |
|
| 105 | - } |
|
| 65 | + /** |
|
| 66 | + * @param EE_Country $country_object |
|
| 67 | + * @return bool |
|
| 68 | + * @throws EE_Error |
|
| 69 | + * @throws InvalidArgumentException |
|
| 70 | + * @throws InvalidDataTypeException |
|
| 71 | + * @throws InvalidInterfaceException |
|
| 72 | + * @throws ReflectionException |
|
| 73 | + */ |
|
| 74 | + public function saveCountrySubRegions(EE_Country $country_object): bool |
|
| 75 | + { |
|
| 76 | + $CNT_ISO = $country_object->ID(); |
|
| 77 | + $has_sub_regions = $this->state_model->count(array(array('Country.CNT_ISO' => $CNT_ISO))); |
|
| 78 | + $data = new stdClass(); |
|
| 79 | + if (empty($this->countries)) { |
|
| 80 | + $this->data_version = $this->getCountrySubRegionDataVersion(); |
|
| 81 | + $data = $this->retrieveJsonData(self::REPO_URL . 'countries.json'); |
|
| 82 | + } |
|
| 83 | + if (empty($data)) { |
|
| 84 | + EE_Error::add_error( |
|
| 85 | + 'Country Subregion Data could not be retrieved', |
|
| 86 | + __FILE__, |
|
| 87 | + __METHOD__, |
|
| 88 | + __LINE__ |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + if ( |
|
| 92 | + ! $has_sub_regions |
|
| 93 | + || (isset($data->version) && version_compare($data->version, $this->data_version)) |
|
| 94 | + ) { |
|
| 95 | + if ( |
|
| 96 | + isset($data->countries) |
|
| 97 | + && $this->processCountryData($CNT_ISO, $data->countries) > 0 |
|
| 98 | + ) { |
|
| 99 | + $this->countries = $data->countries; |
|
| 100 | + $this->updateCountrySubRegionDataVersion($data->version); |
|
| 101 | + return true; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @since 4.9.70.p |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - private function getCountrySubRegionDataVersion(): string |
|
| 113 | - { |
|
| 114 | - return get_option(self::OPTION_NAME_COUNTRY_DATA_VERSION, null); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * @since 4.9.70.p |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + private function getCountrySubRegionDataVersion(): string |
|
| 113 | + { |
|
| 114 | + return get_option(self::OPTION_NAME_COUNTRY_DATA_VERSION, null); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * @param string $version |
|
| 120 | - */ |
|
| 121 | - private function updateCountrySubRegionDataVersion(string $version = '') |
|
| 122 | - { |
|
| 123 | - // add version option if it has never been added before, or update existing |
|
| 124 | - if ($this->data_version === null) { |
|
| 125 | - add_option(self::OPTION_NAME_COUNTRY_DATA_VERSION, $version, '', false); |
|
| 126 | - } else { |
|
| 127 | - update_option(self::OPTION_NAME_COUNTRY_DATA_VERSION, $version); |
|
| 128 | - } |
|
| 129 | - } |
|
| 118 | + /** |
|
| 119 | + * @param string $version |
|
| 120 | + */ |
|
| 121 | + private function updateCountrySubRegionDataVersion(string $version = '') |
|
| 122 | + { |
|
| 123 | + // add version option if it has never been added before, or update existing |
|
| 124 | + if ($this->data_version === null) { |
|
| 125 | + add_option(self::OPTION_NAME_COUNTRY_DATA_VERSION, $version, '', false); |
|
| 126 | + } else { |
|
| 127 | + update_option(self::OPTION_NAME_COUNTRY_DATA_VERSION, $version); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * @param string $CNT_ISO |
|
| 134 | - * @param array $countries |
|
| 135 | - * @return int |
|
| 136 | - * @throws EE_Error |
|
| 137 | - * @since 4.9.70.p |
|
| 138 | - */ |
|
| 139 | - private function processCountryData(string $CNT_ISO, array $countries = array()): int |
|
| 140 | - { |
|
| 141 | - if (! empty($countries)) { |
|
| 142 | - foreach ($countries as $country) { |
|
| 143 | - if ( |
|
| 144 | - $country instanceof stdClass |
|
| 145 | - && $country->code === $CNT_ISO |
|
| 146 | - && empty($country->sub_regions) |
|
| 147 | - && ! empty($country->filename) |
|
| 148 | - ) { |
|
| 149 | - $country->sub_regions = $this->retrieveJsonData( |
|
| 150 | - self::REPO_URL . 'countries/' . $country->filename . '.json' |
|
| 151 | - ); |
|
| 152 | - return $this->saveSubRegionData($country, $country->sub_regions); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - return 0; |
|
| 157 | - } |
|
| 132 | + /** |
|
| 133 | + * @param string $CNT_ISO |
|
| 134 | + * @param array $countries |
|
| 135 | + * @return int |
|
| 136 | + * @throws EE_Error |
|
| 137 | + * @since 4.9.70.p |
|
| 138 | + */ |
|
| 139 | + private function processCountryData(string $CNT_ISO, array $countries = array()): int |
|
| 140 | + { |
|
| 141 | + if (! empty($countries)) { |
|
| 142 | + foreach ($countries as $country) { |
|
| 143 | + if ( |
|
| 144 | + $country instanceof stdClass |
|
| 145 | + && $country->code === $CNT_ISO |
|
| 146 | + && empty($country->sub_regions) |
|
| 147 | + && ! empty($country->filename) |
|
| 148 | + ) { |
|
| 149 | + $country->sub_regions = $this->retrieveJsonData( |
|
| 150 | + self::REPO_URL . 'countries/' . $country->filename . '.json' |
|
| 151 | + ); |
|
| 152 | + return $this->saveSubRegionData($country, $country->sub_regions); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + return 0; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * @param string $url |
|
| 162 | - * @return array |
|
| 163 | - */ |
|
| 164 | - private function retrieveJsonData(string $url): array |
|
| 165 | - { |
|
| 166 | - if (empty($url)) { |
|
| 167 | - EE_Error::add_error( |
|
| 168 | - 'No URL was provided!', |
|
| 169 | - __FILE__, |
|
| 170 | - __METHOD__, |
|
| 171 | - __LINE__ |
|
| 172 | - ); |
|
| 173 | - return array(); |
|
| 174 | - } |
|
| 175 | - $request = wp_safe_remote_get($url); |
|
| 176 | - if ($request instanceof WP_Error) { |
|
| 177 | - EE_Error::add_error( |
|
| 178 | - $request->get_error_message(), |
|
| 179 | - __FILE__, |
|
| 180 | - __METHOD__, |
|
| 181 | - __LINE__ |
|
| 182 | - ); |
|
| 183 | - return array(); |
|
| 184 | - } |
|
| 185 | - $body = wp_remote_retrieve_body($request); |
|
| 186 | - $json = json_decode($body); |
|
| 187 | - if ($this->json_validator->isValid(__FILE__, __METHOD__, __LINE__)) { |
|
| 188 | - return $json; |
|
| 189 | - } |
|
| 190 | - return array(); |
|
| 191 | - } |
|
| 160 | + /** |
|
| 161 | + * @param string $url |
|
| 162 | + * @return array |
|
| 163 | + */ |
|
| 164 | + private function retrieveJsonData(string $url): array |
|
| 165 | + { |
|
| 166 | + if (empty($url)) { |
|
| 167 | + EE_Error::add_error( |
|
| 168 | + 'No URL was provided!', |
|
| 169 | + __FILE__, |
|
| 170 | + __METHOD__, |
|
| 171 | + __LINE__ |
|
| 172 | + ); |
|
| 173 | + return array(); |
|
| 174 | + } |
|
| 175 | + $request = wp_safe_remote_get($url); |
|
| 176 | + if ($request instanceof WP_Error) { |
|
| 177 | + EE_Error::add_error( |
|
| 178 | + $request->get_error_message(), |
|
| 179 | + __FILE__, |
|
| 180 | + __METHOD__, |
|
| 181 | + __LINE__ |
|
| 182 | + ); |
|
| 183 | + return array(); |
|
| 184 | + } |
|
| 185 | + $body = wp_remote_retrieve_body($request); |
|
| 186 | + $json = json_decode($body); |
|
| 187 | + if ($this->json_validator->isValid(__FILE__, __METHOD__, __LINE__)) { |
|
| 188 | + return $json; |
|
| 189 | + } |
|
| 190 | + return array(); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * @param stdClass $country |
|
| 196 | - * @param array $sub_regions |
|
| 197 | - * @return int |
|
| 198 | - * @throws EE_Error |
|
| 199 | - * @throws InvalidArgumentException |
|
| 200 | - * @throws InvalidDataTypeException |
|
| 201 | - * @throws InvalidInterfaceException |
|
| 202 | - */ |
|
| 203 | - private function saveSubRegionData(stdClass $country, array $sub_regions = array()): int |
|
| 204 | - { |
|
| 205 | - $results = 0; |
|
| 206 | - if (is_array($sub_regions)) { |
|
| 207 | - $existing_sub_regions = $this->getExistingStateAbbreviations($country->code); |
|
| 208 | - foreach ($sub_regions as $sub_region) { |
|
| 209 | - // remove country code from sub region code |
|
| 210 | - $abbrev = str_replace( |
|
| 211 | - $country->code . '-', |
|
| 212 | - '', |
|
| 213 | - sanitize_text_field($sub_region->code) |
|
| 214 | - ); |
|
| 215 | - // but NOT if sub region code results in only a number |
|
| 216 | - if (absint($abbrev) !== 0) { |
|
| 217 | - $abbrev = sanitize_text_field($sub_region->code); |
|
| 218 | - } |
|
| 219 | - if ( |
|
| 220 | - ! in_array($abbrev, $existing_sub_regions, true) |
|
| 221 | - && $this->state_model->insert( |
|
| 222 | - [ |
|
| 223 | - // STA_ID CNT_ISO STA_abbrev STA_name STA_active |
|
| 224 | - 'CNT_ISO' => $country->code, |
|
| 225 | - 'STA_abbrev' => $abbrev, |
|
| 226 | - 'STA_name' => sanitize_text_field($sub_region->name), |
|
| 227 | - 'STA_active' => 1, |
|
| 228 | - ] |
|
| 229 | - ) |
|
| 230 | - ) { |
|
| 231 | - $results++; |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - return $results; |
|
| 236 | - } |
|
| 194 | + /** |
|
| 195 | + * @param stdClass $country |
|
| 196 | + * @param array $sub_regions |
|
| 197 | + * @return int |
|
| 198 | + * @throws EE_Error |
|
| 199 | + * @throws InvalidArgumentException |
|
| 200 | + * @throws InvalidDataTypeException |
|
| 201 | + * @throws InvalidInterfaceException |
|
| 202 | + */ |
|
| 203 | + private function saveSubRegionData(stdClass $country, array $sub_regions = array()): int |
|
| 204 | + { |
|
| 205 | + $results = 0; |
|
| 206 | + if (is_array($sub_regions)) { |
|
| 207 | + $existing_sub_regions = $this->getExistingStateAbbreviations($country->code); |
|
| 208 | + foreach ($sub_regions as $sub_region) { |
|
| 209 | + // remove country code from sub region code |
|
| 210 | + $abbrev = str_replace( |
|
| 211 | + $country->code . '-', |
|
| 212 | + '', |
|
| 213 | + sanitize_text_field($sub_region->code) |
|
| 214 | + ); |
|
| 215 | + // but NOT if sub region code results in only a number |
|
| 216 | + if (absint($abbrev) !== 0) { |
|
| 217 | + $abbrev = sanitize_text_field($sub_region->code); |
|
| 218 | + } |
|
| 219 | + if ( |
|
| 220 | + ! in_array($abbrev, $existing_sub_regions, true) |
|
| 221 | + && $this->state_model->insert( |
|
| 222 | + [ |
|
| 223 | + // STA_ID CNT_ISO STA_abbrev STA_name STA_active |
|
| 224 | + 'CNT_ISO' => $country->code, |
|
| 225 | + 'STA_abbrev' => $abbrev, |
|
| 226 | + 'STA_name' => sanitize_text_field($sub_region->name), |
|
| 227 | + 'STA_active' => 1, |
|
| 228 | + ] |
|
| 229 | + ) |
|
| 230 | + ) { |
|
| 231 | + $results++; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + return $results; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * @param string $CNT_ISO |
|
| 241 | - * @return array |
|
| 242 | - * @throws EE_Error |
|
| 243 | - * @throws InvalidArgumentException |
|
| 244 | - * @throws InvalidDataTypeException |
|
| 245 | - * @throws InvalidInterfaceException |
|
| 246 | - *@since 4.9.76.p |
|
| 247 | - */ |
|
| 248 | - private function getExistingStateAbbreviations(string $CNT_ISO): array |
|
| 249 | - { |
|
| 250 | - $existing_sub_region_IDs = []; |
|
| 251 | - $existing_sub_regions = $this->state_model->get_all(array( |
|
| 252 | - array( |
|
| 253 | - 'Country.CNT_ISO' => array( |
|
| 254 | - 'IN', |
|
| 255 | - [$CNT_ISO] |
|
| 256 | - ) |
|
| 257 | - ), |
|
| 258 | - 'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC') |
|
| 259 | - )); |
|
| 260 | - if (is_array($existing_sub_regions)) { |
|
| 261 | - foreach ($existing_sub_regions as $existing_sub_region) { |
|
| 262 | - if ($existing_sub_region instanceof EE_State) { |
|
| 263 | - $existing_sub_region_IDs[] = $existing_sub_region->abbrev(); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - return $existing_sub_region_IDs; |
|
| 268 | - } |
|
| 239 | + /** |
|
| 240 | + * @param string $CNT_ISO |
|
| 241 | + * @return array |
|
| 242 | + * @throws EE_Error |
|
| 243 | + * @throws InvalidArgumentException |
|
| 244 | + * @throws InvalidDataTypeException |
|
| 245 | + * @throws InvalidInterfaceException |
|
| 246 | + *@since 4.9.76.p |
|
| 247 | + */ |
|
| 248 | + private function getExistingStateAbbreviations(string $CNT_ISO): array |
|
| 249 | + { |
|
| 250 | + $existing_sub_region_IDs = []; |
|
| 251 | + $existing_sub_regions = $this->state_model->get_all(array( |
|
| 252 | + array( |
|
| 253 | + 'Country.CNT_ISO' => array( |
|
| 254 | + 'IN', |
|
| 255 | + [$CNT_ISO] |
|
| 256 | + ) |
|
| 257 | + ), |
|
| 258 | + 'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC') |
|
| 259 | + )); |
|
| 260 | + if (is_array($existing_sub_regions)) { |
|
| 261 | + foreach ($existing_sub_regions as $existing_sub_region) { |
|
| 262 | + if ($existing_sub_region instanceof EE_State) { |
|
| 263 | + $existing_sub_region_IDs[] = $existing_sub_region->abbrev(); |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + return $existing_sub_region_IDs; |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $data = new stdClass(); |
| 79 | 79 | if (empty($this->countries)) { |
| 80 | 80 | $this->data_version = $this->getCountrySubRegionDataVersion(); |
| 81 | - $data = $this->retrieveJsonData(self::REPO_URL . 'countries.json'); |
|
| 81 | + $data = $this->retrieveJsonData(self::REPO_URL.'countries.json'); |
|
| 82 | 82 | } |
| 83 | 83 | if (empty($data)) { |
| 84 | 84 | EE_Error::add_error( |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | private function processCountryData(string $CNT_ISO, array $countries = array()): int |
| 140 | 140 | { |
| 141 | - if (! empty($countries)) { |
|
| 141 | + if ( ! empty($countries)) { |
|
| 142 | 142 | foreach ($countries as $country) { |
| 143 | 143 | if ( |
| 144 | 144 | $country instanceof stdClass |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | && ! empty($country->filename) |
| 148 | 148 | ) { |
| 149 | 149 | $country->sub_regions = $this->retrieveJsonData( |
| 150 | - self::REPO_URL . 'countries/' . $country->filename . '.json' |
|
| 150 | + self::REPO_URL.'countries/'.$country->filename.'.json' |
|
| 151 | 151 | ); |
| 152 | 152 | return $this->saveSubRegionData($country, $country->sub_regions); |
| 153 | 153 | } |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | foreach ($sub_regions as $sub_region) { |
| 209 | 209 | // remove country code from sub region code |
| 210 | 210 | $abbrev = str_replace( |
| 211 | - $country->code . '-', |
|
| 211 | + $country->code.'-', |
|
| 212 | 212 | '', |
| 213 | 213 | sanitize_text_field($sub_region->code) |
| 214 | 214 | ); |
@@ -14,35 +14,35 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class RewriteRules implements InterminableInterface |
| 16 | 16 | { |
| 17 | - const OPTION_KEY_FLUSH_REWRITE_RULES = 'ee_flush_rewrite_rules'; |
|
| 17 | + const OPTION_KEY_FLUSH_REWRITE_RULES = 'ee_flush_rewrite_rules'; |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
| 22 | - * |
|
| 23 | - * @return void |
|
| 24 | - */ |
|
| 25 | - public function flush() |
|
| 26 | - { |
|
| 27 | - update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true); |
|
| 28 | - } |
|
| 20 | + /** |
|
| 21 | + * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
| 22 | + * |
|
| 23 | + * @return void |
|
| 24 | + */ |
|
| 25 | + public function flush() |
|
| 26 | + { |
|
| 27 | + update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
| 33 | - * |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public function flushRewriteRules() |
|
| 37 | - { |
|
| 38 | - if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) { |
|
| 39 | - add_action( |
|
| 40 | - 'shutdown', |
|
| 41 | - static function () { |
|
| 42 | - flush_rewrite_rules(); |
|
| 43 | - update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false); |
|
| 44 | - } |
|
| 45 | - ); |
|
| 46 | - } |
|
| 47 | - } |
|
| 31 | + /** |
|
| 32 | + * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
| 33 | + * |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public function flushRewriteRules() |
|
| 37 | + { |
|
| 38 | + if (get_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, true)) { |
|
| 39 | + add_action( |
|
| 40 | + 'shutdown', |
|
| 41 | + static function () { |
|
| 42 | + flush_rewrite_rules(); |
|
| 43 | + update_option(RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES, false); |
|
| 44 | + } |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -15,9 +15,9 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | interface RequestTypeContextFactoryInterface extends InterminableInterface |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @param string $slug |
|
| 20 | - * @return RequestTypeContext |
|
| 21 | - */ |
|
| 22 | - public function create($slug); |
|
| 18 | + /** |
|
| 19 | + * @param string $slug |
|
| 20 | + * @return RequestTypeContext |
|
| 21 | + */ |
|
| 22 | + public function create($slug); |
|
| 23 | 23 | } |
@@ -15,145 +15,145 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class CustomTaxonomyDefinitions implements InterminableInterface |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var array $taxonomies |
|
| 20 | - */ |
|
| 21 | - private $taxonomies; |
|
| 18 | + /** |
|
| 19 | + * @var array $taxonomies |
|
| 20 | + */ |
|
| 21 | + private $taxonomies; |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * EspressoCustomPostTypeDefinitions constructor. |
|
| 26 | - */ |
|
| 27 | - public function __construct() |
|
| 28 | - { |
|
| 29 | - $this->setTaxonomies(); |
|
| 30 | - add_filter('pre_term_description', array($this, 'filterCustomTermDescription'), 1, 2); |
|
| 31 | - } |
|
| 24 | + /** |
|
| 25 | + * EspressoCustomPostTypeDefinitions constructor. |
|
| 26 | + */ |
|
| 27 | + public function __construct() |
|
| 28 | + { |
|
| 29 | + $this->setTaxonomies(); |
|
| 30 | + add_filter('pre_term_description', array($this, 'filterCustomTermDescription'), 1, 2); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - private function setTaxonomies() |
|
| 35 | - { |
|
| 36 | - $this->taxonomies = array( |
|
| 37 | - 'espresso_event_categories' => array( |
|
| 38 | - 'singular_name' => esc_html__('Event Category', 'event_espresso'), |
|
| 39 | - 'plural_name' => esc_html__('Event Categories', 'event_espresso'), |
|
| 40 | - 'args' => array( |
|
| 41 | - 'public' => true, |
|
| 42 | - 'show_in_nav_menus' => true, |
|
| 43 | - 'show_in_rest' => true, |
|
| 44 | - 'capabilities' => array( |
|
| 45 | - 'manage_terms' => 'ee_manage_event_categories', |
|
| 46 | - 'edit_terms' => 'ee_edit_event_category', |
|
| 47 | - 'delete_terms' => 'ee_delete_event_category', |
|
| 48 | - 'assign_terms' => 'ee_assign_event_category', |
|
| 49 | - ), |
|
| 50 | - 'rewrite' => array( |
|
| 51 | - 'slug' => EEH_URL::slugify( |
|
| 52 | - esc_html__('event-category', 'event_espresso'), |
|
| 53 | - 'event-category' |
|
| 54 | - ) |
|
| 55 | - ), |
|
| 56 | - ), |
|
| 57 | - ), |
|
| 58 | - 'espresso_venue_categories' => array( |
|
| 59 | - 'singular_name' => esc_html__('Venue Category', 'event_espresso'), |
|
| 60 | - 'plural_name' => esc_html__('Venue Categories', 'event_espresso'), |
|
| 61 | - 'args' => array( |
|
| 62 | - 'public' => true, |
|
| 63 | - 'show_in_nav_menus' => false, // by default this doesn't show for decaf |
|
| 64 | - 'show_in_rest' => true, |
|
| 65 | - 'capabilities' => array( |
|
| 66 | - 'manage_terms' => 'ee_manage_venue_categories', |
|
| 67 | - 'edit_terms' => 'ee_edit_venue_category', |
|
| 68 | - 'delete_terms' => 'ee_delete_venue_category', |
|
| 69 | - 'assign_terms' => 'ee_assign_venue_category', |
|
| 70 | - ), |
|
| 71 | - 'rewrite' => array( |
|
| 72 | - 'slug' => EEH_URL::slugify( |
|
| 73 | - esc_html__('venue-category', 'event_espresso'), |
|
| 74 | - 'venue-category' |
|
| 75 | - ) |
|
| 76 | - ), |
|
| 77 | - ), |
|
| 78 | - ), |
|
| 79 | - 'espresso_event_type' => array( |
|
| 80 | - 'singular_name' => esc_html__('Event Type', 'event_espresso'), |
|
| 81 | - 'plural_name' => esc_html__('Event Types', 'event_espresso'), |
|
| 82 | - 'args' => array( |
|
| 83 | - 'public' => true, |
|
| 84 | - 'show_ui' => false, |
|
| 85 | - 'show_in_rest' => true, |
|
| 86 | - 'capabilities' => array( |
|
| 87 | - 'manage_terms' => 'ee_read_event_type', |
|
| 88 | - 'edit_terms' => 'ee_edit_event_type', |
|
| 89 | - 'delete_terms' => 'ee_delete_event_type', |
|
| 90 | - 'assign_terms' => 'ee_assign_event_type', |
|
| 91 | - ), |
|
| 92 | - 'rewrite' => array( |
|
| 93 | - 'slug' => EEH_URL::slugify( |
|
| 94 | - esc_html__('event-type', 'event_espresso'), |
|
| 95 | - 'event-type' |
|
| 96 | - ) |
|
| 97 | - ), |
|
| 98 | - 'hierarchical' => true, |
|
| 99 | - ), |
|
| 100 | - ), |
|
| 101 | - ); |
|
| 102 | - } |
|
| 34 | + private function setTaxonomies() |
|
| 35 | + { |
|
| 36 | + $this->taxonomies = array( |
|
| 37 | + 'espresso_event_categories' => array( |
|
| 38 | + 'singular_name' => esc_html__('Event Category', 'event_espresso'), |
|
| 39 | + 'plural_name' => esc_html__('Event Categories', 'event_espresso'), |
|
| 40 | + 'args' => array( |
|
| 41 | + 'public' => true, |
|
| 42 | + 'show_in_nav_menus' => true, |
|
| 43 | + 'show_in_rest' => true, |
|
| 44 | + 'capabilities' => array( |
|
| 45 | + 'manage_terms' => 'ee_manage_event_categories', |
|
| 46 | + 'edit_terms' => 'ee_edit_event_category', |
|
| 47 | + 'delete_terms' => 'ee_delete_event_category', |
|
| 48 | + 'assign_terms' => 'ee_assign_event_category', |
|
| 49 | + ), |
|
| 50 | + 'rewrite' => array( |
|
| 51 | + 'slug' => EEH_URL::slugify( |
|
| 52 | + esc_html__('event-category', 'event_espresso'), |
|
| 53 | + 'event-category' |
|
| 54 | + ) |
|
| 55 | + ), |
|
| 56 | + ), |
|
| 57 | + ), |
|
| 58 | + 'espresso_venue_categories' => array( |
|
| 59 | + 'singular_name' => esc_html__('Venue Category', 'event_espresso'), |
|
| 60 | + 'plural_name' => esc_html__('Venue Categories', 'event_espresso'), |
|
| 61 | + 'args' => array( |
|
| 62 | + 'public' => true, |
|
| 63 | + 'show_in_nav_menus' => false, // by default this doesn't show for decaf |
|
| 64 | + 'show_in_rest' => true, |
|
| 65 | + 'capabilities' => array( |
|
| 66 | + 'manage_terms' => 'ee_manage_venue_categories', |
|
| 67 | + 'edit_terms' => 'ee_edit_venue_category', |
|
| 68 | + 'delete_terms' => 'ee_delete_venue_category', |
|
| 69 | + 'assign_terms' => 'ee_assign_venue_category', |
|
| 70 | + ), |
|
| 71 | + 'rewrite' => array( |
|
| 72 | + 'slug' => EEH_URL::slugify( |
|
| 73 | + esc_html__('venue-category', 'event_espresso'), |
|
| 74 | + 'venue-category' |
|
| 75 | + ) |
|
| 76 | + ), |
|
| 77 | + ), |
|
| 78 | + ), |
|
| 79 | + 'espresso_event_type' => array( |
|
| 80 | + 'singular_name' => esc_html__('Event Type', 'event_espresso'), |
|
| 81 | + 'plural_name' => esc_html__('Event Types', 'event_espresso'), |
|
| 82 | + 'args' => array( |
|
| 83 | + 'public' => true, |
|
| 84 | + 'show_ui' => false, |
|
| 85 | + 'show_in_rest' => true, |
|
| 86 | + 'capabilities' => array( |
|
| 87 | + 'manage_terms' => 'ee_read_event_type', |
|
| 88 | + 'edit_terms' => 'ee_edit_event_type', |
|
| 89 | + 'delete_terms' => 'ee_delete_event_type', |
|
| 90 | + 'assign_terms' => 'ee_assign_event_type', |
|
| 91 | + ), |
|
| 92 | + 'rewrite' => array( |
|
| 93 | + 'slug' => EEH_URL::slugify( |
|
| 94 | + esc_html__('event-type', 'event_espresso'), |
|
| 95 | + 'event-type' |
|
| 96 | + ) |
|
| 97 | + ), |
|
| 98 | + 'hierarchical' => true, |
|
| 99 | + ), |
|
| 100 | + ), |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * @return array |
|
| 107 | - */ |
|
| 108 | - public function getCustomTaxonomyDefinitions(): array |
|
| 109 | - { |
|
| 110 | - return (array) apply_filters( |
|
| 111 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
| 112 | - // legacy filter applied for now, |
|
| 113 | - // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
| 114 | - apply_filters( |
|
| 115 | - 'FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', |
|
| 116 | - $this->taxonomies |
|
| 117 | - ) |
|
| 118 | - ); |
|
| 119 | - } |
|
| 105 | + /** |
|
| 106 | + * @return array |
|
| 107 | + */ |
|
| 108 | + public function getCustomTaxonomyDefinitions(): array |
|
| 109 | + { |
|
| 110 | + return (array) apply_filters( |
|
| 111 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
| 112 | + // legacy filter applied for now, |
|
| 113 | + // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
| 114 | + apply_filters( |
|
| 115 | + 'FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', |
|
| 116 | + $this->taxonomies |
|
| 117 | + ) |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - public function getCustomTaxonomySlugs(): array |
|
| 126 | - { |
|
| 127 | - return array_keys($this->getCustomTaxonomyDefinitions()); |
|
| 128 | - } |
|
| 122 | + /** |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + public function getCustomTaxonomySlugs(): array |
|
| 126 | + { |
|
| 127 | + return array_keys($this->getCustomTaxonomyDefinitions()); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * By default, WordPress strips all html from term taxonomy description content. |
|
| 133 | - * The purpose of this method is to remove that restriction |
|
| 134 | - * and ensure that we still run ee term taxonomy descriptions |
|
| 135 | - * through some full html sanitization equivalent to the post content field. |
|
| 136 | - * So first we remove default filter for term description |
|
| 137 | - * but we have to do this earlier before wp sets their own filter |
|
| 138 | - * because they just set a global filter on all term descriptions |
|
| 139 | - * before the custom term description filter. |
|
| 140 | - * Really sux. |
|
| 141 | - * |
|
| 142 | - * @param string $description The description content. |
|
| 143 | - * @param string $taxonomy The taxonomy name for the taxonomy being filtered. |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - public function filterCustomTermDescription(string $description, string $taxonomy): string |
|
| 147 | - { |
|
| 148 | - // get a list of EE taxonomies |
|
| 149 | - $custom_taxonomies = $this->getCustomTaxonomySlugs(); |
|
| 150 | - // only do our own thing if the taxonomy listed is an ee taxonomy. |
|
| 151 | - if (in_array($taxonomy, $custom_taxonomies, true)) { |
|
| 152 | - // remove default wp filter |
|
| 153 | - remove_filter('pre_term_description', 'wp_filter_kses'); |
|
| 154 | - // sanitize THIS content. |
|
| 155 | - $description = wp_kses($description, wp_kses_allowed_html('post')); |
|
| 156 | - } |
|
| 157 | - return $description; |
|
| 158 | - } |
|
| 131 | + /** |
|
| 132 | + * By default, WordPress strips all html from term taxonomy description content. |
|
| 133 | + * The purpose of this method is to remove that restriction |
|
| 134 | + * and ensure that we still run ee term taxonomy descriptions |
|
| 135 | + * through some full html sanitization equivalent to the post content field. |
|
| 136 | + * So first we remove default filter for term description |
|
| 137 | + * but we have to do this earlier before wp sets their own filter |
|
| 138 | + * because they just set a global filter on all term descriptions |
|
| 139 | + * before the custom term description filter. |
|
| 140 | + * Really sux. |
|
| 141 | + * |
|
| 142 | + * @param string $description The description content. |
|
| 143 | + * @param string $taxonomy The taxonomy name for the taxonomy being filtered. |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + public function filterCustomTermDescription(string $description, string $taxonomy): string |
|
| 147 | + { |
|
| 148 | + // get a list of EE taxonomies |
|
| 149 | + $custom_taxonomies = $this->getCustomTaxonomySlugs(); |
|
| 150 | + // only do our own thing if the taxonomy listed is an ee taxonomy. |
|
| 151 | + if (in_array($taxonomy, $custom_taxonomies, true)) { |
|
| 152 | + // remove default wp filter |
|
| 153 | + remove_filter('pre_term_description', 'wp_filter_kses'); |
|
| 154 | + // sanitize THIS content. |
|
| 155 | + $description = wp_kses($description, wp_kses_allowed_html('post')); |
|
| 156 | + } |
|
| 157 | + return $description; |
|
| 158 | + } |
|
| 159 | 159 | } |
@@ -19,98 +19,98 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class SessionLifespan |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * how long an EE session lasts in seconds |
|
| 24 | - * default session lifespan of 1 hour (for not so instant IPNs) |
|
| 25 | - * |
|
| 26 | - * @var int $lifespan |
|
| 27 | - */ |
|
| 28 | - private $lifespan; |
|
| 22 | + /** |
|
| 23 | + * how long an EE session lasts in seconds |
|
| 24 | + * default session lifespan of 1 hour (for not so instant IPNs) |
|
| 25 | + * |
|
| 26 | + * @var int $lifespan |
|
| 27 | + */ |
|
| 28 | + private $lifespan; |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * SessionLifespan constructor. |
|
| 33 | - * |
|
| 34 | - * @param int $lifespan |
|
| 35 | - * @throws DomainException |
|
| 36 | - */ |
|
| 37 | - public function __construct(int $lifespan = 0) |
|
| 38 | - { |
|
| 39 | - $lifespan = absint($lifespan); |
|
| 40 | - $lifespan = $lifespan > 0 ? $lifespan : (int) HOUR_IN_SECONDS; |
|
| 41 | - $this->setLifespan($lifespan); |
|
| 42 | - } |
|
| 31 | + /** |
|
| 32 | + * SessionLifespan constructor. |
|
| 33 | + * |
|
| 34 | + * @param int $lifespan |
|
| 35 | + * @throws DomainException |
|
| 36 | + */ |
|
| 37 | + public function __construct(int $lifespan = 0) |
|
| 38 | + { |
|
| 39 | + $lifespan = absint($lifespan); |
|
| 40 | + $lifespan = $lifespan > 0 ? $lifespan : (int) HOUR_IN_SECONDS; |
|
| 41 | + $this->setLifespan($lifespan); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param int $lifespan |
|
| 47 | - * @throws DomainException |
|
| 48 | - */ |
|
| 49 | - protected function setLifespan(int $lifespan) |
|
| 50 | - { |
|
| 51 | - if ($lifespan < 60) { |
|
| 52 | - throw new DomainException( |
|
| 53 | - esc_html__( |
|
| 54 | - 'The session lifespan needs to be at least 60 seconds, and even that is extremely short', |
|
| 55 | - 'event_espresso' |
|
| 56 | - ) |
|
| 57 | - ); |
|
| 58 | - } |
|
| 59 | - $this->lifespan = apply_filters( |
|
| 60 | - 'FHEE__EventEspresso_core_domain_values_session_SessionLifespan__setLifespan___lifespan', |
|
| 61 | - // apply legacy filter for now but add doing it wrong notice in future |
|
| 62 | - apply_filters( |
|
| 63 | - 'FHEE__EE_Session__construct___lifespan', |
|
| 64 | - $lifespan |
|
| 65 | - ) |
|
| 66 | - ) + 1; |
|
| 67 | - } |
|
| 45 | + /** |
|
| 46 | + * @param int $lifespan |
|
| 47 | + * @throws DomainException |
|
| 48 | + */ |
|
| 49 | + protected function setLifespan(int $lifespan) |
|
| 50 | + { |
|
| 51 | + if ($lifespan < 60) { |
|
| 52 | + throw new DomainException( |
|
| 53 | + esc_html__( |
|
| 54 | + 'The session lifespan needs to be at least 60 seconds, and even that is extremely short', |
|
| 55 | + 'event_espresso' |
|
| 56 | + ) |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | + $this->lifespan = apply_filters( |
|
| 60 | + 'FHEE__EventEspresso_core_domain_values_session_SessionLifespan__setLifespan___lifespan', |
|
| 61 | + // apply legacy filter for now but add doing it wrong notice in future |
|
| 62 | + apply_filters( |
|
| 63 | + 'FHEE__EE_Session__construct___lifespan', |
|
| 64 | + $lifespan |
|
| 65 | + ) |
|
| 66 | + ) + 1; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @return int |
|
| 72 | - */ |
|
| 73 | - public function inSeconds(): int |
|
| 74 | - { |
|
| 75 | - return $this->lifespan; |
|
| 76 | - } |
|
| 70 | + /** |
|
| 71 | + * @return int |
|
| 72 | + */ |
|
| 73 | + public function inSeconds(): int |
|
| 74 | + { |
|
| 75 | + return $this->lifespan; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @param string $separator |
|
| 81 | - * @return string |
|
| 82 | - */ |
|
| 83 | - public function inHoursMinutesSeconds(string $separator = ':'): string |
|
| 84 | - { |
|
| 85 | - return sprintf( |
|
| 86 | - '%02d%s%02d%s%02d', |
|
| 87 | - floor($this->lifespan / 3600), |
|
| 88 | - $separator, |
|
| 89 | - ($this->lifespan / 60) % 60, |
|
| 90 | - $separator, |
|
| 91 | - $this->lifespan % 60 |
|
| 92 | - ); |
|
| 93 | - } |
|
| 79 | + /** |
|
| 80 | + * @param string $separator |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 83 | + public function inHoursMinutesSeconds(string $separator = ':'): string |
|
| 84 | + { |
|
| 85 | + return sprintf( |
|
| 86 | + '%02d%s%02d%s%02d', |
|
| 87 | + floor($this->lifespan / 3600), |
|
| 88 | + $separator, |
|
| 89 | + ($this->lifespan / 60) % 60, |
|
| 90 | + $separator, |
|
| 91 | + $this->lifespan % 60 |
|
| 92 | + ); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Returns a timestamp for when the session would expire based on this lifespan |
|
| 98 | - * |
|
| 99 | - * @param bool $utc If true, displays expiration in UTC |
|
| 100 | - * If false, displays expiration in local time |
|
| 101 | - * @return int |
|
| 102 | - */ |
|
| 103 | - public function expiration(bool $utc = true): int |
|
| 104 | - { |
|
| 105 | - return (int) current_time('timestamp', $utc) - $this->lifespan; |
|
| 106 | - } |
|
| 96 | + /** |
|
| 97 | + * Returns a timestamp for when the session would expire based on this lifespan |
|
| 98 | + * |
|
| 99 | + * @param bool $utc If true, displays expiration in UTC |
|
| 100 | + * If false, displays expiration in local time |
|
| 101 | + * @return int |
|
| 102 | + */ |
|
| 103 | + public function expiration(bool $utc = true): int |
|
| 104 | + { |
|
| 105 | + return (int) current_time('timestamp', $utc) - $this->lifespan; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function __toString(): string |
|
| 113 | - { |
|
| 114 | - return (string) $this->inSeconds(); |
|
| 115 | - } |
|
| 109 | + /** |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function __toString(): string |
|
| 113 | + { |
|
| 114 | + return (string) $this->inSeconds(); |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -12,133 +12,133 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class EEM_WP_User extends EEM_Base |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * private instance of the EEM_WP_User object |
|
| 17 | - * |
|
| 18 | - * @type EEM_WP_User |
|
| 19 | - */ |
|
| 20 | - protected static $_instance; |
|
| 15 | + /** |
|
| 16 | + * private instance of the EEM_WP_User object |
|
| 17 | + * |
|
| 18 | + * @type EEM_WP_User |
|
| 19 | + */ |
|
| 20 | + protected static $_instance; |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * constructor |
|
| 25 | - * |
|
| 26 | - * @param null $timezone |
|
| 27 | - * @param ModelFieldFactory $model_field_factory |
|
| 28 | - * @throws EE_Error |
|
| 29 | - * @throws InvalidArgumentException |
|
| 30 | - */ |
|
| 31 | - protected function __construct($timezone, ModelFieldFactory $model_field_factory) |
|
| 32 | - { |
|
| 33 | - $this->singular_item = esc_html__('WP_User', 'event_espresso'); |
|
| 34 | - $this->plural_item = esc_html__('WP_Users', 'event_espresso'); |
|
| 35 | - global $wpdb; |
|
| 36 | - $this->_tables = array( |
|
| 37 | - 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
| 38 | - ); |
|
| 39 | - $this->_fields = array( |
|
| 40 | - 'WP_User' => array( |
|
| 41 | - 'ID' => $model_field_factory->createPrimaryKeyIntField( |
|
| 42 | - 'ID', |
|
| 43 | - esc_html__('WP_User ID', 'event_espresso') |
|
| 44 | - ), |
|
| 45 | - 'user_login' => $model_field_factory->createPlainTextField( |
|
| 46 | - 'user_login', |
|
| 47 | - esc_html__('User Login', 'event_espresso'), |
|
| 48 | - false |
|
| 49 | - ), |
|
| 50 | - 'user_pass' => $model_field_factory->createPlainTextField( |
|
| 51 | - 'user_pass', |
|
| 52 | - esc_html__('User Password', 'event_espresso'), |
|
| 53 | - false |
|
| 54 | - ), |
|
| 55 | - 'user_nicename' => $model_field_factory->createPlainTextField( |
|
| 56 | - 'user_nicename', |
|
| 57 | - esc_html__(' User Nice Name', 'event_espresso'), |
|
| 58 | - false |
|
| 59 | - ), |
|
| 60 | - 'user_email' => $model_field_factory->createEmailField( |
|
| 61 | - 'user_email', |
|
| 62 | - esc_html__('User Email', 'event_espresso'), |
|
| 63 | - false |
|
| 64 | - ), |
|
| 65 | - 'user_registered' => $model_field_factory->createDatetimeField( |
|
| 66 | - 'user_registered', |
|
| 67 | - esc_html__('Date User Registered', 'event_espresso'), |
|
| 68 | - $timezone, |
|
| 69 | - false |
|
| 70 | - ), |
|
| 71 | - 'user_activation_key' => $model_field_factory->createPlainTextField( |
|
| 72 | - 'user_activation_key', |
|
| 73 | - esc_html__('User Activation Key', 'event_espresso'), |
|
| 74 | - false |
|
| 75 | - ), |
|
| 76 | - 'user_status' => $model_field_factory->createIntegerField( |
|
| 77 | - 'user_status', |
|
| 78 | - esc_html__('User Status', 'event_espresso') |
|
| 79 | - ), |
|
| 80 | - 'display_name' => $model_field_factory->createPlainTextField( |
|
| 81 | - 'display_name', |
|
| 82 | - esc_html__('Display Name', 'event_espresso'), |
|
| 83 | - false |
|
| 84 | - ), |
|
| 85 | - ), |
|
| 86 | - ); |
|
| 87 | - $this->_model_relations = array( |
|
| 88 | - 'Attendee' => new EE_Has_Many_Relation(), |
|
| 89 | - // all models are related to the change log |
|
| 90 | - // 'Change_Log' => new EE_Has_Many_Relation(), |
|
| 91 | - 'Event' => new EE_Has_Many_Relation(), |
|
| 92 | - 'Message' => new EE_Has_Many_Relation(), |
|
| 93 | - 'Payment_Method' => new EE_Has_Many_Relation(), |
|
| 94 | - 'Price' => new EE_Has_Many_Relation(), |
|
| 95 | - 'Price_Type' => new EE_Has_Many_Relation(), |
|
| 96 | - 'Question' => new EE_Has_Many_Relation(), |
|
| 97 | - 'Question_Group' => new EE_Has_Many_Relation(), |
|
| 98 | - 'Ticket' => new EE_Has_Many_Relation(), |
|
| 99 | - 'Venue' => new EE_Has_Many_Relation(), |
|
| 100 | - ); |
|
| 101 | - $this->foreign_key_aliases = [ |
|
| 102 | - 'Event.EVT_wp_user' => 'WP_User.ID', |
|
| 103 | - 'Payment_Method.PMD_wp_user' => 'WP_User.ID', |
|
| 104 | - 'Price.PRC_wp_user' => 'WP_User.ID', |
|
| 105 | - 'Price_Type.PRT_wp_user' => 'WP_User.ID', |
|
| 106 | - 'Question.QST_wp_user' => 'WP_User.ID', |
|
| 107 | - 'Question_Group.QSG_wp_user' => 'WP_User.ID', |
|
| 108 | - 'Ticket.VNU_wp_user' => 'WP_User.ID', |
|
| 109 | - 'Venue.TKT_wp_user' => 'WP_User.ID', |
|
| 110 | - ]; |
|
| 111 | - $this->_wp_core_model = true; |
|
| 112 | - $this->_caps_slug = 'users'; |
|
| 113 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
| 114 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
| 115 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
| 116 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
| 117 | - } |
|
| 118 | - // @todo: account for create_users controls whether they can create users at all |
|
| 119 | - parent::__construct($timezone); |
|
| 120 | - } |
|
| 23 | + /** |
|
| 24 | + * constructor |
|
| 25 | + * |
|
| 26 | + * @param null $timezone |
|
| 27 | + * @param ModelFieldFactory $model_field_factory |
|
| 28 | + * @throws EE_Error |
|
| 29 | + * @throws InvalidArgumentException |
|
| 30 | + */ |
|
| 31 | + protected function __construct($timezone, ModelFieldFactory $model_field_factory) |
|
| 32 | + { |
|
| 33 | + $this->singular_item = esc_html__('WP_User', 'event_espresso'); |
|
| 34 | + $this->plural_item = esc_html__('WP_Users', 'event_espresso'); |
|
| 35 | + global $wpdb; |
|
| 36 | + $this->_tables = array( |
|
| 37 | + 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
| 38 | + ); |
|
| 39 | + $this->_fields = array( |
|
| 40 | + 'WP_User' => array( |
|
| 41 | + 'ID' => $model_field_factory->createPrimaryKeyIntField( |
|
| 42 | + 'ID', |
|
| 43 | + esc_html__('WP_User ID', 'event_espresso') |
|
| 44 | + ), |
|
| 45 | + 'user_login' => $model_field_factory->createPlainTextField( |
|
| 46 | + 'user_login', |
|
| 47 | + esc_html__('User Login', 'event_espresso'), |
|
| 48 | + false |
|
| 49 | + ), |
|
| 50 | + 'user_pass' => $model_field_factory->createPlainTextField( |
|
| 51 | + 'user_pass', |
|
| 52 | + esc_html__('User Password', 'event_espresso'), |
|
| 53 | + false |
|
| 54 | + ), |
|
| 55 | + 'user_nicename' => $model_field_factory->createPlainTextField( |
|
| 56 | + 'user_nicename', |
|
| 57 | + esc_html__(' User Nice Name', 'event_espresso'), |
|
| 58 | + false |
|
| 59 | + ), |
|
| 60 | + 'user_email' => $model_field_factory->createEmailField( |
|
| 61 | + 'user_email', |
|
| 62 | + esc_html__('User Email', 'event_espresso'), |
|
| 63 | + false |
|
| 64 | + ), |
|
| 65 | + 'user_registered' => $model_field_factory->createDatetimeField( |
|
| 66 | + 'user_registered', |
|
| 67 | + esc_html__('Date User Registered', 'event_espresso'), |
|
| 68 | + $timezone, |
|
| 69 | + false |
|
| 70 | + ), |
|
| 71 | + 'user_activation_key' => $model_field_factory->createPlainTextField( |
|
| 72 | + 'user_activation_key', |
|
| 73 | + esc_html__('User Activation Key', 'event_espresso'), |
|
| 74 | + false |
|
| 75 | + ), |
|
| 76 | + 'user_status' => $model_field_factory->createIntegerField( |
|
| 77 | + 'user_status', |
|
| 78 | + esc_html__('User Status', 'event_espresso') |
|
| 79 | + ), |
|
| 80 | + 'display_name' => $model_field_factory->createPlainTextField( |
|
| 81 | + 'display_name', |
|
| 82 | + esc_html__('Display Name', 'event_espresso'), |
|
| 83 | + false |
|
| 84 | + ), |
|
| 85 | + ), |
|
| 86 | + ); |
|
| 87 | + $this->_model_relations = array( |
|
| 88 | + 'Attendee' => new EE_Has_Many_Relation(), |
|
| 89 | + // all models are related to the change log |
|
| 90 | + // 'Change_Log' => new EE_Has_Many_Relation(), |
|
| 91 | + 'Event' => new EE_Has_Many_Relation(), |
|
| 92 | + 'Message' => new EE_Has_Many_Relation(), |
|
| 93 | + 'Payment_Method' => new EE_Has_Many_Relation(), |
|
| 94 | + 'Price' => new EE_Has_Many_Relation(), |
|
| 95 | + 'Price_Type' => new EE_Has_Many_Relation(), |
|
| 96 | + 'Question' => new EE_Has_Many_Relation(), |
|
| 97 | + 'Question_Group' => new EE_Has_Many_Relation(), |
|
| 98 | + 'Ticket' => new EE_Has_Many_Relation(), |
|
| 99 | + 'Venue' => new EE_Has_Many_Relation(), |
|
| 100 | + ); |
|
| 101 | + $this->foreign_key_aliases = [ |
|
| 102 | + 'Event.EVT_wp_user' => 'WP_User.ID', |
|
| 103 | + 'Payment_Method.PMD_wp_user' => 'WP_User.ID', |
|
| 104 | + 'Price.PRC_wp_user' => 'WP_User.ID', |
|
| 105 | + 'Price_Type.PRT_wp_user' => 'WP_User.ID', |
|
| 106 | + 'Question.QST_wp_user' => 'WP_User.ID', |
|
| 107 | + 'Question_Group.QSG_wp_user' => 'WP_User.ID', |
|
| 108 | + 'Ticket.VNU_wp_user' => 'WP_User.ID', |
|
| 109 | + 'Venue.TKT_wp_user' => 'WP_User.ID', |
|
| 110 | + ]; |
|
| 111 | + $this->_wp_core_model = true; |
|
| 112 | + $this->_caps_slug = 'users'; |
|
| 113 | + $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
| 114 | + $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
| 115 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
| 116 | + $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
| 117 | + } |
|
| 118 | + // @todo: account for create_users controls whether they can create users at all |
|
| 119 | + parent::__construct($timezone); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * We don't need a foreign key to the WP_User model, we just need its primary key |
|
| 125 | - * |
|
| 126 | - * @return string |
|
| 127 | - * @throws EE_Error |
|
| 128 | - */ |
|
| 129 | - public function wp_user_field_name(): string |
|
| 130 | - { |
|
| 131 | - return $this->primary_key_name(); |
|
| 132 | - } |
|
| 123 | + /** |
|
| 124 | + * We don't need a foreign key to the WP_User model, we just need its primary key |
|
| 125 | + * |
|
| 126 | + * @return string |
|
| 127 | + * @throws EE_Error |
|
| 128 | + */ |
|
| 129 | + public function wp_user_field_name(): string |
|
| 130 | + { |
|
| 131 | + return $this->primary_key_name(); |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
| 137 | - * |
|
| 138 | - * @return boolean |
|
| 139 | - */ |
|
| 140 | - public function is_owned(): bool |
|
| 141 | - { |
|
| 142 | - return true; |
|
| 143 | - } |
|
| 135 | + /** |
|
| 136 | + * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
| 137 | + * |
|
| 138 | + * @return boolean |
|
| 139 | + */ |
|
| 140 | + public function is_owned(): bool |
|
| 141 | + { |
|
| 142 | + return true; |
|
| 143 | + } |
|
| 144 | 144 | } |