@@ -11,230 +11,230 @@ |
||
| 11 | 11 | |
| 12 | 12 | class CssToInlineStyles |
| 13 | 13 | { |
| 14 | - private $cssConverter; |
|
| 15 | - |
|
| 16 | - public function __construct() |
|
| 17 | - { |
|
| 18 | - if (class_exists('Symfony\Component\CssSelector\CssSelectorConverter')) { |
|
| 19 | - $this->cssConverter = new CssSelectorConverter(); |
|
| 20 | - } |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Will inline the $css into the given $html |
|
| 25 | - * |
|
| 26 | - * Remark: if the html contains <style>-tags those will be used, the rules |
|
| 27 | - * in $css will be appended. |
|
| 28 | - * |
|
| 29 | - * @param string $html |
|
| 30 | - * @param string $css |
|
| 31 | - * |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public function convert($html, $css = null) |
|
| 35 | - { |
|
| 36 | - $document = $this->createDomDocumentFromHtml($html); |
|
| 37 | - $processor = new Processor(); |
|
| 38 | - |
|
| 39 | - // get all styles from the style-tags |
|
| 40 | - $rules = $processor->getRules( |
|
| 41 | - $processor->getCssFromStyleTags($html) |
|
| 42 | - ); |
|
| 43 | - |
|
| 44 | - if ($css !== null) { |
|
| 45 | - $rules = $processor->getRules($css, $rules); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - $document = $this->inline($document, $rules); |
|
| 49 | - |
|
| 50 | - return $this->getHtmlFromDocument($document); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Inline the given properties on an given DOMElement |
|
| 55 | - * |
|
| 56 | - * @param \DOMElement $element |
|
| 57 | - * @param Css\Property\Property[] $properties |
|
| 58 | - * |
|
| 59 | - * @return \DOMElement |
|
| 60 | - */ |
|
| 61 | - public function inlineCssOnElement(\DOMElement $element, array $properties) |
|
| 62 | - { |
|
| 63 | - if (empty($properties)) { |
|
| 64 | - return $element; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - $cssProperties = array(); |
|
| 68 | - $inlineProperties = array(); |
|
| 69 | - |
|
| 70 | - foreach ($this->getInlineStyles($element) as $property) { |
|
| 71 | - $inlineProperties[$property->getName()] = $property; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - foreach ($properties as $property) { |
|
| 75 | - if (!isset($inlineProperties[$property->getName()])) { |
|
| 76 | - $cssProperties[$property->getName()] = $property; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $rules = array(); |
|
| 81 | - foreach (array_merge($cssProperties, $inlineProperties) as $property) { |
|
| 82 | - $rules[] = $property->toString(); |
|
| 83 | - } |
|
| 84 | - $element->setAttribute('style', implode(' ', $rules)); |
|
| 85 | - |
|
| 86 | - return $element; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Get the current inline styles for a given DOMElement |
|
| 91 | - * |
|
| 92 | - * @param \DOMElement $element |
|
| 93 | - * |
|
| 94 | - * @return Css\Property\Property[] |
|
| 95 | - */ |
|
| 96 | - public function getInlineStyles(\DOMElement $element) |
|
| 97 | - { |
|
| 98 | - $processor = new PropertyProcessor(); |
|
| 99 | - |
|
| 100 | - return $processor->convertArrayToObjects( |
|
| 101 | - $processor->splitIntoSeparateProperties( |
|
| 102 | - $element->getAttribute('style') |
|
| 103 | - ) |
|
| 104 | - ); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param string $html |
|
| 109 | - * |
|
| 110 | - * @return \DOMDocument |
|
| 111 | - */ |
|
| 112 | - protected function createDomDocumentFromHtml($html) |
|
| 113 | - { |
|
| 114 | - $document = new \DOMDocument('1.0', 'UTF-8'); |
|
| 115 | - $internalErrors = libxml_use_internal_errors(true); |
|
| 116 | - $document->loadHTML(mb_encode_numericentity($html, [0x80, 0xFFFF, 0, 0xFFFF], 'UTF-8')); |
|
| 117 | - libxml_use_internal_errors($internalErrors); |
|
| 118 | - $document->formatOutput = true; |
|
| 119 | - |
|
| 120 | - return $document; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @param \DOMDocument $document |
|
| 125 | - * |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - protected function getHtmlFromDocument(\DOMDocument $document) |
|
| 129 | - { |
|
| 130 | - // retrieve the document element |
|
| 131 | - // we do it this way to preserve the utf-8 encoding |
|
| 132 | - $htmlElement = $document->documentElement; |
|
| 133 | - $html = $document->saveHTML($htmlElement); |
|
| 134 | - $html = trim($html); |
|
| 135 | - |
|
| 136 | - // retrieve the doctype |
|
| 137 | - $document->removeChild($htmlElement); |
|
| 138 | - $doctype = $document->saveHTML(); |
|
| 139 | - $doctype = trim($doctype); |
|
| 140 | - |
|
| 141 | - // if it is the html5 doctype convert it to lowercase |
|
| 142 | - if ($doctype === '<!DOCTYPE html>') { |
|
| 143 | - $doctype = strtolower($doctype); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $doctype."\n".$html; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param \DOMDocument $document |
|
| 151 | - * @param Css\Rule\Rule[] $rules |
|
| 152 | - * |
|
| 153 | - * @return \DOMDocument |
|
| 154 | - */ |
|
| 155 | - protected function inline(\DOMDocument $document, array $rules) |
|
| 156 | - { |
|
| 157 | - if (empty($rules)) { |
|
| 158 | - return $document; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $propertyStorage = new \SplObjectStorage(); |
|
| 162 | - |
|
| 163 | - $xPath = new \DOMXPath($document); |
|
| 164 | - |
|
| 165 | - usort($rules, array(RuleProcessor::class, 'sortOnSpecificity')); |
|
| 166 | - |
|
| 167 | - foreach ($rules as $rule) { |
|
| 168 | - try { |
|
| 169 | - if (null !== $this->cssConverter) { |
|
| 170 | - $expression = $this->cssConverter->toXPath($rule->getSelector()); |
|
| 171 | - } else { |
|
| 172 | - // Compatibility layer for Symfony 2.7 and older |
|
| 173 | - $expression = CssSelector::toXPath($rule->getSelector()); |
|
| 174 | - } |
|
| 175 | - } catch (ExceptionInterface $e) { |
|
| 176 | - continue; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $elements = $xPath->query($expression); |
|
| 180 | - |
|
| 181 | - if ($elements === false) { |
|
| 182 | - continue; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - foreach ($elements as $element) { |
|
| 186 | - $propertyStorage[$element] = $this->calculatePropertiesToBeApplied( |
|
| 187 | - $rule->getProperties(), |
|
| 188 | - $propertyStorage->contains($element) ? $propertyStorage[$element] : array() |
|
| 189 | - ); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - foreach ($propertyStorage as $element) { |
|
| 194 | - $this->inlineCssOnElement($element, $propertyStorage[$element]); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $document; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Merge the CSS rules to determine the applied properties. |
|
| 202 | - * |
|
| 203 | - * @param Css\Property\Property[] $properties |
|
| 204 | - * @param Css\Property\Property[] $cssProperties existing applied properties indexed by name |
|
| 205 | - * |
|
| 206 | - * @return Css\Property\Property[] updated properties, indexed by name |
|
| 207 | - */ |
|
| 208 | - private function calculatePropertiesToBeApplied(array $properties, array $cssProperties) |
|
| 209 | - { |
|
| 210 | - if (empty($properties)) { |
|
| 211 | - return $cssProperties; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - foreach ($properties as $property) { |
|
| 215 | - if (isset($cssProperties[$property->getName()])) { |
|
| 216 | - $existingProperty = $cssProperties[$property->getName()]; |
|
| 217 | - |
|
| 218 | - //skip check to overrule if existing property is important and current is not |
|
| 219 | - if ($existingProperty->isImportant() && !$property->isImportant()) { |
|
| 220 | - continue; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - //overrule if current property is important and existing is not, else check specificity |
|
| 224 | - $overrule = !$existingProperty->isImportant() && $property->isImportant(); |
|
| 225 | - if (!$overrule) { |
|
| 226 | - $overrule = $existingProperty->getOriginalSpecificity()->compareTo($property->getOriginalSpecificity()) <= 0; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - if ($overrule) { |
|
| 230 | - unset($cssProperties[$property->getName()]); |
|
| 231 | - $cssProperties[$property->getName()] = $property; |
|
| 232 | - } |
|
| 233 | - } else { |
|
| 234 | - $cssProperties[$property->getName()] = $property; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - return $cssProperties; |
|
| 239 | - } |
|
| 14 | + private $cssConverter; |
|
| 15 | + |
|
| 16 | + public function __construct() |
|
| 17 | + { |
|
| 18 | + if (class_exists('Symfony\Component\CssSelector\CssSelectorConverter')) { |
|
| 19 | + $this->cssConverter = new CssSelectorConverter(); |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Will inline the $css into the given $html |
|
| 25 | + * |
|
| 26 | + * Remark: if the html contains <style>-tags those will be used, the rules |
|
| 27 | + * in $css will be appended. |
|
| 28 | + * |
|
| 29 | + * @param string $html |
|
| 30 | + * @param string $css |
|
| 31 | + * |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public function convert($html, $css = null) |
|
| 35 | + { |
|
| 36 | + $document = $this->createDomDocumentFromHtml($html); |
|
| 37 | + $processor = new Processor(); |
|
| 38 | + |
|
| 39 | + // get all styles from the style-tags |
|
| 40 | + $rules = $processor->getRules( |
|
| 41 | + $processor->getCssFromStyleTags($html) |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + if ($css !== null) { |
|
| 45 | + $rules = $processor->getRules($css, $rules); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + $document = $this->inline($document, $rules); |
|
| 49 | + |
|
| 50 | + return $this->getHtmlFromDocument($document); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Inline the given properties on an given DOMElement |
|
| 55 | + * |
|
| 56 | + * @param \DOMElement $element |
|
| 57 | + * @param Css\Property\Property[] $properties |
|
| 58 | + * |
|
| 59 | + * @return \DOMElement |
|
| 60 | + */ |
|
| 61 | + public function inlineCssOnElement(\DOMElement $element, array $properties) |
|
| 62 | + { |
|
| 63 | + if (empty($properties)) { |
|
| 64 | + return $element; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + $cssProperties = array(); |
|
| 68 | + $inlineProperties = array(); |
|
| 69 | + |
|
| 70 | + foreach ($this->getInlineStyles($element) as $property) { |
|
| 71 | + $inlineProperties[$property->getName()] = $property; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + foreach ($properties as $property) { |
|
| 75 | + if (!isset($inlineProperties[$property->getName()])) { |
|
| 76 | + $cssProperties[$property->getName()] = $property; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $rules = array(); |
|
| 81 | + foreach (array_merge($cssProperties, $inlineProperties) as $property) { |
|
| 82 | + $rules[] = $property->toString(); |
|
| 83 | + } |
|
| 84 | + $element->setAttribute('style', implode(' ', $rules)); |
|
| 85 | + |
|
| 86 | + return $element; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Get the current inline styles for a given DOMElement |
|
| 91 | + * |
|
| 92 | + * @param \DOMElement $element |
|
| 93 | + * |
|
| 94 | + * @return Css\Property\Property[] |
|
| 95 | + */ |
|
| 96 | + public function getInlineStyles(\DOMElement $element) |
|
| 97 | + { |
|
| 98 | + $processor = new PropertyProcessor(); |
|
| 99 | + |
|
| 100 | + return $processor->convertArrayToObjects( |
|
| 101 | + $processor->splitIntoSeparateProperties( |
|
| 102 | + $element->getAttribute('style') |
|
| 103 | + ) |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param string $html |
|
| 109 | + * |
|
| 110 | + * @return \DOMDocument |
|
| 111 | + */ |
|
| 112 | + protected function createDomDocumentFromHtml($html) |
|
| 113 | + { |
|
| 114 | + $document = new \DOMDocument('1.0', 'UTF-8'); |
|
| 115 | + $internalErrors = libxml_use_internal_errors(true); |
|
| 116 | + $document->loadHTML(mb_encode_numericentity($html, [0x80, 0xFFFF, 0, 0xFFFF], 'UTF-8')); |
|
| 117 | + libxml_use_internal_errors($internalErrors); |
|
| 118 | + $document->formatOutput = true; |
|
| 119 | + |
|
| 120 | + return $document; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @param \DOMDocument $document |
|
| 125 | + * |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + protected function getHtmlFromDocument(\DOMDocument $document) |
|
| 129 | + { |
|
| 130 | + // retrieve the document element |
|
| 131 | + // we do it this way to preserve the utf-8 encoding |
|
| 132 | + $htmlElement = $document->documentElement; |
|
| 133 | + $html = $document->saveHTML($htmlElement); |
|
| 134 | + $html = trim($html); |
|
| 135 | + |
|
| 136 | + // retrieve the doctype |
|
| 137 | + $document->removeChild($htmlElement); |
|
| 138 | + $doctype = $document->saveHTML(); |
|
| 139 | + $doctype = trim($doctype); |
|
| 140 | + |
|
| 141 | + // if it is the html5 doctype convert it to lowercase |
|
| 142 | + if ($doctype === '<!DOCTYPE html>') { |
|
| 143 | + $doctype = strtolower($doctype); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $doctype."\n".$html; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param \DOMDocument $document |
|
| 151 | + * @param Css\Rule\Rule[] $rules |
|
| 152 | + * |
|
| 153 | + * @return \DOMDocument |
|
| 154 | + */ |
|
| 155 | + protected function inline(\DOMDocument $document, array $rules) |
|
| 156 | + { |
|
| 157 | + if (empty($rules)) { |
|
| 158 | + return $document; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $propertyStorage = new \SplObjectStorage(); |
|
| 162 | + |
|
| 163 | + $xPath = new \DOMXPath($document); |
|
| 164 | + |
|
| 165 | + usort($rules, array(RuleProcessor::class, 'sortOnSpecificity')); |
|
| 166 | + |
|
| 167 | + foreach ($rules as $rule) { |
|
| 168 | + try { |
|
| 169 | + if (null !== $this->cssConverter) { |
|
| 170 | + $expression = $this->cssConverter->toXPath($rule->getSelector()); |
|
| 171 | + } else { |
|
| 172 | + // Compatibility layer for Symfony 2.7 and older |
|
| 173 | + $expression = CssSelector::toXPath($rule->getSelector()); |
|
| 174 | + } |
|
| 175 | + } catch (ExceptionInterface $e) { |
|
| 176 | + continue; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $elements = $xPath->query($expression); |
|
| 180 | + |
|
| 181 | + if ($elements === false) { |
|
| 182 | + continue; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + foreach ($elements as $element) { |
|
| 186 | + $propertyStorage[$element] = $this->calculatePropertiesToBeApplied( |
|
| 187 | + $rule->getProperties(), |
|
| 188 | + $propertyStorage->contains($element) ? $propertyStorage[$element] : array() |
|
| 189 | + ); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + foreach ($propertyStorage as $element) { |
|
| 194 | + $this->inlineCssOnElement($element, $propertyStorage[$element]); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $document; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Merge the CSS rules to determine the applied properties. |
|
| 202 | + * |
|
| 203 | + * @param Css\Property\Property[] $properties |
|
| 204 | + * @param Css\Property\Property[] $cssProperties existing applied properties indexed by name |
|
| 205 | + * |
|
| 206 | + * @return Css\Property\Property[] updated properties, indexed by name |
|
| 207 | + */ |
|
| 208 | + private function calculatePropertiesToBeApplied(array $properties, array $cssProperties) |
|
| 209 | + { |
|
| 210 | + if (empty($properties)) { |
|
| 211 | + return $cssProperties; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + foreach ($properties as $property) { |
|
| 215 | + if (isset($cssProperties[$property->getName()])) { |
|
| 216 | + $existingProperty = $cssProperties[$property->getName()]; |
|
| 217 | + |
|
| 218 | + //skip check to overrule if existing property is important and current is not |
|
| 219 | + if ($existingProperty->isImportant() && !$property->isImportant()) { |
|
| 220 | + continue; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + //overrule if current property is important and existing is not, else check specificity |
|
| 224 | + $overrule = !$existingProperty->isImportant() && $property->isImportant(); |
|
| 225 | + if (!$overrule) { |
|
| 226 | + $overrule = $existingProperty->getOriginalSpecificity()->compareTo($property->getOriginalSpecificity()) <= 0; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if ($overrule) { |
|
| 230 | + unset($cssProperties[$property->getName()]); |
|
| 231 | + $cssProperties[$property->getName()] = $property; |
|
| 232 | + } |
|
| 233 | + } else { |
|
| 234 | + $cssProperties[$property->getName()] = $property; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + return $cssProperties; |
|
| 239 | + } |
|
| 240 | 240 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | protected function loadPaymentMethods() |
| 60 | 60 | { |
| 61 | 61 | // Scan the PaymentMethods folder. |
| 62 | - $pms_list = glob(EE_PLUGIN_DIR_PATH . 'PaymentMethods/*', GLOB_ONLYDIR); |
|
| 62 | + $pms_list = glob(EE_PLUGIN_DIR_PATH.'PaymentMethods/*', GLOB_ONLYDIR); |
|
| 63 | 63 | // Filter the discovered PM list. |
| 64 | 64 | $pms_list = apply_filters('FHEE__PaymentMethods__Manager__loadPaymentMethods__pms_list', $pms_list); |
| 65 | 65 | // Clean from duplicates. |
@@ -85,19 +85,19 @@ discard block |
||
| 85 | 85 | ): bool { |
| 86 | 86 | do_action('AHEE__PaymentMethods__Manager__registerPaymentMethod__start', $pm_path); |
| 87 | 87 | // Separators should match. |
| 88 | - $pm_path = str_replace('/\\', '/', $pm_path) . DS; |
|
| 88 | + $pm_path = str_replace('/\\', '/', $pm_path).DS; |
|
| 89 | 89 | // Sanitize PM name. |
| 90 | 90 | $module_dir = basename($pm_path); |
| 91 | 91 | // Get class name. |
| 92 | 92 | $pm_class_name = str_replace(' ', '_', $module_dir); |
| 93 | 93 | // Check if file exists. |
| 94 | - if (! is_readable($pm_path . $pm_class_name . $file_ext)) { |
|
| 94 | + if ( ! is_readable($pm_path.$pm_class_name.$file_ext)) { |
|
| 95 | 95 | return false; |
| 96 | 96 | } |
| 97 | 97 | // Load the initial PM class. |
| 98 | - require_once($pm_path . DS . $pm_class_name . $file_ext); |
|
| 98 | + require_once($pm_path.DS.$pm_class_name.$file_ext); |
|
| 99 | 99 | $pm_object = "$pm_namespace\\$pm_class_name"; |
| 100 | - if (! class_exists($pm_object)) { |
|
| 100 | + if ( ! class_exists($pm_object)) { |
|
| 101 | 101 | return false; |
| 102 | 102 | } |
| 103 | 103 | new $pm_object(); |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | { |
| 118 | 118 | foreach (self::$pms_can_hide as $pm_name => $pm_option) { |
| 119 | 119 | // Can we deregister this PM ? |
| 120 | - if (isset($pms_to_list[ $pm_name ]) && self::pmCanBeHidden($pm_name, $pm_option)) { |
|
| 121 | - unset($pms_to_list[ $pm_name ]); |
|
| 120 | + if (isset($pms_to_list[$pm_name]) && self::pmCanBeHidden($pm_name, $pm_option)) { |
|
| 121 | + unset($pms_to_list[$pm_name]); |
|
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | return $pms_to_list; |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
| 170 | 170 | $page_name = $request->getRequestParam('page'); |
| 171 | 171 | // Only show the notice on core EE pages |
| 172 | - if (! str_contains($page_name, 'espresso')) { |
|
| 172 | + if ( ! str_contains($page_name, 'espresso')) { |
|
| 173 | 173 | return; |
| 174 | 174 | } |
| 175 | 175 | // Notice if one of the following payment methods is used: PayPal Express, PayPal Pro, Authorize.net AIM. |
@@ -21,197 +21,197 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Manager |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * List of PMs that can be replaced with PP Commerce. |
|
| 26 | - * ['payment method name' => 'settings option'] |
|
| 27 | - * |
|
| 28 | - * @var array $pms_can_hide |
|
| 29 | - */ |
|
| 30 | - protected static array $pms_can_hide = [ |
|
| 31 | - 'paypal_express' => 'api_username', |
|
| 32 | - 'paypal_pro' => 'api_username', |
|
| 33 | - 'aim' => 'login_id', |
|
| 34 | - ]; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Manager constructor. |
|
| 39 | - */ |
|
| 40 | - public function __construct() |
|
| 41 | - { |
|
| 42 | - if (DbStatus::isOffline()) { |
|
| 43 | - return; |
|
| 44 | - } |
|
| 45 | - $this->loadPaymentMethods(); |
|
| 46 | - if (is_admin()) { |
|
| 47 | - // Use only PayPal Commerce if it's a new setup. |
|
| 48 | - add_filter( |
|
| 49 | - 'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
|
| 50 | - [__CLASS__, 'hidePaymentMethods'] |
|
| 51 | - ); |
|
| 52 | - // Payment methods related admin notices. |
|
| 53 | - add_action('admin_init', [__CLASS__, 'adminNotice']); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Load all payment methods that are in PaymentMethods folder. |
|
| 60 | - * |
|
| 61 | - * @return void |
|
| 62 | - */ |
|
| 63 | - protected function loadPaymentMethods() |
|
| 64 | - { |
|
| 65 | - // Scan the PaymentMethods folder. |
|
| 66 | - $pms_list = glob(EE_PLUGIN_DIR_PATH . 'PaymentMethods/*', GLOB_ONLYDIR); |
|
| 67 | - // Filter the discovered PM list. |
|
| 68 | - $pms_list = apply_filters('FHEE__PaymentMethods__Manager__loadPaymentMethods__pms_list', $pms_list); |
|
| 69 | - // Clean from duplicates. |
|
| 70 | - $pms_list = array_unique($pms_list); |
|
| 71 | - foreach ($pms_list as $pm_path) { |
|
| 72 | - $this->registerPaymentMethod($pm_path); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Looks for the main payment method file and loads it. |
|
| 79 | - * |
|
| 80 | - * @param string $pm_path path to the payment method folder |
|
| 81 | - * @param string $file_ext |
|
| 82 | - * @param string $pm_namespace |
|
| 83 | - * @return boolean |
|
| 84 | - */ |
|
| 85 | - public function registerPaymentMethod( |
|
| 86 | - string $pm_path, |
|
| 87 | - string $file_ext = '.php', |
|
| 88 | - string $pm_namespace = 'EventEspresso\PaymentMethods' |
|
| 89 | - ): bool { |
|
| 90 | - do_action('AHEE__PaymentMethods__Manager__registerPaymentMethod__start', $pm_path); |
|
| 91 | - // Separators should match. |
|
| 92 | - $pm_path = str_replace('/\\', '/', $pm_path) . DS; |
|
| 93 | - // Sanitize PM name. |
|
| 94 | - $module_dir = basename($pm_path); |
|
| 95 | - // Get class name. |
|
| 96 | - $pm_class_name = str_replace(' ', '_', $module_dir); |
|
| 97 | - // Check if file exists. |
|
| 98 | - if (! is_readable($pm_path . $pm_class_name . $file_ext)) { |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - // Load the initial PM class. |
|
| 102 | - require_once($pm_path . DS . $pm_class_name . $file_ext); |
|
| 103 | - $pm_object = "$pm_namespace\\$pm_class_name"; |
|
| 104 | - if (! class_exists($pm_object)) { |
|
| 105 | - return false; |
|
| 106 | - } |
|
| 107 | - new $pm_object(); |
|
| 108 | - return true; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Deactivate a few other PMs if it's a new setup. Use PP Commerce. |
|
| 114 | - * |
|
| 115 | - * @param array $pms_to_list |
|
| 116 | - * @return array |
|
| 117 | - * @throws EE_Error |
|
| 118 | - * @throws ReflectionException |
|
| 119 | - */ |
|
| 120 | - public static function hidePaymentMethods(array $pms_to_list): array |
|
| 121 | - { |
|
| 122 | - foreach (self::$pms_can_hide as $pm_name => $pm_option) { |
|
| 123 | - // Can we deregister this PM ? |
|
| 124 | - if (isset($pms_to_list[ $pm_name ]) && self::pmCanBeHidden($pm_name, $pm_option)) { |
|
| 125 | - unset($pms_to_list[ $pm_name ]); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - return $pms_to_list; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Deregisters the provided payment method if not used. |
|
| 134 | - * |
|
| 135 | - * @param string $pm_name |
|
| 136 | - * @param string $pm_option |
|
| 137 | - * @return bool |
|
| 138 | - * @throws EE_Error |
|
| 139 | - * @throws ReflectionException |
|
| 140 | - */ |
|
| 141 | - public static function pmCanBeHidden(string $pm_name, string $pm_option): bool |
|
| 142 | - { |
|
| 143 | - $pm_to_hide = EEM_Payment_Method::instance()->get_one_by_slug($pm_name); |
|
| 144 | - $pm_active = $pm_active_before = false; |
|
| 145 | - if ($pm_to_hide instanceof EE_Payment_Method) { |
|
| 146 | - $pm_active = $pm_to_hide->active(); |
|
| 147 | - // Payment method used before ? |
|
| 148 | - $option = $pm_to_hide->get_extra_meta($pm_option, true, false); |
|
| 149 | - $pm_active_before = ! empty($option); |
|
| 150 | - } |
|
| 151 | - // If PM not used before and not active, deregister it. |
|
| 152 | - if ( |
|
| 153 | - apply_filters( |
|
| 154 | - "FHEE__PaymentMethods__Manager__register_payment_methods__hide_$pm_name", |
|
| 155 | - ! $pm_active && ! $pm_active_before, |
|
| 156 | - $pm_name |
|
| 157 | - ) |
|
| 158 | - ) { |
|
| 159 | - return true; |
|
| 160 | - } |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Payment methods related admin notices. |
|
| 167 | - * |
|
| 168 | - * @return void |
|
| 169 | - */ |
|
| 170 | - public static function adminNotice() |
|
| 171 | - { |
|
| 172 | - // Is this an EE admin page ? |
|
| 173 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 174 | - $page_name = $request->getRequestParam('page'); |
|
| 175 | - // Only show the notice on core EE pages |
|
| 176 | - if (! str_contains($page_name, 'espresso')) { |
|
| 177 | - return; |
|
| 178 | - } |
|
| 179 | - // Notice if one of the following payment methods is used: PayPal Express, PayPal Pro, Authorize.net AIM. |
|
| 180 | - try { |
|
| 181 | - $pp_commerce = EEM_Payment_Method::instance()->get_one_by_slug('paypalcheckout'); |
|
| 182 | - // Don't show notice if PayPal Commerce is active. |
|
| 183 | - if ($pp_commerce instanceof EE_Payment_Method && $pp_commerce->active()) { |
|
| 184 | - return; |
|
| 185 | - } |
|
| 186 | - foreach (self::$pms_can_hide as $pm_name => $pm_option) { |
|
| 187 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_name); |
|
| 188 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->active()) { |
|
| 189 | - add_action('admin_notices', [__CLASS__, 'usePayPalCommerceNotice']); |
|
| 190 | - return; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } catch (EE_Error | ReflectionException $e) { |
|
| 194 | - // No handling needed right now. |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Recommend PayPal Commerce notice contents. |
|
| 201 | - * |
|
| 202 | - * @return void |
|
| 203 | - */ |
|
| 204 | - public static function usePayPalCommerceNotice() |
|
| 205 | - { |
|
| 206 | - echo '<div class="error"><p>' |
|
| 207 | - . sprintf( |
|
| 208 | - esc_html__( |
|
| 209 | - 'We recommend using our latest PayPal integration - %1$sPayPal Commerce%2$s payment method in place of PayPal Standard, PayPal Express and PayPal Pro.', |
|
| 210 | - 'event_espresso' |
|
| 211 | - ), |
|
| 212 | - '<strong>', |
|
| 213 | - '</strong>' |
|
| 214 | - ) |
|
| 215 | - . '</p></div>'; |
|
| 216 | - } |
|
| 24 | + /** |
|
| 25 | + * List of PMs that can be replaced with PP Commerce. |
|
| 26 | + * ['payment method name' => 'settings option'] |
|
| 27 | + * |
|
| 28 | + * @var array $pms_can_hide |
|
| 29 | + */ |
|
| 30 | + protected static array $pms_can_hide = [ |
|
| 31 | + 'paypal_express' => 'api_username', |
|
| 32 | + 'paypal_pro' => 'api_username', |
|
| 33 | + 'aim' => 'login_id', |
|
| 34 | + ]; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Manager constructor. |
|
| 39 | + */ |
|
| 40 | + public function __construct() |
|
| 41 | + { |
|
| 42 | + if (DbStatus::isOffline()) { |
|
| 43 | + return; |
|
| 44 | + } |
|
| 45 | + $this->loadPaymentMethods(); |
|
| 46 | + if (is_admin()) { |
|
| 47 | + // Use only PayPal Commerce if it's a new setup. |
|
| 48 | + add_filter( |
|
| 49 | + 'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', |
|
| 50 | + [__CLASS__, 'hidePaymentMethods'] |
|
| 51 | + ); |
|
| 52 | + // Payment methods related admin notices. |
|
| 53 | + add_action('admin_init', [__CLASS__, 'adminNotice']); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Load all payment methods that are in PaymentMethods folder. |
|
| 60 | + * |
|
| 61 | + * @return void |
|
| 62 | + */ |
|
| 63 | + protected function loadPaymentMethods() |
|
| 64 | + { |
|
| 65 | + // Scan the PaymentMethods folder. |
|
| 66 | + $pms_list = glob(EE_PLUGIN_DIR_PATH . 'PaymentMethods/*', GLOB_ONLYDIR); |
|
| 67 | + // Filter the discovered PM list. |
|
| 68 | + $pms_list = apply_filters('FHEE__PaymentMethods__Manager__loadPaymentMethods__pms_list', $pms_list); |
|
| 69 | + // Clean from duplicates. |
|
| 70 | + $pms_list = array_unique($pms_list); |
|
| 71 | + foreach ($pms_list as $pm_path) { |
|
| 72 | + $this->registerPaymentMethod($pm_path); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Looks for the main payment method file and loads it. |
|
| 79 | + * |
|
| 80 | + * @param string $pm_path path to the payment method folder |
|
| 81 | + * @param string $file_ext |
|
| 82 | + * @param string $pm_namespace |
|
| 83 | + * @return boolean |
|
| 84 | + */ |
|
| 85 | + public function registerPaymentMethod( |
|
| 86 | + string $pm_path, |
|
| 87 | + string $file_ext = '.php', |
|
| 88 | + string $pm_namespace = 'EventEspresso\PaymentMethods' |
|
| 89 | + ): bool { |
|
| 90 | + do_action('AHEE__PaymentMethods__Manager__registerPaymentMethod__start', $pm_path); |
|
| 91 | + // Separators should match. |
|
| 92 | + $pm_path = str_replace('/\\', '/', $pm_path) . DS; |
|
| 93 | + // Sanitize PM name. |
|
| 94 | + $module_dir = basename($pm_path); |
|
| 95 | + // Get class name. |
|
| 96 | + $pm_class_name = str_replace(' ', '_', $module_dir); |
|
| 97 | + // Check if file exists. |
|
| 98 | + if (! is_readable($pm_path . $pm_class_name . $file_ext)) { |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + // Load the initial PM class. |
|
| 102 | + require_once($pm_path . DS . $pm_class_name . $file_ext); |
|
| 103 | + $pm_object = "$pm_namespace\\$pm_class_name"; |
|
| 104 | + if (! class_exists($pm_object)) { |
|
| 105 | + return false; |
|
| 106 | + } |
|
| 107 | + new $pm_object(); |
|
| 108 | + return true; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Deactivate a few other PMs if it's a new setup. Use PP Commerce. |
|
| 114 | + * |
|
| 115 | + * @param array $pms_to_list |
|
| 116 | + * @return array |
|
| 117 | + * @throws EE_Error |
|
| 118 | + * @throws ReflectionException |
|
| 119 | + */ |
|
| 120 | + public static function hidePaymentMethods(array $pms_to_list): array |
|
| 121 | + { |
|
| 122 | + foreach (self::$pms_can_hide as $pm_name => $pm_option) { |
|
| 123 | + // Can we deregister this PM ? |
|
| 124 | + if (isset($pms_to_list[ $pm_name ]) && self::pmCanBeHidden($pm_name, $pm_option)) { |
|
| 125 | + unset($pms_to_list[ $pm_name ]); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + return $pms_to_list; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Deregisters the provided payment method if not used. |
|
| 134 | + * |
|
| 135 | + * @param string $pm_name |
|
| 136 | + * @param string $pm_option |
|
| 137 | + * @return bool |
|
| 138 | + * @throws EE_Error |
|
| 139 | + * @throws ReflectionException |
|
| 140 | + */ |
|
| 141 | + public static function pmCanBeHidden(string $pm_name, string $pm_option): bool |
|
| 142 | + { |
|
| 143 | + $pm_to_hide = EEM_Payment_Method::instance()->get_one_by_slug($pm_name); |
|
| 144 | + $pm_active = $pm_active_before = false; |
|
| 145 | + if ($pm_to_hide instanceof EE_Payment_Method) { |
|
| 146 | + $pm_active = $pm_to_hide->active(); |
|
| 147 | + // Payment method used before ? |
|
| 148 | + $option = $pm_to_hide->get_extra_meta($pm_option, true, false); |
|
| 149 | + $pm_active_before = ! empty($option); |
|
| 150 | + } |
|
| 151 | + // If PM not used before and not active, deregister it. |
|
| 152 | + if ( |
|
| 153 | + apply_filters( |
|
| 154 | + "FHEE__PaymentMethods__Manager__register_payment_methods__hide_$pm_name", |
|
| 155 | + ! $pm_active && ! $pm_active_before, |
|
| 156 | + $pm_name |
|
| 157 | + ) |
|
| 158 | + ) { |
|
| 159 | + return true; |
|
| 160 | + } |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Payment methods related admin notices. |
|
| 167 | + * |
|
| 168 | + * @return void |
|
| 169 | + */ |
|
| 170 | + public static function adminNotice() |
|
| 171 | + { |
|
| 172 | + // Is this an EE admin page ? |
|
| 173 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
| 174 | + $page_name = $request->getRequestParam('page'); |
|
| 175 | + // Only show the notice on core EE pages |
|
| 176 | + if (! str_contains($page_name, 'espresso')) { |
|
| 177 | + return; |
|
| 178 | + } |
|
| 179 | + // Notice if one of the following payment methods is used: PayPal Express, PayPal Pro, Authorize.net AIM. |
|
| 180 | + try { |
|
| 181 | + $pp_commerce = EEM_Payment_Method::instance()->get_one_by_slug('paypalcheckout'); |
|
| 182 | + // Don't show notice if PayPal Commerce is active. |
|
| 183 | + if ($pp_commerce instanceof EE_Payment_Method && $pp_commerce->active()) { |
|
| 184 | + return; |
|
| 185 | + } |
|
| 186 | + foreach (self::$pms_can_hide as $pm_name => $pm_option) { |
|
| 187 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_name); |
|
| 188 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->active()) { |
|
| 189 | + add_action('admin_notices', [__CLASS__, 'usePayPalCommerceNotice']); |
|
| 190 | + return; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } catch (EE_Error | ReflectionException $e) { |
|
| 194 | + // No handling needed right now. |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Recommend PayPal Commerce notice contents. |
|
| 201 | + * |
|
| 202 | + * @return void |
|
| 203 | + */ |
|
| 204 | + public static function usePayPalCommerceNotice() |
|
| 205 | + { |
|
| 206 | + echo '<div class="error"><p>' |
|
| 207 | + . sprintf( |
|
| 208 | + esc_html__( |
|
| 209 | + 'We recommend using our latest PayPal integration - %1$sPayPal Commerce%2$s payment method in place of PayPal Standard, PayPal Express and PayPal Pro.', |
|
| 210 | + 'event_espresso' |
|
| 211 | + ), |
|
| 212 | + '<strong>', |
|
| 213 | + '</strong>' |
|
| 214 | + ) |
|
| 215 | + . '</p></div>'; |
|
| 216 | + } |
|
| 217 | 217 | } |
@@ -14,30 +14,30 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EspressoEventsAdmin extends AdminRoute |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * returns true if the current request matches this route |
|
| 19 | - * |
|
| 20 | - * @return bool |
|
| 21 | - * @since 5.0.0.p |
|
| 22 | - */ |
|
| 23 | - public function matchesCurrentRequest(): bool |
|
| 24 | - { |
|
| 25 | - global $pagenow; |
|
| 26 | - return parent::matchesCurrentRequest() |
|
| 27 | - && $pagenow |
|
| 28 | - && $pagenow === 'admin.php' |
|
| 29 | - && $this->request->getRequestParam('page') === 'espresso_events'; |
|
| 30 | - } |
|
| 17 | + /** |
|
| 18 | + * returns true if the current request matches this route |
|
| 19 | + * |
|
| 20 | + * @return bool |
|
| 21 | + * @since 5.0.0.p |
|
| 22 | + */ |
|
| 23 | + public function matchesCurrentRequest(): bool |
|
| 24 | + { |
|
| 25 | + global $pagenow; |
|
| 26 | + return parent::matchesCurrentRequest() |
|
| 27 | + && $pagenow |
|
| 28 | + && $pagenow === 'admin.php' |
|
| 29 | + && $this->request->getRequestParam('page') === 'espresso_events'; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @since 5.0.0.p |
|
| 35 | - */ |
|
| 36 | - protected function registerDependencies() |
|
| 37 | - { |
|
| 38 | - $this->dependency_map->registerDependencies( |
|
| 39 | - 'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection', |
|
| 40 | - AdminRoute::getDefaultDependencies() |
|
| 41 | - ); |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * @since 5.0.0.p |
|
| 35 | + */ |
|
| 36 | + protected function registerDependencies() |
|
| 37 | + { |
|
| 38 | + $this->dependency_map->registerDependencies( |
|
| 39 | + 'EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection', |
|
| 40 | + AdminRoute::getDefaultDependencies() |
|
| 41 | + ); |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -37,138 +37,138 @@ |
||
| 37 | 37 | * @since 4.0 |
| 38 | 38 | */ |
| 39 | 39 | if (function_exists('espresso_version')) { |
| 40 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 41 | - /** |
|
| 42 | - * espresso_duplicate_plugin_error |
|
| 43 | - * displays if more than one version of EE is activated at the same time. |
|
| 44 | - */ |
|
| 45 | - function espresso_duplicate_plugin_error() |
|
| 46 | - { |
|
| 47 | - ?> |
|
| 40 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 41 | + /** |
|
| 42 | + * espresso_duplicate_plugin_error |
|
| 43 | + * displays if more than one version of EE is activated at the same time. |
|
| 44 | + */ |
|
| 45 | + function espresso_duplicate_plugin_error() |
|
| 46 | + { |
|
| 47 | + ?> |
|
| 48 | 48 | <div class="error"> |
| 49 | 49 | <p> |
| 50 | 50 | <?php |
| 51 | - echo esc_html__( |
|
| 52 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 53 | - 'event_espresso' |
|
| 54 | - ); ?> |
|
| 51 | + echo esc_html__( |
|
| 52 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 53 | + 'event_espresso' |
|
| 54 | + ); ?> |
|
| 55 | 55 | </p> |
| 56 | 56 | </div> |
| 57 | 57 | <?php |
| 58 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 58 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 62 | 62 | } else { |
| 63 | - define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); |
|
| 64 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 65 | - /** |
|
| 66 | - * espresso_minimum_php_version_error |
|
| 67 | - * |
|
| 68 | - * @return void |
|
| 69 | - */ |
|
| 70 | - function espresso_minimum_php_version_error() |
|
| 71 | - { |
|
| 72 | - ?> |
|
| 63 | + define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); |
|
| 64 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 65 | + /** |
|
| 66 | + * espresso_minimum_php_version_error |
|
| 67 | + * |
|
| 68 | + * @return void |
|
| 69 | + */ |
|
| 70 | + function espresso_minimum_php_version_error() |
|
| 71 | + { |
|
| 72 | + ?> |
|
| 73 | 73 | <div class="error"> |
| 74 | 74 | <p> |
| 75 | 75 | <?php |
| 76 | - printf( |
|
| 77 | - esc_html__( |
|
| 78 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 79 | - 'event_espresso' |
|
| 80 | - ), |
|
| 81 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 82 | - PHP_VERSION, |
|
| 83 | - '<br/>', |
|
| 84 | - '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>' |
|
| 85 | - ); |
|
| 86 | - ?> |
|
| 76 | + printf( |
|
| 77 | + esc_html__( |
|
| 78 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 79 | + 'event_espresso' |
|
| 80 | + ), |
|
| 81 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 82 | + PHP_VERSION, |
|
| 83 | + '<br/>', |
|
| 84 | + '<a href="https://www.php.net/downloads.php">https://php.net/downloads.php</a>' |
|
| 85 | + ); |
|
| 86 | + ?> |
|
| 87 | 87 | </p> |
| 88 | 88 | </div> |
| 89 | 89 | <?php |
| 90 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 91 | - } |
|
| 90 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 94 | - } else { |
|
| 95 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 93 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 94 | + } else { |
|
| 95 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 96 | 96 | |
| 97 | - require_once __DIR__ . '/vendor/autoload.php'; |
|
| 97 | + require_once __DIR__ . '/vendor/autoload.php'; |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * espresso_version |
|
| 101 | - * Returns the plugin version |
|
| 102 | - * |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - function espresso_version(): string |
|
| 106 | - { |
|
| 107 | - return apply_filters('FHEE__espresso__espresso_version', '5.0.13.rc.000'); |
|
| 108 | - } |
|
| 99 | + /** |
|
| 100 | + * espresso_version |
|
| 101 | + * Returns the plugin version |
|
| 102 | + * |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + function espresso_version(): string |
|
| 106 | + { |
|
| 107 | + return apply_filters('FHEE__espresso__espresso_version', '5.0.13.rc.000'); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * espresso_plugin_activation |
|
| 112 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 113 | - */ |
|
| 114 | - function espresso_plugin_activation() |
|
| 115 | - { |
|
| 116 | - update_option('ee_espresso_activation', true); |
|
| 117 | - update_option('event-espresso-core_allow_tracking', 'no'); |
|
| 118 | - update_option('event-espresso-core_tracking_notice', 'hide'); |
|
| 119 | - // Run WP GraphQL activation callback |
|
| 120 | - espressoLoadWpGraphQL(); |
|
| 121 | - graphql_activation_callback(); |
|
| 122 | - } |
|
| 110 | + /** |
|
| 111 | + * espresso_plugin_activation |
|
| 112 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 113 | + */ |
|
| 114 | + function espresso_plugin_activation() |
|
| 115 | + { |
|
| 116 | + update_option('ee_espresso_activation', true); |
|
| 117 | + update_option('event-espresso-core_allow_tracking', 'no'); |
|
| 118 | + update_option('event-espresso-core_tracking_notice', 'hide'); |
|
| 119 | + // Run WP GraphQL activation callback |
|
| 120 | + espressoLoadWpGraphQL(); |
|
| 121 | + graphql_activation_callback(); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 124 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * espresso_plugin_deactivation |
|
| 128 | - */ |
|
| 129 | - function espresso_plugin_deactivation() |
|
| 130 | - { |
|
| 131 | - // Run WP GraphQL deactivation callback |
|
| 132 | - espressoLoadWpGraphQL(); |
|
| 133 | - graphql_deactivation_callback(); |
|
| 134 | - delete_option('event-espresso-core_allow_tracking'); |
|
| 135 | - delete_option('event-espresso-core_tracking_notice'); |
|
| 136 | - } |
|
| 137 | - register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
| 126 | + /** |
|
| 127 | + * espresso_plugin_deactivation |
|
| 128 | + */ |
|
| 129 | + function espresso_plugin_deactivation() |
|
| 130 | + { |
|
| 131 | + // Run WP GraphQL deactivation callback |
|
| 132 | + espressoLoadWpGraphQL(); |
|
| 133 | + graphql_deactivation_callback(); |
|
| 134 | + delete_option('event-espresso-core_allow_tracking'); |
|
| 135 | + delete_option('event-espresso-core_tracking_notice'); |
|
| 136 | + } |
|
| 137 | + register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
| 138 | 138 | |
| 139 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 140 | - bootstrap_espresso(); |
|
| 141 | - } |
|
| 139 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 140 | + bootstrap_espresso(); |
|
| 141 | + } |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | if (! function_exists('espresso_deactivate_plugin')) { |
| 145 | - /** |
|
| 146 | - * deactivate_plugin |
|
| 147 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 148 | - * |
|
| 149 | - * @access public |
|
| 150 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 151 | - * @return void |
|
| 152 | - */ |
|
| 153 | - function espresso_deactivate_plugin(string $plugin_basename = '') |
|
| 154 | - { |
|
| 155 | - if (! function_exists('deactivate_plugins')) { |
|
| 156 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 157 | - } |
|
| 158 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 159 | - deactivate_plugins($plugin_basename); |
|
| 160 | - } |
|
| 145 | + /** |
|
| 146 | + * deactivate_plugin |
|
| 147 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 148 | + * |
|
| 149 | + * @access public |
|
| 150 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 151 | + * @return void |
|
| 152 | + */ |
|
| 153 | + function espresso_deactivate_plugin(string $plugin_basename = '') |
|
| 154 | + { |
|
| 155 | + if (! function_exists('deactivate_plugins')) { |
|
| 156 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 157 | + } |
|
| 158 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 159 | + deactivate_plugins($plugin_basename); |
|
| 160 | + } |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
| 164 | 164 | if (! function_exists('espressoLoadWpGraphQL')) { |
| 165 | - function espressoLoadWpGraphQL() |
|
| 166 | - { |
|
| 167 | - if ( |
|
| 168 | - ! class_exists('WPGraphQL') |
|
| 169 | - && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php') |
|
| 170 | - ) { |
|
| 171 | - require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php'; |
|
| 172 | - } |
|
| 173 | - } |
|
| 165 | + function espressoLoadWpGraphQL() |
|
| 166 | + { |
|
| 167 | + if ( |
|
| 168 | + ! class_exists('WPGraphQL') |
|
| 169 | + && is_readable(__DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php') |
|
| 170 | + ) { |
|
| 171 | + require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php'; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -15,168 +15,168 @@ |
||
| 15 | 15 | |
| 16 | 16 | class InputObjectField |
| 17 | 17 | { |
| 18 | - /** @var string */ |
|
| 19 | - public $name; |
|
| 20 | - |
|
| 21 | - /** @var mixed|null */ |
|
| 22 | - public $defaultValue; |
|
| 23 | - |
|
| 24 | - /** @var string|null */ |
|
| 25 | - public $description; |
|
| 26 | - |
|
| 27 | - /** @var Type&InputType */ |
|
| 28 | - private $type; |
|
| 29 | - |
|
| 30 | - /** @var InputValueDefinitionNode|null */ |
|
| 31 | - public $astNode; |
|
| 32 | - |
|
| 33 | - /** @var mixed[] */ |
|
| 34 | - public $config; |
|
| 35 | - |
|
| 36 | - public $caps; |
|
| 37 | - |
|
| 38 | - public $formatter; |
|
| 39 | - |
|
| 40 | - public $key; |
|
| 41 | - |
|
| 42 | - public $resolver; |
|
| 43 | - |
|
| 44 | - public $use_for_input; |
|
| 45 | - |
|
| 46 | - public $use_for_output; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @param mixed[] $opts |
|
| 50 | - */ |
|
| 51 | - public function __construct(array $opts) |
|
| 52 | - { |
|
| 53 | - foreach ($opts as $k => $v) { |
|
| 54 | - switch ($k) { |
|
| 55 | - case 'defaultValue': |
|
| 56 | - $this->defaultValue = $v; |
|
| 57 | - break; |
|
| 58 | - case 'defaultValueExists': |
|
| 59 | - break; |
|
| 60 | - case 'type': |
|
| 61 | - // do nothing; type is lazy loaded in getType |
|
| 62 | - break; |
|
| 63 | - default: |
|
| 64 | - $this->{$k} = $v; |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - $this->config = $opts; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function __isset(string $name) : bool |
|
| 71 | - { |
|
| 72 | - switch ($name) { |
|
| 73 | - case 'type': |
|
| 74 | - Warning::warnOnce( |
|
| 75 | - "The public getter for 'type' on InputObjectField has been deprecated and will be removed" . |
|
| 76 | - " in the next major version. Please update your code to use the 'getType' method.", |
|
| 77 | - Warning::WARNING_CONFIG_DEPRECATION |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - return isset($this->type); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - return isset($this->$name); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - public function __get(string $name) |
|
| 87 | - { |
|
| 88 | - switch ($name) { |
|
| 89 | - case 'type': |
|
| 90 | - Warning::warnOnce( |
|
| 91 | - "The public getter for 'type' on InputObjectField has been deprecated and will be removed" . |
|
| 92 | - " in the next major version. Please update your code to use the 'getType' method.", |
|
| 93 | - Warning::WARNING_CONFIG_DEPRECATION |
|
| 94 | - ); |
|
| 95 | - |
|
| 96 | - return $this->getType(); |
|
| 97 | - default: |
|
| 98 | - return $this->$name; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return null; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - public function __set(string $name, $value) |
|
| 105 | - { |
|
| 106 | - switch ($name) { |
|
| 107 | - case 'type': |
|
| 108 | - Warning::warnOnce( |
|
| 109 | - "The public setter for 'type' on InputObjectField has been deprecated and will be removed" . |
|
| 110 | - ' in the next major version.', |
|
| 111 | - Warning::WARNING_CONFIG_DEPRECATION |
|
| 112 | - ); |
|
| 113 | - $this->type = $value; |
|
| 114 | - break; |
|
| 115 | - |
|
| 116 | - default: |
|
| 117 | - $this->$name = $value; |
|
| 118 | - break; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return Type&InputType |
|
| 124 | - */ |
|
| 125 | - public function getType() : Type |
|
| 126 | - { |
|
| 127 | - if (! isset($this->type)) { |
|
| 128 | - /** |
|
| 129 | - * TODO: replace this phpstan cast with native assert |
|
| 130 | - * |
|
| 131 | - * @var Type&InputType |
|
| 132 | - */ |
|
| 133 | - $type = Schema::resolveType($this->config['type']); |
|
| 134 | - $this->type = $type; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return $this->type; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - public function defaultValueExists() : bool |
|
| 141 | - { |
|
| 142 | - return array_key_exists('defaultValue', $this->config); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - public function isRequired() : bool |
|
| 146 | - { |
|
| 147 | - return $this->getType() instanceof NonNull && ! $this->defaultValueExists(); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @throws InvariantViolation |
|
| 152 | - */ |
|
| 153 | - public function assertValid(Type $parentType) |
|
| 154 | - { |
|
| 155 | - try { |
|
| 156 | - Utils::assertValidName($this->name); |
|
| 157 | - } catch (Error $e) { |
|
| 158 | - throw new InvariantViolation(sprintf('%s.%s: %s', $parentType->name, $this->name, $e->getMessage())); |
|
| 159 | - } |
|
| 160 | - $type = $this->getType(); |
|
| 161 | - if ($type instanceof WrappingType) { |
|
| 162 | - $type = $type->getWrappedType(true); |
|
| 163 | - } |
|
| 164 | - Utils::invariant( |
|
| 165 | - $type instanceof InputType, |
|
| 166 | - sprintf( |
|
| 167 | - '%s.%s field type must be Input Type but got: %s', |
|
| 168 | - $parentType->name, |
|
| 169 | - $this->name, |
|
| 170 | - Utils::printSafe($this->type) |
|
| 171 | - ) |
|
| 172 | - ); |
|
| 173 | - Utils::invariant( |
|
| 174 | - ! array_key_exists('resolve', $this->config), |
|
| 175 | - sprintf( |
|
| 176 | - '%s.%s field has a resolve property, but Input Types cannot define resolvers.', |
|
| 177 | - $parentType->name, |
|
| 178 | - $this->name |
|
| 179 | - ) |
|
| 180 | - ); |
|
| 181 | - } |
|
| 18 | + /** @var string */ |
|
| 19 | + public $name; |
|
| 20 | + |
|
| 21 | + /** @var mixed|null */ |
|
| 22 | + public $defaultValue; |
|
| 23 | + |
|
| 24 | + /** @var string|null */ |
|
| 25 | + public $description; |
|
| 26 | + |
|
| 27 | + /** @var Type&InputType */ |
|
| 28 | + private $type; |
|
| 29 | + |
|
| 30 | + /** @var InputValueDefinitionNode|null */ |
|
| 31 | + public $astNode; |
|
| 32 | + |
|
| 33 | + /** @var mixed[] */ |
|
| 34 | + public $config; |
|
| 35 | + |
|
| 36 | + public $caps; |
|
| 37 | + |
|
| 38 | + public $formatter; |
|
| 39 | + |
|
| 40 | + public $key; |
|
| 41 | + |
|
| 42 | + public $resolver; |
|
| 43 | + |
|
| 44 | + public $use_for_input; |
|
| 45 | + |
|
| 46 | + public $use_for_output; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param mixed[] $opts |
|
| 50 | + */ |
|
| 51 | + public function __construct(array $opts) |
|
| 52 | + { |
|
| 53 | + foreach ($opts as $k => $v) { |
|
| 54 | + switch ($k) { |
|
| 55 | + case 'defaultValue': |
|
| 56 | + $this->defaultValue = $v; |
|
| 57 | + break; |
|
| 58 | + case 'defaultValueExists': |
|
| 59 | + break; |
|
| 60 | + case 'type': |
|
| 61 | + // do nothing; type is lazy loaded in getType |
|
| 62 | + break; |
|
| 63 | + default: |
|
| 64 | + $this->{$k} = $v; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + $this->config = $opts; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function __isset(string $name) : bool |
|
| 71 | + { |
|
| 72 | + switch ($name) { |
|
| 73 | + case 'type': |
|
| 74 | + Warning::warnOnce( |
|
| 75 | + "The public getter for 'type' on InputObjectField has been deprecated and will be removed" . |
|
| 76 | + " in the next major version. Please update your code to use the 'getType' method.", |
|
| 77 | + Warning::WARNING_CONFIG_DEPRECATION |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + return isset($this->type); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + return isset($this->$name); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + public function __get(string $name) |
|
| 87 | + { |
|
| 88 | + switch ($name) { |
|
| 89 | + case 'type': |
|
| 90 | + Warning::warnOnce( |
|
| 91 | + "The public getter for 'type' on InputObjectField has been deprecated and will be removed" . |
|
| 92 | + " in the next major version. Please update your code to use the 'getType' method.", |
|
| 93 | + Warning::WARNING_CONFIG_DEPRECATION |
|
| 94 | + ); |
|
| 95 | + |
|
| 96 | + return $this->getType(); |
|
| 97 | + default: |
|
| 98 | + return $this->$name; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return null; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + public function __set(string $name, $value) |
|
| 105 | + { |
|
| 106 | + switch ($name) { |
|
| 107 | + case 'type': |
|
| 108 | + Warning::warnOnce( |
|
| 109 | + "The public setter for 'type' on InputObjectField has been deprecated and will be removed" . |
|
| 110 | + ' in the next major version.', |
|
| 111 | + Warning::WARNING_CONFIG_DEPRECATION |
|
| 112 | + ); |
|
| 113 | + $this->type = $value; |
|
| 114 | + break; |
|
| 115 | + |
|
| 116 | + default: |
|
| 117 | + $this->$name = $value; |
|
| 118 | + break; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return Type&InputType |
|
| 124 | + */ |
|
| 125 | + public function getType() : Type |
|
| 126 | + { |
|
| 127 | + if (! isset($this->type)) { |
|
| 128 | + /** |
|
| 129 | + * TODO: replace this phpstan cast with native assert |
|
| 130 | + * |
|
| 131 | + * @var Type&InputType |
|
| 132 | + */ |
|
| 133 | + $type = Schema::resolveType($this->config['type']); |
|
| 134 | + $this->type = $type; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return $this->type; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + public function defaultValueExists() : bool |
|
| 141 | + { |
|
| 142 | + return array_key_exists('defaultValue', $this->config); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + public function isRequired() : bool |
|
| 146 | + { |
|
| 147 | + return $this->getType() instanceof NonNull && ! $this->defaultValueExists(); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @throws InvariantViolation |
|
| 152 | + */ |
|
| 153 | + public function assertValid(Type $parentType) |
|
| 154 | + { |
|
| 155 | + try { |
|
| 156 | + Utils::assertValidName($this->name); |
|
| 157 | + } catch (Error $e) { |
|
| 158 | + throw new InvariantViolation(sprintf('%s.%s: %s', $parentType->name, $this->name, $e->getMessage())); |
|
| 159 | + } |
|
| 160 | + $type = $this->getType(); |
|
| 161 | + if ($type instanceof WrappingType) { |
|
| 162 | + $type = $type->getWrappedType(true); |
|
| 163 | + } |
|
| 164 | + Utils::invariant( |
|
| 165 | + $type instanceof InputType, |
|
| 166 | + sprintf( |
|
| 167 | + '%s.%s field type must be Input Type but got: %s', |
|
| 168 | + $parentType->name, |
|
| 169 | + $this->name, |
|
| 170 | + Utils::printSafe($this->type) |
|
| 171 | + ) |
|
| 172 | + ); |
|
| 173 | + Utils::invariant( |
|
| 174 | + ! array_key_exists('resolve', $this->config), |
|
| 175 | + sprintf( |
|
| 176 | + '%s.%s field has a resolve property, but Input Types cannot define resolvers.', |
|
| 177 | + $parentType->name, |
|
| 178 | + $this->name |
|
| 179 | + ) |
|
| 180 | + ); |
|
| 181 | + } |
|
| 182 | 182 | } |
@@ -93,7 +93,7 @@ |
||
| 93 | 93 | */ |
| 94 | 94 | public $node_resolver; |
| 95 | 95 | |
| 96 | - public $connection_query_class; |
|
| 96 | + public $connection_query_class; |
|
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | 99 | * AppContext constructor. |
@@ -13,264 +13,264 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class Price_Types_List_Table extends EE_Admin_List_Table |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @var Pricing_Admin_Page |
|
| 18 | - */ |
|
| 19 | - protected EE_Admin_Page $_admin_page; |
|
| 20 | - |
|
| 21 | - protected EEM_Price_Type $_PRT; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @throws EE_Error |
|
| 26 | - * @throws ReflectionException |
|
| 27 | - */ |
|
| 28 | - public function __construct($admin_page) |
|
| 29 | - { |
|
| 30 | - parent::__construct($admin_page); |
|
| 31 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 32 | - $this->_PRT = EEM_Price_Type::instance(); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @throws ReflectionException |
|
| 38 | - * @throws EE_Error |
|
| 39 | - */ |
|
| 40 | - protected function _setup_data() |
|
| 41 | - { |
|
| 42 | - $trashed = $this->_admin_page->get_view() == 'trashed'; |
|
| 43 | - $this->_data = $this->_admin_page->get_price_types_overview_data($this->_per_page, false, $trashed); |
|
| 44 | - $this->_all_data_count = $this->_admin_page->get_price_types_overview_data($this->_per_page, true); |
|
| 45 | - $this->_trashed_count = $this->_admin_page->get_price_types_overview_data($this->_per_page, true, true); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - protected function _set_properties() |
|
| 50 | - { |
|
| 51 | - $this->_wp_list_args = [ |
|
| 52 | - 'singular' => esc_html__('price type', 'event_espresso'), |
|
| 53 | - 'plural' => esc_html__('price types', 'event_espresso'), |
|
| 54 | - 'ajax' => true, |
|
| 55 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 56 | - ]; |
|
| 57 | - |
|
| 58 | - $this->_columns = [ |
|
| 59 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
| 60 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
| 61 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
| 62 | - 'base_type' => esc_html__('Base Type', 'event_espresso'), |
|
| 63 | - 'percent' => sprintf( |
|
| 64 | - /* translators: 1: HTML new line, 2: open span tag, 3: close span tag */ |
|
| 65 | - esc_html__('Applied %1$s as %2$s%%%3$s or %2$s$%3$s', 'event_espresso'), |
|
| 66 | - '', |
|
| 67 | - '<span class="big-text">', |
|
| 68 | - '</span>' |
|
| 69 | - ), |
|
| 70 | - 'order' => esc_html__('Order of Application', 'event_espresso'), |
|
| 71 | - ]; |
|
| 72 | - |
|
| 73 | - $this->_sortable_columns = [ |
|
| 74 | - // TRUE means its already sorted |
|
| 75 | - 'name' => ['name' => false], |
|
| 76 | - ]; |
|
| 77 | - |
|
| 78 | - $this->_hidden_columns = []; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - protected function _get_table_filters() |
|
| 83 | - { |
|
| 84 | - return []; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - protected function _add_view_counts() |
|
| 89 | - { |
|
| 90 | - $this->_views['all']['count'] = $this->_all_data_count; |
|
| 91 | - if ( |
|
| 92 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 93 | - 'ee_delete_default_price_types', |
|
| 94 | - 'pricing_trash_price_type' |
|
| 95 | - ) |
|
| 96 | - ) { |
|
| 97 | - $this->_views['trashed']['count'] = $this->_trashed_count; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param EE_Price_Type $price_type |
|
| 104 | - * @param string $action |
|
| 105 | - * @return string |
|
| 106 | - * @throws EE_Error |
|
| 107 | - * @throws ReflectionException |
|
| 108 | - * @since 5.0.0.p |
|
| 109 | - */ |
|
| 110 | - protected function getActionUrl(EE_Price_Type $price_type, string $action): string |
|
| 111 | - { |
|
| 112 | - if (! in_array($action, self::$actions)) { |
|
| 113 | - throw new DomainException(esc_html__('Invalid Action', 'event_espresso')); |
|
| 114 | - } |
|
| 115 | - return EE_Admin_Page::add_query_args_and_nonce( |
|
| 116 | - [ |
|
| 117 | - 'action' => "{$action}_price_type", |
|
| 118 | - 'id' => $price_type->ID(), |
|
| 119 | - 'noheader' => $action !== self::ACTION_EDIT, |
|
| 120 | - ], |
|
| 121 | - PRICING_ADMIN_URL |
|
| 122 | - ); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - public function column_cb($item): string |
|
| 127 | - { |
|
| 128 | - if ($item->base_type() !== 1) { |
|
| 129 | - return sprintf( |
|
| 130 | - '<input type="checkbox" name="checkbox[%1$s]" />', |
|
| 131 | - $item->ID() |
|
| 132 | - ); |
|
| 133 | - } |
|
| 134 | - return ''; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @param EE_Price_Type $item |
|
| 140 | - * @return string |
|
| 141 | - * @throws EE_Error |
|
| 142 | - * @throws ReflectionException |
|
| 143 | - */ |
|
| 144 | - public function column_id($item): string |
|
| 145 | - { |
|
| 146 | - $content = '<span class="ee-entity-id">' . $item->ID() . '</span>'; |
|
| 147 | - $content .= '<span class="show-on-mobile-view-only">' . $this->column_name($item, false) . '</span>'; |
|
| 148 | - return $this->columnContent('id', $content, 'end'); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param EE_Price_Type $price_type |
|
| 154 | - * @param bool $prep_content |
|
| 155 | - * @return string |
|
| 156 | - * @throws EE_Error |
|
| 157 | - * @throws ReflectionException |
|
| 158 | - */ |
|
| 159 | - public function column_name(EE_Price_Type $price_type, bool $prep_content = true): string |
|
| 160 | - { |
|
| 161 | - |
|
| 162 | - // Build row actions |
|
| 163 | - $actions = []; |
|
| 164 | - $name_link = $price_type->name(); |
|
| 165 | - // edit price link |
|
| 166 | - if ( |
|
| 167 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 168 | - 'ee_edit_default_price_type', |
|
| 169 | - 'pricing_edit_price_type', |
|
| 170 | - $price_type->ID() |
|
| 171 | - ) |
|
| 172 | - ) { |
|
| 173 | - $name_link = $this->getActionLink( |
|
| 174 | - $this->getActionUrl($price_type, self::ACTION_EDIT), |
|
| 175 | - stripslashes($price_type->name()), |
|
| 176 | - sprintf( |
|
| 177 | - /* translators: The name of the price type */ |
|
| 178 | - esc_attr__('Edit Price Type (%s)', 'event_espresso'), |
|
| 179 | - $price_type->name() |
|
| 180 | - ) |
|
| 181 | - ); |
|
| 182 | - |
|
| 183 | - $actions['edit'] = $this->getActionLink( |
|
| 184 | - $this->getActionUrl($price_type, self::ACTION_EDIT), |
|
| 185 | - esc_html__('Edit', 'event_espresso'), |
|
| 186 | - sprintf( |
|
| 187 | - /* translators: The name of the price type */ |
|
| 188 | - esc_attr__('Edit Price Type (%s)', 'event_espresso'), |
|
| 189 | - $price_type->name() |
|
| 190 | - ) |
|
| 191 | - ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if ($price_type->base_type() !== 1) { |
|
| 195 | - if ($this->_view == 'all') { |
|
| 196 | - // trash price link |
|
| 197 | - if ( |
|
| 198 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 199 | - 'ee_delete_default_price_type', |
|
| 200 | - 'pricing_trash_price_type', |
|
| 201 | - $price_type->ID() |
|
| 202 | - ) |
|
| 203 | - ) { |
|
| 204 | - $actions['trash'] = $this->getActionLink( |
|
| 205 | - $this->getActionUrl($price_type, self::ACTION_TRASH), |
|
| 206 | - esc_html__('Trash', 'event_espresso'), |
|
| 207 | - sprintf( |
|
| 208 | - /* translators: The name of the price type */ |
|
| 209 | - esc_attr__('Move Price Type %s to Trash', 'event_espresso'), |
|
| 210 | - $price_type->name() |
|
| 211 | - ) |
|
| 212 | - ); |
|
| 213 | - } |
|
| 214 | - } else { |
|
| 215 | - // restore price link |
|
| 216 | - if ( |
|
| 217 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 218 | - 'ee_delete_default_price_type', |
|
| 219 | - 'pricing_restore_price_type', |
|
| 220 | - $price_type->ID() |
|
| 221 | - ) |
|
| 222 | - ) { |
|
| 223 | - $actions['restore'] = $this->getActionLink( |
|
| 224 | - $this->getActionUrl($price_type, self::ACTION_RESTORE), |
|
| 225 | - esc_html__('Restore', 'event_espresso'), |
|
| 226 | - sprintf( |
|
| 227 | - /* translators: The name of the price type */ |
|
| 228 | - esc_attr__('Restore Price Type (%s)', 'event_espresso'), |
|
| 229 | - $price_type->name() |
|
| 230 | - ) |
|
| 231 | - ); |
|
| 232 | - } |
|
| 233 | - // delete price link |
|
| 234 | - if ( |
|
| 235 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 236 | - 'ee_delete_default_price_type', |
|
| 237 | - 'pricing_delete_price_type', |
|
| 238 | - $price_type->ID() |
|
| 239 | - ) |
|
| 240 | - ) { |
|
| 241 | - $actions['delete'] = $this->getActionLink( |
|
| 242 | - $this->getActionUrl($price_type, self::ACTION_DELETE), |
|
| 243 | - esc_html__('Delete Permanently', 'event_espresso'), |
|
| 244 | - sprintf( |
|
| 245 | - /* translators: The name of the price type */ |
|
| 246 | - esc_attr__('Delete Price Type %s Permanently', 'event_espresso'), |
|
| 247 | - $price_type->name() |
|
| 248 | - ) |
|
| 249 | - ); |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - $content = $prep_content ? $name_link . $this->row_actions($actions) : $name_link; |
|
| 255 | - return $prep_content ? $this->columnContent('name', $content) : $content; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - public function column_base_type($price_type): string |
|
| 260 | - { |
|
| 261 | - return $this->columnContent('base_type', $price_type->base_type_name()); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - public function column_percent($price_type): string |
|
| 266 | - { |
|
| 267 | - $content = $price_type->is_percent() ? '%' : EE_Registry::instance()->CFG->currency->sign; |
|
| 268 | - return $this->columnContent('percent', $content, 'center'); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - public function column_order($price_type): string |
|
| 273 | - { |
|
| 274 | - return $this->columnContent('order', $price_type->order(), 'end'); |
|
| 275 | - } |
|
| 16 | + /** |
|
| 17 | + * @var Pricing_Admin_Page |
|
| 18 | + */ |
|
| 19 | + protected EE_Admin_Page $_admin_page; |
|
| 20 | + |
|
| 21 | + protected EEM_Price_Type $_PRT; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @throws EE_Error |
|
| 26 | + * @throws ReflectionException |
|
| 27 | + */ |
|
| 28 | + public function __construct($admin_page) |
|
| 29 | + { |
|
| 30 | + parent::__construct($admin_page); |
|
| 31 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 32 | + $this->_PRT = EEM_Price_Type::instance(); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @throws ReflectionException |
|
| 38 | + * @throws EE_Error |
|
| 39 | + */ |
|
| 40 | + protected function _setup_data() |
|
| 41 | + { |
|
| 42 | + $trashed = $this->_admin_page->get_view() == 'trashed'; |
|
| 43 | + $this->_data = $this->_admin_page->get_price_types_overview_data($this->_per_page, false, $trashed); |
|
| 44 | + $this->_all_data_count = $this->_admin_page->get_price_types_overview_data($this->_per_page, true); |
|
| 45 | + $this->_trashed_count = $this->_admin_page->get_price_types_overview_data($this->_per_page, true, true); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + protected function _set_properties() |
|
| 50 | + { |
|
| 51 | + $this->_wp_list_args = [ |
|
| 52 | + 'singular' => esc_html__('price type', 'event_espresso'), |
|
| 53 | + 'plural' => esc_html__('price types', 'event_espresso'), |
|
| 54 | + 'ajax' => true, |
|
| 55 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 56 | + ]; |
|
| 57 | + |
|
| 58 | + $this->_columns = [ |
|
| 59 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
| 60 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
| 61 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
| 62 | + 'base_type' => esc_html__('Base Type', 'event_espresso'), |
|
| 63 | + 'percent' => sprintf( |
|
| 64 | + /* translators: 1: HTML new line, 2: open span tag, 3: close span tag */ |
|
| 65 | + esc_html__('Applied %1$s as %2$s%%%3$s or %2$s$%3$s', 'event_espresso'), |
|
| 66 | + '', |
|
| 67 | + '<span class="big-text">', |
|
| 68 | + '</span>' |
|
| 69 | + ), |
|
| 70 | + 'order' => esc_html__('Order of Application', 'event_espresso'), |
|
| 71 | + ]; |
|
| 72 | + |
|
| 73 | + $this->_sortable_columns = [ |
|
| 74 | + // TRUE means its already sorted |
|
| 75 | + 'name' => ['name' => false], |
|
| 76 | + ]; |
|
| 77 | + |
|
| 78 | + $this->_hidden_columns = []; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + protected function _get_table_filters() |
|
| 83 | + { |
|
| 84 | + return []; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + protected function _add_view_counts() |
|
| 89 | + { |
|
| 90 | + $this->_views['all']['count'] = $this->_all_data_count; |
|
| 91 | + if ( |
|
| 92 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 93 | + 'ee_delete_default_price_types', |
|
| 94 | + 'pricing_trash_price_type' |
|
| 95 | + ) |
|
| 96 | + ) { |
|
| 97 | + $this->_views['trashed']['count'] = $this->_trashed_count; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param EE_Price_Type $price_type |
|
| 104 | + * @param string $action |
|
| 105 | + * @return string |
|
| 106 | + * @throws EE_Error |
|
| 107 | + * @throws ReflectionException |
|
| 108 | + * @since 5.0.0.p |
|
| 109 | + */ |
|
| 110 | + protected function getActionUrl(EE_Price_Type $price_type, string $action): string |
|
| 111 | + { |
|
| 112 | + if (! in_array($action, self::$actions)) { |
|
| 113 | + throw new DomainException(esc_html__('Invalid Action', 'event_espresso')); |
|
| 114 | + } |
|
| 115 | + return EE_Admin_Page::add_query_args_and_nonce( |
|
| 116 | + [ |
|
| 117 | + 'action' => "{$action}_price_type", |
|
| 118 | + 'id' => $price_type->ID(), |
|
| 119 | + 'noheader' => $action !== self::ACTION_EDIT, |
|
| 120 | + ], |
|
| 121 | + PRICING_ADMIN_URL |
|
| 122 | + ); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + public function column_cb($item): string |
|
| 127 | + { |
|
| 128 | + if ($item->base_type() !== 1) { |
|
| 129 | + return sprintf( |
|
| 130 | + '<input type="checkbox" name="checkbox[%1$s]" />', |
|
| 131 | + $item->ID() |
|
| 132 | + ); |
|
| 133 | + } |
|
| 134 | + return ''; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @param EE_Price_Type $item |
|
| 140 | + * @return string |
|
| 141 | + * @throws EE_Error |
|
| 142 | + * @throws ReflectionException |
|
| 143 | + */ |
|
| 144 | + public function column_id($item): string |
|
| 145 | + { |
|
| 146 | + $content = '<span class="ee-entity-id">' . $item->ID() . '</span>'; |
|
| 147 | + $content .= '<span class="show-on-mobile-view-only">' . $this->column_name($item, false) . '</span>'; |
|
| 148 | + return $this->columnContent('id', $content, 'end'); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param EE_Price_Type $price_type |
|
| 154 | + * @param bool $prep_content |
|
| 155 | + * @return string |
|
| 156 | + * @throws EE_Error |
|
| 157 | + * @throws ReflectionException |
|
| 158 | + */ |
|
| 159 | + public function column_name(EE_Price_Type $price_type, bool $prep_content = true): string |
|
| 160 | + { |
|
| 161 | + |
|
| 162 | + // Build row actions |
|
| 163 | + $actions = []; |
|
| 164 | + $name_link = $price_type->name(); |
|
| 165 | + // edit price link |
|
| 166 | + if ( |
|
| 167 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 168 | + 'ee_edit_default_price_type', |
|
| 169 | + 'pricing_edit_price_type', |
|
| 170 | + $price_type->ID() |
|
| 171 | + ) |
|
| 172 | + ) { |
|
| 173 | + $name_link = $this->getActionLink( |
|
| 174 | + $this->getActionUrl($price_type, self::ACTION_EDIT), |
|
| 175 | + stripslashes($price_type->name()), |
|
| 176 | + sprintf( |
|
| 177 | + /* translators: The name of the price type */ |
|
| 178 | + esc_attr__('Edit Price Type (%s)', 'event_espresso'), |
|
| 179 | + $price_type->name() |
|
| 180 | + ) |
|
| 181 | + ); |
|
| 182 | + |
|
| 183 | + $actions['edit'] = $this->getActionLink( |
|
| 184 | + $this->getActionUrl($price_type, self::ACTION_EDIT), |
|
| 185 | + esc_html__('Edit', 'event_espresso'), |
|
| 186 | + sprintf( |
|
| 187 | + /* translators: The name of the price type */ |
|
| 188 | + esc_attr__('Edit Price Type (%s)', 'event_espresso'), |
|
| 189 | + $price_type->name() |
|
| 190 | + ) |
|
| 191 | + ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if ($price_type->base_type() !== 1) { |
|
| 195 | + if ($this->_view == 'all') { |
|
| 196 | + // trash price link |
|
| 197 | + if ( |
|
| 198 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 199 | + 'ee_delete_default_price_type', |
|
| 200 | + 'pricing_trash_price_type', |
|
| 201 | + $price_type->ID() |
|
| 202 | + ) |
|
| 203 | + ) { |
|
| 204 | + $actions['trash'] = $this->getActionLink( |
|
| 205 | + $this->getActionUrl($price_type, self::ACTION_TRASH), |
|
| 206 | + esc_html__('Trash', 'event_espresso'), |
|
| 207 | + sprintf( |
|
| 208 | + /* translators: The name of the price type */ |
|
| 209 | + esc_attr__('Move Price Type %s to Trash', 'event_espresso'), |
|
| 210 | + $price_type->name() |
|
| 211 | + ) |
|
| 212 | + ); |
|
| 213 | + } |
|
| 214 | + } else { |
|
| 215 | + // restore price link |
|
| 216 | + if ( |
|
| 217 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 218 | + 'ee_delete_default_price_type', |
|
| 219 | + 'pricing_restore_price_type', |
|
| 220 | + $price_type->ID() |
|
| 221 | + ) |
|
| 222 | + ) { |
|
| 223 | + $actions['restore'] = $this->getActionLink( |
|
| 224 | + $this->getActionUrl($price_type, self::ACTION_RESTORE), |
|
| 225 | + esc_html__('Restore', 'event_espresso'), |
|
| 226 | + sprintf( |
|
| 227 | + /* translators: The name of the price type */ |
|
| 228 | + esc_attr__('Restore Price Type (%s)', 'event_espresso'), |
|
| 229 | + $price_type->name() |
|
| 230 | + ) |
|
| 231 | + ); |
|
| 232 | + } |
|
| 233 | + // delete price link |
|
| 234 | + if ( |
|
| 235 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 236 | + 'ee_delete_default_price_type', |
|
| 237 | + 'pricing_delete_price_type', |
|
| 238 | + $price_type->ID() |
|
| 239 | + ) |
|
| 240 | + ) { |
|
| 241 | + $actions['delete'] = $this->getActionLink( |
|
| 242 | + $this->getActionUrl($price_type, self::ACTION_DELETE), |
|
| 243 | + esc_html__('Delete Permanently', 'event_espresso'), |
|
| 244 | + sprintf( |
|
| 245 | + /* translators: The name of the price type */ |
|
| 246 | + esc_attr__('Delete Price Type %s Permanently', 'event_espresso'), |
|
| 247 | + $price_type->name() |
|
| 248 | + ) |
|
| 249 | + ); |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + $content = $prep_content ? $name_link . $this->row_actions($actions) : $name_link; |
|
| 255 | + return $prep_content ? $this->columnContent('name', $content) : $content; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + public function column_base_type($price_type): string |
|
| 260 | + { |
|
| 261 | + return $this->columnContent('base_type', $price_type->base_type_name()); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + public function column_percent($price_type): string |
|
| 266 | + { |
|
| 267 | + $content = $price_type->is_percent() ? '%' : EE_Registry::instance()->CFG->currency->sign; |
|
| 268 | + return $this->columnContent('percent', $content, 'center'); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + public function column_order($price_type): string |
|
| 273 | + { |
|
| 274 | + return $this->columnContent('order', $price_type->order(), 'end'); |
|
| 275 | + } |
|
| 276 | 276 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | maxlength='245' |
| 82 | 82 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_name]" |
| 83 | 83 | placeholder="<?php |
| 84 | - esc_html_e('Ticket Title', 'event_espresso') ?>" |
|
| 84 | + esc_html_e('Ticket Title', 'event_espresso') ?>" |
|
| 85 | 85 | value="<?php echo esc_attr($TKT_name); ?>" |
| 86 | 86 | /> |
| 87 | 87 | </td> |
@@ -279,11 +279,11 @@ discard block |
||
| 279 | 279 | <div class="ee-editor-id-container"> |
| 280 | 280 | <h3 class="ee-item-id"> |
| 281 | 281 | <?php |
| 282 | - echo esc_html( |
|
| 283 | - $TKT_ID |
|
| 284 | - ? sprintf(__('Ticket ID: %d', 'event_espresso'), $TKT_ID) |
|
| 285 | - : '' |
|
| 286 | - ); ?> |
|
| 282 | + echo esc_html( |
|
| 283 | + $TKT_ID |
|
| 284 | + ? sprintf(__('Ticket ID: %d', 'event_espresso'), $TKT_ID) |
|
| 285 | + : '' |
|
| 286 | + ); ?> |
|
| 287 | 287 | </h3> |
| 288 | 288 | </div> |
| 289 | 289 | <div class="basic-ticket-container"> |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | for='edit-ticket-TKT_uses-<?php echo esc_attr($tkt_row); ?>' |
| 344 | 344 | > |
| 345 | 345 | <?php |
| 346 | - esc_html_e('Ticket Uses', 'event_espresso') ?> |
|
| 346 | + esc_html_e('Ticket Uses', 'event_espresso') ?> |
|
| 347 | 347 | </label> |
| 348 | 348 | <input type="text" |
| 349 | 349 | class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | /> |
| 363 | 363 | <label class='screen-reader-text' for='disabled-ticket-TKT_min-<?php echo esc_attr($tkt_row);?>'> |
| 364 | 364 | <?php |
| 365 | - esc_html_e('Minimum Quantity', 'event_espresso') ?> |
|
| 365 | + esc_html_e('Minimum Quantity', 'event_espresso') ?> |
|
| 366 | 366 | </label> |
| 367 | 367 | <input type="text" disabled |
| 368 | 368 | class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" |
@@ -427,14 +427,14 @@ discard block |
||
| 427 | 427 | id="edit-ticket-TKT_required-<?php echo esc_attr($tkt_row); ?>" |
| 428 | 428 | value="1" |
| 429 | 429 | <?php |
| 430 | - echo esc_attr($TKT_required ? ' checked' : ''); |
|
| 431 | - echo esc_attr($disabled ? ' disabled' : ''); |
|
| 432 | - ?> |
|
| 430 | + echo esc_attr($TKT_required ? ' checked' : ''); |
|
| 431 | + echo esc_attr($disabled ? ' disabled' : ''); |
|
| 432 | + ?> |
|
| 433 | 433 | /> |
| 434 | 434 | <?php esc_html_e( |
| 435 | - 'This ticket is required (will appear first in frontend ticket lists).', |
|
| 436 | - 'event_espresso' |
|
| 437 | - ); ?> |
|
| 435 | + 'This ticket is required (will appear first in frontend ticket lists).', |
|
| 436 | + 'event_espresso' |
|
| 437 | + ); ?> |
|
| 438 | 438 | </label> |
| 439 | 439 | </div> |
| 440 | 440 | <div class="ticket-is-taxable-container"> |
@@ -537,19 +537,19 @@ discard block |
||
| 537 | 537 | <h4 class="tickets-heading"><?php esc_html_e('Event Datetimes', 'event_espresso'); ?></h4> |
| 538 | 538 | <p> |
| 539 | 539 | <?php esc_html_e( |
| 540 | - 'This ticket will be usable (allow entrance) for the following selected event datetimes (click to select). The "# Datetimes" amount (above) indicates how many of the assigned datetimes the ticket holder can gain access to:', |
|
| 541 | - 'event_espresso' |
|
| 542 | - ); ?> |
|
| 540 | + 'This ticket will be usable (allow entrance) for the following selected event datetimes (click to select). The "# Datetimes" amount (above) indicates how many of the assigned datetimes the ticket holder can gain access to:', |
|
| 541 | + 'event_espresso' |
|
| 542 | + ); ?> |
|
| 543 | 543 | </p> |
| 544 | 544 | <ul class="datetime-tickets-list"> |
| 545 | 545 | <?php echo wp_kses($ticket_datetimes_list, AllowedTags::getWithFormTags()); ?> |
| 546 | 546 | </ul> |
| 547 | 547 | |
| 548 | 548 | <?php do_action( |
| 549 | - 'AHEE__event_tickets_datetime_ticket_row_template__advanced_details_end', |
|
| 550 | - $tkt_row, |
|
| 551 | - $TKT_ID |
|
| 552 | - ); ?> |
|
| 549 | + 'AHEE__event_tickets_datetime_ticket_row_template__advanced_details_end', |
|
| 550 | + $tkt_row, |
|
| 551 | + $TKT_ID |
|
| 552 | + ); ?> |
|
| 553 | 553 | <div class="ee-editor-footer-container"> |
| 554 | 554 | <div class="ee-layout-row ee-layout-row--spaced"> |
| 555 | 555 | <label for="edit-ticket-TKT_is_default_selector-<?php echo esc_attr($tkt_row); ?>"> |
@@ -561,9 +561,9 @@ discard block |
||
| 561 | 561 | <?php echo esc_attr($disabled ? ' disabled' : ''); ?> |
| 562 | 562 | /> |
| 563 | 563 | <?php esc_html_e( |
| 564 | - 'use this new ticket as a default ticket for any new events', |
|
| 565 | - 'event_espresso' |
|
| 566 | - ); ?> |
|
| 564 | + 'use this new ticket as a default ticket for any new events', |
|
| 565 | + 'event_espresso' |
|
| 566 | + ); ?> |
|
| 567 | 567 | </label> |
| 568 | 568 | <input type="hidden" |
| 569 | 569 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_is_default]" |
@@ -13,285 +13,285 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class Prices_List_Table extends EE_Admin_List_Table |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @var Pricing_Admin_Page |
|
| 18 | - */ |
|
| 19 | - protected EE_Admin_Page $_admin_page; |
|
| 20 | - |
|
| 21 | - protected EEM_Price_Type $_PRT; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var EE_Price_Type[] |
|
| 25 | - */ |
|
| 26 | - protected array $_price_types = []; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @throws ReflectionException |
|
| 31 | - * @throws EE_Error |
|
| 32 | - */ |
|
| 33 | - public function __construct(EE_Admin_Page $admin_page) |
|
| 34 | - { |
|
| 35 | - parent::__construct($admin_page); |
|
| 36 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 37 | - $this->_PRT = EEM_Price_Type::instance(); |
|
| 38 | - $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted(); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @throws ReflectionException |
|
| 44 | - * @throws EE_Error |
|
| 45 | - */ |
|
| 46 | - protected function _setup_data() |
|
| 47 | - { |
|
| 48 | - $trashed = $this->_admin_page->get_view() === 'trashed'; |
|
| 49 | - $this->_data = $this->_admin_page->get_prices_overview_data($this->_per_page, false, $trashed); |
|
| 50 | - $this->_all_data_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true); |
|
| 51 | - $this->_trashed_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, true); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - protected function _set_properties() |
|
| 56 | - { |
|
| 57 | - $this->_wp_list_args = [ |
|
| 58 | - 'singular' => esc_html__('price', 'event_espresso'), |
|
| 59 | - 'plural' => esc_html__('prices', 'event_espresso'), |
|
| 60 | - 'ajax' => true, |
|
| 61 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 62 | - ]; |
|
| 63 | - |
|
| 64 | - $this->_columns = [ |
|
| 65 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
| 66 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
| 67 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
| 68 | - 'type' => esc_html__('Price Type', 'event_espresso'), |
|
| 69 | - 'description' => esc_html__('Description', 'event_espresso'), |
|
| 70 | - 'amount' => esc_html__('Amount', 'event_espresso'), |
|
| 71 | - ]; |
|
| 72 | - $this->_primary_column = 'id'; |
|
| 73 | - |
|
| 74 | - $this->_sortable_columns = [ |
|
| 75 | - // true means its already sorted |
|
| 76 | - 'name' => ['name' => false], |
|
| 77 | - 'type' => ['type' => false], |
|
| 78 | - 'amount' => ['amount' => false], |
|
| 79 | - ]; |
|
| 80 | - |
|
| 81 | - $this->_hidden_columns = []; |
|
| 82 | - |
|
| 83 | - $this->_ajax_sorting_callback = 'update_prices_order'; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - protected function _get_table_filters() |
|
| 88 | - { |
|
| 89 | - return []; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - protected function _add_view_counts() |
|
| 94 | - { |
|
| 95 | - $this->_views['all']['count'] = $this->_all_data_count; |
|
| 96 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
| 97 | - $this->_views['trashed']['count'] = $this->_trashed_count; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * overriding parent method so that we can make sure the row isn't sortable for certain items |
|
| 104 | - * |
|
| 105 | - * @param object $item the current item |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - protected function _get_row_class($item) |
|
| 109 | - { |
|
| 110 | - return $item->type_obj() instanceof EE_Price_Type |
|
| 111 | - && $item->type_obj()->base_type() !== 1 |
|
| 112 | - && $item->type_obj()->base_type() !== 4 |
|
| 113 | - ? ' class="rowsortable"' |
|
| 114 | - : ''; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @param EE_Price $price |
|
| 120 | - * @param string $action |
|
| 121 | - * @return string |
|
| 122 | - * @throws EE_Error |
|
| 123 | - * @throws ReflectionException |
|
| 124 | - * @since 5.0.0.p |
|
| 125 | - */ |
|
| 126 | - protected function getActionUrl(EE_Price $price, string $action): string |
|
| 127 | - { |
|
| 128 | - if (! in_array($action, self::$actions)) { |
|
| 129 | - throw new DomainException(esc_html__('Invalid Action', 'event_espresso')); |
|
| 130 | - } |
|
| 131 | - return EE_Admin_Page::add_query_args_and_nonce( |
|
| 132 | - [ |
|
| 133 | - 'action' => "{$action}_price", |
|
| 134 | - 'id' => $price->ID(), |
|
| 135 | - 'noheader' => $action !== self::ACTION_EDIT, |
|
| 136 | - ], |
|
| 137 | - PRICING_ADMIN_URL |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - public function column_cb($item) |
|
| 143 | - { |
|
| 144 | - return $item->type_obj() instanceof EE_Price_Type && $item->type_obj()->base_type() !== 1 |
|
| 145 | - ? sprintf( |
|
| 146 | - '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
| 147 | - $item->ID() |
|
| 148 | - ) |
|
| 149 | - : ''; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param EE_Price $item |
|
| 155 | - * @return string |
|
| 156 | - * @throws EE_Error |
|
| 157 | - * @throws ReflectionException |
|
| 158 | - */ |
|
| 159 | - public function column_id($item) |
|
| 160 | - { |
|
| 161 | - $content = '<span class="ee-entity-id">' . $item->ID() . '</span>'; |
|
| 162 | - $content .= '<span class="show-on-mobile-view-only">' . $this->column_name($item, false) . '</span>'; |
|
| 163 | - return $this->columnContent('id', $content, 'end'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param EE_Price $price |
|
| 169 | - * @param bool $prep_content |
|
| 170 | - * @return string |
|
| 171 | - * @throws EE_Error |
|
| 172 | - * @throws ReflectionException |
|
| 173 | - */ |
|
| 174 | - public function column_name(EE_Price $price, bool $prep_content = true): string |
|
| 175 | - { |
|
| 176 | - |
|
| 177 | - // Build row actions |
|
| 178 | - $actions = []; |
|
| 179 | - // edit price link |
|
| 180 | - if ( |
|
| 181 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 182 | - 'ee_edit_default_price', |
|
| 183 | - 'pricing_edit_price', |
|
| 184 | - $price->ID() |
|
| 185 | - ) |
|
| 186 | - ) { |
|
| 187 | - $actions['edit'] = $this->getActionLink( |
|
| 188 | - $this->getActionUrl($price, self::ACTION_EDIT), |
|
| 189 | - esc_html__('Edit', 'event_espresso'), |
|
| 190 | - esc_attr__('Edit Price', 'event_espresso') |
|
| 191 | - ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
| 195 | - 'ee_edit_default_price', |
|
| 196 | - 'edit_price', |
|
| 197 | - $price->ID() |
|
| 198 | - ) |
|
| 199 | - ? $this->getActionLink( |
|
| 200 | - $this->getActionUrl($price, self::ACTION_EDIT), |
|
| 201 | - stripslashes($price->name()), |
|
| 202 | - esc_attr__('Edit Price', 'event_espresso') |
|
| 203 | - ) |
|
| 204 | - : $price->name(); |
|
| 205 | - |
|
| 206 | - if ($price->type_obj() instanceof EE_Price_Type && $price->type_obj()->base_type() !== 1) { |
|
| 207 | - if ($this->_view == 'all') { |
|
| 208 | - // trash price link |
|
| 209 | - if ( |
|
| 210 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 211 | - 'ee_delete_default_price', |
|
| 212 | - 'pricing_trash_price', |
|
| 213 | - $price->ID() |
|
| 214 | - ) |
|
| 215 | - ) { |
|
| 216 | - $actions['trash'] = $this->getActionLink( |
|
| 217 | - $this->getActionUrl($price, self::ACTION_TRASH), |
|
| 218 | - esc_html__('Trash', 'event_espresso'), |
|
| 219 | - esc_attr__('Move Price to Trash', 'event_espresso') |
|
| 220 | - ); |
|
| 221 | - } |
|
| 222 | - } else { |
|
| 223 | - if ( |
|
| 224 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 225 | - 'ee_delete_default_price', |
|
| 226 | - 'pricing_restore_price', |
|
| 227 | - $price->ID() |
|
| 228 | - ) |
|
| 229 | - ) { |
|
| 230 | - $actions['restore'] = $this->getActionLink( |
|
| 231 | - $this->getActionUrl($price, self::ACTION_RESTORE), |
|
| 232 | - esc_html__('Restore', 'event_espresso'), |
|
| 233 | - esc_attr__('Restore Price', 'event_espresso') |
|
| 234 | - ); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // delete price link |
|
| 238 | - if ( |
|
| 239 | - EE_Registry::instance()->CAP->current_user_can( |
|
| 240 | - 'ee_delete_default_price', |
|
| 241 | - 'pricing_delete_price', |
|
| 242 | - $price->ID() |
|
| 243 | - ) |
|
| 244 | - ) { |
|
| 245 | - $actions['delete'] = $this->getActionLink( |
|
| 246 | - $this->getActionUrl($price, self::ACTION_DELETE), |
|
| 247 | - esc_html__('Delete Permanently', 'event_espresso'), |
|
| 248 | - esc_attr__('Delete Price Permanently', 'event_espresso') |
|
| 249 | - ); |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - $content = $prep_content ? $name_link . $this->row_actions($actions) : $name_link; |
|
| 255 | - return $prep_content ? $this->columnContent('name', $content) : $content; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @throws EE_Error |
|
| 261 | - * @throws ReflectionException |
|
| 262 | - */ |
|
| 263 | - public function column_type(EE_Price $price): string |
|
| 264 | - { |
|
| 265 | - $content = isset($this->_price_types[ $price->type() ]) |
|
| 266 | - ? $this->_price_types[ $price->type() ]->name() |
|
| 267 | - : ''; |
|
| 268 | - return $this->columnContent('type', $content); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * @throws EE_Error |
|
| 274 | - * @throws ReflectionException |
|
| 275 | - */ |
|
| 276 | - public function column_description(EE_Price $price): string |
|
| 277 | - { |
|
| 278 | - $content = stripslashes($price->desc()); |
|
| 279 | - return $this->columnContent('description', $content); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * @throws EE_Error |
|
| 285 | - * @throws ReflectionException |
|
| 286 | - */ |
|
| 287 | - public function column_amount(EE_Price $price): string |
|
| 288 | - { |
|
| 289 | - $price_type = isset($this->_price_types[ $price->type() ]) |
|
| 290 | - ? $this->_price_types[ $price->type() ] |
|
| 291 | - : null; |
|
| 292 | - $content = $price_type instanceof EE_Price_Type && $price_type->is_percent() ? |
|
| 293 | - '<div class="pad-amnt-rght">' . number_format($price->amount(), 1) . '%</div>' |
|
| 294 | - : '<div class="pad-amnt-rght">' . EEH_Template::format_currency($price->amount()) . '</div>'; |
|
| 295 | - return $this->columnContent('amount', $content, 'end'); |
|
| 296 | - } |
|
| 16 | + /** |
|
| 17 | + * @var Pricing_Admin_Page |
|
| 18 | + */ |
|
| 19 | + protected EE_Admin_Page $_admin_page; |
|
| 20 | + |
|
| 21 | + protected EEM_Price_Type $_PRT; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var EE_Price_Type[] |
|
| 25 | + */ |
|
| 26 | + protected array $_price_types = []; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @throws ReflectionException |
|
| 31 | + * @throws EE_Error |
|
| 32 | + */ |
|
| 33 | + public function __construct(EE_Admin_Page $admin_page) |
|
| 34 | + { |
|
| 35 | + parent::__construct($admin_page); |
|
| 36 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 37 | + $this->_PRT = EEM_Price_Type::instance(); |
|
| 38 | + $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted(); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @throws ReflectionException |
|
| 44 | + * @throws EE_Error |
|
| 45 | + */ |
|
| 46 | + protected function _setup_data() |
|
| 47 | + { |
|
| 48 | + $trashed = $this->_admin_page->get_view() === 'trashed'; |
|
| 49 | + $this->_data = $this->_admin_page->get_prices_overview_data($this->_per_page, false, $trashed); |
|
| 50 | + $this->_all_data_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true); |
|
| 51 | + $this->_trashed_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, true); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + protected function _set_properties() |
|
| 56 | + { |
|
| 57 | + $this->_wp_list_args = [ |
|
| 58 | + 'singular' => esc_html__('price', 'event_espresso'), |
|
| 59 | + 'plural' => esc_html__('prices', 'event_espresso'), |
|
| 60 | + 'ajax' => true, |
|
| 61 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 62 | + ]; |
|
| 63 | + |
|
| 64 | + $this->_columns = [ |
|
| 65 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
| 66 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
| 67 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
| 68 | + 'type' => esc_html__('Price Type', 'event_espresso'), |
|
| 69 | + 'description' => esc_html__('Description', 'event_espresso'), |
|
| 70 | + 'amount' => esc_html__('Amount', 'event_espresso'), |
|
| 71 | + ]; |
|
| 72 | + $this->_primary_column = 'id'; |
|
| 73 | + |
|
| 74 | + $this->_sortable_columns = [ |
|
| 75 | + // true means its already sorted |
|
| 76 | + 'name' => ['name' => false], |
|
| 77 | + 'type' => ['type' => false], |
|
| 78 | + 'amount' => ['amount' => false], |
|
| 79 | + ]; |
|
| 80 | + |
|
| 81 | + $this->_hidden_columns = []; |
|
| 82 | + |
|
| 83 | + $this->_ajax_sorting_callback = 'update_prices_order'; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + protected function _get_table_filters() |
|
| 88 | + { |
|
| 89 | + return []; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + protected function _add_view_counts() |
|
| 94 | + { |
|
| 95 | + $this->_views['all']['count'] = $this->_all_data_count; |
|
| 96 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
| 97 | + $this->_views['trashed']['count'] = $this->_trashed_count; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * overriding parent method so that we can make sure the row isn't sortable for certain items |
|
| 104 | + * |
|
| 105 | + * @param object $item the current item |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + protected function _get_row_class($item) |
|
| 109 | + { |
|
| 110 | + return $item->type_obj() instanceof EE_Price_Type |
|
| 111 | + && $item->type_obj()->base_type() !== 1 |
|
| 112 | + && $item->type_obj()->base_type() !== 4 |
|
| 113 | + ? ' class="rowsortable"' |
|
| 114 | + : ''; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @param EE_Price $price |
|
| 120 | + * @param string $action |
|
| 121 | + * @return string |
|
| 122 | + * @throws EE_Error |
|
| 123 | + * @throws ReflectionException |
|
| 124 | + * @since 5.0.0.p |
|
| 125 | + */ |
|
| 126 | + protected function getActionUrl(EE_Price $price, string $action): string |
|
| 127 | + { |
|
| 128 | + if (! in_array($action, self::$actions)) { |
|
| 129 | + throw new DomainException(esc_html__('Invalid Action', 'event_espresso')); |
|
| 130 | + } |
|
| 131 | + return EE_Admin_Page::add_query_args_and_nonce( |
|
| 132 | + [ |
|
| 133 | + 'action' => "{$action}_price", |
|
| 134 | + 'id' => $price->ID(), |
|
| 135 | + 'noheader' => $action !== self::ACTION_EDIT, |
|
| 136 | + ], |
|
| 137 | + PRICING_ADMIN_URL |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + public function column_cb($item) |
|
| 143 | + { |
|
| 144 | + return $item->type_obj() instanceof EE_Price_Type && $item->type_obj()->base_type() !== 1 |
|
| 145 | + ? sprintf( |
|
| 146 | + '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
| 147 | + $item->ID() |
|
| 148 | + ) |
|
| 149 | + : ''; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param EE_Price $item |
|
| 155 | + * @return string |
|
| 156 | + * @throws EE_Error |
|
| 157 | + * @throws ReflectionException |
|
| 158 | + */ |
|
| 159 | + public function column_id($item) |
|
| 160 | + { |
|
| 161 | + $content = '<span class="ee-entity-id">' . $item->ID() . '</span>'; |
|
| 162 | + $content .= '<span class="show-on-mobile-view-only">' . $this->column_name($item, false) . '</span>'; |
|
| 163 | + return $this->columnContent('id', $content, 'end'); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param EE_Price $price |
|
| 169 | + * @param bool $prep_content |
|
| 170 | + * @return string |
|
| 171 | + * @throws EE_Error |
|
| 172 | + * @throws ReflectionException |
|
| 173 | + */ |
|
| 174 | + public function column_name(EE_Price $price, bool $prep_content = true): string |
|
| 175 | + { |
|
| 176 | + |
|
| 177 | + // Build row actions |
|
| 178 | + $actions = []; |
|
| 179 | + // edit price link |
|
| 180 | + if ( |
|
| 181 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 182 | + 'ee_edit_default_price', |
|
| 183 | + 'pricing_edit_price', |
|
| 184 | + $price->ID() |
|
| 185 | + ) |
|
| 186 | + ) { |
|
| 187 | + $actions['edit'] = $this->getActionLink( |
|
| 188 | + $this->getActionUrl($price, self::ACTION_EDIT), |
|
| 189 | + esc_html__('Edit', 'event_espresso'), |
|
| 190 | + esc_attr__('Edit Price', 'event_espresso') |
|
| 191 | + ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
| 195 | + 'ee_edit_default_price', |
|
| 196 | + 'edit_price', |
|
| 197 | + $price->ID() |
|
| 198 | + ) |
|
| 199 | + ? $this->getActionLink( |
|
| 200 | + $this->getActionUrl($price, self::ACTION_EDIT), |
|
| 201 | + stripslashes($price->name()), |
|
| 202 | + esc_attr__('Edit Price', 'event_espresso') |
|
| 203 | + ) |
|
| 204 | + : $price->name(); |
|
| 205 | + |
|
| 206 | + if ($price->type_obj() instanceof EE_Price_Type && $price->type_obj()->base_type() !== 1) { |
|
| 207 | + if ($this->_view == 'all') { |
|
| 208 | + // trash price link |
|
| 209 | + if ( |
|
| 210 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 211 | + 'ee_delete_default_price', |
|
| 212 | + 'pricing_trash_price', |
|
| 213 | + $price->ID() |
|
| 214 | + ) |
|
| 215 | + ) { |
|
| 216 | + $actions['trash'] = $this->getActionLink( |
|
| 217 | + $this->getActionUrl($price, self::ACTION_TRASH), |
|
| 218 | + esc_html__('Trash', 'event_espresso'), |
|
| 219 | + esc_attr__('Move Price to Trash', 'event_espresso') |
|
| 220 | + ); |
|
| 221 | + } |
|
| 222 | + } else { |
|
| 223 | + if ( |
|
| 224 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 225 | + 'ee_delete_default_price', |
|
| 226 | + 'pricing_restore_price', |
|
| 227 | + $price->ID() |
|
| 228 | + ) |
|
| 229 | + ) { |
|
| 230 | + $actions['restore'] = $this->getActionLink( |
|
| 231 | + $this->getActionUrl($price, self::ACTION_RESTORE), |
|
| 232 | + esc_html__('Restore', 'event_espresso'), |
|
| 233 | + esc_attr__('Restore Price', 'event_espresso') |
|
| 234 | + ); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // delete price link |
|
| 238 | + if ( |
|
| 239 | + EE_Registry::instance()->CAP->current_user_can( |
|
| 240 | + 'ee_delete_default_price', |
|
| 241 | + 'pricing_delete_price', |
|
| 242 | + $price->ID() |
|
| 243 | + ) |
|
| 244 | + ) { |
|
| 245 | + $actions['delete'] = $this->getActionLink( |
|
| 246 | + $this->getActionUrl($price, self::ACTION_DELETE), |
|
| 247 | + esc_html__('Delete Permanently', 'event_espresso'), |
|
| 248 | + esc_attr__('Delete Price Permanently', 'event_espresso') |
|
| 249 | + ); |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + $content = $prep_content ? $name_link . $this->row_actions($actions) : $name_link; |
|
| 255 | + return $prep_content ? $this->columnContent('name', $content) : $content; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @throws EE_Error |
|
| 261 | + * @throws ReflectionException |
|
| 262 | + */ |
|
| 263 | + public function column_type(EE_Price $price): string |
|
| 264 | + { |
|
| 265 | + $content = isset($this->_price_types[ $price->type() ]) |
|
| 266 | + ? $this->_price_types[ $price->type() ]->name() |
|
| 267 | + : ''; |
|
| 268 | + return $this->columnContent('type', $content); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * @throws EE_Error |
|
| 274 | + * @throws ReflectionException |
|
| 275 | + */ |
|
| 276 | + public function column_description(EE_Price $price): string |
|
| 277 | + { |
|
| 278 | + $content = stripslashes($price->desc()); |
|
| 279 | + return $this->columnContent('description', $content); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * @throws EE_Error |
|
| 285 | + * @throws ReflectionException |
|
| 286 | + */ |
|
| 287 | + public function column_amount(EE_Price $price): string |
|
| 288 | + { |
|
| 289 | + $price_type = isset($this->_price_types[ $price->type() ]) |
|
| 290 | + ? $this->_price_types[ $price->type() ] |
|
| 291 | + : null; |
|
| 292 | + $content = $price_type instanceof EE_Price_Type && $price_type->is_percent() ? |
|
| 293 | + '<div class="pad-amnt-rght">' . number_format($price->amount(), 1) . '%</div>' |
|
| 294 | + : '<div class="pad-amnt-rght">' . EEH_Template::format_currency($price->amount()) . '</div>'; |
|
| 295 | + return $this->columnContent('amount', $content, 'end'); |
|
| 296 | + } |
|
| 297 | 297 | } |