@@ -7,12 +7,12 @@ |
||
| 7 | 7 | |
| 8 | 8 | class RegisterTaxonomy |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @return void |
|
| 12 | - */ |
|
| 13 | - public function handle(Command $command) |
|
| 14 | - { |
|
| 15 | - register_taxonomy(Application::TAXONOMY, Application::POST_TYPE, $command->args); |
|
| 16 | - register_taxonomy_for_object_type(Application::TAXONOMY, Application::POST_TYPE); |
|
| 17 | - } |
|
| 10 | + /** |
|
| 11 | + * @return void |
|
| 12 | + */ |
|
| 13 | + public function handle(Command $command) |
|
| 14 | + { |
|
| 15 | + register_taxonomy(Application::TAXONOMY, Application::POST_TYPE, $command->args); |
|
| 16 | + register_taxonomy_for_object_type(Application::TAXONOMY, Application::POST_TYPE); |
|
| 17 | + } |
|
| 18 | 18 | } |
@@ -10,9 +10,9 @@ |
||
| 10 | 10 | /** |
| 11 | 11 | * @return void |
| 12 | 12 | */ |
| 13 | - public function handle(Command $command) |
|
| 13 | + public function handle( Command $command ) |
|
| 14 | 14 | { |
| 15 | - register_taxonomy(Application::TAXONOMY, Application::POST_TYPE, $command->args); |
|
| 16 | - register_taxonomy_for_object_type(Application::TAXONOMY, Application::POST_TYPE); |
|
| 15 | + register_taxonomy( Application::TAXONOMY, Application::POST_TYPE, $command->args ); |
|
| 16 | + register_taxonomy_for_object_type( Application::TAXONOMY, Application::POST_TYPE ); |
|
| 17 | 17 | } |
| 18 | 18 | } |
@@ -6,16 +6,16 @@ |
||
| 6 | 6 | |
| 7 | 7 | class RegisterPostType |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @return void |
|
| 11 | - */ |
|
| 12 | - public function handle(Command $command) |
|
| 13 | - { |
|
| 14 | - if (!in_array($command->postType, get_post_types(['_builtin' => true]))) { |
|
| 15 | - register_post_type($command->postType, $command->args); |
|
| 16 | - glsr()->postTypeColumns = wp_parse_args(glsr()->postTypeColumns, [ |
|
| 17 | - $command->postType => $command->columns, |
|
| 18 | - ]); |
|
| 19 | - } |
|
| 20 | - } |
|
| 9 | + /** |
|
| 10 | + * @return void |
|
| 11 | + */ |
|
| 12 | + public function handle(Command $command) |
|
| 13 | + { |
|
| 14 | + if (!in_array($command->postType, get_post_types(['_builtin' => true]))) { |
|
| 15 | + register_post_type($command->postType, $command->args); |
|
| 16 | + glsr()->postTypeColumns = wp_parse_args(glsr()->postTypeColumns, [ |
|
| 17 | + $command->postType => $command->columns, |
|
| 18 | + ]); |
|
| 19 | + } |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -9,13 +9,13 @@ |
||
| 9 | 9 | /** |
| 10 | 10 | * @return void |
| 11 | 11 | */ |
| 12 | - public function handle(Command $command) |
|
| 12 | + public function handle( Command $command ) |
|
| 13 | 13 | { |
| 14 | - if (!in_array($command->postType, get_post_types(['_builtin' => true]))) { |
|
| 15 | - register_post_type($command->postType, $command->args); |
|
| 16 | - glsr()->postTypeColumns = wp_parse_args(glsr()->postTypeColumns, [ |
|
| 14 | + if( !in_array( $command->postType, get_post_types( ['_builtin' => true] ) ) ) { |
|
| 15 | + register_post_type( $command->postType, $command->args ); |
|
| 16 | + glsr()->postTypeColumns = wp_parse_args( glsr()->postTypeColumns, [ |
|
| 17 | 17 | $command->postType => $command->columns, |
| 18 | - ]); |
|
| 18 | + ] ); |
|
| 19 | 19 | } |
| 20 | 20 | } |
| 21 | 21 | } |
@@ -148,7 +148,8 @@ |
||
| 148 | 148 | { |
| 149 | 149 | if ('parent_id' == $postId) { |
| 150 | 150 | $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
| 151 | - } elseif ('post_id' == $postId) { |
|
| 151 | + } |
|
| 152 | + elseif ('post_id' == $postId) { |
|
| 152 | 153 | $postId = intval(get_the_ID()); |
| 153 | 154 | } |
| 154 | 155 | return $postId; |
@@ -11,227 +11,227 @@ |
||
| 11 | 11 | |
| 12 | 12 | abstract class Shortcode implements ShortcodeContract |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $partialName; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $shortcodeName; |
|
| 23 | - |
|
| 24 | - public function __construct() |
|
| 25 | - { |
|
| 26 | - $this->partialName = $this->getShortcodePartialName(); |
|
| 27 | - $this->shortcodeName = $this->getShortcodeName(); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @param string|array $atts |
|
| 32 | - * @param string $type |
|
| 33 | - * @return string |
|
| 34 | - */ |
|
| 35 | - public function build($atts, array $args = [], $type = 'shortcode') |
|
| 36 | - { |
|
| 37 | - $args = $this->normalizeArgs($args, $type); |
|
| 38 | - $atts = $this->normalizeAtts($atts, $type); |
|
| 39 | - $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
| 40 | - $title = !empty($atts['title']) |
|
| 41 | - ? $args['before_title'].$atts['title'].$args['after_title'] |
|
| 42 | - : ''; |
|
| 43 | - $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']); |
|
| 44 | - return $args['before_widget'].$title.$partial.$debug.$args['after_widget']; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param string|array $atts |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function buildShortcode($atts = []) |
|
| 52 | - { |
|
| 53 | - return $this->build($atts); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @return array |
|
| 58 | - */ |
|
| 59 | - public function getDefaults($atts) |
|
| 60 | - { |
|
| 61 | - return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @return array |
|
| 66 | - */ |
|
| 67 | - public function getHideOptions() |
|
| 68 | - { |
|
| 69 | - $options = $this->hideOptions(); |
|
| 70 | - return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @return string |
|
| 75 | - */ |
|
| 76 | - public function getShortcodeClassName($replace = '', $search = 'Shortcode') |
|
| 77 | - { |
|
| 78 | - return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @return string |
|
| 83 | - */ |
|
| 84 | - public function getShortcodeDefaultsClassName() |
|
| 85 | - { |
|
| 86 | - return Helper::buildClassName( |
|
| 87 | - $this->getShortcodeClassName('Defaults'), |
|
| 88 | - 'Defaults' |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public function getShortcodeName() |
|
| 96 | - { |
|
| 97 | - return Str::snakeCase($this->getShortcodeClassName()); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - public function getShortcodePartialName() |
|
| 104 | - { |
|
| 105 | - return Str::dashCase($this->getShortcodeClassName()); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param array|string $args |
|
| 110 | - * @param string $type |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - public function normalizeArgs($args, $type = 'shortcode') |
|
| 114 | - { |
|
| 115 | - $args = wp_parse_args($args, [ |
|
| 116 | - 'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">', |
|
| 117 | - 'after_widget' => '</div>', |
|
| 118 | - 'before_title' => '<h3 class="glsr-'.$type.'-title">', |
|
| 119 | - 'after_title' => '</h3>', |
|
| 120 | - ]); |
|
| 121 | - return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @param array|string $atts |
|
| 126 | - * @param string $type |
|
| 127 | - * @return array |
|
| 128 | - */ |
|
| 129 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
| 130 | - { |
|
| 131 | - $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
| 132 | - $atts = $this->getDefaults($atts); |
|
| 133 | - array_walk($atts, function (&$value, $key) { |
|
| 134 | - $methodName = Helper::buildMethodName($key, 'normalize'); |
|
| 135 | - if (!method_exists($this, $methodName)) { |
|
| 136 | - return; |
|
| 137 | - } |
|
| 138 | - $value = $this->$methodName($value); |
|
| 139 | - }); |
|
| 140 | - return $atts; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @return array |
|
| 145 | - */ |
|
| 146 | - abstract protected function hideOptions(); |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @param string $postId |
|
| 150 | - * @return int|string |
|
| 151 | - */ |
|
| 152 | - protected function normalizeAssignedTo($postId) |
|
| 153 | - { |
|
| 154 | - if ('parent_id' == $postId) { |
|
| 155 | - $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
| 156 | - } elseif ('post_id' == $postId) { |
|
| 157 | - $postId = intval(get_the_ID()); |
|
| 158 | - } |
|
| 159 | - return $postId; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @param string $postId |
|
| 164 | - * @return int|string |
|
| 165 | - */ |
|
| 166 | - protected function normalizeAssignTo($postId) |
|
| 167 | - { |
|
| 168 | - return $this->normalizeAssignedTo($postId); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param string|array $hide |
|
| 173 | - * @return array |
|
| 174 | - */ |
|
| 175 | - protected function normalizeHide($hide) |
|
| 176 | - { |
|
| 177 | - if (is_string($hide)) { |
|
| 178 | - $hide = explode(',', $hide); |
|
| 179 | - } |
|
| 180 | - $hideKeys = array_keys($this->getHideOptions()); |
|
| 181 | - return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
| 182 | - return in_array($value, $hideKeys); |
|
| 183 | - }); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @param string $id |
|
| 188 | - * @return string |
|
| 189 | - */ |
|
| 190 | - protected function normalizeId($id) |
|
| 191 | - { |
|
| 192 | - return sanitize_title($id); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @param string $labels |
|
| 197 | - * @return array |
|
| 198 | - */ |
|
| 199 | - protected function normalizeLabels($labels) |
|
| 200 | - { |
|
| 201 | - $defaults = [ |
|
| 202 | - __('Excellent', 'site-reviews'), |
|
| 203 | - __('Very good', 'site-reviews'), |
|
| 204 | - __('Average', 'site-reviews'), |
|
| 205 | - __('Poor', 'site-reviews'), |
|
| 206 | - __('Terrible', 'site-reviews'), |
|
| 207 | - ]; |
|
| 208 | - $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class); |
|
| 209 | - $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
| 210 | - $labels = array_map('trim', explode(',', $labels)); |
|
| 211 | - foreach ($defaults as $i => $label) { |
|
| 212 | - if (empty($labels[$i])) { |
|
| 213 | - continue; |
|
| 214 | - } |
|
| 215 | - $defaults[$i] = $labels[$i]; |
|
| 216 | - } |
|
| 217 | - return array_combine(range($maxRating, 1), $defaults); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @param string $schema |
|
| 222 | - * @return bool |
|
| 223 | - */ |
|
| 224 | - protected function normalizeSchema($schema) |
|
| 225 | - { |
|
| 226 | - return wp_validate_boolean($schema); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * @param string $text |
|
| 231 | - * @return string |
|
| 232 | - */ |
|
| 233 | - protected function normalizeText($text) |
|
| 234 | - { |
|
| 235 | - return trim($text); |
|
| 236 | - } |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $partialName; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $shortcodeName; |
|
| 23 | + |
|
| 24 | + public function __construct() |
|
| 25 | + { |
|
| 26 | + $this->partialName = $this->getShortcodePartialName(); |
|
| 27 | + $this->shortcodeName = $this->getShortcodeName(); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @param string|array $atts |
|
| 32 | + * @param string $type |
|
| 33 | + * @return string |
|
| 34 | + */ |
|
| 35 | + public function build($atts, array $args = [], $type = 'shortcode') |
|
| 36 | + { |
|
| 37 | + $args = $this->normalizeArgs($args, $type); |
|
| 38 | + $atts = $this->normalizeAtts($atts, $type); |
|
| 39 | + $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
| 40 | + $title = !empty($atts['title']) |
|
| 41 | + ? $args['before_title'].$atts['title'].$args['after_title'] |
|
| 42 | + : ''; |
|
| 43 | + $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']); |
|
| 44 | + return $args['before_widget'].$title.$partial.$debug.$args['after_widget']; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param string|array $atts |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function buildShortcode($atts = []) |
|
| 52 | + { |
|
| 53 | + return $this->build($atts); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @return array |
|
| 58 | + */ |
|
| 59 | + public function getDefaults($atts) |
|
| 60 | + { |
|
| 61 | + return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @return array |
|
| 66 | + */ |
|
| 67 | + public function getHideOptions() |
|
| 68 | + { |
|
| 69 | + $options = $this->hideOptions(); |
|
| 70 | + return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @return string |
|
| 75 | + */ |
|
| 76 | + public function getShortcodeClassName($replace = '', $search = 'Shortcode') |
|
| 77 | + { |
|
| 78 | + return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @return string |
|
| 83 | + */ |
|
| 84 | + public function getShortcodeDefaultsClassName() |
|
| 85 | + { |
|
| 86 | + return Helper::buildClassName( |
|
| 87 | + $this->getShortcodeClassName('Defaults'), |
|
| 88 | + 'Defaults' |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public function getShortcodeName() |
|
| 96 | + { |
|
| 97 | + return Str::snakeCase($this->getShortcodeClassName()); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + public function getShortcodePartialName() |
|
| 104 | + { |
|
| 105 | + return Str::dashCase($this->getShortcodeClassName()); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param array|string $args |
|
| 110 | + * @param string $type |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + public function normalizeArgs($args, $type = 'shortcode') |
|
| 114 | + { |
|
| 115 | + $args = wp_parse_args($args, [ |
|
| 116 | + 'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">', |
|
| 117 | + 'after_widget' => '</div>', |
|
| 118 | + 'before_title' => '<h3 class="glsr-'.$type.'-title">', |
|
| 119 | + 'after_title' => '</h3>', |
|
| 120 | + ]); |
|
| 121 | + return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @param array|string $atts |
|
| 126 | + * @param string $type |
|
| 127 | + * @return array |
|
| 128 | + */ |
|
| 129 | + public function normalizeAtts($atts, $type = 'shortcode') |
|
| 130 | + { |
|
| 131 | + $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
| 132 | + $atts = $this->getDefaults($atts); |
|
| 133 | + array_walk($atts, function (&$value, $key) { |
|
| 134 | + $methodName = Helper::buildMethodName($key, 'normalize'); |
|
| 135 | + if (!method_exists($this, $methodName)) { |
|
| 136 | + return; |
|
| 137 | + } |
|
| 138 | + $value = $this->$methodName($value); |
|
| 139 | + }); |
|
| 140 | + return $atts; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @return array |
|
| 145 | + */ |
|
| 146 | + abstract protected function hideOptions(); |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @param string $postId |
|
| 150 | + * @return int|string |
|
| 151 | + */ |
|
| 152 | + protected function normalizeAssignedTo($postId) |
|
| 153 | + { |
|
| 154 | + if ('parent_id' == $postId) { |
|
| 155 | + $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
| 156 | + } elseif ('post_id' == $postId) { |
|
| 157 | + $postId = intval(get_the_ID()); |
|
| 158 | + } |
|
| 159 | + return $postId; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @param string $postId |
|
| 164 | + * @return int|string |
|
| 165 | + */ |
|
| 166 | + protected function normalizeAssignTo($postId) |
|
| 167 | + { |
|
| 168 | + return $this->normalizeAssignedTo($postId); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param string|array $hide |
|
| 173 | + * @return array |
|
| 174 | + */ |
|
| 175 | + protected function normalizeHide($hide) |
|
| 176 | + { |
|
| 177 | + if (is_string($hide)) { |
|
| 178 | + $hide = explode(',', $hide); |
|
| 179 | + } |
|
| 180 | + $hideKeys = array_keys($this->getHideOptions()); |
|
| 181 | + return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
| 182 | + return in_array($value, $hideKeys); |
|
| 183 | + }); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @param string $id |
|
| 188 | + * @return string |
|
| 189 | + */ |
|
| 190 | + protected function normalizeId($id) |
|
| 191 | + { |
|
| 192 | + return sanitize_title($id); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @param string $labels |
|
| 197 | + * @return array |
|
| 198 | + */ |
|
| 199 | + protected function normalizeLabels($labels) |
|
| 200 | + { |
|
| 201 | + $defaults = [ |
|
| 202 | + __('Excellent', 'site-reviews'), |
|
| 203 | + __('Very good', 'site-reviews'), |
|
| 204 | + __('Average', 'site-reviews'), |
|
| 205 | + __('Poor', 'site-reviews'), |
|
| 206 | + __('Terrible', 'site-reviews'), |
|
| 207 | + ]; |
|
| 208 | + $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class); |
|
| 209 | + $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
| 210 | + $labels = array_map('trim', explode(',', $labels)); |
|
| 211 | + foreach ($defaults as $i => $label) { |
|
| 212 | + if (empty($labels[$i])) { |
|
| 213 | + continue; |
|
| 214 | + } |
|
| 215 | + $defaults[$i] = $labels[$i]; |
|
| 216 | + } |
|
| 217 | + return array_combine(range($maxRating, 1), $defaults); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @param string $schema |
|
| 222 | + * @return bool |
|
| 223 | + */ |
|
| 224 | + protected function normalizeSchema($schema) |
|
| 225 | + { |
|
| 226 | + return wp_validate_boolean($schema); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * @param string $text |
|
| 231 | + * @return string |
|
| 232 | + */ |
|
| 233 | + protected function normalizeText($text) |
|
| 234 | + { |
|
| 235 | + return trim($text); |
|
| 236 | + } |
|
| 237 | 237 | } |
@@ -32,15 +32,15 @@ discard block |
||
| 32 | 32 | * @param string $type |
| 33 | 33 | * @return string |
| 34 | 34 | */ |
| 35 | - public function build($atts, array $args = [], $type = 'shortcode') |
|
| 35 | + public function build( $atts, array $args = [], $type = 'shortcode' ) |
|
| 36 | 36 | { |
| 37 | - $args = $this->normalizeArgs($args, $type); |
|
| 38 | - $atts = $this->normalizeAtts($atts, $type); |
|
| 39 | - $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
| 37 | + $args = $this->normalizeArgs( $args, $type ); |
|
| 38 | + $atts = $this->normalizeAtts( $atts, $type ); |
|
| 39 | + $partial = glsr( Partial::class )->build( $this->partialName, $atts ); |
|
| 40 | 40 | $title = !empty($atts['title']) |
| 41 | 41 | ? $args['before_title'].$atts['title'].$args['after_title'] |
| 42 | 42 | : ''; |
| 43 | - $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']); |
|
| 43 | + $debug = sprintf( '<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json'] ); |
|
| 44 | 44 | return $args['before_widget'].$title.$partial.$debug.$args['after_widget']; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -48,17 +48,17 @@ discard block |
||
| 48 | 48 | * @param string|array $atts |
| 49 | 49 | * @return string |
| 50 | 50 | */ |
| 51 | - public function buildShortcode($atts = []) |
|
| 51 | + public function buildShortcode( $atts = [] ) |
|
| 52 | 52 | { |
| 53 | - return $this->build($atts); |
|
| 53 | + return $this->build( $atts ); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * @return array |
| 58 | 58 | */ |
| 59 | - public function getDefaults($atts) |
|
| 59 | + public function getDefaults( $atts ) |
|
| 60 | 60 | { |
| 61 | - return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
| 61 | + return glsr( $this->getShortcodeDefaultsClassName() )->restrict( wp_parse_args( $atts ) ); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | public function getHideOptions() |
| 68 | 68 | { |
| 69 | 69 | $options = $this->hideOptions(); |
| 70 | - return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
| 70 | + return apply_filters( 'site-reviews/shortcode/hide-options', $options, $this->shortcodeName ); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * @return string |
| 75 | 75 | */ |
| 76 | - public function getShortcodeClassName($replace = '', $search = 'Shortcode') |
|
| 76 | + public function getShortcodeClassName( $replace = '', $search = 'Shortcode' ) |
|
| 77 | 77 | { |
| 78 | - return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
| 78 | + return str_replace( $search, $replace, (new ReflectionClass( $this ))->getShortName() ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | public function getShortcodeDefaultsClassName() |
| 85 | 85 | { |
| 86 | 86 | return Helper::buildClassName( |
| 87 | - $this->getShortcodeClassName('Defaults'), |
|
| 87 | + $this->getShortcodeClassName( 'Defaults' ), |
|
| 88 | 88 | 'Defaults' |
| 89 | 89 | ); |
| 90 | 90 | } |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | public function getShortcodeName() |
| 96 | 96 | { |
| 97 | - return Str::snakeCase($this->getShortcodeClassName()); |
|
| 97 | + return Str::snakeCase( $this->getShortcodeClassName() ); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function getShortcodePartialName() |
| 104 | 104 | { |
| 105 | - return Str::dashCase($this->getShortcodeClassName()); |
|
| 105 | + return Str::dashCase( $this->getShortcodeClassName() ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -110,15 +110,15 @@ discard block |
||
| 110 | 110 | * @param string $type |
| 111 | 111 | * @return array |
| 112 | 112 | */ |
| 113 | - public function normalizeArgs($args, $type = 'shortcode') |
|
| 113 | + public function normalizeArgs( $args, $type = 'shortcode' ) |
|
| 114 | 114 | { |
| 115 | - $args = wp_parse_args($args, [ |
|
| 115 | + $args = wp_parse_args( $args, [ |
|
| 116 | 116 | 'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">', |
| 117 | 117 | 'after_widget' => '</div>', |
| 118 | 118 | 'before_title' => '<h3 class="glsr-'.$type.'-title">', |
| 119 | 119 | 'after_title' => '</h3>', |
| 120 | - ]); |
|
| 121 | - return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
| 120 | + ] ); |
|
| 121 | + return apply_filters( 'site-reviews/shortcode/args', $args, $type, $this->partialName ); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -126,16 +126,16 @@ discard block |
||
| 126 | 126 | * @param string $type |
| 127 | 127 | * @return array |
| 128 | 128 | */ |
| 129 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
| 129 | + public function normalizeAtts( $atts, $type = 'shortcode' ) |
|
| 130 | 130 | { |
| 131 | - $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
| 132 | - $atts = $this->getDefaults($atts); |
|
| 133 | - array_walk($atts, function (&$value, $key) { |
|
| 134 | - $methodName = Helper::buildMethodName($key, 'normalize'); |
|
| 135 | - if (!method_exists($this, $methodName)) { |
|
| 131 | + $atts = apply_filters( 'site-reviews/shortcode/atts', $atts, $type, $this->partialName ); |
|
| 132 | + $atts = $this->getDefaults( $atts ); |
|
| 133 | + array_walk( $atts, function( &$value, $key ) { |
|
| 134 | + $methodName = Helper::buildMethodName( $key, 'normalize' ); |
|
| 135 | + if( !method_exists( $this, $methodName ) ) { |
|
| 136 | 136 | return; |
| 137 | 137 | } |
| 138 | - $value = $this->$methodName($value); |
|
| 138 | + $value = $this->$methodName( $value ); |
|
| 139 | 139 | }); |
| 140 | 140 | return $atts; |
| 141 | 141 | } |
@@ -149,12 +149,12 @@ discard block |
||
| 149 | 149 | * @param string $postId |
| 150 | 150 | * @return int|string |
| 151 | 151 | */ |
| 152 | - protected function normalizeAssignedTo($postId) |
|
| 152 | + protected function normalizeAssignedTo( $postId ) |
|
| 153 | 153 | { |
| 154 | - if ('parent_id' == $postId) { |
|
| 155 | - $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
| 156 | - } elseif ('post_id' == $postId) { |
|
| 157 | - $postId = intval(get_the_ID()); |
|
| 154 | + if( 'parent_id' == $postId ) { |
|
| 155 | + $postId = intval( wp_get_post_parent_id( intval( get_the_ID() ) ) ); |
|
| 156 | + } elseif( 'post_id' == $postId ) { |
|
| 157 | + $postId = intval( get_the_ID() ); |
|
| 158 | 158 | } |
| 159 | 159 | return $postId; |
| 160 | 160 | } |
@@ -163,23 +163,23 @@ discard block |
||
| 163 | 163 | * @param string $postId |
| 164 | 164 | * @return int|string |
| 165 | 165 | */ |
| 166 | - protected function normalizeAssignTo($postId) |
|
| 166 | + protected function normalizeAssignTo( $postId ) |
|
| 167 | 167 | { |
| 168 | - return $this->normalizeAssignedTo($postId); |
|
| 168 | + return $this->normalizeAssignedTo( $postId ); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
| 172 | 172 | * @param string|array $hide |
| 173 | 173 | * @return array |
| 174 | 174 | */ |
| 175 | - protected function normalizeHide($hide) |
|
| 175 | + protected function normalizeHide( $hide ) |
|
| 176 | 176 | { |
| 177 | - if (is_string($hide)) { |
|
| 178 | - $hide = explode(',', $hide); |
|
| 177 | + if( is_string( $hide ) ) { |
|
| 178 | + $hide = explode( ',', $hide ); |
|
| 179 | 179 | } |
| 180 | - $hideKeys = array_keys($this->getHideOptions()); |
|
| 181 | - return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
| 182 | - return in_array($value, $hideKeys); |
|
| 180 | + $hideKeys = array_keys( $this->getHideOptions() ); |
|
| 181 | + return array_filter( array_map( 'trim', $hide ), function( $value ) use ($hideKeys) { |
|
| 182 | + return in_array( $value, $hideKeys ); |
|
| 183 | 183 | }); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -187,51 +187,51 @@ discard block |
||
| 187 | 187 | * @param string $id |
| 188 | 188 | * @return string |
| 189 | 189 | */ |
| 190 | - protected function normalizeId($id) |
|
| 190 | + protected function normalizeId( $id ) |
|
| 191 | 191 | { |
| 192 | - return sanitize_title($id); |
|
| 192 | + return sanitize_title( $id ); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | 196 | * @param string $labels |
| 197 | 197 | * @return array |
| 198 | 198 | */ |
| 199 | - protected function normalizeLabels($labels) |
|
| 199 | + protected function normalizeLabels( $labels ) |
|
| 200 | 200 | { |
| 201 | 201 | $defaults = [ |
| 202 | - __('Excellent', 'site-reviews'), |
|
| 203 | - __('Very good', 'site-reviews'), |
|
| 204 | - __('Average', 'site-reviews'), |
|
| 205 | - __('Poor', 'site-reviews'), |
|
| 206 | - __('Terrible', 'site-reviews'), |
|
| 202 | + __( 'Excellent', 'site-reviews' ), |
|
| 203 | + __( 'Very good', 'site-reviews' ), |
|
| 204 | + __( 'Average', 'site-reviews' ), |
|
| 205 | + __( 'Poor', 'site-reviews' ), |
|
| 206 | + __( 'Terrible', 'site-reviews' ), |
|
| 207 | 207 | ]; |
| 208 | - $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class); |
|
| 209 | - $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
| 210 | - $labels = array_map('trim', explode(',', $labels)); |
|
| 211 | - foreach ($defaults as $i => $label) { |
|
| 212 | - if (empty($labels[$i])) { |
|
| 208 | + $maxRating = (int)glsr()->constant( 'MAX_RATING', Rating::class ); |
|
| 209 | + $defaults = array_pad( array_slice( $defaults, 0, $maxRating ), $maxRating, '' ); |
|
| 210 | + $labels = array_map( 'trim', explode( ',', $labels ) ); |
|
| 211 | + foreach( $defaults as $i => $label ) { |
|
| 212 | + if( empty($labels[$i]) ) { |
|
| 213 | 213 | continue; |
| 214 | 214 | } |
| 215 | 215 | $defaults[$i] = $labels[$i]; |
| 216 | 216 | } |
| 217 | - return array_combine(range($maxRating, 1), $defaults); |
|
| 217 | + return array_combine( range( $maxRating, 1 ), $defaults ); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
| 221 | 221 | * @param string $schema |
| 222 | 222 | * @return bool |
| 223 | 223 | */ |
| 224 | - protected function normalizeSchema($schema) |
|
| 224 | + protected function normalizeSchema( $schema ) |
|
| 225 | 225 | { |
| 226 | - return wp_validate_boolean($schema); |
|
| 226 | + return wp_validate_boolean( $schema ); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | 230 | * @param string $text |
| 231 | 231 | * @return string |
| 232 | 232 | */ |
| 233 | - protected function normalizeText($text) |
|
| 233 | + protected function normalizeText( $text ) |
|
| 234 | 234 | { |
| 235 | - return trim($text); |
|
| 235 | + return trim( $text ); |
|
| 236 | 236 | } |
| 237 | 237 | } |
@@ -4,50 +4,50 @@ |
||
| 4 | 4 | |
| 5 | 5 | class SiteReviewsFormPopup extends TinymcePopupGenerator |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return array |
|
| 9 | - */ |
|
| 10 | - public function fields() |
|
| 11 | - { |
|
| 12 | - return [[ |
|
| 13 | - 'type' => 'container', |
|
| 14 | - 'html' => '<p class="strong">'.esc_html__('All settings are optional.', 'site-reviews').'</p>', |
|
| 15 | - ], [ |
|
| 16 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
| 17 | - 'name' => 'title', |
|
| 18 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
| 19 | - 'type' => 'textbox', |
|
| 20 | - ], [ |
|
| 21 | - 'label' => esc_html__('Description', 'site-reviews'), |
|
| 22 | - 'minHeight' => 60, |
|
| 23 | - 'minWidth' => 240, |
|
| 24 | - 'multiline' => true, |
|
| 25 | - 'name' => 'description', |
|
| 26 | - 'tooltip' => __('Enter a custom shortcode description.', 'site-reviews'), |
|
| 27 | - 'type' => 'textbox', |
|
| 28 | - ], |
|
| 29 | - $this->getCategories(__('Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews')), |
|
| 30 | - [ |
|
| 31 | - 'label' => esc_html__('Assign To', 'site-reviews'), |
|
| 32 | - 'name' => 'assign_to', |
|
| 33 | - 'tooltip' => __('Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews'), |
|
| 34 | - 'type' => 'textbox', |
|
| 35 | - ], [ |
|
| 36 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
| 37 | - 'name' => 'class', |
|
| 38 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
| 39 | - 'type' => 'textbox', |
|
| 40 | - ], [ |
|
| 41 | - 'columns' => 2, |
|
| 42 | - 'items' => $this->getHideOptions(), |
|
| 43 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
| 44 | - 'layout' => 'grid', |
|
| 45 | - 'spacing' => 5, |
|
| 46 | - 'type' => 'container', |
|
| 47 | - ], [ |
|
| 48 | - 'hidden' => true, |
|
| 49 | - 'name' => 'id', |
|
| 50 | - 'type' => 'textbox', |
|
| 51 | - ], ]; |
|
| 52 | - } |
|
| 7 | + /** |
|
| 8 | + * @return array |
|
| 9 | + */ |
|
| 10 | + public function fields() |
|
| 11 | + { |
|
| 12 | + return [[ |
|
| 13 | + 'type' => 'container', |
|
| 14 | + 'html' => '<p class="strong">'.esc_html__('All settings are optional.', 'site-reviews').'</p>', |
|
| 15 | + ], [ |
|
| 16 | + 'label' => esc_html__('Title', 'site-reviews'), |
|
| 17 | + 'name' => 'title', |
|
| 18 | + 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
| 19 | + 'type' => 'textbox', |
|
| 20 | + ], [ |
|
| 21 | + 'label' => esc_html__('Description', 'site-reviews'), |
|
| 22 | + 'minHeight' => 60, |
|
| 23 | + 'minWidth' => 240, |
|
| 24 | + 'multiline' => true, |
|
| 25 | + 'name' => 'description', |
|
| 26 | + 'tooltip' => __('Enter a custom shortcode description.', 'site-reviews'), |
|
| 27 | + 'type' => 'textbox', |
|
| 28 | + ], |
|
| 29 | + $this->getCategories(__('Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews')), |
|
| 30 | + [ |
|
| 31 | + 'label' => esc_html__('Assign To', 'site-reviews'), |
|
| 32 | + 'name' => 'assign_to', |
|
| 33 | + 'tooltip' => __('Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews'), |
|
| 34 | + 'type' => 'textbox', |
|
| 35 | + ], [ |
|
| 36 | + 'label' => esc_html__('Classes', 'site-reviews'), |
|
| 37 | + 'name' => 'class', |
|
| 38 | + 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
| 39 | + 'type' => 'textbox', |
|
| 40 | + ], [ |
|
| 41 | + 'columns' => 2, |
|
| 42 | + 'items' => $this->getHideOptions(), |
|
| 43 | + 'label' => esc_html__('Hide', 'site-reviews'), |
|
| 44 | + 'layout' => 'grid', |
|
| 45 | + 'spacing' => 5, |
|
| 46 | + 'type' => 'container', |
|
| 47 | + ], [ |
|
| 48 | + 'hidden' => true, |
|
| 49 | + 'name' => 'id', |
|
| 50 | + 'type' => 'textbox', |
|
| 51 | + ], ]; |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -11,36 +11,36 @@ |
||
| 11 | 11 | { |
| 12 | 12 | return [[ |
| 13 | 13 | 'type' => 'container', |
| 14 | - 'html' => '<p class="strong">'.esc_html__('All settings are optional.', 'site-reviews').'</p>', |
|
| 14 | + 'html' => '<p class="strong">'.esc_html__( 'All settings are optional.', 'site-reviews' ).'</p>', |
|
| 15 | 15 | ], [ |
| 16 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
| 16 | + 'label' => esc_html__( 'Title', 'site-reviews' ), |
|
| 17 | 17 | 'name' => 'title', |
| 18 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
| 18 | + 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
|
| 19 | 19 | 'type' => 'textbox', |
| 20 | 20 | ], [ |
| 21 | - 'label' => esc_html__('Description', 'site-reviews'), |
|
| 21 | + 'label' => esc_html__( 'Description', 'site-reviews' ), |
|
| 22 | 22 | 'minHeight' => 60, |
| 23 | 23 | 'minWidth' => 240, |
| 24 | 24 | 'multiline' => true, |
| 25 | 25 | 'name' => 'description', |
| 26 | - 'tooltip' => __('Enter a custom shortcode description.', 'site-reviews'), |
|
| 26 | + 'tooltip' => __( 'Enter a custom shortcode description.', 'site-reviews' ), |
|
| 27 | 27 | 'type' => 'textbox', |
| 28 | 28 | ], |
| 29 | - $this->getCategories(__('Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews')), |
|
| 29 | + $this->getCategories( __( 'Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews' ) ), |
|
| 30 | 30 | [ |
| 31 | - 'label' => esc_html__('Assign To', 'site-reviews'), |
|
| 31 | + 'label' => esc_html__( 'Assign To', 'site-reviews' ), |
|
| 32 | 32 | 'name' => 'assign_to', |
| 33 | - 'tooltip' => __('Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews'), |
|
| 33 | + 'tooltip' => __( 'Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews' ), |
|
| 34 | 34 | 'type' => 'textbox', |
| 35 | 35 | ], [ |
| 36 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
| 36 | + 'label' => esc_html__( 'Classes', 'site-reviews' ), |
|
| 37 | 37 | 'name' => 'class', |
| 38 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
| 38 | + 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
|
| 39 | 39 | 'type' => 'textbox', |
| 40 | 40 | ], [ |
| 41 | 41 | 'columns' => 2, |
| 42 | 42 | 'items' => $this->getHideOptions(), |
| 43 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
| 43 | + 'label' => esc_html__( 'Hide', 'site-reviews' ), |
|
| 44 | 44 | 'layout' => 'grid', |
| 45 | 45 | 'spacing' => 5, |
| 46 | 46 | 'type' => 'container', |
@@ -4,49 +4,49 @@ |
||
| 4 | 4 | |
| 5 | 5 | class SiteReviewsSummaryPopup extends SiteReviewsPopup |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @return array |
|
| 9 | - */ |
|
| 10 | - public function fields() |
|
| 11 | - { |
|
| 12 | - return [[ |
|
| 13 | - 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
| 14 | - 'minWidth' => 320, |
|
| 15 | - 'type' => 'container', |
|
| 16 | - ], [ |
|
| 17 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
| 18 | - 'name' => 'title', |
|
| 19 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
| 20 | - 'type' => 'textbox', |
|
| 21 | - ], |
|
| 22 | - $this->getTypes(__('Which type of review would you like to use?', 'site-reviews')), |
|
| 23 | - $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
| 24 | - [ |
|
| 25 | - 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
| 26 | - 'name' => 'assigned_to', |
|
| 27 | - 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
| 28 | - 'type' => 'textbox', |
|
| 29 | - ], [ |
|
| 30 | - 'label' => esc_html__('Schema', 'site-reviews'), |
|
| 31 | - 'name' => 'schema', |
|
| 32 | - 'options' => [ |
|
| 33 | - 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
| 34 | - 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
| 35 | - ], |
|
| 36 | - 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
| 37 | - 'type' => 'listbox', |
|
| 38 | - ], [ |
|
| 39 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
| 40 | - 'name' => 'class', |
|
| 41 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
| 42 | - 'type' => 'textbox', |
|
| 43 | - ], [ |
|
| 44 | - 'columns' => 2, |
|
| 45 | - 'items' => $this->getHideOptions(), |
|
| 46 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
| 47 | - 'layout' => 'grid', |
|
| 48 | - 'spacing' => 5, |
|
| 49 | - 'type' => 'container', |
|
| 50 | - ], ]; |
|
| 51 | - } |
|
| 7 | + /** |
|
| 8 | + * @return array |
|
| 9 | + */ |
|
| 10 | + public function fields() |
|
| 11 | + { |
|
| 12 | + return [[ |
|
| 13 | + 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
| 14 | + 'minWidth' => 320, |
|
| 15 | + 'type' => 'container', |
|
| 16 | + ], [ |
|
| 17 | + 'label' => esc_html__('Title', 'site-reviews'), |
|
| 18 | + 'name' => 'title', |
|
| 19 | + 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
| 20 | + 'type' => 'textbox', |
|
| 21 | + ], |
|
| 22 | + $this->getTypes(__('Which type of review would you like to use?', 'site-reviews')), |
|
| 23 | + $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
| 24 | + [ |
|
| 25 | + 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
| 26 | + 'name' => 'assigned_to', |
|
| 27 | + 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
| 28 | + 'type' => 'textbox', |
|
| 29 | + ], [ |
|
| 30 | + 'label' => esc_html__('Schema', 'site-reviews'), |
|
| 31 | + 'name' => 'schema', |
|
| 32 | + 'options' => [ |
|
| 33 | + 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
| 34 | + 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
| 35 | + ], |
|
| 36 | + 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
| 37 | + 'type' => 'listbox', |
|
| 38 | + ], [ |
|
| 39 | + 'label' => esc_html__('Classes', 'site-reviews'), |
|
| 40 | + 'name' => 'class', |
|
| 41 | + 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
| 42 | + 'type' => 'textbox', |
|
| 43 | + ], [ |
|
| 44 | + 'columns' => 2, |
|
| 45 | + 'items' => $this->getHideOptions(), |
|
| 46 | + 'label' => esc_html__('Hide', 'site-reviews'), |
|
| 47 | + 'layout' => 'grid', |
|
| 48 | + 'spacing' => 5, |
|
| 49 | + 'type' => 'container', |
|
| 50 | + ], ]; |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -10,40 +10,40 @@ |
||
| 10 | 10 | public function fields() |
| 11 | 11 | { |
| 12 | 12 | return [[ |
| 13 | - 'html' => sprintf('<p class="strong">%s</p>', esc_html__('All settings are optional.', 'site-reviews')), |
|
| 13 | + 'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' ) ), |
|
| 14 | 14 | 'minWidth' => 320, |
| 15 | 15 | 'type' => 'container', |
| 16 | 16 | ], [ |
| 17 | - 'label' => esc_html__('Title', 'site-reviews'), |
|
| 17 | + 'label' => esc_html__( 'Title', 'site-reviews' ), |
|
| 18 | 18 | 'name' => 'title', |
| 19 | - 'tooltip' => __('Enter a custom shortcode heading.', 'site-reviews'), |
|
| 19 | + 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
|
| 20 | 20 | 'type' => 'textbox', |
| 21 | 21 | ], |
| 22 | - $this->getTypes(__('Which type of review would you like to use?', 'site-reviews')), |
|
| 23 | - $this->getCategories(__('Limit reviews to this category.', 'site-reviews')), |
|
| 22 | + $this->getTypes( __( 'Which type of review would you like to use?', 'site-reviews' ) ), |
|
| 23 | + $this->getCategories( __( 'Limit reviews to this category.', 'site-reviews' ) ), |
|
| 24 | 24 | [ |
| 25 | - 'label' => esc_html__('Assigned To', 'site-reviews'), |
|
| 25 | + 'label' => esc_html__( 'Assigned To', 'site-reviews' ), |
|
| 26 | 26 | 'name' => 'assigned_to', |
| 27 | - 'tooltip' => __('Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews'), |
|
| 27 | + 'tooltip' => __( 'Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page, or "parent_id" to use the ID of the parent page.', 'site-reviews' ), |
|
| 28 | 28 | 'type' => 'textbox', |
| 29 | 29 | ], [ |
| 30 | - 'label' => esc_html__('Schema', 'site-reviews'), |
|
| 30 | + 'label' => esc_html__( 'Schema', 'site-reviews' ), |
|
| 31 | 31 | 'name' => 'schema', |
| 32 | 32 | 'options' => [ |
| 33 | - 'true' => esc_html__('Enable rich snippets', 'site-reviews'), |
|
| 34 | - 'false' => esc_html__('Disable rich snippets', 'site-reviews'), |
|
| 33 | + 'true' => esc_html__( 'Enable rich snippets', 'site-reviews' ), |
|
| 34 | + 'false' => esc_html__( 'Disable rich snippets', 'site-reviews' ), |
|
| 35 | 35 | ], |
| 36 | - 'tooltip' => __('Rich snippets are disabled by default.', 'site-reviews'), |
|
| 36 | + 'tooltip' => __( 'Rich snippets are disabled by default.', 'site-reviews' ), |
|
| 37 | 37 | 'type' => 'listbox', |
| 38 | 38 | ], [ |
| 39 | - 'label' => esc_html__('Classes', 'site-reviews'), |
|
| 39 | + 'label' => esc_html__( 'Classes', 'site-reviews' ), |
|
| 40 | 40 | 'name' => 'class', |
| 41 | - 'tooltip' => __('Add custom CSS classes to the shortcode.', 'site-reviews'), |
|
| 41 | + 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
|
| 42 | 42 | 'type' => 'textbox', |
| 43 | 43 | ], [ |
| 44 | 44 | 'columns' => 2, |
| 45 | 45 | 'items' => $this->getHideOptions(), |
| 46 | - 'label' => esc_html__('Hide', 'site-reviews'), |
|
| 46 | + 'label' => esc_html__( 'Hide', 'site-reviews' ), |
|
| 47 | 47 | 'layout' => 'grid', |
| 48 | 48 | 'spacing' => 5, |
| 49 | 49 | 'type' => 'container', |
@@ -4,17 +4,17 @@ |
||
| 4 | 4 | |
| 5 | 5 | class SiteReviewsShortcode extends Shortcode |
| 6 | 6 | { |
| 7 | - protected function hideOptions() |
|
| 8 | - { |
|
| 9 | - return [ |
|
| 10 | - 'title' => __('Hide the title', 'site-reviews'), |
|
| 11 | - 'rating' => __('Hide the rating', 'site-reviews'), |
|
| 12 | - 'date' => __('Hide the date', 'site-reviews'), |
|
| 13 | - 'assigned_to' => __('Hide the assigned to link (if shown)', 'site-reviews'), |
|
| 14 | - 'content' => __('Hide the content', 'site-reviews'), |
|
| 15 | - 'avatar' => __('Hide the avatar (if shown)', 'site-reviews'), |
|
| 16 | - 'author' => __('Hide the author', 'site-reviews'), |
|
| 17 | - 'response' => __('Hide the response', 'site-reviews'), |
|
| 18 | - ]; |
|
| 19 | - } |
|
| 7 | + protected function hideOptions() |
|
| 8 | + { |
|
| 9 | + return [ |
|
| 10 | + 'title' => __('Hide the title', 'site-reviews'), |
|
| 11 | + 'rating' => __('Hide the rating', 'site-reviews'), |
|
| 12 | + 'date' => __('Hide the date', 'site-reviews'), |
|
| 13 | + 'assigned_to' => __('Hide the assigned to link (if shown)', 'site-reviews'), |
|
| 14 | + 'content' => __('Hide the content', 'site-reviews'), |
|
| 15 | + 'avatar' => __('Hide the avatar (if shown)', 'site-reviews'), |
|
| 16 | + 'author' => __('Hide the author', 'site-reviews'), |
|
| 17 | + 'response' => __('Hide the response', 'site-reviews'), |
|
| 18 | + ]; |
|
| 19 | + } |
|
| 20 | 20 | } |
@@ -7,14 +7,14 @@ |
||
| 7 | 7 | protected function hideOptions() |
| 8 | 8 | { |
| 9 | 9 | return [ |
| 10 | - 'title' => __('Hide the title', 'site-reviews'), |
|
| 11 | - 'rating' => __('Hide the rating', 'site-reviews'), |
|
| 12 | - 'date' => __('Hide the date', 'site-reviews'), |
|
| 13 | - 'assigned_to' => __('Hide the assigned to link (if shown)', 'site-reviews'), |
|
| 14 | - 'content' => __('Hide the content', 'site-reviews'), |
|
| 15 | - 'avatar' => __('Hide the avatar (if shown)', 'site-reviews'), |
|
| 16 | - 'author' => __('Hide the author', 'site-reviews'), |
|
| 17 | - 'response' => __('Hide the response', 'site-reviews'), |
|
| 10 | + 'title' => __( 'Hide the title', 'site-reviews' ), |
|
| 11 | + 'rating' => __( 'Hide the rating', 'site-reviews' ), |
|
| 12 | + 'date' => __( 'Hide the date', 'site-reviews' ), |
|
| 13 | + 'assigned_to' => __( 'Hide the assigned to link (if shown)', 'site-reviews' ), |
|
| 14 | + 'content' => __( 'Hide the content', 'site-reviews' ), |
|
| 15 | + 'avatar' => __( 'Hide the avatar (if shown)', 'site-reviews' ), |
|
| 16 | + 'author' => __( 'Hide the author', 'site-reviews' ), |
|
| 17 | + 'response' => __( 'Hide the response', 'site-reviews' ), |
|
| 18 | 18 | ]; |
| 19 | 19 | } |
| 20 | 20 | } |
@@ -4,14 +4,14 @@ |
||
| 4 | 4 | |
| 5 | 5 | class SiteReviewsSummaryShortcode extends Shortcode |
| 6 | 6 | { |
| 7 | - protected function hideOptions() |
|
| 8 | - { |
|
| 9 | - return [ |
|
| 10 | - 'rating' => __('Hide the rating', 'site-reviews'), |
|
| 11 | - 'stars' => __('Hide the stars', 'site-reviews'), |
|
| 12 | - 'summary' => __('Hide the summary', 'site-reviews'), |
|
| 13 | - 'bars' => __('Hide the percentage bars', 'site-reviews'), |
|
| 14 | - 'if_empty' => __('Hide if no reviews are found', 'site-reviews'), |
|
| 15 | - ]; |
|
| 16 | - } |
|
| 7 | + protected function hideOptions() |
|
| 8 | + { |
|
| 9 | + return [ |
|
| 10 | + 'rating' => __('Hide the rating', 'site-reviews'), |
|
| 11 | + 'stars' => __('Hide the stars', 'site-reviews'), |
|
| 12 | + 'summary' => __('Hide the summary', 'site-reviews'), |
|
| 13 | + 'bars' => __('Hide the percentage bars', 'site-reviews'), |
|
| 14 | + 'if_empty' => __('Hide if no reviews are found', 'site-reviews'), |
|
| 15 | + ]; |
|
| 16 | + } |
|
| 17 | 17 | } |
@@ -7,11 +7,11 @@ |
||
| 7 | 7 | protected function hideOptions() |
| 8 | 8 | { |
| 9 | 9 | return [ |
| 10 | - 'rating' => __('Hide the rating', 'site-reviews'), |
|
| 11 | - 'stars' => __('Hide the stars', 'site-reviews'), |
|
| 12 | - 'summary' => __('Hide the summary', 'site-reviews'), |
|
| 13 | - 'bars' => __('Hide the percentage bars', 'site-reviews'), |
|
| 14 | - 'if_empty' => __('Hide if no reviews are found', 'site-reviews'), |
|
| 10 | + 'rating' => __( 'Hide the rating', 'site-reviews' ), |
|
| 11 | + 'stars' => __( 'Hide the stars', 'site-reviews' ), |
|
| 12 | + 'summary' => __( 'Hide the summary', 'site-reviews' ), |
|
| 13 | + 'bars' => __( 'Hide the percentage bars', 'site-reviews' ), |
|
| 14 | + 'if_empty' => __( 'Hide if no reviews are found', 'site-reviews' ), |
|
| 15 | 15 | ]; |
| 16 | 16 | } |
| 17 | 17 | } |
@@ -6,325 +6,325 @@ |
||
| 6 | 6 | |
| 7 | 7 | abstract class TinymcePopupGenerator |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var array |
|
| 11 | - */ |
|
| 12 | - public $properties; |
|
| 9 | + /** |
|
| 10 | + * @var array |
|
| 11 | + */ |
|
| 12 | + public $properties; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public $tag; |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public $tag; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $errors = []; |
|
| 19 | + /** |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $errors = []; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - protected $required = []; |
|
| 24 | + /** |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + protected $required = []; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return array |
|
| 31 | - */ |
|
| 32 | - abstract public function fields(); |
|
| 29 | + /** |
|
| 30 | + * @return array |
|
| 31 | + */ |
|
| 32 | + abstract public function fields(); |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param string $tag |
|
| 36 | - * @return static |
|
| 37 | - */ |
|
| 38 | - public function register($tag, array $args) |
|
| 39 | - { |
|
| 40 | - $this->tag = $tag; |
|
| 41 | - $this->properties = wp_parse_args($args, [ |
|
| 42 | - 'btn_close' => esc_html__('Close', 'site-reviews'), |
|
| 43 | - 'btn_okay' => esc_html__('Insert Shortcode', 'site-reviews'), |
|
| 44 | - 'errors' => $this->errors, |
|
| 45 | - 'fields' => $this->getFields(), |
|
| 46 | - 'label' => '['.$tag.']', |
|
| 47 | - 'required' => $this->required, |
|
| 48 | - 'title' => esc_html__('Shortcode', 'site-reviews'), |
|
| 49 | - ]); |
|
| 50 | - return $this; |
|
| 51 | - } |
|
| 34 | + /** |
|
| 35 | + * @param string $tag |
|
| 36 | + * @return static |
|
| 37 | + */ |
|
| 38 | + public function register($tag, array $args) |
|
| 39 | + { |
|
| 40 | + $this->tag = $tag; |
|
| 41 | + $this->properties = wp_parse_args($args, [ |
|
| 42 | + 'btn_close' => esc_html__('Close', 'site-reviews'), |
|
| 43 | + 'btn_okay' => esc_html__('Insert Shortcode', 'site-reviews'), |
|
| 44 | + 'errors' => $this->errors, |
|
| 45 | + 'fields' => $this->getFields(), |
|
| 46 | + 'label' => '['.$tag.']', |
|
| 47 | + 'required' => $this->required, |
|
| 48 | + 'title' => esc_html__('Shortcode', 'site-reviews'), |
|
| 49 | + ]); |
|
| 50 | + return $this; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return array |
|
| 55 | - */ |
|
| 56 | - protected function generateFields(array $fields) |
|
| 57 | - { |
|
| 58 | - $generatedFields = array_map(function ($field) { |
|
| 59 | - if (empty($field)) { |
|
| 60 | - return; |
|
| 61 | - } |
|
| 62 | - $field = $this->normalize($field); |
|
| 63 | - if (!method_exists($this, $method = 'normalize'.ucfirst($field['type']))) { |
|
| 64 | - return; |
|
| 65 | - } |
|
| 66 | - return $this->$method($field); |
|
| 67 | - }, $fields); |
|
| 68 | - return array_values(array_filter($generatedFields)); |
|
| 69 | - } |
|
| 53 | + /** |
|
| 54 | + * @return array |
|
| 55 | + */ |
|
| 56 | + protected function generateFields(array $fields) |
|
| 57 | + { |
|
| 58 | + $generatedFields = array_map(function ($field) { |
|
| 59 | + if (empty($field)) { |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | + $field = $this->normalize($field); |
|
| 63 | + if (!method_exists($this, $method = 'normalize'.ucfirst($field['type']))) { |
|
| 64 | + return; |
|
| 65 | + } |
|
| 66 | + return $this->$method($field); |
|
| 67 | + }, $fields); |
|
| 68 | + return array_values(array_filter($generatedFields)); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param string $tooltip |
|
| 73 | - * @return array |
|
| 74 | - */ |
|
| 75 | - protected function getCategories($tooltip = '') |
|
| 76 | - { |
|
| 77 | - $terms = glsr(Database::class)->getTerms(); |
|
| 78 | - if (empty($terms)) { |
|
| 79 | - return []; |
|
| 80 | - } |
|
| 81 | - return [ |
|
| 82 | - 'label' => esc_html__('Category', 'site-reviews'), |
|
| 83 | - 'name' => 'category', |
|
| 84 | - 'options' => $terms, |
|
| 85 | - 'tooltip' => $tooltip, |
|
| 86 | - 'type' => 'listbox', |
|
| 87 | - ]; |
|
| 88 | - } |
|
| 71 | + /** |
|
| 72 | + * @param string $tooltip |
|
| 73 | + * @return array |
|
| 74 | + */ |
|
| 75 | + protected function getCategories($tooltip = '') |
|
| 76 | + { |
|
| 77 | + $terms = glsr(Database::class)->getTerms(); |
|
| 78 | + if (empty($terms)) { |
|
| 79 | + return []; |
|
| 80 | + } |
|
| 81 | + return [ |
|
| 82 | + 'label' => esc_html__('Category', 'site-reviews'), |
|
| 83 | + 'name' => 'category', |
|
| 84 | + 'options' => $terms, |
|
| 85 | + 'tooltip' => $tooltip, |
|
| 86 | + 'type' => 'listbox', |
|
| 87 | + ]; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * @return array |
|
| 92 | - */ |
|
| 93 | - protected function getFields() |
|
| 94 | - { |
|
| 95 | - $fields = $this->generateFields($this->fields()); |
|
| 96 | - if (!empty($this->errors)) { |
|
| 97 | - $errors = []; |
|
| 98 | - foreach ($this->required as $name => $alert) { |
|
| 99 | - if (false !== array_search($name, glsr_array_column($fields, 'name'))) { |
|
| 100 | - continue; |
|
| 101 | - } |
|
| 102 | - $errors[] = $this->errors[$name]; |
|
| 103 | - } |
|
| 104 | - $this->errors = $errors; |
|
| 105 | - } |
|
| 106 | - return empty($this->errors) |
|
| 107 | - ? $fields |
|
| 108 | - : $this->errors; |
|
| 109 | - } |
|
| 90 | + /** |
|
| 91 | + * @return array |
|
| 92 | + */ |
|
| 93 | + protected function getFields() |
|
| 94 | + { |
|
| 95 | + $fields = $this->generateFields($this->fields()); |
|
| 96 | + if (!empty($this->errors)) { |
|
| 97 | + $errors = []; |
|
| 98 | + foreach ($this->required as $name => $alert) { |
|
| 99 | + if (false !== array_search($name, glsr_array_column($fields, 'name'))) { |
|
| 100 | + continue; |
|
| 101 | + } |
|
| 102 | + $errors[] = $this->errors[$name]; |
|
| 103 | + } |
|
| 104 | + $this->errors = $errors; |
|
| 105 | + } |
|
| 106 | + return empty($this->errors) |
|
| 107 | + ? $fields |
|
| 108 | + : $this->errors; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * @return array |
|
| 113 | - */ |
|
| 114 | - protected function getHideOptions() |
|
| 115 | - { |
|
| 116 | - $classname = str_replace('Popup', 'Shortcode', get_class($this)); |
|
| 117 | - $hideOptions = glsr($classname)->getHideOptions(); |
|
| 118 | - $options = []; |
|
| 119 | - foreach ($hideOptions as $name => $tooltip) { |
|
| 120 | - $options[] = [ |
|
| 121 | - 'name' => 'hide_'.$name, |
|
| 122 | - 'text' => $name, |
|
| 123 | - 'tooltip' => $tooltip, |
|
| 124 | - 'type' => 'checkbox', |
|
| 125 | - ]; |
|
| 126 | - } |
|
| 127 | - return $options; |
|
| 128 | - } |
|
| 111 | + /** |
|
| 112 | + * @return array |
|
| 113 | + */ |
|
| 114 | + protected function getHideOptions() |
|
| 115 | + { |
|
| 116 | + $classname = str_replace('Popup', 'Shortcode', get_class($this)); |
|
| 117 | + $hideOptions = glsr($classname)->getHideOptions(); |
|
| 118 | + $options = []; |
|
| 119 | + foreach ($hideOptions as $name => $tooltip) { |
|
| 120 | + $options[] = [ |
|
| 121 | + 'name' => 'hide_'.$name, |
|
| 122 | + 'text' => $name, |
|
| 123 | + 'tooltip' => $tooltip, |
|
| 124 | + 'type' => 'checkbox', |
|
| 125 | + ]; |
|
| 126 | + } |
|
| 127 | + return $options; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * @param string $tooltip |
|
| 132 | - * @return array |
|
| 133 | - */ |
|
| 134 | - protected function getTypes($tooltip = '') |
|
| 135 | - { |
|
| 136 | - if (count(glsr()->reviewTypes) < 2) { |
|
| 137 | - return []; |
|
| 138 | - } |
|
| 139 | - return [ |
|
| 140 | - 'label' => esc_html__('Type', 'site-reviews'), |
|
| 141 | - 'name' => 'type', |
|
| 142 | - 'options' => glsr()->reviewTypes, |
|
| 143 | - 'tooltip' => $tooltip, |
|
| 144 | - 'type' => 'listbox', |
|
| 145 | - ]; |
|
| 146 | - } |
|
| 130 | + /** |
|
| 131 | + * @param string $tooltip |
|
| 132 | + * @return array |
|
| 133 | + */ |
|
| 134 | + protected function getTypes($tooltip = '') |
|
| 135 | + { |
|
| 136 | + if (count(glsr()->reviewTypes) < 2) { |
|
| 137 | + return []; |
|
| 138 | + } |
|
| 139 | + return [ |
|
| 140 | + 'label' => esc_html__('Type', 'site-reviews'), |
|
| 141 | + 'name' => 'type', |
|
| 142 | + 'options' => glsr()->reviewTypes, |
|
| 143 | + 'tooltip' => $tooltip, |
|
| 144 | + 'type' => 'listbox', |
|
| 145 | + ]; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * @return array |
|
| 150 | - */ |
|
| 151 | - protected function normalize(array $field) |
|
| 152 | - { |
|
| 153 | - return wp_parse_args($field, [ |
|
| 154 | - 'items' => [], |
|
| 155 | - 'type' => '', |
|
| 156 | - ]); |
|
| 157 | - } |
|
| 148 | + /** |
|
| 149 | + * @return array |
|
| 150 | + */ |
|
| 151 | + protected function normalize(array $field) |
|
| 152 | + { |
|
| 153 | + return wp_parse_args($field, [ |
|
| 154 | + 'items' => [], |
|
| 155 | + 'type' => '', |
|
| 156 | + ]); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * @return void|array |
|
| 161 | - */ |
|
| 162 | - protected function normalizeCheckbox(array $field) |
|
| 163 | - { |
|
| 164 | - return $this->normalizeField($field, [ |
|
| 165 | - 'checked' => false, |
|
| 166 | - 'label' => '', |
|
| 167 | - 'minHeight' => '', |
|
| 168 | - 'minWidth' => '', |
|
| 169 | - 'name' => false, |
|
| 170 | - 'text' => '', |
|
| 171 | - 'tooltip' => '', |
|
| 172 | - 'type' => '', |
|
| 173 | - 'value' => '', |
|
| 174 | - ]); |
|
| 175 | - } |
|
| 159 | + /** |
|
| 160 | + * @return void|array |
|
| 161 | + */ |
|
| 162 | + protected function normalizeCheckbox(array $field) |
|
| 163 | + { |
|
| 164 | + return $this->normalizeField($field, [ |
|
| 165 | + 'checked' => false, |
|
| 166 | + 'label' => '', |
|
| 167 | + 'minHeight' => '', |
|
| 168 | + 'minWidth' => '', |
|
| 169 | + 'name' => false, |
|
| 170 | + 'text' => '', |
|
| 171 | + 'tooltip' => '', |
|
| 172 | + 'type' => '', |
|
| 173 | + 'value' => '', |
|
| 174 | + ]); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * @return void|array |
|
| 179 | - */ |
|
| 180 | - protected function normalizeContainer(array $field) |
|
| 181 | - { |
|
| 182 | - if (!array_key_exists('html', $field) && !array_key_exists('items', $field)) { |
|
| 183 | - return; |
|
| 184 | - } |
|
| 185 | - $field['items'] = $this->generateFields($field['items']); |
|
| 186 | - return $field; |
|
| 187 | - } |
|
| 177 | + /** |
|
| 178 | + * @return void|array |
|
| 179 | + */ |
|
| 180 | + protected function normalizeContainer(array $field) |
|
| 181 | + { |
|
| 182 | + if (!array_key_exists('html', $field) && !array_key_exists('items', $field)) { |
|
| 183 | + return; |
|
| 184 | + } |
|
| 185 | + $field['items'] = $this->generateFields($field['items']); |
|
| 186 | + return $field; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * @return void|array |
|
| 191 | - */ |
|
| 192 | - protected function normalizeField(array $field, array $defaults) |
|
| 193 | - { |
|
| 194 | - if (!$this->validate($field)) { |
|
| 195 | - return; |
|
| 196 | - } |
|
| 197 | - return array_filter(shortcode_atts($defaults, $field), function ($value) { |
|
| 198 | - return '' !== $value; |
|
| 199 | - }); |
|
| 200 | - } |
|
| 189 | + /** |
|
| 190 | + * @return void|array |
|
| 191 | + */ |
|
| 192 | + protected function normalizeField(array $field, array $defaults) |
|
| 193 | + { |
|
| 194 | + if (!$this->validate($field)) { |
|
| 195 | + return; |
|
| 196 | + } |
|
| 197 | + return array_filter(shortcode_atts($defaults, $field), function ($value) { |
|
| 198 | + return '' !== $value; |
|
| 199 | + }); |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * @return void|array |
|
| 204 | - */ |
|
| 205 | - protected function normalizeListbox(array $field) |
|
| 206 | - { |
|
| 207 | - $listbox = $this->normalizeField($field, [ |
|
| 208 | - 'label' => '', |
|
| 209 | - 'minWidth' => '', |
|
| 210 | - 'name' => false, |
|
| 211 | - 'options' => [], |
|
| 212 | - 'placeholder' => esc_attr__('- Select -', 'site-reviews'), |
|
| 213 | - 'tooltip' => '', |
|
| 214 | - 'type' => '', |
|
| 215 | - 'value' => '', |
|
| 216 | - ]); |
|
| 217 | - if (!is_array($listbox)) { |
|
| 218 | - return; |
|
| 219 | - } |
|
| 220 | - if (!array_key_exists('', $listbox['options'])) { |
|
| 221 | - $listbox['options'] = ['' => $listbox['placeholder']] + $listbox['options']; |
|
| 222 | - } |
|
| 223 | - foreach ($listbox['options'] as $value => $text) { |
|
| 224 | - $listbox['values'][] = [ |
|
| 225 | - 'text' => $text, |
|
| 226 | - 'value' => $value, |
|
| 227 | - ]; |
|
| 228 | - } |
|
| 229 | - return $listbox; |
|
| 230 | - } |
|
| 202 | + /** |
|
| 203 | + * @return void|array |
|
| 204 | + */ |
|
| 205 | + protected function normalizeListbox(array $field) |
|
| 206 | + { |
|
| 207 | + $listbox = $this->normalizeField($field, [ |
|
| 208 | + 'label' => '', |
|
| 209 | + 'minWidth' => '', |
|
| 210 | + 'name' => false, |
|
| 211 | + 'options' => [], |
|
| 212 | + 'placeholder' => esc_attr__('- Select -', 'site-reviews'), |
|
| 213 | + 'tooltip' => '', |
|
| 214 | + 'type' => '', |
|
| 215 | + 'value' => '', |
|
| 216 | + ]); |
|
| 217 | + if (!is_array($listbox)) { |
|
| 218 | + return; |
|
| 219 | + } |
|
| 220 | + if (!array_key_exists('', $listbox['options'])) { |
|
| 221 | + $listbox['options'] = ['' => $listbox['placeholder']] + $listbox['options']; |
|
| 222 | + } |
|
| 223 | + foreach ($listbox['options'] as $value => $text) { |
|
| 224 | + $listbox['values'][] = [ |
|
| 225 | + 'text' => $text, |
|
| 226 | + 'value' => $value, |
|
| 227 | + ]; |
|
| 228 | + } |
|
| 229 | + return $listbox; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * @return void|array |
|
| 234 | - */ |
|
| 235 | - protected function normalizePost(array $field) |
|
| 236 | - { |
|
| 237 | - if (!is_array($field['query_args'])) { |
|
| 238 | - $field['query_args'] = []; |
|
| 239 | - } |
|
| 240 | - $posts = get_posts(wp_parse_args($field['query_args'], [ |
|
| 241 | - 'order' => 'ASC', |
|
| 242 | - 'orderby' => 'title', |
|
| 243 | - 'post_type' => 'post', |
|
| 244 | - 'posts_per_page' => 30, |
|
| 245 | - ])); |
|
| 246 | - if (!empty($posts)) { |
|
| 247 | - $options = []; |
|
| 248 | - foreach ($posts as $post) { |
|
| 249 | - $options[$post->ID] = esc_html($post->post_title); |
|
| 250 | - } |
|
| 251 | - $field['options'] = $options; |
|
| 252 | - $field['type'] = 'listbox'; |
|
| 253 | - return $this->normalizeListbox($field); |
|
| 254 | - } |
|
| 255 | - $this->validate($field); |
|
| 256 | - } |
|
| 232 | + /** |
|
| 233 | + * @return void|array |
|
| 234 | + */ |
|
| 235 | + protected function normalizePost(array $field) |
|
| 236 | + { |
|
| 237 | + if (!is_array($field['query_args'])) { |
|
| 238 | + $field['query_args'] = []; |
|
| 239 | + } |
|
| 240 | + $posts = get_posts(wp_parse_args($field['query_args'], [ |
|
| 241 | + 'order' => 'ASC', |
|
| 242 | + 'orderby' => 'title', |
|
| 243 | + 'post_type' => 'post', |
|
| 244 | + 'posts_per_page' => 30, |
|
| 245 | + ])); |
|
| 246 | + if (!empty($posts)) { |
|
| 247 | + $options = []; |
|
| 248 | + foreach ($posts as $post) { |
|
| 249 | + $options[$post->ID] = esc_html($post->post_title); |
|
| 250 | + } |
|
| 251 | + $field['options'] = $options; |
|
| 252 | + $field['type'] = 'listbox'; |
|
| 253 | + return $this->normalizeListbox($field); |
|
| 254 | + } |
|
| 255 | + $this->validate($field); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * @return void|array |
|
| 260 | - */ |
|
| 261 | - protected function normalizeTextbox(array $field) |
|
| 262 | - { |
|
| 263 | - return $this->normalizeField($field, [ |
|
| 264 | - 'hidden' => false, |
|
| 265 | - 'label' => '', |
|
| 266 | - 'maxLength' => '', |
|
| 267 | - 'minHeight' => '', |
|
| 268 | - 'minWidth' => '', |
|
| 269 | - 'multiline' => false, |
|
| 270 | - 'name' => false, |
|
| 271 | - 'size' => '', |
|
| 272 | - 'text' => '', |
|
| 273 | - 'tooltip' => '', |
|
| 274 | - 'type' => '', |
|
| 275 | - 'value' => '', |
|
| 276 | - ]); |
|
| 277 | - } |
|
| 258 | + /** |
|
| 259 | + * @return void|array |
|
| 260 | + */ |
|
| 261 | + protected function normalizeTextbox(array $field) |
|
| 262 | + { |
|
| 263 | + return $this->normalizeField($field, [ |
|
| 264 | + 'hidden' => false, |
|
| 265 | + 'label' => '', |
|
| 266 | + 'maxLength' => '', |
|
| 267 | + 'minHeight' => '', |
|
| 268 | + 'minWidth' => '', |
|
| 269 | + 'multiline' => false, |
|
| 270 | + 'name' => false, |
|
| 271 | + 'size' => '', |
|
| 272 | + 'text' => '', |
|
| 273 | + 'tooltip' => '', |
|
| 274 | + 'type' => '', |
|
| 275 | + 'value' => '', |
|
| 276 | + ]); |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - /** |
|
| 280 | - * @return bool |
|
| 281 | - */ |
|
| 282 | - protected function validate(array $field) |
|
| 283 | - { |
|
| 284 | - $args = shortcode_atts([ |
|
| 285 | - 'label' => '', |
|
| 286 | - 'name' => false, |
|
| 287 | - 'required' => false, |
|
| 288 | - ], $field); |
|
| 289 | - if (!$args['name']) { |
|
| 290 | - return false; |
|
| 291 | - } |
|
| 292 | - return $this->validateErrors($args) && $this->validateRequired($args); |
|
| 293 | - } |
|
| 279 | + /** |
|
| 280 | + * @return bool |
|
| 281 | + */ |
|
| 282 | + protected function validate(array $field) |
|
| 283 | + { |
|
| 284 | + $args = shortcode_atts([ |
|
| 285 | + 'label' => '', |
|
| 286 | + 'name' => false, |
|
| 287 | + 'required' => false, |
|
| 288 | + ], $field); |
|
| 289 | + if (!$args['name']) { |
|
| 290 | + return false; |
|
| 291 | + } |
|
| 292 | + return $this->validateErrors($args) && $this->validateRequired($args); |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * @return bool |
|
| 297 | - */ |
|
| 298 | - protected function validateErrors(array $args) |
|
| 299 | - { |
|
| 300 | - if (!isset($args['required']['error'])) { |
|
| 301 | - return true; |
|
| 302 | - } |
|
| 303 | - $this->errors[$args['name']] = $this->normalizeContainer([ |
|
| 304 | - 'html' => $args['required']['error'], |
|
| 305 | - 'type' => 'container', |
|
| 306 | - ]); |
|
| 307 | - return false; |
|
| 308 | - } |
|
| 295 | + /** |
|
| 296 | + * @return bool |
|
| 297 | + */ |
|
| 298 | + protected function validateErrors(array $args) |
|
| 299 | + { |
|
| 300 | + if (!isset($args['required']['error'])) { |
|
| 301 | + return true; |
|
| 302 | + } |
|
| 303 | + $this->errors[$args['name']] = $this->normalizeContainer([ |
|
| 304 | + 'html' => $args['required']['error'], |
|
| 305 | + 'type' => 'container', |
|
| 306 | + ]); |
|
| 307 | + return false; |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - /** |
|
| 311 | - * @return bool |
|
| 312 | - */ |
|
| 313 | - protected function validateRequired(array $args) |
|
| 314 | - { |
|
| 315 | - if (false == $args['required']) { |
|
| 316 | - return true; |
|
| 317 | - } |
|
| 318 | - $alert = esc_html__('Some of the shortcode options are required.', 'site-reviews'); |
|
| 319 | - if (isset($args['required']['alert'])) { |
|
| 320 | - $alert = $args['required']['alert']; |
|
| 321 | - } elseif (!empty($args['label'])) { |
|
| 322 | - $alert = sprintf( |
|
| 323 | - esc_html_x('The "%s" option is required.', 'the option label', 'site-reviews'), |
|
| 324 | - str_replace(':', '', $args['label']) |
|
| 325 | - ); |
|
| 326 | - } |
|
| 327 | - $this->required[$args['name']] = $alert; |
|
| 328 | - return false; |
|
| 329 | - } |
|
| 310 | + /** |
|
| 311 | + * @return bool |
|
| 312 | + */ |
|
| 313 | + protected function validateRequired(array $args) |
|
| 314 | + { |
|
| 315 | + if (false == $args['required']) { |
|
| 316 | + return true; |
|
| 317 | + } |
|
| 318 | + $alert = esc_html__('Some of the shortcode options are required.', 'site-reviews'); |
|
| 319 | + if (isset($args['required']['alert'])) { |
|
| 320 | + $alert = $args['required']['alert']; |
|
| 321 | + } elseif (!empty($args['label'])) { |
|
| 322 | + $alert = sprintf( |
|
| 323 | + esc_html_x('The "%s" option is required.', 'the option label', 'site-reviews'), |
|
| 324 | + str_replace(':', '', $args['label']) |
|
| 325 | + ); |
|
| 326 | + } |
|
| 327 | + $this->required[$args['name']] = $alert; |
|
| 328 | + return false; |
|
| 329 | + } |
|
| 330 | 330 | } |
@@ -35,51 +35,51 @@ discard block |
||
| 35 | 35 | * @param string $tag |
| 36 | 36 | * @return static |
| 37 | 37 | */ |
| 38 | - public function register($tag, array $args) |
|
| 38 | + public function register( $tag, array $args ) |
|
| 39 | 39 | { |
| 40 | 40 | $this->tag = $tag; |
| 41 | - $this->properties = wp_parse_args($args, [ |
|
| 42 | - 'btn_close' => esc_html__('Close', 'site-reviews'), |
|
| 43 | - 'btn_okay' => esc_html__('Insert Shortcode', 'site-reviews'), |
|
| 41 | + $this->properties = wp_parse_args( $args, [ |
|
| 42 | + 'btn_close' => esc_html__( 'Close', 'site-reviews' ), |
|
| 43 | + 'btn_okay' => esc_html__( 'Insert Shortcode', 'site-reviews' ), |
|
| 44 | 44 | 'errors' => $this->errors, |
| 45 | 45 | 'fields' => $this->getFields(), |
| 46 | 46 | 'label' => '['.$tag.']', |
| 47 | 47 | 'required' => $this->required, |
| 48 | - 'title' => esc_html__('Shortcode', 'site-reviews'), |
|
| 49 | - ]); |
|
| 48 | + 'title' => esc_html__( 'Shortcode', 'site-reviews' ), |
|
| 49 | + ] ); |
|
| 50 | 50 | return $this; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @return array |
| 55 | 55 | */ |
| 56 | - protected function generateFields(array $fields) |
|
| 56 | + protected function generateFields( array $fields ) |
|
| 57 | 57 | { |
| 58 | - $generatedFields = array_map(function ($field) { |
|
| 59 | - if (empty($field)) { |
|
| 58 | + $generatedFields = array_map( function( $field ) { |
|
| 59 | + if( empty($field) ) { |
|
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | - $field = $this->normalize($field); |
|
| 63 | - if (!method_exists($this, $method = 'normalize'.ucfirst($field['type']))) { |
|
| 62 | + $field = $this->normalize( $field ); |
|
| 63 | + if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] ) ) ) { |
|
| 64 | 64 | return; |
| 65 | 65 | } |
| 66 | - return $this->$method($field); |
|
| 67 | - }, $fields); |
|
| 68 | - return array_values(array_filter($generatedFields)); |
|
| 66 | + return $this->$method( $field ); |
|
| 67 | + }, $fields ); |
|
| 68 | + return array_values( array_filter( $generatedFields ) ); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * @param string $tooltip |
| 73 | 73 | * @return array |
| 74 | 74 | */ |
| 75 | - protected function getCategories($tooltip = '') |
|
| 75 | + protected function getCategories( $tooltip = '' ) |
|
| 76 | 76 | { |
| 77 | - $terms = glsr(Database::class)->getTerms(); |
|
| 78 | - if (empty($terms)) { |
|
| 77 | + $terms = glsr( Database::class )->getTerms(); |
|
| 78 | + if( empty($terms) ) { |
|
| 79 | 79 | return []; |
| 80 | 80 | } |
| 81 | 81 | return [ |
| 82 | - 'label' => esc_html__('Category', 'site-reviews'), |
|
| 82 | + 'label' => esc_html__( 'Category', 'site-reviews' ), |
|
| 83 | 83 | 'name' => 'category', |
| 84 | 84 | 'options' => $terms, |
| 85 | 85 | 'tooltip' => $tooltip, |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | protected function getFields() |
| 94 | 94 | { |
| 95 | - $fields = $this->generateFields($this->fields()); |
|
| 96 | - if (!empty($this->errors)) { |
|
| 95 | + $fields = $this->generateFields( $this->fields() ); |
|
| 96 | + if( !empty($this->errors) ) { |
|
| 97 | 97 | $errors = []; |
| 98 | - foreach ($this->required as $name => $alert) { |
|
| 99 | - if (false !== array_search($name, glsr_array_column($fields, 'name'))) { |
|
| 98 | + foreach( $this->required as $name => $alert ) { |
|
| 99 | + if( false !== array_search( $name, glsr_array_column( $fields, 'name' ) ) ) { |
|
| 100 | 100 | continue; |
| 101 | 101 | } |
| 102 | 102 | $errors[] = $this->errors[$name]; |
@@ -113,10 +113,10 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | protected function getHideOptions() |
| 115 | 115 | { |
| 116 | - $classname = str_replace('Popup', 'Shortcode', get_class($this)); |
|
| 117 | - $hideOptions = glsr($classname)->getHideOptions(); |
|
| 116 | + $classname = str_replace( 'Popup', 'Shortcode', get_class( $this ) ); |
|
| 117 | + $hideOptions = glsr( $classname )->getHideOptions(); |
|
| 118 | 118 | $options = []; |
| 119 | - foreach ($hideOptions as $name => $tooltip) { |
|
| 119 | + foreach( $hideOptions as $name => $tooltip ) { |
|
| 120 | 120 | $options[] = [ |
| 121 | 121 | 'name' => 'hide_'.$name, |
| 122 | 122 | 'text' => $name, |
@@ -131,13 +131,13 @@ discard block |
||
| 131 | 131 | * @param string $tooltip |
| 132 | 132 | * @return array |
| 133 | 133 | */ |
| 134 | - protected function getTypes($tooltip = '') |
|
| 134 | + protected function getTypes( $tooltip = '' ) |
|
| 135 | 135 | { |
| 136 | - if (count(glsr()->reviewTypes) < 2) { |
|
| 136 | + if( count( glsr()->reviewTypes ) < 2 ) { |
|
| 137 | 137 | return []; |
| 138 | 138 | } |
| 139 | 139 | return [ |
| 140 | - 'label' => esc_html__('Type', 'site-reviews'), |
|
| 140 | + 'label' => esc_html__( 'Type', 'site-reviews' ), |
|
| 141 | 141 | 'name' => 'type', |
| 142 | 142 | 'options' => glsr()->reviewTypes, |
| 143 | 143 | 'tooltip' => $tooltip, |
@@ -148,20 +148,20 @@ discard block |
||
| 148 | 148 | /** |
| 149 | 149 | * @return array |
| 150 | 150 | */ |
| 151 | - protected function normalize(array $field) |
|
| 151 | + protected function normalize( array $field ) |
|
| 152 | 152 | { |
| 153 | - return wp_parse_args($field, [ |
|
| 153 | + return wp_parse_args( $field, [ |
|
| 154 | 154 | 'items' => [], |
| 155 | 155 | 'type' => '', |
| 156 | - ]); |
|
| 156 | + ] ); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | 160 | * @return void|array |
| 161 | 161 | */ |
| 162 | - protected function normalizeCheckbox(array $field) |
|
| 162 | + protected function normalizeCheckbox( array $field ) |
|
| 163 | 163 | { |
| 164 | - return $this->normalizeField($field, [ |
|
| 164 | + return $this->normalizeField( $field, [ |
|
| 165 | 165 | 'checked' => false, |
| 166 | 166 | 'label' => '', |
| 167 | 167 | 'minHeight' => '', |
@@ -171,30 +171,30 @@ discard block |
||
| 171 | 171 | 'tooltip' => '', |
| 172 | 172 | 'type' => '', |
| 173 | 173 | 'value' => '', |
| 174 | - ]); |
|
| 174 | + ] ); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
| 178 | 178 | * @return void|array |
| 179 | 179 | */ |
| 180 | - protected function normalizeContainer(array $field) |
|
| 180 | + protected function normalizeContainer( array $field ) |
|
| 181 | 181 | { |
| 182 | - if (!array_key_exists('html', $field) && !array_key_exists('items', $field)) { |
|
| 182 | + if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field ) ) { |
|
| 183 | 183 | return; |
| 184 | 184 | } |
| 185 | - $field['items'] = $this->generateFields($field['items']); |
|
| 185 | + $field['items'] = $this->generateFields( $field['items'] ); |
|
| 186 | 186 | return $field; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
| 190 | 190 | * @return void|array |
| 191 | 191 | */ |
| 192 | - protected function normalizeField(array $field, array $defaults) |
|
| 192 | + protected function normalizeField( array $field, array $defaults ) |
|
| 193 | 193 | { |
| 194 | - if (!$this->validate($field)) { |
|
| 194 | + if( !$this->validate( $field ) ) { |
|
| 195 | 195 | return; |
| 196 | 196 | } |
| 197 | - return array_filter(shortcode_atts($defaults, $field), function ($value) { |
|
| 197 | + return array_filter( shortcode_atts( $defaults, $field ), function( $value ) { |
|
| 198 | 198 | return '' !== $value; |
| 199 | 199 | }); |
| 200 | 200 | } |
@@ -202,25 +202,25 @@ discard block |
||
| 202 | 202 | /** |
| 203 | 203 | * @return void|array |
| 204 | 204 | */ |
| 205 | - protected function normalizeListbox(array $field) |
|
| 205 | + protected function normalizeListbox( array $field ) |
|
| 206 | 206 | { |
| 207 | - $listbox = $this->normalizeField($field, [ |
|
| 207 | + $listbox = $this->normalizeField( $field, [ |
|
| 208 | 208 | 'label' => '', |
| 209 | 209 | 'minWidth' => '', |
| 210 | 210 | 'name' => false, |
| 211 | 211 | 'options' => [], |
| 212 | - 'placeholder' => esc_attr__('- Select -', 'site-reviews'), |
|
| 212 | + 'placeholder' => esc_attr__( '- Select -', 'site-reviews' ), |
|
| 213 | 213 | 'tooltip' => '', |
| 214 | 214 | 'type' => '', |
| 215 | 215 | 'value' => '', |
| 216 | - ]); |
|
| 217 | - if (!is_array($listbox)) { |
|
| 216 | + ] ); |
|
| 217 | + if( !is_array( $listbox ) ) { |
|
| 218 | 218 | return; |
| 219 | 219 | } |
| 220 | - if (!array_key_exists('', $listbox['options'])) { |
|
| 220 | + if( !array_key_exists( '', $listbox['options'] ) ) { |
|
| 221 | 221 | $listbox['options'] = ['' => $listbox['placeholder']] + $listbox['options']; |
| 222 | 222 | } |
| 223 | - foreach ($listbox['options'] as $value => $text) { |
|
| 223 | + foreach( $listbox['options'] as $value => $text ) { |
|
| 224 | 224 | $listbox['values'][] = [ |
| 225 | 225 | 'text' => $text, |
| 226 | 226 | 'value' => $value, |
@@ -232,35 +232,35 @@ discard block |
||
| 232 | 232 | /** |
| 233 | 233 | * @return void|array |
| 234 | 234 | */ |
| 235 | - protected function normalizePost(array $field) |
|
| 235 | + protected function normalizePost( array $field ) |
|
| 236 | 236 | { |
| 237 | - if (!is_array($field['query_args'])) { |
|
| 237 | + if( !is_array( $field['query_args'] ) ) { |
|
| 238 | 238 | $field['query_args'] = []; |
| 239 | 239 | } |
| 240 | - $posts = get_posts(wp_parse_args($field['query_args'], [ |
|
| 240 | + $posts = get_posts( wp_parse_args( $field['query_args'], [ |
|
| 241 | 241 | 'order' => 'ASC', |
| 242 | 242 | 'orderby' => 'title', |
| 243 | 243 | 'post_type' => 'post', |
| 244 | 244 | 'posts_per_page' => 30, |
| 245 | - ])); |
|
| 246 | - if (!empty($posts)) { |
|
| 245 | + ] ) ); |
|
| 246 | + if( !empty($posts) ) { |
|
| 247 | 247 | $options = []; |
| 248 | - foreach ($posts as $post) { |
|
| 249 | - $options[$post->ID] = esc_html($post->post_title); |
|
| 248 | + foreach( $posts as $post ) { |
|
| 249 | + $options[$post->ID] = esc_html( $post->post_title ); |
|
| 250 | 250 | } |
| 251 | 251 | $field['options'] = $options; |
| 252 | 252 | $field['type'] = 'listbox'; |
| 253 | - return $this->normalizeListbox($field); |
|
| 253 | + return $this->normalizeListbox( $field ); |
|
| 254 | 254 | } |
| 255 | - $this->validate($field); |
|
| 255 | + $this->validate( $field ); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | 259 | * @return void|array |
| 260 | 260 | */ |
| 261 | - protected function normalizeTextbox(array $field) |
|
| 261 | + protected function normalizeTextbox( array $field ) |
|
| 262 | 262 | { |
| 263 | - return $this->normalizeField($field, [ |
|
| 263 | + return $this->normalizeField( $field, [ |
|
| 264 | 264 | 'hidden' => false, |
| 265 | 265 | 'label' => '', |
| 266 | 266 | 'maxLength' => '', |
@@ -273,55 +273,55 @@ discard block |
||
| 273 | 273 | 'tooltip' => '', |
| 274 | 274 | 'type' => '', |
| 275 | 275 | 'value' => '', |
| 276 | - ]); |
|
| 276 | + ] ); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
| 280 | 280 | * @return bool |
| 281 | 281 | */ |
| 282 | - protected function validate(array $field) |
|
| 282 | + protected function validate( array $field ) |
|
| 283 | 283 | { |
| 284 | - $args = shortcode_atts([ |
|
| 284 | + $args = shortcode_atts( [ |
|
| 285 | 285 | 'label' => '', |
| 286 | 286 | 'name' => false, |
| 287 | 287 | 'required' => false, |
| 288 | - ], $field); |
|
| 289 | - if (!$args['name']) { |
|
| 288 | + ], $field ); |
|
| 289 | + if( !$args['name'] ) { |
|
| 290 | 290 | return false; |
| 291 | 291 | } |
| 292 | - return $this->validateErrors($args) && $this->validateRequired($args); |
|
| 292 | + return $this->validateErrors( $args ) && $this->validateRequired( $args ); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
| 296 | 296 | * @return bool |
| 297 | 297 | */ |
| 298 | - protected function validateErrors(array $args) |
|
| 298 | + protected function validateErrors( array $args ) |
|
| 299 | 299 | { |
| 300 | - if (!isset($args['required']['error'])) { |
|
| 300 | + if( !isset($args['required']['error']) ) { |
|
| 301 | 301 | return true; |
| 302 | 302 | } |
| 303 | - $this->errors[$args['name']] = $this->normalizeContainer([ |
|
| 303 | + $this->errors[$args['name']] = $this->normalizeContainer( [ |
|
| 304 | 304 | 'html' => $args['required']['error'], |
| 305 | 305 | 'type' => 'container', |
| 306 | - ]); |
|
| 306 | + ] ); |
|
| 307 | 307 | return false; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
| 311 | 311 | * @return bool |
| 312 | 312 | */ |
| 313 | - protected function validateRequired(array $args) |
|
| 313 | + protected function validateRequired( array $args ) |
|
| 314 | 314 | { |
| 315 | - if (false == $args['required']) { |
|
| 315 | + if( false == $args['required'] ) { |
|
| 316 | 316 | return true; |
| 317 | 317 | } |
| 318 | - $alert = esc_html__('Some of the shortcode options are required.', 'site-reviews'); |
|
| 319 | - if (isset($args['required']['alert'])) { |
|
| 318 | + $alert = esc_html__( 'Some of the shortcode options are required.', 'site-reviews' ); |
|
| 319 | + if( isset($args['required']['alert']) ) { |
|
| 320 | 320 | $alert = $args['required']['alert']; |
| 321 | - } elseif (!empty($args['label'])) { |
|
| 321 | + } elseif( !empty($args['label']) ) { |
|
| 322 | 322 | $alert = sprintf( |
| 323 | - esc_html_x('The "%s" option is required.', 'the option label', 'site-reviews'), |
|
| 324 | - str_replace(':', '', $args['label']) |
|
| 323 | + esc_html_x( 'The "%s" option is required.', 'the option label', 'site-reviews' ), |
|
| 324 | + str_replace( ':', '', $args['label'] ) |
|
| 325 | 325 | ); |
| 326 | 326 | } |
| 327 | 327 | $this->required[$args['name']] = $alert; |
@@ -318,7 +318,8 @@ |
||
| 318 | 318 | $alert = esc_html__('Some of the shortcode options are required.', 'site-reviews'); |
| 319 | 319 | if (isset($args['required']['alert'])) { |
| 320 | 320 | $alert = $args['required']['alert']; |
| 321 | - } elseif (!empty($args['label'])) { |
|
| 321 | + } |
|
| 322 | + elseif (!empty($args['label'])) { |
|
| 322 | 323 | $alert = sprintf( |
| 323 | 324 | esc_html_x('The "%s" option is required.', 'the option label', 'site-reviews'), |
| 324 | 325 | str_replace(':', '', $args['label']) |
@@ -6,18 +6,18 @@ |
||
| 6 | 6 | |
| 7 | 7 | class PaginationDefaults extends Defaults |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @return array |
|
| 11 | - */ |
|
| 12 | - protected function defaults() |
|
| 13 | - { |
|
| 14 | - return [ |
|
| 15 | - 'before_page_number' => '<span class="meta-nav screen-reader-text">'.__('Page', 'site-reviews').' </span>', |
|
| 16 | - 'format' => '?'.glsr()->constant('PAGED_QUERY_VAR').'=%#%', |
|
| 17 | - 'mid_size' => 1, |
|
| 18 | - 'next_text' => __('Next →', 'site-reviews'), |
|
| 19 | - 'prev_text' => __('← Previous', 'site-reviews'), |
|
| 20 | - 'type' => 'plain', |
|
| 21 | - ]; |
|
| 22 | - } |
|
| 9 | + /** |
|
| 10 | + * @return array |
|
| 11 | + */ |
|
| 12 | + protected function defaults() |
|
| 13 | + { |
|
| 14 | + return [ |
|
| 15 | + 'before_page_number' => '<span class="meta-nav screen-reader-text">'.__('Page', 'site-reviews').' </span>', |
|
| 16 | + 'format' => '?'.glsr()->constant('PAGED_QUERY_VAR').'=%#%', |
|
| 17 | + 'mid_size' => 1, |
|
| 18 | + 'next_text' => __('Next →', 'site-reviews'), |
|
| 19 | + 'prev_text' => __('← Previous', 'site-reviews'), |
|
| 20 | + 'type' => 'plain', |
|
| 21 | + ]; |
|
| 22 | + } |
|
| 23 | 23 | } |
@@ -12,11 +12,11 @@ |
||
| 12 | 12 | protected function defaults() |
| 13 | 13 | { |
| 14 | 14 | return [ |
| 15 | - 'before_page_number' => '<span class="meta-nav screen-reader-text">'.__('Page', 'site-reviews').' </span>', |
|
| 16 | - 'format' => '?'.glsr()->constant('PAGED_QUERY_VAR').'=%#%', |
|
| 15 | + 'before_page_number' => '<span class="meta-nav screen-reader-text">'.__( 'Page', 'site-reviews' ).' </span>', |
|
| 16 | + 'format' => '?'.glsr()->constant( 'PAGED_QUERY_VAR' ).'=%#%', |
|
| 17 | 17 | 'mid_size' => 1, |
| 18 | - 'next_text' => __('Next →', 'site-reviews'), |
|
| 19 | - 'prev_text' => __('← Previous', 'site-reviews'), |
|
| 18 | + 'next_text' => __( 'Next →', 'site-reviews' ), |
|
| 19 | + 'prev_text' => __( '← Previous', 'site-reviews' ), |
|
| 20 | 20 | 'type' => 'plain', |
| 21 | 21 | ]; |
| 22 | 22 | } |