PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.5
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.5
3.4.5 3.4.4 3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 All 198 releases
convertkit / admin / section / class-convertkit-admin-section-base.php

class-convertkit-admin-section-base.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.5, at admin/section/class-convertkit-admin-section-base.php

1,011 lines 24.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Settings Base class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * ConvertKit Settings class
11 *
12 * @package ConvertKit
13 * @author ConvertKit
14 */
15 abstract class ConvertKit_Admin_Section_Base {
16
17 /**
18 * Section name
19 *
20 * @var string
21 */
22 public $name;
23
24 /**
25 * Section title
26 *
27 * @var string
28 */
29 public $title;
30
31 /**
32 * Section tab text
33 *
34 * @var string
35 */
36 public $tab_text;
37
38 /**
39 * Options table key
40 *
41 * @var string
42 */
43 public $settings_key;
44
45 /**
46 * Holds the settings class for the section.
47 *
48 * @since 1.9.6
49 *
50 * @var false|ConvertKit_Settings|ConvertKit_ContactForm7_Settings|ConvertKit_Wishlist_Settings|ConvertKit_Settings_Restrict_Content|ConvertKit_Settings_Broadcasts|ConvertKit_Forminator_Settings|ConvertKit_Settings_MCP
51 */
52 public $settings;
53
54 /**
55 * Holds the settings sections for a settings screen.
56 *
57 * @since 2.7.1
58 *
59 * @var array
60 */
61 public $settings_sections = array();
62
63 /**
64 * Holds whether this settings section is for beta functionality.
65 *
66 * @since 2.1.0
67 *
68 * @var bool
69 */
70 public $is_beta = false;
71
72 /**
73 * Holds whether the save button should be disabled e.g. there are no
74 * settings on screen to save.
75 *
76 * @since 2.4.9
77 *
78 * @var bool
79 */
80 public $save_disabled = false;
81
82 /**
83 * Constructor
84 */
85 public function __construct() {
86
87 // If tab text is not defined, use the title for the tab's text.
88 if ( empty( $this->tab_text ) ) {
89 $this->tab_text = $this->title;
90 }
91
92 // Output the Intercom messenger if we're on the Plugin's settings screen.
93 if ( $this->on_settings_screen( $this->name ) ) {
94 add_action( 'admin_footer', array( $this, 'output_intercom' ) );
95 }
96
97 // Register the settings section.
98 $this->register_section();
99
100 }
101
102 /**
103 * Helper method to determine if we're viewing the current settings screen.
104 *
105 * @since 2.5.0
106 *
107 * @param string $tab Current settings tab (general|tools|restrict-content|broadcasts).
108 * @return bool
109 */
110 public function on_settings_screen( $tab ) {
111
112 // Bail if this is an AJAX or Cron request.
113 if ( wp_doing_ajax() || wp_doing_cron() ) {
114 return false;
115 }
116
117 // Bail if we're not on the settings screen.
118 if ( ! filter_has_var( INPUT_GET, 'page' ) ) {
119 return false;
120 }
121 if ( filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) !== '_wp_convertkit_settings' ) {
122 return false;
123 }
124
125 // Define current settings tab.
126 // General screen won't always be loaded with a `tab` parameter.
127 if ( filter_has_var( INPUT_GET, 'tab' ) ) {
128 $current_tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
129 } else {
130 $current_tab = 'general';
131 }
132
133 // Return whether the request is for the current settings tab.
134 return ( $current_tab === $tab );
135
136 }
137
138 /**
139 * Register settings section.
140 */
141 public function register_section() {
142
143 // Don't register a settings section if no settings key is defined.
144 if ( empty( $this->settings_key ) ) {
145 return;
146 }
147
148 // Register settings sections.
149 foreach ( $this->settings_sections as $name => $settings_section ) {
150 // Determine if this settings section needs to be wrapped in its own container.
151 $wrap = array();
152 if ( $settings_section['wrap'] ) {
153 $wrap = array(
154 'before_section' => $this->get_render_container_start(),
155 'after_section' => $this->get_render_container_end(),
156 );
157 }
158
159 add_settings_section(
160 ( $name === 'general' ? $this->name : $this->name . '-' . $name ),
161 $settings_section['title'],
162 $settings_section['callback'],
163 $this->settings_key,
164 $wrap
165 );
166 }
167
168 // Register settings fields.
169 $this->register_fields();
170
171 // Register setting to store data in options table.
172 register_setting(
173 $this->settings_key,
174 $this->settings_key,
175 array( $this, 'sanitize_settings' )
176 );
177
178 }
179
180 /**
181 * Register fields for this section
182 */
183 public function register_fields() {
184 }
185
186 /**
187 * Prints help info for this section
188 */
189 abstract public function print_section_info();
190
191 /**
192 * Returns the URL for the ConvertKit documentation for this setting section.
193 */
194 abstract public function documentation_url();
195
196 /**
197 * Outputs success and/or error notices if required.
198 *
199 * @since 2.0.0
200 */
201 public function maybe_output_notices() {
202
203 // Define notices that might be displayed as a notification.
204 $notices = array();
205
206 /**
207 * Register success and error notices for settings screens.
208 *
209 * @since 2.5.1
210 *
211 * @param array $notices Regsitered success and error notices.
212 * @return array
213 */
214 $notices = apply_filters( 'convertkit_settings_base_register_notices', $notices );
215
216 // Output the verbose error description if supplied (e.g. OAuth).
217 if ( filter_has_var( INPUT_GET, 'error_description' ) ) {
218 $this->output_error( filter_input( INPUT_GET, 'error_description', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) );
219 }
220
221 // Output error notification if defined.
222 if ( filter_has_var( INPUT_GET, 'error' ) ) {
223 $error = filter_input( INPUT_GET, 'error', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
224 if ( array_key_exists( $error, $notices ) ) {
225 $this->output_error( $notices[ $error ] );
226 }
227 }
228
229 // Output success notification if defined.
230 if ( filter_has_var( INPUT_GET, 'success' ) ) {
231 $success = filter_input( INPUT_GET, 'success', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
232 if ( array_key_exists( $success, $notices ) ) {
233 $this->output_success( $notices[ $success ] );
234 }
235 }
236
237 }
238
239 /**
240 * Renders the section
241 */
242 public function render() {
243
244 /**
245 * Performs actions prior to rendering the settings form.
246 *
247 * @since 1.9.6
248 */
249 do_action( 'convertkit_settings_base_render_before' );
250
251 do_settings_sections( $this->settings_key );
252
253 settings_fields( $this->settings_key );
254
255 if ( ! $this->save_disabled ) {
256 submit_button();
257 }
258
259 /**
260 * Performs actions after rendering of the settings form.
261 *
262 * @since 1.9.6
263 */
264 do_action( 'convertkit_settings_base_render_after' );
265
266 }
267
268 /**
269 * Outputs opening .metabox-holder and .postbox container div elements,
270 * used before beginning a setting screen's output.
271 *
272 * @since 2.0.0
273 */
274 public function render_container_start() {
275
276 echo wp_kses(
277 $this->get_render_container_start(),
278 convertkit_kses_allowed_html()
279 );
280
281 }
282
283 /**
284 * Outputs closing .metabox-holder and .postbox container div elements,
285 * used after finishing a setting screen's output.
286 *
287 * @since 2.0.0
288 */
289 public function render_container_end() {
290
291 echo wp_kses(
292 $this->get_render_container_end(),
293 convertkit_kses_allowed_html()
294 );
295
296 }
297
298 /**
299 * Returns opening .metabox-holder and .postbox container div elements,
300 * used before beginning a section of a settings screen output.
301 *
302 * @since 2.7.1
303 */
304 public function get_render_container_start() {
305
306 return '<div class="metabox-holder"><div class="postbox ' . sanitize_html_class( $this->is_beta ? 'convertkit-beta' : '' ) . '">';
307
308 }
309
310 /**
311 * Returns closing .metabox-holder and .postbox container div elements,
312 * used after finishing a section of a settings screen output.
313 *
314 * @since 2.7.1
315 */
316 public function get_render_container_end() {
317
318 return '</div></div>';
319
320 }
321
322 /**
323 * Redirects to the settings screen.
324 *
325 * @since 2.2.9
326 */
327 public function redirect() {
328
329 wp_safe_redirect(
330 add_query_arg(
331 array(
332 'page' => '_wp_convertkit_settings',
333 'tab' => $this->name,
334 ),
335 'options-general.php'
336 )
337 );
338 exit();
339
340 }
341
342 /**
343 * Redirects to the settings screen with an error notice key.
344 *
345 * The function maybe_output_notices() will then output the translated error notice
346 * based on the supplied key.
347 *
348 * @since 2.5.1
349 *
350 * @param string $error The error notice key, registered using `convertkit_settings_base_register_notices`.
351 */
352 public function redirect_with_error_notice( $error ) {
353
354 wp_safe_redirect(
355 add_query_arg(
356 array(
357 'page' => '_wp_convertkit_settings',
358 'tab' => $this->name,
359 'error' => $error,
360 ),
361 'options-general.php'
362 )
363 );
364 exit();
365
366 }
367
368 /**
369 * Redirects to the settings screen with the verbose error description.
370 *
371 * @since 2.5.1
372 *
373 * @param string $error_description The error description.
374 */
375 public function redirect_with_error_description( $error_description ) {
376
377 wp_safe_redirect(
378 add_query_arg(
379 array(
380 'page' => '_wp_convertkit_settings',
381 'tab' => $this->name,
382 'error_description' => $error_description,
383 ),
384 'options-general.php'
385 )
386 );
387 exit();
388
389 }
390
391 /**
392 * Redirects to the settings screen with a success notice key.
393 *
394 * The function maybe_output_notices() will then output the translated success notice
395 * based on the supplied key.
396 *
397 * @since 2.5.1
398 *
399 * @param string $success The success notice key, registered using `convertkit_settings_base_register_notices`.
400 */
401 public function redirect_with_success_notice( $success ) {
402
403 wp_safe_redirect(
404 add_query_arg(
405 array(
406 'page' => '_wp_convertkit_settings',
407 'tab' => $this->name,
408 'success' => $success,
409 ),
410 'options-general.php'
411 )
412 );
413 exit();
414
415 }
416
417 /**
418 * Outputs the given success message in an inline notice.
419 *
420 * @since 2.0.0
421 *
422 * @param string $success_message Success Message.
423 */
424 public function output_success( $success_message ) {
425
426 ?>
427 <div class="notice notice-success is-dismissible">
428 <p>
429 <?php echo esc_attr( $success_message ); ?>
430 </p>
431 </div>
432 <?php
433
434 }
435
436 /**
437 * Outputs the given warning message in an inline notice, permitting links
438 * so the message can tell the user where to go.
439 *
440 * @since 3.4.5
441 *
442 * @param string $warning_message Warning Message.
443 * @param string $css_class Additional CSS class for the notice.
444 */
445 public function output_warning( $warning_message, $css_class = '' ) {
446
447 ?>
448 <div class="notice notice-warning <?php echo esc_attr( sanitize_html_class( $css_class ) ); ?>">
449 <p>
450 <?php
451 echo wp_kses(
452 $warning_message,
453 array(
454 'a' => array(
455 'href' => array(),
456 'target' => array(),
457 ),
458 'code' => array(),
459 'strong' => array(),
460 )
461 );
462 ?>
463 </p>
464 </div>
465 <?php
466
467 }
468
469 /**
470 * Outputs the given error message in an inline notice.
471 *
472 * @since 1.9.6
473 *
474 * @param string $error_message Error Message.
475 */
476 public function output_error( $error_message ) {
477
478 ?>
479 <div class="notice notice-error is-dismissible">
480 <p>
481 <?php echo esc_attr( $error_message ); ?>
482 </p>
483 </div>
484 <?php
485
486 }
487
488 /**
489 * Returns a masked value.
490 *
491 * @since 1.9.6
492 *
493 * @param string $value Value.
494 * @param bool|string $description Description.
495 * @return string Masked Value
496 */
497 public function get_masked_value( $value, $description = false ) {
498
499 $html = sprintf(
500 '<code>%s</code>',
501 str_repeat( '*', strlen( $value ) - 4 ) . substr( $value, - 4 )
502 );
503
504 if ( $description ) {
505 $html .= $this->get_description( $description );
506 }
507
508 return $html;
509
510 }
511
512 /**
513 * Outputs a masked value.
514 *
515 * @since 2.8.5
516 *
517 * @param string $value Value.
518 * @param bool|string $description Description.
519 */
520 public function output_masked_value( $value, $description = false ) {
521
522 $html = sprintf(
523 '<code>%s</code>',
524 str_repeat( '*', strlen( $value ) - 4 ) . substr( $value, - 4 )
525 );
526
527 if ( $description ) {
528 $html .= $this->get_description( $description );
529 }
530
531 echo wp_kses(
532 $html,
533 convertkit_kses_allowed_html()
534 );
535
536 }
537
538 /**
539 * Returns a text field.
540 *
541 * @since 1.9.6
542 *
543 * @param string $name Name.
544 * @param string $value Value.
545 * @param bool|string|array $description Description (false|string|array).
546 * @param bool|array $css_classes CSS Classes (false|array).
547 * @return string HTML Field
548 */
549 public function get_text_field( $name, $value = '', $description = false, $css_classes = false ) {
550
551 $html = sprintf(
552 '<input type="text" class="%s" id="%s" name="%s[%s]" value="%s" />',
553 ( is_array( $css_classes ) ? implode( ' ', $css_classes ) : 'regular-text' ),
554 $name,
555 $this->settings_key,
556 $name,
557 $value
558 );
559
560 return $html . $this->get_description( $description );
561
562 }
563
564 /**
565 * Outputs a text field.
566 *
567 * @since 2.8.5
568 *
569 * @param string $name Name.
570 * @param string $value Value.
571 * @param bool|string|array $description Description (false|string|array).
572 * @param bool|array $css_classes CSS Classes (false|array).
573 */
574 public function output_text_field( $name, $value = '', $description = false, $css_classes = false ) {
575
576 echo wp_kses(
577 $this->get_text_field( $name, $value, $description, $css_classes ),
578 convertkit_kses_allowed_html()
579 );
580
581 }
582
583 /**
584 * Returns a number field.
585 *
586 * @since 2.6.1
587 *
588 * @param string $name Name.
589 * @param string $value Value.
590 * @param int|float $min `min` attribute value.
591 * @param int|float $max `max` attribute value.
592 * @param int|float $step `step` attribute value.
593 * @param bool|string|array $description Description (false|string|array).
594 * @param bool|array $css_classes CSS Classes (false|array).
595 * @return string HTML Field
596 */
597 public function get_number_field( $name, $value = '', $min = 0, $max = 9999, $step = 1, $description = false, $css_classes = false ) {
598
599 $html = sprintf(
600 '<input type="number" class="%s" id="%s" name="%s[%s]" value="%s" min="%s" max="%s" step="%s" />',
601 ( is_array( $css_classes ) ? implode( ' ', $css_classes ) : 'small-text' ),
602 $name,
603 $this->settings_key,
604 $name,
605 $value,
606 $min,
607 $max,
608 $step
609 );
610
611 return $html . $this->get_description( $description );
612
613 }
614
615 /**
616 * Outputs a number field.
617 *
618 * @since 2.8.5
619 *
620 * @param string $name Name.
621 * @param string $value Value.
622 * @param int|float $min `min` attribute value.
623 * @param int|float $max `max` attribute value.
624 * @param int|float $step `step` attribute value.
625 * @param bool|string|array $description Description (false|string|array).
626 * @param bool|array $css_classes CSS Classes (false|array).
627 */
628 public function output_number_field( $name, $value = '', $min = 0, $max = 9999, $step = 1, $description = false, $css_classes = false ) {
629
630 echo wp_kses(
631 $this->get_number_field( $name, $value, $min, $max, $step, $description, $css_classes ),
632 convertkit_kses_allowed_html()
633 );
634
635 }
636
637 /**
638 * Returns a textarea field.
639 *
640 * @since 2.3.5
641 *
642 * @param string $name Name.
643 * @param string $value Value.
644 * @param bool|string|array $description Description (false|string|array).
645 * @param bool|array $css_classes CSS Classes (false|array).
646 * @return string HTML Field
647 */
648 public function get_textarea_field( $name, $value = '', $description = false, $css_classes = false ) {
649
650 $html = sprintf(
651 '<textarea class="%s" id="%s" name="%s[%s]">%s</textarea>',
652 ( is_array( $css_classes ) ? implode( ' ', $css_classes ) : 'regular-text' ),
653 $name,
654 $this->settings_key,
655 $name,
656 $value
657 );
658
659 return $html . $this->get_description( $description );
660
661 }
662
663 /**
664 * Outputs a textarea field.
665 *
666 * @since 2.8.5
667 *
668 * @param string $name Name.
669 * @param string $value Value.
670 * @param bool|string|array $description Description (false|string|array).
671 * @param bool|array $css_classes CSS Classes (false|array).
672 */
673 public function output_textarea_field( $name, $value = '', $description = false, $css_classes = false ) {
674
675 echo wp_kses(
676 $this->get_textarea_field( $name, $value, $description, $css_classes ),
677 convertkit_kses_allowed_html()
678 );
679
680 }
681
682 /**
683 * Returns a date field.
684 *
685 * @since 2.2.8
686 *
687 * @param string $name Name.
688 * @param string $value Value.
689 * @param bool|string|array $description Description (false|string|array).
690 * @param bool|array $css_classes CSS Classes (false|array).
691 * @return string HTML Field
692 */
693 public function get_date_field( $name, $value = '', $description = false, $css_classes = false ) {
694
695 $html = sprintf(
696 '<input type="date" class="%s" id="%s" name="%s[%s]" value="%s" />',
697 ( is_array( $css_classes ) ? implode( ' ', $css_classes ) : 'regular-text' ),
698 $name,
699 $this->settings_key,
700 $name,
701 $value
702 );
703
704 return $html . $this->get_description( $description );
705
706 }
707
708 /**
709 * Outputs a date field.
710 *
711 * @since 2.8.5
712 *
713 * @param string $name Name.
714 * @param string $value Value.
715 * @param bool|string|array $description Description (false|string|array).
716 * @param bool|array $css_classes CSS Classes (false|array).
717 */
718 public function output_date_field( $name, $value = '', $description = false, $css_classes = false ) {
719
720 echo wp_kses(
721 $this->get_date_field( $name, $value, $description, $css_classes ),
722 convertkit_kses_allowed_html()
723 );
724
725 }
726
727 /**
728 * Returns a select dropdown field.
729 *
730 * @since 1.9.6
731 *
732 * @param string $name Name.
733 * @param string $value Value.
734 * @param array $options Options / Choices.
735 * @param bool|string $description Description.
736 * @param bool|array $css_classes <select> CSS class(es).
737 * @param bool|array $attributes <select> attributes.
738 * @return string HTML Select Field
739 */
740 public function get_select_field( $name, $value = '', $options = array(), $description = false, $css_classes = false, $attributes = false ) {
741
742 // Build opening <select> tag.
743 $html = sprintf(
744 '<select id="%s" name="%s[%s]" class="%s" size="1" %s>',
745 $this->settings_key . '_' . $name,
746 $this->settings_key,
747 $name,
748 ( is_array( $css_classes ) ? implode( ' ', $css_classes ) : '' ),
749 ( is_array( $attributes ) ? $this->array_to_attributes( $attributes ) : '' )
750 );
751
752 // Build <option> tags.
753 foreach ( $options as $option => $label ) {
754 $html .= sprintf(
755 '<option value="%s"%s>%s</option>',
756 $option,
757 selected( $value, $option, false ),
758 $label
759 );
760 }
761
762 // Close <select>.
763 $html .= '</select>';
764
765 // If no description exists, just return the select field.
766 if ( empty( $description ) ) {
767 return $html;
768 }
769
770 // Return select field with description appended to it.
771 return $html . $this->get_description( $description );
772
773 }
774
775 /**
776 * Outputs a select dropdown field.
777 *
778 * @since 2.8.5
779 *
780 * @param string $name Name.
781 * @param string $value Value.
782 * @param array $options Options / Choices.
783 * @param bool|string $description Description.
784 * @param bool|array $css_classes <select> CSS class(es).
785 * @param bool|array $attributes <select> attributes.
786 */
787 public function output_select_field( $name, $value = '', $options = array(), $description = false, $css_classes = false, $attributes = false ) {
788
789 echo wp_kses(
790 $this->get_select_field( $name, $value, $options, $description, $css_classes, $attributes ),
791 convertkit_kses_allowed_html()
792 );
793
794 }
795
796 /**
797 * Returns a checkbox field.
798 *
799 * @since 1.9.6
800 *
801 * @param string $name Name.
802 * @param string $value Value.
803 * @param bool $checked Should checkbox be checked/ticked.
804 * @param bool|string $label Label.
805 * @param bool|string|array $description Description.
806 * @param bool|array $css_classes CSS class(es).
807 * @return string HTML Checkbox
808 */
809 public function get_checkbox_field( $name, $value, $checked = false, $label = '', $description = false, $css_classes = false ) {
810
811 $html = '';
812
813 if ( $label ) {
814 $html .= sprintf(
815 '<label for="%s">',
816 $name
817 );
818 }
819
820 $html .= sprintf(
821 '<input type="checkbox" id="%s" name="%s[%s]" class="%s" value="%s" %s />',
822 $name,
823 $this->settings_key,
824 $name,
825 ( is_array( $css_classes ) ? implode( ' ', $css_classes ) : '' ),
826 $value,
827 ( $checked ? ' checked' : '' )
828 );
829
830 if ( $label ) {
831 $html .= sprintf(
832 '%s</label>',
833 $label
834 );
835 }
836
837 // If no description exists, just return the field.
838 if ( empty( $description ) ) {
839 return $html;
840 }
841
842 // Return field with description appended to it.
843 return $html . $this->get_description( $description );
844
845 }
846
847 /**
848 * Outputs a checkbox field.
849 *
850 * @since 2.8.5
851 *
852 * @param string $name Name.
853 * @param string $value Value.
854 * @param bool $checked Should checkbox be checked/ticked.
855 * @param bool|string $label Label.
856 * @param bool|string|array $description Description.
857 * @param bool|array $css_classes CSS class(es).
858 */
859 public function output_checkbox_field( $name, $value, $checked = false, $label = '', $description = false, $css_classes = false ) {
860
861 echo wp_kses(
862 $this->get_checkbox_field( $name, $value, $checked, $label, $description, $css_classes ),
863 convertkit_kses_allowed_html()
864 );
865
866 }
867
868 /**
869 * Returns a link button.
870 *
871 * @since 2.8.5
872 *
873 * @param string $url URL.
874 * @param string $label Button Label.
875 * @param bool|array $css_classes CSS class(es).
876 * @return string HTML Link Button
877 */
878 public function get_link_button( $url, $label, $css_classes = false ) {
879
880 return sprintf(
881 '<a href="%s" class="button %s">%s</a>',
882 esc_url( $url ),
883 ( is_array( $css_classes ) ? implode( ' ', $css_classes ) : '' ),
884 esc_html( $label )
885 );
886
887 }
888
889 /**
890 * Outputs a link button.
891 *
892 * @since 2.8.5
893 *
894 * @param string $url URL.
895 * @param string $label Button Label.
896 * @param bool|array $css_classes CSS class(es).
897 */
898 public function output_link_button( $url, $label, $css_classes = false ) {
899
900 echo wp_kses(
901 $this->get_link_button( $url, $label, $css_classes ),
902 convertkit_kses_allowed_html()
903 );
904
905 }
906
907 /**
908 * Outputs the given code in a code block, with a button to copy the code
909 * to the clipboard.
910 *
911 * Requires the settings.css and ui.js resources to be enqueued on the screen
912 * calling this method.
913 *
914 * @since 3.4.1
915 *
916 * @param string $code Code to display.
917 * @param string $id Optional ID attribute to assign to the code element.
918 */
919 public function output_code_block( $code, $id = '' ) {
920
921 ?>
922 <div class="kit-code">
923 <pre><code<?php echo ( ! empty( $id ) ? ' id="' . esc_attr( $id ) . '"' : '' ); ?>><?php echo esc_html( $code ); ?></code></pre>
924 <button type="button" class="button button-secondary kit-code-copy"><?php esc_html_e( 'Copy', 'convertkit' ); ?></button>
925 </div>
926 <?php
927
928 }
929
930 /**
931 * Returns the given text wrapped in a paragraph with the description class.
932 *
933 * @since 1.9.6
934 *
935 * @param bool|string|array $description Description.
936 * @return string HTML Description
937 */
938 public function get_description( $description ) {
939
940 // Return blank string if no description specified.
941 if ( ! $description ) {
942 return '';
943 }
944
945 // Return description in paragraph if a string.
946 if ( ! is_array( $description ) ) {
947 return '<p class="description">' . $description . '</p>';
948 }
949
950 // Return description lines in a paragraph, using breaklines for each description entry in the array.
951 return '<p class="description">' . implode( '<br />', $description ) . '</p>';
952
953 }
954
955 /**
956 * Converts the given key/value array pairs into a HTML attribute="value" string.
957 *
958 * @since 1.9.8.5
959 *
960 * @param array $attributes_array Attributes.
961 * @return string HTML attributes string
962 */
963 private function array_to_attributes( $attributes_array ) {
964
965 $attributes = '';
966 foreach ( $attributes_array as $key => $value ) {
967 $attributes .= esc_attr( $key ) . '="' . esc_attr( $value ) . '" ';
968 }
969
970 return trim( $attributes );
971
972 }
973
974 /**
975 * Sanitizes the settings prior to being saved.
976 *
977 * @since 1.9.6
978 *
979 * @param array $settings Submitted Settings Fields.
980 * @return array Sanitized Settings with Defaults
981 */
982 public function sanitize_settings( $settings ) {
983
984 // Merge settings with defaults.
985 $updated_settings = wp_parse_args( $settings, $this->settings->get_defaults() );
986
987 /**
988 * Performs actions prior to settings being saved.
989 *
990 * @since 2.2.8
991 */
992 do_action( 'convertkit_settings_base_sanitize_settings', $this->name, $updated_settings );
993
994 // Return settings to be saved.
995 return $updated_settings;
996
997 }
998
999 /**
1000 * Outputs the Intercom help widget in the footer of the Plugin's settings screens.
1001 *
1002 * @since 2.7.2
1003 */
1004 public function output_intercom() {
1005
1006 convertkit_output_intercom_messenger();
1007
1008 }
1009
1010 }
1011