|
@@ -35,27 +35,27 @@ discard block |
|
|
block discarded – undo |
|
35
|
35
|
/** |
|
36
|
36
|
* Setup the actions and filters required by this class. |
|
37
|
37
|
*/ |
|
38
|
|
-add_action( 'post_submitbox_misc_actions', __NAMESPACE__ . '\publish_box_ui' ); |
|
39
|
|
-add_action( 'save_post', __NAMESPACE__ . '\save_post_repeating_status', 10 ); |
|
40
|
|
-add_action( 'save_post', __NAMESPACE__ . '\create_next_repeat_post', 11 ); |
|
41
|
|
-add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\enqueue_scripts' ); |
|
42
|
|
-add_filter( 'display_post_states', __NAMESPACE__ . '\post_states', 10, 2 ); |
|
|
38
|
+add_action('post_submitbox_misc_actions', __NAMESPACE__.'\publish_box_ui'); |
|
|
39
|
+add_action('save_post', __NAMESPACE__.'\save_post_repeating_status', 10); |
|
|
40
|
+add_action('save_post', __NAMESPACE__.'\create_next_repeat_post', 11); |
|
|
41
|
+add_action('admin_enqueue_scripts', __NAMESPACE__.'\enqueue_scripts'); |
|
|
42
|
+add_filter('display_post_states', __NAMESPACE__.'\post_states', 10, 2); |
|
43
|
43
|
|
|
44
|
44
|
/** |
|
45
|
45
|
* Enqueue the scripts and styles that are needed by this plugin. |
|
46
|
46
|
*/ |
|
47
|
|
-function enqueue_scripts( $hook ) { |
|
|
47
|
+function enqueue_scripts($hook) { |
|
48
|
48
|
|
|
49
|
49
|
// Ensure we only load them on the edit post and add new post admin screens |
|
50
|
|
- if ( ! in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) { |
|
|
50
|
+ if ( ! in_array($hook, array('post.php', 'post-new.php'))) { |
|
51
|
51
|
return; |
|
52
|
52
|
} |
|
53
|
53
|
|
|
54
|
|
- $plugin_data = get_plugin_data( __FILE__ ); |
|
55
|
|
- $plugin_dir_url = plugin_dir_url( __FILE__ ); |
|
|
54
|
+ $plugin_data = get_plugin_data(__FILE__); |
|
|
55
|
+ $plugin_dir_url = plugin_dir_url(__FILE__); |
|
56
|
56
|
|
|
57
|
|
- wp_enqueue_script( 'hm-post-repeat', $plugin_dir_url . 'hm-post-repeat.js', 'jquery', $plugin_data['Version'], true ); |
|
58
|
|
- wp_enqueue_style( 'hm-post-repeat', $plugin_dir_url . 'hm-post-repeat.css', array(), $plugin_data['Version'] ); |
|
|
57
|
+ wp_enqueue_script('hm-post-repeat', $plugin_dir_url.'hm-post-repeat.js', 'jquery', $plugin_data['Version'], true); |
|
|
58
|
+ wp_enqueue_style('hm-post-repeat', $plugin_dir_url.'hm-post-repeat.css', array(), $plugin_data['Version']); |
|
59
|
59
|
|
|
60
|
60
|
} |
|
61
|
61
|
|
|
@@ -67,7 +67,7 @@ discard block |
|
|
block discarded – undo |
|
67
|
67
|
*/ |
|
68
|
68
|
function publish_box_ui() { |
|
69
|
69
|
|
|
70
|
|
- if ( ! in_array( get_post_type(), repeating_post_types() ) ) { |
|
|
70
|
+ if ( ! in_array(get_post_type(), repeating_post_types())) { |
|
71
|
71
|
return; |
|
72
|
72
|
} ?> |
|
73
|
73
|
|
|
@@ -75,22 +75,22 @@ discard block |
|
|
block discarded – undo |
|
75
|
75
|
|
|
76
|
76
|
<span class="dashicons dashicons-controls-repeat"></span> |
|
77
|
77
|
|
|
78
|
|
- <?php esc_html_e( 'Repeat:', 'hm-post-repeat' ); ?> |
|
|
78
|
+ <?php esc_html_e('Repeat:', 'hm-post-repeat'); ?> |
|
79
|
79
|
|
|
80
|
|
- <?php if ( is_repeat_post( get_the_id() ) ) : ?> |
|
|
80
|
+ <?php if (is_repeat_post(get_the_id())) : ?> |
|
81
|
81
|
|
|
82
|
|
- <strong><?php printf( esc_html__( 'Repeat of %s', 'hm-post-repeat' ), '<a href="' . esc_url( get_edit_post_link( get_post()->post_parent ) ) . '">' . esc_html( get_the_title( get_post_field( 'post_parent', get_the_id() ) ) ) . '</a>' ); ?></strong> |
|
|
82
|
+ <strong><?php printf(esc_html__('Repeat of %s', 'hm-post-repeat'), '<a href="'.esc_url(get_edit_post_link(get_post()->post_parent)).'">'.esc_html(get_the_title(get_post_field('post_parent', get_the_id()))).'</a>'); ?></strong> |
|
83
|
83
|
|
|
84
|
84
|
<?php else : ?> |
|
85
|
85
|
|
|
86
|
86
|
<?php |
|
87
|
87
|
|
|
88
|
|
- $repeating_schedule = get_repeating_schedule( get_the_id() ); |
|
89
|
|
- $is_repeating_post = is_repeating_post( get_the_id() ) && isset( $repeating_schedule ); |
|
|
88
|
+ $repeating_schedule = get_repeating_schedule(get_the_id()); |
|
|
89
|
+ $is_repeating_post = is_repeating_post(get_the_id()) && isset($repeating_schedule); |
|
90
|
90
|
|
|
91
|
|
- $post_repeat_end = get_post_repeat_end_from_post_meta( get_the_id() ); |
|
92
|
|
- if ( is_null( $post_repeat_end ) ) { |
|
93
|
|
- $post_repeat_end = array( 'type' => 'forever' ); |
|
|
91
|
+ $post_repeat_end = get_post_repeat_end_from_post_meta(get_the_id()); |
|
|
92
|
+ if (is_null($post_repeat_end)) { |
|
|
93
|
+ $post_repeat_end = array('type' => 'forever'); |
|
94
|
94
|
} |
|
95
|
95
|
|
|
96
|
96
|
?> |
|
@@ -98,36 +98,36 @@ discard block |
|
|
block discarded – undo |
|
98
|
98
|
<strong> |
|
99
|
99
|
<?php |
|
100
|
100
|
|
|
101
|
|
- if ( $is_repeating_post ) { |
|
102
|
|
- echo esc_html( $repeating_schedule['display'] ) . ', '; |
|
|
101
|
+ if ($is_repeating_post) { |
|
|
102
|
+ echo esc_html($repeating_schedule['display']).', '; |
|
103
|
103
|
|
|
104
|
|
- switch ( $post_repeat_end['type'] ) { |
|
|
104
|
+ switch ($post_repeat_end['type']) { |
|
105
|
105
|
case 'forever': |
|
106
|
|
- esc_html_e( 'Forever', 'hm-post-repeat' ); |
|
|
106
|
+ esc_html_e('Forever', 'hm-post-repeat'); |
|
107
|
107
|
break; |
|
108
|
108
|
case 'until': |
|
109
|
|
- echo esc_html( sprintf( __( 'Until %s', 'hm-post-repeat' ), date_i18n( 'M j, Y', $post_repeat_end['value'] ) ) ); |
|
|
109
|
+ echo esc_html(sprintf(__('Until %s', 'hm-post-repeat'), date_i18n('M j, Y', $post_repeat_end['value']))); |
|
110
|
110
|
break; |
|
111
|
111
|
case 'times': |
|
112
|
|
- echo esc_html( sprintf( __( '%d Times', 'hm-post-repeat' ), $post_repeat_end['value'] ) ); |
|
|
112
|
+ echo esc_html(sprintf(__('%d Times', 'hm-post-repeat'), $post_repeat_end['value'])); |
|
113
|
113
|
break; |
|
114
|
114
|
} |
|
115
|
115
|
} else { |
|
116
|
|
- esc_html_e( 'No', 'hm-post-repeat' ); |
|
|
116
|
+ esc_html_e('No', 'hm-post-repeat'); |
|
117
|
117
|
} |
|
118
|
118
|
|
|
119
|
119
|
?> |
|
120
|
120
|
</strong> |
|
121
|
121
|
|
|
122
|
|
- <a href="#hm-post-repeat" class="edit-hm-post-repeat hide-if-no-js"><span aria-hidden="true"><?php esc_html_e( 'Edit', 'hm-post-repeat' ); ?></span> <span class="screen-reader-text"><?php esc_html_e( 'Edit Repeat Settings', 'hm-post-repeat' ); ?></span></a> |
|
|
122
|
+ <a href="#hm-post-repeat" class="edit-hm-post-repeat hide-if-no-js"><span aria-hidden="true"><?php esc_html_e('Edit', 'hm-post-repeat'); ?></span> <span class="screen-reader-text"><?php esc_html_e('Edit Repeat Settings', 'hm-post-repeat'); ?></span></a> |
|
123
|
123
|
|
|
124
|
124
|
<span class="hide-if-js" id="hm-post-repeat"> |
|
125
|
125
|
|
|
126
|
|
- <input type="hidden" id="hidden_hm-post-repeat-schedule" name="hidden_hm-post-repeat-schedule" value="<?php echo ( isset( $repeating_schedule['slug'] ) ) ? esc_attr( $repeating_schedule['slug'] ) : 'no'; ?>" /> |
|
|
126
|
+ <input type="hidden" id="hidden_hm-post-repeat-schedule" name="hidden_hm-post-repeat-schedule" value="<?php echo (isset($repeating_schedule['slug'])) ? esc_attr($repeating_schedule['slug']) : 'no'; ?>" /> |
|
127
|
127
|
<select id="hm-post-repeat-schedule" name="hm-post-repeat-schedule"> |
|
128
|
|
- <option<?php selected( ! $is_repeating_post ); ?> value="no"><?php esc_html_e( 'No', 'hm-post-repeat' ); ?></option> |
|
129
|
|
- <?php foreach ( get_repeating_schedules() as $schedule_slug => $schedule ) : ?> |
|
130
|
|
- <option<?php selected( $is_repeating_post && ( $schedule_slug === $repeating_schedule['slug'] ) ); ?> value="<?php echo esc_attr( $schedule_slug ); ?>"><?php echo esc_html( $schedule['display'] ); ?></option> |
|
|
128
|
+ <option<?php selected( ! $is_repeating_post); ?> value="no"><?php esc_html_e('No', 'hm-post-repeat'); ?></option> |
|
|
129
|
+ <?php foreach (get_repeating_schedules() as $schedule_slug => $schedule) : ?> |
|
|
130
|
+ <option<?php selected($is_repeating_post && ($schedule_slug === $repeating_schedule['slug'])); ?> value="<?php echo esc_attr($schedule_slug); ?>"><?php echo esc_html($schedule['display']); ?></option> |
|
131
|
131
|
<?php endforeach; ?> |
|
132
|
132
|
</select> |
|
133
|
133
|
|
|
@@ -135,27 +135,27 @@ discard block |
|
|
block discarded – undo |
|
135
|
135
|
|
|
136
|
136
|
<p> |
|
137
|
137
|
<label> |
|
138
|
|
- <input type="radio" name="hm-post-repeat-end" value="forever"<?php checked( $post_repeat_end['type'], 'forever' ); ?>><?php esc_html_e( 'Forever', 'hm-post-repeat' ); ?> |
|
|
138
|
+ <input type="radio" name="hm-post-repeat-end" value="forever"<?php checked($post_repeat_end['type'], 'forever'); ?>><?php esc_html_e('Forever', 'hm-post-repeat'); ?> |
|
139
|
139
|
</label> |
|
140
|
140
|
</p> |
|
141
|
141
|
<p> |
|
142
|
142
|
<label> |
|
143
|
|
- <input type="radio" name="hm-post-repeat-end" value="until"<?php checked( $post_repeat_end['type'], 'until' ); ?>><?php esc_html_e( 'Until', 'hm-post-repeat' ); ?> |
|
|
143
|
+ <input type="radio" name="hm-post-repeat-end" value="until"<?php checked($post_repeat_end['type'], 'until'); ?>><?php esc_html_e('Until', 'hm-post-repeat'); ?> |
|
144
|
144
|
</label> |
|
145
|
|
- <?php hm_date_input( ( 'until' === $post_repeat_end['type'] ) ? $post_repeat_end['value'] : time() ); ?> |
|
|
145
|
+ <?php hm_date_input(('until' === $post_repeat_end['type']) ? $post_repeat_end['value'] : time()); ?> |
|
146
|
146
|
</p> |
|
147
|
147
|
<p> |
|
148
|
148
|
<label> |
|
149
|
|
- <input type="radio" name="hm-post-repeat-end" value="times"<?php checked( $post_repeat_end['type'], 'times' ); ?>> |
|
150
|
|
- <input type="number" id="hm-post-repeat-times" name="hm-post-repeat-times" min="1" value="<?php echo ( 'times' === $post_repeat_end['type'] ) ? $post_repeat_end['value'] : '1'; ?>" /><?php esc_html_e( 'Times', 'hm-post-repeat' ); ?> |
|
|
149
|
+ <input type="radio" name="hm-post-repeat-end" value="times"<?php checked($post_repeat_end['type'], 'times'); ?>> |
|
|
150
|
+ <input type="number" id="hm-post-repeat-times" name="hm-post-repeat-times" min="1" value="<?php echo ('times' === $post_repeat_end['type']) ? $post_repeat_end['value'] : '1'; ?>" /><?php esc_html_e('Times', 'hm-post-repeat'); ?> |
|
151
|
151
|
</label> |
|
152
|
152
|
</p> |
|
153
|
153
|
|
|
154
|
154
|
</div> |
|
155
|
155
|
|
|
156
|
156
|
<p> |
|
157
|
|
- <a href="#edit-hm-post-repeat" class="save-post-hm-post-repeat hide-if-no-js button"><?php esc_html_e( 'OK', 'hm-post-repeat' ); ?></a> |
|
158
|
|
- <a href="#edit-hm-post-repeat" class="cancel-post-hm-post-repeat hide-if-no-js button-cancel"><?php esc_html_e( 'Cancel', 'hm-post-repeat' ); ?></a> |
|
|
157
|
+ <a href="#edit-hm-post-repeat" class="save-post-hm-post-repeat hide-if-no-js button"><?php esc_html_e('OK', 'hm-post-repeat'); ?></a> |
|
|
158
|
+ <a href="#edit-hm-post-repeat" class="cancel-post-hm-post-repeat hide-if-no-js button-cancel"><?php esc_html_e('Cancel', 'hm-post-repeat'); ?></a> |
|
159
|
159
|
</p> |
|
160
|
160
|
|
|
161
|
161
|
</span> |
|
@@ -167,7 +167,7 @@ discard block |
|
|
block discarded – undo |
|
167
|
167
|
<?php } |
|
168
|
168
|
|
|
169
|
169
|
|
|
170
|
|
-function hm_date_input( $date ) { |
|
|
170
|
+function hm_date_input($date) { |
|
171
|
171
|
|
|
172
|
172
|
global $wp_locale; |
|
173
|
173
|
|
|
@@ -178,48 +178,48 @@ discard block |
|
|
block discarded – undo |
|
178
|
178
|
'repeat' => 'until 2016-01-01', |
|
179
|
179
|
];*/ |
|
180
|
180
|
|
|
181
|
|
- if ( is_numeric( $date ) ) { |
|
182
|
|
- $date = date( 'Y-m-d', $date ); |
|
|
181
|
+ if (is_numeric($date)) { |
|
|
182
|
+ $date = date('Y-m-d', $date); |
|
183
|
183
|
} |
|
184
|
184
|
|
|
185
|
|
- $cur_date = current_time( 'timestamp' ); |
|
186
|
|
- $cur_d = gmdate( 'd', $cur_date ); |
|
187
|
|
- $cur_m = gmdate( 'm', $cur_date ); |
|
188
|
|
- $cur_Y = gmdate( 'Y', $cur_date ); |
|
|
185
|
+ $cur_date = current_time('timestamp'); |
|
|
186
|
+ $cur_d = gmdate('d', $cur_date); |
|
|
187
|
+ $cur_m = gmdate('m', $cur_date); |
|
|
188
|
+ $cur_Y = gmdate('Y', $cur_date); |
|
189
|
189
|
|
|
190
|
|
- $d = ( $date ) ? mysql2date( 'd', $date, false ) : gmdate( 'd', $cur_d ); |
|
191
|
|
- $m = ( $date ) ? mysql2date( 'm', $date, false ) : gmdate( 'm', $cur_m ); |
|
192
|
|
- $Y = ( $date ) ? mysql2date( 'Y', $date, false ) : gmdate( 'Y', $cur_Y ); |
|
|
190
|
+ $d = ($date) ? mysql2date('d', $date, false) : gmdate('d', $cur_d); |
|
|
191
|
+ $m = ($date) ? mysql2date('m', $date, false) : gmdate('m', $cur_m); |
|
|
192
|
+ $Y = ($date) ? mysql2date('Y', $date, false) : gmdate('Y', $cur_Y); |
|
193
|
193
|
|
|
194
|
|
- $month = '<label><span class="screen-reader-text">' . __( 'Month', 'hm-post-repeat' ) . '</span><select id="hm-post-repeat-until-month" name="hm-post-repeat-until-month">'; |
|
195
|
|
- for ( $i = 1; $i < 13; $i++ ) { |
|
196
|
|
- $monthnum = zeroise( $i, 2 ); |
|
197
|
|
- $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ); |
|
198
|
|
- $month .= '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $m, false ) . '>'; |
|
|
194
|
+ $month = '<label><span class="screen-reader-text">'.__('Month', 'hm-post-repeat').'</span><select id="hm-post-repeat-until-month" name="hm-post-repeat-until-month">'; |
|
|
195
|
+ for ($i = 1; $i < 13; $i++) { |
|
|
196
|
+ $monthnum = zeroise($i, 2); |
|
|
197
|
+ $monthtext = $wp_locale->get_month_abbrev($wp_locale->get_month($i)); |
|
|
198
|
+ $month .= '<option value="'.$monthnum.'" data-text="'.$monthtext.'" '.selected($monthnum, $m, false).'>'; |
|
199
|
199
|
/* translators: 1: month number (01, 02, etc.), 2: month abbreviation */ |
|
200
|
|
- $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $monthtext ) . "</option>\n"; |
|
|
200
|
+ $month .= sprintf(__('%1$s-%2$s'), $monthnum, $monthtext)."</option>\n"; |
|
201
|
201
|
} |
|
202
|
202
|
$month .= '</select></label>'; |
|
203
|
203
|
|
|
204
|
|
- $day = '<label><span class="screen-reader-text">' . __( 'Day', 'hm-post-repeat' ) . '</span><input type="text" id="hm-post-repeat-until-day" name="hm-post-repeat-until-day" value="' . $d . '" size="2" maxlength="2" autocomplete="off" /></label>'; |
|
205
|
|
- $year = '<label><span class="screen-reader-text">' . __( 'Year', 'hm-post-repeat' ) . '</span><input type="text" id="hm-post-repeat-until-year" name="hm-post-repeat-until-year" value="' . $Y . '" size="4" maxlength="4" autocomplete="off" /></label>'; |
|
|
204
|
+ $day = '<label><span class="screen-reader-text">'.__('Day', 'hm-post-repeat').'</span><input type="text" id="hm-post-repeat-until-day" name="hm-post-repeat-until-day" value="'.$d.'" size="2" maxlength="2" autocomplete="off" /></label>'; |
|
|
205
|
+ $year = '<label><span class="screen-reader-text">'.__('Year', 'hm-post-repeat').'</span><input type="text" id="hm-post-repeat-until-year" name="hm-post-repeat-until-year" value="'.$Y.'" size="4" maxlength="4" autocomplete="off" /></label>'; |
|
206
|
206
|
|
|
207
|
207
|
echo '<span class="hm-post-repeat-until-wrap">'; |
|
208
|
208
|
/* translators: 1: month, 2: day, 3: year */ |
|
209
|
|
- printf( __( '%1$s %2$s, %3$s', 'hm-post-repeat' ), $month, $day, $year ); |
|
|
209
|
+ printf(__('%1$s %2$s, %3$s', 'hm-post-repeat'), $month, $day, $year); |
|
210
|
210
|
|
|
211
|
211
|
echo '</span>'; |
|
212
|
212
|
|
|
213
|
213
|
$map = array( |
|
214
|
|
- 'hm-post-repeat-until-day' => array( $d, $cur_d ), |
|
215
|
|
- 'hm-post-repeat-until-month' => array( $m, $cur_m ), |
|
216
|
|
- 'hm-post-repeat-until-year' => array( $Y, $cur_Y ), |
|
|
214
|
+ 'hm-post-repeat-until-day' => array($d, $cur_d), |
|
|
215
|
+ 'hm-post-repeat-until-month' => array($m, $cur_m), |
|
|
216
|
+ 'hm-post-repeat-until-year' => array($Y, $cur_Y), |
|
217
|
217
|
); |
|
218
|
|
- foreach ( $map as $timeunit => $value ) { |
|
219
|
|
- list( $unit, $curr ) = $value; |
|
|
218
|
+ foreach ($map as $timeunit => $value) { |
|
|
219
|
+ list($unit, $curr) = $value; |
|
220
|
220
|
|
|
221
|
|
- echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />'; |
|
222
|
|
- echo '<input type="hidden" id="cur_' . $timeunit . '" name="cur_' . $timeunit . '" value="' . $curr . '" />'; |
|
|
221
|
+ echo '<input type="hidden" id="hidden_'.$timeunit.'" name="hidden_'.$timeunit.'" value="'.$unit.'" />'; |
|
|
222
|
+ echo '<input type="hidden" id="cur_'.$timeunit.'" name="cur_'.$timeunit.'" value="'.$curr.'" />'; |
|
223
|
223
|
} |
|
224
|
224
|
|
|
225
|
225
|
} |
|
@@ -233,36 +233,36 @@ discard block |
|
|
block discarded – undo |
|
233
|
233
|
* @param WP_Post $post The post object to get / return the states. |
|
234
|
234
|
* @return array The array of post states with ours added. |
|
235
|
235
|
*/ |
|
236
|
|
-function post_states( $post_states, $post ) { |
|
|
236
|
+function post_states($post_states, $post) { |
|
237
|
237
|
|
|
238
|
|
- if ( is_repeating_post( $post->ID ) ) { |
|
|
238
|
+ if (is_repeating_post($post->ID)) { |
|
239
|
239
|
|
|
240
|
240
|
// If the schedule has been removed since publishing, let the user know. |
|
241
|
|
- if ( $schedule = get_repeating_schedule( $post->ID ) ) { |
|
242
|
|
- $post_states['hm-post-repeat'] = __( 'Repeating', 'hm-post-repeat' ) . ': ' . $schedule['display']; |
|
243
|
|
- $post_repeat_end = get_post_repeat_end_from_post_meta( $post->ID ); |
|
244
|
|
- switch ( $post_repeat_end['type'] ) { |
|
|
241
|
+ if ($schedule = get_repeating_schedule($post->ID)) { |
|
|
242
|
+ $post_states['hm-post-repeat'] = __('Repeating', 'hm-post-repeat').': '.$schedule['display']; |
|
|
243
|
+ $post_repeat_end = get_post_repeat_end_from_post_meta($post->ID); |
|
|
244
|
+ switch ($post_repeat_end['type']) { |
|
245
|
245
|
case 'forever': |
|
246
|
|
- $post_repeat_end_string = __( 'Forever', 'hm-post-repeat' ); |
|
|
246
|
+ $post_repeat_end_string = __('Forever', 'hm-post-repeat'); |
|
247
|
247
|
break; |
|
248
|
248
|
case 'until': |
|
249
|
|
- $post_repeat_end_string = sprintf( __( 'Until %s', 'hm-post-repeat' ), date_i18n( 'M j, Y', $post_repeat_end['value'] ) ); |
|
|
249
|
+ $post_repeat_end_string = sprintf(__('Until %s', 'hm-post-repeat'), date_i18n('M j, Y', $post_repeat_end['value'])); |
|
250
|
250
|
break; |
|
251
|
251
|
case 'times': |
|
252
|
|
- $post_repeat_end_string = sprintf( __( '%d more times', 'hm-post-repeat' ), $post_repeat_end['value'] ); |
|
|
252
|
+ $post_repeat_end_string = sprintf(__('%d more times', 'hm-post-repeat'), $post_repeat_end['value']); |
|
253
|
253
|
break; |
|
254
|
254
|
} |
|
255
|
|
- if ( isset( $post_repeat_end_string ) ) { |
|
256
|
|
- $post_states['hm-post-repeat'] .= ', ' . $post_repeat_end_string; |
|
|
255
|
+ if (isset($post_repeat_end_string)) { |
|
|
256
|
+ $post_states['hm-post-repeat'] .= ', '.$post_repeat_end_string; |
|
257
|
257
|
} |
|
258
|
258
|
} else { |
|
259
|
|
- $post_states['hm-post-repeat'] = __( 'Invalid Repeating Schedule', 'hm-post-repeat' ); |
|
|
259
|
+ $post_states['hm-post-repeat'] = __('Invalid Repeating Schedule', 'hm-post-repeat'); |
|
260
|
260
|
} |
|
261
|
261
|
|
|
262
|
262
|
} |
|
263
|
263
|
|
|
264
|
|
- if ( is_repeat_post( $post->ID ) ) { |
|
265
|
|
- $post_states['hm-post-repeat'] = __( 'Repeat', 'hm-post-repeat' ); |
|
|
264
|
+ if (is_repeat_post($post->ID)) { |
|
|
265
|
+ $post_states['hm-post-repeat'] = __('Repeat', 'hm-post-repeat'); |
|
266
|
266
|
} |
|
267
|
267
|
|
|
268
|
268
|
return $post_states; |
|
@@ -278,34 +278,34 @@ discard block |
|
|
block discarded – undo |
|
278
|
278
|
* @param string $post_repeat_setting Used to manually set the repeating schedule from tests. |
|
279
|
279
|
* @param array $post_repeat_end_setting Used to manually set the repeat end from tests. |
|
280
|
280
|
*/ |
|
281
|
|
-function save_post_repeating_status( $post_id = null, $post_repeat_setting = null, $post_repeat_end_setting = null ) { |
|
|
281
|
+function save_post_repeating_status($post_id = null, $post_repeat_setting = null, $post_repeat_end_setting = null) { |
|
282
|
282
|
|
|
283
|
|
- if ( is_null( $post_repeat_setting ) ) { |
|
284
|
|
- $post_repeat_setting = get_post_data( 'hm-post-repeat-schedule' ); |
|
|
283
|
+ if (is_null($post_repeat_setting)) { |
|
|
284
|
+ $post_repeat_setting = get_post_data('hm-post-repeat-schedule'); |
|
285
|
285
|
} |
|
286
|
286
|
|
|
287
|
|
- if ( empty( $post_repeat_setting ) || ! in_array( get_post_type( $post_id ), repeating_post_types() ) ) { |
|
|
287
|
+ if (empty($post_repeat_setting) || ! in_array(get_post_type($post_id), repeating_post_types())) { |
|
288
|
288
|
return; |
|
289
|
289
|
} |
|
290
|
290
|
|
|
291
|
291
|
// Make sure we have a valid schedule and repeat end |
|
292
|
|
- if ( 'no' !== $post_repeat_setting && array_key_exists( $post_repeat_setting, get_repeating_schedules() ) ) { |
|
|
292
|
+ if ('no' !== $post_repeat_setting && array_key_exists($post_repeat_setting, get_repeating_schedules())) { |
|
293
|
293
|
|
|
294
|
294
|
// If the repeat end has been reached, stop repeating |
|
295
|
|
- if ( is_post_repeat_end_reached( $post_id ) ) { |
|
|
295
|
+ if (is_post_repeat_end_reached($post_id)) { |
|
296
|
296
|
$post_repeat_setting = 'no'; |
|
297
|
297
|
} else { |
|
298
|
|
- if ( is_null( $post_repeat_end_setting ) ) { |
|
299
|
|
- $post_repeat_end_setting = get_post_repeat_end_from_post_form( $post_id ); |
|
|
298
|
+ if (is_null($post_repeat_end_setting)) { |
|
|
299
|
+ $post_repeat_end_setting = get_post_repeat_end_from_post_form($post_id); |
|
300
|
300
|
} |
|
301
|
301
|
|
|
302
|
|
- update_post_meta( $post_id, 'hm-post-repeat', $post_repeat_setting ); |
|
303
|
|
- update_post_repeat_end_meta( $post_id, $post_repeat_end_setting ); |
|
|
302
|
+ update_post_meta($post_id, 'hm-post-repeat', $post_repeat_setting); |
|
|
303
|
+ update_post_repeat_end_meta($post_id, $post_repeat_end_setting); |
|
304
|
304
|
} |
|
305
|
305
|
} |
|
306
|
306
|
|
|
307
|
|
- if ( 'no' === $post_repeat_setting ) { |
|
308
|
|
- update_post_meta( $post_id, 'hm-post-repeat', 'no' ); |
|
|
307
|
+ if ('no' === $post_repeat_setting) { |
|
|
308
|
+ update_post_meta($post_id, 'hm-post-repeat', 'no'); |
|
309
|
309
|
//delete_post_meta( $post_id, 'hm-post-repeat' ); |
|
310
|
310
|
//delete_post_meta( $post_id, 'hm-post-repeat-end' ); |
|
311
|
311
|
} |
|
@@ -318,43 +318,43 @@ discard block |
|
|
block discarded – undo |
|
318
|
318
|
* @param int $post_id The ID of the post. |
|
319
|
319
|
* @return bool If all checks to create a repeat post have passed. |
|
320
|
320
|
*/ |
|
321
|
|
-function create_next_repeat_post_allowed( $post_id ) { |
|
|
321
|
+function create_next_repeat_post_allowed($post_id) { |
|
322
|
322
|
// Bail if this post type isn't allowed to be repeated |
|
323
|
|
- if ( ! in_array( get_post_type( $post_id ), repeating_post_types() ) ) { |
|
|
323
|
+ if ( ! in_array(get_post_type($post_id), repeating_post_types())) { |
|
324
|
324
|
return false; |
|
325
|
325
|
} |
|
326
|
326
|
|
|
327
|
327
|
// Bail if this post hasn't been published |
|
328
|
|
- if ( 'publish' !== get_post_status( $post_id ) ) { |
|
|
328
|
+ if ('publish' !== get_post_status($post_id)) { |
|
329
|
329
|
return false; |
|
330
|
330
|
} |
|
331
|
331
|
|
|
332
|
|
- $original_post_id = get_repeating_post( $post_id ); |
|
|
332
|
+ $original_post_id = get_repeating_post($post_id); |
|
333
|
333
|
|
|
334
|
334
|
// Bail if we're not publishing a repeat(ing) post |
|
335
|
|
- if ( ! $original_post_id ) { |
|
|
335
|
+ if ( ! $original_post_id) { |
|
336
|
336
|
return false; |
|
337
|
337
|
} |
|
338
|
338
|
|
|
339
|
339
|
// Bail if there is already a repeat post scheduled, don't create another one |
|
340
|
|
- if ( get_next_scheduled_repeat_post( $original_post_id ) ) { |
|
|
340
|
+ if (get_next_scheduled_repeat_post($original_post_id)) { |
|
341
|
341
|
return false; |
|
342
|
342
|
} |
|
343
|
343
|
|
|
344
|
344
|
// Bail if the saved schedule doesn't exist |
|
345
|
|
- $repeating_schedule = get_repeating_schedule( $original_post_id ); |
|
|
345
|
+ $repeating_schedule = get_repeating_schedule($original_post_id); |
|
346
|
346
|
|
|
347
|
|
- if ( ! $repeating_schedule ) { |
|
|
347
|
+ if ( ! $repeating_schedule) { |
|
348
|
348
|
return false; |
|
349
|
349
|
} |
|
350
|
350
|
|
|
351
|
351
|
// Bail if the original post isn't already published |
|
352
|
|
- if ( 'publish' !== get_post_status( $original_post_id ) ) { |
|
|
352
|
+ if ('publish' !== get_post_status($original_post_id)) { |
|
353
|
353
|
return false; |
|
354
|
354
|
} |
|
355
|
355
|
|
|
356
|
356
|
// Bail if the repetition end has been reached |
|
357
|
|
- if ( is_post_repeat_end_reached( $original_post_id ) ) { |
|
|
357
|
+ if (is_post_repeat_end_reached($original_post_id)) { |
|
358
|
358
|
return false; |
|
359
|
359
|
} |
|
360
|
360
|
|
|
@@ -372,9 +372,9 @@ discard block |
|
|
block discarded – undo |
|
372
|
372
|
* |
|
373
|
373
|
* @param int $post_id The ID of the post. |
|
374
|
374
|
*/ |
|
375
|
|
-function create_next_repeat_post( $post_id ) { |
|
|
375
|
+function create_next_repeat_post($post_id) { |
|
376
|
376
|
|
|
377
|
|
- if ( ! create_next_repeat_post_allowed( $post_id ) ) { |
|
|
377
|
+ if ( ! create_next_repeat_post_allowed($post_id)) { |
|
378
|
378
|
return false; |
|
379
|
379
|
} |
|
380
|
380
|
|
|
@@ -417,23 +417,23 @@ discard block |
|
|
block discarded – undo |
|
417
|
417
|
// return false; |
|
418
|
418
|
// } |
|
419
|
419
|
|
|
420
|
|
- if ( /*is_repeat_post( $post_id ) &&*/ is_post_repeat_end_type( $original_post_id, 'times' ) ) { |
|
421
|
|
- $post_repeat_end = get_post_repeat_end_from_post_meta( $original_post_id ); |
|
|
420
|
+ if ( /*is_repeat_post( $post_id ) &&*/ is_post_repeat_end_type($original_post_id, 'times') ) { |
|
|
421
|
+ $post_repeat_end = get_post_repeat_end_from_post_meta($original_post_id); |
|
422
|
422
|
--$post_repeat_end['value']; |
|
423
|
|
- update_post_repeat_end_meta( $original_post_id, $post_repeat_end ); |
|
|
423
|
+ update_post_repeat_end_meta($original_post_id, $post_repeat_end); |
|
424
|
424
|
/*if ( $post_repeat_end['value'] <= 0 ) { |
|
425
|
425
|
return false; |
|
426
|
426
|
}*/ |
|
427
|
427
|
} |
|
428
|
428
|
|
|
429
|
|
- $next_post = get_post( $original_post_id, ARRAY_A ); |
|
|
429
|
+ $next_post = get_post($original_post_id, ARRAY_A); |
|
430
|
430
|
|
|
431
|
431
|
// Create the repeat post as a copy of the original, but ignore some fields |
|
432
|
|
- unset( $next_post['ID'] ); |
|
433
|
|
- unset( $next_post['guid'] ); |
|
434
|
|
- unset( $next_post['post_date_gmt'] ); |
|
435
|
|
- unset( $next_post['post_modified'] ); |
|
436
|
|
- unset( $next_post['post_modified_gmt'] ); |
|
|
432
|
+ unset($next_post['ID']); |
|
|
433
|
+ unset($next_post['guid']); |
|
|
434
|
+ unset($next_post['post_date_gmt']); |
|
|
435
|
+ unset($next_post['post_modified']); |
|
|
436
|
+ unset($next_post['post_modified_gmt']); |
|
437
|
437
|
|
|
438
|
438
|
// We set the post_parent to the original post_id, so they're related |
|
439
|
439
|
$next_post['post_parent'] = $original_post_id; |
|
@@ -442,54 +442,54 @@ discard block |
|
|
block discarded – undo |
|
442
|
442
|
$next_post['post_status'] = 'future'; |
|
443
|
443
|
|
|
444
|
444
|
// Use the date of the current post being saved as the base |
|
445
|
|
- $next_post['post_date'] = date( 'Y-m-d H:i:s', strtotime( get_post_field( 'post_date', $post_id ) . ' + ' . $repeating_schedule['interval'] ) ); |
|
|
445
|
+ $next_post['post_date'] = date('Y-m-d H:i:s', strtotime(get_post_field('post_date', $post_id).' + '.$repeating_schedule['interval'])); |
|
446
|
446
|
|
|
447
|
447
|
// Make sure the next post will be in the future |
|
448
|
|
- if ( strtotime( $next_post['post_date'] ) <= time() ) { |
|
|
448
|
+ if (strtotime($next_post['post_date']) <= time()) { |
|
449
|
449
|
return false; |
|
450
|
450
|
} |
|
451
|
451
|
|
|
452
|
452
|
// All checks done, get that post scheduled! |
|
453
|
|
- $next_post_id = wp_insert_post( wp_slash( $next_post ), true ); |
|
|
453
|
+ $next_post_id = wp_insert_post(wp_slash($next_post), true); |
|
454
|
454
|
|
|
455
|
|
- if ( is_wp_error( $next_post_id ) ) { |
|
|
455
|
+ if (is_wp_error($next_post_id)) { |
|
456
|
456
|
return false; |
|
457
|
457
|
} |
|
458
|
458
|
|
|
459
|
459
|
// Mirror any post_meta |
|
460
|
|
- $post_meta = get_post_meta( $original_post_id ); |
|
|
460
|
+ $post_meta = get_post_meta($original_post_id); |
|
461
|
461
|
|
|
462
|
|
- if ( $post_meta ) { |
|
|
462
|
+ if ($post_meta) { |
|
463
|
463
|
|
|
464
|
464
|
// Ignore some internal meta fields |
|
465
|
|
- unset( $post_meta['_edit_lock'] ); |
|
466
|
|
- unset( $post_meta['_edit_last'] ); |
|
|
465
|
+ unset($post_meta['_edit_lock']); |
|
|
466
|
+ unset($post_meta['_edit_last']); |
|
467
|
467
|
|
|
468
|
468
|
// Don't copy the post repeat meta as only the original post should have that |
|
469
|
|
- unset( $post_meta['hm-post-repeat'] ); |
|
470
|
|
- unset( $post_meta['hm-post-repeat-end'] ); |
|
|
469
|
+ unset($post_meta['hm-post-repeat']); |
|
|
470
|
+ unset($post_meta['hm-post-repeat-end']); |
|
471
|
471
|
|
|
472
|
|
- foreach ( $post_meta as $key => $values ) { |
|
473
|
|
- foreach ( $values as $value ) { |
|
474
|
|
- add_post_meta( $next_post_id, $key, maybe_unserialize( $value ) ); |
|
|
472
|
+ foreach ($post_meta as $key => $values) { |
|
|
473
|
+ foreach ($values as $value) { |
|
|
474
|
+ add_post_meta($next_post_id, $key, maybe_unserialize($value)); |
|
475
|
475
|
} |
|
476
|
476
|
} |
|
477
|
477
|
} |
|
478
|
478
|
|
|
479
|
479
|
// Mirror any term relationships |
|
480
|
|
- $taxonomies = get_object_taxonomies( get_post_type( $original_post_id ) ); |
|
|
480
|
+ $taxonomies = get_object_taxonomies(get_post_type($original_post_id)); |
|
481
|
481
|
|
|
482
|
|
- foreach ( $taxonomies as $taxonomy ) { |
|
483
|
|
- wp_set_object_terms( $next_post_id, wp_list_pluck( wp_get_object_terms( $original_post_id, $taxonomy ), 'slug' ), $taxonomy ); |
|
|
482
|
+ foreach ($taxonomies as $taxonomy) { |
|
|
483
|
+ wp_set_object_terms($next_post_id, wp_list_pluck(wp_get_object_terms($original_post_id, $taxonomy), 'slug'), $taxonomy); |
|
484
|
484
|
} |
|
485
|
485
|
|
|
486
|
486
|
return $next_post_id; |
|
487
|
487
|
|
|
488
|
488
|
} |
|
489
|
489
|
|
|
490
|
|
-function is_post_repeat_end_type( $post_id, $type ) { |
|
491
|
|
- if ( $post_repeat_end = get_post_repeat_end_from_post_meta( $post_id ) ) { |
|
492
|
|
- return ( $type === $post_repeat_end['type'] ); |
|
|
490
|
+function is_post_repeat_end_type($post_id, $type) { |
|
|
491
|
+ if ($post_repeat_end = get_post_repeat_end_from_post_meta($post_id)) { |
|
|
492
|
+ return ($type === $post_repeat_end['type']); |
|
493
|
493
|
} |
|
494
|
494
|
return false; |
|
495
|
495
|
} |
|
@@ -508,7 +508,7 @@ discard block |
|
|
block discarded – undo |
|
508
|
508
|
* |
|
509
|
509
|
* @param string[] $post_types Post type slugs. |
|
510
|
510
|
*/ |
|
511
|
|
- return apply_filters( 'hm_post_repeat_post_types', array( 'post' ) ); |
|
|
511
|
+ return apply_filters('hm_post_repeat_post_types', array('post')); |
|
512
|
512
|
|
|
513
|
513
|
} |
|
514
|
514
|
|
|
@@ -524,13 +524,13 @@ discard block |
|
|
block discarded – undo |
|
524
|
524
|
* |
|
525
|
525
|
* @param array[] $schedules Schedule array items. |
|
526
|
526
|
*/ |
|
527
|
|
- $schedules = apply_filters( 'hm_post_repeat_schedules', array( |
|
528
|
|
- 'daily' => array( 'interval' => '1 day', 'display' => __( 'Daily', 'hm-post-repeat' ) ), |
|
529
|
|
- 'weekly' => array( 'interval' => '1 week', 'display' => __( 'Weekly', 'hm-post-repeat' ) ), |
|
530
|
|
- 'monthly' => array( 'interval' => '1 month', 'display' => __( 'Monthly', 'hm-post-repeat' ) ), |
|
531
|
|
- ) ); |
|
|
527
|
+ $schedules = apply_filters('hm_post_repeat_schedules', array( |
|
|
528
|
+ 'daily' => array('interval' => '1 day', 'display' => __('Daily', 'hm-post-repeat')), |
|
|
529
|
+ 'weekly' => array('interval' => '1 week', 'display' => __('Weekly', 'hm-post-repeat')), |
|
|
530
|
+ 'monthly' => array('interval' => '1 month', 'display' => __('Monthly', 'hm-post-repeat')), |
|
|
531
|
+ )); |
|
532
|
532
|
|
|
533
|
|
- foreach ( $schedules as $slug => &$schedule ) { |
|
|
533
|
+ foreach ($schedules as $slug => &$schedule) { |
|
534
|
534
|
$schedule['slug'] = $slug; |
|
535
|
535
|
} |
|
536
|
536
|
|
|
@@ -544,24 +544,24 @@ discard block |
|
|
block discarded – undo |
|
544
|
544
|
* @param int $post_id The id of the post you want to check. |
|
545
|
545
|
* @return array|null The schedule to repeat by, or null if invalid. |
|
546
|
546
|
*/ |
|
547
|
|
-function get_repeating_schedule( $post_id ) { |
|
|
547
|
+function get_repeating_schedule($post_id) { |
|
548
|
548
|
|
|
549
|
|
- if ( ! is_repeating_post( $post_id ) ) { |
|
|
549
|
+ if ( ! is_repeating_post($post_id)) { |
|
550
|
550
|
return; |
|
551
|
551
|
} |
|
552
|
552
|
|
|
553
|
|
- $repeating_schedule = get_post_meta( $post_id, 'hm-post-repeat', true ); |
|
|
553
|
+ $repeating_schedule = get_post_meta($post_id, 'hm-post-repeat', true); |
|
554
|
554
|
$schedules = get_repeating_schedules(); |
|
555
|
555
|
|
|
556
|
|
- if ( isset( $repeating_schedule['schedule'] ) ) { |
|
|
556
|
+ if (isset($repeating_schedule['schedule'])) { |
|
557
|
557
|
$repeating_schedule = $repeating_schedule['schedule']; |
|
558
|
|
- } elseif ( '1' === $repeating_schedule ) { |
|
|
558
|
+ } elseif ('1' === $repeating_schedule) { |
|
559
|
559
|
// Backwards compatibility with 0.3 when we only supported weekly |
|
560
|
560
|
$repeating_schedule = 'weekly'; |
|
561
|
561
|
} |
|
562
|
562
|
|
|
563
|
|
- if ( array_key_exists( $repeating_schedule, $schedules ) ) { |
|
564
|
|
- return $schedules[ $repeating_schedule ]; |
|
|
563
|
+ if (array_key_exists($repeating_schedule, $schedules)) { |
|
|
564
|
+ return $schedules[$repeating_schedule]; |
|
565
|
565
|
} |
|
566
|
566
|
|
|
567
|
567
|
} |
|
@@ -599,28 +599,28 @@ discard block |
|
|
block discarded – undo |
|
599
|
599
|
* @param int $post_id The id of the post you want to check. |
|
600
|
600
|
* @return bool Whether the given post_id has reached the end of its repetition. |
|
601
|
601
|
*/ |
|
602
|
|
-function is_post_repeat_end_reached( $post_id ) { |
|
|
602
|
+function is_post_repeat_end_reached($post_id) { |
|
603
|
603
|
|
|
604
|
604
|
/* if ( ! is_repeating_post( $post_id ) ) { |
|
605
|
605
|
return true; |
|
606
|
606
|
}*/ |
|
607
|
|
- $post_id = get_repeating_post( $post_id ); |
|
|
607
|
+ $post_id = get_repeating_post($post_id); |
|
608
|
608
|
|
|
609
|
609
|
// We check $_POST data so that this function works inside a `save_post` hook when the post_meta hasn't yet been saved |
|
610
|
|
- $repeat_end = get_post_repeat_end_from_post_form( $post_id ); |
|
|
610
|
+ $repeat_end = get_post_repeat_end_from_post_form($post_id); |
|
611
|
611
|
|
|
612
|
612
|
// If not from the post form data, let's try the post meta |
|
613
|
|
- empty( $repeat_end ) && $repeat_end = get_post_repeat_end_from_post_meta( $post_id ); |
|
|
613
|
+ empty($repeat_end) && $repeat_end = get_post_repeat_end_from_post_meta($post_id); |
|
614
|
614
|
|
|
615
|
|
- switch ( $repeat_end['type'] ) { |
|
|
615
|
+ switch ($repeat_end['type']) { |
|
616
|
616
|
//case 'until': return ( $repeat_end['value'] < strtotime( get_post( $post_id )->post_date ) ); |
|
617
|
617
|
//return ( $repeat_end['value'] < strtotime( get_post_field( 'post_date', $post_id ) . ' + ' . $repeating_schedule['interval'] ) ); |
|
618
|
618
|
case 'until': |
|
619
|
|
- $repeating_schedule = get_repeating_schedule( $post_id ); |
|
620
|
|
- return ( $repeat_end['value'] < strtotime( get_post_field( 'post_date', $post_id ) . ' + ' . $repeating_schedule['interval'] ) ); |
|
|
619
|
+ $repeating_schedule = get_repeating_schedule($post_id); |
|
|
620
|
+ return ($repeat_end['value'] < strtotime(get_post_field('post_date', $post_id).' + '.$repeating_schedule['interval'])); |
|
621
|
621
|
//$date = ( strtotime( get_post_field( 'post_date', $post_id ) ) < time() ) ? date( 'Y-m-d' ) : get_post_field( 'post_date', $post_id ); |
|
622
|
622
|
//return ( $repeat_end['value'] < strtotime( $date . ' + ' . $repeating_schedule['interval'] ) ); |
|
623
|
|
- case 'times': return ( is_null( $repeat_end['value'] ) || $repeat_end['value'] <= 0 ); |
|
|
623
|
+ case 'times': return (is_null($repeat_end['value']) || $repeat_end['value'] <= 0); |
|
624
|
624
|
} |
|
625
|
625
|
|
|
626
|
626
|
// Ok, we're repeating forever |
|
@@ -634,14 +634,14 @@ discard block |
|
|
block discarded – undo |
|
634
|
634
|
* @param int $post_id The ID of the post. |
|
635
|
635
|
* @param array $post_repeat_end Array with post repeat end data. |
|
636
|
636
|
*/ |
|
637
|
|
-function update_post_repeat_end_meta( $post_id, $post_repeat_end ) { |
|
|
637
|
+function update_post_repeat_end_meta($post_id, $post_repeat_end) { |
|
638
|
638
|
|
|
639
|
|
- if ( is_array( $post_repeat_end ) && 2 === count( $post_repeat_end ) ) { |
|
|
639
|
+ if (is_array($post_repeat_end) && 2 === count($post_repeat_end)) { |
|
640
|
640
|
$post_repeat_end_meta = 'forever'; |
|
641
|
|
- if ( in_array( $post_repeat_end['type'], array( 'until', 'times' ) ) ) { |
|
642
|
|
- $post_repeat_end_meta = $post_repeat_end['type'] . ':' . $post_repeat_end['value']; |
|
|
641
|
+ if (in_array($post_repeat_end['type'], array('until', 'times'))) { |
|
|
642
|
+ $post_repeat_end_meta = $post_repeat_end['type'].':'.$post_repeat_end['value']; |
|
643
|
643
|
} |
|
644
|
|
- update_post_meta( $post_id, 'hm-post-repeat-end', $post_repeat_end_meta ); |
|
|
644
|
+ update_post_meta($post_id, 'hm-post-repeat-end', $post_repeat_end_meta); |
|
645
|
645
|
} |
|
646
|
646
|
|
|
647
|
647
|
} |
|
@@ -652,27 +652,27 @@ discard block |
|
|
block discarded – undo |
|
652
|
652
|
* @param int $post_id The ID of the post to get the repeat end data. |
|
653
|
653
|
* @return array $post_repeat_end Array with post repeat end data. |
|
654
|
654
|
*/ |
|
655
|
|
-function get_post_repeat_end_from_post_form( $post_id ) { |
|
|
655
|
+function get_post_repeat_end_from_post_form($post_id) { |
|
656
|
656
|
|
|
657
|
|
- if ( ( $repeat_end = get_post_data( 'hm-post-repeat-end' ) ) && (int) get_post_data( 'ID' ) === $post_id ) { |
|
|
657
|
+ if (($repeat_end = get_post_data('hm-post-repeat-end')) && (int) get_post_data('ID') === $post_id) { |
|
658
|
658
|
$end = array( |
|
659
|
659
|
'type' => 'forever', |
|
660
|
660
|
'value' => null, |
|
661
|
661
|
); |
|
662
|
662
|
|
|
663
|
|
- switch ( $repeat_end ) { |
|
|
663
|
+ switch ($repeat_end) { |
|
664
|
664
|
case 'until': |
|
665
|
665
|
$end['type'] = 'until'; |
|
666
|
|
- $day = get_post_data( 'hm-post-repeat-until-day' ); |
|
667
|
|
- $month = get_post_data( 'hm-post-repeat-until-month' ); |
|
668
|
|
- $year = get_post_data( 'hm-post-repeat-until-year' ); |
|
669
|
|
- if ( isset( $day, $month, $year ) && checkdate( $month, $day, $year ) ) { |
|
670
|
|
- $end['value'] = strtotime( "$year-$month-$day" ); |
|
|
666
|
+ $day = get_post_data('hm-post-repeat-until-day'); |
|
|
667
|
+ $month = get_post_data('hm-post-repeat-until-month'); |
|
|
668
|
+ $year = get_post_data('hm-post-repeat-until-year'); |
|
|
669
|
+ if (isset($day, $month, $year) && checkdate($month, $day, $year)) { |
|
|
670
|
+ $end['value'] = strtotime("$year-$month-$day"); |
|
671
|
671
|
} |
|
672
|
672
|
break; |
|
673
|
673
|
case 'times': |
|
674
|
674
|
$end['type'] = 'times'; |
|
675
|
|
- if ( $times = get_post_data( 'hm-post-repeat-times' ) ) { |
|
|
675
|
+ if ($times = get_post_data('hm-post-repeat-times')) { |
|
676
|
676
|
$end['value'] = (int) $times; |
|
677
|
677
|
} |
|
678
|
678
|
break; |
|
@@ -689,18 +689,18 @@ discard block |
|
|
block discarded – undo |
|
689
|
689
|
* @param int $post_id The ID of the post to get the repeat end993743 data. |
|
690
|
690
|
* @return array $post_repeat_end Array with post repeat end data. |
|
691
|
691
|
*/ |
|
692
|
|
-function get_post_repeat_end_from_post_meta( $post_id ) { |
|
|
692
|
+function get_post_repeat_end_from_post_meta($post_id) { |
|
693
|
693
|
|
|
694
|
|
- if ( $repeat_end = get_post_meta( $post_id, 'hm-post-repeat-end', true ) ) { |
|
|
694
|
+ if ($repeat_end = get_post_meta($post_id, 'hm-post-repeat-end', true)) { |
|
695
|
695
|
$end = array( |
|
696
|
696
|
'type' => 'forever', |
|
697
|
697
|
'value' => null, |
|
698
|
698
|
); |
|
699
|
699
|
|
|
700
|
700
|
if ( |
|
701
|
|
- ( $parts = explode( ':', $repeat_end ) ) && |
|
702
|
|
- ( 2 === count( $parts ) ) && |
|
703
|
|
- ( in_array( $parts[0], array( 'until', 'times' ) ) ) |
|
|
701
|
+ ($parts = explode(':', $repeat_end)) && |
|
|
702
|
+ (2 === count($parts)) && |
|
|
703
|
+ (in_array($parts[0], array('until', 'times'))) |
|
704
|
704
|
) { |
|
705
|
705
|
$end['type'] = $parts[0]; |
|
706
|
706
|
$end['value'] = (int) $parts[1]; |
|
@@ -727,8 +727,8 @@ discard block |
|
|
block discarded – undo |
|
727
|
727
|
* @param mixed $default If value is null, return this default instead. |
|
728
|
728
|
* @return string|null Value of the fetched element, or null. |
|
729
|
729
|
*/ |
|
730
|
|
-function get_post_data( $key, $default = null ) { |
|
731
|
|
- return ( isset( $_POST[ $key ] ) ) ? sanitize_text_field( $_POST[ $key ] ) : $default; |
|
|
730
|
+function get_post_data($key, $default = null) { |
|
|
731
|
+ return (isset($_POST[$key])) ? sanitize_text_field($_POST[$key]) : $default; |
|
732
|
732
|
} |
|
733
|
733
|
|
|
734
|
734
|
/** |
|
@@ -739,14 +739,14 @@ discard block |
|
|
block discarded – undo |
|
739
|
739
|
* @param int $post_id The id of the post you want to check. |
|
740
|
740
|
* @return bool Whether the passed post_id is a repeating post or not. |
|
741
|
741
|
*/ |
|
742
|
|
-function is_repeating_post( $post_id ) { |
|
|
742
|
+function is_repeating_post($post_id) { |
|
743
|
743
|
|
|
744
|
744
|
// We check $_POST data so that this function works inside a `save_post` hook when the post_meta hasn't yet been saved |
|
745
|
|
- if ( isset( $_POST['hm-post-repeat-schedule'] ) && (int) get_post_data( 'ID' ) === $post_id ) { |
|
|
745
|
+ if (isset($_POST['hm-post-repeat-schedule']) && (int) get_post_data('ID') === $post_id) { |
|
746
|
746
|
return true; |
|
747
|
747
|
} |
|
748
|
748
|
|
|
749
|
|
- if ( get_post_meta( $post_id, 'hm-post-repeat', true ) ) { |
|
|
749
|
+ if (get_post_meta($post_id, 'hm-post-repeat', true)) { |
|
750
|
750
|
return true; |
|
751
|
751
|
} |
|
752
|
752
|
|
|
@@ -762,11 +762,11 @@ discard block |
|
|
block discarded – undo |
|
762
|
762
|
* @param int $post_id The id of the post you want to check. |
|
763
|
763
|
* @return bool Whether the passed post_id is a repeat post or not. |
|
764
|
764
|
*/ |
|
765
|
|
-function is_repeat_post( $post_id ) { |
|
|
765
|
+function is_repeat_post($post_id) { |
|
766
|
766
|
|
|
767
|
|
- $post_parent = get_post_field( 'post_parent', $post_id ); |
|
|
767
|
+ $post_parent = get_post_field('post_parent', $post_id); |
|
768
|
768
|
|
|
769
|
|
- if ( $post_parent && get_post_meta( $post_parent, 'hm-post-repeat', true ) ) { |
|
|
769
|
+ if ($post_parent && get_post_meta($post_parent, 'hm-post-repeat', true)) { |
|
770
|
770
|
return true; |
|
771
|
771
|
} |
|
772
|
772
|
|
|
@@ -780,11 +780,11 @@ discard block |
|
|
block discarded – undo |
|
780
|
780
|
* @param int $post_id The id of a repeat or repeating post. |
|
781
|
781
|
* @return int|bool Return the ID of the next repeat post_id or false if it can't find one. |
|
782
|
782
|
*/ |
|
783
|
|
-function get_next_scheduled_repeat_post( $post_id ) { |
|
|
783
|
+function get_next_scheduled_repeat_post($post_id) { |
|
784
|
784
|
|
|
785
|
|
- $repeat_posts = get_posts( array( 'post_status' => 'future', 'post_parent' => get_repeating_post( $post_id ) ) ); |
|
|
785
|
+ $repeat_posts = get_posts(array('post_status' => 'future', 'post_parent' => get_repeating_post($post_id))); |
|
786
|
786
|
|
|
787
|
|
- if ( isset( $repeat_posts[0] ) ) { |
|
|
787
|
+ if (isset($repeat_posts[0])) { |
|
788
|
788
|
return $repeat_posts[0]; |
|
789
|
789
|
} |
|
790
|
790
|
|
|
@@ -798,17 +798,17 @@ discard block |
|
|
block discarded – undo |
|
798
|
798
|
* @param int $post_id The id of a repeat or repeating post. |
|
799
|
799
|
* @return int|bool Return the original repeating post_id or false if it can't find it. |
|
800
|
800
|
*/ |
|
801
|
|
-function get_repeating_post( $post_id ) { |
|
|
801
|
+function get_repeating_post($post_id) { |
|
802
|
802
|
|
|
803
|
803
|
$original_post_id = false; |
|
804
|
804
|
|
|
805
|
805
|
// Are we publishing a repeat post |
|
806
|
|
- if ( is_repeat_post( $post_id ) ) { |
|
807
|
|
- $original_post_id = get_post( $post_id )->post_parent; |
|
|
806
|
+ if (is_repeat_post($post_id)) { |
|
|
807
|
+ $original_post_id = get_post($post_id)->post_parent; |
|
808
|
808
|
} |
|
809
|
809
|
|
|
810
|
810
|
// Or the original |
|
811
|
|
- elseif ( is_repeating_post( $post_id ) ) { |
|
|
811
|
+ elseif (is_repeating_post($post_id)) { |
|
812
|
812
|
$original_post_id = $post_id; |
|
813
|
813
|
} |
|
814
|
814
|
|