• carlosmarugan

    (@carlosmarugan)


    Hi.

    I need to hide some <section> in the Single Event Page according to the Event Author role.

    This is the <section> that i want to hide:

    <section class="em-event-type">
    	<h3>Datos</h3>
    		<div class="em-item-meta-line em-event-time em-event-meta-datetime">
    			<span class="em-icon-info em-icon"></span>TIPO DE ESPECTACULO: #_ATT{tipo_espectaculo}
    		</div>
    		<div class="em-item-meta-line em-event-time em-event-meta-datetime">
    			<span class="em-icon-clock em-icon"></span>DURACIóN: #_ATT{duracion_espectaculo} H.
    		</div>
    </section>

    And this is the code that i’ve used

    function custom_event_section_based_on_author_role($replace, $EM_Event, $result) {
        $author_id = $EM_Event->event_owner;
        $author_roles = get_userdata($author_id)->roles;
    
        if (in_array('otros_profesionales', $author_roles)) {
            if ($result == '#_ATT{tipo_espectaculo}') {
                return '';
            } else {
                return $replace;
            }
        } else {
            return $replace;
        }
    }
    add_filter('em_event_output_placeholder', 'custom_event_section_based_on_author_role', 10, 3);

    This code only hide the value of #_ATT{tipo_espectaculo}, but I need all the <section class=”em-event-type”> to be hide.

    Is it possible?

    Some help, please?

    Thanks. Carlos

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • joneiseman

    (@joneiseman)

    You could create a custom conditional placeholder to only hide the em-event-section for particular authors roles:

    function custom_event_section_based_on_author_role($show, $condition, $full_match, $EM_Event) {
        if(is_object($EM_Event) && preg_match('/^author_not_otros_professional$/', $condition, $matches)){
            $author_id = $EM_Event->event_owner;
            $author_roles = get_userdata($author_id)->roles;
    
            if (in_array('otros_profesionales', $author_roles)) {
                $show = false;
            }
            else { 
                $show = true;
            }
        }
        return $show;
    }
    add_filter('em_event_output_show_condition', 'custom_event_section_based_on_author_role', 1, 4);

    Then you could use the following in the formatting for the single event:

    {author_not_otros_professionals}
    <section class="em-event-type">
    	<h3>Datos</h3>
    		<div class="em-item-meta-line em-event-time em-event-meta-datetime">
    			<span class="em-icon-info em-icon"></span>TIPO DE ESPECTACULO: #_ATT{tipo_espectaculo}
    		</div>
    		<div class="em-item-meta-line em-event-time em-event-meta-datetime">
    			<span class="em-icon-clock em-icon"></span>DURACIóN: #_ATT{duracion_espectaculo} H.
    		</div>
    </section>
    {/author_not_otros_profesionals}
Viewing 1 replies (of 1 total)
  • The topic ‘Problem with placeholder’ is closed to new replies.