Changeset 1237993
- Timestamp:
- 09/04/2015 11:32:27 AM (11 years ago)
- Location:
- am-events/trunk
- Files:
-
- 2 edited
-
am-events.php (modified) (55 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
am-events/trunk/am-events.php
r1237326 r1237993 4 4 Plugin URI: http://wordpress.org/extend/plugins/am-events/ 5 5 Description: Adds a post type for events and a customizable widget for displaying upcoming events. 6 Version: 1.9. 76 Version: 1.9.8 7 7 Author: Atte Moisio 8 8 Author URI: http://attemoisio.fi … … 34 34 /************************************************************************************ 35 35 * VARIABLE NAMES, TAXONOMY NAMES, WIDGET SHORTCODES AND TEMPLATE TAGS FOR REFERENCE 36 * 37 * Custom post type name: 38 * 36 * 37 * Custom post type name: 38 * 39 39 * 'am_event' 40 * 41 * Meta: 42 * 40 * 41 * Meta: 42 * 43 43 * 'am_startdate' 44 44 * 'am_enddate' 45 * 46 * Taxonomies: 47 * 45 * 46 * Taxonomies: 47 * 48 48 * 'am_venues' 49 49 * 'am_event_categories' 50 * 50 * 51 51 * Widget template shortcodes: 52 * 52 * 53 53 * [event-title] //The event title 54 54 * [start-date] //The start date of the event (uses the date format from the feed options, if it is set. Otherwise uses the default WordPress date format) … … 56 56 * [event-venue] //The event venue 57 57 * [event-category] //The event category 58 * [excerpt] //The event excerpt58 * [excerpt] //The event excerpt 59 59 * [thumbnail] //The event featured image 60 * [content] //The event content (number of words can be limited by the 'limit' attribute) 60 * [content] //The event content (number of words can be limited by the 'limit' attribute) 61 61 * [if cond="startdate-is-enddate"] 62 62 * [if cond="startdate-not-enddate"] 63 63 * [if cond="startday-is-endday"] 64 * [if cond="startday-not-endday"] 64 * [if cond="startday-not-endday"] 65 65 * 66 66 * Template tags: … … 72 72 * am_the_enddate($format = 'Y-m-d H:i:s', $before = '', $after = '', $echo = true) 73 73 * am_get_the_enddate( $format = 'Y-m-d H:i:s', $post = 0 ) 74 * 74 * 75 75 * Venues: 76 76 * … … 79 79 * am_get_the_venue_list( $separator = '', $parents='', $post_id = false ) 80 80 * am_the_venue( $separator = '', $parents='', $post_id = false ) 81 * 81 * 82 82 * Event categories: 83 83 * … … 96 96 //require_once dirname(__FILE__) . '/widget-event-calendar.php'; 97 97 require_once dirname(__FILE__) . '/template-tags.php'; 98 98 99 99 /****************************************************************************** 100 100 * =ACTION HOOKS … … 119 119 * 120 120 */ 121 121 122 122 add_filter('post_row_actions','am_action_row', 10, 2); 123 123 add_filter('parse_query', 'am_convert_id_to_term_in_query'); … … 160 160 161 161 /* 162 * Modifies event archive page to show events based on start and end dates 162 * Modifies event archive page to show events based on start and end dates 163 163 * instead of publish date. 164 164 */ 165 165 function am_alter_event_archive_query( $query ){ 166 if( $query->is_main_query() && $query->is_post_type_archive( 'am_event' ) ) { 166 if( $query->is_main_query() && $query->is_post_type_archive( 'am_event' ) ) { 167 167 168 168 $this_year = get_query_var('year', gmdate('Y', current_time('timestamp'))); 169 169 $this_month = get_query_var('month', gmdate('m', current_time('timestamp'))); 170 170 $this_day = get_query_var('day', gmdate('d', current_time('timestamp'))); 171 171 172 172 if (is_year()) { // Yearly archive page 173 173 $start = "$this_year-01-01 00:00:00"; 174 174 $end = "$this_year-12-31 23:59:59"; 175 $query->set( 'meta_query', am_get_archive_meta_query($start, $end) ); 175 $query->set( 'meta_query', am_get_archive_meta_query($start, $end) ); 176 176 am_pre_modify_query($query); 177 177 } else if (is_month()) { // Monthly archive page … … 183 183 $start = "$this_year-$this_month-$this_day 00:00:00"; 184 184 $end = "$this_year-$this_month-$this_day 23:59:59"; 185 $query->set( 'meta_query', am_get_archive_meta_query($start, $end) ); 185 $query->set( 'meta_query', am_get_archive_meta_query($start, $end) ); 186 186 am_pre_modify_query($query); 187 187 } … … 237 237 wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); 238 238 } 239 239 240 240 ?> 241 241 <div class="wrap"> 242 242 <h2><?php _e( 'AM Events settings', 'am_events' ) ?></h2> 243 <form method="post" action="options.php"> 244 243 <form method="post" action="options.php"> 244 245 245 <?php 246 246 settings_fields( 'am-events-settings-group' ); … … 254 254 <table><tbody> 255 255 <tr> 256 <td><label for="am_rewrite_slug"><?php _e( 'Slug for event posts', 'am_events' ) ?></label> </td> 256 <td><label for="am_rewrite_slug"><?php _e( 'Slug for event posts', 'am_events' ) ?></label> </td> 257 257 <td> 258 258 <input id="am_rewrite_slug" valuechanged="" type="text" name="am_rewrite_slug" value="<?php echo get_option('am_rewrite_slug', 'am_event'); ?>" /> 259 259 260 260 </td> 261 261 … … 263 263 <tr></tr> 264 264 <tr> 265 <td><label for="am_timepicker_minutestep"><?php _e( 'Timepicker minute step', 'am-events' ) ?></label> </td> 265 <td><label for="am_timepicker_minutestep"><?php _e( 'Timepicker minute step', 'am-events' ) ?></label> </td> 266 266 <td><input id="am_timepicker_minutestep" valuechanged="" type="number" min="1" max="59" name="am_timepicker_minutestep" value="<?php echo get_option('am_timepicker_minutestep', 15); ?>" /></td> 267 267 </tr> … … 269 269 </tr> 270 270 </tbody></table> 271 272 273 271 272 273 274 274 <?php submit_button(); ?> 275 275 </form> 276 276 <span id="slug-instructions" style="display:none"></span> 277 278 277 278 279 279 </div> 280 280 … … 285 285 * =SCRIPT =STYLE 286 286 * *************************************************************************** */ 287 287 288 288 function am_custom_script_post() { 289 289 global $post; 290 290 if ($post->post_type === 'am_event' && is_admin()) { 291 291 292 292 // include JQuery 293 293 wp_enqueue_script( 294 294 'jquery-custom', plugins_url('/script/jquery-ui-1.10.2.custom.min.js', __FILE__) 295 295 ); 296 296 297 297 // JQuery datetime picker from http://trentrichardson.com/examples/timepicker/ 298 298 // datetimepicker localization 299 299 $localization = array( 300 300 301 301 // Date picker 302 302 'clearText' => _x('Clear', 'date picker', 'am-events'), //Display text for clear link … … 329 329 'initStatus' => _x('Select a date', 'date picker', 'am-events'), //Initial Status text on opening 330 330 'isRTL' => false, //True if right-to-left language, false if left-to-right 331 331 332 332 // Time picker 333 333 'minuteStep' => get_option('am_timepicker_minutestep', 15), … … 349 349 'isRTL' => false 350 350 ); 351 351 352 352 // Add Timepicker script 353 353 wp_register_script('jquery-ui-timepicker', plugins_url('/script/jquery-ui-timepicker-addon.js', __FILE__)); … … 367 367 if( 'edit.php' != $hook ) 368 368 return; 369 369 370 370 $localization = array( 371 371 'confirmation' => __( 'Are you sure you want to move this and all other events in the series to the Trash?', 'am-events'), 372 372 ); 373 373 374 374 wp_register_script('am_edit_script', plugins_url('/script/admin-edit.js', __FILE__)); 375 375 wp_localize_script('am_edit_script', 'localization', $localization); //pass any values to javascript … … 414 414 add_meta_box('submitdiv', __('Publish'), 'am_post_submit_meta_box', 'am_event', 'side', 'high', null); 415 415 } 416 416 417 417 /** 418 418 * Custom meta box for events … … 438 438 if (function_exists('am_nonce')) 439 439 wp_nonce_field(plugin_basename(__FILE__), 'am_nonce'); 440 440 441 441 // The actual fields for data entry 442 442 // Use get_post_meta to retrieve an existing value from the database and use the value for the form … … 452 452 if ($metaEndDate !== '') 453 453 $endDate = date(_x('m/d/Y H:i','administration', 'am-events'), strtotime($metaEndDate)); 454 454 455 455 // Echo content of the meta box 456 456 ?> … … 458 458 <tr> 459 459 <td align="right"> 460 <label for="am_startdate"> 460 <label for="am_startdate"> 461 461 <?php _e("Start Date:", 'am-events') ?> 462 462 </label> … … 485 485 <input type="radio" name="am_recurrence_type" value="am_weekly" checked /><span><?php _e('weekly', 'am-events') ?></span><br /> 486 486 <input type="radio" name="am_recurrence_type" value="am_biweekly" /><span><?php _e('every two weeks', 'am-events') ?></span><br /> 487 487 488 488 <br /> 489 489 … … 504 504 function am_save_custom_meta($post_id) { 505 505 global $post; 506 506 507 507 if (isset($_GET['action']) && $_GET['action'] == 'trash') 508 508 return; … … 511 511 if ( isset($_POST['am_nonce']) && !wp_verify_nonce( $_POST['am_nonce'], plugin_basename(__FILE__) ) ) 512 512 return; 513 513 514 514 // And they're of the right level? 515 515 if (!current_user_can('edit_posts')) 516 516 return; 517 517 /* 518 * check if the $_POST variable is set, 519 * meaning that the form been submitted, 518 * check if the $_POST variable is set, 519 * meaning that the form been submitted, 520 520 * and if so then update our post meta options using update_post_meta(). 521 521 */ … … 547 547 else 548 548 return; 549 549 550 550 } 551 551 } … … 743 743 </div> 744 744 <?php endif; 745 745 746 746 ?> 747 747 <div class="misc-pub-section misc-pub-recurrent" id="recurrence"> … … 784 784 do_action( 'post_submitbox_start' ); 785 785 ?> 786 786 787 787 <div style="margin-bottom: 10px"> 788 <?php 788 <?php 789 789 if ($recurring_count > 0) { 790 790 echo '' . __( 'This is a recurring event. You can update just this one or all events in the series.' ) . ''; … … 792 792 ?> 793 793 </div> 794 794 795 795 <div id="delete-action"> 796 796 <?php … … 817 817 <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" /> 818 818 <?php submit_button( __( 'Publish' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?> 819 820 <?php 821 if ($recurring_count > 1) { 819 820 <?php 821 if ($recurring_count > 1) { 822 822 submit_button( __('Publish All', 'am-events'), 'primary button-large', 'publish', false, array( 'accesskey' => 'p', 'onclick' => "document.getElementById('submit_all').value='yes'") ); 823 823 } ?> … … 827 827 <?php submit_button( __( 'Submit for Review' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?> 828 828 <?php 829 if ($recurring_count > 1) { 829 if ($recurring_count > 1) { 830 830 submit_button( __('Submit All for Review', 'am-events'), 'primary button-large', 'publish', false, array( 'accesskey' => 'p', 'onclick' => "document.getElementById('submit_all').value='yes'") ); 831 831 } ?> … … 865 865 866 866 echo "$message"; 867 867 868 868 echo "</div>"; 869 869 } … … 873 873 */ 874 874 function am_show_admin_messages() { 875 875 876 876 if(isset($_COOKIE['wp-admin-messages-normal'])) { 877 877 878 878 //setcookie('wp-admin-messages-normal', null); 879 879 880 880 $messages = strtok($_COOKIE['wp-admin-messages-normal'], "@@"); 881 881 … … 885 885 } 886 886 887 887 888 888 } 889 889 … … 925 925 function am_action_row($actions, $post){ 926 926 //check for your post type 927 927 928 928 if ($post->post_type === 'am_event'){ 929 if ($post->post_status !== 'trash') { 929 if ($post->post_status !== 'trash') { 930 930 $post_type = 'am_event'; 931 931 $recurrence_id = get_post_meta($post->ID, 'am_recurrence_id', true); 932 932 if (isset($recurrence_id) && $recurrence_id) { 933 933 $class = 'submitdelete recurrent recurrent-' . $recurrence_id;; 934 934 935 935 $title = esc_attr( __( 'Move this and all recurring items to trash', 'am-events' ) ); 936 936 $span_id = "trash-recurring-event" . $post->ID; … … 986 986 */ 987 987 function am_wp_trash_event_recurring($post_id) { 988 989 if (!isset($_GET['recurrent'])) 988 989 if (!isset($_GET['recurrent'])) 990 990 return; 991 991 992 992 $recurrent = $_GET['recurrent']; 993 993 if ($recurrent === 'yes') { … … 997 997 $recurrence_id = get_post_meta($post_id, 'am_recurrence_id', true); 998 998 if (isset($recurrence_id) && $recurrence_id !== '') { 999 999 1000 1000 // clear recurrence id to avoid infinite loop 1001 1001 //update_post_meta($post_id, 'am_recurrence_id', ''); … … 1003 1003 'post_type' => 'am_event', 1004 1004 'post_status' => 'any', 1005 'post_count' => 9999,1006 'posts_per_page' => 9999,1005 'post_count' => -1, 1006 'posts_per_page' => -1, 1007 1007 'meta_query' => array( 1008 1008 array( … … 1014 1014 'post__not_in' => array($post_id), //exclude current event 1015 1015 ); 1016 1016 1017 1017 $the_query = new WP_Query( $args ); 1018 1018 $post_count = $the_query->post_count; … … 1031 1031 $link = ''; 1032 1032 am_add_admin_message( '<p>' . sprintf( __('%d recurrent posts moved to the Trash.', 'am-events'), $post_count) . ' ' . $link . '<p>' ); 1033 1033 1034 1034 } 1035 1035 } … … 1076 1076 // Remove save_post action to avoid infinite loop when calling wp_insert_posts 1077 1077 remove_action('save_post', 'am_save_event'); 1078 1078 1079 1079 if (!isset($_POST['post_ID'])) 1080 1080 return; 1081 1081 1082 1082 $post_id = $_POST['post_ID']; 1083 1083 $orig_post = get_post($post_id); 1084 1084 1085 1085 if ($_POST && get_post_type($orig_post) === 'am_event') { 1086 1086 … … 1089 1089 { 1090 1090 $recurrent = $_POST['am_recurrent']; 1091 1091 1092 1092 if ($recurrent === 'yes') { // If so, create the events 1093 1093 $recurrent_amount = $_POST['am_recurrent_amount']; … … 1125 1125 $new_post_id = wp_insert_post($new_post); 1126 1126 1127 wp_set_post_tags($new_post_id, wp_get_post_tags($post_id, array('fields' => 'ids')), false);1127 am_copy_replace_tags($post_id, $new_post_id); 1128 1128 set_post_thumbnail($new_post_id, get_post_thumbnail_id($post_id)); 1129 1129 … … 1145 1145 update_post_meta($new_post_id, 'am_recurrence_id', $recurrence_id); 1146 1146 1147 $eventCategories = wp_get_post_terms($post_id, 'am_event_categories'); 1148 $venues = wp_get_post_terms($post_id, 'am_venues'); 1149 foreach ($eventCategories as $c) { 1150 wp_set_post_terms($new_post_id, $c->term_id, 'am_event_categories', true); 1151 } 1152 foreach ($venues as $v) { 1153 wp_set_post_terms($new_post_id, $v->term_id, 'am_venues', true); 1154 } 1147 am_copy_replace_terms($post_id, $new_post_id, 'am_event_categories'); 1148 am_copy_replace_terms($post_id, $new_post_id, 'am_venues'); 1149 1155 1150 } 1156 1151 … … 1160 1155 } 1161 1156 } 1162 1157 1163 1158 // Determine if the specified post is not a revision or auto-save 1164 1159 if (!( wp_is_post_revision($post_id) && wp_is_post_autosave($post_id) )) { … … 1168 1163 // Update all recurring events 1169 1164 $recurrence_id = get_post_meta($post_id, 'am_recurrence_id', true); 1170 1165 1171 1166 $args = array( 1172 1167 'post_type' => 'am_event', 1173 1168 'post_status' => 'any', 1174 'post_count' => 99999,1175 'posts_per_page' => 99999,1169 'post_count' => -1, 1170 'posts_per_page' => -1, 1176 1171 'meta_query' => array( 1177 1172 array( … … 1183 1178 'post__not_in' => array($post_id), //exclude current event 1184 1179 ); 1185 1180 1186 1181 $the_query = new WP_Query( $args ); 1187 1182 $post_count = $the_query->post_count; 1188 1183 1189 1184 while ($the_query->have_posts()) { 1190 1185 $the_query->the_post(); 1191 1186 $id = get_the_ID(); 1192 1187 1193 1188 $recurrent_post = array( 1194 1189 'ID' => $id, … … 1205 1200 wp_update_post( $recurrent_post ); 1206 1201 add_action('save_post', 'am_save_custom_meta'); 1207 1208 wp_set_post_tags($id, wp_get_post_tags($post_id, array('fields' => 'ids')), false);1202 1203 am_copy_replace_tags($post_id, $id); 1209 1204 set_post_thumbnail($id, get_post_thumbnail_id($post_id)); 1210 1211 // Clear all event categories and venues 1212 wp_delete_object_term_relationships( $id, 'am_event_categories' ); 1213 wp_delete_object_term_relationships( $id, 'am_venues' ); 1214 1215 // Update event categories and venues to match current post 1216 $event_categories = wp_get_post_terms($post_id, 'am_event_categories'); 1217 $venues = wp_get_post_terms($post_id, 'am_venues'); 1218 foreach ($event_categories as $c) { 1219 wp_set_post_terms($id, $c->term_id, 'am_event_categories', true); 1220 } 1221 foreach ($venues as $v) { 1222 wp_set_post_terms($id, $v->term_id, 'am_venues', true); 1223 } 1224 1205 1206 am_copy_replace_terms($post_id, $id, 'am_event_categories'); 1207 am_copy_replace_terms($post_id, $id, 'am_venues'); 1208 1225 1209 } 1226 1210 1227 1211 // Notify user when recurrent events have been created. 1228 1212 am_add_admin_message( '<p>' . sprintf(__('%d recurring events updated.', 'am-events') . '</p>', $post_count) ); 1229 1213 1230 1214 } 1231 1215 1232 1216 } 1233 1217 } 1234 1218 } 1235 1219 1236 1220 1221 } 1222 1223 /** 1224 * Copies and replaces terms from one post to another. 1225 */ 1226 function am_copy_replace_terms($from, $to, $taxonomy) { 1227 wp_delete_object_term_relationships( $to, $taxonomy ); 1228 $terms = wp_get_post_terms($from, $taxonomy); 1229 foreach ($terms as $term) { 1230 wp_set_post_terms($to, $term->term_id, $taxonomy, true); 1231 } 1232 } 1233 1234 /** 1235 * Copies and replaces all tags from one post to another. 1236 */ 1237 function am_copy_replace_tags($from, $to) { 1238 wp_set_post_tags($to, wp_get_post_tags($from, array('fields' => 'ids')), false); 1237 1239 } 1238 1240 … … 1301 1303 1302 1304 /** 1303 * Used to sort the events in the administration. 1305 * Used to sort the events in the administration. 1304 1306 */ 1305 1307 function am_sort_events($vars) { … … 1377 1379 1378 1380 register_post_type('am_event', $args); 1379 1380 register_taxonomy('post_tag', array('am_event')); 1381 1381 1382 } 1382 1383 … … 1496 1497 // First, we "add" the custom post type via the above written function. 1497 1498 // Note: "add" is written with quotes, as CPTs don't get added to the DB, 1498 // They are only referenced in the post_type column with a post entry, 1499 // They are only referenced in the post_type column with a post entry, 1499 1500 // when you add a post of this CPT. 1500 1501 am_cpt_init(); … … 1508 1509 1509 1510 /* * **************************************************************************** 1510 * =TAXONOMY FILTER 1511 * =TAXONOMY FILTER 1511 1512 * *************************************************************************** */ 1512 1513 … … 1573 1574 1574 1575 ?> 1575 1576 1576 1577 <fieldset class="inline-edit-col-left inline-edit-event"> 1577 1578 <div class="inline-edit-col column-<?php echo $column_name ?>"> 1578 1579 <label class="inline-edit-group"> 1579 <?php 1580 <?php 1580 1581 switch ( $column_name ) { 1581 1582 1582 1583 case 'am_startdate': 1583 1584 ?><span class="title"><?php _e("Start Date", 'am-events') ?></span><span class="input-text-wrap"><input name="am_startdate" type="text" /></span><?php … … 1591 1592 </div> 1592 1593 </fieldset> 1593 1594 1594 1595 <?php 1595 1596 1596 1597 } 1597 1598 … … 1602 1603 $recurrence_id = get_post_meta($post_id, 'am_recurrence_id', true); 1603 1604 if (isset($recurrence_id) && $recurrence_id !== '') { 1604 1605 1605 1606 $args = array( 1606 1607 'post_type' => 'am_event', … … 1616 1617 ), 1617 1618 ); 1618 1619 1619 1620 $the_query = new WP_Query( $args ); 1620 1621 return $the_query->post_count; 1621 1622 1622 1623 } else { 1623 1624 return 0; -
am-events/trunk/readme.txt
r1237326 r1237993 4 4 Requires at least: 3.3.1 5 5 Tested up to: 4.3 6 Stable tag: 1.9. 76 Stable tag: 1.9.8 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 55 55 56 56 == Changelog == 57 58 = 1.9.8 = 59 * Fixed problem with tags 57 60 58 61 = 1.9.7 = … … 135 138 == Upgrade Notice == 136 139 140 = 1.9.8 = 141 * Fixes problems with tags 142 137 143 = 1.9.7 = 138 * Fixes admin panel event list ordering .144 * Fixes admin panel event list ordering 139 145 140 146 = 1.9.6 =
Note: See TracChangeset
for help on using the changeset viewer.