PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.5.2
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.5.2
3.4.4 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 All 197 releases
← All changes | admin/section/class-convertkit-admin-settings-broadcasts.php +241 -45 2.3.0 → 2.5.2 View file →
@@ -28,16 +28,19 @@
28 28 $this->settings_key = $this->settings::SETTINGS_NAME;
29 29
30 30 // Define the programmatic name, Title and Tab Text.
31 31 $this->name = 'broadcasts';
32 - $this->title = __( 'Broadcasts to Posts', 'convertkit' );
32 + $this->title = __( 'Broadcasts', 'convertkit' );
33 33 $this->tab_text = __( 'Broadcasts', 'convertkit' );
34 34
35 35 // Identify that this is beta functionality.
36 36 $this->is_beta = true;
37 37
38 - // Output notices.
39 - add_action( 'convertkit_settings_base_render_before', array( $this, 'maybe_output_notices' ) );
38 + // Register and maybe output notices for this settings screen.
39 + if ( $this->on_settings_screen( $this->name ) ) {
40 + add_filter( 'convertkit_settings_base_register_notices', array( $this, 'register_notices' ) );
41 + add_action( 'convertkit_settings_base_render_before', array( $this, 'maybe_output_notices' ) );
42 + }
40 43
41 44 // Enqueue scripts and CSS.
42 45 add_action( 'convertkit_admin_settings_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
43 46 add_action( 'convertkit_admin_settings_enqueue_styles', array( $this, 'enqueue_styles' ) );
@@ -48,8 +51,29 @@
48 51
49 52 }
50 53
51 54 /**
55 + * Registers success and error notices for the Tools screen, to be displayed
56 + * depending on the action.
57 + *
58 + * @since 2.5.1
59 + *
60 + * @param array $notices Regsitered success and error notices.
61 + * @return array
62 + */
63 + public function register_notices( $notices ) {
64 +
65 + return array_merge(
66 + $notices,
67 + array(
68 + 'broadcast_import_error' => __( 'Broadcasts import failed. Please try again.', 'convertkit' ),
69 + 'broadcast_import_success' => __( 'Broadcasts import started. Check the Posts screen shortly to confirm Broadcasts imported successfully.', 'convertkit' ),
70 + )
71 + );
72 +
73 + }
74 +
75 + /**
52 76 * Import Broadcasts now, if requested through the UI.
53 77 *
54 78 * @since 2.2.9
55 79 */
@@ -68,15 +92,16 @@
68 92 $result = $cron->run( 'convertkit_resource_refresh_posts' );
69 93
70 94 // If an error occured, show it now.
71 95 if ( is_wp_error( $result ) ) {
72 - // Redirect to Broadcasts screen.
73 - $this->redirect( 'broadcast_import_error' );
96 + // Redirect to Broadcasts screen with error.
97 + $this->redirect_with_error_description( $result->get_error_message() );
74 98 return;
75 99 }
76 100
77 101 // If here, the task scheduled.
78 - $this->redirect( false, 'broadcast_import_success' );
102 + // Redirect with success notice.
103 + $this->redirect_with_success_notice( 'broadcast_import_success' );
79 104
80 105 }
81 106
82 107 /**
@@ -120,48 +145,44 @@
120 145
121 146 }
122 147
123 148 /**
124 - * Outputs success and/or error notices if required.
149 + * Registers settings fields for this section.
125 150 *
126 151 * @since 2.2.9
127 152 */
128 - public function maybe_output_notices() {
153 + public function register_fields() {
129 154
130 - // Define messages that might be displayed as a notification.
131 - $messages = array(
132 - 'broadcast_import_error' => __( 'Broadcasts import failed. Please try again.', 'convertkit' ),
133 - 'broadcast_import_success' => __( 'Broadcasts import started. Check the Posts screen shortly to confirm Broadcasts imported successfully.', 'convertkit' ),
134 - );
155 + // Check if DOMDocument is installed.
156 + // It should be installed as mosts hosts include php-dom and php-xml modules.
157 + // If not, disable Broadcast to Posts import functionality as we can't parse
158 + // imported Broadcasts.
159 + if ( ! class_exists( 'DOMDocument' ) ) {
160 + // Disable saving settings.
161 + $this->save_disabled = true;
135 162
136 - // Output error notification if defined.
137 - if ( isset( $_REQUEST['error'] ) && array_key_exists( sanitize_text_field( $_REQUEST['error'] ), $messages ) ) { // phpcs:ignore WordPress.Security.NonceVerification
138 - $this->output_error( $messages[ sanitize_text_field( $_REQUEST['error'] ) ] ); // phpcs:ignore WordPress.Security.NonceVerification
139 - }
163 + // Return if we're not on the Plugin settings screen.
164 + if ( ! $this->on_settings_screen( 'broadcasts' ) ) {
165 + return;
166 + }
140 167
141 - // Output success notification if defined.
142 - if ( isset( $_REQUEST['success'] ) && array_key_exists( sanitize_text_field( $_REQUEST['success'] ), $messages ) ) { // phpcs:ignore WordPress.Security.NonceVerification
143 - $this->output_success( $messages[ sanitize_text_field( $_REQUEST['success'] ) ] ); // phpcs:ignore WordPress.Security.NonceVerification
168 + // Output a notice if we're on the Broadcasts settings screen.
169 + $this->output_error(
170 + __( 'Importing public broadcasts from ConvertKit requires the PHP extensions `php-dom` and `php-xml` to be installed. Work with your web host to do this, and reload the page when done.', 'convertkit' )
171 + );
172 + return;
144 173 }
145 174
146 - }
147 -
148 - /**
149 - * Registers settings fields for this section.
150 - *
151 - * @since 2.2.9
152 - */
153 - public function register_fields() {
154 -
155 175 // Initialize classes that will be used.
156 176 $posts = new ConvertKit_Resource_Posts( 'cron' );
157 177
158 178 // Define description for the 'Enabled' setting.
159 179 // If enabled, include the next scheduled date and time the Plugin will import broadcasts.
180 + // If the next scheduled timestamp is 1, the event is running now.
160 181 $enabled_description = '';
161 - if ( $this->settings->enabled() && $posts->get_cron_event_next_scheduled() ) {
182 + if ( $this->settings->enabled() && $posts->get_cron_event_next_scheduled() && $posts->get_cron_event_next_scheduled() > 1 ) {
162 183 $enabled_description = sprintf(
163 - '%s %s',
184 + '%s %s<br />%s <strong>%s</strong> %s',
164 185 esc_html__( 'Broadcasts will next import at approximately ', 'convertkit' ),
165 186 // The cron event's next scheduled timestamp is always in UTC.
166 187 // Display it converted to the WordPress site's timezone.
167 188 get_date_from_gmt(
@@ -166,21 +187,25 @@
166 187 // Display it converted to the WordPress site's timezone.
167 188 get_date_from_gmt(
168 189 gmdate( 'Y-m-d H:i:s', $posts->get_cron_event_next_scheduled() ),
169 190 get_option( 'date_format' ) . ' ' . get_option( 'time_format' )
170 - )
191 + ),
192 + esc_html__( 'Broadcasts', 'convertkit' ),
193 + esc_html__( 'must', 'convertkit' ),
194 + esc_html__( 'have their "Enabled on public feeds" setting enabled in ConvertKit, to be eligible for import.', 'convertkit' )
171 195 );
172 196 }
173 197
174 198 add_settings_field(
175 199 'enabled',
176 - __( 'Enable', 'convertkit' ),
200 + __( 'Enable Automatic Import', 'convertkit' ),
177 201 array( $this, 'enable_callback' ),
178 202 $this->settings_key,
179 203 $this->name,
180 204 array(
181 205 'name' => 'enabled',
182 - 'label' => __( 'Enables automatic publication of ConvertKit Broadcasts to WordPress Posts.', 'convertkit' ),
206 + 'label_for' => 'enabled',
207 + 'label' => __( 'Enables automatic publication of public ConvertKit Broadcasts as WordPress Posts.', 'convertkit' ),
183 208 'description' => $enabled_description,
184 209 )
185 210 );
186 211
@@ -195,8 +220,34 @@
195 220 );
196 221 }
197 222
198 223 add_settings_field(
224 + 'post_status',
225 + __( 'Status', 'convertkit' ),
226 + array( $this, 'post_status_callback' ),
227 + $this->settings_key,
228 + $this->name,
229 + array(
230 + 'name' => 'post_status',
231 + 'label_for' => 'post_status',
232 + 'description' => __( 'The WordPress Post status to assign imported public broadcasts to.', 'convertkit' ),
233 + )
234 + );
235 +
236 + add_settings_field(
237 + 'author_id',
238 + __( 'Author', 'convertkit' ),
239 + array( $this, 'author_id_callback' ),
240 + $this->settings_key,
241 + $this->name,
242 + array(
243 + 'name' => 'author_id',
244 + 'label_for' => 'author_id',
245 + 'description' => __( 'The WordPress User to set as the author for WordPress Posts created from imported public broadcasts.', 'convertkit' ),
246 + )
247 + );
248 +
249 + add_settings_field(
199 250 'category_id',
200 251 __( 'Category', 'convertkit' ),
201 252 array( $this, 'category_callback' ),
202 253 $this->settings_key,
@@ -202,13 +253,28 @@
202 253 $this->settings_key,
203 254 $this->name,
204 255 array(
205 256 'name' => 'category_id',
206 - 'description' => __( 'The category to assign imported broadcasts to.', 'convertkit' ),
257 + 'label_for' => 'category_id',
258 + 'description' => __( 'The category to assign imported public broadcasts to.', 'convertkit' ),
207 259 )
208 260 );
209 261
210 262 add_settings_field(
263 + 'import_thumbnail',
264 + __( 'Include Thumbnail', 'convertkit' ),
265 + array( $this, 'import_thumbnail_callback' ),
266 + $this->settings_key,
267 + $this->name,
268 + array(
269 + 'name' => 'import_thumbnail',
270 + 'label_for' => 'import_thumbnail',
271 + 'label' => __( 'If enabled, the Broadcast\'s thumbnail will be used as the WordPress Post\'s featured image.', 'convertkit' ),
272 + 'description' => '',
273 + )
274 + );
275 +
276 + add_settings_field(
211 277 'published_at_min_date',
212 278 __( 'Earliest Date', 'convertkit' ),
213 279 array( $this, 'date_callback' ),
214 280 $this->settings_key,
@@ -214,13 +280,27 @@
214 280 $this->settings_key,
215 281 $this->name,
216 282 array(
217 283 'name' => 'published_at_min_date',
218 - 'description' => __( 'The earliest date to import broadcasts from, based on the broadcast\'s published date and time.', 'convertkit' ),
284 + 'label_for' => 'published_at_min_date',
285 + 'description' => __( 'The earliest date to import public broadcasts from, based on the broadcast\'s published date and time.', 'convertkit' ),
219 286 )
220 287 );
221 288
222 289 add_settings_field(
290 + 'enabled_export',
291 + __( 'Enable Export Actions', 'convertkit' ),
292 + array( $this, 'enable_export_callback' ),
293 + $this->settings_key,
294 + $this->name,
295 + array(
296 + 'name' => 'enabled_export',
297 + 'label_for' => 'enabled_export',
298 + 'label' => __( 'Displays actions in WordPress to create draft broadcasts from existing WordPress posts.', 'convertkit' ),
299 + )
300 + );
301 +
302 + add_settings_field(
223 303 'no_styles',
224 304 __( 'Disable Styles', 'convertkit' ),
225 305 array( $this, 'no_styles_callback' ),
226 306 $this->settings_key,
@@ -226,9 +306,10 @@
226 306 $this->settings_key,
227 307 $this->name,
228 308 array(
229 309 'name' => 'no_styles',
230 - 'description' => __( 'Removes inline styles and layout when importing broadcasts.', 'convertkit' ),
310 + 'label_for' => 'no_styles',
311 + 'description' => __( 'Removes inline styles and layout when importing broadcasts and exporting posts.', 'convertkit' ),
231 312 )
232 313 );
233 314
234 315 }
@@ -241,9 +322,9 @@
241 322 public function print_section_info() {
242 323
243 324 ?>
244 325 <span class="convertkit-beta-label"><?php esc_html_e( 'Beta', 'convertkit' ); ?></span>
245 - <p class="description"><?php esc_html_e( 'Defines whether public broadcasts created in ConvertKit should automatically be published on this site as WordPress Posts.', 'convertkit' ); ?></p>
326 + <p class="description"><?php esc_html_e( 'Defines whether public broadcasts ("Enabled on public feeds") in ConvertKit should automatically be published on this site as WordPress Posts, and whether to enable options to create draft ConvertKit Broadcasts from WordPress Posts.', 'convertkit' ); ?></p>
246 327 <?php
247 328
248 329 }
249 330
@@ -302,8 +383,60 @@
302 383
303 384 }
304 385
305 386 /**
387 + * Renders the input for the status setting.
388 + *
389 + * @since 2.3.4
390 + *
391 + * @param array $args Setting field arguments (name,description).
392 + */
393 + public function post_status_callback( $args ) {
394 +
395 + // Build field.
396 + $select_field = $this->get_select_field(
397 + $args['name'],
398 + $this->settings->post_status(),
399 + get_post_statuses(),
400 + $args['description'],
401 + array(
402 + 'enabled',
403 + 'convertkit-select2',
404 + )
405 + );
406 +
407 + // Output field.
408 + echo '<div class="convertkit-select2-container">' . $select_field . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput
409 +
410 + }
411 +
412 + /**
413 + * Renders the input for the author setting.
414 + *
415 + * @since 2.3.9
416 + *
417 + * @param array $args Setting field arguments (name,description).
418 + */
419 + public function author_id_callback( $args ) {
420 +
421 + // Build field.
422 + $select_field = wp_dropdown_users(
423 + array(
424 + 'echo' => false,
425 + 'selected' => $this->settings->author_id(),
426 + 'include_selected' => true,
427 + 'name' => $this->settings_key . '[' . $args['name'] . ']',
428 + 'id' => $this->settings_key . '_' . $args['name'],
429 + 'class' => 'enabled convertkit-select2',
430 + )
431 + );
432 +
433 + // Output field.
434 + echo '<div class="convertkit-select2-container">' . $select_field . '</div>' . $this->get_description( $args['description'] ); // phpcs:ignore WordPress.Security.EscapeOutput
435 +
436 + }
437 +
438 + /**
306 439 * Renders the input for the category setting.
307 440 *
308 441 * @since 2.2.9
309 442 *
@@ -319,9 +452,9 @@
319 452 'hierarhical' => 1,
320 453 'name' => $this->settings_key . '[' . $args['name'] . ']',
321 454 'id' => $this->settings_key . '_' . $args['name'],
322 455 'class' => 'convertkit-select2 enabled',
323 - 'selected' => $this->settings->get_by_key( $args['name'] ),
456 + 'selected' => $this->settings->category_id(),
324 457 'taxonomy' => 'category',
325 458 'hide_empty' => false,
326 459 )
327 460 );
@@ -331,8 +464,31 @@
331 464
332 465 }
333 466
334 467 /**
468 + * Renders the input for the Import Thumbnail setting.
469 + *
470 + * @since 2.4.1
471 + *
472 + * @param array $args Setting field arguments (name,description).
473 + */
474 + public function import_thumbnail_callback( $args ) {
475 +
476 + // Output field.
477 + echo $this->get_checkbox_field( // phpcs:ignore WordPress.Security.EscapeOutput
478 + $args['name'],
479 + 'on',
480 + $this->settings->import_thumbnail(), // phpcs:ignore WordPress.Security.EscapeOutput
481 + $args['label'], // phpcs:ignore WordPress.Security.EscapeOutput
482 + $args['description'], // phpcs:ignore WordPress.Security.EscapeOutput
483 + array(
484 + 'enabled',
485 + )
486 + );
487 +
488 + }
489 +
490 + /**
335 491 * Renders the input for the date setting.
336 492 *
337 493 * @since 2.2.9
338 494 *
@@ -342,9 +498,9 @@
342 498
343 499 // Output field.
344 500 echo $this->get_date_field( // phpcs:ignore WordPress.Security.EscapeOutput
345 501 $args['name'],
346 - esc_attr( $this->settings->get_by_key( $args['name'] ) ),
502 + esc_attr( $this->settings->published_at_min_date() ),
347 503 $args['description'], // phpcs:ignore WordPress.Security.EscapeOutput
348 504 array(
349 505 'enabled',
350 506 )
@@ -352,8 +508,27 @@
352 508
353 509 }
354 510
355 511 /**
512 + * Renders the input for the Enable Export setting.
513 + *
514 + * @since 2.4.0
515 + *
516 + * @param array $args Setting field arguments (name,description).
517 + */
518 + public function enable_export_callback( $args ) {
519 +
520 + // Output field.
521 + echo $this->get_checkbox_field( // phpcs:ignore WordPress.Security.EscapeOutput
522 + $args['name'],
523 + 'on',
524 + $this->settings->enabled_export(), // phpcs:ignore WordPress.Security.EscapeOutput
525 + $args['label'] // phpcs:ignore WordPress.Security.EscapeOutput
526 + );
527 +
528 + }
529 +
530 + /**
356 531 * Renders the input for the No Styles setting.
357 532 *
358 533 * @since 2.2.9
359 534 *
@@ -365,14 +540,35 @@
365 540 echo $this->get_checkbox_field( // phpcs:ignore WordPress.Security.EscapeOutput
366 541 $args['name'],
367 542 'on',
368 543 $this->settings->no_styles(), // phpcs:ignore WordPress.Security.EscapeOutput
369 - $args['description'], // phpcs:ignore WordPress.Security.EscapeOutput
370 - '',
371 - array(
372 - 'enabled',
373 - )
544 + $args['description'] // phpcs:ignore WordPress.Security.EscapeOutput
374 545 );
546 +
547 + }
548 +
549 + /**
550 + * Sanitizes the settings prior to being saved.
551 + *
552 + * @since 2.4.1
553 + *
554 + * @param array $settings Submitted Settings Fields.
555 + * @return array Sanitized Settings with Defaults
556 + */
557 + public function sanitize_settings( $settings ) {
558 +
559 + // If the 'Include Thumbnail' setting isn't checked, it won't be included
560 + // in the array of settings, and the defaults will enable this.
561 + // Therefore, if the setting doesn't exist, set it to blank.
562 + if ( ! array_key_exists( 'import_thumbnail', $settings ) ) {
563 + $settings['import_thumbnail'] = '';
564 + }
565 +
566 + // Merge settings with defaults.
567 + $settings = wp_parse_args( $settings, $this->settings->get_defaults() );
568 +
569 + // Return settings to be saved.
570 + return $settings;
375 571
376 572 }
377 573
378 574 }