Navigation überspringen

Open

Topic Tags: Compatibility

Overview of the issue

When creating an event with a registration limit with WP Event Manager and its WP Event Manager – Registrations addon, the registration limit is not synchronized between languages.

Workaround

Please, make sure of having a full site backup of your site before proceeding.

  • Open …/wp-content/plugins/wp-event-manager-registrations/wp-event-manager-registrations-functions.php file.
  • Look for line 497.
  • Replace:
    if(!function_exists('get_event_registration_count')) {
        /**
         * Get number of registrations for a event
         * @param  int $event_id
         * @return int
         */
        function get_event_registration_count($event_id) {
            return sizeof(get_posts(array(
                'post_type'      => 'event_registration',
                'post_status'    => array_merge(array_keys(get_event_registration_statuses()), array('publish')),
                'posts_per_page' => -1,
                'fields'         => 'ids',
                'post_parent'    => $event_id
            )));
        }
    }
    
  • With:
    if(!function_exists('get_event_registration_count')) {
        /**
         * Get number of registrations for a event
         * @param  int $event_id
         * @return int
         */
        function get_event_registration_count($event_id) {
            
            // WPML workaround for compsupp-7562 - Part I
            $translations = apply_filters( 'wpml_get_element_translations', null, $event_id, 'post_' . get_post_type($event_id) );
            
            // Extract the IDs of the translated posts
            $event_ids = array_map(function($translation) {
                return $translation->element_id;
            }, $translations);
        
            // Get event registrations for all translations
            return sizeof(get_posts(array(
                'post_type'      => 'event_registration',
                'post_status'    => array_merge(array_keys(get_event_registration_statuses()), array('publish')),
                'posts_per_page' => -1,
                'fields'         => 'ids',
                'post_parent__in' => $event_ids // Get all registrations for the event IDs
            )));
        }
        
    }
    
  • Then, look for line 595.
  • Replace:
    if(!function_exists('user_has_registered_for_event')) {
        /**
         * See if a user has already appled for a event
         * @param  int $user_id, $event_id
         * @return int
         */
        function user_has_registered_for_event($user_id, $event_id) {
            if(!$user_id) {
                return false;
            }
            return sizeof(get_posts(array(
                'post_type'      => 'event_registration',
                'post_status'    => array_merge(array_keys(get_event_registration_statuses()), array('publish')),
                'posts_per_page' => 1,
                'fields'         => 'ids',
                'post_parent'    => $event_id,
                'meta_query'     => array(
                    array(
                        'key' => '_attendee_user_id',
                        'value' => absint($user_id)
                    )
                )
            )));
        }
    }
    
  • With:
    if(!function_exists('user_has_registered_for_event')) {
        /**
         * See if a user has already appled for a event
         * @param  int $user_id, $event_id
         * @return int
         */
        function user_has_registered_for_event($user_id, $event_id) {
            if(!$user_id) {
                return false;
            }
    
            // WPML Workaround for compsupp-7562 - Part II
            $translations = apply_filters( 'wpml_get_element_translations', null, $event_id, 'post_' . get_post_type($event_id) );
            
            // Extract the IDs of the translated posts
            $event_ids = array_map(function($translation) {
                return $translation->element_id;
            }, $translations);
    
            // Check if the user is registered for any translation of the event
            return sizeof(get_posts(array(
                'post_type'      => 'event_registration',
                'post_status'    => array_merge(array_keys(get_event_registration_statuses()), array('publish')),
                'posts_per_page' => 1,
                'fields'         => 'ids',
                'post_parent__in' => $event_ids, // Check all event translations
                'meta_query'     => array(
                    array(
                        'key'   => '_attendee_user_id',
                        'value' => absint($user_id)
                    )
                )
            ))) > 0;
        }
    
    }
    

Eine Antwort hinterlassen

Bitte bleiben Sie beim Thema und verhalten Sie sich anderen gegenüber respektvoll. Wenn Sie Hilfe bei Problemen benötigen, die nicht mit diesem Beitrag zusammenhängen, nutzen Sie unser Support-Forum, um einen Chat zu starten oder ein Ticket einzureichen.

Sie können diese Tags verwenden:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>