PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.3
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.3
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 2.3.0 2.3.1 All 196 releases
convertkit / includes / integrations / contactform7 / class-convertkit-contactform7-settings.php

class-convertkit-contactform7-settings.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.3, at includes/integrations/contactform7/class-convertkit-contactform7-settings.php

157 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Contact Form 7 Settings class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Class to read ConvertKit Contact Form 7 Integration Settings.
11 *
12 * @since 1.9.6
13 */
14 class ConvertKit_ContactForm7_Settings {
15
16 /**
17 * Holds the Settings Key that stores this integration's settings.
18 *
19 * @var string
20 */
21 const SETTINGS_NAME = '_wp_convertkit_integration_contactform7_settings';
22
23 /**
24 * Holds the Settings
25 *
26 * @var array
27 */
28 private $settings = array();
29
30 /**
31 * Constructor. Reads settings from options table, falling back to defaults
32 * if no settings exist.
33 *
34 * @since 1.9.6
35 */
36 public function __construct() {
37
38 // Get Settings.
39 $settings = get_option( self::SETTINGS_NAME );
40
41 // If no Settings exist, falback to default settings.
42 if ( ! $settings ) {
43 $this->settings = $this->get_defaults();
44 } else {
45 $this->settings = $settings;
46 }
47
48 }
49
50 /**
51 * Returns Integration settings.
52 *
53 * @since 1.9.6
54 *
55 * @return array
56 */
57 public function get() {
58
59 return $this->settings;
60
61 }
62
63 /**
64 * Checks if any settings are defined.
65 *
66 * @since 1.9.6
67 *
68 * @return bool
69 */
70 public function has_settings() {
71
72 if ( empty( $this->get() ) ) {
73 return false;
74 }
75
76 return true;
77
78 }
79
80 /**
81 * Returns the ConvertKit subscription setting for the given Contact Form 7 Form ID.
82 *
83 * @since 1.9.6
84 *
85 * @param int $cf7_form_id Contact Form 7 Form ID.
86 * @return bool|string|int
87 */
88 public function get_convertkit_subscribe_setting_by_cf7_form_id( $cf7_form_id ) {
89
90 // Bail if no settings exist.
91 if ( ! $this->has_settings() ) {
92 return false;
93 }
94
95 // Bail if no mapping exists.
96 if ( ! array_key_exists( $cf7_form_id, $this->get() ) ) {
97 return false;
98 }
99
100 return $this->get()[ $cf7_form_id ];
101
102 }
103
104 /**
105 * Returns whether Creator Network Recommendations are enabled for the given Contact Form 7 Form ID.
106 *
107 * @since 2.2.7
108 *
109 * @param int $cf7_form_id Contact Form 7 Form ID.
110 * @return bool
111 */
112 public function get_creator_network_recommendations_enabled_by_cf7_form_id( $cf7_form_id ) {
113
114 // Bail if no settings exist for any Contact Form 7 Forms.
115 if ( ! $this->has_settings() ) {
116 return false;
117 }
118
119 // Bail if no setting exists for the given Contact Form 7 Form.
120 if ( ! array_key_exists( 'creator_network_recommendations_' . $cf7_form_id, $this->get() ) ) {
121 return false;
122 }
123
124 return (bool) $this->get()[ 'creator_network_recommendations_' . $cf7_form_id ];
125
126 }
127
128 /**
129 * The default settings, used when this integration's Settings haven't been saved
130 * e.g. on a new installation or when the integration's Plugin has just been activated
131 * for the first time.
132 *
133 * @since 1.9.6
134 *
135 * @return array
136 */
137 public function get_defaults() {
138
139 $defaults = array();
140
141 /**
142 * The default settings, used when Contact Form 7's Settings haven't been saved
143 * e.g. on a new installation or when the Contact Form 7 Plugin has just been activated
144 * for the first time.
145 *
146 * @since 1.9.6
147 *
148 * @param array $defaults Default Settings.
149 */
150 $defaults = apply_filters( 'convertkit_contactform7_settings_get_defaults', $defaults );
151
152 return $defaults;
153
154 }
155
156 }
157