@@ -82,9 +82,12 @@ |
||
| 82 | 82 | |
| 83 | 83 | <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> |
| 84 | 84 | |
| 85 | - <?php else : ?> |
|
| 85 | + <?php else { |
|
| 86 | + : ?> |
|
| 86 | 87 | |
| 87 | - <?php $repeating_schedule = get_repeating_schedule( get_the_id() ); ?> |
|
| 88 | + <?php $repeating_schedule = get_repeating_schedule( get_the_id() ); |
|
| 89 | +} |
|
| 90 | +?> |
|
| 88 | 91 | <?php $is_repeating_post = is_repeating_post( get_the_id() ) && isset( $repeating_schedule ); ?> |
| 89 | 92 | |
| 90 | 93 | <strong><?php echo ! $is_repeating_post ? esc_html__( 'No', 'hm-post-repeat' ) : esc_html( $repeating_schedule['display'] ); ?></strong> |
@@ -35,27 +35,27 @@ 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__ . '\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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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,44 +231,44 @@ discard block |
||
| 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 | |
| 241 | 241 | // All checks done, get that post scheduled! |
| 242 | - $next_post_id = wp_insert_post( wp_slash( $next_post ), true ); |
|
| 242 | + $next_post_id = wp_insert_post(wp_slash($next_post), true); |
|
| 243 | 243 | |
| 244 | - if ( is_wp_error( $next_post_id ) ) { |
|
| 244 | + if (is_wp_error($next_post_id)) { |
|
| 245 | 245 | return false; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // Mirror any post_meta |
| 249 | - $post_meta = get_post_meta( $original_post['ID'] ); |
|
| 249 | + $post_meta = get_post_meta($original_post['ID']); |
|
| 250 | 250 | |
| 251 | - if ( $post_meta ) { |
|
| 251 | + if ($post_meta) { |
|
| 252 | 252 | |
| 253 | 253 | // Ignore some internal meta fields |
| 254 | - unset( $post_meta['_edit_lock'] ); |
|
| 255 | - unset( $post_meta['_edit_last'] ); |
|
| 254 | + unset($post_meta['_edit_lock']); |
|
| 255 | + unset($post_meta['_edit_last']); |
|
| 256 | 256 | |
| 257 | 257 | // Don't copy the post repeat meta as only the original post should have that |
| 258 | - unset( $post_meta['hm-post-repeat'] ); |
|
| 258 | + unset($post_meta['hm-post-repeat']); |
|
| 259 | 259 | |
| 260 | - foreach ( $post_meta as $key => $values ) { |
|
| 261 | - foreach ( $values as $value ) { |
|
| 262 | - add_post_meta( $next_post_id, $key, maybe_unserialize( $value ) ); |
|
| 260 | + foreach ($post_meta as $key => $values) { |
|
| 261 | + foreach ($values as $value) { |
|
| 262 | + add_post_meta($next_post_id, $key, maybe_unserialize($value)); |
|
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | // Mirror any term relationships |
| 268 | - $taxonomies = get_object_taxonomies( $original_post['post_type'] ); |
|
| 268 | + $taxonomies = get_object_taxonomies($original_post['post_type']); |
|
| 269 | 269 | |
| 270 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 271 | - wp_set_object_terms( $next_post_id, wp_list_pluck( wp_get_object_terms( $original_post['ID'], $taxonomy ), 'slug' ), $taxonomy ); |
|
| 270 | + foreach ($taxonomies as $taxonomy) { |
|
| 271 | + wp_set_object_terms($next_post_id, wp_list_pluck(wp_get_object_terms($original_post['ID'], $taxonomy), 'slug'), $taxonomy); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | return $next_post_id; |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | * |
| 290 | 290 | * @param string[] $post_types Post type slugs. |
| 291 | 291 | */ |
| 292 | - return apply_filters( 'hm_post_repeat_post_types', array( 'post' ) ); |
|
| 292 | + return apply_filters('hm_post_repeat_post_types', array('post')); |
|
| 293 | 293 | |
| 294 | 294 | } |
| 295 | 295 | |
@@ -305,14 +305,14 @@ discard block |
||
| 305 | 305 | * |
| 306 | 306 | * @param array[] $schedules Schedule array items. |
| 307 | 307 | */ |
| 308 | - $schedules = apply_filters( 'hm_post_repeat_schedules', array( |
|
| 309 | - 'daily' => array( 'interval' => '1 day', 'display' => __( 'Daily', 'hm-post-repeat' ) ), |
|
| 310 | - 'weekly' => array( 'interval' => '1 week', 'display' => __( 'Weekly', 'hm-post-repeat' ) ), |
|
| 311 | - 'monthly' => array( 'interval' => '1 month', 'display' => __( 'Monthly', 'hm-post-repeat' ) ), |
|
| 312 | - 'yearly' => array( 'interval' => '1 year', 'display' => __( 'Yearly', 'hm-post-repeat' ) ) |
|
| 313 | - ) ); |
|
| 314 | - |
|
| 315 | - foreach ( $schedules as $slug => &$schedule ) { |
|
| 308 | + $schedules = apply_filters('hm_post_repeat_schedules', array( |
|
| 309 | + 'daily' => array('interval' => '1 day', 'display' => __('Daily', 'hm-post-repeat')), |
|
| 310 | + 'weekly' => array('interval' => '1 week', 'display' => __('Weekly', 'hm-post-repeat')), |
|
| 311 | + 'monthly' => array('interval' => '1 month', 'display' => __('Monthly', 'hm-post-repeat')), |
|
| 312 | + 'yearly' => array('interval' => '1 year', 'display' => __('Yearly', 'hm-post-repeat')) |
|
| 313 | + )); |
|
| 314 | + |
|
| 315 | + foreach ($schedules as $slug => &$schedule) { |
|
| 316 | 316 | $schedule['slug'] = $slug; |
| 317 | 317 | } |
| 318 | 318 | |
@@ -326,22 +326,22 @@ discard block |
||
| 326 | 326 | * @param int $post_id The id of the post you want to check. |
| 327 | 327 | * @return array|null The schedule to repeat by, or null if invalid. |
| 328 | 328 | */ |
| 329 | -function get_repeating_schedule( $post_id ) { |
|
| 329 | +function get_repeating_schedule($post_id) { |
|
| 330 | 330 | |
| 331 | - if ( ! is_repeating_post( $post_id ) ) { |
|
| 331 | + if ( ! is_repeating_post($post_id)) { |
|
| 332 | 332 | return; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - $repeating_schedule = get_post_meta( $post_id, 'hm-post-repeat', true ); |
|
| 335 | + $repeating_schedule = get_post_meta($post_id, 'hm-post-repeat', true); |
|
| 336 | 336 | $schedules = get_repeating_schedules(); |
| 337 | 337 | |
| 338 | 338 | // Backwards compatibility with 0.3 when we only supported weekly |
| 339 | - if ( '1' === $repeating_schedule ) { |
|
| 339 | + if ('1' === $repeating_schedule) { |
|
| 340 | 340 | $repeating_schedule = 'weekly'; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - if ( array_key_exists( $repeating_schedule, $schedules ) ) { |
|
| 344 | - return $schedules[ $repeating_schedule ]; |
|
| 343 | + if (array_key_exists($repeating_schedule, $schedules)) { |
|
| 344 | + return $schedules[$repeating_schedule]; |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | } |
@@ -354,14 +354,14 @@ discard block |
||
| 354 | 354 | * @param int $post_id The id of the post you want to check. |
| 355 | 355 | * @return bool Whether the passed post_id is a repeating post or not. |
| 356 | 356 | */ |
| 357 | -function is_repeating_post( $post_id ) { |
|
| 357 | +function is_repeating_post($post_id) { |
|
| 358 | 358 | |
| 359 | 359 | // We check $_POST data so that this function works inside a `save_post` hook when the post_meta hasn't yet been saved |
| 360 | - if ( isset( $_POST['hm-post-repeat'] ) && isset( $_POST['ID'] ) && $_POST['ID'] === $post_id ) { |
|
| 360 | + if (isset($_POST['hm-post-repeat']) && isset($_POST['ID']) && $_POST['ID'] === $post_id) { |
|
| 361 | 361 | return true; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - if ( get_post_meta( $post_id, 'hm-post-repeat', true ) ) { |
|
| 364 | + if (get_post_meta($post_id, 'hm-post-repeat', true)) { |
|
| 365 | 365 | return true; |
| 366 | 366 | } |
| 367 | 367 | |
@@ -377,11 +377,11 @@ discard block |
||
| 377 | 377 | * @param int $post_id The id of the post you want to check. |
| 378 | 378 | * @return bool Whether the passed post_id is a repeat post or not. |
| 379 | 379 | */ |
| 380 | -function is_repeat_post( $post_id ) { |
|
| 380 | +function is_repeat_post($post_id) { |
|
| 381 | 381 | |
| 382 | - $post_parent = get_post_field( 'post_parent', $post_id ); |
|
| 382 | + $post_parent = get_post_field('post_parent', $post_id); |
|
| 383 | 383 | |
| 384 | - if ( $post_parent && get_post_meta( $post_parent, 'hm-post-repeat', true ) ) { |
|
| 384 | + if ($post_parent && get_post_meta($post_parent, 'hm-post-repeat', true)) { |
|
| 385 | 385 | return true; |
| 386 | 386 | } |
| 387 | 387 | |
@@ -395,13 +395,13 @@ discard block |
||
| 395 | 395 | * @param int $post_id The id of a repeat or repeating post |
| 396 | 396 | * @return Int|Bool Return the ID of the next repeat post_id or false if it can't find one |
| 397 | 397 | */ |
| 398 | -function get_next_scheduled_repeat_post( $post_id ) { |
|
| 398 | +function get_next_scheduled_repeat_post($post_id) { |
|
| 399 | 399 | |
| 400 | - $post = get_post( get_repeating_post( $post_id ) ); |
|
| 400 | + $post = get_post(get_repeating_post($post_id)); |
|
| 401 | 401 | |
| 402 | - $repeat_posts = get_posts( array( 'post_status' => 'future', 'post_parent' => $post->ID ) ); |
|
| 402 | + $repeat_posts = get_posts(array('post_status' => 'future', 'post_parent' => $post->ID)); |
|
| 403 | 403 | |
| 404 | - if ( isset( $repeat_posts[0] ) ) { |
|
| 404 | + if (isset($repeat_posts[0])) { |
|
| 405 | 405 | return $repeat_posts[0]; |
| 406 | 406 | } |
| 407 | 407 | |
@@ -415,17 +415,17 @@ discard block |
||
| 415 | 415 | * @param int $post_id The id of a repeat or repeating post |
| 416 | 416 | * @return Int|Bool Return the original repeating post_id or false if it can't find it |
| 417 | 417 | */ |
| 418 | -function get_repeating_post( $post_id ) { |
|
| 418 | +function get_repeating_post($post_id) { |
|
| 419 | 419 | |
| 420 | 420 | $original_post_id = false; |
| 421 | 421 | |
| 422 | 422 | // Are we publishing a repeat post |
| 423 | - if ( is_repeat_post( $post_id ) ) { |
|
| 424 | - $original_post_id = get_post( $post_id )->post_parent; |
|
| 423 | + if (is_repeat_post($post_id)) { |
|
| 424 | + $original_post_id = get_post($post_id)->post_parent; |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | // Or the original |
| 428 | - elseif ( is_repeating_post( $post_id ) ) { |
|
| 428 | + elseif (is_repeating_post($post_id)) { |
|
| 429 | 429 | $original_post_id = $post_id; |
| 430 | 430 | } |
| 431 | 431 | |