PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.5.7
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.5.7
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 2.3.3 All 194 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.5.7, at includes/class-convertkit-settings-broadcasts.php

259 lines 4.9 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 // Check if DOMDocument is installed.
77 // It should be installed as mosts hosts include php-dom and php-xml modules.
78 // If not, disable Broadcast to Posts import functionality as we can't parse
79 // imported Broadcasts.
80 if ( ! class_exists( 'DOMDocument' ) ) {
81 return false;
82 }
83
84 return ( $this->settings['enabled'] === 'on' ? true : false );
85
86 }
87
88 /**
89 * Returns the WordPress Author ID to assign imported Broadcasts to.
90 *
91 * @since 2.2.9
92 *
93 * @return int
94 */
95 public function author_id() {
96
97 return $this->settings['author_id'];
98
99 }
100
101 /**
102 * Returns the WordPress Post Status to assign to Posts created from imported Broadcasts.
103 *
104 * @since 2.3.4
105 *
106 * @return string
107 */
108 public function post_status() {
109
110 return $this->settings['post_status'];
111
112 }
113
114 /**
115 * Returns the WordPress Category ID to assign imported Broadcasts to.
116 *
117 * @since 2.2.9
118 *
119 * @return int
120 */
121 public function category_id() {
122
123 return $this->settings['category_id'];
124
125 }
126
127 /**
128 * Returns whether to import the thumbnail to the Featured Image.
129 *
130 * @since 2.4.1
131 *
132 * @return bool
133 */
134 public function import_thumbnail() {
135
136 return ( $this->settings['import_thumbnail'] === 'on' ? true : false );
137
138 }
139
140 /**
141 * Returns the earliest date that Broadcasts should be imported,
142 * based on their published_at date.
143 *
144 * @since 2.2.9
145 *
146 * @return string Date (yyyy-mm-dd)
147 */
148 public function published_at_min_date() {
149
150 return $this->settings['published_at_min_date'];
151
152 }
153
154 /**
155 * Returns whether exporting Posts to Broadcasts is enabled in the Plugin settings.
156 *
157 * @since 2.4.0
158 *
159 * @return bool
160 */
161 public function enabled_export() {
162
163 return ( $this->settings['enabled_export'] === 'on' ? true : false );
164
165 }
166
167 /**
168 * Returns whether Broadcasts should have their styles imported.
169 *
170 * @since 2.2.9
171 *
172 * @return bool
173 */
174 public function no_styles() {
175
176 return ( $this->settings['no_styles'] === 'on' ? true : false );
177
178 }
179
180 /**
181 * Returns whether imported Broadcasts should have their Restrict Content
182 * setting defined, if the Broadcast is marked as paid.
183 *
184 * @since 2.2.9
185 *
186 * @return bool
187 */
188 public function restrict_content_enabled() {
189
190 return ! empty( $this->settings['restrict_content'] );
191
192 }
193
194 /**
195 * Returns the Restrict Content setting to assign to imported Broadcasts
196 *
197 * @since 2.2.9
198 *
199 * @return string
200 */
201 public function restrict_content() {
202
203 return $this->settings['restrict_content'];
204
205 }
206
207 /**
208 * The default settings, used when the ConvertKit Broadcasts Settings haven't been saved
209 * e.g. on a new installation.
210 *
211 * @since 2.2.9
212 *
213 * @return array
214 */
215 public function get_defaults() {
216
217 $defaults = array(
218 'enabled' => '',
219 'author_id' => get_current_user_id(),
220 'post_status' => 'publish',
221 'category_id' => '',
222 'import_thumbnail' => 'on',
223
224 // By default, only import Broadcasts as Posts for the last 30 days.
225 'published_at_min_date' => gmdate( 'Y-m-d', strtotime( '-30 days' ) ),
226
227 'enabled_export' => '',
228 'no_styles' => '',
229 );
230
231 /**
232 * The default settings, used when the ConvertKit Broadcasts Settings haven't been saved
233 * e.g. on a new installation.
234 *
235 * @since 2.2.9
236 *
237 * @param array $defaults Default settings.
238 */
239 $defaults = apply_filters( 'convertkit_settings_broadcasts_get_defaults', $defaults );
240
241 return $defaults;
242
243 }
244
245 /**
246 * Saves the given array of settings to the WordPress options table.
247 *
248 * @since 2.2.9
249 *
250 * @param array $settings Settings.
251 */
252 public function save( $settings ) {
253
254 update_option( self::SETTINGS_NAME, array_merge( $this->get(), $settings ) );
255
256 }
257
258 }
259