@@ -35,37 +35,37 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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; |
@@ -156,23 +156,23 @@ discard block |
||
| 156 | 156 | * @param int $post_id The ID of the post. |
| 157 | 157 | * @param string $post_repeat_setting Used to manually set the repeating schedule from tests. |
| 158 | 158 | */ |
| 159 | -function save_post_repeating_status( $post_id = null, $post_repeat_setting = null ) { |
|
| 159 | +function save_post_repeating_status($post_id = null, $post_repeat_setting = null) { |
|
| 160 | 160 | |
| 161 | - if ( is_null( $post_repeat_setting ) ) { |
|
| 162 | - $post_repeat_setting = isset( $_POST['hm-post-repeat'] ) ? sanitize_text_field( $_POST['hm-post-repeat'] ) : ''; |
|
| 161 | + if (is_null($post_repeat_setting)) { |
|
| 162 | + $post_repeat_setting = isset($_POST['hm-post-repeat']) ? sanitize_text_field($_POST['hm-post-repeat']) : ''; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - if ( ! in_array( get_post_type( $post_id ), repeating_post_types() ) || empty( $post_repeat_setting ) ) { |
|
| 165 | + if ( ! in_array(get_post_type($post_id), repeating_post_types()) || empty($post_repeat_setting)) { |
|
| 166 | 166 | return; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if ( 'no' === $post_repeat_setting ) { |
|
| 170 | - delete_post_meta( $post_id, 'hm-post-repeat' ); |
|
| 169 | + if ('no' === $post_repeat_setting) { |
|
| 170 | + delete_post_meta($post_id, 'hm-post-repeat'); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // Make sure we have a valid schedule. |
| 174 | - elseif ( in_array( $post_repeat_setting, array_keys( get_repeating_schedules() ) ) ) { |
|
| 175 | - update_post_meta( $post_id, 'hm-post-repeat', $post_repeat_setting ); |
|
| 174 | + elseif (in_array($post_repeat_setting, array_keys(get_repeating_schedules()))) { |
|
| 175 | + update_post_meta($post_id, 'hm-post-repeat', $post_repeat_setting); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | } |
@@ -188,50 +188,50 @@ discard block |
||
| 188 | 188 | * |
| 189 | 189 | * @param int $post_id The ID of the post. |
| 190 | 190 | */ |
| 191 | -function create_next_repeat_post( $post_id ) { |
|
| 191 | +function create_next_repeat_post($post_id) { |
|
| 192 | 192 | |
| 193 | - if ( ! in_array( get_post_type( $post_id ), repeating_post_types() ) ) { |
|
| 193 | + if ( ! in_array(get_post_type($post_id), repeating_post_types())) { |
|
| 194 | 194 | return false; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - if ( 'publish' !== get_post_status( $post_id ) ) { |
|
| 197 | + if ('publish' !== get_post_status($post_id)) { |
|
| 198 | 198 | return false; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - $original_post_id = get_repeating_post( $post_id ); |
|
| 201 | + $original_post_id = get_repeating_post($post_id); |
|
| 202 | 202 | |
| 203 | 203 | // Bail if we're not publishing a repeat(ing) post |
| 204 | - if ( ! $original_post_id ) { |
|
| 204 | + if ( ! $original_post_id) { |
|
| 205 | 205 | return false; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - $original_post = get_post( $original_post_id, ARRAY_A ); |
|
| 208 | + $original_post = get_post($original_post_id, ARRAY_A); |
|
| 209 | 209 | |
| 210 | 210 | // If there is already a repeat post scheduled don't create another one |
| 211 | - if ( get_next_scheduled_repeat_post( $original_post['ID'] ) ) { |
|
| 211 | + if (get_next_scheduled_repeat_post($original_post['ID'])) { |
|
| 212 | 212 | return false; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | // Bail if the saved schedule doesn't exist |
| 216 | - $repeating_schedule = get_repeating_schedule( $original_post['ID'] ); |
|
| 216 | + $repeating_schedule = get_repeating_schedule($original_post['ID']); |
|
| 217 | 217 | |
| 218 | - if ( ! $repeating_schedule ) { |
|
| 218 | + if ( ! $repeating_schedule) { |
|
| 219 | 219 | return false; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // Bail if the original post isn't already published |
| 223 | - if ( 'publish' !== $original_post['post_status'] ) { |
|
| 223 | + if ('publish' !== $original_post['post_status']) { |
|
| 224 | 224 | return false; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | $next_post = $original_post; |
| 228 | 228 | |
| 229 | 229 | // Create the repeat post as a copy of the original, but ignore some fields |
| 230 | - unset( $next_post['ID'] ); |
|
| 231 | - unset( $next_post['guid'] ); |
|
| 232 | - unset( $next_post['post_date_gmt'] ); |
|
| 233 | - unset( $next_post['post_modified'] ); |
|
| 234 | - unset( $next_post['post_modified_gmt'] ); |
|
| 230 | + unset($next_post['ID']); |
|
| 231 | + unset($next_post['guid']); |
|
| 232 | + unset($next_post['post_date_gmt']); |
|
| 233 | + unset($next_post['post_modified']); |
|
| 234 | + unset($next_post['post_modified_gmt']); |
|
| 235 | 235 | |
| 236 | 236 | // We set the post_parent to the original post_id, so they're related |
| 237 | 237 | $next_post['post_parent'] = $original_post['ID']; |
@@ -240,10 +240,10 @@ discard block |
||
| 240 | 240 | $next_post['post_status'] = 'future'; |
| 241 | 241 | |
| 242 | 242 | // Use the date of the current post being saved as the base |
| 243 | - $next_post['post_date'] = date( 'Y-m-d H:i:s', strtotime( get_post_field( 'post_date', $post_id ) . ' + ' . $repeating_schedule['interval'] ) ); |
|
| 243 | + $next_post['post_date'] = date('Y-m-d H:i:s', strtotime(get_post_field('post_date', $post_id).' + '.$repeating_schedule['interval'])); |
|
| 244 | 244 | |
| 245 | 245 | // Make sure the next post will be in the future |
| 246 | - if ( strtotime( $next_post['post_date'] ) <= time() ) { |
|
| 246 | + if (strtotime($next_post['post_date']) <= time()) { |
|
| 247 | 247 | return false; |
| 248 | 248 | } |
| 249 | 249 | |
@@ -254,39 +254,39 @@ discard block |
||
| 254 | 254 | * @param array $repeating_schedule Repeating schedule info. |
| 255 | 255 | * @param array $original_post The original repeating post. |
| 256 | 256 | */ |
| 257 | - $next_post = apply_filters( 'hm_post_repeat_edit_repeat_post', $next_post, $repeating_schedule, $original_post ); |
|
| 257 | + $next_post = apply_filters('hm_post_repeat_edit_repeat_post', $next_post, $repeating_schedule, $original_post); |
|
| 258 | 258 | |
| 259 | 259 | // All checks done, get that post scheduled! |
| 260 | - $next_post_id = wp_insert_post( wp_slash( $next_post ), true ); |
|
| 260 | + $next_post_id = wp_insert_post(wp_slash($next_post), true); |
|
| 261 | 261 | |
| 262 | - if ( is_wp_error( $next_post_id ) ) { |
|
| 262 | + if (is_wp_error($next_post_id)) { |
|
| 263 | 263 | return false; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // Mirror any post_meta |
| 267 | - $post_meta = get_post_meta( $original_post['ID'] ); |
|
| 267 | + $post_meta = get_post_meta($original_post['ID']); |
|
| 268 | 268 | |
| 269 | - if ( $post_meta ) { |
|
| 269 | + if ($post_meta) { |
|
| 270 | 270 | |
| 271 | 271 | // Ignore some internal meta fields |
| 272 | - unset( $post_meta['_edit_lock'] ); |
|
| 273 | - unset( $post_meta['_edit_last'] ); |
|
| 272 | + unset($post_meta['_edit_lock']); |
|
| 273 | + unset($post_meta['_edit_last']); |
|
| 274 | 274 | |
| 275 | 275 | // Don't copy the post repeat meta as only the original post should have that |
| 276 | - unset( $post_meta['hm-post-repeat'] ); |
|
| 276 | + unset($post_meta['hm-post-repeat']); |
|
| 277 | 277 | |
| 278 | - foreach ( $post_meta as $key => $values ) { |
|
| 279 | - foreach ( $values as $value ) { |
|
| 280 | - add_post_meta( $next_post_id, $key, maybe_unserialize( $value ) ); |
|
| 278 | + foreach ($post_meta as $key => $values) { |
|
| 279 | + foreach ($values as $value) { |
|
| 280 | + add_post_meta($next_post_id, $key, maybe_unserialize($value)); |
|
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | // Mirror any term relationships |
| 286 | - $taxonomies = get_object_taxonomies( $original_post['post_type'] ); |
|
| 286 | + $taxonomies = get_object_taxonomies($original_post['post_type']); |
|
| 287 | 287 | |
| 288 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 289 | - wp_set_object_terms( $next_post_id, wp_list_pluck( wp_get_object_terms( $original_post['ID'], $taxonomy ), 'slug' ), $taxonomy ); |
|
| 288 | + foreach ($taxonomies as $taxonomy) { |
|
| 289 | + wp_set_object_terms($next_post_id, wp_list_pluck(wp_get_object_terms($original_post['ID'], $taxonomy), 'slug'), $taxonomy); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | return $next_post_id; |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | * |
| 308 | 308 | * @param string[] $post_types Post type slugs. |
| 309 | 309 | */ |
| 310 | - return apply_filters( 'hm_post_repeat_post_types', array( 'post' ) ); |
|
| 310 | + return apply_filters('hm_post_repeat_post_types', array('post')); |
|
| 311 | 311 | |
| 312 | 312 | } |
| 313 | 313 | |
@@ -323,13 +323,13 @@ discard block |
||
| 323 | 323 | * |
| 324 | 324 | * @param array[] $schedules Schedule array items. |
| 325 | 325 | */ |
| 326 | - $schedules = apply_filters( 'hm_post_repeat_schedules', array( |
|
| 327 | - 'daily' => array( 'interval' => '1 day', 'display' => __( 'Daily', 'hm-post-repeat' ) ), |
|
| 328 | - 'weekly' => array( 'interval' => '1 week', 'display' => __( 'Weekly', 'hm-post-repeat' ) ), |
|
| 329 | - 'monthly' => array( 'interval' => '1 month', 'display' => __( 'Monthly', 'hm-post-repeat' ) ), |
|
| 330 | - ) ); |
|
| 326 | + $schedules = apply_filters('hm_post_repeat_schedules', array( |
|
| 327 | + 'daily' => array('interval' => '1 day', 'display' => __('Daily', 'hm-post-repeat')), |
|
| 328 | + 'weekly' => array('interval' => '1 week', 'display' => __('Weekly', 'hm-post-repeat')), |
|
| 329 | + 'monthly' => array('interval' => '1 month', 'display' => __('Monthly', 'hm-post-repeat')), |
|
| 330 | + )); |
|
| 331 | 331 | |
| 332 | - foreach ( $schedules as $slug => &$schedule ) { |
|
| 332 | + foreach ($schedules as $slug => &$schedule) { |
|
| 333 | 333 | $schedule['slug'] = $slug; |
| 334 | 334 | } |
| 335 | 335 | |
@@ -343,22 +343,22 @@ discard block |
||
| 343 | 343 | * @param int $post_id The id of the post you want to check. |
| 344 | 344 | * @return array|null The schedule to repeat by, or null if invalid. |
| 345 | 345 | */ |
| 346 | -function get_repeating_schedule( $post_id ) { |
|
| 346 | +function get_repeating_schedule($post_id) { |
|
| 347 | 347 | |
| 348 | - if ( ! is_repeating_post( $post_id ) ) { |
|
| 348 | + if ( ! is_repeating_post($post_id)) { |
|
| 349 | 349 | return; |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - $repeating_schedule = get_post_meta( $post_id, 'hm-post-repeat', true ); |
|
| 352 | + $repeating_schedule = get_post_meta($post_id, 'hm-post-repeat', true); |
|
| 353 | 353 | $schedules = get_repeating_schedules(); |
| 354 | 354 | |
| 355 | 355 | // Backwards compatibility with 0.3 when we only supported weekly |
| 356 | - if ( '1' === $repeating_schedule ) { |
|
| 356 | + if ('1' === $repeating_schedule) { |
|
| 357 | 357 | $repeating_schedule = 'weekly'; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - if ( array_key_exists( $repeating_schedule, $schedules ) ) { |
|
| 361 | - return $schedules[ $repeating_schedule ]; |
|
| 360 | + if (array_key_exists($repeating_schedule, $schedules)) { |
|
| 361 | + return $schedules[$repeating_schedule]; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | } |
@@ -371,14 +371,14 @@ discard block |
||
| 371 | 371 | * @param int $post_id The id of the post you want to check. |
| 372 | 372 | * @return bool Whether the passed post_id is a repeating post or not. |
| 373 | 373 | */ |
| 374 | -function is_repeating_post( $post_id ) { |
|
| 374 | +function is_repeating_post($post_id) { |
|
| 375 | 375 | |
| 376 | 376 | // We check $_POST data so that this function works inside a `save_post` hook when the post_meta hasn't yet been saved |
| 377 | - if ( isset( $_POST['hm-post-repeat'] ) && isset( $_POST['ID'] ) && $_POST['ID'] === $post_id ) { |
|
| 377 | + if (isset($_POST['hm-post-repeat']) && isset($_POST['ID']) && $_POST['ID'] === $post_id) { |
|
| 378 | 378 | return true; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - if ( get_post_meta( $post_id, 'hm-post-repeat', true ) ) { |
|
| 381 | + if (get_post_meta($post_id, 'hm-post-repeat', true)) { |
|
| 382 | 382 | return true; |
| 383 | 383 | } |
| 384 | 384 | |
@@ -394,11 +394,11 @@ discard block |
||
| 394 | 394 | * @param int $post_id The id of the post you want to check. |
| 395 | 395 | * @return bool Whether the passed post_id is a repeat post or not. |
| 396 | 396 | */ |
| 397 | -function is_repeat_post( $post_id ) { |
|
| 397 | +function is_repeat_post($post_id) { |
|
| 398 | 398 | |
| 399 | - $post_parent = get_post_field( 'post_parent', $post_id ); |
|
| 399 | + $post_parent = get_post_field('post_parent', $post_id); |
|
| 400 | 400 | |
| 401 | - if ( $post_parent && get_post_meta( $post_parent, 'hm-post-repeat', true ) ) { |
|
| 401 | + if ($post_parent && get_post_meta($post_parent, 'hm-post-repeat', true)) { |
|
| 402 | 402 | return true; |
| 403 | 403 | } |
| 404 | 404 | |
@@ -412,13 +412,13 @@ discard block |
||
| 412 | 412 | * @param int $post_id The id of a repeat or repeating post |
| 413 | 413 | * @return Int|Bool Return the ID of the next repeat post_id or false if it can't find one |
| 414 | 414 | */ |
| 415 | -function get_next_scheduled_repeat_post( $post_id ) { |
|
| 415 | +function get_next_scheduled_repeat_post($post_id) { |
|
| 416 | 416 | |
| 417 | - $post = get_post( get_repeating_post( $post_id ) ); |
|
| 417 | + $post = get_post(get_repeating_post($post_id)); |
|
| 418 | 418 | |
| 419 | - $repeat_posts = get_posts( array( 'post_status' => 'future', 'post_parent' => $post->ID ) ); |
|
| 419 | + $repeat_posts = get_posts(array('post_status' => 'future', 'post_parent' => $post->ID)); |
|
| 420 | 420 | |
| 421 | - if ( isset( $repeat_posts[0] ) ) { |
|
| 421 | + if (isset($repeat_posts[0])) { |
|
| 422 | 422 | return $repeat_posts[0]; |
| 423 | 423 | } |
| 424 | 424 | |
@@ -432,17 +432,17 @@ discard block |
||
| 432 | 432 | * @param int $post_id The id of a repeat or repeating post |
| 433 | 433 | * @return Int|Bool Return the original repeating post_id or false if it can't find it |
| 434 | 434 | */ |
| 435 | -function get_repeating_post( $post_id ) { |
|
| 435 | +function get_repeating_post($post_id) { |
|
| 436 | 436 | |
| 437 | 437 | $original_post_id = false; |
| 438 | 438 | |
| 439 | 439 | // Are we publishing a repeat post |
| 440 | - if ( is_repeat_post( $post_id ) ) { |
|
| 441 | - $original_post_id = get_post( $post_id )->post_parent; |
|
| 440 | + if (is_repeat_post($post_id)) { |
|
| 441 | + $original_post_id = get_post($post_id)->post_parent; |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | // Or the original |
| 445 | - elseif ( is_repeating_post( $post_id ) ) { |
|
| 445 | + elseif (is_repeating_post($post_id)) { |
|
| 446 | 446 | $original_post_id = $post_id; |
| 447 | 447 | } |
| 448 | 448 | |
@@ -460,10 +460,10 @@ discard block |
||
| 460 | 460 | * |
| 461 | 461 | * @return array Available list of table views with custom added views per repeat type. |
| 462 | 462 | */ |
| 463 | -function admin_table_views_links( $views ) { |
|
| 463 | +function admin_table_views_links($views) { |
|
| 464 | 464 | |
| 465 | 465 | // Add status link for each repeat type. |
| 466 | - foreach ( get_available_repeat_types() as $repeat_type => $repeat_desc ) { |
|
| 466 | + foreach (get_available_repeat_types() as $repeat_type => $repeat_desc) { |
|
| 467 | 467 | |
| 468 | 468 | $url_args = array( |
| 469 | 469 | 'post_type' => get_current_screen()->post_type, |
@@ -471,25 +471,25 @@ discard block |
||
| 471 | 471 | ); |
| 472 | 472 | |
| 473 | 473 | // Custom WP_Query to get posts count of repeat type. |
| 474 | - $repeat_type_query = new \WP_Query( get_repeat_type_query_params( $repeat_type ) ); |
|
| 474 | + $repeat_type_query = new \WP_Query(get_repeat_type_query_params($repeat_type)); |
|
| 475 | 475 | |
| 476 | 476 | $link_label = sprintf( |
| 477 | 477 | '%s <span class="count">(%s)</span>', |
| 478 | - esc_html( $repeat_desc ), |
|
| 479 | - esc_html( number_format_i18n( $repeat_type_query->post_count ) ) |
|
| 478 | + esc_html($repeat_desc), |
|
| 479 | + esc_html(number_format_i18n($repeat_type_query->post_count)) |
|
| 480 | 480 | ); |
| 481 | 481 | |
| 482 | 482 | // Add current class to the link to highlight it when it's selected. |
| 483 | - $class_html = ( get_repeat_type_url_param() === $repeat_type ) ? ' class="current"' : ''; |
|
| 483 | + $class_html = (get_repeat_type_url_param() === $repeat_type) ? ' class="current"' : ''; |
|
| 484 | 484 | |
| 485 | 485 | $link_html = sprintf( |
| 486 | 486 | '<a href="%s"%s>%s</a>', |
| 487 | - esc_url( add_query_arg( $url_args, 'edit.php' ) ), |
|
| 487 | + esc_url(add_query_arg($url_args, 'edit.php')), |
|
| 488 | 488 | $class_html, // html - hardcoded, no need to escape. |
| 489 | 489 | $link_label // html - escaped earlier in the code. |
| 490 | 490 | ); |
| 491 | 491 | |
| 492 | - $views[ $repeat_type ] = $link_html; |
|
| 492 | + $views[$repeat_type] = $link_html; |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | return $views; |
@@ -503,23 +503,23 @@ discard block |
||
| 503 | 503 | * |
| 504 | 504 | * @return mixed Main admin query with edited params to get posts of specified repeat type. |
| 505 | 505 | */ |
| 506 | -function admin_table_repeat_type_posts_query( $wp_query ) { |
|
| 506 | +function admin_table_repeat_type_posts_query($wp_query) { |
|
| 507 | 507 | |
| 508 | 508 | // Stop - if not admin or not main query (there are secondary WP_Query for counting posts for view links, etc). |
| 509 | - if ( ! is_admin() || ! $wp_query->is_main_query() ) { |
|
| 509 | + if ( ! is_admin() || ! $wp_query->is_main_query()) { |
|
| 510 | 510 | return $wp_query; |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | // Get URL query param for repeat type and check it's valid. |
| 514 | 514 | $repeat_type = get_repeat_type_url_param(); |
| 515 | 515 | |
| 516 | - if ( ! $repeat_type || ! is_allowed_repeat_type( $repeat_type ) ) { |
|
| 516 | + if ( ! $repeat_type || ! is_allowed_repeat_type($repeat_type)) { |
|
| 517 | 517 | return $wp_query; |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | // Add a table view link per each repeat type. |
| 521 | - foreach ( get_repeat_type_query_params( $repeat_type ) as $key => $value ) { |
|
| 522 | - $wp_query->set( $key, $value ); |
|
| 521 | + foreach (get_repeat_type_query_params($repeat_type) as $key => $value) { |
|
| 522 | + $wp_query->set($key, $value); |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | return $wp_query; |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | * |
| 534 | 534 | * @return array Array of custom WP_Query params. |
| 535 | 535 | */ |
| 536 | -function get_repeat_type_query_params( $repeat_type ) { |
|
| 536 | +function get_repeat_type_query_params($repeat_type) { |
|
| 537 | 537 | |
| 538 | 538 | $query['post_type'] = get_current_screen()->post_type; |
| 539 | 539 | |
@@ -545,11 +545,11 @@ discard block |
||
| 545 | 545 | ), |
| 546 | 546 | ); |
| 547 | 547 | |
| 548 | - if ( $repeat_type === 'repeat' ) { |
|
| 549 | - $query['post_parent__not_in'] = array( 0 ); |
|
| 548 | + if ($repeat_type === 'repeat') { |
|
| 549 | + $query['post_parent__not_in'] = array(0); |
|
| 550 | 550 | |
| 551 | - } elseif ( $repeat_type === 'repeating' ) { |
|
| 552 | - $query['post_parent__in'] = array( 0 ); |
|
| 551 | + } elseif ($repeat_type === 'repeating') { |
|
| 552 | + $query['post_parent__in'] = array(0); |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | return $query; |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | * @return string Sanitized string of repeat type being displayed. |
| 563 | 563 | */ |
| 564 | 564 | function get_repeat_type_url_param() { |
| 565 | - return isset( $_GET['hm-post-repeat'] ) ? sanitize_text_field( $_GET['hm-post-repeat'] ) : ''; |
|
| 565 | + return isset($_GET['hm-post-repeat']) ? sanitize_text_field($_GET['hm-post-repeat']) : ''; |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | /** |
@@ -572,8 +572,8 @@ discard block |
||
| 572 | 572 | */ |
| 573 | 573 | function get_available_repeat_types() { |
| 574 | 574 | return array( |
| 575 | - 'repeating' => __( 'Repeating', 'hm-post-repeat' ), |
|
| 576 | - 'repeat' => __( 'Repeat', 'hm-post-repeat' ), |
|
| 575 | + 'repeating' => __('Repeating', 'hm-post-repeat'), |
|
| 576 | + 'repeat' => __('Repeat', 'hm-post-repeat'), |
|
| 577 | 577 | ); |
| 578 | 578 | } |
| 579 | 579 | |
@@ -585,6 +585,6 @@ discard block |
||
| 585 | 585 | * @return bool True if repeat type is valid, |
| 586 | 586 | * False otherwise. |
| 587 | 587 | */ |
| 588 | -function is_allowed_repeat_type( $repeat_type ) { |
|
| 589 | - return in_array( $repeat_type, array_keys( get_available_repeat_types() ) ); |
|
| 588 | +function is_allowed_repeat_type($repeat_type) { |
|
| 589 | + return in_array($repeat_type, array_keys(get_available_repeat_types())); |
|
| 590 | 590 | } |