Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -2947,4 +2947,36 @@ button.feedzy-action-button {

#feedzy-validate-feed .dashicons {
font-size: 20px;
}
}

.fz-schedule-counter {
text-align: right;
margin-bottom: 10px;
color: #757575;
font-size: 13px;
}

.fz-schedules-table {
border-collapse: collapse;
}

.fz-schedules-table th {
font-weight: 600;
background: #f6f7f7;
}

.fz-schedules-table td {
padding: 10px;
}

.fz-schedule-attributes {
color: #050505;
}

.fz-delete-schedule.fz-is-destructive {
background: #dc3545;
border-color: #dc3545;
color: #ffffff;
font-size: 12px;
padding: 4px 12px;
}
55 changes: 55 additions & 0 deletions includes/admin/feedzy-rss-feeds-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public function enqueue_styles_admin() {
'media_iframe_button' => __( 'Set default image', 'feedzy-rss-feeds' ),
'action_btn_text_1' => __( 'Choose image', 'feedzy-rss-feeds' ),
'action_btn_text_2' => __( 'Replace image', 'feedzy-rss-feeds' ),
'delete_btn_label' => __( 'Delete', 'feedzy-rss-feeds' ),
),
)
);
Expand Down Expand Up @@ -1464,6 +1465,31 @@ function ( $item ) {
'pass' => isset( $_POST['proxy-pass'] ) ? sanitize_text_field( wp_unslash( $_POST['proxy-pass'] ) ) : '',
);
break;
case 'schedules':
if ( feedzy_is_pro() ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$custom_schedules = isset( $_POST['fz-custom-schedule-interval'] ) ? (array) wp_unslash( $_POST['fz-custom-schedule-interval'] ) : array();
$settings['custom_schedules'] = array();
if ( ! empty( $custom_schedules ) ) {
$cron_timout = defined( 'WP_CRON_LOCK_TIMEOUT' ) ? WP_CRON_LOCK_TIMEOUT : 60;

foreach ( $custom_schedules as $key => $value ) {
$interval = isset( $value['interval'] ) ? absint( $value['interval'] ) : $cron_timout;
$display = isset( $value['display'] ) ? sanitize_text_field( $value['display'] ) : '';

if (
is_numeric( $interval ) && $cron_timout <= $interval &&
! empty( $display )
) {
$settings['custom_schedules'][ $key ] = array(
'interval' => $interval,
'display' => $display,
);
}
}
}
}
break;
default:
$settings = apply_filters( 'feedzy_save_tab_settings', $settings, $post_tab );
}
Expand Down Expand Up @@ -3133,6 +3159,35 @@ public function validate_feed() {
}
}

/**
* Append custom schedules to the existing schedules.
*
* @since 5.1.0
* @param array<string,array{interval:int,display:string}> $schedules Existing schedules.
* @return array<string,array{interval:int,display:string}> Modified schedules with custom schedules appended.
*/
public function append_custom_cron_schedules( $schedules ) {
if ( ! feedzy_is_pro() ) {
return $schedules;
}

$saved_settings = apply_filters( 'feedzy_get_settings', array() );
if ( ! empty( $saved_settings['custom_schedules'] ) && is_array( $saved_settings['custom_schedules'] ) ) {
$custom_schedules = $saved_settings['custom_schedules'];

foreach ( $custom_schedules as $key => $value ) {
if ( ! empty( $value['interval'] ) && ! empty( $value['display'] ) ) {
$schedules[ $key ] = array(
'interval' => intval( $value['interval'] ),
'display' => sanitize_text_field( $value['display'] ),
);
}
}
}

return $schedules;
}

/**
* Add slugs for internal cron schedules.
*
Expand Down
1 change: 1 addition & 0 deletions includes/feedzy-rss-feeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ private function define_admin_hooks() {
self::$instance->loader->add_action( 'wp_ajax_feedzy_validate_feed', self::$instance->admin, 'validate_feed' );
self::$instance->loader->add_action( 'wp_ajax_feedzy_dashboard_subscribe', self::$instance->admin, 'feedzy_dashboard_subscribe' );
self::$instance->loader->add_filter( 'feedzy_internal_cron_schedule_slugs', self::$instance->admin, 'internal_cron_schedule_slugs', 10, 1 );
self::$instance->loader->add_filter( 'cron_schedules', self::$instance->admin, 'append_custom_cron_schedules' );

// do not load this with the loader as this will need a corresponding remove_filter also.
add_filter( 'update_post_metadata', array( self::$instance->admin, 'validate_category_feeds' ), 10, 5 );
Expand Down
141 changes: 141 additions & 0 deletions includes/layouts/feedzy-schedules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php
$custom_schedules = array();
$has_pro = feedzy_is_pro();
$settings = apply_filters( 'feedzy_get_settings', array() );

if ( isset( $settings['custom_schedules'] ) && is_array( $settings['custom_schedules'] ) ) {
$custom_schedules = $settings['custom_schedules'];
}
?>
<div class="fz-form-wrap">
<div class="form-block">
<div class="fz-form-group">
<h4 class="h4">
<?php esc_html_e( 'Add Cron Schedule', 'feedzy-rss-feeds' ); ?>
<?php if ( ! $has_pro ) : ?>
<span class="pro-label">PRO</span>
<?php endif; ?>
</h4>
<div class="fz-condition-control" style="padding-bottom: 0;">
<div class="fz-form-row" style="margin: 0; gap: 1rem; align-items: flex-end;">
<div class="fz-form-group">
<label class="form-label" for="fz-schedule-interval">
<?php esc_html_e( 'Interval (seconds)', 'feedzy-rss-feeds' ); ?>
</label>
<input
type="number"
class="form-control"
id="fz-schedule-interval"
placeholder="3600"
min="<?php echo esc_attr( defined( 'WP_CRON_LOCK_TIMEOUT' ) ? WP_CRON_LOCK_TIMEOUT : 60 ); ?>"
<?php disabled( ! $has_pro ); ?>
/>
</div>

<div class="fz-form-group">
<label class="form-label" for="fz-schedule-display">
<?php esc_html_e( 'Display Name', 'feedzy-rss-feeds' ); ?>
</label>
<input
type="text"
class="form-control"
id="fz-schedule-display"
placeholder="Once Hourly"
<?php disabled( ! $has_pro ); ?>
/>
</div>

<div class="fz-form-group">
<label class="form-label" for="fz-schedule-name">
<?php esc_html_e( 'Internal Name', 'feedzy-rss-feeds' ); ?>
</label>
<input
type="text"
class="form-control"
id="fz-schedule-name"
placeholder="hourly"
<?php disabled( ! $has_pro ); ?>
/>
</div>
<div class="fz-form-group">
<button
class="btn btn-primary"
id="fz-add-schedule"
<?php disabled( ! $has_pro ); ?>
>
<?php esc_html_e( 'Add Cron Schedule', 'feedzy-rss-feeds' ); ?>
</button>
</div>
</div>
</div>
</div>
</div>

<div
class="form-block"
>
<div
class="fz-schedules-table"
style="<?php echo empty( $custom_schedules ) || ! $has_pro ? 'display: none;' : ''; ?>"
>
<div class="fz-schedule-counter">
<?php
$schedule_count = count( $custom_schedules );

// translators: %s is the number of custom schedules.
echo esc_html( sprintf( __( '%s items', 'feedzy-rss-feeds' ), $schedule_count ) );
?>
</div>

<table class="fz-schedules-table widefat striped">
<thead>
<tr>
<th><?php esc_html_e( 'Internal Name', 'feedzy-rss-feeds' ); ?></th>
<th><?php esc_html_e( 'Interval', 'feedzy-rss-feeds' ); ?></th>
<th><?php esc_html_e( 'Display Name', 'feedzy-rss-feeds' ); ?></th>
<th><?php esc_html_e( 'Actions', 'feedzy-rss-feeds' ); ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ( $custom_schedules as $slug => $schedule ) :
$interval_seconds = $schedule['interval'];
$interval_display = $interval_seconds . ' (' . human_time_diff( 0, $interval_seconds ) . ')';
?>
<tr>
<td class="fz-schedule-attributes">
<strong><?php echo esc_html( $slug ); ?></strong>
</td>

<td class="fz-schedule-attributes">
<?php echo esc_html( $interval_display ); ?>
</td>

<td class="fz-schedule-attributes">
<?php echo esc_html( $schedule['display'] ); ?>
</td>

<td class="fz-schedule-attributes">
<button type="button" class="btn btn-outline-primary fz-delete-schedule fz-is-destructive" data-schedule="<?php echo esc_attr( $slug ); ?>">
<?php esc_html_e( 'Delete', 'feedzy-rss-feeds' ); ?>
</button>
</td>

<input
type="hidden"
value="<?php echo esc_attr( $schedule['interval'] ); ?>"
name="fz-custom-schedule-interval[<?php echo esc_attr( $slug ); ?>][interval]"
>

<input
type="hidden"
value="<?php echo esc_attr( $schedule['display'] ); ?>"
name="fz-custom-schedule-interval[<?php echo esc_attr( $slug ); ?>][display]"
>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
16 changes: 15 additions & 1 deletion includes/layouts/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ class="<?php echo 'logs' === $active_tab ? esc_attr( 'active' ) : ''; ?>"
<?php esc_html_e( 'Logs', 'feedzy-rss-feeds' ); ?>
</a>
</li>
<li>
<a
href="<?php echo esc_url( admin_url( 'admin.php?page=feedzy-settings&tab=schedules' ) ); ?>"
class="<?php echo 'schedules' === $active_tab ? esc_attr( 'active' ) : ''; ?>"
>
<?php esc_html_e( 'Schedules', 'feedzy-rss-feeds' ); ?>
<?php if ( ! feedzy_is_pro() ) : ?>
<span class="pro-label">PRO</span>
<?php endif; ?>
</a>
</li>
<?php
$_tabs = apply_filters( 'feedzy_settings_tabs', array() );
if ( $_tabs ) {
Expand Down Expand Up @@ -506,6 +517,9 @@ class="form-control"
case 'logs':
$show_button = false;
break;
case 'schedules':
load_template( FEEDZY_ABSPATH . '/includes/layouts/feedzy-schedules.php' );
break;
default:
$fields = apply_filters( 'feedzy_display_tab_settings', array(), $active_tab );
if ( $fields ) {
Expand Down Expand Up @@ -543,7 +557,7 @@ class="form-control"
</div>
</div>

<?php if ( 'proxy' !== $active_tab && 'headers' !== $active_tab ) : ?>
<?php if ( 'proxy' !== $active_tab && 'headers' !== $active_tab && 'schedules' !== $active_tab ) : ?>
<div class="cta pt-30">
<a href="<?php echo esc_url( $help_btn_url ); ?>" class="btn btn-ghost" target="_blank"><?php esc_html_e( 'Need help?', 'feedzy-rss-feeds' ); ?></a>
</div>
Expand Down
Loading
Loading