GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#36)
by
unknown
01:32
created
hm-post-repeat.php 1 patch
Spacing   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -35,37 +35,37 @@  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__ . '\admin_table_row_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__.'\admin_table_row_post_states', 10, 2);
43 43
 
44 44
 // Add repeat type table view links to admin screen for each CPT that supports Repeatable Posts.
45
-add_action( 'init', function() {
46
-	foreach ( repeating_post_types() as $post_type ) {
47
-		add_filter( "views_edit-{$post_type}", __NAMESPACE__ . '\admin_table_views_links' );
45
+add_action('init', function() {
46
+	foreach (repeating_post_types() as $post_type) {
47
+		add_filter("views_edit-{$post_type}", __NAMESPACE__.'\admin_table_views_links');
48 48
 	}
49 49
 } );
50 50
 
51 51
 // Display only Repeatable Posts in admin table view for registered view links.
52
-add_filter( 'pre_get_posts', __NAMESPACE__ . '\admin_table_repeat_type_posts_query' );
52
+add_filter('pre_get_posts', __NAMESPACE__.'\admin_table_repeat_type_posts_query');
53 53
 
54 54
 /**
55 55
  * Enqueue the scripts and styles that are needed by this plugin.
56 56
  */
57
-function enqueue_scripts( $hook ) {
57
+function enqueue_scripts($hook) {
58 58
 
59 59
 	// Ensure we only load them on the edit post and add new post admin screens
60
-	if ( ! in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) {
60
+	if ( ! in_array($hook, array('post.php', 'post-new.php'))) {
61 61
 		return;
62 62
 	}
63 63
 
64
-	$plugin_data = get_plugin_data( __FILE__ );
65
-	$plugin_dir_url = plugin_dir_url( __FILE__ );
64
+	$plugin_data = get_plugin_data(__FILE__);
65
+	$plugin_dir_url = plugin_dir_url(__FILE__);
66 66
 
67
-	wp_enqueue_script( 'hm-post-repeat', $plugin_dir_url . 'hm-post-repeat.js', 'jquery', $plugin_data['Version'], true );
68
-	wp_enqueue_style( 'hm-post-repeat', $plugin_dir_url . 'hm-post-repeat.css', array(), $plugin_data['Version'] );
67
+	wp_enqueue_script('hm-post-repeat', $plugin_dir_url.'hm-post-repeat.js', 'jquery', $plugin_data['Version'], true);
68
+	wp_enqueue_style('hm-post-repeat', $plugin_dir_url.'hm-post-repeat.css', array(), $plugin_data['Version']);
69 69
 
70 70
 }
71 71
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function publish_box_ui() {
79 79
 
80
-	if ( ! in_array( get_post_type(), repeating_post_types() ) ) {
80
+	if ( ! in_array(get_post_type(), repeating_post_types())) {
81 81
 		return;
82 82
 	} ?>
83 83
 
@@ -85,31 +85,31 @@  discard block
 block discarded – undo
85 85
 
86 86
 		<span class="dashicons dashicons-controls-repeat"></span>
87 87
 
88
-		<?php esc_html_e( 'Repeat:', 'hm-post-repeat' ); ?>
88
+		<?php esc_html_e('Repeat:', 'hm-post-repeat'); ?>
89 89
 
90
-		<?php if ( is_repeat_post( get_the_id() ) ) : ?>
90
+		<?php if (is_repeat_post(get_the_id())) : ?>
91 91
 
92
-			<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>
92
+			<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>
93 93
 
94 94
 		<?php else : ?>
95 95
 
96
-			<?php $repeating_schedule = get_repeating_schedule( get_the_id() ); ?>
97
-			<?php $is_repeating_post = is_repeating_post( get_the_id() ) && isset( $repeating_schedule ); ?>
96
+			<?php $repeating_schedule = get_repeating_schedule(get_the_id()); ?>
97
+			<?php $is_repeating_post = is_repeating_post(get_the_id()) && isset($repeating_schedule); ?>
98 98
 
99
-			<strong><?php echo ! $is_repeating_post ? esc_html__( 'No', 'hm-post-repeat' ) : esc_html( $repeating_schedule['display'] ); ?></strong>
99
+			<strong><?php echo ! $is_repeating_post ? esc_html__('No', 'hm-post-repeat') : esc_html($repeating_schedule['display']); ?></strong>
100 100
 
101
-			<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>
101
+			<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>
102 102
 
103 103
 			<span class="hide-if-js" id="hm-post-repeat">
104 104
 
105 105
 				<select name="hm-post-repeat">
106
-					<option<?php selected( ! $is_repeating_post ); ?> value="no"><?php esc_html_e( 'No', 'hm-post-repeat' ); ?></option>
107
-					<?php foreach ( get_repeating_schedules() as $schedule_slug => $schedule ) : ?>
108
-						<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>
106
+					<option<?php selected( ! $is_repeating_post); ?> value="no"><?php esc_html_e('No', 'hm-post-repeat'); ?></option>
107
+					<?php foreach (get_repeating_schedules() as $schedule_slug => $schedule) : ?>
108
+						<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>
109 109
 					<?php endforeach; ?>
110 110
 				</select>
111 111
 
112
-				<a href="#hm-post-repeat" class="save-post-hm-post-repeat hide-if-no-js button"><?php esc_html_e( 'OK', 'hm-post-repeat' ); ?></a>
112
+				<a href="#hm-post-repeat" class="save-post-hm-post-repeat hide-if-no-js button"><?php esc_html_e('OK', 'hm-post-repeat'); ?></a>
113 113
 
114 114
 			</span>
115 115
 
@@ -128,21 +128,21 @@  discard block
 block discarded – undo
128 128
  * @param WP_Post $post        The post object to get / return the states.
129 129
  * @return array The array of post states with ours added.
130 130
  */
131
-function admin_table_row_post_states( $post_states, $post ) {
131
+function admin_table_row_post_states($post_states, $post) {
132 132
 
133
-	if ( is_repeating_post( $post->ID ) ) {
133
+	if (is_repeating_post($post->ID)) {
134 134
 
135 135
 		// If the schedule has been removed since publishing, let the user know.
136
-		if ( get_repeating_schedule( $post->ID ) ) {
137
-			$post_states['hm-post-repeat'] = __( 'Repeating', 'hm-post-repeat' );
136
+		if (get_repeating_schedule($post->ID)) {
137
+			$post_states['hm-post-repeat'] = __('Repeating', 'hm-post-repeat');
138 138
 		} else {
139
-			$post_states['hm-post-repeat'] = __( 'Invalid Repeating Schedule', 'hm-post-repeat' );
139
+			$post_states['hm-post-repeat'] = __('Invalid Repeating Schedule', 'hm-post-repeat');
140 140
 		}
141 141
 
142 142
 	}
143 143
 
144
-	if ( is_repeat_post( $post->ID ) ) {
145
-		$post_states['hm-post-repeat'] = __( 'Repeat', 'hm-post-repeat' );
144
+	if (is_repeat_post($post->ID)) {
145
+		$post_states['hm-post-repeat'] = __('Repeat', 'hm-post-repeat');
146 146
 	}
147 147
 
148 148
 	return $post_states;
@@ -161,29 +161,29 @@  discard block
 block discarded – undo
161 161
  * @param int    $post_id             The ID of the post.
162 162
  * @param string $post_repeat_setting Used to manually set the repeating schedule from tests.
163 163
  */
164
-function save_post_repeating_status( $post_id = null, $post_repeat_setting = null ) {
164
+function save_post_repeating_status($post_id = null, $post_repeat_setting = null) {
165 165
 	global $is_creating_repeat;
166 166
 
167 167
 	// Stop - Repeat post is being saved, it doesn't need meta data.
168 168
 	// N.B. when inserting a Repeat post via `wp_insert_post` the `save_post` filters are firing again.
169
-	if ( $is_creating_repeat ) {
169
+	if ($is_creating_repeat) {
170 170
 		return;
171 171
 	}
172 172
 
173
-	if ( is_null( $post_repeat_setting ) ) {
174
-		$post_repeat_setting = isset( $_POST['hm-post-repeat'] ) ? sanitize_text_field( $_POST['hm-post-repeat'] ) : '';
173
+	if (is_null($post_repeat_setting)) {
174
+		$post_repeat_setting = isset($_POST['hm-post-repeat']) ? sanitize_text_field($_POST['hm-post-repeat']) : '';
175 175
 	}
176 176
 
177
-	if ( ! in_array( get_post_type( $post_id ), repeating_post_types() ) || empty( $post_repeat_setting ) ) {
177
+	if ( ! in_array(get_post_type($post_id), repeating_post_types()) || empty($post_repeat_setting)) {
178 178
 		return;
179 179
 	}
180 180
 
181
-	if ( 'no' === $post_repeat_setting ) {
182
-		delete_post_meta( $post_id, 'hm-post-repeat' );
181
+	if ('no' === $post_repeat_setting) {
182
+		delete_post_meta($post_id, 'hm-post-repeat');
183 183
 	}
184 184
 	// Make sure we have a valid schedule.
185
-	elseif ( in_array( $post_repeat_setting, array_keys( get_repeating_schedules() ) ) ) {
186
-		update_post_meta( $post_id, 'hm-post-repeat', $post_repeat_setting );
185
+	elseif (in_array($post_repeat_setting, array_keys(get_repeating_schedules()))) {
186
+		update_post_meta($post_id, 'hm-post-repeat', $post_repeat_setting);
187 187
 	}
188 188
 }
189 189
 
@@ -206,57 +206,57 @@  discard block
 block discarded – undo
206 206
  * @return int|\WP_Error A Repeat post ID on success, WP_Error if Repeat post could not be created.
207 207
  *                       Terminate function execution if conditions are not met.
208 208
  */
209
-function create_next_repeat_post( $post_id ) {
209
+function create_next_repeat_post($post_id) {
210 210
 	global $is_creating_repeat;
211 211
 
212 212
 	// Stop - Repeat post is being saved, we need to run this code just once.
213 213
 	// N.B. when inserting a Repeat post via `wp_insert_post` the `save_post` filters are firing again.
214
-	if ( $is_creating_repeat ) {
214
+	if ($is_creating_repeat) {
215 215
 		return;
216 216
 	}
217 217
 
218
-	if ( ! in_array( get_post_type( $post_id ), repeating_post_types() ) ) {
218
+	if ( ! in_array(get_post_type($post_id), repeating_post_types())) {
219 219
 		return false;
220 220
 	}
221 221
 
222
-	if ( 'publish' !== get_post_status( $post_id ) ) {
222
+	if ('publish' !== get_post_status($post_id)) {
223 223
 		return false;
224 224
 	}
225 225
 
226
-	$original_post_id = get_repeating_post( $post_id );
226
+	$original_post_id = get_repeating_post($post_id);
227 227
 
228 228
 	// Bail if we're not publishing a repeat(ing) post.
229
-	if ( ! $original_post_id ) {
229
+	if ( ! $original_post_id) {
230 230
 		return false;
231 231
 	}
232 232
 
233
-	$original_post = get_post( $original_post_id, ARRAY_A );
233
+	$original_post = get_post($original_post_id, ARRAY_A);
234 234
 
235 235
 	// If there is already a repeat post scheduled don't create another one.
236
-	if ( get_next_scheduled_repeat_post( $original_post['ID'] ) ) {
236
+	if (get_next_scheduled_repeat_post($original_post['ID'])) {
237 237
 		return false;
238 238
 	}
239 239
 
240 240
 	// Bail if the saved schedule doesn't exist.
241
-	$repeating_schedule = get_repeating_schedule( $original_post['ID'] );
241
+	$repeating_schedule = get_repeating_schedule($original_post['ID']);
242 242
 
243
-	if ( ! $repeating_schedule ) {
243
+	if ( ! $repeating_schedule) {
244 244
 		return false;
245 245
 	}
246 246
 
247 247
 	// Bail if the original post isn't already published.
248
-	if ( 'publish' !== $original_post['post_status'] ) {
248
+	if ('publish' !== $original_post['post_status']) {
249 249
 		return false;
250 250
 	}
251 251
 
252 252
 	$next_post = $original_post;
253 253
 
254 254
 	// Create the repeat post as a copy of the original, but ignore some fields.
255
-	unset( $next_post['ID'] );
256
-	unset( $next_post['guid'] );
257
-	unset( $next_post['post_date_gmt'] );
258
-	unset( $next_post['post_modified'] );
259
-	unset( $next_post['post_modified_gmt'] );
255
+	unset($next_post['ID']);
256
+	unset($next_post['guid']);
257
+	unset($next_post['post_date_gmt']);
258
+	unset($next_post['post_modified']);
259
+	unset($next_post['post_modified_gmt']);
260 260
 
261 261
 	// We set the post_parent to the original post_id, so they're related.
262 262
 	$next_post['post_parent'] = $original_post['ID'];
@@ -265,10 +265,10 @@  discard block
 block discarded – undo
265 265
 	$next_post['post_status'] = 'future';
266 266
 
267 267
 	// Use the date of the current post being saved as the base.
268
-	$next_post['post_date'] = date( 'Y-m-d H:i:s', strtotime( get_post_field( 'post_date', $post_id ) . ' + ' . $repeating_schedule['interval'] ) );
268
+	$next_post['post_date'] = date('Y-m-d H:i:s', strtotime(get_post_field('post_date', $post_id).' + '.$repeating_schedule['interval']));
269 269
 
270 270
 	// Make sure the next post will be in the future from the current time.
271
-	if ( strtotime( $next_post['post_date'] ) <= time() ) {
271
+	if (strtotime($next_post['post_date']) <= time()) {
272 272
 		return false;
273 273
 	}
274 274
 
@@ -279,41 +279,41 @@  discard block
 block discarded – undo
279 279
 	 * @param array $repeating_schedule Repeating schedule info.
280 280
 	 * @param array $original_post      The original repeating post.
281 281
 	 */
282
-	$next_post = apply_filters( 'hm_post_repeat_edit_repeat_post', $next_post, $repeating_schedule, $original_post );
282
+	$next_post = apply_filters('hm_post_repeat_edit_repeat_post', $next_post, $repeating_schedule, $original_post);
283 283
 
284 284
 	// All checks done, get that post scheduled!
285 285
 	$is_creating_repeat = true;
286
-	$next_post_id       = wp_insert_post( wp_slash( $next_post ), true );
286
+	$next_post_id       = wp_insert_post(wp_slash($next_post), true);
287 287
 	$is_creating_repeat = false;
288 288
 
289
-	if ( is_wp_error( $next_post_id ) ) {
289
+	if (is_wp_error($next_post_id)) {
290 290
 		return false;
291 291
 	}
292 292
 
293 293
 	// Mirror any post meta.
294
-	$post_meta = get_post_meta( $original_post['ID'] );
294
+	$post_meta = get_post_meta($original_post['ID']);
295 295
 
296
-	if ( $post_meta ) {
296
+	if ($post_meta) {
297 297
 
298 298
 		// Ignore some internal meta fields.
299
-		unset( $post_meta['_edit_lock'] );
300
-		unset( $post_meta['_edit_last'] );
299
+		unset($post_meta['_edit_lock']);
300
+		unset($post_meta['_edit_last']);
301 301
 
302 302
 		// Don't copy the post repeat meta as only the original post should have that.
303
-		unset( $post_meta['hm-post-repeat'] );
303
+		unset($post_meta['hm-post-repeat']);
304 304
 
305
-		foreach ( $post_meta as $key => $values ) {
306
-			foreach ( $values as $value ) {
307
-				add_post_meta( $next_post_id, $key, maybe_unserialize( $value ) );
305
+		foreach ($post_meta as $key => $values) {
306
+			foreach ($values as $value) {
307
+				add_post_meta($next_post_id, $key, maybe_unserialize($value));
308 308
 			}
309 309
 		}
310 310
 	}
311 311
 
312 312
 	// Mirror any term relationships.
313
-	$taxonomies = get_object_taxonomies( $original_post['post_type'] );
313
+	$taxonomies = get_object_taxonomies($original_post['post_type']);
314 314
 
315
-	foreach ( $taxonomies as $taxonomy ) {
316
-		wp_set_object_terms( $next_post_id, wp_list_pluck( wp_get_object_terms( $original_post['ID'], $taxonomy ), 'slug' ), $taxonomy );
315
+	foreach ($taxonomies as $taxonomy) {
316
+		wp_set_object_terms($next_post_id, wp_list_pluck(wp_get_object_terms($original_post['ID'], $taxonomy), 'slug'), $taxonomy);
317 317
 	}
318 318
 
319 319
 	return $next_post_id;
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 *
334 334
 	 * @param string[] $post_types Post type slugs.
335 335
 	 */
336
-	return apply_filters( 'hm_post_repeat_post_types', array( 'post' ) );
336
+	return apply_filters('hm_post_repeat_post_types', array('post'));
337 337
 
338 338
 }
339 339
 
@@ -349,13 +349,13 @@  discard block
 block discarded – undo
349 349
 	 *
350 350
 	 * @param array[] $schedules Schedule array items.
351 351
 	 */
352
-	$schedules = apply_filters( 'hm_post_repeat_schedules', array(
353
-		'daily'   => array( 'interval' => '1 day',   'display' => __( 'Daily',   'hm-post-repeat' ) ),
354
-		'weekly'  => array( 'interval' => '1 week',  'display' => __( 'Weekly',  'hm-post-repeat' ) ),
355
-		'monthly' => array( 'interval' => '1 month', 'display' => __( 'Monthly', 'hm-post-repeat' ) ),
356
-	) );
352
+	$schedules = apply_filters('hm_post_repeat_schedules', array(
353
+		'daily'   => array('interval' => '1 day', 'display' => __('Daily', 'hm-post-repeat')),
354
+		'weekly'  => array('interval' => '1 week', 'display' => __('Weekly', 'hm-post-repeat')),
355
+		'monthly' => array('interval' => '1 month', 'display' => __('Monthly', 'hm-post-repeat')),
356
+	));
357 357
 
358
-	foreach ( $schedules as $slug => &$schedule ) {
358
+	foreach ($schedules as $slug => &$schedule) {
359 359
 		$schedule['slug'] = $slug;
360 360
 	}
361 361
 
@@ -369,22 +369,22 @@  discard block
 block discarded – undo
369 369
  * @param int $post_id The id of the post you want to check.
370 370
  * @return array|null The schedule to repeat by, or null if invalid.
371 371
  */
372
-function get_repeating_schedule( $post_id ) {
372
+function get_repeating_schedule($post_id) {
373 373
 
374
-	if ( ! is_repeating_post( $post_id ) ) {
374
+	if ( ! is_repeating_post($post_id)) {
375 375
 		return;
376 376
 	}
377 377
 
378
-	$repeating_schedule = get_post_meta( $post_id, 'hm-post-repeat', true );
378
+	$repeating_schedule = get_post_meta($post_id, 'hm-post-repeat', true);
379 379
 	$schedules = get_repeating_schedules();
380 380
 
381 381
 	// Backwards compatibility with 0.3 when we only supported weekly
382
-	if ( '1' === $repeating_schedule ) {
382
+	if ('1' === $repeating_schedule) {
383 383
 		$repeating_schedule = 'weekly';
384 384
 	}
385 385
 
386
-	if ( array_key_exists( $repeating_schedule, $schedules ) ) {
387
-		return $schedules[ $repeating_schedule ];
386
+	if (array_key_exists($repeating_schedule, $schedules)) {
387
+		return $schedules[$repeating_schedule];
388 388
 	}
389 389
 
390 390
 }
@@ -397,14 +397,14 @@  discard block
 block discarded – undo
397 397
  * @param int $post_id The id of the post you want to check.
398 398
  * @return bool Whether the passed post_id is a repeating post or not.
399 399
  */
400
-function is_repeating_post( $post_id ) {
400
+function is_repeating_post($post_id) {
401 401
 
402 402
 	// We check $_POST data so that this function works inside a `save_post` hook when the post_meta hasn't yet been saved
403
-	if ( isset( $_POST['hm-post-repeat'] ) && isset( $_POST['ID'] ) && $_POST['ID'] === $post_id ) {
403
+	if (isset($_POST['hm-post-repeat']) && isset($_POST['ID']) && $_POST['ID'] === $post_id) {
404 404
 		return true;
405 405
 	}
406 406
 
407
-	if ( get_post_meta( $post_id, 'hm-post-repeat', true ) ) {
407
+	if (get_post_meta($post_id, 'hm-post-repeat', true)) {
408 408
 		return true;
409 409
 	}
410 410
 
@@ -420,11 +420,11 @@  discard block
 block discarded – undo
420 420
  * @param int $post_id The id of the post you want to check.
421 421
  * @return bool Whether the passed post_id is a repeat post or not.
422 422
  */
423
-function is_repeat_post( $post_id ) {
423
+function is_repeat_post($post_id) {
424 424
 
425
-	$post_parent = get_post_field( 'post_parent', $post_id );
425
+	$post_parent = get_post_field('post_parent', $post_id);
426 426
 
427
-	if ( $post_parent && get_post_meta( $post_parent, 'hm-post-repeat', true ) ) {
427
+	if ($post_parent && get_post_meta($post_parent, 'hm-post-repeat', true)) {
428 428
 		return true;
429 429
 	}
430 430
 
@@ -438,13 +438,13 @@  discard block
 block discarded – undo
438 438
  * @param int $post_id The id of a repeat or repeating post
439 439
  * @return Int|Bool Return the ID of the next repeat post_id or false if it can't find one
440 440
  */
441
-function get_next_scheduled_repeat_post( $post_id ) {
441
+function get_next_scheduled_repeat_post($post_id) {
442 442
 
443
-	$post = get_post( get_repeating_post( $post_id ) );
443
+	$post = get_post(get_repeating_post($post_id));
444 444
 
445
-	$repeat_posts = get_posts( array( 'post_status' => 'future', 'post_parent' => $post->ID ) );
445
+	$repeat_posts = get_posts(array('post_status' => 'future', 'post_parent' => $post->ID));
446 446
 
447
-	if ( isset( $repeat_posts[0] ) ) {
447
+	if (isset($repeat_posts[0])) {
448 448
 	 	return $repeat_posts[0];
449 449
 	}
450 450
 
@@ -458,17 +458,17 @@  discard block
 block discarded – undo
458 458
  * @param int $post_id The id of a repeat or repeating post
459 459
  * @return Int|Bool Return the original repeating post_id or false if it can't find it
460 460
  */
461
-function get_repeating_post( $post_id ) {
461
+function get_repeating_post($post_id) {
462 462
 
463 463
 	$original_post_id = false;
464 464
 
465 465
 	// Are we publishing a repeat post
466
-	if ( is_repeat_post( $post_id ) ) {
467
-		$original_post_id = get_post( $post_id )->post_parent;
466
+	if (is_repeat_post($post_id)) {
467
+		$original_post_id = get_post($post_id)->post_parent;
468 468
 	}
469 469
 
470 470
 	// Or the original
471
-	elseif ( is_repeating_post( $post_id ) ) {
471
+	elseif (is_repeating_post($post_id)) {
472 472
 		$original_post_id = $post_id;
473 473
 	}
474 474
 
@@ -486,10 +486,10 @@  discard block
 block discarded – undo
486 486
  *
487 487
  * @return array Available list of table views with custom added views per repeat type.
488 488
  */
489
-function admin_table_views_links( $views ) {
489
+function admin_table_views_links($views) {
490 490
 
491 491
 	// Add status link for each repeat type.
492
-	foreach ( get_available_repeat_types() as $repeat_type => $repeat_desc ) {
492
+	foreach (get_available_repeat_types() as $repeat_type => $repeat_desc) {
493 493
 
494 494
 		$url_args = array(
495 495
 			'post_type'      => get_current_screen()->post_type,
@@ -497,25 +497,25 @@  discard block
 block discarded – undo
497 497
 		);
498 498
 
499 499
 		// Custom WP_Query to get posts count of repeat type.
500
-		$repeat_type_query = new \WP_Query( get_repeat_type_query_params( $repeat_type ) );
500
+		$repeat_type_query = new \WP_Query(get_repeat_type_query_params($repeat_type));
501 501
 
502 502
 		$link_label = sprintf(
503 503
 				'%s <span class="count">(%s)</span>',
504
-			esc_html( $repeat_desc ),
505
-			esc_html( number_format_i18n( $repeat_type_query->post_count ) )
504
+			esc_html($repeat_desc),
505
+			esc_html(number_format_i18n($repeat_type_query->post_count))
506 506
 		);
507 507
 
508 508
 		// Add current class to the link to highlight it when it's selected.
509
-		$class_html = ( get_repeat_type_url_param() === $repeat_type ) ? ' class="current"' : '';
509
+		$class_html = (get_repeat_type_url_param() === $repeat_type) ? ' class="current"' : '';
510 510
 
511 511
 		$link_html = sprintf(
512 512
 			'<a href="%s"%s>%s</a>',
513
-			esc_url( add_query_arg( $url_args, 'edit.php' ) ),
513
+			esc_url(add_query_arg($url_args, 'edit.php')),
514 514
 			$class_html, // html - hardcoded, no need to escape.
515 515
 			$link_label  // html - escaped earlier in the code.
516 516
 		);
517 517
 
518
-		$views[ $repeat_type ] = $link_html;
518
+		$views[$repeat_type] = $link_html;
519 519
 	}
520 520
 
521 521
 	return $views;
@@ -529,23 +529,23 @@  discard block
 block discarded – undo
529 529
  *
530 530
  * @return mixed Main admin query with edited params to get posts of specified repeat type.
531 531
  */
532
-function admin_table_repeat_type_posts_query( $wp_query ) {
532
+function admin_table_repeat_type_posts_query($wp_query) {
533 533
 
534 534
 	// Stop - if not admin or not main query (there are secondary WP_Query for counting posts for view links, etc).
535
-	if ( ! is_admin() || ! $wp_query->is_main_query() ) {
535
+	if ( ! is_admin() || ! $wp_query->is_main_query()) {
536 536
 		return $wp_query;
537 537
 	}
538 538
 
539 539
 	// Get URL query param for repeat type and check it's valid.
540 540
 	$repeat_type = get_repeat_type_url_param();
541 541
 
542
-	if ( ! $repeat_type || ! is_allowed_repeat_type( $repeat_type ) ) {
542
+	if ( ! $repeat_type || ! is_allowed_repeat_type($repeat_type)) {
543 543
 		return $wp_query;
544 544
 	}
545 545
 
546 546
 	// Add a table view link per each repeat type.
547
-	foreach ( get_repeat_type_query_params( $repeat_type ) as $key => $value ) {
548
-		$wp_query->set( $key, $value );
547
+	foreach (get_repeat_type_query_params($repeat_type) as $key => $value) {
548
+		$wp_query->set($key, $value);
549 549
 	}
550 550
 
551 551
 	return $wp_query;
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
  *
560 560
  * @return array Array of custom WP_Query params.
561 561
  */
562
-function get_repeat_type_query_params( $repeat_type ) {
562
+function get_repeat_type_query_params($repeat_type) {
563 563
 
564 564
 	$query['post_type'] = get_current_screen()->post_type;
565 565
 
@@ -571,11 +571,11 @@  discard block
 block discarded – undo
571 571
 			),
572 572
 	);
573 573
 
574
-	if ( $repeat_type === 'repeat' ) {
575
-		$query['post_parent__not_in'] = array( 0 );
574
+	if ($repeat_type === 'repeat') {
575
+		$query['post_parent__not_in'] = array(0);
576 576
 
577
-	} elseif ( $repeat_type === 'repeating' ) {
578
-		$query['post_parent__in'] = array( 0 );
577
+	} elseif ($repeat_type === 'repeating') {
578
+		$query['post_parent__in'] = array(0);
579 579
 	}
580 580
 
581 581
 	return $query;
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
  * @return string Sanitized string of repeat type being displayed.
589 589
  */
590 590
 function get_repeat_type_url_param() {
591
-	return isset( $_GET['hm-post-repeat'] ) ? sanitize_text_field( $_GET['hm-post-repeat'] ) : '';
591
+	return isset($_GET['hm-post-repeat']) ? sanitize_text_field($_GET['hm-post-repeat']) : '';
592 592
 }
593 593
 
594 594
 /**
@@ -598,8 +598,8 @@  discard block
 block discarded – undo
598 598
  */
599 599
 function get_available_repeat_types() {
600 600
 	return array(
601
-		'repeating' => __( 'Repeating', 'hm-post-repeat' ),
602
-		'repeat'    => __( 'Repeat', 'hm-post-repeat' ),
601
+		'repeating' => __('Repeating', 'hm-post-repeat'),
602
+		'repeat'    => __('Repeat', 'hm-post-repeat'),
603 603
 	);
604 604
 }
605 605
 
@@ -611,6 +611,6 @@  discard block
 block discarded – undo
611 611
  * @return bool True if repeat type is valid,
612 612
  *              False otherwise.
613 613
  */
614
-function is_allowed_repeat_type( $repeat_type ) {
615
-	return in_array( $repeat_type, array_keys( get_available_repeat_types() ) );
614
+function is_allowed_repeat_type($repeat_type) {
615
+	return in_array($repeat_type, array_keys(get_available_repeat_types()));
616 616
 }
Please login to merge, or discard this patch.