• Resolved b2995

    (@b2995)


    I’d like to display the table that shows what a user has signed up for to a template page but can’t seem to get it to display correctly. Any ideas? Here’s the complete code if anyone has any ideas:

    <?php
    /*
     Template Name: Template History
     *
     * @package Swift
     * @subpackage Template
     * @since 6.0
     */
    
    get_header(); ?>
    
    <div id="content" role="main">
    	<div class="div-content">
    		<?php swift_before_content() ?>
    		<?php while ( have_posts() ) : the_post(); ?>
    		<?php get_template_part( 'display/post', 'page' ); ?>
    
            <?php $signups = apply_filters( 'pta_sus_user_signups', $this->data->get_user_signups($current_user->ID) );
    
                    if ($signups) {
    
                        $return .= apply_filters( 'pta_sus_before_user_signups_list_headers', '' );
    
                        $return .= '<font size="3" face="arial"><strong>'.apply_filters( 'pta_sus_public_output', __('You Signed Up for These Positions', 'pta_volunteer_sus'), 'user_signups_list_headers_h3' ).'</strong></font></br>';
    
                        $return .= '<font size="2" face="arial"><i>'.apply_filters( 'pta_sus_public_output', __('IMPORTANT: Email the <a href="mailto:'.esc_attr($sheet->chair_email).'">Committee Head</a> if you Need to be Remove from a Position', 'pta_volunteer_sus'),'user_signups_list_headers_h4' ).'</i></font>';
    
                        $return .= apply_filters( 'pta_sus_before_user_signups_list_table', '' );
    
                        $return .= '
    
                            <table class="pta-sus-sheets" cellspacing="0">
                            <thead>
                                <tr>
                                    <th class="column-title" bgcolor="#EEEEEE">'.esc_html($title_header).'</th>
                                    <th class="column-date" bgcolor="#EEEEEE">'.esc_html($date_header).'</th>
                                    <th class="column-task" bgcolor="#EEEEEE">'.esc_html($this->task_item_header).'</th>
                                    <th class="column-time" bgcolor="#EEEEEE" style="text-align:right;">'.esc_html($this->start_time_header).'</th>
                                    <th class="column-time" bgcolor="#EEEEEE" style="text-align:right;">'.esc_html($this->end_time_header).'</th>
                                    <th class="column-details" bgcolor="#EEEEEE" style="text-align:left;">'.esc_html($this->item_details_header).'</th>
                                </tr>
                            </thead>
                            <tbody>';
    
                        foreach ($signups as $signup) {
    
                            $clear_args = array('sheet_id' => false, 'task_id' => false, 'signup_id' => (int)$signup->id);
    
                            $clear_url = add_query_arg($clear_args);
    
                            $clear_text = apply_filters( 'pta_sus_public_output', __('Clear', 'pta_volunteer_sus'), 'clear_signup_link_text');
    
                            $return .= '<tr>
    
                                <td>'.esc_html($signup->title).'</td>
                                <td>'.(($signup->signup_date == "0000-00-00") ? esc_html($this->na_text) : date_i18n(get_option("date_format"), strtotime($signup->signup_date))).'</td>
                                <td>'.esc_html($signup->task_title).'</td>
                                <td style="text-align:right;">'.(("" == $signup->time_start) ? esc_html($this->na_text) : date_i18n(get_option("time_format"), strtotime($signup->time_start)) ).'</td>
                                <td style="text-align:right;">'.(("" == $signup->time_end) ? esc_html($this->na_text) : date_i18n(get_option("time_format"), strtotime($signup->time_end)) ).'</td>
                                <td style="text-align:left;">'.((" " !== $signup->item) ? esc_html($signup->item) : esc_html($this->na_text) ).'</td>
                            </tr>';
                        }
    
                        $return .= '</tbody></table>';
    
                        $return .= apply_filters( 'pta_sus_after_user_signups_list_table', '' );
    
                    }
    
    ?>
    
    		<?php //swift_content_nav( 'nav-below' ); ?>
    
    		<?php comments_template( '', true ); ?>
    
    		<?php endwhile; // end of the loop. ?>
    		<?php swift_after_content() ?>
    	</div>
    	<!-- #content -->
    </div>
    <!-- #primary -->
    <?php get_sidebar(); ?>
    <?php get_sidebar('bbPress'); ?>
    <?php get_footer(); ?>

    https://www.ads-software.com/plugins/pta-volunteer-sign-up-sheets/

Viewing 1 replies (of 1 total)
  • Plugin Author DBAR Productions

    (@dbar-productions)

    You copied the right section of code, however that code won’t work on its own in a template file, as that’s from a class/object. In the context of your template file, you don’t have my class object to work with, so the line:
    <?php $signups = apply_filters( 'pta_sus_user_signups', $this->data->get_user_signups($current_user->ID) );
    is not going to work for you.

    Instead, you need to first create a new data object that you can then use to call the get_user_signups function.

    So, that one line should be replaced with something like the following PHP code (within PHP tags in your template):

    <?php
    $pta_data = new PTA_SUS_Data();
    $signups = $pta_data->get_user_signups($current_user->ID);

    Then, since you are working with a different template, and not within the page that processes my plugin’s shortcode, you’ll either need to change the clear link to go back to the page where you have that shortcode so that it can process the clear link, or you will also need to include (and modify accordingly again, since you aren’t within my class/object) the section of code that checks the global $_GET variable to see if a clear link was clicked.

    Something like this will need to be near the top of the template:

    $pta_data = new PTA_SUS_Data();
    if (isset($_GET['signup_id'])) {
                        // Make sure the signup exists first
                        if (null == $pta_data->get_signup((int)$_GET['signup_id'])) {
                            $return .= '<p class="pta-sus error">'.apply_filters( 'pta_sus_public_output', __('Not a valid signup!', 'pta_volunteer_sus'), 'clear_invalid_signup_error_message' ).'</p>';
                        } else {
                            // Send cleared emails
                            if(!class_exists('PTA_SUS_Emails')) {
                                include_once(dirname(__FILE__).'/class-pta_sus_emails.php');
                            }
                            $emails = new PTA_SUS_Emails();
                            $emails->send_mail((int)$_GET['signup_id'], $reminder=false, $clear=true);
                            $cleared = $pta_data->delete_signup((int)$_GET['signup_id']);
                            if ($cleared) {
                                $return .= '<p class="pta-sus updated">'.apply_filters( 'pta_sus_public_output', __('Signup Cleared', 'pta_volunteer_sus'), 'signup_cleared_message' ).'</p>';
                            } else {
                                $return .= '<p class="pta-sus error">'.apply_filters( 'pta_sus_public_output', __('ERROR clearing signup!', 'pta_volunteer_sus'), 'error_clearing_signup_message' ).'</p>';
                            }
                        }
                    }

    Within that, you’ll need to modify the include path to the PTA_SUS_Emails class. Also, although the public side of my plugin should be initiated, you’ll probably also need to first check if the data class exists before trying to create those data objects. If it doesn’t, you’ll need to do an include to my data.php file.

    Good luck!

Viewing 1 replies (of 1 total)
  • The topic ‘Add Code to Another Page’ is closed to new replies.