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 (#25)
by
unknown
01:44
created
hm-post-repeat.php 1 patch
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -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,31 +75,31 @@  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
-			<?php $repeating_schedule = get_repeating_schedule( get_the_id() ); ?>
87
-			<?php $is_repeating_post = is_repeating_post( get_the_id() ) && isset( $repeating_schedule ); ?>
86
+			<?php $repeating_schedule = get_repeating_schedule(get_the_id()); ?>
87
+			<?php $is_repeating_post = is_repeating_post(get_the_id()) && isset($repeating_schedule); ?>
88 88
 
89
-			<strong><?php echo ! $is_repeating_post ? esc_html__( 'No', 'hm-post-repeat' ) : esc_html( $repeating_schedule['display'] ); ?></strong>
89
+			<strong><?php echo ! $is_repeating_post ? esc_html__('No', 'hm-post-repeat') : esc_html($repeating_schedule['display']); ?></strong>
90 90
 
91
-			<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>
91
+			<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>
92 92
 
93 93
 			<span class="hide-if-js" id="hm-post-repeat">
94 94
 
95 95
 				<select name="hm-post-repeat">
96
-					<option<?php selected( ! $is_repeating_post ); ?> value="no"><?php esc_html_e( 'No', 'hm-post-repeat' ); ?></option>
97
-					<?php foreach ( get_repeating_schedules() as $schedule_slug => $schedule ) : ?>
98
-						<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>
96
+					<option<?php selected( ! $is_repeating_post); ?> value="no"><?php esc_html_e('No', 'hm-post-repeat'); ?></option>
97
+					<?php foreach (get_repeating_schedules() as $schedule_slug => $schedule) : ?>
98
+						<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>
99 99
 					<?php endforeach; ?>
100 100
 				</select>
101 101
 
102
-				<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>
102
+				<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>
103 103
 
104 104
 			</span>
105 105
 
@@ -118,21 +118,21 @@  discard block
 block discarded – undo
118 118
  * @param WP_Post $post        The post object to get / return the states.
119 119
  * @return array The array of post states with ours added.
120 120
  */
121
-function post_states( $post_states, $post ) {
121
+function post_states($post_states, $post) {
122 122
 
123
-	if ( is_repeating_post( $post->ID ) ) {
123
+	if (is_repeating_post($post->ID)) {
124 124
 
125 125
 		// If the schedule has been removed since publishing, let the user know.
126
-		if ( get_repeating_schedule( $post->ID ) ) {
127
-			$post_states['hm-post-repeat'] = __( 'Repeating', 'hm-post-repeat' );
126
+		if (get_repeating_schedule($post->ID)) {
127
+			$post_states['hm-post-repeat'] = __('Repeating', 'hm-post-repeat');
128 128
 		} else {
129
-			$post_states['hm-post-repeat'] = __( 'Invalid Repeating Schedule', 'hm-post-repeat' );
129
+			$post_states['hm-post-repeat'] = __('Invalid Repeating Schedule', 'hm-post-repeat');
130 130
 		}
131 131
 
132 132
 	}
133 133
 
134
-	if ( is_repeat_post( $post->ID ) ) {
135
-		$post_states['hm-post-repeat'] = __( 'Repeat', 'hm-post-repeat' );
134
+	if (is_repeat_post($post->ID)) {
135
+		$post_states['hm-post-repeat'] = __('Repeat', 'hm-post-repeat');
136 136
 	}
137 137
 
138 138
 	return $post_states;
@@ -147,23 +147,23 @@  discard block
 block discarded – undo
147 147
  * @param int    $post_id             The ID of the post.
148 148
  * @param string $post_repeat_setting Used to manually set the repeating schedule from tests.
149 149
  */
150
-function save_post_repeating_status( $post_id = null, $post_repeat_setting = null ) {
150
+function save_post_repeating_status($post_id = null, $post_repeat_setting = null) {
151 151
 
152
-	if ( is_null( $post_repeat_setting ) ) {
153
-		$post_repeat_setting = isset( $_POST['hm-post-repeat'] ) ? sanitize_text_field( $_POST['hm-post-repeat'] ) : '';
152
+	if (is_null($post_repeat_setting)) {
153
+		$post_repeat_setting = isset($_POST['hm-post-repeat']) ? sanitize_text_field($_POST['hm-post-repeat']) : '';
154 154
 	}
155 155
 
156
-	if ( ! in_array( get_post_type( $post_id ), repeating_post_types() ) || empty( $post_repeat_setting ) ) {
156
+	if ( ! in_array(get_post_type($post_id), repeating_post_types()) || empty($post_repeat_setting)) {
157 157
 		return;
158 158
 	}
159 159
 
160
-	if ( 'no' === $post_repeat_setting ) {
161
-		delete_post_meta( $post_id, 'hm-post-repeat' );
160
+	if ('no' === $post_repeat_setting) {
161
+		delete_post_meta($post_id, 'hm-post-repeat');
162 162
 	}
163 163
 
164 164
 	// Make sure we have a valid schedule.
165
-	elseif ( in_array( $post_repeat_setting, array_keys( get_repeating_schedules() ) ) ) {
166
-		update_post_meta( $post_id, 'hm-post-repeat', $post_repeat_setting );
165
+	elseif (in_array($post_repeat_setting, array_keys(get_repeating_schedules()))) {
166
+		update_post_meta($post_id, 'hm-post-repeat', $post_repeat_setting);
167 167
 	}
168 168
 
169 169
 }
@@ -179,50 +179,50 @@  discard block
 block discarded – undo
179 179
  *
180 180
  * @param int $post_id The ID of the post.
181 181
  */
182
-function create_next_repeat_post( $post_id ) {
182
+function create_next_repeat_post($post_id) {
183 183
 
184
-	if ( ! in_array( get_post_type( $post_id ), repeating_post_types() ) ) {
184
+	if ( ! in_array(get_post_type($post_id), repeating_post_types())) {
185 185
 		return false;
186 186
 	}
187 187
 
188
-	if ( 'publish' !== get_post_status( $post_id ) ) {
188
+	if ('publish' !== get_post_status($post_id)) {
189 189
 		return false;
190 190
 	}
191 191
 
192
-	$original_post_id = get_repeating_post( $post_id );
192
+	$original_post_id = get_repeating_post($post_id);
193 193
 
194 194
 	// Bail if we're not publishing a repeat(ing) post
195
-	if ( ! $original_post_id ) {
195
+	if ( ! $original_post_id) {
196 196
 		return false;
197 197
 	}
198 198
 
199
-	$original_post = get_post( $original_post_id, ARRAY_A );
199
+	$original_post = get_post($original_post_id, ARRAY_A);
200 200
 
201 201
 	// If there is already a repeat post scheduled don't create another one
202
-	if ( get_next_scheduled_repeat_post( $original_post['ID'] ) ) {
202
+	if (get_next_scheduled_repeat_post($original_post['ID'])) {
203 203
 		return false;
204 204
 	}
205 205
 
206 206
 	// Bail if the saved schedule doesn't exist
207
-	$repeating_schedule = get_repeating_schedule( $original_post['ID'] );
207
+	$repeating_schedule = get_repeating_schedule($original_post['ID']);
208 208
 
209
-	if ( ! $repeating_schedule ) {
209
+	if ( ! $repeating_schedule) {
210 210
 		return false;
211 211
 	}
212 212
 
213 213
 	// Bail if the original post isn't already published
214
-	if ( 'publish' !== $original_post['post_status'] ) {
214
+	if ('publish' !== $original_post['post_status']) {
215 215
 		return false;
216 216
 	}
217 217
 
218 218
 	$next_post = $original_post;
219 219
 
220 220
 	// Create the repeat post as a copy of the original, but ignore some fields
221
-	unset( $next_post['ID'] );
222
-	unset( $next_post['guid'] );
223
-	unset( $next_post['post_date_gmt'] );
224
-	unset( $next_post['post_modified'] );
225
-	unset( $next_post['post_modified_gmt'] );
221
+	unset($next_post['ID']);
222
+	unset($next_post['guid']);
223
+	unset($next_post['post_date_gmt']);
224
+	unset($next_post['post_modified']);
225
+	unset($next_post['post_modified_gmt']);
226 226
 
227 227
 	// We set the post_parent to the original post_id, so they're related
228 228
 	$next_post['post_parent'] = $original_post['ID'];
@@ -231,10 +231,10 @@  discard block
 block discarded – undo
231 231
 	$next_post['post_status'] = 'future';
232 232
 
233 233
 	// Use the date of the current post being saved as the base
234
-	$next_post['post_date'] = date( 'Y-m-d H:i:s', strtotime( get_post_field( 'post_date', $post_id ) . ' + ' . $repeating_schedule['interval'] ) );
234
+	$next_post['post_date'] = date('Y-m-d H:i:s', strtotime(get_post_field('post_date', $post_id).' + '.$repeating_schedule['interval']));
235 235
 
236 236
 	// Make sure the next post will be in the future
237
-	if ( strtotime( $next_post['post_date'] ) <= time() ) {
237
+	if (strtotime($next_post['post_date']) <= time()) {
238 238
 		return false;
239 239
 	}
240 240
 
@@ -245,39 +245,39 @@  discard block
 block discarded – undo
245 245
 	 * @param array $repeating_schedule Repeating schedule info.
246 246
 	 * @param array $original_post      The original repeating post.
247 247
 	 */
248
-	$next_post = apply_filters( 'hm_post_repeat_edit_repeat_post', $next_post, $repeating_schedule, $original_post );
248
+	$next_post = apply_filters('hm_post_repeat_edit_repeat_post', $next_post, $repeating_schedule, $original_post);
249 249
 
250 250
 	// All checks done, get that post scheduled!
251
-	$next_post_id = wp_insert_post( wp_slash( $next_post ), true );
251
+	$next_post_id = wp_insert_post(wp_slash($next_post), true);
252 252
 
253
-	if ( is_wp_error( $next_post_id ) ) {
253
+	if (is_wp_error($next_post_id)) {
254 254
 		return false;
255 255
 	}
256 256
 
257 257
 	// Mirror any post_meta
258
-	$post_meta = get_post_meta( $original_post['ID'] );
258
+	$post_meta = get_post_meta($original_post['ID']);
259 259
 
260
-	if ( $post_meta  ) {
260
+	if ($post_meta) {
261 261
 
262 262
 		// Ignore some internal meta fields
263
-		unset( $post_meta['_edit_lock'] );
264
-		unset( $post_meta['_edit_last'] );
263
+		unset($post_meta['_edit_lock']);
264
+		unset($post_meta['_edit_last']);
265 265
 
266 266
 		// Don't copy the post repeat meta as only the original post should have that
267
-		unset( $post_meta['hm-post-repeat'] );
267
+		unset($post_meta['hm-post-repeat']);
268 268
 
269
-		foreach ( $post_meta as $key => $values ) {
270
-			foreach ( $values as $value ) {
271
-				add_post_meta( $next_post_id, $key, maybe_unserialize( $value ) );
269
+		foreach ($post_meta as $key => $values) {
270
+			foreach ($values as $value) {
271
+				add_post_meta($next_post_id, $key, maybe_unserialize($value));
272 272
 			}
273 273
 		}
274 274
 	}
275 275
 
276 276
 	// Mirror any term relationships
277
-	$taxonomies = get_object_taxonomies( $original_post['post_type'] );
277
+	$taxonomies = get_object_taxonomies($original_post['post_type']);
278 278
 
279
-	foreach ( $taxonomies as $taxonomy ) {
280
-		wp_set_object_terms( $next_post_id, wp_list_pluck( wp_get_object_terms( $original_post['ID'], $taxonomy ), 'slug' ), $taxonomy );
279
+	foreach ($taxonomies as $taxonomy) {
280
+		wp_set_object_terms($next_post_id, wp_list_pluck(wp_get_object_terms($original_post['ID'], $taxonomy), 'slug'), $taxonomy);
281 281
 	}
282 282
 
283 283
 	return $next_post_id;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 	 *
299 299
 	 * @param string[] $post_types Post type slugs.
300 300
 	 */
301
-	return apply_filters( 'hm_post_repeat_post_types', array( 'post' ) );
301
+	return apply_filters('hm_post_repeat_post_types', array('post'));
302 302
 
303 303
 }
304 304
 
@@ -314,13 +314,13 @@  discard block
 block discarded – undo
314 314
 	 *
315 315
 	 * @param array[] $schedules Schedule array items.
316 316
 	 */
317
-	$schedules = apply_filters( 'hm_post_repeat_schedules', array(
318
-		'daily'   => array( 'interval' => '1 day',   'display' => __( 'Daily',   'hm-post-repeat' ) ),
319
-		'weekly'  => array( 'interval' => '1 week',  'display' => __( 'Weekly',  'hm-post-repeat' ) ),
320
-		'monthly' => array( 'interval' => '1 month', 'display' => __( 'Monthly', 'hm-post-repeat' ) ),
321
-	) );
317
+	$schedules = apply_filters('hm_post_repeat_schedules', array(
318
+		'daily'   => array('interval' => '1 day', 'display' => __('Daily', 'hm-post-repeat')),
319
+		'weekly'  => array('interval' => '1 week', 'display' => __('Weekly', 'hm-post-repeat')),
320
+		'monthly' => array('interval' => '1 month', 'display' => __('Monthly', 'hm-post-repeat')),
321
+	));
322 322
 
323
-	foreach ( $schedules as $slug => &$schedule ) {
323
+	foreach ($schedules as $slug => &$schedule) {
324 324
 		$schedule['slug'] = $slug;
325 325
 	}
326 326
 
@@ -334,22 +334,22 @@  discard block
 block discarded – undo
334 334
  * @param int $post_id The id of the post you want to check.
335 335
  * @return array|null The schedule to repeat by, or null if invalid.
336 336
  */
337
-function get_repeating_schedule( $post_id ) {
337
+function get_repeating_schedule($post_id) {
338 338
 
339
-	if ( ! is_repeating_post( $post_id ) ) {
339
+	if ( ! is_repeating_post($post_id)) {
340 340
 		return;
341 341
 	}
342 342
 
343
-	$repeating_schedule = get_post_meta( $post_id, 'hm-post-repeat', true );
343
+	$repeating_schedule = get_post_meta($post_id, 'hm-post-repeat', true);
344 344
 	$schedules = get_repeating_schedules();
345 345
 
346 346
 	// Backwards compatibility with 0.3 when we only supported weekly
347
-	if ( '1' === $repeating_schedule ) {
347
+	if ('1' === $repeating_schedule) {
348 348
 		$repeating_schedule = 'weekly';
349 349
 	}
350 350
 
351
-	if ( array_key_exists( $repeating_schedule, $schedules ) ) {
352
-		return $schedules[ $repeating_schedule ];
351
+	if (array_key_exists($repeating_schedule, $schedules)) {
352
+		return $schedules[$repeating_schedule];
353 353
 	}
354 354
 
355 355
 }
@@ -362,14 +362,14 @@  discard block
 block discarded – undo
362 362
  * @param int $post_id The id of the post you want to check.
363 363
  * @return bool Whether the passed post_id is a repeating post or not.
364 364
  */
365
-function is_repeating_post( $post_id ) {
365
+function is_repeating_post($post_id) {
366 366
 
367 367
 	// We check $_POST data so that this function works inside a `save_post` hook when the post_meta hasn't yet been saved
368
-	if ( isset( $_POST['hm-post-repeat'] ) && isset( $_POST['ID'] ) && $_POST['ID'] === $post_id ) {
368
+	if (isset($_POST['hm-post-repeat']) && isset($_POST['ID']) && $_POST['ID'] === $post_id) {
369 369
 		return true;
370 370
 	}
371 371
 
372
-	if ( get_post_meta( $post_id, 'hm-post-repeat', true ) ) {
372
+	if (get_post_meta($post_id, 'hm-post-repeat', true)) {
373 373
 		return true;
374 374
 	}
375 375
 
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
  * @param int $post_id The id of the post you want to check.
386 386
  * @return bool Whether the passed post_id is a repeat post or not.
387 387
  */
388
-function is_repeat_post( $post_id ) {
388
+function is_repeat_post($post_id) {
389 389
 
390
-	$post_parent = get_post_field( 'post_parent', $post_id );
390
+	$post_parent = get_post_field('post_parent', $post_id);
391 391
 
392
-	if ( $post_parent && get_post_meta( $post_parent, 'hm-post-repeat', true ) ) {
392
+	if ($post_parent && get_post_meta($post_parent, 'hm-post-repeat', true)) {
393 393
 		return true;
394 394
 	}
395 395
 
@@ -403,13 +403,13 @@  discard block
 block discarded – undo
403 403
  * @param int $post_id The id of a repeat or repeating post
404 404
  * @return Int|Bool Return the ID of the next repeat post_id or false if it can't find one
405 405
  */
406
-function get_next_scheduled_repeat_post( $post_id ) {
406
+function get_next_scheduled_repeat_post($post_id) {
407 407
 
408
-	$post = get_post( get_repeating_post( $post_id ) );
408
+	$post = get_post(get_repeating_post($post_id));
409 409
 
410
-	$repeat_posts = get_posts( array( 'post_status' => 'future', 'post_parent' => $post->ID ) );
410
+	$repeat_posts = get_posts(array('post_status' => 'future', 'post_parent' => $post->ID));
411 411
 
412
-	if ( isset( $repeat_posts[0] ) ) {
412
+	if (isset($repeat_posts[0])) {
413 413
 	 	return $repeat_posts[0];
414 414
 	}
415 415
 
@@ -423,17 +423,17 @@  discard block
 block discarded – undo
423 423
  * @param int $post_id The id of a repeat or repeating post
424 424
  * @return Int|Bool Return the original repeating post_id or false if it can't find it
425 425
  */
426
-function get_repeating_post( $post_id ) {
426
+function get_repeating_post($post_id) {
427 427
 
428 428
 	$original_post_id = false;
429 429
 
430 430
 	// Are we publishing a repeat post
431
-	if ( is_repeat_post( $post_id ) ) {
432
-		$original_post_id = get_post( $post_id )->post_parent;
431
+	if (is_repeat_post($post_id)) {
432
+		$original_post_id = get_post($post_id)->post_parent;
433 433
 	}
434 434
 
435 435
 	// Or the original
436
-	elseif ( is_repeating_post( $post_id ) ) {
436
+	elseif (is_repeating_post($post_id)) {
437 437
 		$original_post_id = $post_id;
438 438
 	}
439 439
 
Please login to merge, or discard this patch.