Plugin Directory

Changeset 1237993


Ignore:
Timestamp:
09/04/2015 11:32:27 AM (11 years ago)
Author:
Moisture
Message:

Fix problems with tags

Location:
am-events/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • am-events/trunk/am-events.php

    r1237326 r1237993  
    44  Plugin URI: http://wordpress.org/extend/plugins/am-events/
    55  Description: Adds a post type for events and a customizable widget for displaying upcoming events.
    6   Version: 1.9.7
     6  Version: 1.9.8
    77  Author: Atte Moisio
    88  Author URI: http://attemoisio.fi
     
    3434/************************************************************************************
    3535 * 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 *
    3939 *      'am_event'
    40  * 
    41  * Meta: 
    42  * 
     40 *
     41 * Meta:
     42 *
    4343 *      'am_startdate'
    4444 *      'am_enddate'
    45  * 
    46  * Taxonomies: 
    47  *             
     45 *
     46 * Taxonomies:
     47 *
    4848 *      'am_venues'
    4949 *      'am_event_categories'
    50  * 
     50 *
    5151 * Widget template shortcodes:
    52  * 
     52 *
    5353 *     [event-title]    //The event title
    5454 *     [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)
     
    5656 *     [event-venue]    //The event venue
    5757 *     [event-category] //The event category
    58  *     [excerpt]          //The event excerpt
     58 *     [excerpt]        //The event excerpt
    5959 *     [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)
    6161 *     [if cond="startdate-is-enddate"]
    6262 *     [if cond="startdate-not-enddate"]
    6363 *     [if cond="startday-is-endday"]
    64  *     [if cond="startday-not-endday"] 
     64 *     [if cond="startday-not-endday"]
    6565 *
    6666 * Template tags:
     
    7272 *              am_the_enddate($format = 'Y-m-d H:i:s', $before = '', $after = '', $echo = true)
    7373 *              am_get_the_enddate( $format = 'Y-m-d H:i:s', $post = 0 )
    74  * 
     74 *
    7575 *     Venues:
    7676 *
     
    7979 *              am_get_the_venue_list( $separator = '', $parents='', $post_id = false )
    8080 *              am_the_venue( $separator = '', $parents='', $post_id = false )
    81  * 
     81 *
    8282 *     Event categories:
    8383 *
     
    9696//require_once dirname(__FILE__) . '/widget-event-calendar.php';
    9797require_once dirname(__FILE__) . '/template-tags.php';
    98  
     98
    9999/******************************************************************************
    100100 * =ACTION HOOKS
     
    119119 *
    120120 */
    121  
     121
    122122add_filter('post_row_actions','am_action_row', 10, 2);
    123123add_filter('parse_query', 'am_convert_id_to_term_in_query');
     
    160160
    161161/*
    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
    163163 * instead of publish date.
    164164 */
    165165function 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' )  ) {
    167167
    168168        $this_year = get_query_var('year', gmdate('Y', current_time('timestamp')));
    169169        $this_month = get_query_var('month', gmdate('m', current_time('timestamp')));
    170170        $this_day = get_query_var('day', gmdate('d', current_time('timestamp')));
    171        
     171
    172172        if (is_year()) { // Yearly archive page
    173173            $start = "$this_year-01-01 00:00:00";
    174174            $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) );
    176176            am_pre_modify_query($query);
    177177        } else if (is_month()) { // Monthly archive page
     
    183183            $start = "$this_year-$this_month-$this_day 00:00:00";
    184184            $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) );
    186186            am_pre_modify_query($query);
    187187        }
     
    237237        wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    238238    }
    239        
     239
    240240        ?>
    241241    <div class="wrap">
    242242        <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
    245245        <?php
    246246        settings_fields( 'am-events-settings-group' );
     
    254254        <table><tbody>
    255255            <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>
    257257                <td>
    258258                    <input id="am_rewrite_slug" valuechanged="" type="text" name="am_rewrite_slug" value="<?php echo get_option('am_rewrite_slug', 'am_event'); ?>" />
    259                    
     259
    260260                </td>
    261261
     
    263263            <tr></tr>
    264264            <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>
    266266                <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>
    267267            </tr>
     
    269269            </tr>
    270270        </tbody></table>
    271        
    272 
    273        
     271
     272
     273
    274274        <?php submit_button(); ?>
    275275        </form>
    276276        <span id="slug-instructions" style="display:none"></span>
    277        
    278        
     277
     278
    279279    </div>
    280280
     
    285285 * =SCRIPT =STYLE
    286286 * *************************************************************************** */
    287  
     287
    288288function am_custom_script_post() {
    289289    global $post;
    290290    if ($post->post_type === 'am_event' && is_admin()) {
    291        
     291
    292292        // include JQuery
    293293        wp_enqueue_script(
    294294                'jquery-custom', plugins_url('/script/jquery-ui-1.10.2.custom.min.js', __FILE__)
    295295        );
    296        
     296
    297297        // JQuery datetime picker from http://trentrichardson.com/examples/timepicker/
    298298        // datetimepicker localization
    299299        $localization = array(
    300        
     300
    301301            // Date picker
    302302            'clearText' => _x('Clear', 'date picker', 'am-events'), //Display text for clear link
     
    329329            'initStatus' => _x('Select a date', 'date picker', 'am-events'), //Initial Status text on opening
    330330            'isRTL' => false, //True if right-to-left language, false if left-to-right
    331            
     331
    332332            // Time picker
    333333            'minuteStep' => get_option('am_timepicker_minutestep', 15),
     
    349349            'isRTL' => false
    350350        );
    351        
     351
    352352        // Add Timepicker script
    353353        wp_register_script('jquery-ui-timepicker', plugins_url('/script/jquery-ui-timepicker-addon.js', __FILE__));
     
    367367    if( 'edit.php' != $hook )
    368368        return;
    369    
     369
    370370    $localization = array(
    371371        'confirmation' => __( 'Are you sure you want to move this and all other events in the series to the Trash?', 'am-events'),
    372372    );
    373    
     373
    374374    wp_register_script('am_edit_script', plugins_url('/script/admin-edit.js', __FILE__));
    375375    wp_localize_script('am_edit_script', 'localization', $localization); //pass any values to javascript
     
    414414    add_meta_box('submitdiv', __('Publish'), 'am_post_submit_meta_box', 'am_event', 'side', 'high', null);
    415415}
    416  
     416
    417417/**
    418418 * Custom meta box for events
     
    438438    if (function_exists('am_nonce'))
    439439        wp_nonce_field(plugin_basename(__FILE__), 'am_nonce');
    440    
     440
    441441    // The actual fields for data entry
    442442    // Use get_post_meta to retrieve an existing value from the database and use the value for the form
     
    452452    if ($metaEndDate !== '')
    453453        $endDate = date(_x('m/d/Y H:i','administration', 'am-events'), strtotime($metaEndDate));
    454    
     454
    455455    // Echo content of the meta box
    456456    ?>
     
    458458        <tr>
    459459            <td align="right">
    460                 <label for="am_startdate"> 
     460                <label for="am_startdate">
    461461                    <?php _e("Start Date:", 'am-events') ?>
    462462                </label>
     
    485485        <input type="radio" name="am_recurrence_type" value="am_weekly" checked /><span><?php _e('weekly', 'am-events') ?></span><br />
    486486        <input type="radio" name="am_recurrence_type" value="am_biweekly" /><span><?php _e('every two weeks', 'am-events') ?></span><br />
    487        
     487
    488488        <br />
    489489
     
    504504function am_save_custom_meta($post_id) {
    505505    global $post;
    506    
     506
    507507    if (isset($_GET['action']) && $_GET['action'] == 'trash')
    508508        return;
     
    511511    if ( isset($_POST['am_nonce']) && !wp_verify_nonce( $_POST['am_nonce'], plugin_basename(__FILE__) ) )
    512512        return;
    513    
     513
    514514    // And they're of the right level?
    515515    if (!current_user_can('edit_posts'))
    516516        return;
    517517    /*
    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,
    520520     * and if so then update our post meta options using update_post_meta().
    521521     */
     
    547547        else
    548548            return;
    549        
     549
    550550    }
    551551}
     
    743743    </div>
    744744    <?php endif;
    745    
     745
    746746    ?>
    747747    <div class="misc-pub-section misc-pub-recurrent" id="recurrence">
     
    784784    do_action( 'post_submitbox_start' );
    785785    ?>
    786    
     786
    787787    <div style="margin-bottom: 10px">
    788         <?php 
     788        <?php
    789789            if ($recurring_count > 0) {
    790790                echo '' . __( 'This is a recurring event. You can update just this one or all events in the series.' ) . '';
     
    792792        ?>
    793793    </div>
    794    
     794
    795795    <div id="delete-action">
    796796    <?php
     
    817817            <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" />
    818818            <?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) {
    822822                submit_button( __('Publish All', 'am-events'), 'primary button-large', 'publish', false, array( 'accesskey' => 'p', 'onclick' => "document.getElementById('submit_all').value='yes'") );
    823823            } ?>
     
    827827            <?php submit_button( __( 'Submit for Review' ), 'primary button-large', 'publish', false, array( 'accesskey' => 'p' ) ); ?>
    828828            <?php
    829             if ($recurring_count > 1) { 
     829            if ($recurring_count > 1) {
    830830                submit_button( __('Submit All for Review', 'am-events'), 'primary button-large', 'publish', false, array( 'accesskey' => 'p', 'onclick' => "document.getElementById('submit_all').value='yes'") );
    831831            } ?>
     
    865865
    866866    echo "$message";
    867    
     867
    868868    echo "</div>";
    869869}
     
    873873 */
    874874function am_show_admin_messages() {
    875    
     875
    876876    if(isset($_COOKIE['wp-admin-messages-normal'])) {
    877877
    878878        //setcookie('wp-admin-messages-normal', null);
    879        
     879
    880880        $messages = strtok($_COOKIE['wp-admin-messages-normal'], "@@");
    881881
     
    885885        }
    886886
    887        
     887
    888888    }
    889889
     
    925925function am_action_row($actions, $post){
    926926    //check for your post type
    927    
     927
    928928    if ($post->post_type === 'am_event'){
    929         if ($post->post_status !== 'trash') { 
     929        if ($post->post_status !== 'trash') {
    930930            $post_type = 'am_event';
    931931            $recurrence_id = get_post_meta($post->ID, 'am_recurrence_id', true);
    932932            if (isset($recurrence_id) && $recurrence_id) {
    933933                $class = 'submitdelete recurrent recurrent-' . $recurrence_id;;
    934                
     934
    935935                $title = esc_attr( __( 'Move this and all recurring items to trash', 'am-events' ) );
    936936                $span_id = "trash-recurring-event" . $post->ID;
     
    986986 */
    987987function am_wp_trash_event_recurring($post_id) {
    988    
    989     if (!isset($_GET['recurrent'])) 
     988
     989    if (!isset($_GET['recurrent']))
    990990        return;
    991    
     991
    992992    $recurrent = $_GET['recurrent'];
    993993    if ($recurrent === 'yes') {
     
    997997            $recurrence_id = get_post_meta($post_id, 'am_recurrence_id', true);
    998998            if (isset($recurrence_id) && $recurrence_id !== '') {
    999            
     999
    10001000                // clear recurrence id to avoid infinite loop
    10011001                //update_post_meta($post_id, 'am_recurrence_id', '');
     
    10031003                    'post_type' => 'am_event',
    10041004                    'post_status' => 'any',
    1005                     'post_count' => 9999,
    1006                     'posts_per_page' => 9999,
     1005                    'post_count' => -1,
     1006                    'posts_per_page' => -1,
    10071007                    'meta_query' => array(
    10081008                        array(
     
    10141014                    'post__not_in' => array($post_id), //exclude current event
    10151015                );
    1016                
     1016
    10171017                $the_query = new WP_Query( $args );
    10181018                $post_count = $the_query->post_count;
     
    10311031                $link = '';
    10321032                am_add_admin_message( '<p>' . sprintf( __('%d recurrent posts moved to the Trash.', 'am-events'), $post_count) . ' ' . $link . '<p>' );
    1033                
     1033
    10341034            }
    10351035        }
     
    10761076        // Remove save_post action to avoid infinite loop when calling wp_insert_posts
    10771077        remove_action('save_post', 'am_save_event');
    1078        
     1078
    10791079        if (!isset($_POST['post_ID']))
    10801080            return;
    1081            
     1081
    10821082        $post_id = $_POST['post_ID'];
    10831083        $orig_post = get_post($post_id);
    1084        
     1084
    10851085        if ($_POST && get_post_type($orig_post) === 'am_event') {
    10861086
     
    10891089            {
    10901090                $recurrent = $_POST['am_recurrent'];
    1091            
     1091
    10921092                if ($recurrent === 'yes') { // If so, create the events
    10931093                    $recurrent_amount = $_POST['am_recurrent_amount'];
     
    11251125                        $new_post_id = wp_insert_post($new_post);
    11261126
    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);
    11281128                        set_post_thumbnail($new_post_id, get_post_thumbnail_id($post_id));
    11291129
     
    11451145                        update_post_meta($new_post_id, 'am_recurrence_id', $recurrence_id);
    11461146
    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
    11551150                    }
    11561151
     
    11601155                }
    11611156            }
    1162        
     1157
    11631158            // Determine if the specified post is not a revision or auto-save
    11641159            if (!( wp_is_post_revision($post_id) && wp_is_post_autosave($post_id) )) {
     
    11681163                    // Update all recurring events
    11691164                    $recurrence_id = get_post_meta($post_id, 'am_recurrence_id', true);
    1170                    
     1165
    11711166                    $args = array(
    11721167                        'post_type' => 'am_event',
    11731168                        'post_status' => 'any',
    1174                         'post_count' => 99999,
    1175                         'posts_per_page' => 99999,
     1169                        'post_count' => -1,
     1170                        'posts_per_page' => -1,
    11761171                        'meta_query' => array(
    11771172                            array(
     
    11831178                        'post__not_in' => array($post_id), //exclude current event
    11841179                    );
    1185                    
     1180
    11861181                    $the_query = new WP_Query( $args );
    11871182                    $post_count = $the_query->post_count;
    1188                    
     1183
    11891184                    while ($the_query->have_posts()) {
    11901185                        $the_query->the_post();
    11911186                        $id = get_the_ID();
    1192                        
     1187
    11931188                        $recurrent_post = array(
    11941189                            'ID' => $id,
     
    12051200                        wp_update_post( $recurrent_post );
    12061201                        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);
    12091204                        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
    12251209                    }
    1226                    
     1210
    12271211                    // Notify user when recurrent events have been created.
    12281212                    am_add_admin_message( '<p>' . sprintf(__('%d recurring events updated.', 'am-events') . '</p>', $post_count) );
    1229                    
     1213
    12301214                }
    1231                
     1215
    12321216            }
    12331217        }
    12341218    }
    12351219
    1236    
     1220
     1221}
     1222
     1223/**
     1224 * Copies and replaces terms from one post to another.
     1225 */
     1226function 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 */
     1237function am_copy_replace_tags($from, $to) {
     1238    wp_set_post_tags($to, wp_get_post_tags($from, array('fields' => 'ids')), false);
    12371239}
    12381240
     
    13011303
    13021304/**
    1303  *  Used to sort the events in the administration. 
     1305 *  Used to sort the events in the administration.
    13041306 */
    13051307function am_sort_events($vars) {
     
    13771379
    13781380    register_post_type('am_event', $args);
    1379    
    1380     register_taxonomy('post_tag', array('am_event'));
     1381
    13811382}
    13821383
     
    14961497    // First, we "add" the custom post type via the above written function.
    14971498    // 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,
    14991500    // when you add a post of this CPT.
    15001501    am_cpt_init();
     
    15081509
    15091510/* * ****************************************************************************
    1510  * =TAXONOMY FILTER 
     1511 * =TAXONOMY FILTER
    15111512 * *************************************************************************** */
    15121513
     
    15731574
    15741575    ?>
    1575    
     1576
    15761577    <fieldset class="inline-edit-col-left inline-edit-event">
    15771578      <div class="inline-edit-col column-<?php echo $column_name ?>">
    15781579        <label class="inline-edit-group">
    1579         <?php 
     1580        <?php
    15801581         switch ( $column_name ) {
    1581          
     1582
    15821583         case 'am_startdate':
    15831584             ?><span class="title"><?php _e("Start Date", 'am-events') ?></span><span class="input-text-wrap"><input name="am_startdate" type="text" /></span><?php
     
    15911592      </div>
    15921593    </fieldset>
    1593    
     1594
    15941595    <?php
    1595    
     1596
    15961597}
    15971598
     
    16021603    $recurrence_id = get_post_meta($post_id, 'am_recurrence_id', true);
    16031604    if (isset($recurrence_id) && $recurrence_id !== '') {
    1604    
     1605
    16051606        $args = array(
    16061607            'post_type' => 'am_event',
     
    16161617            ),
    16171618        );
    1618        
     1619
    16191620        $the_query = new WP_Query( $args );
    16201621        return $the_query->post_count;
    1621        
     1622
    16221623    } else {
    16231624        return 0;
  • am-events/trunk/readme.txt

    r1237326 r1237993  
    44Requires at least: 3.3.1
    55Tested up to: 4.3
    6 Stable tag: 1.9.7
     6Stable tag: 1.9.8
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5555
    5656== Changelog ==
     57
     58= 1.9.8 =
     59* Fixed problem with tags
    5760
    5861= 1.9.7 =
     
    135138== Upgrade Notice ==
    136139
     140= 1.9.8 =
     141* Fixes problems with tags
     142
    137143= 1.9.7 =
    138 * Fixes admin panel event list ordering.
     144* Fixes admin panel event list ordering
    139145
    140146= 1.9.6 =
Note: See TracChangeset for help on using the changeset viewer.