= ( mc_is_all_day( $data ) ) ? '' : mc_date( 'H:i', mc_strtotime( $data->event_endtime ), false ); } else { // Set start date/time to last event. $transient_start = get_transient( 'mc_last_event' ); if ( is_array( $transient_start ) ) { $event_begin = $transient_start['begin']; $starttime = $transient_start['time']; } else { $event_begin = mc_date( 'Y-m-d' ); $starttime = ''; } $event_end = ''; $endtime = ''; } $allday = ( $has_data && ( mc_is_all_day( $data ) ) ) ? ' checked="checked"' : ''; $hide = ( $has_data && '1' === $data->event_hide_end ) ? ' checked="checked"' : ''; $allday_label = ( $has_data ) ? mc_notime_label( $data ) : mc_get_option( 'notime_text' ); $same_day = ( $has_data && 'true' === get_post_meta( $data->event_post, '_event_same_day', true ) ) ? ' checked="checked"' : ''; $args = array( 'value' => $event_begin, 'id' => 'mc_event_date', 'name' => 'event_begin[]', ); $picker_begin = mc_datepicker_html( $args ); $args = array( 'value' => $event_end, 'id' => 'mc_event_enddate', 'name' => 'event_end[]', ); $picker_end = mc_datepicker_html( $args ); /** * Set the latest time an event can be scheduled for. * * @hook mc_time_max * * @param {string} $max Time string. Default 00:00. * * @return {string} */ $max = apply_filters( 'mc_time_max', '00:00' ); /** * Set the earliest time an event can be scheduled for. * * @hook mc_time_min * * @param {string} $min Time string. Default 00:00. * * @return {string} */ $min = apply_filters( 'mc_time_min', '00:00' ); $attrs = ( '00:00' !== $min || '00:00' !== $max ) ? ' max="' . $max . '" min="' . $min . '"' : ''; $append = ''; $range = ''; $aria = ''; if ( '00:00' !== $max || '00:00' !== $min ) { // Translators: starting time, ending time. $range = '

' . sprintf( __( 'Times must be between %1$s and %2$s', 'my-calendar' ), mc_date( mc_time_format(), strtotime( $min ) ), mc_date( mc_time_format(), strtotime( $max ) ) ) . '

'; $aria = ' aria-describedby="mc_time_range_allowed"'; $append = '' . __( 'Invalid time', 'my-calendar' ) . ''; } $form .= $range . '

' . $append . '

' . $append . '

' . $picker_begin . '

' . $picker_end . '' . __( 'Your selected end date is before your start date.', 'my-calendar' ) . '

'; return $form; } /** * Repeatable date/time input form. * * @param string $form Previous defined values. * @param boolean $has_data Whether field has data. * @param object $data form data object. * @param string $context rendering context [not used]. */ function mc_repeatable_datetime_input( $form, $has_data, $data, $context = 'admin' ) { echo mc_get_repeatable_datetime_input( $form, $has_data, $data, $context = 'admin' ); } /** * Repeatable date/time input form. * * @param string $form Previous defined values. * @param boolean $has_data Whether field has data. * @param object $data form data object. * @param string $context rendering context [not used]. * * @return string submission form part */ function mc_get_repeatable_datetime_input( $form, $has_data, $data, $context = 'admin' ) { if ( $has_data ) { $event_begin = $data->event_begin; $event_end = $data->event_end; if ( isset( $_GET['date'] ) ) { $event = mc_get_event( (int) $_GET['date'] ); $event_begin = mc_date( 'Y-m-d', mc_strtotime( $event->occur_begin ), false ); $event_end = mc_date( 'Y-m-d', mc_strtotime( $event->occur_end ), false ); } // Set event end to empty if matches begin. Makes input and changes easier. if ( $event_begin === $event_end ) { $event_end = ''; } $starttime = ( mc_is_all_day( $data ) ) ? '' : mc_date( 'H:i', mc_strtotime( $data->event_time ), false ); $endtime = ( mc_is_all_day( $data ) ) ? '' : mc_date( 'H:i', mc_strtotime( $data->event_endtime ), false ); } else { $event_end = ''; $starttime = ''; $endtime = ''; } $form .= '

'; return $form; } /** * Date time inputs to add a single instance to recurring event info * * @param object $data Source event data. * * @return string form HTML */ function mc_recur_datetime_input( $data ) { $event_begin = ( $data->event_begin ) ? $data->event_begin : mc_date( 'Y-m-d' ); $event_end = ( $data->event_end && $data->event_end !== $data->event_begin ) ? $data->event_end : ''; $starttime = ( $data->event_time ) ? $data->event_time : ''; $endtime = ( $data->event_endtime ) ? $data->event_endtime : ''; $args = array( 'value' => $event_begin, 'id' => 'r_begin', 'name' => 'recur_begin[]', ); $picker_begin = mc_datepicker_html( $args ); $args = array( 'value' => $event_end, 'id' => 'r_end', 'name' => 'recur_end[]', ); $picker_end = mc_datepicker_html( $args ); $form = '

' . $picker_begin . '

' . $picker_end . '

'; return $form; } /** * Generate standard event registration info fields. * * @param string $form Form HTML. * @param boolean $has_data Does this event have data. * @param object $data Data for event. * @param string $context Context displayed in. * * @return string HTML output for form */ function mc_standard_event_registration( $form, $has_data, $data, $context = 'admin' ) { if ( $has_data ) { $tickets = $data->event_tickets; $registration = stripslashes( esc_attr( $data->event_registration ) ); } else { $tickets = ''; $registration = ''; } $form .= "

"; /** * Filter event registration form for event input. * * @hook mc_event_registration_form * * @param {string} $form Default form HTML output. * @param {bool} $has_data If this event has data. * @param {object} $data Event object. * @param {string} $context Admin context. * * @return {string} */ return apply_filters( 'mc_event_registration_form', $form, $has_data, $data, 'admin' ); } add_action( 'save_post', 'mc_post_update_event' ); /** * When updating event post, make sure changed featured image is copied into event. * * @param int $id Post ID. */ function mc_post_update_event( $id ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE || wp_is_post_revision( $id ) || ! ( get_post_type( $id ) === 'mc-events' ) ) { return $id; } // If event image fields are empty, don't image that's being removed back to the event. if ( isset( $_POST['event_image'] ) && '' === $_POST['event_image'] || isset( $_POST['event_image_id'] ) && '' === $_POST['event_image_id'] ) { return $id; } $post = get_post( $id ); $featured_image = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); $event_id = get_post_meta( $post->ID, '_mc_event_id', true ); if ( esc_url( $featured_image ) ) { mc_update_data( $event_id, 'event_image', $featured_image, '%s' ); } } /** * Generate controls for a given event * * @param string $mode Context of event editing page. * @param boolean $has_data Does this event have data. * @param object $event Event data. * @param string $position location of form. * * @return string output controls */ function mc_controls( $mode, $has_data, $event, $position = 'header' ) { $controls = array(); if ( 'edit' === $mode ) { $publish_text = __( 'Update', 'my-calendar' ); $event_id = $event->event_id; $mcnonce = wp_create_nonce( '_mcnonce' ); $url = add_query_arg( array( 'mode' => 'delete', 'event_id' => $event_id, '_mcnonce' => $mcnonce, ), admin_url( 'admin.php?page=my-calendar-manage' ) ); if ( isset( $_GET['date'] ) ) { $id = ( is_numeric( $_GET['date'] ) ) ? absint( $_GET['date'] ) : false; if ( $id ) { $url = add_query_arg( 'date', $id, $url ); } } $controls['delete'] = "" . __( 'Delete', 'my-calendar' ) . ''; /** * Check whether permalinks are enabled. * * @hook mc_use_permalinks * * @param {string} $option Value of mc_use_permalinks setting. * * @return {string} 'true' value if permalinks are enabled. */ if ( 'true' === apply_filters( 'mc_use_permalinks', mc_get_option( 'use_permalinks' ) ) ) { $post_id = $event->event_post; $post_link = ( $post_id ) ? get_edit_post_link( $post_id ) : false; $controls['post'] = ( $post_link ) ? sprintf( "" . __( 'Edit Event Post', 'my-calendar' ) . '', $post_link ) : ''; } } else { $publish_text = __( 'Publish', 'my-calendar' ); } if ( $has_data && is_object( $event ) ) { $first = mc_get_first_event( $event->event_id ); $view_url = mc_get_details_link( $first ); if ( mc_event_published( $event ) ) { $controls['view'] = "" . __( 'View', 'my-calendar' ) . ''; } elseif ( current_user_can( 'mc_manage_events' ) ) { $controls['view'] = "" . __( 'Preview', 'my-calendar' ) . ''; } $manage_text = __( 'Events', 'my-calendar' ); $controls['manage'] = "" . '' . $manage_text . ''; } if ( 'footer' === $position ) { if ( 'edit' === $mode ) { $controls['publish'] = ''; } else { if ( current_user_can( 'mc_approve_events' ) || current_user_can( 'mc_publish_events' ) ) { $controls['publish'] = ' '; } else { $controls['publish'] = ''; } } } // Event Status settings: draft, published, trash, (custom). $statuses = mc_event_statuses(); if ( 'header' === $position ) { $status_control = ''; if ( 'edit' === $mode ) { $controls['publish'] = ''; $controls['prev_status'] = ""; if ( current_user_can( 'mc_approve_events' ) || current_user_can( 'mc_publish_events' ) ) { // Added by Roland P. foreach ( $statuses as $code => $label ) { $status_control .= ''; } } else { unset( $statuses['1'] ); foreach ( $statuses as $code => $label ) { $status_control .= ''; } } } else { // Case: adding new event (if user can, then 1, else 0). $status_control = ''; if ( current_user_can( 'mc_approve_events' ) || current_user_can( 'mc_publish_events' ) ) { $controls['publish'] = ' '; } else { $controls['publish'] = ''; } } $controls['status'] = ( '' !== $status_control ) ? " " : ''; } /** * Filter array of controls shown on event editor. * * @hook mc_event_controls * * @param {array} $controls Array of HTML strings to output in header and footer of event editor. * @param {string} $mode Context of event editing page. * @param {object} $event Event data. * @param {string} $position location of form. * * @return {array} */ $controls = apply_filters( 'mc_filter_event_controls', $controls, $mode, $event, $position = 'header' ); $controls_output = ''; foreach ( $controls as $key => $control ) { if ( 'prev_status' !== $key ) { $control = ( '' !== $control ) ? '
  • ' . $control . '
  • ' : ''; } $controls_output .= $control; } return ''; } /** * Get the array of available event status codes. * * @return array */ function mc_event_statuses() { // Switch to select status. $statuses = array( '1' => __( 'Publish', 'my-calendar' ), '0' => __( 'Draft', 'my-calendar' ), '2' => __( 'Trash', 'my-calendar' ), ); /** * Filter available event status types. * * @hook mc_event_statuses * * @param {array} Array of statuses where key is the integer value of the status and the value is the status label. * * @return {array} */ $statuses = apply_filters( 'mc_event_statuses', $statuses ); return $statuses; } /** * Get a list of event in a group and list admin editing links * * @param int $id group ID. * @param string $template Template format. */ function mc_grouped_events( $id, $template = '' ) { $id = (int) $id; $output = ''; $results = mc_get_grouped_events( $id ); if ( ! empty( $results ) ) { foreach ( $results as $result ) { $first = mc_get_first_event( $result->event_id ); if ( ! is_object( $first ) ) { continue; } $event = $first->occur_event_id; $current = ''; $close = ''; $begin = date_i18n( mc_date_format(), strtotime( $first->occur_begin ) ) . ', ' . mc_date( mc_time_format(), strtotime( $first->occur_begin ), false ); $array = array( 'current' => $current, 'begin' => $begin, 'end' => $close, ); $current_output = ( '' === $template ) ? $current . $begin : mc_draw_template( $array, $template ); $output .= "
  • $current_output
  • "; } } else { $output = '
  • ' . __( 'No grouped events', 'my-calendar' ) . '
  • '; } echo wp_kses_post( $output ); } /** * Generate recurrence options list * * @param string $value current event's value. * @param string $return_type Return type: '; } } else { return $values; } return $options; } add_filter( 'mc_instance_data', 'mc_reuse_id', 10, 3 ); /** * If an instance ID is for the same starting date (date *only*), use same ID * * @param array $data data to be inserted into occurrences. * @param string $begin Starting time for the new occurrence. * @param array $instances Array of previous instances for this event. * * @return array new data to insert */ function mc_reuse_id( $data, $begin, $instances ) { $begin = sanitize_key( mc_date( 'Y-m-d', $begin, false ) ); $keys = array_keys( $instances ); if ( ! empty( $instances ) && in_array( $begin, $keys, true ) ) { $restore_id = $instances[ $begin ]; $data['occur_id'] = $restore_id; } return $data; } add_filter( 'mc_instance_format', 'mc_reuse_id_format', 10, 3 ); /** * If an instance ID is for the same starting date (date *only*), return format for altered insertion. * * @param array $format Original formats array. * @param string $begin Starting time for the new occurrence. * @param array $instances Array of previous instances for this event. * * @return array new formats for data */ function mc_reuse_id_format( $format, $begin, $instances ) { $begin = sanitize_key( mc_date( 'Y-m-d', $begin, false ) ); $keys = array_keys( $instances ); if ( ! empty( $instances ) && in_array( $begin, $keys, true ) ) { $format = array( '%d', '%s', '%s', '%d', '%d' ); } return $format; } /** * Given a recurrence pattern and a start date/time, increment the additional instances of an event. * * @param integer $id Event ID in my_calendar db. * @param array $post an array of POST data (or array containing dates). * @param boolean $test true if testing. * @param array $instances When rebuilding, an array of all prior event dates & ids. * * @return array */ function mc_increment_event( $id, $post = array(), $test = false, $instances = array() ) { $event = mc_get_event_core( $id, true ); if ( ! $event ) { return array(); } $data = array(); $return = array(); if ( empty( $post ) ) { $orig_begin = $event->event_begin . ' ' . $event->event_time; $orig_end = $event->event_end . ' ' . $event->event_endtime; } else { $post_begin = ( isset( $post['event_begin'] ) ) ? $post['event_begin'] : ''; $post_time = ( isset( $post['event_time'] ) ) ? $post['event_time'] : ''; $post_end = ( isset( $post['event_end'] ) ) ? $post['event_end'] : ''; $post_endtime = ( isset( $post['event_endtime'] ) ) ? $post['event_endtime'] : ''; $orig_begin = $post_begin . ' ' . $post_time; $orig_end = $post_end . ' ' . $post_endtime; } // Calculate time offset for date and time. $begin_diff = strtotime( gmdate( 'Y-m-d H:i:s', strtotime( $orig_begin ) ) ) - strtotime( gmdate( 'Y-m-d', strtotime( $orig_begin ) ) ); $end_diff = strtotime( gmdate( 'Y-m-d H:i:s', strtotime( $orig_end ) ) ) - strtotime( gmdate( 'Y-m-d', strtotime( $orig_end ) ) ); $group_id = $event->event_group_id; $recurs = str_split( $event->event_recur, 1 ); $recur = $recurs[0]; // Can't use 2nd value directly if it's two digits. $every = ( isset( $recurs[1] ) ) ? str_replace( $recurs[0], '', $event->event_recur ) : 1; if ( 'S' !== $recur ) { // If this event had a rep of 0, translate that. if ( is_numeric( $event->event_repeats ) ) { // Backwards compatibility. $event_repetition = ( 0 !== (int) $event->event_repeats ) ? $event->event_repeats : _mc_increment_values( $recur ); $post_until = false; } else { $post_until = $event->event_repeats; // Set event repetition to 1. Autoincrement up as needed. $event_repetition = ( my_calendar_date_xcomp( $orig_end, $post_until ) ) ? 1 : false; } // Toggle recurrence type to single if invalid repeat target passed. $recur = ( ! $event_repetition ) ? 'S' : $recur; $numforward = (int) $event_repetition; switch ( $recur ) { // Daily. case 'D': for ( $i = 0; $i <= $numforward; $i++ ) { $begin = my_calendar_add_date( $orig_begin, $i * $every, 0, 0 ); $end = my_calendar_add_date( $orig_end, $i * $every, 0, 0 ); $data = array( 'occur_event_id' => $id, 'occur_begin' => mc_date( 'Y-m-d H:i:s', $begin, false ), 'occur_end' => mc_date( 'Y-m-d H:i:s', $end, false ), 'occur_group_id' => $group_id, ); if ( true === $test && $i > 0 ) { return $data; } if ( $post_until ) { if ( $begin <= strtotime( $post_until ) ) { ++$numforward; } else { continue; } } $return[] = $data; mc_insert_recurring( $data, $id, $begin, $instances, $test, 'daily' ); } break; // Weekdays only. case 'E': // Every = $every = e.g. every 14 weekdays. // Num forward = $numforward = e.g. 7 times. for ( $i = 0; $i <= $numforward; $i++ ) { $begin = strtotime( $event->event_begin . ' ' . ( $every * $i ) . ' weekdays' ) + $begin_diff; $end = strtotime( $event->event_end . ' ' . ( $every * $i ) . ' weekdays' ) + $end_diff; $data = array( 'occur_event_id' => $id, 'occur_begin' => mc_date( 'Y-m-d H:i:s', $begin, false ), 'occur_end' => mc_date( 'Y-m-d H:i:s', $end, false ), 'occur_group_id' => $group_id, ); if ( true === $test && $i > 0 ) { return $data; } if ( $post_until ) { if ( $begin <= strtotime( $post_until ) ) { ++$numforward; } else { continue; } } $return[] = $data; mc_insert_recurring( $data, $id, $begin, $instances, $test, 'weekday' ); } break; // Weekly. case 'W': for ( $i = 0; $i <= $numforward; $i++ ) { $begin = my_calendar_add_date( $orig_begin, ( $i * 7 ) * $every, 0, 0 ); $end = my_calendar_add_date( $orig_end, ( $i * 7 ) * $every, 0, 0 ); $data = array( 'occur_event_id' => $id, 'occur_begin' => mc_date( 'Y-m-d H:i:s', $begin, false ), 'occur_end' => mc_date( 'Y-m-d H:i:s', $end, false ), 'occur_group_id' => $group_id, ); if ( true === $test && $i > 0 ) { return $data; } if ( $post_until ) { if ( $begin <= strtotime( $post_until ) ) { ++$numforward; } else { continue; } } $return[] = $data; mc_insert_recurring( $data, $id, $begin, $instances, $test, 'weekly' ); } break; // Biweekly. case 'B': for ( $i = 0; $i <= $numforward; $i++ ) { $begin = my_calendar_add_date( $orig_begin, ( $i * 14 ), 0, 0 ); $end = my_calendar_add_date( $orig_end, ( $i * 14 ), 0, 0 ); $data = array( 'occur_event_id' => $id, 'occur_begin' => mc_date( 'Y-m-d H:i:s', $begin, false ), 'occur_end' => mc_date( 'Y-m-d H:i:s', $end, false ), 'occur_group_id' => $group_id, ); if ( true === $test && $i > 0 ) { return $data; } if ( $post_until ) { if ( $begin <= strtotime( $post_until ) ) { ++$numforward; } else { continue; } } $return[] = $data; mc_insert_recurring( $data, $id, $begin, $instances, $test, 'biweekly' ); } break; // Monthly by date. case 'M': for ( $i = 0; $i <= $numforward; $i++ ) { $begin = my_calendar_add_date( $orig_begin, 0, $i * $every, 0 ); $end = my_calendar_add_date( $orig_end, 0, $i * $every, 0 ); $data = array( 'occur_event_id' => $id, 'occur_begin' => mc_date( 'Y-m-d H:i:s', $begin, false ), 'occur_end' => mc_date( 'Y-m-d H:i:s', $end, false ), 'occur_group_id' => $group_id, ); if ( true === $test && $i > 0 ) { return $data; } if ( $post_until ) { if ( $begin <= strtotime( $post_until ) ) { ++$numforward; } else { continue; } } $return[] = $data; mc_insert_recurring( $data, $id, $begin, $instances, $test, 'monthly' ); } break; // Monthly by day. case 'U': // The numeric week of the month this event occurs in. $week_of_event = mc_week_of_month( mc_date( 'd', strtotime( $event->event_begin ), false ) ); $newbegin = my_calendar_add_date( $orig_begin, 28, 0, 0 ); $newend = my_calendar_add_date( $orig_end, 28, 0, 0 ); $data = array( 'occur_event_id' => $id, 'occur_begin' => mc_date( 'Y-m-d H:i:s', strtotime( $orig_begin ), false ), 'occur_end' => mc_date( 'Y-m-d H:i:s', strtotime( $orig_end ), false ), 'occur_group_id' => $group_id, ); mc_insert_recurring( $data, $id, strtotime( $orig_begin ), $instances, $test, 'month-by-day' ); $numforward = ( $numforward - 1 ); for ( $i = 0; $i <= $numforward; $i++ ) { $skip = false; // If next week is a different month, and we're supposed move the event, return true. $move_event = mc_move_date( $newbegin, $event ); $week = mc_week_of_month( mc_date( 'd', $newbegin, false ) ); if ( $week === $week_of_event || $move_event ) { // If this is the correct week or is the last week of the month and dates are adjustable. } else { // If this is not the correct week generate a new date + 1 week. $oldbegin = $newbegin; $oldend = $newend; $newbegin = my_calendar_add_date( mc_date( 'Y-m-d H:i:s', $newbegin, false ), 7, 0, 0 ); $newend = my_calendar_add_date( mc_date( 'Y-m-d H:i:s', $newend, false ), 7, 0, 0 ); $week = mc_week_of_month( mc_date( 'd', $newbegin, false ) ); $move_event = mc_move_date( $newbegin, $event ); if ( $week === $week_of_event || true === $move_event ) { // If $newbegin is the correct week or is the last week of the month and dates are adjustable. } else { // Restore values because we're now in the wrong month. $newbegin = $oldbegin; $newend = $oldend; $skip = true; } } // Skip on events starting on 5th week but not moved to the 4th week in months without 5 weeks. if ( ! $skip ) { $data = array( 'occur_event_id' => $id, 'occur_begin' => mc_date( 'Y-m-d H:i:s', $newbegin, false ), 'occur_end' => mc_date( 'Y-m-d H:i:s', $newend, false ), 'occur_group_id' => $group_id, ); if ( true === $test && $i > 0 ) { return $data; } if ( $post_until ) { if ( $newbegin <= strtotime( $post_until ) ) { ++$numforward; } else { continue; } } $return[] = $data; mc_insert_recurring( $data, $id, $newbegin, $instances, $test, 'month-by-day' ); // Jump forward 4 weeks. } else { ++$numforward; } $newbegin = my_calendar_add_date( mc_date( 'Y-m-d H:i:s', $newbegin, false ), 28, 0, 0 ); $newend = my_calendar_add_date( mc_date( 'Y-m-d H:i:s', $newend, false ), 28, 0, 0 ); } break; // Annual. case 'Y': for ( $i = 0; $i <= $numforward; $i++ ) { $begin = my_calendar_add_date( $orig_begin, 0, 0, $i * $every ); $end = my_calendar_add_date( $orig_end, 0, 0, $i * $every ); $data = array( 'occur_event_id' => $id, 'occur_begin' => mc_date( 'Y-m-d H:i:s', $begin, false ), 'occur_end' => mc_date( 'Y-m-d H:i:s', $end, false ), 'occur_group_id' => $group_id, ); if ( true === $test && $i > 0 ) { return $data; } if ( $post_until ) { if ( $begin <= strtotime( $post_until ) ) { ++$numforward; } else { continue; } } $return[] = $data; mc_insert_recurring( $data, $id, $begin, $instances, $test, 'annual' ); } break; } } else { $begin = strtotime( $orig_begin ); $end = strtotime( $orig_end ); $data = array( 'occur_event_id' => $id, 'occur_begin' => mc_date( 'Y-m-d H:i:s', $begin, false ), 'occur_end' => mc_date( 'Y-m-d H:i:s', $end, false ), 'occur_group_id' => $group_id, ); mc_insert_recurring( $data, $id, $begin, $instances, $test, 'single' ); } if ( true === $test ) { return $return; } return $data; } /** * Check whether a last-week of the month recurring date needs to be moved. * Checks a given date & an object to see whether the event should only exist in the 5th week or is intended for the last week, regardless of number, then tests the date to see which week it is. * * @param int $newbegin A datestamp to check against. * @param object $event The My Calendar event object source to generate recurrences for. * * @return bool */ function mc_move_date( $newbegin, $event ) { $week_of_event = mc_week_of_month( mc_date( 'd', strtotime( $event->event_begin ), false ) ); $fifth_week = ( 1 === (int) $event->event_fifth_week ) ? true : false; if ( ! $fifth_week ) { return false; } // Is the date one week ahead of the current date in the next month. If so, this is the last week. $next_week_diff = ( mc_date( 'm', $newbegin, false ) === mc_date( 'm', my_calendar_add_date( mc_date( 'Y-m-d', $newbegin, false ), 7, 0, 0 ), false ) ) ? false : true; $week = mc_week_of_month( mc_date( 'd', $newbegin, false ) ); // If next week is not this month, and event should move, return true. This is the last week of the month. $move_event = ( ( ( $week + 1 ) === $week_of_event ) && ( true === $next_week_diff ) ) ? true : false; return $move_event; } /** * Insert a recurring event instance. * * @param array $data Instance data. * @param int $id Event ID. * @param string $begin Beginning date. * @param array $instances Array of existing dates used when rebuilding values. * @param bool|string $test Whether we're testing values or generating dates. * @param string $context Type of recurring event. */ function mc_insert_recurring( $data, $id, $begin, $instances, $test, $context ) { global $wpdb; $format = array( '%d', '%s', '%s', '%d' ); if ( ! $test ) { /** * Short circuit inserting a recurring event. Return true if event should not be inserted. * * @hook mc_insert_recurring * * @param {bool} $insert True to skip inserting. * @param {array} $data Event date info. * @param {int} $id Event ID. * @param {string} $context Type of recurring event. * * @return {bool} */ $insert = apply_filters( 'mc_insert_recurring', false, $data, $id, $context ); if ( ! $insert ) { /** * Filter recurring event instance data array. * * @hook mc_instance_data * * @param {array} $format Array of data passed to insert query. * @param {string} $begin Beginning date. * @param {array} $instances Original instances. * * @return {array} */ $data = apply_filters( 'mc_instance_data', $data, $begin, $instances ); /** * Filter recurring event instance database format array. * * @hook mc_instance_format * * @param {array} $format Array of placeholder formats in insert query. * @param {string} $begin Beginning date. * @param {array} $instances Original instances. * * @return {array} */ $format = apply_filters( 'mc_instance_format', $format, $begin, $instances ); $wpdb->insert( my_calendar_event_table(), $data, $format ); } } } /** * Execute a refresh of the My Calendar primary URL cache if caching plug-in installed. * * @param string $action Type of action performed. * @param array $data Data passed to filter. * @param int $event_id Event ID being affected. * @param int $result Result of calendar save query. */ function mc_refresh_cache( $action, $data, $event_id, $result ) { // Delete transient caches. delete_transient( 'mc_categories_' . $event_id ); delete_transient( 'mc_first_event_cache_' . $event_id ); delete_transient( 'mc_get_date_bounds' ); // Check page caches. $mc_uri_id = mc_get_option( 'uri_id' ); /** * Filter URLS that should be refreshed in caches. * * @hook mc_cached_pages_to_refresh * * @param {array} $to_refresh Array of post IDs to clear cache on. * @param {string} $action My Calendar action executing. * @param {array} $data Data passed from event. * @param {int} $event_id Event ID. * @param {int} $result Result of calendar database query. * * @return {array} */ $to_refresh = apply_filters( 'mc_cached_pages_to_refresh', array( $mc_uri_id ), $action, $data, $event_id, $result ); foreach ( $to_refresh as $calendar ) { if ( ! $calendar || ! get_post( $calendar ) ) { continue; } // W3 Total Cache. if ( function_exists( 'w3tc_pgcache_flush_post' ) ) { w3tc_pgcache_flush_post( $calendar ); } // WP Super Cache. if ( function_exists( 'wp_cache_post_change' ) ) { wp_cache_post_change( $calendar ); } // WP Rocket. if ( function_exists( 'rocket_clean_post' ) ) { rocket_clean_post( $calendar ); } // WP Fastest Cache. if ( isset( $GLOBALS['wp_fastest_cache'] ) && method_exists( $GLOBALS['wp_fastest_cache'], 'singleDeleteCache' ) ) { $GLOBALS['wp_fastest_cache']->singleDeleteCache( false, $calendar ); } // Comet Cache. if ( class_exists( 'comet_cache' ) ) { comet_cache::clearPost( $calendar ); } // Cache Enabler. if ( class_exists( 'Cache_Enabler' ) ) { Cache_Enabler::clear_page_cache_by_post_id( $calendar ); } if ( class_exists( 'WPO_Page_Cache' ) ) { WPO_Page_Cache::delete_single_post_cache( $calendar ); } } } add_action( 'mc_save_event', 'mc_refresh_cache', 10, 4 ); Calendar of Events – Radość-Joy
    en_USEnglish