Making WordPress.org

Changeset 120


Ignore:
Timestamp:
11/16/2013 06:24:02 PM (12 years ago)
Author:
kovshenin
Message:

WordCamp.org: better groups and groupings handling in the MailChimp addon for CampTix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-mailchimp/addons/camptix-mailchimp.php

    r102 r120  
    182182
    183183                foreach ( $tickets as $ticket ) {
    184                     $group_name = apply_filters( 'the_title', $ticket->post_title );
     184                    $group_name = $ticket->post_title;
    185185
    186186                    // Look into the current MailChimp groupings and skip adding existing groups.
     
    229229                    $grouping_id = absint( $existing_groups['questions'][ $question->ID ] );
    230230
    231                 $grouping_name = sprintf( 'CampTix: %s', apply_filters( 'the_title', $question->post_title ) );
     231                $grouping_name = $this->trim_group( sprintf( 'CampTix: %s', $question->post_title ) );
    232232
    233233                // Attempt to find the grouping from MailChimp by name.
    234234                if ( ! $grouping_id ) {
    235235                    foreach ( $current_groupings as $grouping ) {
    236                         if ( $grouping_name == $grouping->name ) {
     236                        if ( $grouping_name == $this->trim_group( $grouping->name ) ) {
    237237                            $grouping_id = $grouping->id;
    238238                            break;
     
    245245                    $result = $this->api( 'lists/interest-grouping-add', array(
    246246                        'id' => $this->options['mailchimp_list'],
    247                         'name' => sprintf( 'CampTix: %s', apply_filters( 'the_title', $question->post_title ) ),
     247                        'name' => $grouping_name,
    248248                        'type' => 'hidden',
    249249                        'groups' => array( 'None' ), // @todo: add groups here vs more api calls
     
    264264                foreach ( $question->tix_values as $group_name ) {
    265265
     266                    $group_name = $this->trim_group( $group_name );
     267
    266268                    // Look into the current MailChimp groupings and skip adding existing groups.
    267269                    if ( isset( $current_groupings[ $grouping_id ] ) && ! empty( $current_groupings[ $grouping_id ]->groups ) ) {
    268270                        foreach ( $current_groupings[ $grouping_id ]->groups as $group ) {
    269                             if ( $group_name == $group->name ) {
     271                            if ( $group_name == $this->trim_group( $group->name ) ) {
    270272                                continue 2;
    271273                            }
     
    361363                            else
    362364                                $groups = array( $answer );
     365
     366                            $groups = array_map( 'the_title', $groups );
     367                            $groups = array_map( array( $this, 'trim_group' ), $groups );
    363368                        }
    364369
     
    373378                        $groupings[] = array(
    374379                            'id' => $existing_groups['tickets'],
    375                             'groups' => array( apply_filters( 'the_title', $ticket->post_title ) ),
     380                            'groups' => array( $ticket->post_title ),
    376381                        );
    377382                    }
     
    460465    }
    461466
     467    public function trim_group( $group_name ) {
     468        return trim( substr( $group_name, 0, 50 ) );
     469    }
     470
    462471    public function menu_setup_section_mailchimp() {
    463472        _e( 'Your main MailChimp export settings are here. Make sure your API key is valid and active. To obtain your API key, please refer to <a href="http://kb.mailchimp.com/article/where-can-i-find-my-api-key">this article</a>.' );
Note: See TracChangeset for help on using the changeset viewer.