Skip to content

Commit a0ed1a8

Browse files
refactor: UI for Schedule option in Settings (#1141)
1 parent 7ec9487 commit a0ed1a8

4 files changed

Lines changed: 47 additions & 7 deletions

File tree

includes/admin/feedzy-rss-feeds-admin.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,4 +3132,21 @@ public function validate_feed() {
31323132
);
31333133
}
31343134
}
3135+
3136+
/**
3137+
* Add slugs for internal cron schedules.
3138+
*
3139+
* @param string[] $cron_slugs The cron slugs to be modified.
3140+
* @return string[]
3141+
*/
3142+
public function internal_cron_schedule_slugs( $cron_slugs ) {
3143+
$wp_standard_schedules = array(
3144+
'hourly',
3145+
'twicedaily',
3146+
'daily',
3147+
'weekly',
3148+
);
3149+
3150+
return array_merge( $wp_standard_schedules, $cron_slugs );
3151+
}
31353152
}

includes/feedzy-rss-feeds.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ private function define_admin_hooks() {
205205
self::$instance->loader->add_action( 'init', self::$instance->admin, 'register_settings' );
206206
self::$instance->loader->add_action( 'wp_ajax_feedzy_validate_feed', self::$instance->admin, 'validate_feed' );
207207
self::$instance->loader->add_action( 'wp_ajax_feedzy_dashboard_subscribe', self::$instance->admin, 'feedzy_dashboard_subscribe' );
208+
self::$instance->loader->add_filter( 'feedzy_internal_cron_schedule_slugs', self::$instance->admin, 'internal_cron_schedule_slugs', 10, 1 );
208209

209210
// do not load this with the loader as this will need a corresponding remove_filter also.
210211
add_filter( 'update_post_metadata', array( self::$instance->admin, 'validate_category_feeds' ), 10, 5 );

includes/layouts/settings.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class="btn btn-outline-primary<?php echo 0 === $index ? ' disabled' : ''; ?>" <?
258258
<div class="fz-form-row">
259259
<div class="fz-form-col-6">
260260
<div class="fz-form-group">
261-
<label class="form-label"><?php esc_html_e( 'Schedule', 'feedzy-rss-feeds' ); ?></label>
261+
<label class="form-label"><?php esc_html_e( 'Default Importing Schedule', 'feedzy-rss-feeds' ); ?></label>
262262
<?php
263263
$save_schedule = ! empty( $settings['general']['fz_cron_schedule'] ) ? $settings['general']['fz_cron_schedule'] : '';
264264

@@ -268,20 +268,34 @@ class="btn btn-outline-primary<?php echo 0 === $index ? ' disabled' : ''; ?>" <?
268268
unset( $schedules['hourly'] );
269269
$schedules = array_merge( array( 'hourly' => $hourly ), $schedules );
270270
}
271+
$internal_cron_schedules = apply_filters( 'feedzy_internal_cron_schedule_slugs', array() );
271272
?>
272273
<select id="fz-event-schedule" class="form-control fz-select-control" name="fz_cron_schedule">
273274
<?php
274275
$duplicate_schedule = array();
275276
foreach ( $schedules as $slug => $schedule ) :
276-
if ( empty( $schedule['interval'] ) || in_array( $schedule['interval'], $duplicate_schedule, true ) ) {
277+
if (
278+
empty( $schedule['interval'] ) ||
279+
in_array( $schedule['interval'], $duplicate_schedule, true )
280+
) {
277281
continue;
278282
}
279283
$duplicate_schedule[] = $schedule['interval'];
284+
$display_text = $schedule['display'];
285+
286+
if ( ! in_array( $slug, $internal_cron_schedules, true ) ) {
287+
// translators: (externally created) is used to indicate that the schedule is created by another plugin or manually.
288+
$display_text .= ' (' . esc_html__( 'externally created', 'feedzy-rss-feeds' ) . ')';
289+
}
280290
?>
281-
<option value="<?php echo esc_attr( $slug ); ?>"<?php selected( $save_schedule, $slug ); ?>><?php echo esc_html( $schedule['display'] ); ?> (<?php echo esc_html( $slug ); ?>)</option>
291+
<option
292+
value="<?php echo esc_attr( $slug ); ?>"
293+
<?php selected( $save_schedule, $slug ); ?>
294+
>
295+
<?php echo esc_html( $display_text ); ?>
296+
</option>
282297
<?php endforeach; ?>
283298
</select>
284-
<div class="help-text pt-8"><?php esc_html_e( 'How often Feedzy will run the import.', 'feedzy-rss-feeds' ); ?></div>
285299
</div>
286300
</div>
287301
</div>

includes/views/import-metabox-edit.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,20 +672,28 @@ class="fz-switch-toggle" type="checkbox" value="yes"
672672
unset( $schedules['daily'] );
673673
$schedules = array_merge( array( 'daily' => $daily ), $schedules );
674674
}
675-
$duplicate_schedule = array();
675+
$internal_cron_schedules = apply_filters( 'feedzy_internal_cron_schedule_slugs', array() );
676+
$duplicate_schedule = array();
676677
foreach ( $schedules as $slug => $schedule ) :
677678
if ( empty( $schedule['interval'] ) || in_array( $schedule['interval'], $duplicate_schedule, true ) ) {
678679
continue;
679680
}
680681
$duplicate_schedule[] = $schedule['interval'];
682+
$display_text = $schedule['display'];
683+
684+
if ( ! in_array( $slug, $internal_cron_schedules, true ) ) {
685+
$display_text .= ' (' . esc_html__( 'externally created)', 'feedzy-rss-feeds' ) . ')';
686+
}
681687
?>
682688
<option data-slug="<?php echo esc_attr( $slug ); ?>" value="<?php echo esc_attr( $slug ); ?>"<?php selected( $save_schedule, $slug ); ?>
683689
>
684-
<?php echo esc_html( $schedule['display'] ); ?>
690+
<?php echo esc_html( $display_text ); ?>
685691
</option>
686692
<?php endforeach; ?>
687693
</select>
688-
<div class="help-text pt-8"><?php esc_html_e( 'Choose how often Feedzy should import new items from your feeds.', 'feedzy-rss-feeds' ); ?></div>
694+
<div class="help-text pt-8">
695+
<?php esc_html_e( 'Choose how often Feedzy should import new items from your feeds.', 'feedzy-rss-feeds' ); ?>
696+
</div>
689697
</div>
690698
</div>
691699
</div>

0 commit comments

Comments
 (0)