-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathclass-convertkit-admin-section-general.php
More file actions
1151 lines (997 loc) · 33.7 KB
/
class-convertkit-admin-section-general.php
File metadata and controls
1151 lines (997 loc) · 33.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* ConvertKit Settings General class.
*
* @package ConvertKit
* @author ConvertKit
*/
/**
* Registers General Settings that can be edited at Settings > Kit > General.
*
* @package ConvertKit
* @author ConvertKit
*/
class ConvertKit_Admin_Section_General extends ConvertKit_Admin_Section_Base {
/**
* Holds the API instance.
*
* @since 1.9.6
*
* @var ConvertKit_API_V4
*/
private $api;
/**
* Holds the ConvertKit Account Name.
*
* @since 1.9.6
*
* @var bool|WP_Error|array
*/
private $account = false;
/**
* Holds the ConvertKit Forms Resource.
*
* @since 1.9.6
*
* @var bool|ConvertKit_Resource_Forms
*/
private $forms = false;
/**
* Constructor.
*/
public function __construct() {
// Define the class that reads/writes settings.
$this->settings = new ConvertKit_Settings();
// Define the settings key.
$this->settings_key = $this->settings::SETTINGS_NAME;
// Define the programmatic name, Title and Tab Text.
$this->name = 'general';
$this->title = __( 'General Settings', 'convertkit' );
$this->tab_text = __( 'General', 'convertkit' );
// Define settings sections.
$this->settings_sections = array(
'general' => array(
'title' => $this->title,
'callback' => array( $this, 'print_section_info' ),
'wrap' => true,
),
'site-wide' => array(
'title' => __( 'Non-inline Forms', 'convertkit' ),
'callback' => array( $this, 'print_section_info_site_wide' ),
'wrap' => true,
),
'recaptcha' => array(
'title' => __( 'reCAPTCHA', 'convertkit' ),
'callback' => array( $this, 'print_section_info_recaptcha' ),
'wrap' => true,
),
'advanced' => array(
'title' => __( 'Advanced', 'convertkit' ),
'callback' => array( $this, 'print_section_info_advanced' ),
'wrap' => true,
),
);
$this->maybe_disconnect();
// Register and maybe output notices for this settings screen, and the Intercom messenger.
if ( $this->on_settings_screen( $this->name ) ) {
add_filter( 'convertkit_settings_base_register_notices', array( $this, 'register_notices' ) );
add_action( 'convertkit_settings_base_render_before', array( $this, 'maybe_output_notices' ) );
}
// Enqueue scripts and CSS.
add_action( 'convertkit_admin_settings_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'convertkit_admin_settings_enqueue_styles', array( $this, 'enqueue_styles' ) );
parent::__construct();
$this->check_credentials();
}
/**
* Registers success and error notices for the General screen, to be displayed
* depending on the action.
*
* @since 2.5.1
*
* @param array $notices Regsitered success and error notices.
* @return array
*/
public function register_notices( $notices ) {
return array_merge(
$notices,
array(
'oauth2_success' => __( 'Successfully authorized with Kit.', 'convertkit' ),
)
);
}
/**
* Test the access token, if it exists.
* If the access token has been revoked or is invalid, remove it from the settings now.
*
* @since 2.5.0
*/
private function check_credentials() {
// Bail if we're not on the settings screen.
if ( ! $this->on_settings_screen( $this->name ) ) {
return;
}
// Bail if no access and refresh token exist.
if ( ! $this->settings->has_access_and_refresh_token() ) {
// Redirect to General screen, which will now show the ConvertKit_Admin_Section_OAuth screen, because
// the Plugin has no access token.
wp_safe_redirect(
add_query_arg(
array(
'page' => $this->settings_key,
),
'options-general.php'
)
);
exit();
}
// Initialize the API.
$this->api = new ConvertKit_API_V4(
CONVERTKIT_OAUTH_CLIENT_ID,
CONVERTKIT_OAUTH_CLIENT_REDIRECT_URI,
$this->settings->get_access_token(),
$this->settings->get_refresh_token(),
$this->settings->debug_enabled(),
'settings'
);
// Get Account Details, which we'll use in account_name_callback(), but also lets us test
// whether the API credentials are valid.
$this->account = $this->api->get_account();
// If the request succeeded, no need to perform further actions.
if ( ! is_wp_error( $this->account ) ) {
return;
}
// Depending on the error code, display an error notice in the settings screen until the user
// fixes the problem.
$this->output_error( $this->account->get_error_message() );
}
/**
* Deletes the OAuth Access Token, Refresh Token and Expiry from the Plugin's settings, if the user
* clicked the Disconnect button.
*
* @since 2.5.0
*/
private function maybe_disconnect() {
// Bail if we're not on the settings screen.
if ( ! $this->on_settings_screen( $this->name ) ) {
return;
}
// Bail if nonce verification fails.
if ( ! isset( $_REQUEST['_convertkit_settings_oauth_disconnect'] ) ) {
return;
}
if ( ! wp_verify_nonce( sanitize_key( $_REQUEST['_convertkit_settings_oauth_disconnect'] ), 'convertkit-oauth-disconnect' ) ) {
return;
}
// Get Settings class.
$settings = new ConvertKit_Settings();
// Setup API.
$api = new ConvertKit_API_V4(
CONVERTKIT_OAUTH_CLIENT_ID,
CONVERTKIT_OAUTH_CLIENT_REDIRECT_URI,
$settings->get_access_token(),
$settings->get_refresh_token(),
$settings->debug_enabled(),
'settings'
);
// Check that we're using the Kit WordPress Libraries 2.1.4 or higher.
// If another Kit Plugin is active and out of date, its libraries might
// be loaded that don't have this method.
if ( ! method_exists( $api, 'revoke_tokens' ) ) { // @phpstan-ignore-line Older WordPress Libraries won't have this function.
$this->output_error( __( 'The Kit WordPress Libraries is missing the `revoke_tokens` method. Please update all Kit WordPress Plugins to their latest versions, and click Disconnect again.', 'convertkit' ) );
return;
}
// Revoke Access and Refresh Tokens.
// See convertkit_delete_credentials() method in functions.php, which is called
// by the `convertkit_api_revoke_tokens` action and deletes credentials from the Plugin's settings.
$result = $api->revoke_tokens();
if ( is_wp_error( $result ) ) {
$this->output_error( $result->get_error_message() );
return;
}
// Delete cached resources.
$creator_network = new ConvertKit_Resource_Creator_Network_Recommendations();
$custom_fields = new ConvertKit_Resource_Custom_Fields();
$forms = new ConvertKit_Resource_Forms();
$landing_pages = new ConvertKit_Resource_Landing_Pages();
$posts = new ConvertKit_Resource_Posts();
$products = new ConvertKit_Resource_Products();
$sequences = new ConvertKit_Resource_Sequences();
$tags = new ConvertKit_Resource_Tags();
$creator_network->delete();
$custom_fields->delete();
$forms->delete();
$landing_pages->delete();
$posts->delete();
$products->delete();
$sequences->delete();
$tags->delete();
// Redirect to General screen, which will now show the ConvertKit_Settings_OAuth screen, because
// the Plugin has no access token.
wp_safe_redirect(
add_query_arg(
array(
'page' => $this->settings_key,
),
'options-general.php'
)
);
exit();
}
/**
* Enqueues scripts for the Settings > General screen.
*
* @since 2.2.4
*
* @param string $section Settings section / tab (general|tools|restrict-content).
*/
public function enqueue_scripts( $section ) {
// Bail if we're not on the general section.
if ( $section !== $this->name ) {
return;
}
// Enqueue Select2 JS.
convertkit_select2_enqueue_scripts();
// Enqueue JS.
wp_enqueue_script( 'convertkit-admin-preview-output', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/preview-output.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
wp_enqueue_script( 'convertkit-admin-settings-conditional-display', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/settings-conditional-display.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
}
/**
* Enqueues styles for the Settings > General screen.
*
* @since 2.2.4
*
* @param string $section Settings section / tab (general|tools|restrict-content).
*/
public function enqueue_styles( $section ) {
// Bail if we're not on the general section.
if ( $section !== $this->name ) {
return;
}
// Enqueue Select2 CSS.
convertkit_select2_enqueue_styles();
}
/**
* Registers settings fields for this section.
*/
public function register_fields() {
// Initialize resource classes.
$this->maybe_initialize_and_refresh_resources();
add_settings_field(
'account_name',
__( 'Account Name', 'convertkit' ),
array( $this, 'account_name_callback' ),
$this->settings_key,
$this->name
);
// Initialize resource classes and perform a refresh if this hasn't yet been done.
foreach ( convertkit_get_supported_post_types() as $supported_post_type ) {
// Get Post Type's Label.
$post_type = get_post_type_object( $supported_post_type );
// Skip if the Post Type doesn't exist.
if ( ! $post_type ) {
continue;
}
// Add Settings Fields.
add_settings_field(
$supported_post_type . '_form',
sprintf(
/* translators: Post Type Name, plural */
__( 'Default Form (%s)', 'convertkit' ),
$post_type->label
),
array( $this, 'default_form_callback' ),
$this->settings_key,
$this->name,
array(
'label_for' => '_wp_convertkit_settings_' . $supported_post_type . '_form',
'post_type' => $supported_post_type,
'post_type_object' => $post_type,
)
);
if ( $this->forms->exist() ) {
add_settings_field(
$supported_post_type . '_form_position',
sprintf(
/* translators: Post Type Name, plural */
__( 'Form Position (%s)', 'convertkit' ),
$post_type->label
),
array( $this, 'default_form_position_callback' ),
$this->settings_key,
$this->name,
array(
'label_for' => '_wp_convertkit_settings_' . $supported_post_type . '_form_position',
'post_type' => $supported_post_type,
'post_type_object' => $post_type,
)
);
add_settings_field(
$supported_post_type . '_form_position_element',
'',
array( $this, 'default_form_position_element_callback' ),
$this->settings_key,
$this->name,
array(
'label_for' => '_wp_convertkit_settings_' . $supported_post_type . '_form_position_element',
'post_type' => $supported_post_type,
'post_type_object' => $post_type,
)
);
}
}
// Site Wide.
add_settings_field(
'non_inline_form',
__( 'Default Forms (Site Wide)', 'convertkit' ),
array( $this, 'non_inline_form_callback' ),
$this->settings_key,
$this->name . '-site-wide',
array(
'label_for' => 'non_inline_form',
)
);
add_settings_field(
'non_inline_form_honor_none_setting',
__( 'Behavior', 'convertkit' ),
array( $this, 'non_inline_form_honor_none_setting_callback' ),
$this->settings_key,
$this->name . '-site-wide',
array(
'label_for' => 'non_inline_form_honor_none_setting',
)
);
// Non-inline Form Limit per Session.
add_settings_field(
'non_inline_form_limit_per_session',
__( 'Limit Display', 'convertkit' ),
array( $this, 'non_inline_form_limit_per_session_callback' ),
$this->settings_key,
$this->name . '-site-wide',
array(
'label_for' => 'non_inline_form_limit_per_session',
)
);
// reCAPTCHA.
add_settings_field(
'recaptcha_site_key',
__( 'reCAPTCHA: Site Key', 'convertkit' ),
array( $this, 'recaptcha_site_key_callback' ),
$this->settings_key,
$this->name . '-recaptcha',
array(
'label_for' => 'recaptcha_site_key',
'description' => array(
__( 'Enter your Google reCAPTCHA v3 Site Key. When specified, this will be used to reduce spam signups.', 'convertkit' ),
),
)
);
add_settings_field(
'recaptcha_secret_key',
__( 'reCAPTCHA: Secret Key', 'convertkit' ),
array( $this, 'recaptcha_secret_key_callback' ),
$this->settings_key,
$this->name . '-recaptcha',
array(
'label_for' => 'recaptcha_secret_key',
'description' => array(
__( 'Enter your Google reCAPTCHA v3 Secret Key. When specified, this will be used to reduce spam signups.', 'convertkit' ),
),
)
);
add_settings_field(
'recaptcha_minimum_score',
__( 'reCAPTCHA: Minimum Score', 'convertkit' ),
array( $this, 'recaptcha_minimum_score_callback' ),
$this->settings_key,
$this->name . '-recaptcha',
array(
'label_for' => 'recaptcha_minimum_score',
'min' => 0,
'max' => 1,
'step' => 0.01,
'description' => array(
__( 'Enter the minimum threshold for a subscriber to pass Google reCAPTCHA. A higher number will reduce spam signups (1.0 is very likely a good interaction, 0.0 is very likely a bot).', 'convertkit' ),
),
)
);
// Advanced.
add_settings_field(
'debug',
__( 'Debug', 'convertkit' ),
array( $this, 'debug_callback' ),
$this->settings_key,
$this->name . '-advanced',
array(
'label_for' => 'debug',
)
);
add_settings_field(
'no_scripts',
__( 'Disable JavaScript', 'convertkit' ),
array( $this, 'no_scripts_callback' ),
$this->settings_key,
$this->name . '-advanced',
array(
'label_for' => 'no_scripts',
)
);
add_settings_field(
'no_css',
__( 'Disable CSS', 'convertkit' ),
array( $this, 'no_css_callback' ),
$this->settings_key,
$this->name . '-advanced',
array(
'label_for' => 'no_css',
)
);
add_settings_field(
'no_add_new_button',
__( 'Disable Add New Landing Page / Member Content Button', 'convertkit' ),
array( $this, 'no_add_new_button_callback' ),
$this->settings_key,
$this->name . '-advanced',
array(
'label_for' => 'no_add_new_button',
)
);
add_settings_field(
'usage_tracking',
__( 'Usage Tracking', 'convertkit' ),
array( $this, 'usage_tracking_callback' ),
$this->settings_key,
$this->name . '-advanced',
array(
'label_for' => 'usage_tracking',
)
);
}
/**
* Prints help info for this section
*/
public function print_section_info() {
?>
<p><?php esc_html_e( 'Forms can be embedded before and/or after (or following number of elements) on every post or page (in single view only) across your site by using the settings below.', 'convertkit' ); ?>
<p><?php esc_html_e( 'You can also configure non-inline forms to display site wide under the "Non-inline Forms" section below.', 'convertkit' ); ?></p>
<p><?php esc_html_e( 'These default form settings can be overridden using the Kit meta box on a page or post\'s edit screen. For site wide non-inline forms to respect when a post/page has forms disabled, enable the "Behavior" option in the "Non-inline Forms" section below.', 'convertkit' ); ?></p>
<p>
<?php
printf(
/* translators: [convertkit] shortcode, wrapped in <code> tags */
esc_html__( 'The default form can be inserted into the middle of post or page content by using either the %s shortcode or block.', 'convertkit' ),
'<code>[convertkit]</code>'
);
?>
</p>
<?php
}
/**
* Prints help info for the site wide section of the settings screen.
*
* @since 2.7.3
*/
public function print_section_info_site_wide() {
?>
<p class="description"><?php esc_html_e( 'Defines non-inline forms to display site wide, and if these forms should display on Pages / Posts that have the Kit Form setting = None.', 'convertkit' ); ?></p>
<?php
}
/**
* Prints help info for the recaptcha section of the settings screen.
*
* @since 3.0.0
*/
public function print_section_info_recaptcha() {
?>
<p class="description"><?php esc_html_e( 'Configure reCAPTCHA to protect the Member Content signup form and Form Builder block from spam and abuse.', 'convertkit' ); ?></p>
<?php
}
/**
* Prints help info for the advanced section of the settings screen.
*
* @since 2.7.1
*/
public function print_section_info_advanced() {
?>
<p class="description"><?php esc_html_e( 'Defines advanced configuration settings, usually when working with support or needing to disable JS or CSS.', 'convertkit' ); ?></p>
<?php
}
/**
* Returns the URL for the ConvertKit documentation for this setting section.
*
* @since 2.0.8
*
* @return string Documentation URL.
*/
public function documentation_url() {
return 'https://help.kit.com/en/articles/2502591-how-to-set-up-the-kit-plugin-on-your-wordpress-website';
}
/**
* Outputs the Account Name
*
* @since 1.9.6
*/
public function account_name_callback() {
// Output Account Name.
// If account is an error, check_credentials() will output an error above the settings section.
$html = sprintf(
'<p>%s</p>',
! is_wp_error( $this->account ) && isset( $this->account['account']['name'] ) ? esc_attr( $this->account['account']['name'] ) : esc_html__( '(Not specified)', 'convertkit' )
);
// Display an option to disconnect.
$html .= sprintf(
'<p><a href="%1$s" class="button button-secondary">%2$s</a></p>',
esc_url(
add_query_arg(
array(
'page' => '_wp_convertkit_settings',
'_convertkit_settings_oauth_disconnect' => wp_create_nonce( 'convertkit-oauth-disconnect' ),
),
'options-general.php'
)
),
esc_html__( 'Disconnect', 'convertkit' )
);
echo wp_kses( $html, convertkit_kses_allowed_html() );
}
/**
* Initialize resource classes and perform a and refresh of resources,
* if initialization has not yet taken place.
*
* @since 2.5.9
*/
public function maybe_initialize_and_refresh_resources() {
// If the Forms resource class is initialized, this has already been done.
if ( $this->forms !== false ) {
return;
}
// Initialize forms resource class.
$this->forms = new ConvertKit_Resource_Forms( 'settings' );
// Don't refresh resources if we're not on the settings screen, as
// it's a resource intense process that can take several seconds.
// We don't want to block other parts of the admin UI.
if ( ! $this->on_settings_screen( $this->name ) ) {
return;
}
// Refresh Forms.
$result = $this->forms->refresh();
// Bail if an error occured.
if ( is_wp_error( $result ) ) {
return;
}
// Also refresh Landing Pages, Tags and Posts. Whilst not displayed in the Plugin Settings, this ensures up to date
// lists are stored for when editing e.g. Pages.
$landing_pages = new ConvertKit_Resource_Landing_Pages( 'settings' );
$result = $landing_pages->refresh();
// Bail if an error occured.
if ( is_wp_error( $result ) ) {
return;
}
remove_all_actions( 'convertkit_resource_refreshed_posts' );
$posts = new ConvertKit_Resource_Posts( 'settings' );
$result = $posts->refresh();
// Bail if an error occured.
if ( is_wp_error( $result ) ) {
return;
}
$products = new ConvertKit_Resource_Products( 'settings' );
$result = $products->refresh();
// Bail if an error occured.
if ( is_wp_error( $result ) ) {
return;
}
$sequences = new ConvertKit_Resource_Sequences( 'settings' );
$result = $sequences->refresh();
// Bail if an error occured.
if ( is_wp_error( $result ) ) {
return;
}
$tags = new ConvertKit_Resource_Tags( 'settings' );
$result = $tags->refresh();
// Bail if an error occured.
if ( is_wp_error( $result ) ) {
return;
}
}
/**
* Renders the input for the Default Form setting for the given Post Type.
*
* @since 1.9.6
*
* @param array $args Field arguments.
*/
public function default_form_callback( $args ) {
// Bail if no Forms exist.
if ( ! $this->forms->exist() ) {
esc_html_e( 'No Forms exist in Kit.', 'convertkit' );
echo '<br /><a href="' . esc_url( convertkit_get_new_form_url() ) . '" target="_blank">' . esc_html__( 'Click here to create your first form', 'convertkit' ) . '</a>';
return;
}
// Build description with preview link.
$description = false;
$preview_url = WP_ConvertKit()->get_class( 'preview_output' )->get_preview_form_url( $args['post_type'] );
if ( $preview_url ) {
// Include a preview link in the description.
$description = sprintf(
'%s %s %s',
sprintf(
/* translators: Post Type name, plural */
esc_html__( 'Select a form above to automatically output below all %s.', 'convertkit' ),
$args['post_type_object']->label
),
'<a href="' . esc_url( $preview_url ) . '" id="convertkit-preview-form-' . esc_attr( $args['post_type'] ) . '" target="_blank">' . esc_html__( 'Click here', 'convertkit' ) . '</a>',
esc_html__( 'to preview how this will display.', 'convertkit' )
);
} else {
// Just output the field's description.
$description = sprintf(
/* translators: Post Type name, plural */
esc_html__( 'Select a form above to automatically output below all %s.', 'convertkit' ),
$args['post_type_object']->label
);
}
// Output field.
echo '<div class="convertkit-select2-container">';
$this->forms->output_select_field_all(
$this->settings_key . '[' . $args['post_type'] . '_form]',
$this->settings_key . '_' . $args['post_type'] . '_form',
array(
'convertkit-select2',
'convertkit-preview-output-link',
),
$this->settings->get_default_form( $args['post_type'] ),
array(
'default' => esc_html__( 'None', 'convertkit' ),
),
array(
'data-target' => '#convertkit-preview-form-' . esc_attr( $args['post_type'] ),
'data-link' => esc_attr( $preview_url ) . '&convertkit_form_id=',
),
$description
);
echo '</div>';
}
/**
* Renders the input for the Default Form Position setting for the given Post Type.
*
* @since 2.5.8
*
* @param array $args Field arguments.
*/
public function default_form_position_callback( $args ) {
$this->output_select_field(
$args['post_type'] . '_form_position',
esc_attr( $this->settings->get_default_form_position( $args['post_type'] ) ),
array(
'before_content' => sprintf(
/* translators: Post type singular name */
esc_attr__( 'Before %s content', 'convertkit' ),
esc_attr( $args['post_type_object']->labels->singular_name )
),
'after_content' => sprintf(
/* translators: Post type singular name */
esc_attr__( 'After %s content', 'convertkit' ),
esc_attr( $args['post_type_object']->labels->singular_name )
),
'before_after_content' => sprintf(
/* translators: Post type singular name */
esc_attr__( 'Before and after %s content', 'convertkit' ),
esc_attr( $args['post_type_object']->labels->singular_name )
),
'after_element' => esc_html__( 'After element', 'convertkit' ),
),
sprintf(
/* translators: Post Type name, plural */
esc_html__( 'Where forms should display relative to the %s content', 'convertkit' ),
esc_html( $args['post_type_object']->labels->singular_name )
),
array( 'convertkit-conditional-display' ),
array(
'data-conditional-value' => 'after_element',
'data-conditional-element' => esc_attr( $args['post_type'] ) . '_form_position_element_index',
)
);
}
/**
* Renders the input for the Default Form Position Index setting for the given Post Type.
*
* @since 2.6.1
*
* @param array $args Field arguments.
*/
public function default_form_position_element_callback( $args ) {
$this->output_number_field(
$args['post_type'] . '_form_position_element_index',
esc_attr( (string) $this->settings->get_default_form_position_element_index( $args['post_type'] ) ),
1,
999,
1,
false,
array( 'after_element' )
);
$this->output_select_field(
$args['post_type'] . '_form_position_element',
esc_attr( $this->settings->get_default_form_position_element( $args['post_type'] ) ),
array(
'p' => esc_html__( 'Paragraphs', 'convertkit' ),
'h2' => esc_html__( 'Headings <h2>', 'convertkit' ),
'h3' => esc_html__( 'Headings <h3>', 'convertkit' ),
'h4' => esc_html__( 'Headings <h4>', 'convertkit' ),
'h5' => esc_html__( 'Headings <h5>', 'convertkit' ),
'h6' => esc_html__( 'Headings <h6>', 'convertkit' ),
'img' => esc_html__( 'Images', 'convertkit' ),
),
esc_html__( 'The number of elements before outputting the form.', 'convertkit' ),
array( 'after_element' )
);
}
/**
* Renders the input for the Non-inline Form setting.
*
* @since 2.2.3
*
* @param array $args Field arguments.
*/
public function non_inline_form_callback( $args ) {
// Bail if no non-inline Forms exist.
if ( ! $this->forms->non_inline_exist() ) {
esc_html_e( 'No non-inline Forms exist in Kit.', 'convertkit' );
echo '<br /><a href="' . esc_url( convertkit_get_new_form_url() ) . '" target="_blank">' . esc_html__( 'Click here to create your first modal, slide in or sticky bar form', 'convertkit' ) . '</a>';
return;
}
// Build description with preview link.
$preview_url = WP_ConvertKit()->get_class( 'preview_output' )->get_preview_form_home_url();
$description = sprintf(
'%s %s %s',
esc_html__( 'Automatically display one or more modal, slide-in, or sticky bar forms across your site. This setting is overridden if a default non-inline form is set above, a specific non-inline form or "None" option is chosen for a post/page, or a non-inline form is specified in a block/shortcode.', 'convertkit' ),
'<a href="' . esc_url( $preview_url ) . '" id="convertkit-preview-non-inline-form" target="_blank">' . esc_html__( 'Click here', 'convertkit' ) . '</a>',
esc_html__( 'to preview how this will display.', 'convertkit' )
);
// Output field.
echo '<div class="convertkit-select2-container">';
$this->forms->output_select_field_non_inline(
$this->settings_key . '[non_inline_form]',
$this->settings_key . '_non_inline_form',
array(
'convertkit-select2',
'convertkit-preview-output-link',
),
$this->settings->get_non_inline_form(),
false,
array(
'data-target' => '#convertkit-preview-non-inline-form',
'data-link' => esc_attr( $preview_url ) . '&convertkit_form_id=',
),
$description
);
echo '</div>';
}
/**
* Renders the input for the Non-inline Form override setting.
*
* @since 2.7.3
*/
public function non_inline_form_honor_none_setting_callback() {
// Output field.
$this->output_checkbox_field(
'non_inline_form_honor_none_setting',
'on',
$this->settings->non_inline_form_honor_none_setting(),
esc_html__( 'If checked, do not display the site wide form(s) above on Pages / Posts that have their Kit Form setting = None.', 'convertkit' )
);
}
/**
* Renders the input for the Modal Form Limit per Session setting.
*
* @since 3.0.0
*
* @param array $args Setting field arguments (name,description).
*/
public function non_inline_form_limit_per_session_callback( $args ) {
// Output field.
$this->output_checkbox_field(
'non_inline_form_limit_per_session',
'on',
$this->settings->non_inline_form_limit_per_session(),
esc_html__( 'If checked, one non-inline form will be displayed per session. This applies to all non-inline forms defined on this screen, Page / Post / Category settings, and any Form blocks or shortcodes specifying a non-inline form.', 'convertkit' )
);
}
/**
* Renders the input for the reCAPTCHA Site Key setting.
*
* @since 3.0.0
*
* @param array $args Setting field arguments (name,description).
*/
public function recaptcha_site_key_callback( $args ) {
// Output field.
$this->output_text_field(
'recaptcha_site_key',
esc_attr( $this->settings->recaptcha_site_key() ),
$args['description'],
array(
'widefat',
)
);
}
/**
* Renders the input for the reCAPTCHA Secret Key setting.
*
* @since 3.0.0
*
* @param array $args Setting field arguments (name,description).
*/
public function recaptcha_secret_key_callback( $args ) {
// Output field.
$this->output_text_field(
'recaptcha_secret_key',
esc_attr( $this->settings->recaptcha_secret_key() ),
$args['description'],
array(
'widefat',
)
);
}
/**
* Renders the input for the reCAPTCHA Minimum Score setting.
*
* @since 3.0.0
*
* @param array $args Setting field arguments (name,description).
*/
public function recaptcha_minimum_score_callback( $args ) {
// Output field.
$this->output_number_field(
'recaptcha_minimum_score',
esc_attr( (string) $this->settings->recaptcha_minimum_score() ),
$args['min'],
$args['max'],
$args['step'],
$args['description'],
array(
'widefat',
)
);
}
/**
* Renders the input for the Debug setting.
*
* @since 1.9.6
*/
public function debug_callback() {
// Output field.
$this->output_checkbox_field(
'debug',
'on',
$this->settings->debug_enabled(),
esc_html__( 'Log requests to file and output browser console messages.', 'convertkit' ),