EditShortcodeEditProfile
5 years ago
EditShortcodeLogin
5 years ago
EditShortcodeMelange
5 years ago
EditShortcodeMemberDirectories
5 years ago
EditShortcodePasswordReset
5 years ago
EditShortcodeRegistration
5 years ago
EditShortcodeUserProfile
5 years ago
ShortcodeInserterTrait.php
5 years ago
ShortcodeInserterTrait.php
602 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Admin\SettingsPages\ShortcodeBuilder; |
| 4 | |
| 5 | use ProfilePress\Core\Classes\ExtensionManager as EM; |
| 6 | use ProfilePress\Core\Classes\PROFILEPRESS_sql; |
| 7 | |
| 8 | trait ShortcodeInserterTrait |
| 9 | { |
| 10 | public $form_shortcodes; |
| 11 | |
| 12 | public function traitInit($form_shortcodes) |
| 13 | { |
| 14 | $this->form_shortcodes = $form_shortcodes; |
| 15 | |
| 16 | add_action('admin_footer', [$this, 'shortcode_inserter_modal']); |
| 17 | add_action('admin_footer', [$this, 'shortcode_inserter_script']); |
| 18 | } |
| 19 | |
| 20 | public static function global_shortcodes() |
| 21 | { |
| 22 | return apply_filters('ppress_global_available_shortcodes', [ |
| 23 | 'pp-user-avatar' => [ |
| 24 | 'description' => esc_html__("Displays user's avatar", 'wp-user-avatar'), |
| 25 | 'shortcode' => 'pp-user-avatar', |
| 26 | 'attributes' => [ |
| 27 | 'size' => [ |
| 28 | 'label' => esc_html__('Size of avatar', 'wp-user-avatar'), |
| 29 | 'field' => 'number' |
| 30 | ], |
| 31 | 'class' => [ |
| 32 | 'label' => esc_html__('CSS class', 'wp-user-avatar'), |
| 33 | 'field' => 'text' |
| 34 | ], |
| 35 | ] |
| 36 | ], |
| 37 | 'pp-user-cover-image' => [ |
| 38 | 'description' => esc_html__("Displays user's cover image", 'wp-user-avatar'), |
| 39 | 'shortcode' => 'pp-user-cover-image', |
| 40 | 'attributes' => [ |
| 41 | 'id' => [ |
| 42 | 'label' => esc_html__('ID', 'wp-user-avatar'), |
| 43 | 'field' => 'text' |
| 44 | ], |
| 45 | 'class' => [ |
| 46 | 'label' => esc_html__('CSS class', 'wp-user-avatar'), |
| 47 | 'field' => 'text' |
| 48 | ], |
| 49 | 'alt' => [ |
| 50 | 'label' => esc_html__('Alternate text', 'wp-user-avatar'), |
| 51 | 'field' => 'text' |
| 52 | ], |
| 53 | ] |
| 54 | ], |
| 55 | 'pp-password-hint' => [ |
| 56 | 'description' => esc_html__('Displays password hint', 'wp-user-avatar'), |
| 57 | 'shortcode' => 'pp-password-hint' |
| 58 | ], |
| 59 | 'pp-social-login' => [ |
| 60 | 'description' => esc_html__('Social login button', 'wp-user-avatar'), |
| 61 | 'shortcode' => 'pp-social-login', |
| 62 | 'attributes' => [ |
| 63 | 'type' => [ |
| 64 | 'label' => esc_html__('Social network', 'wp-user-avatar'), |
| 65 | 'field' => 'select', |
| 66 | 'options' => [ |
| 67 | 'facebook' => esc_html__('Facebook', 'wp-user-avatar'), |
| 68 | 'twitter' => esc_html__('Twitter', 'wp-user-avatar'), |
| 69 | 'google' => esc_html__('Google', 'wp-user-avatar'), |
| 70 | 'linkedin' => esc_html__('LinkedIn', 'wp-user-avatar'), |
| 71 | 'vk' => esc_html__('VK', 'wp-user-avatar'), |
| 72 | 'github' => esc_html__('GitHub', 'wp-user-avatar'), |
| 73 | ] |
| 74 | ] |
| 75 | ] |
| 76 | ], |
| 77 | 'link-registration' => [ |
| 78 | 'description' => esc_html__('Link to registration page', 'wp-user-avatar'), |
| 79 | 'shortcode' => 'link-registration', |
| 80 | 'attributes' => [ |
| 81 | 'label' => [ |
| 82 | 'label' => esc_html__('Link label', 'wp-user-avatar'), |
| 83 | 'field' => 'text', |
| 84 | ], |
| 85 | 'id' => [ |
| 86 | 'label' => esc_html__('ID', 'wp-user-avatar'), |
| 87 | 'field' => 'text' |
| 88 | ], |
| 89 | 'class' => [ |
| 90 | 'label' => esc_html__('CSS class', 'wp-user-avatar'), |
| 91 | 'field' => 'text' |
| 92 | ], |
| 93 | 'raw' => [ |
| 94 | 'label' => esc_html__('Check to return URL', 'wp-user-avatar'), |
| 95 | 'field' => 'checkbox' |
| 96 | ], |
| 97 | ] |
| 98 | ], |
| 99 | 'link-login' => [ |
| 100 | 'description' => esc_html__('Link to login page', 'wp-user-avatar'), |
| 101 | 'shortcode' => 'link-login', |
| 102 | 'attributes' => [ |
| 103 | 'label' => [ |
| 104 | 'label' => esc_html__('Link label', 'wp-user-avatar'), |
| 105 | 'field' => 'text', |
| 106 | ], |
| 107 | 'id' => [ |
| 108 | 'label' => esc_html__('ID', 'wp-user-avatar'), |
| 109 | 'field' => 'text' |
| 110 | ], |
| 111 | 'class' => [ |
| 112 | 'label' => esc_html__('CSS class', 'wp-user-avatar'), |
| 113 | 'field' => 'text' |
| 114 | ], |
| 115 | 'raw' => [ |
| 116 | 'label' => esc_html__('Check to return URL', 'wp-user-avatar'), |
| 117 | 'field' => 'checkbox' |
| 118 | ], |
| 119 | ] |
| 120 | ], |
| 121 | 'link-lost-password' => [ |
| 122 | 'description' => esc_html__('Link to password reset page', 'wp-user-avatar'), |
| 123 | 'shortcode' => 'link-lost-password', |
| 124 | 'attributes' => [ |
| 125 | 'label' => [ |
| 126 | 'label' => esc_html__('Link label', 'wp-user-avatar'), |
| 127 | 'field' => 'text', |
| 128 | ], |
| 129 | 'id' => [ |
| 130 | 'label' => esc_html__('ID', 'wp-user-avatar'), |
| 131 | 'field' => 'text' |
| 132 | ], |
| 133 | 'class' => [ |
| 134 | 'label' => esc_html__('CSS class', 'wp-user-avatar'), |
| 135 | 'field' => 'text' |
| 136 | ], |
| 137 | 'raw' => [ |
| 138 | 'label' => esc_html__('Check to return URL', 'wp-user-avatar'), |
| 139 | 'field' => 'checkbox' |
| 140 | ], |
| 141 | ] |
| 142 | ], |
| 143 | 'link-my-account' => [ |
| 144 | 'description' => esc_html__('Link to My Account page', 'wp-user-avatar'), |
| 145 | 'shortcode' => 'link-my-account', |
| 146 | 'attributes' => [ |
| 147 | 'label' => [ |
| 148 | 'label' => esc_html__('Link label', 'wp-user-avatar'), |
| 149 | 'field' => 'text', |
| 150 | ], |
| 151 | 'id' => [ |
| 152 | 'label' => esc_html__('ID', 'wp-user-avatar'), |
| 153 | 'field' => 'text' |
| 154 | ], |
| 155 | 'class' => [ |
| 156 | 'label' => esc_html__('CSS class', 'wp-user-avatar'), |
| 157 | 'field' => 'text' |
| 158 | ], |
| 159 | 'raw' => [ |
| 160 | 'label' => esc_html__('Check to return URL', 'wp-user-avatar'), |
| 161 | 'field' => 'checkbox' |
| 162 | ], |
| 163 | ] |
| 164 | ], |
| 165 | 'link-logout' => [ |
| 166 | 'description' => esc_html__('Link to log out', 'wp-user-avatar'), |
| 167 | 'shortcode' => 'link-logout', |
| 168 | 'attributes' => [ |
| 169 | 'label' => [ |
| 170 | 'label' => esc_html__('Link label', 'wp-user-avatar'), |
| 171 | 'field' => 'text', |
| 172 | ], |
| 173 | 'id' => [ |
| 174 | 'label' => esc_html__('ID', 'wp-user-avatar'), |
| 175 | 'field' => 'text' |
| 176 | ], |
| 177 | 'class' => [ |
| 178 | 'label' => esc_html__('CSS class', 'wp-user-avatar'), |
| 179 | 'field' => 'text' |
| 180 | ], |
| 181 | 'raw' => [ |
| 182 | 'label' => esc_html__('Check to return URL', 'wp-user-avatar'), |
| 183 | 'field' => 'checkbox' |
| 184 | ], |
| 185 | ] |
| 186 | ], |
| 187 | 'facebook-login-url' => [ |
| 188 | 'description' => esc_html__('Link to login with Facebook', 'wp-user-avatar'), |
| 189 | 'shortcode' => 'facebook-login-url' |
| 190 | ], |
| 191 | 'twitter-login-url' => [ |
| 192 | 'description' => esc_html__('Link to login with Twitter', 'wp-user-avatar'), |
| 193 | 'shortcode' => 'twitter-login-url' |
| 194 | ], |
| 195 | 'linkedin-login-url' => [ |
| 196 | 'description' => esc_html__('Link to login with LinkedIn', 'wp-user-avatar'), |
| 197 | 'shortcode' => 'linkedin-login-url' |
| 198 | ], |
| 199 | 'google-login-url' => [ |
| 200 | 'description' => esc_html__('Link to login with Google', 'wp-user-avatar'), |
| 201 | 'shortcode' => 'google-login-url' |
| 202 | ], |
| 203 | 'github-login-url' => [ |
| 204 | 'description' => esc_html__('Link to login with GitHub', 'wp-user-avatar'), |
| 205 | 'shortcode' => 'github-login-url' |
| 206 | ], |
| 207 | 'vk-login-url' => [ |
| 208 | 'description' => esc_html__('Link to login with VK', 'wp-user-avatar'), |
| 209 | 'shortcode' => 'vk-login-url' |
| 210 | ], |
| 211 | ]); |
| 212 | } |
| 213 | |
| 214 | public static function popular_attributes($show_required = false, $remove_value = false, $show_cpf_fields = false) |
| 215 | { |
| 216 | $args = []; |
| 217 | |
| 218 | if ($show_cpf_fields) { |
| 219 | |
| 220 | $custom_fields = PROFILEPRESS_sql::get_profile_custom_fields(); |
| 221 | |
| 222 | $contact_infos = PROFILEPRESS_sql::get_contact_info_fields(); |
| 223 | |
| 224 | $options = ['' => esc_html__('Select...', 'wp-user-avatar')]; |
| 225 | |
| 226 | foreach ($contact_infos as $field_key => $label) { |
| 227 | $options[$field_key] = $label; |
| 228 | } |
| 229 | |
| 230 | foreach ($custom_fields as $custom_field) { |
| 231 | $options[$custom_field['field_key']] = $custom_field['label_name']; |
| 232 | } |
| 233 | |
| 234 | $args['key'] = [ |
| 235 | 'label' => esc_html__('Field key', 'wp-user-avatar'), |
| 236 | 'field' => 'select', |
| 237 | 'options' => $options |
| 238 | ]; |
| 239 | } |
| 240 | |
| 241 | $args = $args + [ |
| 242 | 'id' => [ |
| 243 | 'label' => esc_html__('ID', 'wp-user-avatar'), |
| 244 | 'field' => 'text' |
| 245 | ], |
| 246 | 'placeholder' => [ |
| 247 | 'label' => esc_html__('Placeholder', 'wp-user-avatar'), |
| 248 | 'field' => 'text' |
| 249 | ], |
| 250 | 'class' => [ |
| 251 | 'label' => esc_html__('CSS class', 'wp-user-avatar'), |
| 252 | 'field' => 'text' |
| 253 | ], |
| 254 | 'value' => [ |
| 255 | 'label' => esc_html__('Default field value', 'wp-user-avatar'), |
| 256 | 'field' => 'text' |
| 257 | ], |
| 258 | ]; |
| 259 | |
| 260 | if ($remove_value) { |
| 261 | unset($args['value']); |
| 262 | } |
| 263 | |
| 264 | if ($show_required) { |
| 265 | $args['required'] = [ |
| 266 | 'label' => esc_html__('Mark as required', 'wp-user-avatar'), |
| 267 | 'field' => 'checkbox' |
| 268 | ]; |
| 269 | } |
| 270 | |
| 271 | return $args; |
| 272 | } |
| 273 | |
| 274 | public static function reg_edit_profile_available_shortcodes($type = 'reg') |
| 275 | { |
| 276 | $shortcodes = apply_filters('ppress_reg_edit_profile_available_shortcodes', [ |
| 277 | $type . '-username' => [ |
| 278 | 'description' => esc_html__('Username field', 'wp-user-avatar'), |
| 279 | 'shortcode' => $type . '-username', |
| 280 | 'attributes' => self::popular_attributes() |
| 281 | ], |
| 282 | $type . '-password' => [ |
| 283 | 'description' => esc_html__('Password field', 'wp-user-avatar'), |
| 284 | 'shortcode' => $type . '-password', |
| 285 | 'attributes' => self::popular_attributes() |
| 286 | ], |
| 287 | $type . '-confirm-password' => [ |
| 288 | 'description' => esc_html__('Confirm password field', 'wp-user-avatar'), |
| 289 | 'shortcode' => $type . '-confirm-password', |
| 290 | 'attributes' => self::popular_attributes() |
| 291 | ], |
| 292 | $type . '-password-meter' => [ |
| 293 | 'description' => esc_html__('Password strength meter', 'wp-user-avatar'), |
| 294 | 'shortcode' => $type . '-password-meter', |
| 295 | 'attributes' => [ |
| 296 | 'enforce' => [ |
| 297 | 'label' => esc_html__('Enforce strong password', 'wp-user-avatar'), |
| 298 | 'field' => 'select', |
| 299 | 'options' => ['true' => esc_html__('Yes', 'wp-user-avatar'), 'false' => esc_html__('No', 'wp-user-avatar')] |
| 300 | ], |
| 301 | 'id' => [ |
| 302 | 'label' => esc_html__('ID', 'wp-user-avatar'), |
| 303 | 'field' => 'text' |
| 304 | ], |
| 305 | 'class' => [ |
| 306 | 'label' => esc_html__('CSS class', 'wp-user-avatar'), |
| 307 | 'field' => 'text' |
| 308 | ], |
| 309 | ] |
| 310 | ], |
| 311 | $type . '-email' => [ |
| 312 | 'description' => esc_html__('Email address field', 'wp-user-avatar'), |
| 313 | 'shortcode' => $type . '-email', |
| 314 | 'attributes' => self::popular_attributes() |
| 315 | ], |
| 316 | $type . '-confirm-email' => [ |
| 317 | 'description' => esc_html__('Confirm email address field', 'wp-user-avatar'), |
| 318 | 'shortcode' => $type . '-confirm-email', |
| 319 | 'attributes' => self::popular_attributes() |
| 320 | ], |
| 321 | $type . '-website' => [ |
| 322 | 'description' => esc_html__('Website field', 'wp-user-avatar'), |
| 323 | 'shortcode' => $type . '-website', |
| 324 | 'attributes' => self::popular_attributes(true) |
| 325 | ], |
| 326 | $type . '-nickname' => [ |
| 327 | 'description' => esc_html__('Nickname field', 'wp-user-avatar'), |
| 328 | 'shortcode' => $type . '-nickname', |
| 329 | 'attributes' => self::popular_attributes(true) |
| 330 | ], |
| 331 | $type . '-display-name' => [ |
| 332 | 'description' => esc_html__('Display name field', 'wp-user-avatar'), |
| 333 | 'shortcode' => $type . '-display-name', |
| 334 | 'attributes' => self::popular_attributes(true) |
| 335 | ], |
| 336 | $type . '-first-name' => [ |
| 337 | 'description' => esc_html__('First name field', 'wp-user-avatar'), |
| 338 | 'shortcode' => $type . '-first-name', |
| 339 | 'attributes' => self::popular_attributes(true) |
| 340 | ], |
| 341 | $type . '-last-name' => [ |
| 342 | 'description' => esc_html__('Last name field', 'wp-user-avatar'), |
| 343 | 'shortcode' => $type . '-last-name', |
| 344 | 'attributes' => self::popular_attributes(true) |
| 345 | ], |
| 346 | $type . '-bio' => [ |
| 347 | 'description' => esc_html__('Biographical info field', 'wp-user-avatar'), |
| 348 | 'shortcode' => $type . '-bio', |
| 349 | 'attributes' => self::popular_attributes(true) |
| 350 | ], |
| 351 | $type . '-avatar' => [ |
| 352 | 'description' => esc_html__('Profile picture upload field', 'wp-user-avatar'), |
| 353 | 'shortcode' => $type . '-avatar', |
| 354 | 'attributes' => self::popular_attributes(true, true) |
| 355 | ], |
| 356 | $type . '-cover-image' => [ |
| 357 | 'description' => esc_html__('Profile cover image upload field', 'wp-user-avatar'), |
| 358 | 'shortcode' => $type . '-cover-image', |
| 359 | 'attributes' => self::popular_attributes(true, true) |
| 360 | ], |
| 361 | $type . '-cpf' => [ |
| 362 | 'description' => esc_html__('Custom field', 'wp-user-avatar'), |
| 363 | 'shortcode' => $type . '-cpf', |
| 364 | 'attributes' => self::popular_attributes(true, true, true) |
| 365 | ], |
| 366 | $type . '-submit' => [ |
| 367 | 'description' => esc_html__('Form submit button', 'wp-user-avatar'), |
| 368 | 'shortcode' => $type . '-submit', |
| 369 | 'attributes' => [ |
| 370 | 'value' => [ |
| 371 | 'label' => esc_html__('Button label', 'wp-user-avatar'), |
| 372 | 'field' => 'text' |
| 373 | ], |
| 374 | 'id' => [ |
| 375 | 'label' => esc_html__('ID', 'wp-user-avatar'), |
| 376 | 'field' => 'text' |
| 377 | ], |
| 378 | 'class' => [ |
| 379 | 'label' => esc_html__('CSS class', 'wp-user-avatar'), |
| 380 | 'field' => 'text' |
| 381 | ], |
| 382 | ] |
| 383 | ] |
| 384 | ], $type) + self::global_shortcodes(); |
| 385 | |
| 386 | if ( ! EM::is_enabled(EM::CUSTOM_FIELDS)) { |
| 387 | unset($shortcodes[$type . '-cpf']); |
| 388 | } |
| 389 | |
| 390 | return $shortcodes; |
| 391 | } |
| 392 | |
| 393 | public function shortcode_inserter_script() |
| 394 | { |
| 395 | printf( |
| 396 | '<script type="text/javascript"> |
| 397 | var pp_shortcode_available_shortcodes = %s; |
| 398 | </script>', |
| 399 | json_encode($this->form_shortcodes) |
| 400 | ); |
| 401 | } |
| 402 | |
| 403 | public function shortcode_inserter_modal() |
| 404 | { |
| 405 | ?> |
| 406 | <script type="text/html" id="tmpl-ppress-builder-shortcodes-inserter"> |
| 407 | <div id="ppress-builder-shortcodes-inserter"> |
| 408 | <div class="ppress-builder-shortcodes-inserter-search"> |
| 409 | <input type="text" name="ppress_shortcode_inserter_search" id="ppress_shortcode_inserter_search" placeholder="<?= esc_html__('Search shortcodes', 'wp-user-avatar') ?>"> |
| 410 | </div> |
| 411 | <div class="ppress-builder-shortcode-list-wrapper"> |
| 412 | <?php foreach ($this->form_shortcodes as $key => $shortcode) : ?> |
| 413 | <div class="ppress-builder-shortcode-item-wrap ppclearfix"> |
| 414 | <div class="ppress-builder-shortcode-item"> |
| 415 | <div class="ppress-builder-shortcode-name"><?= $key ?></div> |
| 416 | <div class="ppress-builder-shortcode-desc"><?= $shortcode['description'] ?></div> |
| 417 | </div> |
| 418 | <div class="ppress-builder-shortcode-item-btn"> |
| 419 | <a data-pp-form-shortcode="<?= $key ?>" href="#" class="button"><?= esc_html__('Select', 'wp-user-avatar') ?></a> |
| 420 | </div> |
| 421 | </div> |
| 422 | <?php endforeach; ?> |
| 423 | </div> |
| 424 | </div> |
| 425 | </script> |
| 426 | |
| 427 | <script type="text/javascript"> |
| 428 | |
| 429 | (function ($) { |
| 430 | |
| 431 | var tmpl = wp.template('ppress-builder-shortcodes-inserter'), |
| 432 | |
| 433 | initModal = function () { |
| 434 | return new jBox('Modal', { |
| 435 | id: 'ppress-available-shortcodes-jbox', |
| 436 | closeButton: 'title', |
| 437 | maxHeight: 400, |
| 438 | repositionOnContent: true, |
| 439 | onOpen: onOpen |
| 440 | }); |
| 441 | }, |
| 442 | |
| 443 | init_clipboard = function () { |
| 444 | |
| 445 | var clipboardJS = new ClipboardJS('.ppress-builder-shortcode-btn', { |
| 446 | text: function () { |
| 447 | return $('#ppress-builder-shortcode-preview-field').text(); |
| 448 | } |
| 449 | }); |
| 450 | |
| 451 | clipboardJS.on('success', function () { |
| 452 | |
| 453 | alert('<?= esc_html__('Shortcode copied to clipboard.', 'wp-user-avatar') ?>'); |
| 454 | |
| 455 | setTimeout(function () { |
| 456 | window.ppressShortcodeBuilderMModal.close(); |
| 457 | }, 200); |
| 458 | }); |
| 459 | }, |
| 460 | |
| 461 | onOpen = function () { |
| 462 | |
| 463 | var cache, tmpl = wp.template('ppress-shortcode-inserter-form'); |
| 464 | |
| 465 | $(document).on('click', '#ppress-builder-shortcodes-inserter .ppress-builder-shortcode-item-btn a', function (e) { |
| 466 | e.preventDefault(); |
| 467 | cache = $('#ppress-builder-shortcodes-inserter'), |
| 468 | shortcode = $(this).data('pp-form-shortcode'); |
| 469 | |
| 470 | $('#ppress-shortcode-inserter-form').remove(); |
| 471 | |
| 472 | cache.hide(); |
| 473 | cache.after(tmpl(pp_shortcode_available_shortcodes[shortcode])); |
| 474 | |
| 475 | window.ppressShortcodeBuilderMModal |
| 476 | .setTitle('<span class="dashicons dashicons-arrow-left-alt ppress-shortcode-inserter-back" title="Back"></span>' + shortcode); |
| 477 | |
| 478 | // trigger change to add defaults attribute and their values. looking at you select dropdown. |
| 479 | $('#ppress-available-shortcodes-jbox .ppress-shortcode-inserter-builder-field').change(); |
| 480 | |
| 481 | window.ppressShortcodeBuilderMModal.position(); // recalculate placement in DOM |
| 482 | }); |
| 483 | |
| 484 | $(document).on('click', '#ppress-available-shortcodes-jbox .ppress-shortcode-inserter-back', function (e) { |
| 485 | e.preventDefault(); |
| 486 | |
| 487 | $('#ppress-shortcode-inserter-form').remove(); |
| 488 | |
| 489 | $('#ppress-builder-shortcodes-inserter').show(); |
| 490 | |
| 491 | window.ppressShortcodeBuilderMModal |
| 492 | .setTitle('<?= esc_html__('Available Shortcodes', 'wp-user-avatar');?>'); |
| 493 | }); |
| 494 | }; |
| 495 | |
| 496 | $(document).on('click', '#ppress-available-shortcodes-btn', function () { |
| 497 | |
| 498 | if (typeof window.ppressShortcodeBuilderMModal != 'undefined') { |
| 499 | window.ppressShortcodeBuilderMModal.destroy(); |
| 500 | } |
| 501 | |
| 502 | window.ppressShortcodeBuilderMModal = initModal() |
| 503 | .setTitle('<?= esc_html__('Available Shortcodes', 'wp-user-avatar');?>') |
| 504 | .setContent(tmpl()) |
| 505 | .open(); |
| 506 | }); |
| 507 | |
| 508 | $(document).on('change', '.ppress-shortcode-inserter-builder-field', function () { |
| 509 | var field_value, |
| 510 | selected_shortcode = $('#ppress-shortcode-inserter-form').data('pp-selected-shortcode'), |
| 511 | constructed_shortcode = '[' + selected_shortcode; |
| 512 | |
| 513 | $(this).parents('.ppress-builder-shortcode-attributes-wrap').find('.ppress-shortcode-inserter-builder-field').each(function () { |
| 514 | |
| 515 | if ($(this).attr('type') === 'checkbox') { |
| 516 | if ($(this).prop('checked') === true) { |
| 517 | constructed_shortcode += ' ' + $(this).attr('name'); |
| 518 | } |
| 519 | } else { |
| 520 | |
| 521 | field_value = $(this).val(); |
| 522 | |
| 523 | if (typeof field_value !== "undefined" && field_value !== '' && field_value != '0') { |
| 524 | constructed_shortcode += ' ' + $(this).attr('name') + '="' + field_value + '"'; |
| 525 | } |
| 526 | } |
| 527 | }); |
| 528 | |
| 529 | constructed_shortcode += ']'; |
| 530 | |
| 531 | $('#ppress-builder-shortcode-preview-field').text(constructed_shortcode); |
| 532 | }); |
| 533 | |
| 534 | $(document).on('keyup change', '#ppress_shortcode_inserter_search', function () { |
| 535 | |
| 536 | var term = this.value, |
| 537 | cache = $('.ppress-builder-shortcode-item-wrap'); |
| 538 | |
| 539 | if (term === '') { |
| 540 | cache.show(); |
| 541 | } else { |
| 542 | cache.hide().each(function () { |
| 543 | var content = $(this).text().replace(/\s/g, ''); |
| 544 | |
| 545 | if (new RegExp('(?=.*' + term + ').+', 'i').test(content) === true) { |
| 546 | $(this).show(); |
| 547 | } |
| 548 | }); |
| 549 | } |
| 550 | }); |
| 551 | |
| 552 | init_clipboard(); |
| 553 | |
| 554 | })(jQuery); |
| 555 | |
| 556 | </script> |
| 557 | |
| 558 | <script type="text/html" id="tmpl-ppress-shortcode-inserter-form"> |
| 559 | <div id="ppress-shortcode-inserter-form" data-pp-selected-shortcode="{{data.shortcode}}"> |
| 560 | <div class="ppress-builder-shortcode-desc"> |
| 561 | {{{data.description}}} |
| 562 | </div> |
| 563 | <# if(_.isEmpty(data.attributes) === false) { #> |
| 564 | <div class="ppress-builder-shortcode-attributes-wrap"> |
| 565 | <# _.each(data.attributes, function(value, key) { #> |
| 566 | <div class="ppress-builder-shortcode-attribute-row"> |
| 567 | <div class="ppress-builder-shortcode-attribute-label">{{value.label}}</div> |
| 568 | <div class="ppress-builder-shortcode-attribute-field"> |
| 569 | <# if(value.field == 'text') { placeholder = typeof value.placeholder !== 'undefined' ? value.placeholder : ''; #> |
| 570 | <input class="ppress-shortcode-inserter-builder-field" type="text" name="{{key}}" placeholder="{{placeholder}}"> |
| 571 | <# } #> |
| 572 | |
| 573 | <# if(value.field == 'number') { #> |
| 574 | <input class="ppress-shortcode-inserter-builder-field" type="number" name="{{key}}"> |
| 575 | <# } #> |
| 576 | |
| 577 | <# if(value.field == 'checkbox') { #> |
| 578 | <input class="ppress-shortcode-inserter-builder-field" type="checkbox" name="{{key}}" value="true"> |
| 579 | <# } #> |
| 580 | |
| 581 | <# if(value.field == 'select') { #> |
| 582 | <select class="ppress-shortcode-inserter-builder-field" name="{{key}}"> |
| 583 | |
| 584 | <# _.each(value.options, function(value2, key2) { #> |
| 585 | <option value="{{key2}}">{{value2}}</option> |
| 586 | <# }); #> |
| 587 | </select> |
| 588 | <# } #> |
| 589 | </div> |
| 590 | </div> |
| 591 | <# }); #> |
| 592 | </div> |
| 593 | <# } #> |
| 594 | <div class="ppress-builder-shortcode-clipboard-form"> |
| 595 | <div id="ppress-builder-shortcode-preview-field">[{{data.shortcode}}]</div> |
| 596 | <button class="ppress-builder-shortcode-btn button button-primary button-large"><?= esc_html__('Copy to clipboard', 'wp-user-avatar') ?></button> |
| 597 | </div> |
| 598 | </div> |
| 599 | </script> |
| 600 | <?php |
| 601 | } |
| 602 | } |