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 / forminator / class-convertkit-forminator-settings.php

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

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