PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.4.7
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.4.7
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 2.3.2 All 195 releases
convertkit / includes / class-convertkit-settings-broadcasts.php

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

251 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Broadcasts Settings class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Class to read ConvertKit Broadcasts Settings.
11 *
12 * @since 2.2.9
13 */
14 class ConvertKit_Settings_Broadcasts {
15
16 /**
17 * Holds the Settings Key that stores site wide ConvertKit settings
18 *
19 * @var string
20 *
21 * @since 2.2.9
22 */
23 const SETTINGS_NAME = '_wp_convertkit_settings_broadcasts';
24
25 /**
26 * Holds the Settings
27 *
28 * @var array
29 *
30 * @since 2.2.9
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.2.9
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 = array_merge( $this->get_defaults(), $settings );
50 }
51
52 }
53
54 /**
55 * Returns Plugin settings.
56 *
57 * @since 2.2.9
58 *
59 * @return array
60 */
61 public function get() {
62
63 return $this->settings;
64
65 }
66
67 /**
68 * Returns whether Broadcasts are enabled in the Plugin settings.
69 *
70 * @since 2.2.9
71 *
72 * @return bool
73 */
74 public function enabled() {
75
76 return ( $this->settings['enabled'] === 'on' ? true : false );
77
78 }
79
80 /**
81 * Returns the WordPress Author ID to assign imported Broadcasts to.
82 *
83 * @since 2.2.9
84 *
85 * @return int
86 */
87 public function author_id() {
88
89 return $this->settings['author_id'];
90
91 }
92
93 /**
94 * Returns the WordPress Post Status to assign to Posts created from imported Broadcasts.
95 *
96 * @since 2.3.4
97 *
98 * @return string
99 */
100 public function post_status() {
101
102 return $this->settings['post_status'];
103
104 }
105
106 /**
107 * Returns the WordPress Category ID to assign imported Broadcasts to.
108 *
109 * @since 2.2.9
110 *
111 * @return int
112 */
113 public function category_id() {
114
115 return $this->settings['category_id'];
116
117 }
118
119 /**
120 * Returns whether to import the thumbnail to the Featured Image.
121 *
122 * @since 2.4.1
123 *
124 * @return bool
125 */
126 public function import_thumbnail() {
127
128 return ( $this->settings['import_thumbnail'] === 'on' ? true : false );
129
130 }
131
132 /**
133 * Returns the earliest date that Broadcasts should be imported,
134 * based on their published_at date.
135 *
136 * @since 2.2.9
137 *
138 * @return string Date (yyyy-mm-dd)
139 */
140 public function published_at_min_date() {
141
142 return $this->settings['published_at_min_date'];
143
144 }
145
146 /**
147 * Returns whether exporting Posts to Broadcasts is enabled in the Plugin settings.
148 *
149 * @since 2.4.0
150 *
151 * @return bool
152 */
153 public function enabled_export() {
154
155 return ( $this->settings['enabled_export'] === 'on' ? true : false );
156
157 }
158
159 /**
160 * Returns whether Broadcasts should have their styles imported.
161 *
162 * @since 2.2.9
163 *
164 * @return bool
165 */
166 public function no_styles() {
167
168 return ( $this->settings['no_styles'] === 'on' ? true : false );
169
170 }
171
172 /**
173 * Returns whether imported Broadcasts should have their Restrict Content
174 * setting defined, if the Broadcast is marked as paid.
175 *
176 * @since 2.2.9
177 *
178 * @return bool
179 */
180 public function restrict_content_enabled() {
181
182 return ! empty( $this->settings['restrict_content'] );
183
184 }
185
186 /**
187 * Returns the Restrict Content setting to assign to imported Broadcasts
188 *
189 * @since 2.2.9
190 *
191 * @return string
192 */
193 public function restrict_content() {
194
195 return $this->settings['restrict_content'];
196
197 }
198
199 /**
200 * The default settings, used when the ConvertKit Broadcasts Settings haven't been saved
201 * e.g. on a new installation.
202 *
203 * @since 2.2.9
204 *
205 * @return array
206 */
207 public function get_defaults() {
208
209 $defaults = array(
210 'enabled' => '',
211 'author_id' => get_current_user_id(),
212 'post_status' => 'publish',
213 'category_id' => '',
214 'import_thumbnail' => 'on',
215
216 // By default, only import Broadcasts as Posts for the last 30 days.
217 'published_at_min_date' => gmdate( 'Y-m-d', strtotime( '-30 days' ) ),
218
219 'enabled_export' => '',
220 'no_styles' => '',
221 );
222
223 /**
224 * The default settings, used when the ConvertKit Broadcasts Settings haven't been saved
225 * e.g. on a new installation.
226 *
227 * @since 2.2.9
228 *
229 * @param array $defaults Default settings.
230 */
231 $defaults = apply_filters( 'convertkit_settings_broadcasts_get_defaults', $defaults );
232
233 return $defaults;
234
235 }
236
237 /**
238 * Saves the given array of settings to the WordPress options table.
239 *
240 * @since 2.2.9
241 *
242 * @param array $settings Settings.
243 */
244 public function save( $settings ) {
245
246 update_option( self::SETTINGS_NAME, array_merge( $this->get(), $settings ) );
247
248 }
249
250 }
251