Plugin Directory

Changeset 3103736


Ignore:
Timestamp:
06/17/2024 07:51:13 PM (19 months ago)
Author:
christer_f
Message:

Possible to use a custom page to display event.
The custom page slug can be set in the global plugin settings or given as parameter to event list shortcodes.
(Backlinks from the tickets will use default or page set in the global settings)

Location:
hello-event/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • hello-event/trunk/hello_event.php

    r3103735 r3103736  
    3838 */
    3939
    40 // STILL NEED TO FIX: Backlink to event if custom event page!!!
    41 // IDEA: Set this in the settings rather that as a parameter to the short code for listing events.
    4240
    4341namespace Tekomatik\HelloEvent;
     
    656654  }
    657655 
     656  // =========================== Helpers ================================
     657  function permalink_by_slug($slug) {
     658    $args = array(
     659        'post_type'       => 'page',
     660        'name'            => $slug,
     661        'posts_per_page'  => 1
     662    );
     663    $pages = get_posts($args);
     664    if ($pages)
     665      return get_permalink($pages[0]);
     666    else
     667      return false;
     668  }
     669
     670 
     671  function link_to_event_page($permalink, $event_id, $custom_page_slug) {
     672    // A custom page slug can be given as parameter.
     673    // If not defined or empty we will look in the settings for a custom page slug
     674    // If a custom page slug is found and the page exists the link returned = custom page URL with event id as parameter
     675    // Otherwise the $permalink is returned
     676    if (isset(get_option( 'hello_event')['hello_field_custom_event_page']))
     677        $custom_page_in_settings = get_option( 'hello_event')['hello_field_custom_event_page'];
     678    $custom_page_slug = $custom_page_slug ? $custom_page_slug : $custom_page_in_settings;
     679    if (!$custom_page_slug)
     680      return $permalink;
     681    $url = $this->permalink_by_slug($custom_page_slug);
     682    if ($url)
     683      return add_query_arg('event_id',$event_id, $url);
     684    else
     685      return $permalink;
     686  }
    658687 
    659688 
     
    856885      list($event_id, $rc) = $this->get_id_of_event($prod_id);
    857886      if ($event_id) {
    858         $backlink = get_permalink( $event_id );
     887        $backlink = $this->link_to_event_page(get_permalink($event_id), $event_id, false);
    859888        $html = '<a href="' . $backlink .'">' . __("Goto the event", 'hello-event') . '</a><br/><br/>';
    860889        $html = apply_filters('hello_event_display_link_to_event', $html, $prod_id, $event_id);
     
    14121441    list($event_id, $rc) = $this->get_id_of_event($prod_id);
    14131442    if ($event_id) {
    1414       $backlink = get_permalink( $event_id );
     1443      $backlink = $this->link_to_event_page(get_permalink($event_id), $event_id, false);
    14151444      $html = '<a href="' . $backlink .'">' . $a['text'] . '</a><br/>';
    14161445      $html = apply_filters('hello_event_display_link_to_event', $html, $prod_id, $event_id);
  • hello-event/trunk/includes/hello-event-list-events.php

    r3103735 r3103736  
    3131  }
    3232 
    33   // =========================== Helpers ================================
    34   function permalink_by_slug($slug) {
    35     $args = array(
    36         'post_type'       => 'page',
    37         'name'            => $slug,
    38         'posts_per_page'  => 1
    39     );
    40     $pages = get_posts($args);
    41     if ($pages)
    42       return get_permalink($pages[0]);
    43     else
    44       return false;
    45     // $query = new \WP_Query( $args );
    46     // if( $query->have_posts() ) {
    47     //       $query->the_post();
    48     //       $permalink = get_permalink( get_the_ID() );
    49     // }
    50     // wp_reset_postdata();
    51     // return $permalink;
    52   }
    53 
    54  
    55   function link_to_event_page($permalink, $event_id, $custom_page_slug) {
    56     // If custom page is false the link returned = $permalink
    57     // Otherwise the link is to the link returned = custom page URL with event id as parameter
    58     if (!$custom_page_slug)
    59       return $permalink;
    60     $url = $this->permalink_by_slug($custom_page_slug);
    61     if ($url)
    62       return add_query_arg('event_id',$event_id, $url);
    63     else
    64       return $permalink;
    65   }
    6633 
    6734  function handle_shortcode_event_list($args0) {
     
    228195            $html .= '  <div class="start-date">'.$start_date.'</div>';
    229196            $html .= '  <div class="event-title">';
    230             $html .= '     <a href="'.$this->link_to_event_page(get_the_permalink(), $id, $args['event_page']).'" rel="bookmark" title="Permanent Link to '.get_the_title().'">';
     197            $html .= '     <a href="'.$hello_event_object->link_to_event_page(get_the_permalink(), $id, $args['event_page']).'" rel="bookmark" title="Permanent Link to '.get_the_title().'">';
    231198            $html .=       get_the_title().'</a>';
    232199            $html .= '  </div>';
     
    267234            $g_title = "
    268235              <div class='title'>
    269                 <a href='".$this->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
     236                <a href='".$hello_event_object->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
    270237                    rel='bookmark'
    271238                    title='Permalink to ".get_the_title()."'>".get_the_title()."
     
    298265              <div class='description'>
    299266                <div class='title'>
    300                   <a href='".$this->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
     267                  <a href='".$hello_event_object->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
    301268                      rel='bookmark'
    302269                      title='Permalink to ".get_the_title()."'>".get_the_title()."
     
    324291                  </div>
    325292                  <div class='title'>
    326                     <a href='".$this->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
     293                    <a href='".$hello_event_object->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
    327294                        rel='bookmark'
    328295                        title='Permalink to ".get_the_title()."'>".get_the_title()."
     
    352319                <div class='intro'>
    353320                  <div class='title'>
    354                     <a href='".$this->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
     321                    <a href='".$hello_event_object->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
    355322                        rel='bookmark'
    356323                        title='Permalink to ".get_the_title()."'>".get_the_title()."
     
    381348                  </div>
    382349                  <div class='title'>
    383                     <a href='".$this->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
     350                    <a href='".$hello_event_object->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
    384351                        rel='bookmark'
    385352                        title='Permalink to ".get_the_title()."'>".get_the_title()."
     
    427394                  </div>
    428395                  <div class='title'>
    429                     <a href='".$this->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
     396                    <a href='".$hello_event_object->link_to_event_page(get_the_permalink(), $id, $args['event_page'])."'
    430397                        rel='bookmark'
    431398                        title='Permalink to ".get_the_title()."'>".get_the_title()."
  • hello-event/trunk/includes/hello-event-settings.php

    r2946985 r3103736  
    7070    );
    7171 
     72    // New section for custom event page
     73    add_settings_section(
     74      'hello_section_6a',
     75      __('Custom event page', 'hello-event'),
     76      array($this, 'hello_section_6a_intro'),
     77      'hello_event'
     78    );
     79 
    7280    add_settings_section(
    7381      'hello_section_6',
     
    194202    );
    195203
     204    // New field for custom event page
     205    add_settings_field(
     206      'hello_field_select_map_api',
     207      __( 'Slug for custom event page', 'hello-event' ),
     208      array($this, 'hello_field_custom_event_page_cb'),
     209      'hello_event',
     210      'hello_section_6a',
     211      [
     212        'label_for' => 'hello_field_custom_event_page',
     213        'class' => 'hello_row',
     214        'hello_custom_data' => 'custom',
     215      ]
     216    );
    196217
    197218    add_settings_field(
     
    410431  }
    411432   
     433  function hello_section_6a_intro( $args ) {
     434    $html = "";
     435    $html .= "<p>" . __("It is possible to create a custom page used to display the events.", 'hello-event') . "<br/>";
     436    $html .= __("If no custom page is defined, events will be displayed using the standard page template of the theme, and in the settings below", 'hello-event') .", <i>". __("Auto inserted content", "hello-event") .",</i> " . __("you can decide what information should be automatically inserted", "hello-event") . "<br/>";
     437    $html .= __("When using a custom event page you must use shortcodes to show the event information.", 'hello-event') . "</p>";
     438    echo $html;
     439  }
     440 
    412441  function hello_section_6_intro( $args ) {
    413442    $html = "";
     
    588617    $html .= __('this page', 'hello-event') . '</a></p>';
    589618    echo $html;
    590          
     619  }
     620 
     621  function hello_field_custom_event_page_cb($args) {
     622    $options = get_option( 'hello_event' );
     623    //print_r($options);
     624    ?>
     625    <input type="text"
     626        id="<?php echo esc_attr( $args['label_for'] ); ?>"
     627        data-custom="<?php echo esc_attr( $args['hello_custom_data'] ); ?>"
     628        name="hello_event[<?php echo esc_attr( $args['label_for'] ); ?>]"
     629        value="<?php echo isset($options[ $args['label_for'] ]) ? $options[ $args['label_for'] ] : '' ; ?>"/>
     630    <?php
     631    $html = '<p class="description">' . __("Fill in the slug of the custom event page, or leave blank for default.", 'hello-event') . '<br/>';
     632    $html .=  __("If the page does not exist the default will be used.", 'hello-event') . '</p>';
     633    echo $html;
     634   
    591635  }
    592636 
  • hello-event/trunk/readme.txt

    r3103735 r3103736  
    7474== Changelog ==
    7575= 1.3.14
     76* Added possibility to display the event using a custom page
    7677* More debug info when debug setting is switched on in the settings
    7778* Added Dutch language - courtesy of Wim De Kelver
Note: See TracChangeset for help on using the changeset viewer.