PluginProbe
Constant Contact Forms / trunk
Constant Contact Forms vtrunk
2.21.0 2.20.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.10.0 1.10.1 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 All 91 releases
constant-contact-forms / constant-contact-forms.php

constant-contact-forms.php in Constant Contact Forms trunk, at constant-contact-forms.php

1,011 lines 23.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Constant Contact Main Plugin File
4 *
5 * @package Constant Contact Forms
6 * @subpackage Loader
7 * @author Constant Contact
8 * @since 1.0.1
9 * @license GPLv3
10 *
11 * @wordpress-plugin
12 * Plugin Name: Constant Contact Forms for WordPress
13 * Plugin URI: https://www.constantcontact.com
14 * Description: Be a better marketer. All it takes is Constant Contact email marketing.
15 * Version: 2.21.0
16 * Author: Constant Contact
17 * Author URI: https://www.constantcontact.com/index?pn=miwordpress
18 * Requires PHP: 8.1
19 * License: GPLv3
20 * Text Domain: constant-contact-forms
21 *
22 * phpcs:disable WebDevStudios.All.RequireAuthor -- Don't require author tag in docblocks.
23 *
24 * Copyright (c) 2016 Constant Contact (email : legal@constantcontact.com)
25 *
26 * This program is free software: you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation, either version 3 of the License, or
29 * (at your option) any later version.
30 *
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
35 *
36 * You should have received a copy of the GNU General Public License
37 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 */
39
40 /**
41 * Autoloads files with classes when needed.
42 *
43 * @since 1.0.0
44 *
45 * @param string $class_name Name of the class being requested.
46 * @return null
47 */
48 function constant_contact_autoload_classes( string $class_name ) {
49 if ( ! str_starts_with( $class_name, 'ConstantContact_' ) ) {
50 return null;
51 }
52
53 $filename = strtolower(
54 str_replace(
55 '_',
56 '-',
57 substr( $class_name, strlen( 'ConstantContact_' ) )
58 )
59 );
60
61 Constant_Contact::include_file( $filename );
62
63 return null;
64 }
65 spl_autoload_register( 'constant_contact_autoload_classes' );
66
67 /**
68 * Main initiation class.
69 *
70 * @since 1.0.0
71 */
72 class Constant_Contact {
73
74 /**
75 * Current version.
76 *
77 * @since 1.0.0
78 * @var string
79 */
80 const VERSION = '2.21.0';
81
82 /**
83 * URL of plugin directory.
84 *
85 * @since 1.0.0
86 * @var string
87 */
88 protected string $url = '';
89
90 /**
91 * Path of plugin directory.
92 *
93 * @since 1.0.0
94 * @var string
95 */
96 protected string $path = '';
97
98 /**
99 * Plugin basename.
100 *
101 * @since 1.0.0
102 * @var string
103 */
104 protected string $basename = '';
105
106 /**
107 * Log location.
108 *
109 * @since 1.3.7
110 * @var string
111 */
112 public string $logger_location = '';
113
114 /**
115 * Singleton instance of plugin.
116 *
117 * @since 1.0.0
118 * @var Constant_Contact
119 */
120 protected static $single_instance;
121
122 /**
123 * An instance of the ConstantContact_API Class.
124 *
125 * @since 1.0.1
126 * @var ConstantContact_API
127 */
128 private ConstantContact_API $api;
129
130 /**
131 * An instance of the ConstantContact_Builder Class.
132 *
133 * @since 1.0.1
134 * @var ConstantContact_Builder
135 */
136 private ConstantContact_Builder $builder;
137
138 /**
139 * An instance of the ConstantContact_Builder_Fields Class.
140 *
141 * @since 1.0.1
142 * @var ConstantContact_Builder_Fields
143 */
144 private ConstantContact_Builder_Fields $builder_fields;
145
146 /**
147 * An instance of the ConstantContact_CPTS Class.
148 *
149 * @since 1.0.1
150 * @var ConstantContact_CPTS
151 */
152 private ConstantContact_CPTS $cpts;
153
154 /**
155 * An instance of the ConstantContact_Display Class.
156 *
157 * @since 1.0.1
158 * @var ConstantContact_Display
159 */
160 private ConstantContact_Display $display;
161
162 /**
163 * An instance of the ConstantContact_Display_Shortcode Class.
164 *
165 * @since 1.0.1
166 * @var ConstantContact_Display_Shortcode
167 */
168 private ConstantContact_Display_Shortcode $display_shortcode;
169
170 /**
171 * An instance of the ConstantContact_Lists Class.
172 *
173 * @since 1.0.1
174 * @var ConstantContact_Lists
175 */
176 private ConstantContact_Lists $lists;
177
178 /**
179 * An instance of the ConstantContact_Process_Form Class.
180 *
181 * @since 1.0.1
182 * @var ConstantContact_Process_Form
183 */
184 private ConstantContact_Process_Form $process_form;
185
186 /**
187 * An instance of the ConstantContact_Settings Class.
188 *
189 * @since 1.0.1
190 * @var ConstantContact_Settings
191 */
192 private ConstantContact_Settings $settings;
193
194 /**
195 * An instance of the ConstantContact_Connect Class.
196 *
197 * @since 1.0.1
198 * @var ConstantContact_Connect
199 */
200 private ConstantContact_Connect $connect;
201
202 /**
203 * An instance of the ConstantContact_Mail Class.
204 *
205 * @since 1.0.1
206 * @var ConstantContact_Mail
207 */
208 private ConstantContact_Mail $mail;
209
210 /**
211 * An instance of the ConstantContact_Notifications Class.
212 *
213 * @since 1.0.1
214 * @var ConstantContact_Notifications
215 */
216 private ConstantContact_Notifications $notifications;
217
218 /**
219 * An instance of the ConstantContact_Notification_Content Class.
220 *
221 * @since 1.0.1
222 * @var ConstantContact_Notification_Content
223 */
224 private ConstantContact_Notification_Content $notification_content;
225
226 /**
227 * An instance of the ConstantContact_Updates Class.
228 *
229 * @since 1.0.1
230 * @var ConstantContact_Updates
231 */
232 private ConstantContact_Updates $updates;
233
234 /**
235 * An instance of the ConstantContact_User_Customizations Class.
236 *
237 * @since 1.0.1
238 * @var ConstantContact_User_Customizations
239 */
240 private ConstantContact_User_Customizations $customizations;
241
242 /**
243 * An instance of the ConstantContact_Logging Class.
244 *
245 * @since 1.3.7
246 * @var ConstantContact_Logging
247 */
248 private ConstantContact_Logging $logging;
249
250 /**
251 * An instance of the ConstantContact_Admin Class.
252 *
253 * @since 1.0.1
254 * @var ConstantContact_Admin
255 */
256 private ConstantContact_Admin $admin;
257
258 /**
259 * An instance of the ConstantContact_Admin_Pages class.
260 *
261 * @since 1.0.1
262 * @var ConstantContact_Admin_Pages
263 */
264 private ConstantContact_Admin_Pages $admin_pages;
265
266 /**
267 * An instance of the ConstantContact_Shortcode class.
268 *
269 * @since 1.0.1
270 * @var ConstantContact_Shortcode
271 */
272 private ConstantContact_Shortcode $shortcode;
273
274 /**
275 * An instance of the ConstantContact_Block class.
276 *
277 * @since 1.5.0
278 * @var ConstantContact_Block
279 */
280 private ConstantContact_Block $block;
281
282 /**
283 * An instance of the ConstantContact_Beaver_Builder class.
284 *
285 * @since 1.5.0
286 * @var ConstantContact_Beaver_Builder
287 */
288 private ConstantContact_Beaver_Builder $beaver_builder;
289
290 /**
291 * An instance of the ConstantContact_Attached_Lists_Field class
292 *
293 * @since 2.6.0
294 * @var ConstantContact_Attached_Lists_Field
295 */
296 private ConstantContact_Attached_Lists_Field $attached_lists;
297
298 /*
299 * An instance of the ConstantContact_Elementor class.
300 *
301 * @since 1.5.0
302 * @var ConstantContact_Elementor
303 */
304 private ConstantContact_Elementor $elementor;
305
306 /**
307 * An instance of the ConstantContact_Health class.
308 *
309 * @since 2.3.0
310 * @var ConstantContact_Health
311 */
312 private ConstantContact_Health $health;
313
314 /**
315 * An instance of the ConstantContact_API_Utility class.
316 * @since 2.18.0
317 * @var ConstantContact_API_Utility
318 */
319 private ConstantContact_API_Utility $utility;
320
321 /**
322 * Option name for where we store the timestamp of when the plugin was activated.
323 *
324 * @since 1.6.0
325 *
326 * @var string
327 */
328 public static string $activated_date_option = 'ctct_plugin_activated_date';
329
330 /**
331 * License file.
332 *
333 * @since 1.0.1
334 * @var string
335 */
336 const LICENSE_FILE = 'license.txt';
337
338 /**
339 * Creates or returns an instance of this class.
340 *
341 * @since 1.0.0
342 *
343 * @return Constant_Contact A single instance of this class.
344 */
345 public static function get_instance(): Constant_Contact {
346 if ( null === self::$single_instance ) {
347 self::$single_instance = new self();
348 }
349
350 return self::$single_instance;
351 }
352
353 /**
354 * Sets up our plugin.
355 *
356 * @since 1.0.0
357 *
358 * @return void
359 */
360 protected function __construct() {
361
362 // Set up some helper properties.
363 $this->basename = plugin_basename( __FILE__ );
364 $this->url = plugin_dir_url( __FILE__ );
365 $this->path = plugin_dir_path( __FILE__ );
366
367 // Load our plugin and our libraries.
368 $this->plugin_classes();
369 $this->admin_plugin_classes();
370
371 // Set logging location.
372 $this->logger_location = $this->logging->get_logging_location();
373
374 // Include our notifications logic.
375 self::include_file( 'notification-logic', false );
376
377 // Include our helper functions function for end-users.
378 self::include_file( 'helper-functions', false );
379
380 // Include compatibility fixes to address conflicts with other plug-ins.
381 self::include_file( 'compatibility', false );
382
383 // Include deprecated functions.
384 self::include_file( 'deprecated', false );
385 }
386
387 /**
388 * Attach other plugin classes to the base plugin class.
389 *
390 * @since 1.0.0
391 */
392 public function plugin_classes() {
393 $this->utility = new ConstantContact_API_Utility( $this );
394 $this->api = new ConstantContact_API( $this );
395 if ( class_exists( 'FLBuilder' ) ) {
396 // Load if Beaver Builder is active.
397 $this->beaver_builder = new ConstantContact_Beaver_Builder( $this );
398 }
399 $this->builder = new ConstantContact_Builder( $this );
400 $this->builder_fields = new ConstantContact_Builder_Fields( $this );
401 $this->cpts = new ConstantContact_CPTS( $this );
402 $this->display = new ConstantContact_Display( $this );
403 $this->shortcode = new ConstantContact_Shortcode( $this );
404 $this->display_shortcode = new ConstantContact_Display_Shortcode( $this );
405 $this->lists = new ConstantContact_Lists( $this );
406 $this->process_form = new ConstantContact_Process_Form( $this );
407 $this->settings = new ConstantContact_Settings( $this );
408 $this->connect = new ConstantContact_Connect( $this );
409 $this->mail = new ConstantContact_Mail( $this );
410 $this->notifications = new ConstantContact_Notifications( $this );
411 $this->notification_content = new ConstantContact_Notification_Content( $this );
412 $this->updates = new ConstantContact_Updates( $this );
413 $this->logging = new ConstantContact_Logging( $this );
414 $this->customizations = new ConstantContact_User_Customizations( $this );
415 $this->health = new ConstantContact_Health( $this );
416 $this->attached_lists = new ConstantContact_Attached_Lists_Field();
417 if ( in_array( 'elementor/elementor.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
418 // Load if Elementor is active.
419 $this->elementor = new ConstantContact_Elementor( $this );
420 }
421 }
422
423 /**
424 * Attach other plugin classes to the base plugin class, but only in the admin.
425 *
426 * @since 1.0.0
427 */
428 public function admin_plugin_classes(): void {
429 $this->admin = new ConstantContact_Admin( $this, $this->basename );
430 $this->admin_pages = new ConstantContact_Admin_Pages( $this );
431 $this->block = new ConstantContact_Block( $this );
432 }
433
434 /**
435 * Add hooks and filters.
436 *
437 * @since 1.0.0
438 *
439 * @return void
440 */
441 public function hooks(): void {
442 add_action( 'init', [ $this, 'init' ] );
443 add_action( 'widgets_init', [ $this, 'widgets' ] );
444 add_filter( 'body_class', [ $this, 'body_classes' ] );
445
446 $this->load_libs();
447
448 add_filter( 'widget_text', 'do_shortcode' );
449 add_action( 'admin_enqueue_scripts', [ $this, 'register_admin_assets' ], 1 );
450 add_action( 'wp_enqueue_scripts', [ $this, 'register_front_assets' ], 1 );
451 add_action( 'init', [ $this->shortcode, 'register_shortcode' ] );
452 add_action( 'save_post', [ $this->shortcode, 'clear_forms_list_transient' ], 10, 2 );
453
454 if ( is_admin() ) {
455 add_action( 'wp_ajax_ctct_dismiss_first_modal', [ $this, 'ajax_save_clear_first_form' ] );
456 add_action( 'wp_ajax_nopriv_ctct_dismiss_first_modal', [ $this, 'ajax_save_clear_first_form' ] );
457 }
458 }
459
460 /**
461 * Activate the plugin.
462 *
463 * @since 1.0.0
464 */
465 public function activate(): void {
466 update_option( self::$activated_date_option, time() );
467 }
468
469 /**
470 * Deactivate the plugin, refresh some notification dismissals.
471 *
472 * @since 1.0.0
473 *
474 * @return void
475 */
476 public function deactivate(): void {
477
478 // Clear out connection data when deactivating plugin.
479 delete_option( 'ctct_access_token' );
480 delete_option( '_ctct_access_token' );
481 delete_option( 'ctct_refresh_token' );
482 delete_option( '_ctct_refresh_token' );
483 delete_option( '_ctct_expires_in' );
484 delete_option( 'CtctConstantContactcode_verifier' );
485 delete_option( 'CtctConstantContactState' );
486 delete_option( 'ctct_auth_url' );
487 delete_option( 'ctct_key' );
488 delete_option( 'ctct_maybe_needs_reconnected' );
489 delete_option( 'ctct_acquiring_token' );
490 delete_option( 'ctct_refreshing_token' );
491 constant_contact_delete_option( '_ctct_form_state_authcode' );
492 wp_clear_scheduled_hook( 'ctct_refresh_token_job' );
493 wp_unschedule_hook( 'ctct_refresh_token_job' );
494
495 $this->notifications->delete_dismissed_notification( 'activation' );
496 }
497
498 /**
499 * Delete a number of transients and database options on uninstall.
500 *
501 * @since 1.6.0
502 */
503 public function uninstall(): void {
504 $uninstaller = new ConstantContact_Uninstall();
505 $uninstaller->run();
506 }
507
508 /**
509 * Init hooks.
510 *
511 * @since 1.0.0
512 */
513 public function init(): void {
514 $this->init_debug_log();
515 }
516
517 /**
518 * Initialize debug log on init.
519 *
520 * @since 1.8.5
521 *
522 * @return void
523 */
524 protected function init_debug_log(): void {
525
526 if ( ! constant_contact_debugging_enabled() ) {
527 return;
528 }
529
530 // Create logging file and directory.
531 $this->logging->initialize_logging();
532 }
533
534 /**
535 * Load Vendor libraries.
536 *
537 * @since 1.0.0
538 */
539 public function load_libs(): void {
540
541 // Load what we can, automagically.
542 require_once $this->dir( 'vendor_prefixed/autoload.php' );
543
544 require_once $this->dir( 'vendor/cmb2/cmb2/init.php' );
545 }
546
547 /**
548 * Load and register our Constant Contact widget.
549 *
550 * @since 1.1.0
551 */
552 public function widgets() {
553 require_once constant_contact()->path . 'includes/widgets/contact-form-select.php';
554 register_widget( 'ConstantContactWidget' );
555 }
556
557 /**
558 * Save our dismissed first form notification.
559 *
560 * @since 1.0.0
561 */
562 public function ajax_save_clear_first_form() {
563
564 if ( 'ctct_dismiss_first_modal' === filter_input( INPUT_POST, 'action', FILTER_SANITIZE_SPECIAL_CHARS ) ) {
565 // Save our dismiss for the first form modal.
566 update_option( 'ctct_first_form_modal_dismissed', current_time( 'timestamp' ) );
567
568 wp_send_json_success(
569 [ 'message' => esc_html__( 'Dismiss successsful', 'constant-contact-forms' ) ]
570 );
571 exit();
572 }
573
574 wp_send_json_error(
575 [ 'message' => esc_html__( 'Dismiss failed', 'constant-contact-forms' ) ]
576 );
577 exit();
578 }
579
580 /**
581 * Magic getter for our object.
582 *
583 * @since 1.0.0
584 *
585 * @throws Exception Throws an exception if the field is invalid.
586 *
587 * @param string $field Field to get.
588 * @return mixed
589 */
590 public function __get( $field ) {
591 return match ( $field ) {
592 'version' => self::VERSION,
593 'basename', 'path', 'url' => $this->$field,
594 default => throw new Exception( 'Invalid ' . __CLASS__ . ' property: ' . $field ),
595 };
596 }
597
598 /**
599 * Admin getter
600 * @since 2.11.0
601 * @return ConstantContact_Admin
602 */
603 public function get_admin() : ConstantContact_Admin {
604 return $this->admin;
605 }
606
607 /**
608 * Admin pages getter
609 * @since 2.11.0
610 * @return ConstantContact_Admin_Pages
611 */
612 public function get_admin_pages(): ConstantContact_Admin_Pages {
613 return $this->admin_pages;
614 }
615
616 /**
617 * API getter
618 * @since 2.11.0
619 * @return ConstantContact_API
620 */
621 public function get_api(): ConstantContact_API {
622 return $this->api;
623 }
624
625 /**
626 * Beaver Builder getter.
627 *
628 * @since 2.11.0
629 * @return ConstantContact_Beaver_Builder
630 */
631 public function get_beaver_builder(): ConstantContact_Beaver_Builder {
632 return $this->beaver_builder;
633 }
634
635 /**
636 * Form Builder getter.
637 *
638 * @since 2.11.0
639 * @return ConstantContact_Builder
640 */
641 public function get_builder(): ConstantContact_Builder {
642 return $this->builder;
643 }
644
645 /**
646 * Form Builder Fields getter.
647 *
648 * @since 2.11.0
649 * @return ConstantContact_Builder_Fields
650 */
651 public function get_builder_fields(): ConstantContact_Builder_Fields {
652 return $this->builder_fields;
653 }
654
655 /**
656 * Connect getter.
657 *
658 * @since 2.11.0
659 * @return ConstantContact_Connect
660 */
661 public function get_connect(): ConstantContact_Connect {
662 return $this->connect;
663 }
664
665 /**
666 * CPTS getter.
667 *
668 * @since 2.11.0
669 * @return ConstantContact_CPTS
670 */
671 public function get_cpts(): ConstantContact_CPTS {
672 return $this->cpts;
673 }
674
675 /**
676 * User Customizations getter.
677 *
678 * @since 2.11.0
679 * @return ConstantContact_User_Customizations
680 */
681 public function get_customizations(): ConstantContact_User_Customizations {
682 return $this->customizations;
683 }
684
685 /**
686 * Display getter.
687 *
688 * @since 2.11.0
689 * @return ConstantContact_Display
690 */
691 public function get_display(): ConstantContact_Display {
692 return $this->display;
693 }
694
695 /**
696 * Display shortcode getter.
697 *
698 * @since 2.11.0
699 * @return ConstantContact_Display_Shortcode
700 */
701 public function get_display_shortcode(): ConstantContact_Display_Shortcode {
702 return $this->display_shortcode;
703 }
704
705 /**
706 * Elementor getter.
707 *
708 * @since 2.11.0
709 * @return ConstantContact_Elementor
710 */
711 public function get_elementor() : ConstantContact_Elementor {
712 return $this->elementor;
713 }
714
715 /**
716 * Block getter.
717 *
718 * @since 2.11.0
719 * @return ConstantContact_Block
720 */
721 public function get_block(): ConstantContact_Block {
722 return $this->block;
723 }
724
725 /**
726 * Health getter.
727 * @since 2.11.0
728 * @return ConstantContact_Health
729 */
730 public function get_health() : ConstantContact_Health {
731 return $this->health;
732 }
733
734 /**
735 * Lists getter.
736 *
737 * @since 2.11.0
738 * @return ConstantContact_Lists
739 */
740 public function get_lists(): ConstantContact_Lists {
741 return $this->lists;
742 }
743
744 /**
745 * Logging getter.
746 *
747 * @since 2.11.0
748 * @return ConstantContact_Logging
749 */
750 public function get_logging(): ConstantContact_Logging {
751 return $this->logging;
752 }
753
754 /**
755 * Mail getter.
756 *
757 * @since 2.11.0
758 * @return ConstantContact_Mail
759 */
760 public function get_mail(): ConstantContact_Mail {
761 return $this->mail;
762 }
763
764 /**
765 * Notifications getter.
766 *
767 * @since 2.11.0
768 * @return ConstantContact_Notifications
769 */
770 public function get_notifications(): ConstantContact_Notifications {
771 return $this->notifications;
772 }
773
774 /**
775 * Notification Content getter.
776 *
777 * @since 2.11.0
778 * @return ConstantContact_Notification_Content
779 */
780 public function get_notification_content(): ConstantContact_Notification_Content {
781 return $this->notification_content;
782 }
783
784 /**
785 * Process Form getter.
786 *
787 * @since 2.11.0
788 * @return ConstantContact_Process_Form
789 */
790 public function get_process_form(): ConstantContact_Process_Form {
791 return $this->process_form;
792 }
793
794 /**
795 * Settings getter.
796 *
797 * @since 2.11.0
798 * @return ConstantContact_Settings
799 */
800 public function get_settings(): ConstantContact_Settings {
801 return $this->settings;
802 }
803
804 /**
805 * Shortcode getter.
806 *
807 * @since 2.11.0
808 * @return ConstantContact_Shortcode
809 */
810 public function get_shortcode(): ConstantContact_Shortcode {
811 return $this->shortcode;
812 }
813
814 /**
815 * Updates getter.
816 *
817 * @since 2.11.0
818 * @return ConstantContact_Updates
819 */
820 public function get_updates(): ConstantContact_Updates {
821 return $this->updates;
822 }
823
824 /**
825 * API Utility getter.
826 * @return ConstantContact_API_Utility
827 * @since 2.18.0
828 */
829 public function get_api_utility(): ConstantContact_API_Utility {
830 return $this->utility;
831 }
832
833 /**
834 * Include a file from the classes directory.
835 *
836 * @since 1.0.0
837 *
838 * @param string $filename Name of the file to be included.
839 * @param bool $include_class Whether or ot to include the class.
840 * @return bool Result of include call.
841 */
842 public static function include_file( string $filename, bool $include_class = true ): bool {
843
844 // By default, all files are named 'class-something.php'.
845 if ( $include_class ) {
846 $filename = 'class-' . $filename;
847 }
848
849 $file = self::dir( 'includes/' . $filename . '.php' );
850
851 if ( file_exists( $file ) ) {
852 return include_once $file;
853 }
854
855 return false;
856 }
857
858 /**
859 * This plugin's directory.
860 *
861 * @since 1.0.0
862 *
863 * @param string $path Appended path. Optional.
864 * @return string Directory and path.
865 */
866 public static function dir( string $path = '' ) : string {
867 static $dir;
868 $dir = $dir ?: trailingslashit( __DIR__ );
869 return $dir . $path;
870 }
871
872 /**
873 * This plugin's url.
874 *
875 * @since 1.0.0
876 *
877 * @param string $path Appended path. Optional.
878 * @return string URL and path
879 */
880 public static function url( string $path = '' ) : string {
881 static $url;
882 $url = $url ?: trailingslashit( plugin_dir_url( __FILE__ ) );
883 return $url . $path;
884 }
885
886 /**
887 * Retrieve license as text.
888 *
889 * @since 1.0.0
890 *
891 * @return string License text.
892 */
893 public function get_license_text(): string {
894 $license = self::url( self::LICENSE_FILE );
895 $license_content = wp_remote_get( $license );
896
897 if ( 200 === wp_remote_retrieve_response_code( $license_content ) ) {
898 return wp_remote_retrieve_body( $license_content );
899 }
900
901 return esc_html__( 'Error loading license.', 'constant-contact-forms' );
902 }
903
904 /**
905 * Add some custom body classes for our needs.
906 *
907 * @since 1.2.0
908 *
909 * @param array $classes Existing body classes.
910 * @return array Amended body classes.
911 */
912 public function body_classes( array $classes = [] ) : array {
913 $theme = wp_get_theme()->get_template();
914 $classes[] = "ctct-{$theme}"; // Prefixing for user knowledge of source.
915
916 return $classes;
917 }
918
919 /**
920 * Register our admin styles.
921 *
922 * @since 1.4.0
923 */
924 public function register_admin_assets(): void {
925
926 wp_register_style(
927 'constant-contact-forms-admin',
928 self::url() . 'assets/css/admin-style.css',
929 [],
930 self::VERSION
931 );
932 }
933
934 /**
935 * Register our frontend styles.
936 *
937 * @since 1.4.0
938 */
939 public function register_front_assets(): void {
940
941 if ( constant_contact_disable_frontend_css() ) {
942 return;
943 }
944
945 wp_register_style(
946 'ctct_form_styles',
947 self::url() . 'assets/css/style.css',
948 [],
949 self::VERSION
950 );
951 }
952
953 /**
954 * Determine if we are in a Constant Contact area.
955 *
956 * @since 1.2.0
957 *
958 * @return bool
959 */
960 public function is_constant_contact() : bool {
961 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
962 return false;
963 }
964
965 if ( ! is_admin() ) {
966 return false;
967 }
968
969 $ctct_types = [ 'ctct_forms', 'ctct_lists' ];
970 $post_type = filter_input( INPUT_GET, 'post_type', FILTER_SANITIZE_SPECIAL_CHARS );
971 $post = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );
972
973 if ( in_array( $post_type, $ctct_types, true ) ) {
974 return true;
975 }
976
977 if ( in_array( get_post_type( $post ), $ctct_types, true ) ) {
978 return true;
979 }
980
981 return false;
982 }
983 }
984 add_action( 'plugins_loaded', [ constant_contact(), 'hooks' ] );
985
986 register_activation_hook( __FILE__, [ constant_contact(), 'activate' ] );
987 register_deactivation_hook( __FILE__, [ constant_contact(), 'deactivate' ] );
988 register_uninstall_hook( __FILE__, 'constant_contact_uninstall' );
989
990 /**
991 * Grab the Constant_Contact object and return it.
992 * Wrapper for Constant_Contact::get_instance().
993 *
994 * @since 1.0.0
995 *
996 * @return Constant_Contact Singleton instance of plugin class.
997 */
998 function constant_contact(): Constant_Contact {
999 return Constant_Contact::get_instance();
1000 }
1001
1002 /**
1003 * Callback for the uninstall hook.
1004 *
1005 * @since 1.6.0
1006 */
1007 function constant_contact_uninstall(): void {
1008 $instance = Constant_Contact::get_instance();
1009 $instance->uninstall();
1010 }
1011