Skip to content

Commit 0e2d356

Browse files
chore: re-structure and PRO locks
1 parent 830a16a commit 0e2d356

File tree

4 files changed

+208
-126
lines changed

4 files changed

+208
-126
lines changed

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,18 +1330,26 @@ function ( $item ) {
13301330
);
13311331
break;
13321332
case 'schedules':
1333-
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1334-
$custom_schedules = isset( $_POST['fz-custom-schedule-interval'] ) ? (array) wp_unslash( $_POST['fz-custom-schedule-interval'] ) : array();
1335-
$settings['custom_schedules'] = array();
1336-
if ( ! empty( $custom_schedules ) ) {
1337-
foreach ( $custom_schedules as $key => $value ) {
1338-
$interval = isset( $value['interval'] ) ? absint( $value['interval'] ) : 0;
1339-
$display = isset( $value['display'] ) ? sanitize_text_field( $value['display'] ) : '';
1340-
if ( ! empty( $interval ) && ! empty( $display ) ) {
1341-
$settings['custom_schedules'][ $key ] = array(
1342-
'interval' => $interval,
1343-
'display' => $display,
1344-
);
1333+
if ( feedzy_is_pro() ) {
1334+
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1335+
$custom_schedules = isset( $_POST['fz-custom-schedule-interval'] ) ? (array) wp_unslash( $_POST['fz-custom-schedule-interval'] ) : array();
1336+
$settings['custom_schedules'] = array();
1337+
if ( ! empty( $custom_schedules ) ) {
1338+
$cron_timout = defined( 'WP_CRON_LOCK_TIMEOUT' ) ? WP_CRON_LOCK_TIMEOUT : 60;
1339+
1340+
foreach ( $custom_schedules as $key => $value ) {
1341+
$interval = isset( $value['interval'] ) ? absint( $value['interval'] ) : $cron_timout;
1342+
$display = isset( $value['display'] ) ? sanitize_text_field( $value['display'] ) : '';
1343+
1344+
if (
1345+
is_numeric( $interval ) && $cron_timout <= $interval &&
1346+
! empty( $display )
1347+
) {
1348+
$settings['custom_schedules'][ $key ] = array(
1349+
'interval' => $interval,
1350+
'display' => $display,
1351+
);
1352+
}
13451353
}
13461354
}
13471355
}
@@ -2937,6 +2945,9 @@ public function validate_feed() {
29372945
* @return array<string,array{interval:int,display:string}> Modified schedules with custom schedules appended.
29382946
*/
29392947
public function append_custom_cron_schedules( $schedules ) {
2948+
if ( ! feedzy_is_pro() ) {
2949+
return $schedules;
2950+
}
29402951

29412952
$saved_settings = apply_filters( 'feedzy_get_settings', array() );
29422953
if ( ! empty( $saved_settings['custom_schedules'] ) && is_array( $saved_settings['custom_schedules'] ) ) {
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
$custom_schedules = array();
3+
$has_pro = feedzy_is_pro();
4+
$settings = apply_filters( 'feedzy_get_settings', array() );
5+
6+
if ( isset( $settings['custom_schedules'] ) && is_array( $settings['custom_schedules'] ) ) {
7+
$custom_schedules = $settings['custom_schedules'];
8+
}
9+
?>
10+
<div class="fz-form-wrap">
11+
<div class="form-block">
12+
<div class="fz-form-group">
13+
<h4 class="h4">
14+
<?php esc_html_e( 'Add Cron Schedule', 'feedzy-rss-feeds' ); ?>
15+
<?php if ( ! $has_pro ) : ?>
16+
<span class="pro-label">PRO</span>
17+
<?php endif; ?>
18+
</h4>
19+
<div class="fz-condition-control" style="padding-bottom: 0;">
20+
<div class="fz-form-row" style="margin: 0; gap: 1rem; align-items: flex-end;">
21+
<div class="fz-form-group">
22+
<label class="form-label" for="fz-schedule-interval">
23+
<?php esc_html_e( 'Interval (seconds)', 'feedzy-rss-feeds' ); ?>
24+
</label>
25+
<input
26+
type="number"
27+
class="form-control"
28+
id="fz-schedule-interval"
29+
placeholder="3600"
30+
min="<?php echo esc_attr( defined( 'WP_CRON_LOCK_TIMEOUT' ) ? WP_CRON_LOCK_TIMEOUT : 60 ); ?>"
31+
<?php disabled( ! $has_pro ); ?>
32+
/>
33+
</div>
34+
35+
<div class="fz-form-group">
36+
<label class="form-label" for="fz-schedule-display">
37+
<?php esc_html_e( 'Display Name', 'feedzy-rss-feeds' ); ?>
38+
</label>
39+
<input
40+
type="text"
41+
class="form-control"
42+
id="fz-schedule-display"
43+
placeholder="Once Hourly"
44+
<?php disabled( ! $has_pro ); ?>
45+
/>
46+
</div>
47+
48+
<div class="fz-form-group">
49+
<label class="form-label" for="fz-schedule-name">
50+
<?php esc_html_e( 'Internal Name', 'feedzy-rss-feeds' ); ?>
51+
</label>
52+
<input
53+
type="text"
54+
class="form-control"
55+
id="fz-schedule-name"
56+
placeholder="hourly"
57+
<?php disabled( ! $has_pro ); ?>
58+
/>
59+
</div>
60+
<div class="fz-form-group">
61+
<button
62+
class="btn btn-primary"
63+
id="fz-add-schedule"
64+
<?php disabled( ! $has_pro ); ?>
65+
>
66+
<?php esc_html_e( 'Add Cron Schedule', 'feedzy-rss-feeds' ); ?>
67+
</button>
68+
</div>
69+
</div>
70+
</div>
71+
</div>
72+
</div>
73+
74+
<div
75+
class="form-block"
76+
>
77+
<div
78+
class="fz-schedules-table"
79+
style="<?php echo empty( $custom_schedules ) ? 'display: none;' : ''; ?>"
80+
>
81+
<div class="fz-schedule-counter">
82+
<?php
83+
$schedule_count = count( $custom_schedules );
84+
85+
// translators: %s is the number of custom schedules.
86+
echo esc_html( sprintf( __( '%s items', 'feedzy-rss-feeds' ), $schedule_count ) );
87+
?>
88+
</div>
89+
90+
<table class="fz-schedules-table widefat striped">
91+
<thead>
92+
<tr>
93+
<th><?php esc_html_e( 'Internal Name', 'feedzy-rss-feeds' ); ?></th>
94+
<th><?php esc_html_e( 'Interval', 'feedzy-rss-feeds' ); ?></th>
95+
<th><?php esc_html_e( 'Display Name', 'feedzy-rss-feeds' ); ?></th>
96+
<th><?php esc_html_e( 'Actions', 'feedzy-rss-feeds' ); ?></th>
97+
</tr>
98+
</thead>
99+
<tbody>
100+
<?php
101+
foreach ( $custom_schedules as $slug => $schedule ) :
102+
$interval_seconds = $schedule['interval'];
103+
$interval_display = $interval_seconds . ' (' . human_time_diff( 0, $interval_seconds ) . ')';
104+
?>
105+
<tr>
106+
<td class="fz-schedule-attributes">
107+
<strong><?php echo esc_html( $slug ); ?></strong>
108+
</td>
109+
110+
<td class="fz-schedule-attributes">
111+
<?php echo esc_html( $interval_display ); ?>
112+
</td>
113+
114+
<td class="fz-schedule-attributes">
115+
<?php echo esc_html( $schedule['display'] ); ?>
116+
</td>
117+
118+
<td class="fz-schedule-attributes">
119+
<button type="button" class="btn btn-outline-primary fz-delete-schedule fz-is-destructive" data-schedule="<?php echo esc_attr( $slug ); ?>">
120+
<?php esc_html_e( 'Delete', 'feedzy-rss-feeds' ); ?>
121+
</button>
122+
</td>
123+
124+
<input
125+
type="hidden"
126+
value="<?php echo esc_attr( $schedule['interval'] ); ?>"
127+
name="fz-custom-schedule-interval[<?php echo esc_attr( $slug ); ?>][interval]"
128+
>
129+
130+
<input
131+
type="hidden"
132+
value="<?php echo esc_attr( $schedule['display'] ); ?>"
133+
name="fz-custom-schedule-interval[<?php echo esc_attr( $slug ); ?>][display]"
134+
>
135+
</tr>
136+
<?php endforeach; ?>
137+
</tbody>
138+
</table>
139+
</div>
140+
</div>
141+
</div>

includes/layouts/settings.php

Lines changed: 4 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
$email_error_enabled = isset( $settings['logs'], $settings['logs']['send_email_report'] ) ? $settings['logs']['send_email_report'] : 0;
3333
$email_error_address_placeholder = ( ! empty( $email_error_address ) ) ? $email_error_address : get_option( 'admin_email' );
3434

35-
$custom_schedules = array();
36-
if ( isset( $settings['custom_schedules'] ) && is_array( $settings['custom_schedules'] ) ) {
37-
$custom_schedules = $settings['custom_schedules'];
38-
}
39-
4035
if ( 'logs' === $active_tab ) {
4136
$logs_type = isset( $_REQUEST['logs_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['logs_type'] ) ) : null;// phpcs:ignore WordPress.Security.NonceVerification
4237
$logs = Feedzy_Rss_Feeds_Log::get_instance()->get_recent_logs( 50, $logs_type );
@@ -110,6 +105,9 @@ class="<?php echo 'logs' === $active_tab ? esc_attr( 'active' ) : ''; ?>"
110105
class="<?php echo 'schedules' === $active_tab ? esc_attr( 'active' ) : ''; ?>"
111106
>
112107
<?php esc_html_e( 'Schedules', 'feedzy-rss-feeds' ); ?>
108+
<?php if ( ! feedzy_is_pro() ) : ?>
109+
<span class="pro-label">PRO</span>
110+
<?php endif; ?>
113111
</a>
114112
</li>
115113
<?php
@@ -505,115 +503,7 @@ class="form-control"
505503
$show_button = false;
506504
break;
507505
case 'schedules':
508-
?>
509-
<div class="fz-form-wrap">
510-
<div class="form-block">
511-
<div class="fz-form-group">
512-
<h4 class="h4">
513-
<?php esc_html_e( 'Add Cron Schedule', 'feedzy-rss-feeds' ); ?>
514-
</h4>
515-
<div class="fz-condition-control" style="padding-bottom: 0;">
516-
<div class="fz-form-row" style="margin: 0; gap: 1rem; align-items: flex-end;">
517-
<div class="fz-form-group">
518-
<label class="form-label" for="fz-schedule-interval">
519-
<?php esc_html_e( 'Interval (seconds)', 'feedzy-rss-feeds' ); ?>
520-
</label>
521-
<input
522-
type="number"
523-
class="form-control"
524-
id="fz-schedule-interval"
525-
placeholder="3600"
526-
required
527-
min="<?php echo esc_attr( defined( 'WP_CRON_LOCK_TIMEOUT' ) ? WP_CRON_LOCK_TIMEOUT : 60 ); ?>"
528-
/>
529-
</div>
530-
531-
<div class="fz-form-group">
532-
<label class="form-label" for="fz-schedule-display">
533-
<?php esc_html_e( 'Display Name', 'feedzy-rss-feeds' ); ?>
534-
</label>
535-
<input required type="text" class="form-control" id="fz-schedule-display" placeholder="Once Hourly" />
536-
</div>
537-
538-
<div class="fz-form-group">
539-
<label class="form-label" for="fz-schedule-name">
540-
<?php esc_html_e( 'Internal Name', 'feedzy-rss-feeds' ); ?>
541-
</label>
542-
<input required type="text" class="form-control" id="fz-schedule-name" placeholder="hourly" />
543-
</div>
544-
<div class="fz-form-group">
545-
<button class="btn btn-primary" id="fz-add-schedule">
546-
<?php esc_html_e( 'Add Cron Schedule', 'feedzy-rss-feeds' ); ?>
547-
</button>
548-
</div>
549-
</div>
550-
</div>
551-
</div>
552-
</div>
553-
554-
<div class="form-block">
555-
<div class="fz-schedule-counter">
556-
<?php
557-
$schedule_count = count( $custom_schedules );
558-
559-
// translators: %s is the number of custom schedules.
560-
echo esc_html( sprintf( __( '%s items', 'feedzy-rss-feeds' ), $schedule_count ) );
561-
?>
562-
</div>
563-
564-
<table class="fz-schedules-table widefat striped">
565-
<thead>
566-
<tr>
567-
<th><?php esc_html_e( 'Internal Name', 'feedzy-rss-feeds' ); ?></th>
568-
<th><?php esc_html_e( 'Interval', 'feedzy-rss-feeds' ); ?></th>
569-
<th><?php esc_html_e( 'Display Name', 'feedzy-rss-feeds' ); ?></th>
570-
<th><?php esc_html_e( 'Actions', 'feedzy-rss-feeds' ); ?></th>
571-
</tr>
572-
</thead>
573-
<tbody>
574-
<?php
575-
foreach ( $custom_schedules as $slug => $schedule ) :
576-
$interval_seconds = $schedule['interval'];
577-
$interval_display = $interval_seconds . ' (' . human_time_diff( 0, $interval_seconds ) . ')';
578-
?>
579-
<tr>
580-
<td class="fz-schedule-attributes">
581-
<strong><?php echo esc_html( $slug ); ?></strong>
582-
</td>
583-
584-
<td class="fz-schedule-attributes">
585-
<?php echo esc_html( $interval_display ); ?>
586-
</td>
587-
588-
<td class="fz-schedule-attributes">
589-
<?php echo esc_html( $schedule['display'] ); ?>
590-
</td>
591-
592-
<td class="fz-schedule-attributes">
593-
<button type="button" class="btn btn-outline-primary fz-delete-schedule fz-is-destructive" data-schedule="<?php echo esc_attr( $slug ); ?>">
594-
<?php esc_html_e( 'Delete', 'feedzy-rss-feeds' ); ?>
595-
</button>
596-
</td>
597-
598-
<input
599-
type="hidden"
600-
value="<?php echo esc_attr( $schedule['interval'] ); ?>"
601-
name="fz-custom-schedule-interval[<?php echo esc_attr( $slug ); ?>][interval]"
602-
>
603-
604-
<input
605-
type="hidden"
606-
value="<?php echo esc_attr( $schedule['display'] ); ?>"
607-
name="fz-custom-schedule-interval[<?php echo esc_attr( $slug ); ?>][display]"
608-
>
609-
</tr>
610-
<?php endforeach; ?>
611-
</tbody>
612-
</table>
613-
</div>
614-
615-
</div>
616-
<?php
506+
load_template( FEEDZY_ABSPATH . '/includes/layouts/feedzy-schedules.php' );
617507
break;
618508
default:
619509
$fields = apply_filters( 'feedzy_display_tab_settings', array(), $active_tab );

0 commit comments

Comments
 (0)