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 (#32)
by
unknown
20:31
created
hm-post-repeat.php 1 patch
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -35,40 +35,40 @@  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
 // Add a row link to view all Repeat posts for the current Repeating post.
55
-add_filter( 'post_row_actions', __NAMESPACE__ . '\admin_table_row_actions_view_repeat_posts', 10, 2 );
55
+add_filter('post_row_actions', __NAMESPACE__.'\admin_table_row_actions_view_repeat_posts', 10, 2);
56 56
 
57 57
 /**
58 58
  * Enqueue the scripts and styles that are needed by this plugin.
59 59
  */
60
-function enqueue_scripts( $hook ) {
60
+function enqueue_scripts($hook) {
61 61
 
62 62
 	// Ensure we only load them on the edit post and add new post admin screens
63
-	if ( ! in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) {
63
+	if ( ! in_array($hook, array('post.php', 'post-new.php'))) {
64 64
 		return;
65 65
 	}
66 66
 
67
-	$plugin_data = get_plugin_data( __FILE__ );
68
-	$plugin_dir_url = plugin_dir_url( __FILE__ );
67
+	$plugin_data = get_plugin_data(__FILE__);
68
+	$plugin_dir_url = plugin_dir_url(__FILE__);
69 69
 
70
-	wp_enqueue_script( 'hm-post-repeat', $plugin_dir_url . 'hm-post-repeat.js', 'jquery', $plugin_data['Version'], true );
71
-	wp_enqueue_style( 'hm-post-repeat', $plugin_dir_url . 'hm-post-repeat.css', array(), $plugin_data['Version'] );
70
+	wp_enqueue_script('hm-post-repeat', $plugin_dir_url.'hm-post-repeat.js', 'jquery', $plugin_data['Version'], true);
71
+	wp_enqueue_style('hm-post-repeat', $plugin_dir_url.'hm-post-repeat.css', array(), $plugin_data['Version']);
72 72
 
73 73
 }
74 74
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function publish_box_ui() {
82 82
 
83
-	if ( ! in_array( get_post_type(), repeating_post_types() ) ) {
83
+	if ( ! in_array(get_post_type(), repeating_post_types())) {
84 84
 		return;
85 85
 	} ?>
86 86
 
@@ -88,31 +88,31 @@  discard block
 block discarded – undo
88 88
 
89 89
 		<span class="dashicons dashicons-controls-repeat"></span>
90 90
 
91
-		<?php esc_html_e( 'Repeat:', 'hm-post-repeat' ); ?>
91
+		<?php esc_html_e('Repeat:', 'hm-post-repeat'); ?>
92 92
 
93
-		<?php if ( is_repeat_post( get_the_id() ) ) : ?>
93
+		<?php if (is_repeat_post(get_the_id())) : ?>
94 94
 
95
-			<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>
95
+			<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>
96 96
 
97 97
 		<?php else : ?>
98 98
 
99
-			<?php $repeating_schedule = get_repeating_schedule( get_the_id() ); ?>
100
-			<?php $is_repeating_post = is_repeating_post( get_the_id() ) && isset( $repeating_schedule ); ?>
99
+			<?php $repeating_schedule = get_repeating_schedule(get_the_id()); ?>
100
+			<?php $is_repeating_post = is_repeating_post(get_the_id()) && isset($repeating_schedule); ?>
101 101
 
102
-			<strong><?php echo ! $is_repeating_post ? esc_html__( 'No', 'hm-post-repeat' ) : esc_html( $repeating_schedule['display'] ); ?></strong>
102
+			<strong><?php echo ! $is_repeating_post ? esc_html__('No', 'hm-post-repeat') : esc_html($repeating_schedule['display']); ?></strong>
103 103
 
104
-			<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>
104
+			<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>
105 105
 
106 106
 			<span class="hide-if-js" id="hm-post-repeat">
107 107
 
108 108
 				<select name="hm-post-repeat">
109
-					<option<?php selected( ! $is_repeating_post ); ?> value="no"><?php esc_html_e( 'No', 'hm-post-repeat' ); ?></option>
110
-					<?php foreach ( get_repeating_schedules() as $schedule_slug => $schedule ) : ?>
111
-						<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
+					<option<?php selected( ! $is_repeating_post); ?> value="no"><?php esc_html_e('No', 'hm-post-repeat'); ?></option>
110
+					<?php foreach (get_repeating_schedules() as $schedule_slug => $schedule) : ?>
111
+						<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>
112 112
 					<?php endforeach; ?>
113 113
 				</select>
114 114
 
115
-				<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>
115
+				<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>
116 116
 
117 117
 			</span>
118 118
 
@@ -131,21 +131,21 @@  discard block
 block discarded – undo
131 131
  * @param WP_Post $post        The post object to get / return the states.
132 132
  * @return array The array of post states with ours added.
133 133
  */
134
-function admin_table_row_post_states( $post_states, $post ) {
134
+function admin_table_row_post_states($post_states, $post) {
135 135
 
136
-	if ( is_repeating_post( $post->ID ) ) {
136
+	if (is_repeating_post($post->ID)) {
137 137
 
138 138
 		// If the schedule has been removed since publishing, let the user know.
139
-		if ( get_repeating_schedule( $post->ID ) ) {
140
-			$post_states['hm-post-repeat'] = __( 'Repeating', 'hm-post-repeat' );
139
+		if (get_repeating_schedule($post->ID)) {
140
+			$post_states['hm-post-repeat'] = __('Repeating', 'hm-post-repeat');
141 141
 		} else {
142
-			$post_states['hm-post-repeat'] = __( 'Invalid Repeating Schedule', 'hm-post-repeat' );
142
+			$post_states['hm-post-repeat'] = __('Invalid Repeating Schedule', 'hm-post-repeat');
143 143
 		}
144 144
 
145 145
 	}
146 146
 
147
-	if ( is_repeat_post( $post->ID ) ) {
148
-		$post_states['hm-post-repeat'] = __( 'Repeat', 'hm-post-repeat' );
147
+	if (is_repeat_post($post->ID)) {
148
+		$post_states['hm-post-repeat'] = __('Repeat', 'hm-post-repeat');
149 149
 	}
150 150
 
151 151
 	return $post_states;
@@ -159,23 +159,23 @@  discard block
 block discarded – undo
159 159
  * @param int    $post_id             The ID of the post.
160 160
  * @param string $post_repeat_setting Used to manually set the repeating schedule from tests.
161 161
  */
162
-function save_post_repeating_status( $post_id = null, $post_repeat_setting = null ) {
162
+function save_post_repeating_status($post_id = null, $post_repeat_setting = null) {
163 163
 
164
-	if ( is_null( $post_repeat_setting ) ) {
165
-		$post_repeat_setting = isset( $_POST['hm-post-repeat'] ) ? sanitize_text_field( $_POST['hm-post-repeat'] ) : '';
164
+	if (is_null($post_repeat_setting)) {
165
+		$post_repeat_setting = isset($_POST['hm-post-repeat']) ? sanitize_text_field($_POST['hm-post-repeat']) : '';
166 166
 	}
167 167
 
168
-	if ( ! in_array( get_post_type( $post_id ), repeating_post_types() ) || empty( $post_repeat_setting ) ) {
168
+	if ( ! in_array(get_post_type($post_id), repeating_post_types()) || empty($post_repeat_setting)) {
169 169
 		return;
170 170
 	}
171 171
 
172
-	if ( 'no' === $post_repeat_setting ) {
173
-		delete_post_meta( $post_id, 'hm-post-repeat' );
172
+	if ('no' === $post_repeat_setting) {
173
+		delete_post_meta($post_id, 'hm-post-repeat');
174 174
 	}
175 175
 
176 176
 	// Make sure we have a valid schedule.
177
-	elseif ( in_array( $post_repeat_setting, array_keys( get_repeating_schedules() ) ) ) {
178
-		update_post_meta( $post_id, 'hm-post-repeat', $post_repeat_setting );
177
+	elseif (in_array($post_repeat_setting, array_keys(get_repeating_schedules()))) {
178
+		update_post_meta($post_id, 'hm-post-repeat', $post_repeat_setting);
179 179
 	}
180 180
 
181 181
 }
@@ -191,50 +191,50 @@  discard block
 block discarded – undo
191 191
  *
192 192
  * @param int $post_id The ID of the post.
193 193
  */
194
-function create_next_repeat_post( $post_id ) {
194
+function create_next_repeat_post($post_id) {
195 195
 
196
-	if ( ! in_array( get_post_type( $post_id ), repeating_post_types() ) ) {
196
+	if ( ! in_array(get_post_type($post_id), repeating_post_types())) {
197 197
 		return false;
198 198
 	}
199 199
 
200
-	if ( 'publish' !== get_post_status( $post_id ) ) {
200
+	if ('publish' !== get_post_status($post_id)) {
201 201
 		return false;
202 202
 	}
203 203
 
204
-	$original_post_id = get_repeating_post( $post_id );
204
+	$original_post_id = get_repeating_post($post_id);
205 205
 
206 206
 	// Bail if we're not publishing a repeat(ing) post
207
-	if ( ! $original_post_id ) {
207
+	if ( ! $original_post_id) {
208 208
 		return false;
209 209
 	}
210 210
 
211
-	$original_post = get_post( $original_post_id, ARRAY_A );
211
+	$original_post = get_post($original_post_id, ARRAY_A);
212 212
 
213 213
 	// If there is already a repeat post scheduled don't create another one
214
-	if ( get_next_scheduled_repeat_post( $original_post['ID'] ) ) {
214
+	if (get_next_scheduled_repeat_post($original_post['ID'])) {
215 215
 		return false;
216 216
 	}
217 217
 
218 218
 	// Bail if the saved schedule doesn't exist
219
-	$repeating_schedule = get_repeating_schedule( $original_post['ID'] );
219
+	$repeating_schedule = get_repeating_schedule($original_post['ID']);
220 220
 
221
-	if ( ! $repeating_schedule ) {
221
+	if ( ! $repeating_schedule) {
222 222
 		return false;
223 223
 	}
224 224
 
225 225
 	// Bail if the original post isn't already published
226
-	if ( 'publish' !== $original_post['post_status'] ) {
226
+	if ('publish' !== $original_post['post_status']) {
227 227
 		return false;
228 228
 	}
229 229
 
230 230
 	$next_post = $original_post;
231 231
 
232 232
 	// Create the repeat post as a copy of the original, but ignore some fields
233
-	unset( $next_post['ID'] );
234
-	unset( $next_post['guid'] );
235
-	unset( $next_post['post_date_gmt'] );
236
-	unset( $next_post['post_modified'] );
237
-	unset( $next_post['post_modified_gmt'] );
233
+	unset($next_post['ID']);
234
+	unset($next_post['guid']);
235
+	unset($next_post['post_date_gmt']);
236
+	unset($next_post['post_modified']);
237
+	unset($next_post['post_modified_gmt']);
238 238
 
239 239
 	// We set the post_parent to the original post_id, so they're related
240 240
 	$next_post['post_parent'] = $original_post['ID'];
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
 	$next_post['post_status'] = 'future';
244 244
 
245 245
 	// Use the date of the current post being saved as the base
246
-	$next_post['post_date'] = date( 'Y-m-d H:i:s', strtotime( get_post_field( 'post_date', $post_id ) . ' + ' . $repeating_schedule['interval'] ) );
246
+	$next_post['post_date'] = date('Y-m-d H:i:s', strtotime(get_post_field('post_date', $post_id).' + '.$repeating_schedule['interval']));
247 247
 
248 248
 	// Make sure the next post will be in the future
249
-	if ( strtotime( $next_post['post_date'] ) <= time() ) {
249
+	if (strtotime($next_post['post_date']) <= time()) {
250 250
 		return false;
251 251
 	}
252 252
 
@@ -257,39 +257,39 @@  discard block
 block discarded – undo
257 257
 	 * @param array $repeating_schedule Repeating schedule info.
258 258
 	 * @param array $original_post      The original repeating post.
259 259
 	 */
260
-	$next_post = apply_filters( 'hm_post_repeat_edit_repeat_post', $next_post, $repeating_schedule, $original_post );
260
+	$next_post = apply_filters('hm_post_repeat_edit_repeat_post', $next_post, $repeating_schedule, $original_post);
261 261
 
262 262
 	// All checks done, get that post scheduled!
263
-	$next_post_id = wp_insert_post( wp_slash( $next_post ), true );
263
+	$next_post_id = wp_insert_post(wp_slash($next_post), true);
264 264
 
265
-	if ( is_wp_error( $next_post_id ) ) {
265
+	if (is_wp_error($next_post_id)) {
266 266
 		return false;
267 267
 	}
268 268
 
269 269
 	// Mirror any post_meta
270
-	$post_meta = get_post_meta( $original_post['ID'] );
270
+	$post_meta = get_post_meta($original_post['ID']);
271 271
 
272
-	if ( $post_meta  ) {
272
+	if ($post_meta) {
273 273
 
274 274
 		// Ignore some internal meta fields
275
-		unset( $post_meta['_edit_lock'] );
276
-		unset( $post_meta['_edit_last'] );
275
+		unset($post_meta['_edit_lock']);
276
+		unset($post_meta['_edit_last']);
277 277
 
278 278
 		// Don't copy the post repeat meta as only the original post should have that
279
-		unset( $post_meta['hm-post-repeat'] );
279
+		unset($post_meta['hm-post-repeat']);
280 280
 
281
-		foreach ( $post_meta as $key => $values ) {
282
-			foreach ( $values as $value ) {
283
-				add_post_meta( $next_post_id, $key, maybe_unserialize( $value ) );
281
+		foreach ($post_meta as $key => $values) {
282
+			foreach ($values as $value) {
283
+				add_post_meta($next_post_id, $key, maybe_unserialize($value));
284 284
 			}
285 285
 		}
286 286
 	}
287 287
 
288 288
 	// Mirror any term relationships
289
-	$taxonomies = get_object_taxonomies( $original_post['post_type'] );
289
+	$taxonomies = get_object_taxonomies($original_post['post_type']);
290 290
 
291
-	foreach ( $taxonomies as $taxonomy ) {
292
-		wp_set_object_terms( $next_post_id, wp_list_pluck( wp_get_object_terms( $original_post['ID'], $taxonomy ), 'slug' ), $taxonomy );
291
+	foreach ($taxonomies as $taxonomy) {
292
+		wp_set_object_terms($next_post_id, wp_list_pluck(wp_get_object_terms($original_post['ID'], $taxonomy), 'slug'), $taxonomy);
293 293
 	}
294 294
 
295 295
 	return $next_post_id;
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 	 *
311 311
 	 * @param string[] $post_types Post type slugs.
312 312
 	 */
313
-	return apply_filters( 'hm_post_repeat_post_types', array( 'post' ) );
313
+	return apply_filters('hm_post_repeat_post_types', array('post'));
314 314
 
315 315
 }
316 316
 
@@ -326,13 +326,13 @@  discard block
 block discarded – undo
326 326
 	 *
327 327
 	 * @param array[] $schedules Schedule array items.
328 328
 	 */
329
-	$schedules = apply_filters( 'hm_post_repeat_schedules', array(
330
-		'daily'   => array( 'interval' => '1 day',   'display' => __( 'Daily',   'hm-post-repeat' ) ),
331
-		'weekly'  => array( 'interval' => '1 week',  'display' => __( 'Weekly',  'hm-post-repeat' ) ),
332
-		'monthly' => array( 'interval' => '1 month', 'display' => __( 'Monthly', 'hm-post-repeat' ) ),
333
-	) );
329
+	$schedules = apply_filters('hm_post_repeat_schedules', array(
330
+		'daily'   => array('interval' => '1 day', 'display' => __('Daily', 'hm-post-repeat')),
331
+		'weekly'  => array('interval' => '1 week', 'display' => __('Weekly', 'hm-post-repeat')),
332
+		'monthly' => array('interval' => '1 month', 'display' => __('Monthly', 'hm-post-repeat')),
333
+	));
334 334
 
335
-	foreach ( $schedules as $slug => &$schedule ) {
335
+	foreach ($schedules as $slug => &$schedule) {
336 336
 		$schedule['slug'] = $slug;
337 337
 	}
338 338
 
@@ -346,22 +346,22 @@  discard block
 block discarded – undo
346 346
  * @param int $post_id The id of the post you want to check.
347 347
  * @return array|null The schedule to repeat by, or null if invalid.
348 348
  */
349
-function get_repeating_schedule( $post_id ) {
349
+function get_repeating_schedule($post_id) {
350 350
 
351
-	if ( ! is_repeating_post( $post_id ) ) {
351
+	if ( ! is_repeating_post($post_id)) {
352 352
 		return;
353 353
 	}
354 354
 
355
-	$repeating_schedule = get_post_meta( $post_id, 'hm-post-repeat', true );
355
+	$repeating_schedule = get_post_meta($post_id, 'hm-post-repeat', true);
356 356
 	$schedules = get_repeating_schedules();
357 357
 
358 358
 	// Backwards compatibility with 0.3 when we only supported weekly
359
-	if ( '1' === $repeating_schedule ) {
359
+	if ('1' === $repeating_schedule) {
360 360
 		$repeating_schedule = 'weekly';
361 361
 	}
362 362
 
363
-	if ( array_key_exists( $repeating_schedule, $schedules ) ) {
364
-		return $schedules[ $repeating_schedule ];
363
+	if (array_key_exists($repeating_schedule, $schedules)) {
364
+		return $schedules[$repeating_schedule];
365 365
 	}
366 366
 
367 367
 }
@@ -375,17 +375,17 @@  discard block
 block discarded – undo
375 375
  *
376 376
  * @return bool Whether the passed post_id is a repeating post or not.
377 377
  */
378
-function is_repeating_post( $post_id ) {
378
+function is_repeating_post($post_id) {
379 379
 
380 380
 	// We check $_POST data so that this function works inside a `save_post` hook when the post_meta hasn't yet been saved.
381
-	if ( isset( $_POST['hm-post-repeat'] ) && isset( $_POST['ID'] ) && $_POST['ID'] === $post_id ) {
381
+	if (isset($_POST['hm-post-repeat']) && isset($_POST['ID']) && $_POST['ID'] === $post_id) {
382 382
 		return true;
383 383
 	}
384 384
 
385 385
 	// For saved posts - Repeating post has meta key and does NOT have a parent.
386
-	$post_parent = get_post_field( 'post_parent', $post_id );
386
+	$post_parent = get_post_field('post_parent', $post_id);
387 387
 
388
-	if ( ! $post_parent && get_post_meta( $post_id, 'hm-post-repeat', true ) ) {
388
+	if ( ! $post_parent && get_post_meta($post_id, 'hm-post-repeat', true)) {
389 389
 		return true;
390 390
 	}
391 391
 
@@ -402,12 +402,12 @@  discard block
 block discarded – undo
402 402
  *
403 403
  * @return bool Whether the passed post_id is a repeat post or not.
404 404
  */
405
-function is_repeat_post( $post_id ) {
405
+function is_repeat_post($post_id) {
406 406
 
407 407
 	// Repeat post has meta key and has a parent.
408
-	$post_parent = get_post_field( 'post_parent', $post_id );
408
+	$post_parent = get_post_field('post_parent', $post_id);
409 409
 
410
-	if ( $post_parent && get_post_meta( $post_parent, 'hm-post-repeat', true ) ) {
410
+	if ($post_parent && get_post_meta($post_parent, 'hm-post-repeat', true)) {
411 411
 		return true;
412 412
 	}
413 413
 
@@ -421,13 +421,13 @@  discard block
 block discarded – undo
421 421
  * @param int $post_id The id of a repeat or repeating post
422 422
  * @return Int|Bool Return the ID of the next repeat post_id or false if it can't find one
423 423
  */
424
-function get_next_scheduled_repeat_post( $post_id ) {
424
+function get_next_scheduled_repeat_post($post_id) {
425 425
 
426
-	$post = get_post( get_repeating_post( $post_id ) );
426
+	$post = get_post(get_repeating_post($post_id));
427 427
 
428
-	$repeat_posts = get_posts( array( 'post_status' => 'future', 'post_parent' => $post->ID ) );
428
+	$repeat_posts = get_posts(array('post_status' => 'future', 'post_parent' => $post->ID));
429 429
 
430
-	if ( isset( $repeat_posts[0] ) ) {
430
+	if (isset($repeat_posts[0])) {
431 431
 	 	return $repeat_posts[0];
432 432
 	}
433 433
 
@@ -441,17 +441,17 @@  discard block
 block discarded – undo
441 441
  * @param int $post_id The id of a repeat or repeating post
442 442
  * @return Int|Bool Return the original repeating post_id or false if it can't find it
443 443
  */
444
-function get_repeating_post( $post_id ) {
444
+function get_repeating_post($post_id) {
445 445
 
446 446
 	$original_post_id = false;
447 447
 
448 448
 	// Are we publishing a repeat post
449
-	if ( is_repeat_post( $post_id ) ) {
450
-		$original_post_id = get_post( $post_id )->post_parent;
449
+	if (is_repeat_post($post_id)) {
450
+		$original_post_id = get_post($post_id)->post_parent;
451 451
 	}
452 452
 
453 453
 	// Or the original
454
-	elseif ( is_repeating_post( $post_id ) ) {
454
+	elseif (is_repeating_post($post_id)) {
455 455
 		$original_post_id = $post_id;
456 456
 	}
457 457
 
@@ -469,10 +469,10 @@  discard block
 block discarded – undo
469 469
  *
470 470
  * @return array Available list of table views with custom added views per repeat type.
471 471
  */
472
-function admin_table_views_links( $views ) {
472
+function admin_table_views_links($views) {
473 473
 
474 474
 	// Add status link for each repeat type.
475
-	foreach ( get_available_repeat_types() as $repeat_type => $repeat_desc ) {
475
+	foreach (get_available_repeat_types() as $repeat_type => $repeat_desc) {
476 476
 
477 477
 		$url_args = array(
478 478
 			'post_type'      => get_current_screen()->post_type,
@@ -480,12 +480,12 @@  discard block
 block discarded – undo
480 480
 		);
481 481
 
482 482
 		// Custom WP_Query to get posts count of repeat type.
483
-		$repeat_type_query = new \WP_Query( get_repeat_type_query_params( $repeat_type ) );
483
+		$repeat_type_query = new \WP_Query(get_repeat_type_query_params($repeat_type));
484 484
 
485 485
 		$link_label = sprintf(
486 486
 				'%s <span class="count">(%s)</span>',
487
-			esc_html( $repeat_desc ),
488
-			esc_html( number_format_i18n( $repeat_type_query->post_count ) )
487
+			esc_html($repeat_desc),
488
+			esc_html(number_format_i18n($repeat_type_query->post_count))
489 489
 		);
490 490
 
491 491
 		/**
@@ -496,19 +496,19 @@  discard block
 block discarded – undo
496 496
 		$class_html = '';
497 497
 		if (
498 498
 			get_repeat_type_url_param() === $repeat_type &&
499
-			! isset( $_GET['post_parent'] )
499
+			! isset($_GET['post_parent'])
500 500
 		) {
501 501
 			$class_html = ' class="current"';
502 502
 		}
503 503
 
504 504
 		$link_html = sprintf(
505 505
 			'<a href="%s"%s>%s</a>',
506
-			esc_url( add_query_arg( $url_args, 'edit.php' ) ),
506
+			esc_url(add_query_arg($url_args, 'edit.php')),
507 507
 			$class_html, // html - hardcoded, no need to escape.
508 508
 			$link_label  // html - escaped earlier in the code.
509 509
 		);
510 510
 
511
-		$views[ $repeat_type ] = $link_html;
511
+		$views[$repeat_type] = $link_html;
512 512
 	}
513 513
 
514 514
 	return $views;
@@ -526,26 +526,26 @@  discard block
 block discarded – undo
526 526
  *
527 527
  * @return mixed Main admin query with edited params to get posts of specified repeat type.
528 528
  */
529
-function admin_table_repeat_type_posts_query( $wp_query ) {
529
+function admin_table_repeat_type_posts_query($wp_query) {
530 530
 
531 531
 	// Stop - if not admin or not main query (there are secondary WP_Query for counting posts for view links, etc).
532
-	if ( ! is_admin() || ! $wp_query->is_main_query() ) {
532
+	if ( ! is_admin() || ! $wp_query->is_main_query()) {
533 533
 		return $wp_query;
534 534
 	}
535 535
 
536 536
 	// Get URL query param for repeat type and check it's valid.
537 537
 	$repeat_type = get_repeat_type_url_param();
538 538
 
539
-	if ( ! $repeat_type || ! is_allowed_repeat_type( $repeat_type ) ) {
539
+	if ( ! $repeat_type || ! is_allowed_repeat_type($repeat_type)) {
540 540
 		return $wp_query;
541 541
 	}
542 542
 
543 543
 	// Repeat post display - only displaying Repeat posts for a specific Repeating post.
544
-	$post_parent_id = isset( $_GET['post_parent'] ) ? intval( $_GET['post_parent'] ) : 0;
544
+	$post_parent_id = isset($_GET['post_parent']) ? intval($_GET['post_parent']) : 0;
545 545
 
546 546
 	// Add WP_Query param depending on displayed repeat type.
547
-	foreach ( get_repeat_type_query_params( $repeat_type, $post_parent_id ) as $key => $value ) {
548
-		$wp_query->set( $key, $value );
547
+	foreach (get_repeat_type_query_params($repeat_type, $post_parent_id) as $key => $value) {
548
+		$wp_query->set($key, $value);
549 549
 	}
550 550
 
551 551
 	return $wp_query;
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
  *
561 561
  * @return array Array of custom WP_Query params.
562 562
  */
563
-function get_repeat_type_query_params( $repeat_type, $post_parent_id = 0 ) {
563
+function get_repeat_type_query_params($repeat_type, $post_parent_id = 0) {
564 564
 
565 565
 	$query['post_type'] = get_current_screen()->post_type;
566 566
 
@@ -572,15 +572,15 @@  discard block
 block discarded – undo
572 572
 			),
573 573
 	);
574 574
 
575
-	if ( $repeat_type === 'repeat' ) {
576
-		$query['post_parent__not_in'] = array( 0 );
575
+	if ($repeat_type === 'repeat') {
576
+		$query['post_parent__not_in'] = array(0);
577 577
 
578
-	} elseif ( $repeat_type === 'repeating' ) {
579
-		$query['post_parent__in'] = array( 0 );
578
+	} elseif ($repeat_type === 'repeating') {
579
+		$query['post_parent__in'] = array(0);
580 580
 	}
581 581
 
582 582
 	// Repeat post display - only displaying Repeat posts for specific Repeating post.
583
-	if ( $post_parent_id ) {
583
+	if ($post_parent_id) {
584 584
 		$query['post_parent']         = $post_parent_id;
585 585
 		$query['post_parent__not_in'] = '';
586 586
 		$query['post_parent__in']     = '';
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
  * @return string Sanitized string of repeat type being displayed.
597 597
  */
598 598
 function get_repeat_type_url_param() {
599
-	return isset( $_GET['hm-post-repeat'] ) ? sanitize_text_field( $_GET['hm-post-repeat'] ) : '';
599
+	return isset($_GET['hm-post-repeat']) ? sanitize_text_field($_GET['hm-post-repeat']) : '';
600 600
 }
601 601
 
602 602
 /**
@@ -606,8 +606,8 @@  discard block
 block discarded – undo
606 606
  */
607 607
 function get_available_repeat_types() {
608 608
 	return array(
609
-		'repeating' => __( 'Repeating', 'hm-post-repeat' ),
610
-		'repeat'    => __( 'Repeat', 'hm-post-repeat' ),
609
+		'repeating' => __('Repeating', 'hm-post-repeat'),
610
+		'repeat'    => __('Repeat', 'hm-post-repeat'),
611 611
 	);
612 612
 }
613 613
 
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
  * @return bool True if repeat type is valid,
620 620
  *              False otherwise.
621 621
  */
622
-function is_allowed_repeat_type( $repeat_type ) {
623
-	return in_array( $repeat_type, array_keys( get_available_repeat_types() ) );
622
+function is_allowed_repeat_type($repeat_type) {
623
+	return in_array($repeat_type, array_keys(get_available_repeat_types()));
624 624
 }
625 625
 
626 626
 /**
@@ -635,9 +635,9 @@  discard block
 block discarded – undo
635 635
  *
636 636
  * @return array An array of row action links with added link to view Repeat posts and there count.
637 637
  */
638
-function admin_table_row_actions_view_repeat_posts( $actions, $post ) {
638
+function admin_table_row_actions_view_repeat_posts($actions, $post) {
639 639
 
640
-	if ( ! is_repeating_post( $post->ID ) ) {
640
+	if ( ! is_repeating_post($post->ID)) {
641 641
 		return $actions;
642 642
 	}
643 643
 
@@ -649,44 +649,44 @@  discard block
 block discarded – undo
649 649
 	);
650 650
 
651 651
 	// TODO: I think this is an expensive thing to do per each post. Maybe we can store Repeat post count in meta data?
652
-	$repeat_posts_query = new \WP_Query( get_repeat_type_query_params( 'repeat', $post->ID ) );
652
+	$repeat_posts_query = new \WP_Query(get_repeat_type_query_params('repeat', $post->ID));
653 653
 	$repeat_posts_count = $repeat_posts_query->post_count;
654 654
 
655
-	if ( $repeat_posts_count ) {
655
+	if ($repeat_posts_count) {
656 656
 		$actions['view_repeat'] = sprintf(
657 657
 			'<a href="%s" aria-label="%s">%s</a>',
658
-			esc_url( add_query_arg( $url_args, 'edit.php' ) ),
659
-			esc_attr( sprintf(
658
+			esc_url(add_query_arg($url_args, 'edit.php')),
659
+			esc_attr(sprintf(
660 660
 				_n(
661 661
 					'View %d repeat post',
662 662
 					'View %d repeat posts',
663 663
 					$repeat_posts_count,
664 664
 					'hm-post-repeat'
665 665
 				),
666
-				number_format_i18n( $repeat_posts_count )
667
-			) ),
668
-			esc_html( sprintf(
666
+				number_format_i18n($repeat_posts_count)
667
+			)),
668
+			esc_html(sprintf(
669 669
 				_n(
670 670
 					'%d repeat post',
671 671
 					'%d repeat posts',
672 672
 					$repeat_posts_count,
673 673
 					'hm-post-repeat'
674 674
 				),
675
-				number_format_i18n( $repeat_posts_count )
676
-			) )
675
+				number_format_i18n($repeat_posts_count)
676
+			))
677 677
 		);
678 678
 	} else {
679 679
 
680 680
 		// 0 Repeat post - display text, not a link.
681
-		$actions['view_repeat'] = esc_html( sprintf(
681
+		$actions['view_repeat'] = esc_html(sprintf(
682 682
 			_n(
683 683
 				'%d repeat post',
684 684
 				'%d repeat posts',
685 685
 				$repeat_posts_count,
686 686
 				'hm-post-repeat'
687 687
 			),
688
-			number_format_i18n( $repeat_posts_count )
689
-		) );
688
+			number_format_i18n($repeat_posts_count)
689
+		));
690 690
 	}
691 691
 
692 692
 	return $actions;
Please login to merge, or discard this patch.