@@ -6,285 +6,285 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Attributes |
| 8 | 8 | { |
| 9 | - const ATTRIBUTES_A = [ |
|
| 10 | - 'download', 'href', 'hreflang', 'ping', 'referrerpolicy', 'rel', 'target', 'type', |
|
| 11 | - ]; |
|
| 9 | + const ATTRIBUTES_A = [ |
|
| 10 | + 'download', 'href', 'hreflang', 'ping', 'referrerpolicy', 'rel', 'target', 'type', |
|
| 11 | + ]; |
|
| 12 | 12 | |
| 13 | - const ATTRIBUTES_BUTTON = [ |
|
| 14 | - 'autofocus', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod', |
|
| 15 | - 'formnovalidate', 'formtarget', 'name', 'type', 'value', |
|
| 16 | - ]; |
|
| 13 | + const ATTRIBUTES_BUTTON = [ |
|
| 14 | + 'autofocus', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod', |
|
| 15 | + 'formnovalidate', 'formtarget', 'name', 'type', 'value', |
|
| 16 | + ]; |
|
| 17 | 17 | |
| 18 | - const ATTRIBUTES_FORM = [ |
|
| 19 | - 'accept', 'accept-charset', 'action', 'autocapitalize', 'autocomplete', 'enctype', 'method', |
|
| 20 | - 'name', 'novalidate', 'target', |
|
| 21 | - ]; |
|
| 18 | + const ATTRIBUTES_FORM = [ |
|
| 19 | + 'accept', 'accept-charset', 'action', 'autocapitalize', 'autocomplete', 'enctype', 'method', |
|
| 20 | + 'name', 'novalidate', 'target', |
|
| 21 | + ]; |
|
| 22 | 22 | |
| 23 | - const ATTRIBUTES_IMG = [ |
|
| 24 | - 'alt', 'crossorigin', 'decoding', 'height', 'ismap', 'referrerpolicy', 'sizes', 'src', |
|
| 25 | - 'srcset', 'width', 'usemap', |
|
| 26 | - ]; |
|
| 23 | + const ATTRIBUTES_IMG = [ |
|
| 24 | + 'alt', 'crossorigin', 'decoding', 'height', 'ismap', 'referrerpolicy', 'sizes', 'src', |
|
| 25 | + 'srcset', 'width', 'usemap', |
|
| 26 | + ]; |
|
| 27 | 27 | |
| 28 | - const ATTRIBUTES_INPUT = [ |
|
| 29 | - 'accept', 'autocomplete', 'autocorrect', 'autofocus', 'capture', 'checked', 'disabled', |
|
| 30 | - 'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height', |
|
| 31 | - 'incremental', 'inputmode', 'list', 'max', 'maxlength', 'min', 'minlength', 'multiple', |
|
| 32 | - 'name', 'pattern', 'placeholder', 'readonly', 'results', 'required', 'selectionDirection', |
|
| 33 | - 'selectionEnd', 'selectionStart', 'size', 'spellcheck', 'src', 'step', 'tabindex', 'type', |
|
| 34 | - 'value', 'webkitdirectory', 'width', |
|
| 35 | - ]; |
|
| 28 | + const ATTRIBUTES_INPUT = [ |
|
| 29 | + 'accept', 'autocomplete', 'autocorrect', 'autofocus', 'capture', 'checked', 'disabled', |
|
| 30 | + 'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height', |
|
| 31 | + 'incremental', 'inputmode', 'list', 'max', 'maxlength', 'min', 'minlength', 'multiple', |
|
| 32 | + 'name', 'pattern', 'placeholder', 'readonly', 'results', 'required', 'selectionDirection', |
|
| 33 | + 'selectionEnd', 'selectionStart', 'size', 'spellcheck', 'src', 'step', 'tabindex', 'type', |
|
| 34 | + 'value', 'webkitdirectory', 'width', |
|
| 35 | + ]; |
|
| 36 | 36 | |
| 37 | - const ATTRIBUTES_LABEL = [ |
|
| 38 | - 'for', |
|
| 39 | - ]; |
|
| 37 | + const ATTRIBUTES_LABEL = [ |
|
| 38 | + 'for', |
|
| 39 | + ]; |
|
| 40 | 40 | |
| 41 | - const ATTRIBUTES_OPTION = [ |
|
| 42 | - 'disabled', 'label', 'selected', 'value', |
|
| 43 | - ]; |
|
| 41 | + const ATTRIBUTES_OPTION = [ |
|
| 42 | + 'disabled', 'label', 'selected', 'value', |
|
| 43 | + ]; |
|
| 44 | 44 | |
| 45 | - const ATTRIBUTES_SELECT = [ |
|
| 46 | - 'autofocus', 'disabled', 'form', 'multiple', 'name', 'required', 'size', |
|
| 47 | - ]; |
|
| 45 | + const ATTRIBUTES_SELECT = [ |
|
| 46 | + 'autofocus', 'disabled', 'form', 'multiple', 'name', 'required', 'size', |
|
| 47 | + ]; |
|
| 48 | 48 | |
| 49 | - const ATTRIBUTES_TEXTAREA = [ |
|
| 50 | - 'autocapitalize', 'autocomplete', 'autofocus', 'cols', 'disabled', 'form', 'maxlength', |
|
| 51 | - 'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'spellcheck', 'wrap', |
|
| 52 | - ]; |
|
| 49 | + const ATTRIBUTES_TEXTAREA = [ |
|
| 50 | + 'autocapitalize', 'autocomplete', 'autofocus', 'cols', 'disabled', 'form', 'maxlength', |
|
| 51 | + 'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'spellcheck', 'wrap', |
|
| 52 | + ]; |
|
| 53 | 53 | |
| 54 | - const BOOLEAN_ATTRIBUTES = [ |
|
| 55 | - 'autofocus', 'capture', 'checked', 'disabled', 'draggable', 'formnovalidate', 'hidden', |
|
| 56 | - 'multiple', 'novalidate', 'readonly', 'required', 'selected', 'spellcheck', |
|
| 57 | - 'webkitdirectory', |
|
| 58 | - ]; |
|
| 54 | + const BOOLEAN_ATTRIBUTES = [ |
|
| 55 | + 'autofocus', 'capture', 'checked', 'disabled', 'draggable', 'formnovalidate', 'hidden', |
|
| 56 | + 'multiple', 'novalidate', 'readonly', 'required', 'selected', 'spellcheck', |
|
| 57 | + 'webkitdirectory', |
|
| 58 | + ]; |
|
| 59 | 59 | |
| 60 | - const GLOBAL_ATTRIBUTES = [ |
|
| 61 | - 'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone', |
|
| 62 | - 'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title', |
|
| 63 | - ]; |
|
| 60 | + const GLOBAL_ATTRIBUTES = [ |
|
| 61 | + 'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone', |
|
| 62 | + 'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title', |
|
| 63 | + ]; |
|
| 64 | 64 | |
| 65 | - const GLOBAL_WILDCARD_ATTRIBUTES = [ |
|
| 66 | - 'aria-', 'data-', 'item', 'on', |
|
| 67 | - ]; |
|
| 65 | + const GLOBAL_WILDCARD_ATTRIBUTES = [ |
|
| 66 | + 'aria-', 'data-', 'item', 'on', |
|
| 67 | + ]; |
|
| 68 | 68 | |
| 69 | - const INPUT_TYPES = [ |
|
| 70 | - 'button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', |
|
| 71 | - 'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', |
|
| 72 | - 'time', 'url', 'week', |
|
| 73 | - ]; |
|
| 69 | + const INPUT_TYPES = [ |
|
| 70 | + 'button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', |
|
| 71 | + 'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', |
|
| 72 | + 'time', 'url', 'week', |
|
| 73 | + ]; |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - protected $attributes = []; |
|
| 75 | + /** |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + protected $attributes = []; |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @param string $method |
|
| 82 | - * @param array $args |
|
| 83 | - * @return static |
|
| 84 | - */ |
|
| 85 | - public function __call($method, $args) |
|
| 86 | - { |
|
| 87 | - $args += [[], false]; |
|
| 88 | - $constant = 'static::ATTRIBUTES_'.strtoupper($method); |
|
| 89 | - $allowedAttributeKeys = defined($constant) |
|
| 90 | - ? constant($constant) |
|
| 91 | - : []; |
|
| 92 | - $this->normalize((array) $args[0], $allowedAttributeKeys); |
|
| 93 | - $this->normalizeInputType($method); |
|
| 94 | - return $this; |
|
| 95 | - } |
|
| 80 | + /** |
|
| 81 | + * @param string $method |
|
| 82 | + * @param array $args |
|
| 83 | + * @return static |
|
| 84 | + */ |
|
| 85 | + public function __call($method, $args) |
|
| 86 | + { |
|
| 87 | + $args += [[], false]; |
|
| 88 | + $constant = 'static::ATTRIBUTES_'.strtoupper($method); |
|
| 89 | + $allowedAttributeKeys = defined($constant) |
|
| 90 | + ? constant($constant) |
|
| 91 | + : []; |
|
| 92 | + $this->normalize((array) $args[0], $allowedAttributeKeys); |
|
| 93 | + $this->normalizeInputType($method); |
|
| 94 | + return $this; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @return array |
|
| 99 | - */ |
|
| 100 | - public function toArray() |
|
| 101 | - { |
|
| 102 | - return $this->attributes; |
|
| 103 | - } |
|
| 97 | + /** |
|
| 98 | + * @return array |
|
| 99 | + */ |
|
| 100 | + public function toArray() |
|
| 101 | + { |
|
| 102 | + return $this->attributes; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - public function toString() |
|
| 109 | - { |
|
| 110 | - $attributes = []; |
|
| 111 | - foreach ($this->attributes as $attribute => $value) { |
|
| 112 | - $quote = $this->getQuoteChar($attribute); |
|
| 113 | - $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES) |
|
| 114 | - ? $attribute |
|
| 115 | - : $attribute.'='.$quote.implode(',', (array) $value).$quote; |
|
| 116 | - } |
|
| 117 | - return implode(' ', $attributes); |
|
| 118 | - } |
|
| 105 | + /** |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + public function toString() |
|
| 109 | + { |
|
| 110 | + $attributes = []; |
|
| 111 | + foreach ($this->attributes as $attribute => $value) { |
|
| 112 | + $quote = $this->getQuoteChar($attribute); |
|
| 113 | + $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES) |
|
| 114 | + ? $attribute |
|
| 115 | + : $attribute.'='.$quote.implode(',', (array) $value).$quote; |
|
| 116 | + } |
|
| 117 | + return implode(' ', $attributes); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @return array |
|
| 122 | - */ |
|
| 123 | - protected function filterAttributes(array $allowedAttributeKeys) |
|
| 124 | - { |
|
| 125 | - return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys)); |
|
| 126 | - } |
|
| 120 | + /** |
|
| 121 | + * @return array |
|
| 122 | + */ |
|
| 123 | + protected function filterAttributes(array $allowedAttributeKeys) |
|
| 124 | + { |
|
| 125 | + return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys)); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * @return array |
|
| 130 | - */ |
|
| 131 | - protected function filterGlobalAttributes() |
|
| 132 | - { |
|
| 133 | - $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES); |
|
| 134 | - $wildcards = []; |
|
| 135 | - foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) { |
|
| 136 | - $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) { |
|
| 137 | - return Str::startsWith($wildcard, $key); |
|
| 138 | - }, ARRAY_FILTER_USE_KEY); |
|
| 139 | - $wildcards = array_merge($wildcards, $newWildcards); |
|
| 140 | - } |
|
| 141 | - return array_merge($globalAttributes, $wildcards); |
|
| 142 | - } |
|
| 128 | + /** |
|
| 129 | + * @return array |
|
| 130 | + */ |
|
| 131 | + protected function filterGlobalAttributes() |
|
| 132 | + { |
|
| 133 | + $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES); |
|
| 134 | + $wildcards = []; |
|
| 135 | + foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) { |
|
| 136 | + $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) { |
|
| 137 | + return Str::startsWith($wildcard, $key); |
|
| 138 | + }, ARRAY_FILTER_USE_KEY); |
|
| 139 | + $wildcards = array_merge($wildcards, $newWildcards); |
|
| 140 | + } |
|
| 141 | + return array_merge($globalAttributes, $wildcards); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * @return array |
|
| 146 | - */ |
|
| 147 | - protected function getPermanentAttributes() |
|
| 148 | - { |
|
| 149 | - $permanentAttributes = []; |
|
| 150 | - if (array_key_exists('value', $this->attributes)) { |
|
| 151 | - $permanentAttributes['value'] = $this->attributes['value']; |
|
| 152 | - } |
|
| 153 | - return $permanentAttributes; |
|
| 154 | - } |
|
| 144 | + /** |
|
| 145 | + * @return array |
|
| 146 | + */ |
|
| 147 | + protected function getPermanentAttributes() |
|
| 148 | + { |
|
| 149 | + $permanentAttributes = []; |
|
| 150 | + if (array_key_exists('value', $this->attributes)) { |
|
| 151 | + $permanentAttributes['value'] = $this->attributes['value']; |
|
| 152 | + } |
|
| 153 | + return $permanentAttributes; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * @param string $attribute |
|
| 158 | - * @return string |
|
| 159 | - */ |
|
| 160 | - protected function getQuoteChar($attribute) |
|
| 161 | - { |
|
| 162 | - return Str::startsWith('data-', $attribute) |
|
| 163 | - ? '\'' |
|
| 164 | - : '"'; |
|
| 165 | - } |
|
| 156 | + /** |
|
| 157 | + * @param string $attribute |
|
| 158 | + * @return string |
|
| 159 | + */ |
|
| 160 | + protected function getQuoteChar($attribute) |
|
| 161 | + { |
|
| 162 | + return Str::startsWith('data-', $attribute) |
|
| 163 | + ? '\'' |
|
| 164 | + : '"'; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * @param string $key |
|
| 169 | - * @param mixed $value |
|
| 170 | - * @return bool |
|
| 171 | - */ |
|
| 172 | - protected function isAttributeKeyNumeric($key, $value) |
|
| 173 | - { |
|
| 174 | - return is_string($value) |
|
| 175 | - && is_numeric($key) |
|
| 176 | - && !array_key_exists($value, $this->attributes); |
|
| 177 | - } |
|
| 167 | + /** |
|
| 168 | + * @param string $key |
|
| 169 | + * @param mixed $value |
|
| 170 | + * @return bool |
|
| 171 | + */ |
|
| 172 | + protected function isAttributeKeyNumeric($key, $value) |
|
| 173 | + { |
|
| 174 | + return is_string($value) |
|
| 175 | + && is_numeric($key) |
|
| 176 | + && !array_key_exists($value, $this->attributes); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * @return void |
|
| 181 | - */ |
|
| 182 | - protected function normalize(array $args, array $allowedAttributeKeys) |
|
| 183 | - { |
|
| 184 | - $this->attributes = array_change_key_case($args, CASE_LOWER); |
|
| 185 | - $this->normalizeBooleanAttributes(); |
|
| 186 | - $this->normalizeDataAttributes(); |
|
| 187 | - $this->normalizeStringAttributes(); |
|
| 188 | - $this->removeEmptyAttributes(); |
|
| 189 | - $this->removeIndexedAttributes(); |
|
| 190 | - $this->attributes = array_merge( |
|
| 191 | - $this->filterGlobalAttributes(), |
|
| 192 | - $this->filterAttributes($allowedAttributeKeys) |
|
| 193 | - ); |
|
| 194 | - } |
|
| 179 | + /** |
|
| 180 | + * @return void |
|
| 181 | + */ |
|
| 182 | + protected function normalize(array $args, array $allowedAttributeKeys) |
|
| 183 | + { |
|
| 184 | + $this->attributes = array_change_key_case($args, CASE_LOWER); |
|
| 185 | + $this->normalizeBooleanAttributes(); |
|
| 186 | + $this->normalizeDataAttributes(); |
|
| 187 | + $this->normalizeStringAttributes(); |
|
| 188 | + $this->removeEmptyAttributes(); |
|
| 189 | + $this->removeIndexedAttributes(); |
|
| 190 | + $this->attributes = array_merge( |
|
| 191 | + $this->filterGlobalAttributes(), |
|
| 192 | + $this->filterAttributes($allowedAttributeKeys) |
|
| 193 | + ); |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * @return void |
|
| 198 | - */ |
|
| 199 | - protected function normalizeBooleanAttributes() |
|
| 200 | - { |
|
| 201 | - foreach ($this->attributes as $key => $value) { |
|
| 202 | - if ($this->isAttributeKeyNumeric($key, $value)) { |
|
| 203 | - $key = $value; |
|
| 204 | - $value = true; |
|
| 205 | - } |
|
| 206 | - if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) { |
|
| 207 | - continue; |
|
| 208 | - } |
|
| 209 | - $this->attributes[$key] = wp_validate_boolean($value); |
|
| 210 | - } |
|
| 211 | - } |
|
| 196 | + /** |
|
| 197 | + * @return void |
|
| 198 | + */ |
|
| 199 | + protected function normalizeBooleanAttributes() |
|
| 200 | + { |
|
| 201 | + foreach ($this->attributes as $key => $value) { |
|
| 202 | + if ($this->isAttributeKeyNumeric($key, $value)) { |
|
| 203 | + $key = $value; |
|
| 204 | + $value = true; |
|
| 205 | + } |
|
| 206 | + if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) { |
|
| 207 | + continue; |
|
| 208 | + } |
|
| 209 | + $this->attributes[$key] = wp_validate_boolean($value); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * @return void |
|
| 215 | - */ |
|
| 216 | - protected function normalizeDataAttributes() |
|
| 217 | - { |
|
| 218 | - foreach ($this->attributes as $key => $value) { |
|
| 219 | - if ($this->isAttributeKeyNumeric($key, $value)) { |
|
| 220 | - $key = $value; |
|
| 221 | - $value = ''; |
|
| 222 | - } |
|
| 223 | - if (!Str::startsWith('data-', $key)) { |
|
| 224 | - continue; |
|
| 225 | - } |
|
| 226 | - if (is_array($value)) { |
|
| 227 | - $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
| 228 | - } |
|
| 229 | - $this->attributes[$key] = $value; |
|
| 230 | - } |
|
| 231 | - } |
|
| 213 | + /** |
|
| 214 | + * @return void |
|
| 215 | + */ |
|
| 216 | + protected function normalizeDataAttributes() |
|
| 217 | + { |
|
| 218 | + foreach ($this->attributes as $key => $value) { |
|
| 219 | + if ($this->isAttributeKeyNumeric($key, $value)) { |
|
| 220 | + $key = $value; |
|
| 221 | + $value = ''; |
|
| 222 | + } |
|
| 223 | + if (!Str::startsWith('data-', $key)) { |
|
| 224 | + continue; |
|
| 225 | + } |
|
| 226 | + if (is_array($value)) { |
|
| 227 | + $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
| 228 | + } |
|
| 229 | + $this->attributes[$key] = $value; |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * @return void |
|
| 235 | - */ |
|
| 236 | - protected function normalizeStringAttributes() |
|
| 237 | - { |
|
| 238 | - foreach ($this->attributes as $key => $value) { |
|
| 239 | - if (!is_string($value)) { |
|
| 240 | - continue; |
|
| 241 | - } |
|
| 242 | - $this->attributes[$key] = trim($value); |
|
| 243 | - } |
|
| 244 | - } |
|
| 233 | + /** |
|
| 234 | + * @return void |
|
| 235 | + */ |
|
| 236 | + protected function normalizeStringAttributes() |
|
| 237 | + { |
|
| 238 | + foreach ($this->attributes as $key => $value) { |
|
| 239 | + if (!is_string($value)) { |
|
| 240 | + continue; |
|
| 241 | + } |
|
| 242 | + $this->attributes[$key] = trim($value); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * @param string $method |
|
| 248 | - * @return void |
|
| 249 | - */ |
|
| 250 | - protected function normalizeInputType($method) |
|
| 251 | - { |
|
| 252 | - if ('input' != $method) { |
|
| 253 | - return; |
|
| 254 | - } |
|
| 255 | - $attributes = wp_parse_args($this->attributes, ['type' => '']); |
|
| 256 | - if (!in_array($attributes['type'], static::INPUT_TYPES)) { |
|
| 257 | - $this->attributes['type'] = 'text'; |
|
| 258 | - } |
|
| 259 | - } |
|
| 246 | + /** |
|
| 247 | + * @param string $method |
|
| 248 | + * @return void |
|
| 249 | + */ |
|
| 250 | + protected function normalizeInputType($method) |
|
| 251 | + { |
|
| 252 | + if ('input' != $method) { |
|
| 253 | + return; |
|
| 254 | + } |
|
| 255 | + $attributes = wp_parse_args($this->attributes, ['type' => '']); |
|
| 256 | + if (!in_array($attributes['type'], static::INPUT_TYPES)) { |
|
| 257 | + $this->attributes['type'] = 'text'; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * @return void |
|
| 263 | - */ |
|
| 264 | - protected function removeEmptyAttributes() |
|
| 265 | - { |
|
| 266 | - $attributes = $this->attributes; |
|
| 267 | - $permanentAttributes = $this->getPermanentAttributes(); |
|
| 268 | - foreach ($this->attributes as $key => $value) { |
|
| 269 | - if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) { |
|
| 270 | - unset($attributes[$key]); |
|
| 271 | - } |
|
| 272 | - if (Str::startsWith('data-', $key)) { |
|
| 273 | - $permanentAttributes[$key] = $value; |
|
| 274 | - unset($attributes[$key]); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - $this->attributes = array_merge(array_filter($attributes), $permanentAttributes); |
|
| 278 | - } |
|
| 261 | + /** |
|
| 262 | + * @return void |
|
| 263 | + */ |
|
| 264 | + protected function removeEmptyAttributes() |
|
| 265 | + { |
|
| 266 | + $attributes = $this->attributes; |
|
| 267 | + $permanentAttributes = $this->getPermanentAttributes(); |
|
| 268 | + foreach ($this->attributes as $key => $value) { |
|
| 269 | + if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) { |
|
| 270 | + unset($attributes[$key]); |
|
| 271 | + } |
|
| 272 | + if (Str::startsWith('data-', $key)) { |
|
| 273 | + $permanentAttributes[$key] = $value; |
|
| 274 | + unset($attributes[$key]); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + $this->attributes = array_merge(array_filter($attributes), $permanentAttributes); |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - /** |
|
| 281 | - * @return void |
|
| 282 | - */ |
|
| 283 | - protected function removeIndexedAttributes() |
|
| 284 | - { |
|
| 285 | - $this->attributes = array_diff_key( |
|
| 286 | - $this->attributes, |
|
| 287 | - array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY) |
|
| 288 | - ); |
|
| 289 | - } |
|
| 280 | + /** |
|
| 281 | + * @return void |
|
| 282 | + */ |
|
| 283 | + protected function removeIndexedAttributes() |
|
| 284 | + { |
|
| 285 | + $this->attributes = array_diff_key( |
|
| 286 | + $this->attributes, |
|
| 287 | + array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY) |
|
| 288 | + ); |
|
| 289 | + } |
|
| 290 | 290 | } |
@@ -82,15 +82,15 @@ discard block |
||
| 82 | 82 | * @param array $args |
| 83 | 83 | * @return static |
| 84 | 84 | */ |
| 85 | - public function __call($method, $args) |
|
| 85 | + public function __call( $method, $args ) |
|
| 86 | 86 | { |
| 87 | 87 | $args += [[], false]; |
| 88 | - $constant = 'static::ATTRIBUTES_'.strtoupper($method); |
|
| 89 | - $allowedAttributeKeys = defined($constant) |
|
| 90 | - ? constant($constant) |
|
| 88 | + $constant = 'static::ATTRIBUTES_'.strtoupper( $method ); |
|
| 89 | + $allowedAttributeKeys = defined( $constant ) |
|
| 90 | + ? constant( $constant ) |
|
| 91 | 91 | : []; |
| 92 | - $this->normalize((array) $args[0], $allowedAttributeKeys); |
|
| 93 | - $this->normalizeInputType($method); |
|
| 92 | + $this->normalize( (array)$args[0], $allowedAttributeKeys ); |
|
| 93 | + $this->normalizeInputType( $method ); |
|
| 94 | 94 | return $this; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -108,21 +108,21 @@ discard block |
||
| 108 | 108 | public function toString() |
| 109 | 109 | { |
| 110 | 110 | $attributes = []; |
| 111 | - foreach ($this->attributes as $attribute => $value) { |
|
| 112 | - $quote = $this->getQuoteChar($attribute); |
|
| 113 | - $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES) |
|
| 111 | + foreach( $this->attributes as $attribute => $value ) { |
|
| 112 | + $quote = $this->getQuoteChar( $attribute ); |
|
| 113 | + $attributes[] = in_array( $attribute, static::BOOLEAN_ATTRIBUTES ) |
|
| 114 | 114 | ? $attribute |
| 115 | - : $attribute.'='.$quote.implode(',', (array) $value).$quote; |
|
| 115 | + : $attribute.'='.$quote.implode( ',', (array)$value ).$quote; |
|
| 116 | 116 | } |
| 117 | - return implode(' ', $attributes); |
|
| 117 | + return implode( ' ', $attributes ); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | - protected function filterAttributes(array $allowedAttributeKeys) |
|
| 123 | + protected function filterAttributes( array $allowedAttributeKeys ) |
|
| 124 | 124 | { |
| 125 | - return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys)); |
|
| 125 | + return array_intersect_key( $this->attributes, array_flip( $allowedAttributeKeys ) ); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -130,15 +130,15 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | protected function filterGlobalAttributes() |
| 132 | 132 | { |
| 133 | - $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES); |
|
| 133 | + $globalAttributes = $this->filterAttributes( static::GLOBAL_ATTRIBUTES ); |
|
| 134 | 134 | $wildcards = []; |
| 135 | - foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) { |
|
| 136 | - $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) { |
|
| 137 | - return Str::startsWith($wildcard, $key); |
|
| 138 | - }, ARRAY_FILTER_USE_KEY); |
|
| 139 | - $wildcards = array_merge($wildcards, $newWildcards); |
|
| 135 | + foreach( static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard ) { |
|
| 136 | + $newWildcards = array_filter( $this->attributes, function( $key ) use ($wildcard) { |
|
| 137 | + return Str::startsWith( $wildcard, $key ); |
|
| 138 | + }, ARRAY_FILTER_USE_KEY ); |
|
| 139 | + $wildcards = array_merge( $wildcards, $newWildcards ); |
|
| 140 | 140 | } |
| 141 | - return array_merge($globalAttributes, $wildcards); |
|
| 141 | + return array_merge( $globalAttributes, $wildcards ); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | protected function getPermanentAttributes() |
| 148 | 148 | { |
| 149 | 149 | $permanentAttributes = []; |
| 150 | - if (array_key_exists('value', $this->attributes)) { |
|
| 150 | + if( array_key_exists( 'value', $this->attributes ) ) { |
|
| 151 | 151 | $permanentAttributes['value'] = $this->attributes['value']; |
| 152 | 152 | } |
| 153 | 153 | return $permanentAttributes; |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | * @param string $attribute |
| 158 | 158 | * @return string |
| 159 | 159 | */ |
| 160 | - protected function getQuoteChar($attribute) |
|
| 160 | + protected function getQuoteChar( $attribute ) |
|
| 161 | 161 | { |
| 162 | - return Str::startsWith('data-', $attribute) |
|
| 162 | + return Str::startsWith( 'data-', $attribute ) |
|
| 163 | 163 | ? '\'' |
| 164 | 164 | : '"'; |
| 165 | 165 | } |
@@ -169,19 +169,19 @@ discard block |
||
| 169 | 169 | * @param mixed $value |
| 170 | 170 | * @return bool |
| 171 | 171 | */ |
| 172 | - protected function isAttributeKeyNumeric($key, $value) |
|
| 172 | + protected function isAttributeKeyNumeric( $key, $value ) |
|
| 173 | 173 | { |
| 174 | - return is_string($value) |
|
| 175 | - && is_numeric($key) |
|
| 176 | - && !array_key_exists($value, $this->attributes); |
|
| 174 | + return is_string( $value ) |
|
| 175 | + && is_numeric( $key ) |
|
| 176 | + && !array_key_exists( $value, $this->attributes ); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
| 180 | 180 | * @return void |
| 181 | 181 | */ |
| 182 | - protected function normalize(array $args, array $allowedAttributeKeys) |
|
| 182 | + protected function normalize( array $args, array $allowedAttributeKeys ) |
|
| 183 | 183 | { |
| 184 | - $this->attributes = array_change_key_case($args, CASE_LOWER); |
|
| 184 | + $this->attributes = array_change_key_case( $args, CASE_LOWER ); |
|
| 185 | 185 | $this->normalizeBooleanAttributes(); |
| 186 | 186 | $this->normalizeDataAttributes(); |
| 187 | 187 | $this->normalizeStringAttributes(); |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $this->removeIndexedAttributes(); |
| 190 | 190 | $this->attributes = array_merge( |
| 191 | 191 | $this->filterGlobalAttributes(), |
| 192 | - $this->filterAttributes($allowedAttributeKeys) |
|
| 192 | + $this->filterAttributes( $allowedAttributeKeys ) |
|
| 193 | 193 | ); |
| 194 | 194 | } |
| 195 | 195 | |
@@ -198,15 +198,15 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | protected function normalizeBooleanAttributes() |
| 200 | 200 | { |
| 201 | - foreach ($this->attributes as $key => $value) { |
|
| 202 | - if ($this->isAttributeKeyNumeric($key, $value)) { |
|
| 201 | + foreach( $this->attributes as $key => $value ) { |
|
| 202 | + if( $this->isAttributeKeyNumeric( $key, $value ) ) { |
|
| 203 | 203 | $key = $value; |
| 204 | 204 | $value = true; |
| 205 | 205 | } |
| 206 | - if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) { |
|
| 206 | + if( !in_array( $key, static::BOOLEAN_ATTRIBUTES ) ) { |
|
| 207 | 207 | continue; |
| 208 | 208 | } |
| 209 | - $this->attributes[$key] = wp_validate_boolean($value); |
|
| 209 | + $this->attributes[$key] = wp_validate_boolean( $value ); |
|
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | |
@@ -215,16 +215,16 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | protected function normalizeDataAttributes() |
| 217 | 217 | { |
| 218 | - foreach ($this->attributes as $key => $value) { |
|
| 219 | - if ($this->isAttributeKeyNumeric($key, $value)) { |
|
| 218 | + foreach( $this->attributes as $key => $value ) { |
|
| 219 | + if( $this->isAttributeKeyNumeric( $key, $value ) ) { |
|
| 220 | 220 | $key = $value; |
| 221 | 221 | $value = ''; |
| 222 | 222 | } |
| 223 | - if (!Str::startsWith('data-', $key)) { |
|
| 223 | + if( !Str::startsWith( 'data-', $key ) ) { |
|
| 224 | 224 | continue; |
| 225 | 225 | } |
| 226 | - if (is_array($value)) { |
|
| 227 | - $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
| 226 | + if( is_array( $value ) ) { |
|
| 227 | + $value = json_encode( $value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); |
|
| 228 | 228 | } |
| 229 | 229 | $this->attributes[$key] = $value; |
| 230 | 230 | } |
@@ -235,11 +235,11 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | protected function normalizeStringAttributes() |
| 237 | 237 | { |
| 238 | - foreach ($this->attributes as $key => $value) { |
|
| 239 | - if (!is_string($value)) { |
|
| 238 | + foreach( $this->attributes as $key => $value ) { |
|
| 239 | + if( !is_string( $value ) ) { |
|
| 240 | 240 | continue; |
| 241 | 241 | } |
| 242 | - $this->attributes[$key] = trim($value); |
|
| 242 | + $this->attributes[$key] = trim( $value ); |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | |
@@ -247,13 +247,13 @@ discard block |
||
| 247 | 247 | * @param string $method |
| 248 | 248 | * @return void |
| 249 | 249 | */ |
| 250 | - protected function normalizeInputType($method) |
|
| 250 | + protected function normalizeInputType( $method ) |
|
| 251 | 251 | { |
| 252 | - if ('input' != $method) { |
|
| 252 | + if( 'input' != $method ) { |
|
| 253 | 253 | return; |
| 254 | 254 | } |
| 255 | - $attributes = wp_parse_args($this->attributes, ['type' => '']); |
|
| 256 | - if (!in_array($attributes['type'], static::INPUT_TYPES)) { |
|
| 255 | + $attributes = wp_parse_args( $this->attributes, ['type' => ''] ); |
|
| 256 | + if( !in_array( $attributes['type'], static::INPUT_TYPES ) ) { |
|
| 257 | 257 | $this->attributes['type'] = 'text'; |
| 258 | 258 | } |
| 259 | 259 | } |
@@ -265,16 +265,16 @@ discard block |
||
| 265 | 265 | { |
| 266 | 266 | $attributes = $this->attributes; |
| 267 | 267 | $permanentAttributes = $this->getPermanentAttributes(); |
| 268 | - foreach ($this->attributes as $key => $value) { |
|
| 269 | - if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) { |
|
| 268 | + foreach( $this->attributes as $key => $value ) { |
|
| 269 | + if( in_array( $key, static::BOOLEAN_ATTRIBUTES ) && !$value ) { |
|
| 270 | 270 | unset($attributes[$key]); |
| 271 | 271 | } |
| 272 | - if (Str::startsWith('data-', $key)) { |
|
| 272 | + if( Str::startsWith( 'data-', $key ) ) { |
|
| 273 | 273 | $permanentAttributes[$key] = $value; |
| 274 | 274 | unset($attributes[$key]); |
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | - $this->attributes = array_merge(array_filter($attributes), $permanentAttributes); |
|
| 277 | + $this->attributes = array_merge( array_filter( $attributes ), $permanentAttributes ); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | /** |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | { |
| 285 | 285 | $this->attributes = array_diff_key( |
| 286 | 286 | $this->attributes, |
| 287 | - array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY) |
|
| 287 | + array_filter( $this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY ) |
|
| 288 | 288 | ); |
| 289 | 289 | } |
| 290 | 290 | } |
@@ -6,30 +6,30 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Partial |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @param string $partialPath |
|
| 11 | - * @return string |
|
| 12 | - */ |
|
| 13 | - public function build($partialPath, array $args = []) |
|
| 14 | - { |
|
| 15 | - $className = Helper::buildClassName($partialPath, 'Modules\Html\Partials'); |
|
| 16 | - if (!class_exists($className)) { |
|
| 17 | - glsr_log()->error('Partial missing: '.$className); |
|
| 18 | - return; |
|
| 19 | - } |
|
| 20 | - $args = apply_filters('site-reviews/partial/args/'.$partialPath, $args); |
|
| 21 | - $partial = glsr($className)->build($args); |
|
| 22 | - $partial = apply_filters('site-reviews/rendered/partial', $partial, $partialPath, $args); |
|
| 23 | - $partial = apply_filters('site-reviews/rendered/partial/'.$partialPath, $partial, $args); |
|
| 24 | - return $partial; |
|
| 25 | - } |
|
| 9 | + /** |
|
| 10 | + * @param string $partialPath |
|
| 11 | + * @return string |
|
| 12 | + */ |
|
| 13 | + public function build($partialPath, array $args = []) |
|
| 14 | + { |
|
| 15 | + $className = Helper::buildClassName($partialPath, 'Modules\Html\Partials'); |
|
| 16 | + if (!class_exists($className)) { |
|
| 17 | + glsr_log()->error('Partial missing: '.$className); |
|
| 18 | + return; |
|
| 19 | + } |
|
| 20 | + $args = apply_filters('site-reviews/partial/args/'.$partialPath, $args); |
|
| 21 | + $partial = glsr($className)->build($args); |
|
| 22 | + $partial = apply_filters('site-reviews/rendered/partial', $partial, $partialPath, $args); |
|
| 23 | + $partial = apply_filters('site-reviews/rendered/partial/'.$partialPath, $partial, $args); |
|
| 24 | + return $partial; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @param string $partialPath |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function render($partialPath, array $args = []) |
|
| 32 | - { |
|
| 33 | - echo $this->build($partialPath, $args); |
|
| 34 | - } |
|
| 27 | + /** |
|
| 28 | + * @param string $partialPath |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function render($partialPath, array $args = []) |
|
| 32 | + { |
|
| 33 | + echo $this->build($partialPath, $args); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -10,17 +10,17 @@ discard block |
||
| 10 | 10 | * @param string $partialPath |
| 11 | 11 | * @return string |
| 12 | 12 | */ |
| 13 | - public function build($partialPath, array $args = []) |
|
| 13 | + public function build( $partialPath, array $args = [] ) |
|
| 14 | 14 | { |
| 15 | - $className = Helper::buildClassName($partialPath, 'Modules\Html\Partials'); |
|
| 16 | - if (!class_exists($className)) { |
|
| 17 | - glsr_log()->error('Partial missing: '.$className); |
|
| 15 | + $className = Helper::buildClassName( $partialPath, 'Modules\Html\Partials' ); |
|
| 16 | + if( !class_exists( $className ) ) { |
|
| 17 | + glsr_log()->error( 'Partial missing: '.$className ); |
|
| 18 | 18 | return; |
| 19 | 19 | } |
| 20 | - $args = apply_filters('site-reviews/partial/args/'.$partialPath, $args); |
|
| 21 | - $partial = glsr($className)->build($args); |
|
| 22 | - $partial = apply_filters('site-reviews/rendered/partial', $partial, $partialPath, $args); |
|
| 23 | - $partial = apply_filters('site-reviews/rendered/partial/'.$partialPath, $partial, $args); |
|
| 20 | + $args = apply_filters( 'site-reviews/partial/args/'.$partialPath, $args ); |
|
| 21 | + $partial = glsr( $className )->build( $args ); |
|
| 22 | + $partial = apply_filters( 'site-reviews/rendered/partial', $partial, $partialPath, $args ); |
|
| 23 | + $partial = apply_filters( 'site-reviews/rendered/partial/'.$partialPath, $partial, $args ); |
|
| 24 | 24 | return $partial; |
| 25 | 25 | } |
| 26 | 26 | |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | * @param string $partialPath |
| 29 | 29 | * @return void |
| 30 | 30 | */ |
| 31 | - public function render($partialPath, array $args = []) |
|
| 31 | + public function render( $partialPath, array $args = [] ) |
|
| 32 | 32 | { |
| 33 | - echo $this->build($partialPath, $args); |
|
| 33 | + echo $this->build( $partialPath, $args ); |
|
| 34 | 34 | } |
| 35 | 35 | } |
@@ -13,9 +13,9 @@ discard block |
||
| 13 | 13 | * @return array |
| 14 | 14 | * @filter block_categories |
| 15 | 15 | */ |
| 16 | - public function filterBlockCategories($categories) |
|
| 16 | + public function filterBlockCategories( $categories ) |
|
| 17 | 17 | { |
| 18 | - $categories = Arr::consolidateArray($categories); |
|
| 18 | + $categories = Arr::consolidateArray( $categories ); |
|
| 19 | 19 | $categories[] = [ |
| 20 | 20 | 'icon' => null, |
| 21 | 21 | 'slug' => Application::ID, |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @filter classic_editor_enabled_editors_for_post_type |
| 32 | 32 | * @plugin classic-editor/classic-editor.php |
| 33 | 33 | */ |
| 34 | - public function filterEnabledEditors($editors, $postType) |
|
| 34 | + public function filterEnabledEditors( $editors, $postType ) |
|
| 35 | 35 | { |
| 36 | 36 | return Application::POST_TYPE == $postType |
| 37 | 37 | ? ['block_editor' => false, 'classic_editor' => false] |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @return bool |
| 45 | 45 | * @filter use_block_editor_for_post_type |
| 46 | 46 | */ |
| 47 | - public function filterUseBlockEditor($bool, $postType) |
|
| 47 | + public function filterUseBlockEditor( $bool, $postType ) |
|
| 48 | 48 | { |
| 49 | 49 | return Application::POST_TYPE == $postType |
| 50 | 50 | ? false |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | { |
| 59 | 59 | wp_register_style( |
| 60 | 60 | Application::ID.'/blocks', |
| 61 | - glsr()->url('assets/styles/'.Application::ID.'-blocks.css'), |
|
| 61 | + glsr()->url( 'assets/styles/'.Application::ID.'-blocks.css' ), |
|
| 62 | 62 | ['wp-edit-blocks'], |
| 63 | 63 | glsr()->version |
| 64 | 64 | ); |
| 65 | 65 | wp_register_script( |
| 66 | 66 | Application::ID.'/blocks', |
| 67 | - glsr()->url('assets/scripts/'.Application::ID.'-blocks.js'), |
|
| 67 | + glsr()->url( 'assets/scripts/'.Application::ID.'-blocks.js' ), |
|
| 68 | 68 | ['wp-api-fetch', 'wp-blocks', 'wp-i18n', 'wp-editor', 'wp-element', Application::ID], |
| 69 | 69 | glsr()->version |
| 70 | 70 | ); |
@@ -79,14 +79,14 @@ discard block |
||
| 79 | 79 | $blocks = [ |
| 80 | 80 | 'form', 'reviews', 'summary', |
| 81 | 81 | ]; |
| 82 | - foreach ($blocks as $block) { |
|
| 83 | - $id = str_replace('_reviews', '', Application::ID.'_'.$block); |
|
| 84 | - $blockClass = Helper::buildClassName($id.'-block', 'Blocks'); |
|
| 85 | - if (!class_exists($blockClass)) { |
|
| 86 | - glsr_log()->error(sprintf('Class missing (%s)', $blockClass)); |
|
| 82 | + foreach( $blocks as $block ) { |
|
| 83 | + $id = str_replace( '_reviews', '', Application::ID.'_'.$block ); |
|
| 84 | + $blockClass = Helper::buildClassName( $id.'-block', 'Blocks' ); |
|
| 85 | + if( !class_exists( $blockClass ) ) { |
|
| 86 | + glsr_log()->error( sprintf( 'Class missing (%s)', $blockClass ) ); |
|
| 87 | 87 | continue; |
| 88 | 88 | } |
| 89 | - glsr($blockClass)->register($block); |
|
| 89 | + glsr( $blockClass )->register( $block ); |
|
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -8,86 +8,86 @@ |
||
| 8 | 8 | |
| 9 | 9 | class BlocksController extends Controller |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @param array $categories |
|
| 13 | - * @return array |
|
| 14 | - * @filter block_categories |
|
| 15 | - */ |
|
| 16 | - public function filterBlockCategories($categories) |
|
| 17 | - { |
|
| 18 | - $categories = Arr::consolidateArray($categories); |
|
| 19 | - $categories[] = [ |
|
| 20 | - 'icon' => null, |
|
| 21 | - 'slug' => Application::ID, |
|
| 22 | - 'title' => glsr()->name, |
|
| 23 | - ]; |
|
| 24 | - return $categories; |
|
| 25 | - } |
|
| 11 | + /** |
|
| 12 | + * @param array $categories |
|
| 13 | + * @return array |
|
| 14 | + * @filter block_categories |
|
| 15 | + */ |
|
| 16 | + public function filterBlockCategories($categories) |
|
| 17 | + { |
|
| 18 | + $categories = Arr::consolidateArray($categories); |
|
| 19 | + $categories[] = [ |
|
| 20 | + 'icon' => null, |
|
| 21 | + 'slug' => Application::ID, |
|
| 22 | + 'title' => glsr()->name, |
|
| 23 | + ]; |
|
| 24 | + return $categories; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @param array $editors |
|
| 29 | - * @param string $postType |
|
| 30 | - * @return array |
|
| 31 | - * @filter classic_editor_enabled_editors_for_post_type |
|
| 32 | - * @plugin classic-editor/classic-editor.php |
|
| 33 | - */ |
|
| 34 | - public function filterEnabledEditors($editors, $postType) |
|
| 35 | - { |
|
| 36 | - return Application::POST_TYPE == $postType |
|
| 37 | - ? ['block_editor' => false, 'classic_editor' => false] |
|
| 38 | - : $editors; |
|
| 39 | - } |
|
| 27 | + /** |
|
| 28 | + * @param array $editors |
|
| 29 | + * @param string $postType |
|
| 30 | + * @return array |
|
| 31 | + * @filter classic_editor_enabled_editors_for_post_type |
|
| 32 | + * @plugin classic-editor/classic-editor.php |
|
| 33 | + */ |
|
| 34 | + public function filterEnabledEditors($editors, $postType) |
|
| 35 | + { |
|
| 36 | + return Application::POST_TYPE == $postType |
|
| 37 | + ? ['block_editor' => false, 'classic_editor' => false] |
|
| 38 | + : $editors; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param bool $bool |
|
| 43 | - * @param string $postType |
|
| 44 | - * @return bool |
|
| 45 | - * @filter use_block_editor_for_post_type |
|
| 46 | - */ |
|
| 47 | - public function filterUseBlockEditor($bool, $postType) |
|
| 48 | - { |
|
| 49 | - return Application::POST_TYPE == $postType |
|
| 50 | - ? false |
|
| 51 | - : $bool; |
|
| 52 | - } |
|
| 41 | + /** |
|
| 42 | + * @param bool $bool |
|
| 43 | + * @param string $postType |
|
| 44 | + * @return bool |
|
| 45 | + * @filter use_block_editor_for_post_type |
|
| 46 | + */ |
|
| 47 | + public function filterUseBlockEditor($bool, $postType) |
|
| 48 | + { |
|
| 49 | + return Application::POST_TYPE == $postType |
|
| 50 | + ? false |
|
| 51 | + : $bool; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return void |
|
| 56 | - * @action init |
|
| 57 | - */ |
|
| 58 | - public function registerAssets() |
|
| 59 | - { |
|
| 60 | - wp_register_style( |
|
| 61 | - Application::ID.'/blocks', |
|
| 62 | - glsr()->url('assets/styles/'.Application::ID.'-blocks.css'), |
|
| 63 | - ['wp-edit-blocks'], |
|
| 64 | - glsr()->version |
|
| 65 | - ); |
|
| 66 | - wp_register_script( |
|
| 67 | - Application::ID.'/blocks', |
|
| 68 | - glsr()->url('assets/scripts/'.Application::ID.'-blocks.js'), |
|
| 69 | - ['wp-api-fetch', 'wp-blocks', 'wp-i18n', 'wp-editor', 'wp-element', Application::ID], |
|
| 70 | - glsr()->version |
|
| 71 | - ); |
|
| 72 | - } |
|
| 54 | + /** |
|
| 55 | + * @return void |
|
| 56 | + * @action init |
|
| 57 | + */ |
|
| 58 | + public function registerAssets() |
|
| 59 | + { |
|
| 60 | + wp_register_style( |
|
| 61 | + Application::ID.'/blocks', |
|
| 62 | + glsr()->url('assets/styles/'.Application::ID.'-blocks.css'), |
|
| 63 | + ['wp-edit-blocks'], |
|
| 64 | + glsr()->version |
|
| 65 | + ); |
|
| 66 | + wp_register_script( |
|
| 67 | + Application::ID.'/blocks', |
|
| 68 | + glsr()->url('assets/scripts/'.Application::ID.'-blocks.js'), |
|
| 69 | + ['wp-api-fetch', 'wp-blocks', 'wp-i18n', 'wp-editor', 'wp-element', Application::ID], |
|
| 70 | + glsr()->version |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return void |
|
| 76 | - * @action init |
|
| 77 | - */ |
|
| 78 | - public function registerBlocks() |
|
| 79 | - { |
|
| 80 | - $blocks = [ |
|
| 81 | - 'form', 'reviews', 'summary', |
|
| 82 | - ]; |
|
| 83 | - foreach ($blocks as $block) { |
|
| 84 | - $id = str_replace('_reviews', '', Application::ID.'_'.$block); |
|
| 85 | - $blockClass = Helper::buildClassName($id.'-block', 'Blocks'); |
|
| 86 | - if (!class_exists($blockClass)) { |
|
| 87 | - glsr_log()->error(sprintf('Class missing (%s)', $blockClass)); |
|
| 88 | - continue; |
|
| 89 | - } |
|
| 90 | - glsr($blockClass)->register($block); |
|
| 91 | - } |
|
| 92 | - } |
|
| 74 | + /** |
|
| 75 | + * @return void |
|
| 76 | + * @action init |
|
| 77 | + */ |
|
| 78 | + public function registerBlocks() |
|
| 79 | + { |
|
| 80 | + $blocks = [ |
|
| 81 | + 'form', 'reviews', 'summary', |
|
| 82 | + ]; |
|
| 83 | + foreach ($blocks as $block) { |
|
| 84 | + $id = str_replace('_reviews', '', Application::ID.'_'.$block); |
|
| 85 | + $blockClass = Helper::buildClassName($id.'-block', 'Blocks'); |
|
| 86 | + if (!class_exists($blockClass)) { |
|
| 87 | + glsr_log()->error(sprintf('Class missing (%s)', $blockClass)); |
|
| 88 | + continue; |
|
| 89 | + } |
|
| 90 | + glsr($blockClass)->register($block); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -7,18 +7,18 @@ |
||
| 7 | 7 | |
| 8 | 8 | class RegisterShortcodes |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @return void |
|
| 12 | - */ |
|
| 13 | - public function handle(Command $command) |
|
| 14 | - { |
|
| 15 | - foreach ($command->shortcodes as $shortcode) { |
|
| 16 | - $shortcodeClass = Helper::buildClassName($shortcode.'-shortcode', 'Shortcodes'); |
|
| 17 | - if (!class_exists($shortcodeClass)) { |
|
| 18 | - glsr_log()->error(sprintf('Class missing (%s)', $shortcodeClass)); |
|
| 19 | - continue; |
|
| 20 | - } |
|
| 21 | - add_shortcode($shortcode, [glsr($shortcodeClass), 'buildShortcode']); |
|
| 22 | - } |
|
| 23 | - } |
|
| 10 | + /** |
|
| 11 | + * @return void |
|
| 12 | + */ |
|
| 13 | + public function handle(Command $command) |
|
| 14 | + { |
|
| 15 | + foreach ($command->shortcodes as $shortcode) { |
|
| 16 | + $shortcodeClass = Helper::buildClassName($shortcode.'-shortcode', 'Shortcodes'); |
|
| 17 | + if (!class_exists($shortcodeClass)) { |
|
| 18 | + glsr_log()->error(sprintf('Class missing (%s)', $shortcodeClass)); |
|
| 19 | + continue; |
|
| 20 | + } |
|
| 21 | + add_shortcode($shortcode, [glsr($shortcodeClass), 'buildShortcode']); |
|
| 22 | + } |
|
| 23 | + } |
|
| 24 | 24 | } |
@@ -10,15 +10,15 @@ |
||
| 10 | 10 | /** |
| 11 | 11 | * @return void |
| 12 | 12 | */ |
| 13 | - public function handle(Command $command) |
|
| 13 | + public function handle( Command $command ) |
|
| 14 | 14 | { |
| 15 | - foreach ($command->shortcodes as $shortcode) { |
|
| 16 | - $shortcodeClass = Helper::buildClassName($shortcode.'-shortcode', 'Shortcodes'); |
|
| 17 | - if (!class_exists($shortcodeClass)) { |
|
| 18 | - glsr_log()->error(sprintf('Class missing (%s)', $shortcodeClass)); |
|
| 15 | + foreach( $command->shortcodes as $shortcode ) { |
|
| 16 | + $shortcodeClass = Helper::buildClassName( $shortcode.'-shortcode', 'Shortcodes' ); |
|
| 17 | + if( !class_exists( $shortcodeClass ) ) { |
|
| 18 | + glsr_log()->error( sprintf( 'Class missing (%s)', $shortcodeClass ) ); |
|
| 19 | 19 | continue; |
| 20 | 20 | } |
| 21 | - add_shortcode($shortcode, [glsr($shortcodeClass), 'buildShortcode']); |
|
| 21 | + add_shortcode( $shortcode, [glsr( $shortcodeClass ), 'buildShortcode'] ); |
|
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | } |
@@ -7,22 +7,22 @@ |
||
| 7 | 7 | |
| 8 | 8 | class RegisterTinymcePopups |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @return void |
|
| 12 | - */ |
|
| 13 | - public function handle(Command $command) |
|
| 14 | - { |
|
| 15 | - foreach ($command->popups as $slug => $label) { |
|
| 16 | - $buttonClass = Helper::buildClassName($slug.'-popup', 'Shortcodes'); |
|
| 17 | - if (!class_exists($buttonClass)) { |
|
| 18 | - glsr_log()->error(sprintf('Class missing (%s)', $buttonClass)); |
|
| 19 | - continue; |
|
| 20 | - } |
|
| 21 | - $shortcode = glsr($buttonClass)->register($slug, [ |
|
| 22 | - 'label' => $label, |
|
| 23 | - 'title' => $label, |
|
| 24 | - ]); |
|
| 25 | - glsr()->mceShortcodes[$slug] = $shortcode->properties; |
|
| 26 | - } |
|
| 27 | - } |
|
| 10 | + /** |
|
| 11 | + * @return void |
|
| 12 | + */ |
|
| 13 | + public function handle(Command $command) |
|
| 14 | + { |
|
| 15 | + foreach ($command->popups as $slug => $label) { |
|
| 16 | + $buttonClass = Helper::buildClassName($slug.'-popup', 'Shortcodes'); |
|
| 17 | + if (!class_exists($buttonClass)) { |
|
| 18 | + glsr_log()->error(sprintf('Class missing (%s)', $buttonClass)); |
|
| 19 | + continue; |
|
| 20 | + } |
|
| 21 | + $shortcode = glsr($buttonClass)->register($slug, [ |
|
| 22 | + 'label' => $label, |
|
| 23 | + 'title' => $label, |
|
| 24 | + ]); |
|
| 25 | + glsr()->mceShortcodes[$slug] = $shortcode->properties; |
|
| 26 | + } |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -10,18 +10,18 @@ |
||
| 10 | 10 | /** |
| 11 | 11 | * @return void |
| 12 | 12 | */ |
| 13 | - public function handle(Command $command) |
|
| 13 | + public function handle( Command $command ) |
|
| 14 | 14 | { |
| 15 | - foreach ($command->popups as $slug => $label) { |
|
| 16 | - $buttonClass = Helper::buildClassName($slug.'-popup', 'Shortcodes'); |
|
| 17 | - if (!class_exists($buttonClass)) { |
|
| 18 | - glsr_log()->error(sprintf('Class missing (%s)', $buttonClass)); |
|
| 15 | + foreach( $command->popups as $slug => $label ) { |
|
| 16 | + $buttonClass = Helper::buildClassName( $slug.'-popup', 'Shortcodes' ); |
|
| 17 | + if( !class_exists( $buttonClass ) ) { |
|
| 18 | + glsr_log()->error( sprintf( 'Class missing (%s)', $buttonClass ) ); |
|
| 19 | 19 | continue; |
| 20 | 20 | } |
| 21 | - $shortcode = glsr($buttonClass)->register($slug, [ |
|
| 21 | + $shortcode = glsr( $buttonClass )->register( $slug, [ |
|
| 22 | 22 | 'label' => $label, |
| 23 | 23 | 'title' => $label, |
| 24 | - ]); |
|
| 24 | + ] ); |
|
| 25 | 25 | glsr()->mceShortcodes[$slug] = $shortcode->properties; |
| 26 | 26 | } |
| 27 | 27 | } |
@@ -6,60 +6,60 @@ |
||
| 6 | 6 | |
| 7 | 7 | class DefaultsManager |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @return array |
|
| 11 | - */ |
|
| 12 | - public function defaults() |
|
| 13 | - { |
|
| 14 | - $settings = $this->settings(); |
|
| 15 | - $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default')); |
|
| 16 | - return wp_parse_args($defaults, [ |
|
| 17 | - 'version' => '', |
|
| 18 | - 'version_upgraded_from' => '', |
|
| 19 | - ]); |
|
| 20 | - } |
|
| 9 | + /** |
|
| 10 | + * @return array |
|
| 11 | + */ |
|
| 12 | + public function defaults() |
|
| 13 | + { |
|
| 14 | + $settings = $this->settings(); |
|
| 15 | + $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default')); |
|
| 16 | + return wp_parse_args($defaults, [ |
|
| 17 | + 'version' => '', |
|
| 18 | + 'version_upgraded_from' => '', |
|
| 19 | + ]); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @return array |
|
| 24 | - */ |
|
| 25 | - public function get() |
|
| 26 | - { |
|
| 27 | - return Arr::convertDotNotationArray($this->defaults()); |
|
| 28 | - } |
|
| 22 | + /** |
|
| 23 | + * @return array |
|
| 24 | + */ |
|
| 25 | + public function get() |
|
| 26 | + { |
|
| 27 | + return Arr::convertDotNotationArray($this->defaults()); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @return array |
|
| 32 | - */ |
|
| 33 | - public function set() |
|
| 34 | - { |
|
| 35 | - $settings = glsr(OptionManager::class)->all(); |
|
| 36 | - $currentSettings = Arr::removeEmptyArrayValues($settings); |
|
| 37 | - $defaultSettings = array_replace_recursive($this->get(), $currentSettings); |
|
| 38 | - $updatedSettings = array_replace_recursive($settings, $defaultSettings); |
|
| 39 | - update_option(OptionManager::databaseKey(), $updatedSettings); |
|
| 40 | - return $defaultSettings; |
|
| 41 | - } |
|
| 30 | + /** |
|
| 31 | + * @return array |
|
| 32 | + */ |
|
| 33 | + public function set() |
|
| 34 | + { |
|
| 35 | + $settings = glsr(OptionManager::class)->all(); |
|
| 36 | + $currentSettings = Arr::removeEmptyArrayValues($settings); |
|
| 37 | + $defaultSettings = array_replace_recursive($this->get(), $currentSettings); |
|
| 38 | + $updatedSettings = array_replace_recursive($settings, $defaultSettings); |
|
| 39 | + update_option(OptionManager::databaseKey(), $updatedSettings); |
|
| 40 | + return $defaultSettings; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return array |
|
| 45 | - */ |
|
| 46 | - public function settings() |
|
| 47 | - { |
|
| 48 | - $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings')); |
|
| 49 | - return $this->normalize($settings); |
|
| 50 | - } |
|
| 43 | + /** |
|
| 44 | + * @return array |
|
| 45 | + */ |
|
| 46 | + public function settings() |
|
| 47 | + { |
|
| 48 | + $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings')); |
|
| 49 | + return $this->normalize($settings); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return array |
|
| 54 | - */ |
|
| 55 | - protected function normalize(array $settings) |
|
| 56 | - { |
|
| 57 | - array_walk($settings, function (&$setting) { |
|
| 58 | - if (isset($setting['default'])) { |
|
| 59 | - return; |
|
| 60 | - } |
|
| 61 | - $setting['default'] = ''; |
|
| 62 | - }); |
|
| 63 | - return $settings; |
|
| 64 | - } |
|
| 52 | + /** |
|
| 53 | + * @return array |
|
| 54 | + */ |
|
| 55 | + protected function normalize(array $settings) |
|
| 56 | + { |
|
| 57 | + array_walk($settings, function (&$setting) { |
|
| 58 | + if (isset($setting['default'])) { |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | + $setting['default'] = ''; |
|
| 62 | + }); |
|
| 63 | + return $settings; |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -12,11 +12,11 @@ discard block |
||
| 12 | 12 | public function defaults() |
| 13 | 13 | { |
| 14 | 14 | $settings = $this->settings(); |
| 15 | - $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default')); |
|
| 16 | - return wp_parse_args($defaults, [ |
|
| 15 | + $defaults = (array)array_combine( array_keys( $settings ), glsr_array_column( $settings, 'default' ) ); |
|
| 16 | + return wp_parse_args( $defaults, [ |
|
| 17 | 17 | 'version' => '', |
| 18 | 18 | 'version_upgraded_from' => '', |
| 19 | - ]); |
|
| 19 | + ] ); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public function get() |
| 26 | 26 | { |
| 27 | - return Arr::convertDotNotationArray($this->defaults()); |
|
| 27 | + return Arr::convertDotNotationArray( $this->defaults() ); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public function set() |
| 34 | 34 | { |
| 35 | - $settings = glsr(OptionManager::class)->all(); |
|
| 36 | - $currentSettings = Arr::removeEmptyArrayValues($settings); |
|
| 37 | - $defaultSettings = array_replace_recursive($this->get(), $currentSettings); |
|
| 38 | - $updatedSettings = array_replace_recursive($settings, $defaultSettings); |
|
| 39 | - update_option(OptionManager::databaseKey(), $updatedSettings); |
|
| 35 | + $settings = glsr( OptionManager::class )->all(); |
|
| 36 | + $currentSettings = Arr::removeEmptyArrayValues( $settings ); |
|
| 37 | + $defaultSettings = array_replace_recursive( $this->get(), $currentSettings ); |
|
| 38 | + $updatedSettings = array_replace_recursive( $settings, $defaultSettings ); |
|
| 39 | + update_option( OptionManager::databaseKey(), $updatedSettings ); |
|
| 40 | 40 | return $defaultSettings; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -45,17 +45,17 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function settings() |
| 47 | 47 | { |
| 48 | - $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings')); |
|
| 49 | - return $this->normalize($settings); |
|
| 48 | + $settings = apply_filters( 'site-reviews/addon/settings', glsr()->config( 'settings' ) ); |
|
| 49 | + return $this->normalize( $settings ); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @return array |
| 54 | 54 | */ |
| 55 | - protected function normalize(array $settings) |
|
| 55 | + protected function normalize( array $settings ) |
|
| 56 | 56 | { |
| 57 | - array_walk($settings, function (&$setting) { |
|
| 58 | - if (isset($setting['default'])) { |
|
| 57 | + array_walk( $settings, function( &$setting ) { |
|
| 58 | + if( isset($setting['default']) ) { |
|
| 59 | 59 | return; |
| 60 | 60 | } |
| 61 | 61 | $setting['default'] = ''; |
@@ -11,239 +11,239 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Settings |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - public $settings; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @param string $id |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function buildFields($id) |
|
| 24 | - { |
|
| 25 | - $this->settings = glsr(DefaultsManager::class)->settings(); |
|
| 26 | - $method = Helper::buildMethodName($id, 'getTemplateDataFor'); |
|
| 27 | - $data = !method_exists($this, $method) |
|
| 28 | - ? $this->getTemplateData($id) |
|
| 29 | - : $this->$method($id); |
|
| 30 | - return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @return string |
|
| 35 | - */ |
|
| 36 | - protected function getFieldDefault(array $field) |
|
| 37 | - { |
|
| 38 | - return Arr::get($field, 'default'); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - protected function getFieldNameForDependsOn($path) |
|
| 45 | - { |
|
| 46 | - $fieldName = Str::convertPathToName($path, OptionManager::databaseKey()); |
|
| 47 | - return $this->isMultiDependency($path) |
|
| 48 | - ? $fieldName.'[]' |
|
| 49 | - : $fieldName; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return array |
|
| 54 | - */ |
|
| 55 | - protected function getSettingFields($path) |
|
| 56 | - { |
|
| 57 | - return array_filter($this->settings, function ($key) use ($path) { |
|
| 58 | - return Str::startsWith($path, $key); |
|
| 59 | - }, ARRAY_FILTER_USE_KEY); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - protected function getSettingRows(array $fields) |
|
| 66 | - { |
|
| 67 | - $rows = ''; |
|
| 68 | - foreach ($fields as $name => $field) { |
|
| 69 | - $field = wp_parse_args($field, [ |
|
| 70 | - 'is_setting' => true, |
|
| 71 | - 'name' => $name, |
|
| 72 | - ]); |
|
| 73 | - $rows.= new Field($this->normalize($field)); |
|
| 74 | - } |
|
| 75 | - return $rows; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param string $id |
|
| 80 | - * @return array |
|
| 81 | - */ |
|
| 82 | - protected function getTemplateData($id) |
|
| 83 | - { |
|
| 84 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 85 | - return [ |
|
| 86 | - 'context' => [ |
|
| 87 | - 'rows' => $this->getSettingRows($fields), |
|
| 88 | - ], |
|
| 89 | - ]; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param string $id |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - protected function getTemplateDataForAddons($id) |
|
| 97 | - { |
|
| 98 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 99 | - $settings = Arr::convertDotNotationArray($fields); |
|
| 100 | - $settingKeys = array_keys($settings['settings']['addons']); |
|
| 101 | - $results = []; |
|
| 102 | - foreach ($settingKeys as $key) { |
|
| 103 | - $addonFields = array_filter($fields, function ($path) use ($key) { |
|
| 104 | - return Str::startsWith('settings.addons.'.$key, $path); |
|
| 105 | - }, ARRAY_FILTER_USE_KEY); |
|
| 106 | - $results[$key] = $this->getSettingRows($addonFields); |
|
| 107 | - } |
|
| 108 | - ksort($results); |
|
| 109 | - return [ |
|
| 110 | - 'settings' => $results, |
|
| 111 | - ]; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @param string $id |
|
| 116 | - * @return array |
|
| 117 | - */ |
|
| 118 | - protected function getTemplateDataForLicenses($id) |
|
| 119 | - { |
|
| 120 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 121 | - ksort($fields); |
|
| 122 | - return [ |
|
| 123 | - 'context' => [ |
|
| 124 | - 'rows' => $this->getSettingRows($fields), |
|
| 125 | - ], |
|
| 126 | - ]; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @return array |
|
| 131 | - */ |
|
| 132 | - protected function getTemplateDataForTranslations() |
|
| 133 | - { |
|
| 134 | - $translations = glsr(Translation::class)->renderAll(); |
|
| 135 | - $class = empty($translations) |
|
| 136 | - ? 'glsr-hidden' |
|
| 137 | - : ''; |
|
| 138 | - return [ |
|
| 139 | - 'context' => [ |
|
| 140 | - 'class' => $class, |
|
| 141 | - 'database_key' => OptionManager::databaseKey(), |
|
| 142 | - 'translations' => $translations, |
|
| 143 | - ], |
|
| 144 | - ]; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param string $path |
|
| 149 | - * @param string|array $expectedValue |
|
| 150 | - * @return bool |
|
| 151 | - */ |
|
| 152 | - protected function isFieldHidden($path, $expectedValue) |
|
| 153 | - { |
|
| 154 | - $optionValue = glsr(OptionManager::class)->get( |
|
| 155 | - $path, |
|
| 156 | - Arr::get(glsr()->defaults, $path) |
|
| 157 | - ); |
|
| 158 | - if (is_array($expectedValue)) { |
|
| 159 | - return is_array($optionValue) |
|
| 160 | - ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
| 161 | - : !in_array($optionValue, $expectedValue); |
|
| 162 | - } |
|
| 163 | - return $optionValue != $expectedValue; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @return bool |
|
| 168 | - */ |
|
| 169 | - protected function isMultiDependency($path) |
|
| 170 | - { |
|
| 171 | - if (isset($this->settings[$path])) { |
|
| 172 | - $field = $this->settings[$path]; |
|
| 173 | - return ('checkbox' == $field['type'] && !empty($field['options'])) |
|
| 174 | - || !empty($field['multiple']); |
|
| 175 | - } |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @return array |
|
| 181 | - */ |
|
| 182 | - protected function normalize(array $field) |
|
| 183 | - { |
|
| 184 | - $field = $this->normalizeDependsOn($field); |
|
| 185 | - $field = $this->normalizeLabelAndLegend($field); |
|
| 186 | - $field = $this->normalizeValue($field); |
|
| 187 | - return $field; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @return array |
|
| 192 | - */ |
|
| 193 | - protected function normalizeDependsOn(array $field) |
|
| 194 | - { |
|
| 195 | - if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
| 196 | - $isFieldHidden = false; |
|
| 197 | - $conditions = []; |
|
| 198 | - foreach ($field['depends_on'] as $path => $value) { |
|
| 199 | - $conditions[] = [ |
|
| 200 | - 'name' => $this->getFieldNameForDependsOn($path), |
|
| 201 | - 'value' => $value, |
|
| 202 | - ]; |
|
| 203 | - if ($this->isFieldHidden($path, $value)) { |
|
| 204 | - $isFieldHidden = true; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
| 208 | - $field['is_hidden'] = $isFieldHidden; |
|
| 209 | - } |
|
| 210 | - return $field; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @return array |
|
| 215 | - */ |
|
| 216 | - protected function normalizeLabelAndLegend(array $field) |
|
| 217 | - { |
|
| 218 | - if (!empty($field['label'])) { |
|
| 219 | - $field['legend'] = $field['label']; |
|
| 220 | - unset($field['label']); |
|
| 221 | - } else { |
|
| 222 | - $field['is_valid'] = false; |
|
| 223 | - glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
| 224 | - } |
|
| 225 | - return $field; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @return array |
|
| 230 | - */ |
|
| 231 | - protected function normalizeValue(array $field) |
|
| 232 | - { |
|
| 233 | - if (!isset($field['value'])) { |
|
| 234 | - $field['value'] = glsr(OptionManager::class)->get( |
|
| 235 | - $field['name'], |
|
| 236 | - $this->getFieldDefault($field) |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - return $field; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - protected function normalizeSettingPath($path) |
|
| 246 | - { |
|
| 247 | - return Str::prefix('settings.', rtrim($path, '.')); |
|
| 248 | - } |
|
| 14 | + /** |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + public $settings; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @param string $id |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function buildFields($id) |
|
| 24 | + { |
|
| 25 | + $this->settings = glsr(DefaultsManager::class)->settings(); |
|
| 26 | + $method = Helper::buildMethodName($id, 'getTemplateDataFor'); |
|
| 27 | + $data = !method_exists($this, $method) |
|
| 28 | + ? $this->getTemplateData($id) |
|
| 29 | + : $this->$method($id); |
|
| 30 | + return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @return string |
|
| 35 | + */ |
|
| 36 | + protected function getFieldDefault(array $field) |
|
| 37 | + { |
|
| 38 | + return Arr::get($field, 'default'); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + protected function getFieldNameForDependsOn($path) |
|
| 45 | + { |
|
| 46 | + $fieldName = Str::convertPathToName($path, OptionManager::databaseKey()); |
|
| 47 | + return $this->isMultiDependency($path) |
|
| 48 | + ? $fieldName.'[]' |
|
| 49 | + : $fieldName; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return array |
|
| 54 | + */ |
|
| 55 | + protected function getSettingFields($path) |
|
| 56 | + { |
|
| 57 | + return array_filter($this->settings, function ($key) use ($path) { |
|
| 58 | + return Str::startsWith($path, $key); |
|
| 59 | + }, ARRAY_FILTER_USE_KEY); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + protected function getSettingRows(array $fields) |
|
| 66 | + { |
|
| 67 | + $rows = ''; |
|
| 68 | + foreach ($fields as $name => $field) { |
|
| 69 | + $field = wp_parse_args($field, [ |
|
| 70 | + 'is_setting' => true, |
|
| 71 | + 'name' => $name, |
|
| 72 | + ]); |
|
| 73 | + $rows.= new Field($this->normalize($field)); |
|
| 74 | + } |
|
| 75 | + return $rows; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param string $id |
|
| 80 | + * @return array |
|
| 81 | + */ |
|
| 82 | + protected function getTemplateData($id) |
|
| 83 | + { |
|
| 84 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 85 | + return [ |
|
| 86 | + 'context' => [ |
|
| 87 | + 'rows' => $this->getSettingRows($fields), |
|
| 88 | + ], |
|
| 89 | + ]; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param string $id |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + protected function getTemplateDataForAddons($id) |
|
| 97 | + { |
|
| 98 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 99 | + $settings = Arr::convertDotNotationArray($fields); |
|
| 100 | + $settingKeys = array_keys($settings['settings']['addons']); |
|
| 101 | + $results = []; |
|
| 102 | + foreach ($settingKeys as $key) { |
|
| 103 | + $addonFields = array_filter($fields, function ($path) use ($key) { |
|
| 104 | + return Str::startsWith('settings.addons.'.$key, $path); |
|
| 105 | + }, ARRAY_FILTER_USE_KEY); |
|
| 106 | + $results[$key] = $this->getSettingRows($addonFields); |
|
| 107 | + } |
|
| 108 | + ksort($results); |
|
| 109 | + return [ |
|
| 110 | + 'settings' => $results, |
|
| 111 | + ]; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @param string $id |
|
| 116 | + * @return array |
|
| 117 | + */ |
|
| 118 | + protected function getTemplateDataForLicenses($id) |
|
| 119 | + { |
|
| 120 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 121 | + ksort($fields); |
|
| 122 | + return [ |
|
| 123 | + 'context' => [ |
|
| 124 | + 'rows' => $this->getSettingRows($fields), |
|
| 125 | + ], |
|
| 126 | + ]; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @return array |
|
| 131 | + */ |
|
| 132 | + protected function getTemplateDataForTranslations() |
|
| 133 | + { |
|
| 134 | + $translations = glsr(Translation::class)->renderAll(); |
|
| 135 | + $class = empty($translations) |
|
| 136 | + ? 'glsr-hidden' |
|
| 137 | + : ''; |
|
| 138 | + return [ |
|
| 139 | + 'context' => [ |
|
| 140 | + 'class' => $class, |
|
| 141 | + 'database_key' => OptionManager::databaseKey(), |
|
| 142 | + 'translations' => $translations, |
|
| 143 | + ], |
|
| 144 | + ]; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param string $path |
|
| 149 | + * @param string|array $expectedValue |
|
| 150 | + * @return bool |
|
| 151 | + */ |
|
| 152 | + protected function isFieldHidden($path, $expectedValue) |
|
| 153 | + { |
|
| 154 | + $optionValue = glsr(OptionManager::class)->get( |
|
| 155 | + $path, |
|
| 156 | + Arr::get(glsr()->defaults, $path) |
|
| 157 | + ); |
|
| 158 | + if (is_array($expectedValue)) { |
|
| 159 | + return is_array($optionValue) |
|
| 160 | + ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
| 161 | + : !in_array($optionValue, $expectedValue); |
|
| 162 | + } |
|
| 163 | + return $optionValue != $expectedValue; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @return bool |
|
| 168 | + */ |
|
| 169 | + protected function isMultiDependency($path) |
|
| 170 | + { |
|
| 171 | + if (isset($this->settings[$path])) { |
|
| 172 | + $field = $this->settings[$path]; |
|
| 173 | + return ('checkbox' == $field['type'] && !empty($field['options'])) |
|
| 174 | + || !empty($field['multiple']); |
|
| 175 | + } |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @return array |
|
| 181 | + */ |
|
| 182 | + protected function normalize(array $field) |
|
| 183 | + { |
|
| 184 | + $field = $this->normalizeDependsOn($field); |
|
| 185 | + $field = $this->normalizeLabelAndLegend($field); |
|
| 186 | + $field = $this->normalizeValue($field); |
|
| 187 | + return $field; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @return array |
|
| 192 | + */ |
|
| 193 | + protected function normalizeDependsOn(array $field) |
|
| 194 | + { |
|
| 195 | + if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
| 196 | + $isFieldHidden = false; |
|
| 197 | + $conditions = []; |
|
| 198 | + foreach ($field['depends_on'] as $path => $value) { |
|
| 199 | + $conditions[] = [ |
|
| 200 | + 'name' => $this->getFieldNameForDependsOn($path), |
|
| 201 | + 'value' => $value, |
|
| 202 | + ]; |
|
| 203 | + if ($this->isFieldHidden($path, $value)) { |
|
| 204 | + $isFieldHidden = true; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
| 208 | + $field['is_hidden'] = $isFieldHidden; |
|
| 209 | + } |
|
| 210 | + return $field; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @return array |
|
| 215 | + */ |
|
| 216 | + protected function normalizeLabelAndLegend(array $field) |
|
| 217 | + { |
|
| 218 | + if (!empty($field['label'])) { |
|
| 219 | + $field['legend'] = $field['label']; |
|
| 220 | + unset($field['label']); |
|
| 221 | + } else { |
|
| 222 | + $field['is_valid'] = false; |
|
| 223 | + glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
| 224 | + } |
|
| 225 | + return $field; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @return array |
|
| 230 | + */ |
|
| 231 | + protected function normalizeValue(array $field) |
|
| 232 | + { |
|
| 233 | + if (!isset($field['value'])) { |
|
| 234 | + $field['value'] = glsr(OptionManager::class)->get( |
|
| 235 | + $field['name'], |
|
| 236 | + $this->getFieldDefault($field) |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + return $field; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + protected function normalizeSettingPath($path) |
|
| 246 | + { |
|
| 247 | + return Str::prefix('settings.', rtrim($path, '.')); |
|
| 248 | + } |
|
| 249 | 249 | } |
@@ -20,31 +20,31 @@ discard block |
||
| 20 | 20 | * @param string $id |
| 21 | 21 | * @return string |
| 22 | 22 | */ |
| 23 | - public function buildFields($id) |
|
| 23 | + public function buildFields( $id ) |
|
| 24 | 24 | { |
| 25 | - $this->settings = glsr(DefaultsManager::class)->settings(); |
|
| 26 | - $method = Helper::buildMethodName($id, 'getTemplateDataFor'); |
|
| 27 | - $data = !method_exists($this, $method) |
|
| 28 | - ? $this->getTemplateData($id) |
|
| 29 | - : $this->$method($id); |
|
| 30 | - return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
| 25 | + $this->settings = glsr( DefaultsManager::class )->settings(); |
|
| 26 | + $method = Helper::buildMethodName( $id, 'getTemplateDataFor' ); |
|
| 27 | + $data = !method_exists( $this, $method ) |
|
| 28 | + ? $this->getTemplateData( $id ) |
|
| 29 | + : $this->$method( $id ); |
|
| 30 | + return glsr( Template::class )->build( 'pages/settings/'.$id, $data ); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * @return string |
| 35 | 35 | */ |
| 36 | - protected function getFieldDefault(array $field) |
|
| 36 | + protected function getFieldDefault( array $field ) |
|
| 37 | 37 | { |
| 38 | - return Arr::get($field, 'default'); |
|
| 38 | + return Arr::get( $field, 'default' ); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * @return string |
| 43 | 43 | */ |
| 44 | - protected function getFieldNameForDependsOn($path) |
|
| 44 | + protected function getFieldNameForDependsOn( $path ) |
|
| 45 | 45 | { |
| 46 | - $fieldName = Str::convertPathToName($path, OptionManager::databaseKey()); |
|
| 47 | - return $this->isMultiDependency($path) |
|
| 46 | + $fieldName = Str::convertPathToName( $path, OptionManager::databaseKey() ); |
|
| 47 | + return $this->isMultiDependency( $path ) |
|
| 48 | 48 | ? $fieldName.'[]' |
| 49 | 49 | : $fieldName; |
| 50 | 50 | } |
@@ -52,25 +52,25 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * @return array |
| 54 | 54 | */ |
| 55 | - protected function getSettingFields($path) |
|
| 55 | + protected function getSettingFields( $path ) |
|
| 56 | 56 | { |
| 57 | - return array_filter($this->settings, function ($key) use ($path) { |
|
| 58 | - return Str::startsWith($path, $key); |
|
| 59 | - }, ARRAY_FILTER_USE_KEY); |
|
| 57 | + return array_filter( $this->settings, function( $key ) use ($path) { |
|
| 58 | + return Str::startsWith( $path, $key ); |
|
| 59 | + }, ARRAY_FILTER_USE_KEY ); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * @return string |
| 64 | 64 | */ |
| 65 | - protected function getSettingRows(array $fields) |
|
| 65 | + protected function getSettingRows( array $fields ) |
|
| 66 | 66 | { |
| 67 | 67 | $rows = ''; |
| 68 | - foreach ($fields as $name => $field) { |
|
| 69 | - $field = wp_parse_args($field, [ |
|
| 68 | + foreach( $fields as $name => $field ) { |
|
| 69 | + $field = wp_parse_args( $field, [ |
|
| 70 | 70 | 'is_setting' => true, |
| 71 | 71 | 'name' => $name, |
| 72 | - ]); |
|
| 73 | - $rows.= new Field($this->normalize($field)); |
|
| 72 | + ] ); |
|
| 73 | + $rows .= new Field( $this->normalize( $field ) ); |
|
| 74 | 74 | } |
| 75 | 75 | return $rows; |
| 76 | 76 | } |
@@ -79,12 +79,12 @@ discard block |
||
| 79 | 79 | * @param string $id |
| 80 | 80 | * @return array |
| 81 | 81 | */ |
| 82 | - protected function getTemplateData($id) |
|
| 82 | + protected function getTemplateData( $id ) |
|
| 83 | 83 | { |
| 84 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 84 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
| 85 | 85 | return [ |
| 86 | 86 | 'context' => [ |
| 87 | - 'rows' => $this->getSettingRows($fields), |
|
| 87 | + 'rows' => $this->getSettingRows( $fields ), |
|
| 88 | 88 | ], |
| 89 | 89 | ]; |
| 90 | 90 | } |
@@ -93,19 +93,19 @@ discard block |
||
| 93 | 93 | * @param string $id |
| 94 | 94 | * @return array |
| 95 | 95 | */ |
| 96 | - protected function getTemplateDataForAddons($id) |
|
| 96 | + protected function getTemplateDataForAddons( $id ) |
|
| 97 | 97 | { |
| 98 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 99 | - $settings = Arr::convertDotNotationArray($fields); |
|
| 100 | - $settingKeys = array_keys($settings['settings']['addons']); |
|
| 98 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
| 99 | + $settings = Arr::convertDotNotationArray( $fields ); |
|
| 100 | + $settingKeys = array_keys( $settings['settings']['addons'] ); |
|
| 101 | 101 | $results = []; |
| 102 | - foreach ($settingKeys as $key) { |
|
| 103 | - $addonFields = array_filter($fields, function ($path) use ($key) { |
|
| 104 | - return Str::startsWith('settings.addons.'.$key, $path); |
|
| 105 | - }, ARRAY_FILTER_USE_KEY); |
|
| 106 | - $results[$key] = $this->getSettingRows($addonFields); |
|
| 102 | + foreach( $settingKeys as $key ) { |
|
| 103 | + $addonFields = array_filter( $fields, function( $path ) use ($key) { |
|
| 104 | + return Str::startsWith( 'settings.addons.'.$key, $path ); |
|
| 105 | + }, ARRAY_FILTER_USE_KEY ); |
|
| 106 | + $results[$key] = $this->getSettingRows( $addonFields ); |
|
| 107 | 107 | } |
| 108 | - ksort($results); |
|
| 108 | + ksort( $results ); |
|
| 109 | 109 | return [ |
| 110 | 110 | 'settings' => $results, |
| 111 | 111 | ]; |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | * @param string $id |
| 116 | 116 | * @return array |
| 117 | 117 | */ |
| 118 | - protected function getTemplateDataForLicenses($id) |
|
| 118 | + protected function getTemplateDataForLicenses( $id ) |
|
| 119 | 119 | { |
| 120 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
| 121 | - ksort($fields); |
|
| 120 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
| 121 | + ksort( $fields ); |
|
| 122 | 122 | return [ |
| 123 | 123 | 'context' => [ |
| 124 | - 'rows' => $this->getSettingRows($fields), |
|
| 124 | + 'rows' => $this->getSettingRows( $fields ), |
|
| 125 | 125 | ], |
| 126 | 126 | ]; |
| 127 | 127 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | protected function getTemplateDataForTranslations() |
| 133 | 133 | { |
| 134 | - $translations = glsr(Translation::class)->renderAll(); |
|
| 134 | + $translations = glsr( Translation::class )->renderAll(); |
|
| 135 | 135 | $class = empty($translations) |
| 136 | 136 | ? 'glsr-hidden' |
| 137 | 137 | : ''; |
@@ -149,16 +149,16 @@ discard block |
||
| 149 | 149 | * @param string|array $expectedValue |
| 150 | 150 | * @return bool |
| 151 | 151 | */ |
| 152 | - protected function isFieldHidden($path, $expectedValue) |
|
| 152 | + protected function isFieldHidden( $path, $expectedValue ) |
|
| 153 | 153 | { |
| 154 | - $optionValue = glsr(OptionManager::class)->get( |
|
| 154 | + $optionValue = glsr( OptionManager::class )->get( |
|
| 155 | 155 | $path, |
| 156 | - Arr::get(glsr()->defaults, $path) |
|
| 156 | + Arr::get( glsr()->defaults, $path ) |
|
| 157 | 157 | ); |
| 158 | - if (is_array($expectedValue)) { |
|
| 159 | - return is_array($optionValue) |
|
| 160 | - ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
| 161 | - : !in_array($optionValue, $expectedValue); |
|
| 158 | + if( is_array( $expectedValue ) ) { |
|
| 159 | + return is_array( $optionValue ) |
|
| 160 | + ? 0 === count( array_intersect( $optionValue, $expectedValue ) ) |
|
| 161 | + : !in_array( $optionValue, $expectedValue ); |
|
| 162 | 162 | } |
| 163 | 163 | return $optionValue != $expectedValue; |
| 164 | 164 | } |
@@ -166,9 +166,9 @@ discard block |
||
| 166 | 166 | /** |
| 167 | 167 | * @return bool |
| 168 | 168 | */ |
| 169 | - protected function isMultiDependency($path) |
|
| 169 | + protected function isMultiDependency( $path ) |
|
| 170 | 170 | { |
| 171 | - if (isset($this->settings[$path])) { |
|
| 171 | + if( isset($this->settings[$path]) ) { |
|
| 172 | 172 | $field = $this->settings[$path]; |
| 173 | 173 | return ('checkbox' == $field['type'] && !empty($field['options'])) |
| 174 | 174 | || !empty($field['multiple']); |
@@ -179,32 +179,32 @@ discard block |
||
| 179 | 179 | /** |
| 180 | 180 | * @return array |
| 181 | 181 | */ |
| 182 | - protected function normalize(array $field) |
|
| 182 | + protected function normalize( array $field ) |
|
| 183 | 183 | { |
| 184 | - $field = $this->normalizeDependsOn($field); |
|
| 185 | - $field = $this->normalizeLabelAndLegend($field); |
|
| 186 | - $field = $this->normalizeValue($field); |
|
| 184 | + $field = $this->normalizeDependsOn( $field ); |
|
| 185 | + $field = $this->normalizeLabelAndLegend( $field ); |
|
| 186 | + $field = $this->normalizeValue( $field ); |
|
| 187 | 187 | return $field; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | 191 | * @return array |
| 192 | 192 | */ |
| 193 | - protected function normalizeDependsOn(array $field) |
|
| 193 | + protected function normalizeDependsOn( array $field ) |
|
| 194 | 194 | { |
| 195 | - if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
| 195 | + if( !empty($field['depends_on']) && is_array( $field['depends_on'] ) ) { |
|
| 196 | 196 | $isFieldHidden = false; |
| 197 | 197 | $conditions = []; |
| 198 | - foreach ($field['depends_on'] as $path => $value) { |
|
| 198 | + foreach( $field['depends_on'] as $path => $value ) { |
|
| 199 | 199 | $conditions[] = [ |
| 200 | - 'name' => $this->getFieldNameForDependsOn($path), |
|
| 200 | + 'name' => $this->getFieldNameForDependsOn( $path ), |
|
| 201 | 201 | 'value' => $value, |
| 202 | 202 | ]; |
| 203 | - if ($this->isFieldHidden($path, $value)) { |
|
| 203 | + if( $this->isFieldHidden( $path, $value ) ) { |
|
| 204 | 204 | $isFieldHidden = true; |
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | - $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
| 207 | + $field['data-depends'] = json_encode( $conditions, JSON_HEX_APOS | JSON_HEX_QUOT ); |
|
| 208 | 208 | $field['is_hidden'] = $isFieldHidden; |
| 209 | 209 | } |
| 210 | 210 | return $field; |
@@ -213,14 +213,14 @@ discard block |
||
| 213 | 213 | /** |
| 214 | 214 | * @return array |
| 215 | 215 | */ |
| 216 | - protected function normalizeLabelAndLegend(array $field) |
|
| 216 | + protected function normalizeLabelAndLegend( array $field ) |
|
| 217 | 217 | { |
| 218 | - if (!empty($field['label'])) { |
|
| 218 | + if( !empty($field['label']) ) { |
|
| 219 | 219 | $field['legend'] = $field['label']; |
| 220 | 220 | unset($field['label']); |
| 221 | 221 | } else { |
| 222 | 222 | $field['is_valid'] = false; |
| 223 | - glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
| 223 | + glsr_log()->warning( 'Setting field is missing a label' )->debug( $field ); |
|
| 224 | 224 | } |
| 225 | 225 | return $field; |
| 226 | 226 | } |
@@ -228,12 +228,12 @@ discard block |
||
| 228 | 228 | /** |
| 229 | 229 | * @return array |
| 230 | 230 | */ |
| 231 | - protected function normalizeValue(array $field) |
|
| 231 | + protected function normalizeValue( array $field ) |
|
| 232 | 232 | { |
| 233 | - if (!isset($field['value'])) { |
|
| 234 | - $field['value'] = glsr(OptionManager::class)->get( |
|
| 233 | + if( !isset($field['value']) ) { |
|
| 234 | + $field['value'] = glsr( OptionManager::class )->get( |
|
| 235 | 235 | $field['name'], |
| 236 | - $this->getFieldDefault($field) |
|
| 236 | + $this->getFieldDefault( $field ) |
|
| 237 | 237 | ); |
| 238 | 238 | } |
| 239 | 239 | return $field; |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | /** |
| 243 | 243 | * @return string |
| 244 | 244 | */ |
| 245 | - protected function normalizeSettingPath($path) |
|
| 245 | + protected function normalizeSettingPath( $path ) |
|
| 246 | 246 | { |
| 247 | - return Str::prefix('settings.', rtrim($path, '.')); |
|
| 247 | + return Str::prefix( 'settings.', rtrim( $path, '.' ) ); |
|
| 248 | 248 | } |
| 249 | 249 | } |
@@ -12,144 +12,144 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Style |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - public $fields; |
|
| 15 | + /** |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + public $fields; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - public $style; |
|
| 20 | + /** |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + public $style; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - public $pagination; |
|
| 25 | + /** |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + public $pagination; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - public $validation; |
|
| 30 | + /** |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + public $validation; |
|
| 34 | 34 | |
| 35 | - public function __construct() |
|
| 36 | - { |
|
| 37 | - $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
| 38 | - $this->setConfig(); |
|
| 39 | - } |
|
| 35 | + public function __construct() |
|
| 36 | + { |
|
| 37 | + $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
| 38 | + $this->setConfig(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param string $view |
|
| 43 | - * @return string |
|
| 44 | - */ |
|
| 45 | - public function filterView($view) |
|
| 46 | - { |
|
| 47 | - $styledViews = [ |
|
| 48 | - 'templates/form/field', |
|
| 49 | - 'templates/form/response', |
|
| 50 | - 'templates/form/submit-button', |
|
| 51 | - 'templates/reviews-form', |
|
| 52 | - ]; |
|
| 53 | - if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
| 54 | - return $view; |
|
| 55 | - } |
|
| 56 | - $views = $this->generatePossibleViews($view); |
|
| 57 | - foreach ($views as $possibleView) { |
|
| 58 | - if (!file_exists(glsr()->file($possibleView))) { |
|
| 59 | - continue; |
|
| 60 | - } |
|
| 61 | - return Str::removePrefix('views/', $possibleView); |
|
| 62 | - } |
|
| 63 | - return $view; |
|
| 64 | - } |
|
| 41 | + /** |
|
| 42 | + * @param string $view |
|
| 43 | + * @return string |
|
| 44 | + */ |
|
| 45 | + public function filterView($view) |
|
| 46 | + { |
|
| 47 | + $styledViews = [ |
|
| 48 | + 'templates/form/field', |
|
| 49 | + 'templates/form/response', |
|
| 50 | + 'templates/form/submit-button', |
|
| 51 | + 'templates/reviews-form', |
|
| 52 | + ]; |
|
| 53 | + if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
| 54 | + return $view; |
|
| 55 | + } |
|
| 56 | + $views = $this->generatePossibleViews($view); |
|
| 57 | + foreach ($views as $possibleView) { |
|
| 58 | + if (!file_exists(glsr()->file($possibleView))) { |
|
| 59 | + continue; |
|
| 60 | + } |
|
| 61 | + return Str::removePrefix('views/', $possibleView); |
|
| 62 | + } |
|
| 63 | + return $view; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - public function get() |
|
| 70 | - { |
|
| 71 | - return apply_filters('site-reviews/style', $this->style); |
|
| 72 | - } |
|
| 66 | + /** |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + public function get() |
|
| 70 | + { |
|
| 71 | + return apply_filters('site-reviews/style', $this->style); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return array |
|
| 76 | - */ |
|
| 77 | - public function setConfig() |
|
| 78 | - { |
|
| 79 | - $config = shortcode_atts( |
|
| 80 | - array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
| 81 | - glsr()->config('styles/'.$this->style) |
|
| 82 | - ); |
|
| 83 | - $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
| 84 | - $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
| 85 | - $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
| 86 | - } |
|
| 74 | + /** |
|
| 75 | + * @return array |
|
| 76 | + */ |
|
| 77 | + public function setConfig() |
|
| 78 | + { |
|
| 79 | + $config = shortcode_atts( |
|
| 80 | + array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
| 81 | + glsr()->config('styles/'.$this->style) |
|
| 82 | + ); |
|
| 83 | + $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
| 84 | + $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
| 85 | + $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @return void |
|
| 90 | - */ |
|
| 91 | - public function modifyField(Builder $instance) |
|
| 92 | - { |
|
| 93 | - if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
| 94 | - return; |
|
| 95 | - } |
|
| 96 | - call_user_func_array([$this, 'customize'], [$instance]); |
|
| 97 | - } |
|
| 88 | + /** |
|
| 89 | + * @return void |
|
| 90 | + */ |
|
| 91 | + public function modifyField(Builder $instance) |
|
| 92 | + { |
|
| 93 | + if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | + call_user_func_array([$this, 'customize'], [$instance]); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @return array |
|
| 101 | - */ |
|
| 102 | - public function paginationArgs(array $args) |
|
| 103 | - { |
|
| 104 | - return wp_parse_args($args, $this->pagination); |
|
| 105 | - } |
|
| 99 | + /** |
|
| 100 | + * @return array |
|
| 101 | + */ |
|
| 102 | + public function paginationArgs(array $args) |
|
| 103 | + { |
|
| 104 | + return wp_parse_args($args, $this->pagination); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @return void |
|
| 109 | - */ |
|
| 110 | - protected function customize(Builder $instance) |
|
| 111 | - { |
|
| 112 | - if (!array_key_exists($instance->tag, $this->fields)) { |
|
| 113 | - return; |
|
| 114 | - } |
|
| 115 | - $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
| 116 | - $key = $instance->tag.'_'.$args['type']; |
|
| 117 | - $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
| 118 | - $instance->args['class'] = trim($args['class'].' '.$classes); |
|
| 119 | - do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
| 120 | - } |
|
| 107 | + /** |
|
| 108 | + * @return void |
|
| 109 | + */ |
|
| 110 | + protected function customize(Builder $instance) |
|
| 111 | + { |
|
| 112 | + if (!array_key_exists($instance->tag, $this->fields)) { |
|
| 113 | + return; |
|
| 114 | + } |
|
| 115 | + $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
| 116 | + $key = $instance->tag.'_'.$args['type']; |
|
| 117 | + $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
| 118 | + $instance->args['class'] = trim($args['class'].' '.$classes); |
|
| 119 | + do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * @param string $view |
|
| 124 | - * @return array |
|
| 125 | - */ |
|
| 126 | - protected function generatePossibleViews($view) |
|
| 127 | - { |
|
| 128 | - $basename = basename($view); |
|
| 129 | - $basepath = rtrim($view, $basename); |
|
| 130 | - $customPath = 'views/partials/styles/'.$this->style.'/'; |
|
| 131 | - $parts = explode('_', $basename); |
|
| 132 | - $views = [ |
|
| 133 | - $customPath.$basename, |
|
| 134 | - $customPath.$parts[0], |
|
| 135 | - $view, |
|
| 136 | - $basepath.$parts[0], |
|
| 137 | - ]; |
|
| 138 | - return array_filter($views); |
|
| 139 | - } |
|
| 122 | + /** |
|
| 123 | + * @param string $view |
|
| 124 | + * @return array |
|
| 125 | + */ |
|
| 126 | + protected function generatePossibleViews($view) |
|
| 127 | + { |
|
| 128 | + $basename = basename($view); |
|
| 129 | + $basepath = rtrim($view, $basename); |
|
| 130 | + $customPath = 'views/partials/styles/'.$this->style.'/'; |
|
| 131 | + $parts = explode('_', $basename); |
|
| 132 | + $views = [ |
|
| 133 | + $customPath.$basename, |
|
| 134 | + $customPath.$parts[0], |
|
| 135 | + $view, |
|
| 136 | + $basepath.$parts[0], |
|
| 137 | + ]; |
|
| 138 | + return array_filter($views); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * @return bool |
|
| 143 | - */ |
|
| 144 | - protected function isPublicInstance(Builder $instance) |
|
| 145 | - { |
|
| 146 | - $args = wp_parse_args($instance->args, [ |
|
| 147 | - 'is_public' => false, |
|
| 148 | - 'is_raw' => false, |
|
| 149 | - ]); |
|
| 150 | - if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
| 151 | - return false; |
|
| 152 | - } |
|
| 153 | - return true; |
|
| 154 | - } |
|
| 141 | + /** |
|
| 142 | + * @return bool |
|
| 143 | + */ |
|
| 144 | + protected function isPublicInstance(Builder $instance) |
|
| 145 | + { |
|
| 146 | + $args = wp_parse_args($instance->args, [ |
|
| 147 | + 'is_public' => false, |
|
| 148 | + 'is_raw' => false, |
|
| 149 | + ]); |
|
| 150 | + if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
| 151 | + return false; |
|
| 152 | + } |
|
| 153 | + return true; |
|
| 154 | + } |
|
| 155 | 155 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | public function __construct() |
| 36 | 36 | { |
| 37 | - $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
| 37 | + $this->style = glsr( OptionManager::class )->get( 'settings.general.style', 'default' ); |
|
| 38 | 38 | $this->setConfig(); |
| 39 | 39 | } |
| 40 | 40 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @param string $view |
| 43 | 43 | * @return string |
| 44 | 44 | */ |
| 45 | - public function filterView($view) |
|
| 45 | + public function filterView( $view ) |
|
| 46 | 46 | { |
| 47 | 47 | $styledViews = [ |
| 48 | 48 | 'templates/form/field', |
@@ -50,15 +50,15 @@ discard block |
||
| 50 | 50 | 'templates/form/submit-button', |
| 51 | 51 | 'templates/reviews-form', |
| 52 | 52 | ]; |
| 53 | - if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
| 53 | + if( !preg_match( '('.implode( '|', $styledViews ).')', $view ) ) { |
|
| 54 | 54 | return $view; |
| 55 | 55 | } |
| 56 | - $views = $this->generatePossibleViews($view); |
|
| 57 | - foreach ($views as $possibleView) { |
|
| 58 | - if (!file_exists(glsr()->file($possibleView))) { |
|
| 56 | + $views = $this->generatePossibleViews( $view ); |
|
| 57 | + foreach( $views as $possibleView ) { |
|
| 58 | + if( !file_exists( glsr()->file( $possibleView ) ) ) { |
|
| 59 | 59 | continue; |
| 60 | 60 | } |
| 61 | - return Str::removePrefix('views/', $possibleView); |
|
| 61 | + return Str::removePrefix( 'views/', $possibleView ); |
|
| 62 | 62 | } |
| 63 | 63 | return $view; |
| 64 | 64 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function get() |
| 70 | 70 | { |
| 71 | - return apply_filters('site-reviews/style', $this->style); |
|
| 71 | + return apply_filters( 'site-reviews/style', $this->style ); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -77,77 +77,77 @@ discard block |
||
| 77 | 77 | public function setConfig() |
| 78 | 78 | { |
| 79 | 79 | $config = shortcode_atts( |
| 80 | - array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
| 81 | - glsr()->config('styles/'.$this->style) |
|
| 80 | + array_fill_keys( ['fields', 'pagination', 'validation'], [] ), |
|
| 81 | + glsr()->config( 'styles/'.$this->style ) |
|
| 82 | 82 | ); |
| 83 | - $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
| 84 | - $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
| 85 | - $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
| 83 | + $this->fields = glsr( StyleFieldsDefaults::class )->restrict( $config['fields'] ); |
|
| 84 | + $this->pagination = glsr( PaginationDefaults::class )->restrict( $config['pagination'] ); |
|
| 85 | + $this->validation = glsr( StyleValidationDefaults::class )->restrict( $config['validation'] ); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * @return void |
| 90 | 90 | */ |
| 91 | - public function modifyField(Builder $instance) |
|
| 91 | + public function modifyField( Builder $instance ) |
|
| 92 | 92 | { |
| 93 | - if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
| 93 | + if( !$this->isPublicInstance( $instance ) || empty(array_filter( $this->fields )) ) { |
|
| 94 | 94 | return; |
| 95 | 95 | } |
| 96 | - call_user_func_array([$this, 'customize'], [$instance]); |
|
| 96 | + call_user_func_array( [$this, 'customize'], [$instance] ); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * @return array |
| 101 | 101 | */ |
| 102 | - public function paginationArgs(array $args) |
|
| 102 | + public function paginationArgs( array $args ) |
|
| 103 | 103 | { |
| 104 | - return wp_parse_args($args, $this->pagination); |
|
| 104 | + return wp_parse_args( $args, $this->pagination ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * @return void |
| 109 | 109 | */ |
| 110 | - protected function customize(Builder $instance) |
|
| 110 | + protected function customize( Builder $instance ) |
|
| 111 | 111 | { |
| 112 | - if (!array_key_exists($instance->tag, $this->fields)) { |
|
| 112 | + if( !array_key_exists( $instance->tag, $this->fields ) ) { |
|
| 113 | 113 | return; |
| 114 | 114 | } |
| 115 | - $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
| 115 | + $args = wp_parse_args( $instance->args, array_fill_keys( ['class', 'type'], '' ) ); |
|
| 116 | 116 | $key = $instance->tag.'_'.$args['type']; |
| 117 | - $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
| 118 | - $instance->args['class'] = trim($args['class'].' '.$classes); |
|
| 119 | - do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
| 117 | + $classes = Arr::get( $this->fields, $key, Arr::get( $this->fields, $instance->tag ) ); |
|
| 118 | + $instance->args['class'] = trim( $args['class'].' '.$classes ); |
|
| 119 | + do_action_ref_array( 'site-reviews/customize/'.$this->style, [$instance] ); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | 123 | * @param string $view |
| 124 | 124 | * @return array |
| 125 | 125 | */ |
| 126 | - protected function generatePossibleViews($view) |
|
| 126 | + protected function generatePossibleViews( $view ) |
|
| 127 | 127 | { |
| 128 | - $basename = basename($view); |
|
| 129 | - $basepath = rtrim($view, $basename); |
|
| 128 | + $basename = basename( $view ); |
|
| 129 | + $basepath = rtrim( $view, $basename ); |
|
| 130 | 130 | $customPath = 'views/partials/styles/'.$this->style.'/'; |
| 131 | - $parts = explode('_', $basename); |
|
| 131 | + $parts = explode( '_', $basename ); |
|
| 132 | 132 | $views = [ |
| 133 | 133 | $customPath.$basename, |
| 134 | 134 | $customPath.$parts[0], |
| 135 | 135 | $view, |
| 136 | 136 | $basepath.$parts[0], |
| 137 | 137 | ]; |
| 138 | - return array_filter($views); |
|
| 138 | + return array_filter( $views ); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * @return bool |
| 143 | 143 | */ |
| 144 | - protected function isPublicInstance(Builder $instance) |
|
| 144 | + protected function isPublicInstance( Builder $instance ) |
|
| 145 | 145 | { |
| 146 | - $args = wp_parse_args($instance->args, [ |
|
| 146 | + $args = wp_parse_args( $instance->args, [ |
|
| 147 | 147 | 'is_public' => false, |
| 148 | 148 | 'is_raw' => false, |
| 149 | - ]); |
|
| 150 | - if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
| 149 | + ] ); |
|
| 150 | + if( is_admin() || !$args['is_public'] || $args['is_raw'] ) { |
|
| 151 | 151 | return false; |
| 152 | 152 | } |
| 153 | 153 | return true; |
@@ -12,173 +12,173 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Review implements \ArrayAccess |
| 14 | 14 | { |
| 15 | - public $assigned_to; |
|
| 16 | - public $author; |
|
| 17 | - public $avatar; |
|
| 18 | - public $content; |
|
| 19 | - public $custom; |
|
| 20 | - public $date; |
|
| 21 | - public $email; |
|
| 22 | - public $ID; |
|
| 23 | - public $ip_address; |
|
| 24 | - public $modified; |
|
| 25 | - public $pinned; |
|
| 26 | - public $rating; |
|
| 27 | - public $response; |
|
| 28 | - public $review_id; |
|
| 29 | - public $review_type; |
|
| 30 | - public $status; |
|
| 31 | - public $term_ids; |
|
| 32 | - public $title; |
|
| 33 | - public $url; |
|
| 34 | - public $user_id; |
|
| 15 | + public $assigned_to; |
|
| 16 | + public $author; |
|
| 17 | + public $avatar; |
|
| 18 | + public $content; |
|
| 19 | + public $custom; |
|
| 20 | + public $date; |
|
| 21 | + public $email; |
|
| 22 | + public $ID; |
|
| 23 | + public $ip_address; |
|
| 24 | + public $modified; |
|
| 25 | + public $pinned; |
|
| 26 | + public $rating; |
|
| 27 | + public $response; |
|
| 28 | + public $review_id; |
|
| 29 | + public $review_type; |
|
| 30 | + public $status; |
|
| 31 | + public $term_ids; |
|
| 32 | + public $title; |
|
| 33 | + public $url; |
|
| 34 | + public $user_id; |
|
| 35 | 35 | |
| 36 | - public function __construct(WP_Post $post) |
|
| 37 | - { |
|
| 38 | - if (Application::POST_TYPE != $post->post_type) { |
|
| 39 | - return; |
|
| 40 | - } |
|
| 41 | - $this->content = $post->post_content; |
|
| 42 | - $this->date = $post->post_date; |
|
| 43 | - $this->ID = intval($post->ID); |
|
| 44 | - $this->status = $post->post_status; |
|
| 45 | - $this->title = $post->post_title; |
|
| 46 | - $this->user_id = intval($post->post_author); |
|
| 47 | - $this->setProperties($post); |
|
| 48 | - $this->setTermIds($post); |
|
| 49 | - } |
|
| 36 | + public function __construct(WP_Post $post) |
|
| 37 | + { |
|
| 38 | + if (Application::POST_TYPE != $post->post_type) { |
|
| 39 | + return; |
|
| 40 | + } |
|
| 41 | + $this->content = $post->post_content; |
|
| 42 | + $this->date = $post->post_date; |
|
| 43 | + $this->ID = intval($post->ID); |
|
| 44 | + $this->status = $post->post_status; |
|
| 45 | + $this->title = $post->post_title; |
|
| 46 | + $this->user_id = intval($post->post_author); |
|
| 47 | + $this->setProperties($post); |
|
| 48 | + $this->setTermIds($post); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return mixed |
|
| 53 | - */ |
|
| 54 | - public function __get($key) |
|
| 55 | - { |
|
| 56 | - return $this->offsetGet($key); |
|
| 57 | - } |
|
| 51 | + /** |
|
| 52 | + * @return mixed |
|
| 53 | + */ |
|
| 54 | + public function __get($key) |
|
| 55 | + { |
|
| 56 | + return $this->offsetGet($key); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public function __toString() |
|
| 63 | - { |
|
| 64 | - return (string) $this->build(); |
|
| 65 | - } |
|
| 59 | + /** |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public function __toString() |
|
| 63 | + { |
|
| 64 | + return (string) $this->build(); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @return ReviewHtml |
|
| 69 | - */ |
|
| 70 | - public function build(array $args = []) |
|
| 71 | - { |
|
| 72 | - if (empty($this->ID)) { |
|
| 73 | - return new ReviewHtml($this); |
|
| 74 | - } |
|
| 75 | - $partial = glsr(SiteReviewsPartial::class); |
|
| 76 | - $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
| 77 | - $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
| 78 | - return $partial->buildReview($this); |
|
| 79 | - } |
|
| 67 | + /** |
|
| 68 | + * @return ReviewHtml |
|
| 69 | + */ |
|
| 70 | + public function build(array $args = []) |
|
| 71 | + { |
|
| 72 | + if (empty($this->ID)) { |
|
| 73 | + return new ReviewHtml($this); |
|
| 74 | + } |
|
| 75 | + $partial = glsr(SiteReviewsPartial::class); |
|
| 76 | + $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
| 77 | + $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
| 78 | + return $partial->buildReview($this); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @param mixed $key |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - public function offsetExists($key) |
|
| 86 | - { |
|
| 87 | - return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
| 88 | - } |
|
| 81 | + /** |
|
| 82 | + * @param mixed $key |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + public function offsetExists($key) |
|
| 86 | + { |
|
| 87 | + return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * @param mixed $key |
|
| 92 | - * @return mixed |
|
| 93 | - */ |
|
| 94 | - public function offsetGet($key) |
|
| 95 | - { |
|
| 96 | - return property_exists($this, $key) |
|
| 97 | - ? $this->$key |
|
| 98 | - : Arr::get($this->custom, $key, null); |
|
| 99 | - } |
|
| 90 | + /** |
|
| 91 | + * @param mixed $key |
|
| 92 | + * @return mixed |
|
| 93 | + */ |
|
| 94 | + public function offsetGet($key) |
|
| 95 | + { |
|
| 96 | + return property_exists($this, $key) |
|
| 97 | + ? $this->$key |
|
| 98 | + : Arr::get($this->custom, $key, null); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @param mixed $key |
|
| 103 | - * @param mixed $value |
|
| 104 | - * @return void |
|
| 105 | - */ |
|
| 106 | - public function offsetSet($key, $value) |
|
| 107 | - { |
|
| 108 | - if (property_exists($this, $key)) { |
|
| 109 | - $this->$key = $value; |
|
| 110 | - return; |
|
| 111 | - } |
|
| 112 | - if (!is_array($this->custom)) { |
|
| 113 | - $this->custom = array_filter((array) $this->custom); |
|
| 114 | - } |
|
| 115 | - $this->custom[$key] = $value; |
|
| 116 | - } |
|
| 101 | + /** |
|
| 102 | + * @param mixed $key |
|
| 103 | + * @param mixed $value |
|
| 104 | + * @return void |
|
| 105 | + */ |
|
| 106 | + public function offsetSet($key, $value) |
|
| 107 | + { |
|
| 108 | + if (property_exists($this, $key)) { |
|
| 109 | + $this->$key = $value; |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | + if (!is_array($this->custom)) { |
|
| 113 | + $this->custom = array_filter((array) $this->custom); |
|
| 114 | + } |
|
| 115 | + $this->custom[$key] = $value; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * @param mixed $key |
|
| 120 | - * @return void |
|
| 121 | - */ |
|
| 122 | - public function offsetUnset($key) |
|
| 123 | - { |
|
| 124 | - $this->offsetSet($key, null); |
|
| 125 | - } |
|
| 118 | + /** |
|
| 119 | + * @param mixed $key |
|
| 120 | + * @return void |
|
| 121 | + */ |
|
| 122 | + public function offsetUnset($key) |
|
| 123 | + { |
|
| 124 | + $this->offsetSet($key, null); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * @return void |
|
| 129 | - */ |
|
| 130 | - public function render() |
|
| 131 | - { |
|
| 132 | - echo $this->build(); |
|
| 133 | - } |
|
| 127 | + /** |
|
| 128 | + * @return void |
|
| 129 | + */ |
|
| 130 | + public function render() |
|
| 131 | + { |
|
| 132 | + echo $this->build(); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * @return bool |
|
| 137 | - */ |
|
| 138 | - protected function isModified(array $properties) |
|
| 139 | - { |
|
| 140 | - return $this->date != $properties['date'] |
|
| 141 | - || $this->content != $properties['content'] |
|
| 142 | - || $this->title != $properties['title']; |
|
| 143 | - } |
|
| 135 | + /** |
|
| 136 | + * @return bool |
|
| 137 | + */ |
|
| 138 | + protected function isModified(array $properties) |
|
| 139 | + { |
|
| 140 | + return $this->date != $properties['date'] |
|
| 141 | + || $this->content != $properties['content'] |
|
| 142 | + || $this->title != $properties['title']; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * @return void |
|
| 147 | - */ |
|
| 148 | - protected function setProperties(WP_Post $post) |
|
| 149 | - { |
|
| 150 | - $defaults = [ |
|
| 151 | - 'author' => __('Anonymous', 'site-reviews'), |
|
| 152 | - 'date' => '', |
|
| 153 | - 'review_id' => '', |
|
| 154 | - 'review_type' => 'local', |
|
| 155 | - ]; |
|
| 156 | - $meta = array_filter( |
|
| 157 | - array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
| 158 | - 'strlen' |
|
| 159 | - ); |
|
| 160 | - $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
| 161 | - $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
| 162 | - $this->modified = $this->isModified($properties); |
|
| 163 | - array_walk($properties, function ($value, $key) { |
|
| 164 | - if (!property_exists($this, $key) || isset($this->$key)) { |
|
| 165 | - return; |
|
| 166 | - } |
|
| 167 | - $this->$key = maybe_unserialize($value); |
|
| 168 | - }); |
|
| 169 | - } |
|
| 145 | + /** |
|
| 146 | + * @return void |
|
| 147 | + */ |
|
| 148 | + protected function setProperties(WP_Post $post) |
|
| 149 | + { |
|
| 150 | + $defaults = [ |
|
| 151 | + 'author' => __('Anonymous', 'site-reviews'), |
|
| 152 | + 'date' => '', |
|
| 153 | + 'review_id' => '', |
|
| 154 | + 'review_type' => 'local', |
|
| 155 | + ]; |
|
| 156 | + $meta = array_filter( |
|
| 157 | + array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
| 158 | + 'strlen' |
|
| 159 | + ); |
|
| 160 | + $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
| 161 | + $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
| 162 | + $this->modified = $this->isModified($properties); |
|
| 163 | + array_walk($properties, function ($value, $key) { |
|
| 164 | + if (!property_exists($this, $key) || isset($this->$key)) { |
|
| 165 | + return; |
|
| 166 | + } |
|
| 167 | + $this->$key = maybe_unserialize($value); |
|
| 168 | + }); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * @return void |
|
| 173 | - */ |
|
| 174 | - protected function setTermIds(WP_Post $post) |
|
| 175 | - { |
|
| 176 | - $this->term_ids = []; |
|
| 177 | - if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
| 178 | - return; |
|
| 179 | - } |
|
| 180 | - foreach ($terms as $term) { |
|
| 181 | - $this->term_ids[] = $term->term_id; |
|
| 182 | - } |
|
| 183 | - } |
|
| 171 | + /** |
|
| 172 | + * @return void |
|
| 173 | + */ |
|
| 174 | + protected function setTermIds(WP_Post $post) |
|
| 175 | + { |
|
| 176 | + $this->term_ids = []; |
|
| 177 | + if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
| 178 | + return; |
|
| 179 | + } |
|
| 180 | + foreach ($terms as $term) { |
|
| 181 | + $this->term_ids[] = $term->term_id; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | 184 | } |
@@ -33,27 +33,27 @@ discard block |
||
| 33 | 33 | public $url; |
| 34 | 34 | public $user_id; |
| 35 | 35 | |
| 36 | - public function __construct(WP_Post $post) |
|
| 36 | + public function __construct( WP_Post $post ) |
|
| 37 | 37 | { |
| 38 | - if (Application::POST_TYPE != $post->post_type) { |
|
| 38 | + if( Application::POST_TYPE != $post->post_type ) { |
|
| 39 | 39 | return; |
| 40 | 40 | } |
| 41 | 41 | $this->content = $post->post_content; |
| 42 | 42 | $this->date = $post->post_date; |
| 43 | - $this->ID = intval($post->ID); |
|
| 43 | + $this->ID = intval( $post->ID ); |
|
| 44 | 44 | $this->status = $post->post_status; |
| 45 | 45 | $this->title = $post->post_title; |
| 46 | - $this->user_id = intval($post->post_author); |
|
| 47 | - $this->setProperties($post); |
|
| 48 | - $this->setTermIds($post); |
|
| 46 | + $this->user_id = intval( $post->post_author ); |
|
| 47 | + $this->setProperties( $post ); |
|
| 48 | + $this->setTermIds( $post ); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * @return mixed |
| 53 | 53 | */ |
| 54 | - public function __get($key) |
|
| 54 | + public function __get( $key ) |
|
| 55 | 55 | { |
| 56 | - return $this->offsetGet($key); |
|
| 56 | + return $this->offsetGet( $key ); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -61,41 +61,41 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function __toString() |
| 63 | 63 | { |
| 64 | - return (string) $this->build(); |
|
| 64 | + return (string)$this->build(); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * @return ReviewHtml |
| 69 | 69 | */ |
| 70 | - public function build(array $args = []) |
|
| 70 | + public function build( array $args = [] ) |
|
| 71 | 71 | { |
| 72 | - if (empty($this->ID)) { |
|
| 73 | - return new ReviewHtml($this); |
|
| 72 | + if( empty($this->ID) ) { |
|
| 73 | + return new ReviewHtml( $this ); |
|
| 74 | 74 | } |
| 75 | - $partial = glsr(SiteReviewsPartial::class); |
|
| 76 | - $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
| 77 | - $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
| 78 | - return $partial->buildReview($this); |
|
| 75 | + $partial = glsr( SiteReviewsPartial::class ); |
|
| 76 | + $partial->args = glsr( SiteReviewsDefaults::class )->merge( $args ); |
|
| 77 | + $partial->options = Arr::flattenArray( glsr( OptionManager::class )->all() ); |
|
| 78 | + return $partial->buildReview( $this ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * @param mixed $key |
| 83 | 83 | * @return bool |
| 84 | 84 | */ |
| 85 | - public function offsetExists($key) |
|
| 85 | + public function offsetExists( $key ) |
|
| 86 | 86 | { |
| 87 | - return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
| 87 | + return property_exists( $this, $key ) || array_key_exists( $key, (array)$this->custom ); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | 91 | * @param mixed $key |
| 92 | 92 | * @return mixed |
| 93 | 93 | */ |
| 94 | - public function offsetGet($key) |
|
| 94 | + public function offsetGet( $key ) |
|
| 95 | 95 | { |
| 96 | - return property_exists($this, $key) |
|
| 96 | + return property_exists( $this, $key ) |
|
| 97 | 97 | ? $this->$key |
| 98 | - : Arr::get($this->custom, $key, null); |
|
| 98 | + : Arr::get( $this->custom, $key, null ); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | * @param mixed $value |
| 104 | 104 | * @return void |
| 105 | 105 | */ |
| 106 | - public function offsetSet($key, $value) |
|
| 106 | + public function offsetSet( $key, $value ) |
|
| 107 | 107 | { |
| 108 | - if (property_exists($this, $key)) { |
|
| 108 | + if( property_exists( $this, $key ) ) { |
|
| 109 | 109 | $this->$key = $value; |
| 110 | 110 | return; |
| 111 | 111 | } |
| 112 | - if (!is_array($this->custom)) { |
|
| 113 | - $this->custom = array_filter((array) $this->custom); |
|
| 112 | + if( !is_array( $this->custom ) ) { |
|
| 113 | + $this->custom = array_filter( (array)$this->custom ); |
|
| 114 | 114 | } |
| 115 | 115 | $this->custom[$key] = $value; |
| 116 | 116 | } |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | * @param mixed $key |
| 120 | 120 | * @return void |
| 121 | 121 | */ |
| 122 | - public function offsetUnset($key) |
|
| 122 | + public function offsetUnset( $key ) |
|
| 123 | 123 | { |
| 124 | - $this->offsetSet($key, null); |
|
| 124 | + $this->offsetSet( $key, null ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | /** |
| 136 | 136 | * @return bool |
| 137 | 137 | */ |
| 138 | - protected function isModified(array $properties) |
|
| 138 | + protected function isModified( array $properties ) |
|
| 139 | 139 | { |
| 140 | 140 | return $this->date != $properties['date'] |
| 141 | 141 | || $this->content != $properties['content'] |
@@ -145,39 +145,39 @@ discard block |
||
| 145 | 145 | /** |
| 146 | 146 | * @return void |
| 147 | 147 | */ |
| 148 | - protected function setProperties(WP_Post $post) |
|
| 148 | + protected function setProperties( WP_Post $post ) |
|
| 149 | 149 | { |
| 150 | 150 | $defaults = [ |
| 151 | - 'author' => __('Anonymous', 'site-reviews'), |
|
| 151 | + 'author' => __( 'Anonymous', 'site-reviews' ), |
|
| 152 | 152 | 'date' => '', |
| 153 | 153 | 'review_id' => '', |
| 154 | 154 | 'review_type' => 'local', |
| 155 | 155 | ]; |
| 156 | 156 | $meta = array_filter( |
| 157 | - array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
| 157 | + array_map( 'array_shift', array_filter( (array)get_post_meta( $post->ID ) ) ), |
|
| 158 | 158 | 'strlen' |
| 159 | 159 | ); |
| 160 | - $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
| 161 | - $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
| 162 | - $this->modified = $this->isModified($properties); |
|
| 163 | - array_walk($properties, function ($value, $key) { |
|
| 164 | - if (!property_exists($this, $key) || isset($this->$key)) { |
|
| 160 | + $meta = array_merge( $defaults, Arr::unprefixArrayKeys( $meta ) ); |
|
| 161 | + $properties = glsr( CreateReviewDefaults::class )->restrict( array_merge( $defaults, $meta ) ); |
|
| 162 | + $this->modified = $this->isModified( $properties ); |
|
| 163 | + array_walk( $properties, function( $value, $key ) { |
|
| 164 | + if( !property_exists( $this, $key ) || isset($this->$key) ) { |
|
| 165 | 165 | return; |
| 166 | 166 | } |
| 167 | - $this->$key = maybe_unserialize($value); |
|
| 167 | + $this->$key = maybe_unserialize( $value ); |
|
| 168 | 168 | }); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
| 172 | 172 | * @return void |
| 173 | 173 | */ |
| 174 | - protected function setTermIds(WP_Post $post) |
|
| 174 | + protected function setTermIds( WP_Post $post ) |
|
| 175 | 175 | { |
| 176 | 176 | $this->term_ids = []; |
| 177 | - if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
| 177 | + if( !is_array( $terms = get_the_terms( $post, Application::TAXONOMY ) ) ) { |
|
| 178 | 178 | return; |
| 179 | 179 | } |
| 180 | - foreach ($terms as $term) { |
|
| 180 | + foreach( $terms as $term ) { |
|
| 181 | 181 | $this->term_ids[] = $term->term_id; |
| 182 | 182 | } |
| 183 | 183 | } |