how to show content in popular post in wordpress? - php

I am using top 10 -popular post plugin.
I added the following lines but it wont display...
$output .= '<li>' .wpautop(wp_trim_words($result["post_content"], 15)). '</li>';
code:
function tptn_pop_posts( $args ) {
global $wpdb, $siteurl, $tableposts, $id, $tptn_settings;
$defaults = array(
'is_widget' => FALSE,
'daily' => FALSE,
'echo' => FALSE,
'strict_limit' => FALSE,
'posts_only' => FALSE,
'is_shortcode' => FALSE,
'heading' => 1,
);
$defaults = array_merge( $defaults, $tptn_settings );
// Parse incomming $args into an array and merge it with $defaults
$args = wp_parse_args( $args, $defaults );
// OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
extract( $args, EXTR_SKIP );
if ($daily) {
$table_name = $wpdb->prefix . "top_ten_daily";
} else {
$table_name = $wpdb->prefix . "top_ten";
}
$limit = ( $strict_limit ) ? $limit : ( $limit * 5 );
$exclude_categories = explode( ',', $exclude_categories );
$target_attribute = ( $link_new_window ) ? ' target="_blank" ' : ' '; // Set Target attribute
$rel_attribute = ( $link_nofollow ) ? ' nofollow' : ''; // Set nofollow attribute
parse_str( $post_types, $post_types ); // Save post types in $post_types variable
if ( ! $daily ) {
$args = array();
$sql = "SELECT postnumber, cntaccess as sumCount, ID, post_type, post_status ";
$sql .= "FROM {$table_name} INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
$sql .= "AND post_status = 'publish' ";
if ( '' != $exclude_post_ids ) {
$sql .= "AND ID NOT IN ({$exclude_post_ids}) ";
}
$sql .= "AND ( ";
$multiple = false;
foreach ( $post_types as $post_type ) {
if ( $multiple ) $sql .= ' OR ';
$sql .= " post_type = '%s' ";
$multiple = true;
$args[] = $post_type; // Add the post types to the $args array
}
$sql .= " ) ";
$sql .= "ORDER BY sumCount DESC LIMIT %d";
$args[] = $limit;
} else {
$current_time = current_time( 'timestamp', 0 );
$current_time = $current_time - ( $daily_range - 1 ) * 3600 * 24;
$current_date = date( 'Y-m-j', $current_time );
$args = array(
$current_date,
);
$sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
$sql .= "FROM {$table_name} INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
$sql .= "AND post_status = 'publish' AND dp_date >= '%s' ";
if ( '' != $exclude_post_ids ) {
$sql .= "AND ID NOT IN ({$exclude_post_ids}) ";
}
$sql .= "AND ( ";
$multiple = false;
foreach ( $post_types as $post_type ) {
if ( $multiple ) $sql .= ' OR ';
$sql .= " post_type = '%s' ";
$multiple = true;
$args[] = $post_type; // Add the post types to the $args array
}
$sql .= " ) ";
$sql .= "GROUP BY postnumber ";
$sql .= "ORDER BY sumCount DESC LIMIT %d";
$args[] = $limit;
}
if ( $posts_only ) { // Return the array of posts only if the variable is set
return apply_filters( 'tptn_pop_posts_array', $wpdb->get_results( $wpdb->prepare( $sql , $args ) , ARRAY_A ) );
}
$results = $wpdb->get_results( $wpdb->prepare( $sql , $args ) );
$counter = 0;
$output = '';
$shortcode_class = $is_shortcode ? ' tptn_posts_shortcode' : '';
$widget_class = $is_widget ? ' tptn_posts_widget' : '';
if ( $heading ) {
if ( ! $daily ) {
$output .= '<div id="tptn_related" class="tptn_posts ' . $widget_class . $shortcode_class . '">' . apply_filters( 'tptn_heading_title', $title );
} else {
$output .= '<div id="tptn_related_daily" class="tptn_posts_daily' . $shortcode_class . '">' . apply_filters( 'tptn_heading_title', $title_daily );
}
} else {
if ( ! $daily ) {
$output .= '<div class="tptn_posts' . $widget_class . $shortcode_class . '">';
} else {
$output .= '<div class="tptn_posts_daily' . $widget_class . $shortcode_class . '">';
}
}
if ( $results ) {
$output .= apply_filters( 'tptn_before_list', $before_list );
foreach ( $results as $result ) {
$sumcount = $result->sumCount;
$result = get_post( apply_filters( 'tptn_post_id', $result->ID ) ); // Let's get the Post using the ID
$categorys = get_the_category( apply_filters( 'tptn_post_cat_id', $result->ID ) ); //Fetch categories of the plugin
$p_in_c = false; // Variable to check if post exists in a particular category
foreach ( $categorys as $cat ) { // Loop to check if post exists in excluded category
$p_in_c = ( in_array( $cat->cat_ID, $exclude_categories ) ) ? true : false;
if ( $p_in_c ) break; // End loop if post found in category
}
$title = tptn_max_formatted_content( get_the_title( $result->ID ), $title_length );
if ( ! $p_in_c ) {
$output .= apply_filters( 'tptn_before_list_item', $before_list_item, $result->ID );
if ( 'after' == $post_thumb_op ) {
$output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
$output .= '<span class="tptn_title">' . $title . '</span>'; // Add title if post thumbnail is to be displayed after
$output .= '</a>'; // Close the link
}
if ( 'inline' == $post_thumb_op || 'after' == $post_thumb_op || 'thumbs_only' == $post_thumb_op ) {
$output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
$output .= tptn_get_the_post_thumbnail( array(
'postid' => $result->ID,
'thumb_height' => $thumb_height,
'thumb_width' => $thumb_width,
'thumb_meta' => $thumb_meta,
'thumb_html' => $thumb_html,
'thumb_default' => $thumb_default,
'thumb_default_show' => $thumb_default_show,
'thumb_timthumb' => $thumb_timthumb,
'thumb_timthumb_q' => $thumb_timthumb_q,
'scan_images' => $scan_images,
'class' => "tptn_thumb",
'filter' => "tptn_postimage",
) );
$output .= '</a>'; // Close the link
}
if ( 'inline' == $post_thumb_op || 'text_only' == $post_thumb_op ) {
$output .= '<span class="tptn_after_thumb">';
$output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
$output .= '<span class="tptn_title">' . $title . '</span>'; // Add title when required by settings
// $output .= '<li>' .wpautop(wp_trim_words($result["post_content"], 15)). '</li>';
$output .= '</a>'; // Close the link
}
if ( $show_author ) {
$author_info = get_userdata( $result->post_author );
$author_name = ucwords( trim( stripslashes( $author_info->display_name ) ) );
$author_link = get_author_posts_url( $author_info->ID );
$output .= '<span class="tptn_author"> ' . __( ' by ', TPTN_LOCAL_NAME ).'' . $author_name . '</span> ';
}
if ( $show_date ) {
$output .= '<span class="tptn_date"> ' . mysql2date( get_option( 'date_format', 'd/m/y' ), $result->post_date ).'</span> ';
}
if ( $show_excerpt ) {
$output .= '<span class="tptn_excerpt"> ' . tptn_excerpt( $result->ID, $excerpt_length ).'</span>';
}
if ( $disp_list_count ) $output .= ' <span class="tptn_list_count">(' . number_format_i18n( $sumcount ) . ')</span>';
if ( 'inline' == $post_thumb_op || 'text_only' == $post_thumb_op ) {
$output .= '</span>';
}
$output .= apply_filters( 'tptn_after_list_item', $after_list_item, $result->ID );
$counter++;
}
if ( $counter == $limit/5 ) break; // End loop when related posts limit is reached
}
if ( $show_credit ) {
$output .= apply_filters( 'tptn_before_list_item', $before_list_item, $result->ID );
$output .= sprintf( 'Popular posts by Top 10 plugin', TPTN_LOCAL_NAME );
$output .= apply_filters( 'tptn_after_list_item', $after_list_item, $result->ID );
}
$output .= apply_filters( 'tptn_after_list', $after_list );
} else {
$output .= ( $blank_output ) ? '' : $blank_output_text;
}
$output .= '</div>';
return apply_filters( 'tptn_pop_posts', $output );
}

You seem to be returning $output. You will need to use echo in order for your HTML to display.
Ref: http://php.net/manual/en/function.echo.php

to show content in popular post by adding the following line below the code.
$output .= '<li><p>' .wp_trim_words(get_post($result->ID)->post_content,15). '</p></li>';
top10.php (top10 popular post plugin)
code:
if ( 'inline' == $post_thumb_op || 'text_only' == $post_thumb_op ) {
$output .= '<span class="tptn_after_thumb">';
$output .= '<a href="' . get_permalink( $result->ID ) . '" rel="bookmark' . $rel_attribute . '" ' . $target_attribute . 'class="tptn_link">'; // Add beginning of link
$output .= '<span class="tptn_title">' . $title . '</span>'; // Add title when required by settings
$output .= '</a>'; // Close the link
$output .= '<li><p>' .wp_trim_words(get_post($result->ID)->post_content,15). '</p></li>';
}

Related

Passing default arguments value in function not working

First of all, sorry for my lack of knowledge in PHP. I have tried googling for the answer, and also tried several answers here. For some reason passing argument in my function isn't working. However, if I directly call the default value in function, it works. Here is the function I am using.
function pnet_breadcrumbs( $seperator = '»', $home = true, $blog = true, $show_hierarchy = true ) {
global $post, $wp_query;
$html = '<div class="breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/">';
$position = 1;
if ( $home ) {
$html .= '<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to ' . get_option( 'blogname' ) . '." href="' . home_url( '/' ) . '" class="home"><span property="name">' . get_option( 'blogname' ) . '</span></a><meta property="position" content="' . $position . '"></span>' . $seperator;
$html .= ' ' . $seperator . ' '; //Not Working
$html .= ' » '; //Working
$position = $position + 1;
}
if ( is_tax() || is_category() || is_tag() ) {
$obj = $wp_query->get_queried_object();
if ( $show_hierarchy ) {
$ancestors = get_ancestors( $obj->term_id, $obj->taxonomy, 'taxonomy' );
if ( is_array($ancestors) && !empty($ancestors) ) {
$ancestors = array_reverse( $ancestors );
foreach( $ancestors as $ancestor ) {
$term_obj = get_term($ancestor);
$term_url = get_term_link($term_obj->term_id);
$html .= '<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="' . sprintf( __( 'View Archive for %s.', 'pnet' ), $term_obj->name ) . '." href="' . $term_url . '" class="home"><span property="name">' . $term_obj->name . '</span></a><meta property="position" content="' . $position . '"></span>';
$html .= $seperator;
$position++;
}
}
}
$html .= '<span property="itemListElement" typeof="ListItem"><span property="name">' . $obj->name . '</span><meta property="position" content="' . $position . '"></span>';
}
if ( is_search() ) {
$html .= '<span property="itemListElement" typeof="ListItem"><span property="name">' . sprintf( __( 'Search results for %s.', 'pnet' ), get_search_query() ) . '</span><meta property="position" content="' . $position . '"></span>';
}
$html .= '</div>';
echo $html;
}
add_action( 'wp_footer', 'pnet_breadcrumbs', 0 );
The variable $seperator is returning empty.
I know this is basic PHP, but I really can't figure out why I can't use a default value. What am I doing wrong?

Breadcrumb Incrementing Number for meta position content

I'm new to PHP, still learning, so please excuse and kindly tell me what would be the appropriate fix. I used the breadcrumb script from here answered by Pieter Goosen. I want the breadcrumbs to work with google and schema, the part that isn't working is the <meta itemprop="position" content="number" /> tag. The content="number" needs to be set for each crumb, in order (1,2,3...). On line 8 I added $i = 1;, then changed $link_after = '<meta itemprop="position" content="' . $i++ . '" /></li>';. But $i++ is not printing a new sequential number, it is just repeating itself as if there was no other $i++. My guess is to apply the rule globally and to search for $i++ used, as it's probably being applied closed within the rule, but wouldn't know how to do this.
Code:
function get_hansel_and_gretel_breadcrumbs()
{
// Set variables for later use
$here_text = __( 'You are currently here!' );
$home_link = home_url('/');
$home_text = __( 'Home' );
$link_before = '<span typeof="v:Breadcrumb">';
$i = 1;
$link_after = '<meta itemprop="position" content="' . $i++ . '" /></span>'
$link_attr = ' rel="v:url" property="v:title"';
$link = $link_before . '<a' . $link_attr . ' href="%1$s">%2$s</a>' . $link_after;
$delimiter = ' » '; // Delimiter between crumbs
$before = '<span class="current">'; // Tag before the current crumb
$after = '</span>'; // Tag after the current crumb
$page_addon = ''; // Adds the page number if the query is paged
$breadcrumb_trail = '';
$category_links = '';
/**
* Set our own $wp_the_query variable. Do not use the global variable version due to
* reliability
*/
$wp_the_query = $GLOBALS['wp_the_query'];
$queried_object = $wp_the_query->get_queried_object();
// Handle single post requests which includes single pages, posts and attatchments
if ( is_singular() )
{
/**
* Set our own $post variable. Do not use the global variable version due to
* reliability. We will set $post_object variable to $GLOBALS['wp_the_query']
*/
$post_object = sanitize_post( $queried_object );
// Set variables
$title = apply_filters( 'the_title', $post_object->post_title );
$parent = $post_object->post_parent;
$post_type = $post_object->post_type;
$post_id = $post_object->ID;
$post_link = $before . $title . $after;
$parent_string = '';
$post_type_link = '';
if ( 'post' === $post_type )
{
// Get the post categories
$categories = get_the_category( $post_id );
if ( $categories ) {
// Lets grab the first category
$category = $categories[0];
$category_links = get_category_parents( $category, true, $delimiter );
$category_links = str_replace( '<a', $link_before . '<a' . $link_attr, $category_links );
$category_links = str_replace( '</a>', '</a>' . $link_after, $category_links );
}
}
if ( !in_array( $post_type, ['post', 'page', 'attachment'] ) )
{
$post_type_object = get_post_type_object( $post_type );
$archive_link = esc_url( get_post_type_archive_link( $post_type ) );
$post_type_link = sprintf( $link, $archive_link, $post_type_object->labels->singular_name );
}
// Get post parents if $parent !== 0
if ( 0 !== $parent )
{
$parent_links = [];
while ( $parent ) {
$post_parent = get_post( $parent );
$parent_links[] = sprintf( $link, esc_url( get_permalink( $post_parent->ID ) ), get_the_title( $post_parent->ID ) );
$parent = $post_parent->post_parent;
}
$parent_links = array_reverse( $parent_links );
$parent_string = implode( $delimiter, $parent_links );
}
// Lets build the breadcrumb trail
if ( $parent_string ) {
$breadcrumb_trail = $parent_string . $delimiter . $post_link;
} else {
$breadcrumb_trail = $post_link;
}
if ( $post_type_link )
$breadcrumb_trail = $post_type_link . $delimiter . $breadcrumb_trail;
if ( $category_links )
$breadcrumb_trail = $category_links . $breadcrumb_trail;
}
// Handle archives which includes category-, tag-, taxonomy-, date-, custom post type archives and author archives
if( is_archive() )
{
if ( is_category()
|| is_tag()
|| is_tax()
) {
// Set the variables for this section
$term_object = get_term( $queried_object );
$taxonomy = $term_object->taxonomy;
$term_id = $term_object->term_id;
$term_name = $term_object->name;
$term_parent = $term_object->parent;
$taxonomy_object = get_taxonomy( $taxonomy );
$current_term_link = $before->labels->singular_name . '<li class="curr-cat" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">' . $term_name . '</span><meta itemprop="position" content="' . $i++ . '" /></li>';
$parent_term_string = '';
if ( 0 !== $term_parent )
{
// Get all the current term ancestors
$parent_term_links = [];
while ( $term_parent ) {
$term = get_term( $term_parent, $taxonomy );
$parent_term_links[] = sprintf( $link, esc_url( get_term_link( $term ) ), $term->name );
$term_parent = $term->parent;
}
$parent_term_links = array_reverse( $parent_term_links );
$parent_term_string = implode( $delimiter, $parent_term_links );
}
if ( $parent_term_string ) {
$breadcrumb_trail = $parent_term_string . $delimiter . $current_term_link;
} else {
$breadcrumb_trail = $current_term_link;
}
} elseif ( is_author() ) {
$breadcrumb_trail = __( 'Author archive for ') . $before . $queried_object->data->display_name . $after;
} elseif ( is_date() ) {
// Set default variables
$year = $wp_the_query->query_vars['year'];
$monthnum = $wp_the_query->query_vars['monthnum'];
$day = $wp_the_query->query_vars['day'];
// Get the month name if $monthnum has a value
if ( $monthnum ) {
$date_time = DateTime::createFromFormat( '!m', $monthnum );
$month_name = $date_time->format( 'F' );
}
if ( is_year() ) {
$breadcrumb_trail = $before . $year . $after;
} elseif( is_month() ) {
$year_link = sprintf( $link, esc_url( get_year_link( $year ) ), $year );
$breadcrumb_trail = $year_link . $delimiter . $before . $month_name . $after;
} elseif( is_day() ) {
$year_link = sprintf( $link, esc_url( get_year_link( $year ) ), $year );
$month_link = sprintf( $link, esc_url( get_month_link( $year, $monthnum ) ), $month_name );
$breadcrumb_trail = $year_link . $delimiter . $month_link . $delimiter . $before . $day . $after;
}
} elseif ( is_post_type_archive() ) {
$post_type = $wp_the_query->query_vars['post_type'];
$post_type_object = get_post_type_object( $post_type );
$breadcrumb_trail = $before . $post_type_object->labels->singular_name . $after;
}
}
// Handle the search page
if ( is_search() ) {
$breadcrumb_trail = __( 'Search query for: ' ) . $before . get_search_query() . $after;
}
// Handle 404's
if ( is_404() ) {
$breadcrumb_trail = $before . __( 'Error 404' ) . $after;
}
// Handle paged pages
if ( is_paged() ) {
$current_page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' );
$page_addon = $before . sprintf( __( ' ( Page %s )' ), number_format_i18n( $current_page ) ) . $after;
}
$breadcrumb_output_link = '';
$breadcrumb_output_link .= '<div class="breadcrumb">';
if ( is_home()
|| is_front_page()
) {
// Do not show breadcrumbs on page one of home and frontpage
if ( is_paged() ) {
$breadcrumb_output_link .= $here_text . $delimiter;
$breadcrumb_output_link .= '' . $home_text . '';
$breadcrumb_output_link .= $page_addon;
}
} else {
$breadcrumb_output_link .= $here_text . $delimiter;
$breadcrumb_output_link .= '' . $home_text . '';
$breadcrumb_output_link .= $delimiter;
$breadcrumb_output_link .= $breadcrumb_trail;
$breadcrumb_output_link .= $page_addon;
}
$breadcrumb_output_link .= '</div><!-- .breadcrumbs -->';
return $breadcrumb_output_link;
}

Custom Gravity Forms Field with Multiple Inputs

I have been working on a Gravity Forms extension for a client. The concept is to add a new field type with 4 inputs. I have tried about 10 different variations on how people build custom gravity form fields, but I keep running into the same issue.
When creating a custom field, if I use only 1 input under the naming convention of input_{field_id} the form will save and validate properly. But the moment I try to add more than one field using the names input_{field_id}.{i} just like the built in fields the form will no longer save my data.
<?php if ( ! class_exists( 'GFForms' ) ) { die(); }
class GF_Field_Attendees extends GF_Field {
public $type = 'attendees';
public function get_form_editor_field_title() { return esc_attr__( 'Attendees', 'gravityforms' ); }
public function get_form_editor_button() {
return array(
'group' => 'advanced_fields',
'text' => $this->get_form_editor_field_title(),
'onclick' => "StartAddField('".$this->type."');",
);
}
public function get_form_editor_field_settings() {
return array(
'conditional_logic_field_setting',
'prepopulate_field_setting',
'error_message_setting',
'label_setting',
'admin_label_setting',
'rules_setting',
'duplicate_setting',
'description_setting',
'css_class_setting',
);
}
public function is_conditional_logic_supported() { return true; }
public function get_field_input( $form, $value = '', $entry = null ) {
$form_id = $form['id'];
$field_id = intval( $this->id );
$first = esc_attr( GFForms::get( 'input_' . $this->id . '_1', $value ) );
$last = esc_attr( GFForms::get( 'input_' . $this->id . '_2', $value ) );
$email = esc_attr( GFForms::get( 'input_' . $this->id . '_3', $value ) );
$phone = esc_attr( GFForms::get( 'input_' . $this->id . '_4', $value ) );
$disabled_text = $is_form_editor ? "disabled='disabled'" : '';
$class_suffix = $is_entry_detail ? '_admin' : '';
$first_tabindex = GFCommon::get_tabindex();
$last_tabindex = GFCommon::get_tabindex();
$email_tabindex = GFCommon::get_tabindex();
$phone_tabindex = GFCommon::get_tabindex();
$required_attribute = $this->isRequired ? 'aria-required="true"' : '';
$invalid_attribute = $this->failed_validation ? 'aria-invalid="true"' : 'aria-invalid="false"';
$first_markup = '<span id="input_'.$field_id.'_'.$form_id.'.1_container" class="attendees_first">';
$first_markup .= '<input type="text" name="input_'.$field_id.'.1" id="input_'.$field_id.'_'.$form_id.'_1" value="'.$first.'" aria-label="First Name" '.$first_tabindex.' '.$disabled_text.' '.$required_attribute.' '.$invalid_attribute.'>';
$first_markup .= '<label for="input_'.$field_id.'_'.$form_id.'_1">First Name</label>';
$first_markup .= '</span>';
$last_markup = '<span id="input_'.$field_id.'_'.$form_id.'.2_container" class="attendees_last">';
$last_markup .= '<input type="text" name="input_'.$field_id.'.2" id="input_'.$field_id.'_'.$form_id.'_2" value="'.$last.'" aria-label="Last Name" '.$last_tabindex.' '.$disabled_text.' '.$required_attribute.' '.$invalid_attribute.'>';
$last_markup .= '<label for="input_'.$field_id.'_'.$form_id.'_2">Last Name</label>';
$last_markup .= '</span>';
$email_markup = '<span id="input_'.$field_id.'_'.$form_id.'.3_container" class="attendees_email">';
$email_markup .= '<input type="text" name="input_'.$field_id.'.3" id="input_'.$field_id.'_'.$form_id.'_3" value="'.$email.'" aria-label="Email" '.$email_tabindex.' '.$disabled_text.' '.$required_attribute.' '.$invalid_attribute.'>';
$email_markup .= '<label for="input_'.$field_id.'_'.$form_id.'_3">Email</label>';
$email_markup .= '</span>';
$phone_markup = '<span id="input_'.$field_id.'_'.$form_id.'.4_container" class="attendees_phone">';
$phone_markup .= '<input type="text" name="input_'.$field_id.'.4" id="input_'.$field_id.'_'.$form_id.'_4" value="'.$phone.'" aria-label="Phone #" '.$phone_tabindex.' '.$disabled_text.' '.$required_attribute.' '.$invalid_attribute.'>';
$phone_markup .= '<label for="input_'.$field_id.'_'.$form_id.'_4">Phone #</label>';
$phone_markup .= '</span>';
$css_class = $this->get_css_class();
return "<div class='ginput_complex{$class_suffix} ginput_container {$css_class} gfield_trigger_change' id='{$field_id}'>
{$first_markup}
{$last_markup}
{$email_markup}
{$phone_markup}
<div class='gf_clear gf_clear_complex'></div>
</div>";
}
public function get_css_class() {
$first_input = GFFormsModel::get_input( $this, $this->id . '_2' );
$last_input = GFFormsModel::get_input( $this, $this->id . '_3' );
$email_input = GFFormsModel::get_input( $this, $this->id . '_4' );
$phone_input = GFFormsModel::get_input( $this, $this->id . '_5' );
$css_class = '';
$visible_input_count = 0;
if ( $first_input && ! rgar( $first_input, 'isHidden' ) ) {
$visible_input_count++;
$css_class .= 'has_first_name ';
} else {
$css_class .= 'no_first_name ';
}
if ( $last_input && ! rgar( $last_input, 'isHidden' ) ) {
$visible_input_count++;
$css_class .= 'has_last_name ';
} else {
$css_class .= 'no_last_name ';
}
if ( $email_input && ! rgar( $email_input, 'isHidden' ) ) {
$visible_input_count++;
$css_class .= 'has_email ';
} else {
$css_class .= 'no_email ';
}
if ( $phone_input && ! rgar( $phone_input, 'isHidden' ) ) {
$visible_input_count++;
$css_class .= 'has_phone ';
} else {
$css_class .= 'no_phone ';
}
$css_class .= "gf_attendees_has_{$visible_input_count} ginput_container_attendees ";
return trim( $css_class );
}
public function get_value_submission( $field_values, $get_from_post ) {
if(!$get_from_post) {
return $field_values;
}
return $_POST;
}
}
GF_Fields::register( new GF_Field_Attendees() );
I have spend about 20 hours trying different fixes and searching the internet to get this working, with no luck to show for it. At one point I was able to get the form fields to save using a different method (see below), but I could not make the field required or use conditional login on it, which is a must.
$group_title = "Attendees";
$group_name = "attendees";
$group_fields = array(
'attendee_first' => 'First Name',
'attendee_last' => 'Last Name',
'attendee_email' => 'Email',
'attendee_phone' => 'Phone'
);
$group_values = array();
add_filter('gform_add_field_buttons', add_field);
function add_field($field_group)
{
global $group_title, $group_name;
foreach ($field_group as &$group) {
if ($group['name'] == 'advanced_fields') {
$group['fields'][] = array (
'class' => 'button',
'value' => __($group_title, 'gravityforms'),
'onclick' => "StartAddField('".$group_name."');",
'data-type' => $group_name
);
break;
}
}
return $field_group;
}
add_filter('gform_field_type_title', add_field_title, 10, 2);
function add_field_title($title, $field_type)
{
global $group_title, $group_name;
if ($field_type == $group_name) {
$title = __($group_title, 'gravityforms');
}
return $title;
}
add_filter('gform_field_input', 'render_fields', 10, 5);
function render_fields($input, $field, $value, $entry_id, $form_id)
{
global $group_name, $group_fields;
if ($field->type == $group_name)
{
$i = 1;
$input = '<div class="ginput_complex ginput_container">';
foreach ($group_fields as $key => $val) {
$input .= '<span id="input_'.$field['id'].'_'.$form_id.'_'.$i.'_container" class="name_suffix ">';
$input .= '<input type="text" name="input_'.$field['id'].'_'.$i.'" id="input_'.$field['id'].'_'.$form_id.'_'.$i.'" value="'.$value[$field['id'].'.'.$i].'" class="'.esc_attr($key).'" aria-label="'.$val.'">';
$input .= '<label for="input_'.$field['id'].'_'.$form_id.'_'.$i.'">'.$val.'</label>';
$input .= '</span>';
$i ++;
if ($i % 10 == 0) { $i++; }
}
$input .= '</div>';
}
return $input;
}
add_action('gform_editor_js_set_default_values', set_default_values);
function set_default_values()
{
global $group_title, $group_name, $group_fields;
?>
case '<?php echo $group_name; ?>' :
field.label = '<?php _e($group_title, 'gravityforms'); ?>';
field.inputs = [
<?php
$i = 1;
foreach ($group_fields as $key => $val) { ?>
new Input(field.id + 0.<?php echo $i; ?>, '<?php echo esc_js(__($val, 'gravityforms')); ?>'),
<?php
$i++;
if ($i % 10 == 0) { $i++; }
} ?>
];
break;
<?php
}
add_filter( 'gform_entry_field_value', 'category_names', 10, 4 );
function category_names( $value, $field, $lead, $form )
{
global $group_name, $group_values;
if($field->type == $group_name)
{
$array = array();
$output = "";
foreach($field->inputs as $input)
{
$array[$input['label']] = $value[$input['id']];
$output .= "<strong>".$input['label'].":</strong> ";
$output .= $value[$input['id']]."<br>";
}
$group_values[] = $array;
return $output;
}
return $value;
}
If anyone can help me with either issue, it would be greatly appreciated.
Class update:
Cleaned Up get_field_input
Added get_value_submission
After working with the Gravity Forms support team for a few days, we were able to come up with this solution. Everything seems to be working now. Hope this helps someone in the future.
class GF_Field_Attendees extends GF_Field {
public $type = 'attendees';
public function get_form_editor_field_title() {
return esc_attr__( 'Attendees', 'gravityforms' );
}
public function get_form_editor_button() {
return array(
'group' => 'advanced_fields',
'text' => $this->get_form_editor_field_title(),
);
}
public function get_form_editor_field_settings() {
return array(
'conditional_logic_field_setting',
'prepopulate_field_setting',
'error_message_setting',
'label_setting',
'admin_label_setting',
'rules_setting',
'duplicate_setting',
'description_setting',
'css_class_setting',
);
}
public function is_conditional_logic_supported() {
return true;
}
public function get_field_input( $form, $value = '', $entry = null ) {
$is_entry_detail = $this->is_entry_detail();
$is_form_editor = $this->is_form_editor();
$form_id = $form['id'];
$field_id = intval( $this->id );
$first = $last = $email = $phone = '';
if ( is_array( $value ) ) {
$first = esc_attr( rgget( $this->id . '.1', $value ) );
$last = esc_attr( rgget( $this->id . '.2', $value ) );
$email = esc_attr( rgget( $this->id . '.3', $value ) );
$phone = esc_attr( rgget( $this->id . '.4', $value ) );
}
$disabled_text = $is_form_editor ? "disabled='disabled'" : '';
$class_suffix = $is_entry_detail ? '_admin' : '';
$first_tabindex = GFCommon::get_tabindex();
$last_tabindex = GFCommon::get_tabindex();
$email_tabindex = GFCommon::get_tabindex();
$phone_tabindex = GFCommon::get_tabindex();
$required_attribute = $this->isRequired ? 'aria-required="true"' : '';
$invalid_attribute = $this->failed_validation ? 'aria-invalid="true"' : 'aria-invalid="false"';
$first_markup = '<span id="input_' . $field_id . '_' . $form_id . '.1_container" class="attendees_first">';
$first_markup .= '<input type="text" name="input_' . $field_id . '.1" id="input_' . $field_id . '_' . $form_id . '_1" value="' . $first . '" aria-label="First Name" ' . $first_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
$first_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_1">First Name</label>';
$first_markup .= '</span>';
$last_markup = '<span id="input_' . $field_id . '_' . $form_id . '.2_container" class="attendees_last">';
$last_markup .= '<input type="text" name="input_' . $field_id . '.2" id="input_' . $field_id . '_' . $form_id . '_2" value="' . $last . '" aria-label="Last Name" ' . $last_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
$last_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_2">Last Name</label>';
$last_markup .= '</span>';
$email_markup = '<span id="input_' . $field_id . '_' . $form_id . '.3_container" class="attendees_email">';
$email_markup .= '<input type="text" name="input_' . $field_id . '.3" id="input_' . $field_id . '_' . $form_id . '_3" value="' . $email . '" aria-label="Email" ' . $email_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
$email_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_3">Email</label>';
$email_markup .= '</span>';
$phone_markup = '<span id="input_' . $field_id . '_' . $form_id . '.4_container" class="attendees_phone">';
$phone_markup .= '<input type="text" name="input_' . $field_id . '.4" id="input_' . $field_id . '_' . $form_id . '_4" value="' . $phone . '" aria-label="Phone #" ' . $phone_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
$phone_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_4">Phone #</label>';
$phone_markup .= '</span>';
$css_class = $this->get_css_class();
return "<div class='ginput_complex{$class_suffix} ginput_container {$css_class} gfield_trigger_change' id='{$field_id}'>
{$first_markup}
{$last_markup}
{$email_markup}
{$phone_markup}
<div class='gf_clear gf_clear_complex'></div>
</div>";
}
public function get_css_class() {
$first_input = GFFormsModel::get_input( $this, $this->id . '.1' );
$last_input = GFFormsModel::get_input( $this, $this->id . '.2' );
$email_input = GFFormsModel::get_input( $this, $this->id . '.3' );
$phone_input = GFFormsModel::get_input( $this, $this->id . '.4' );
$css_class = '';
$visible_input_count = 0;
if ( $first_input && ! rgar( $first_input, 'isHidden' ) ) {
$visible_input_count ++;
$css_class .= 'has_first_name ';
} else {
$css_class .= 'no_first_name ';
}
if ( $last_input && ! rgar( $last_input, 'isHidden' ) ) {
$visible_input_count ++;
$css_class .= 'has_last_name ';
} else {
$css_class .= 'no_last_name ';
}
if ( $email_input && ! rgar( $email_input, 'isHidden' ) ) {
$visible_input_count ++;
$css_class .= 'has_email ';
} else {
$css_class .= 'no_email ';
}
if ( $phone_input && ! rgar( $phone_input, 'isHidden' ) ) {
$visible_input_count ++;
$css_class .= 'has_phone ';
} else {
$css_class .= 'no_phone ';
}
$css_class .= "gf_attendees_has_{$visible_input_count} ginput_container_attendees ";
return trim( $css_class );
}
public function get_form_editor_inline_script_on_page_render() {
// set the default field label for the field
$script = sprintf( "function SetDefaultValues_%s(field) {
field.label = '%s';
field.inputs = [new Input(field.id + '.1', '%s'), new Input(field.id + '.2', '%s'), new Input(field.id + '.3', '%s'), new Input(field.id + '.4', '%s')];
}", $this->type, $this->get_form_editor_field_title(), 'First Name', 'Last Name', 'Email', 'Phone' ) . PHP_EOL;
return $script;
}
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
if ( is_array( $value ) ) {
$first = trim( rgget( $this->id . '.1', $value ) );
$last = trim( rgget( $this->id . '.2', $value ) );
$email = trim( rgget( $this->id . '.3', $value ) );
$phone = trim( rgget( $this->id . '.4', $value ) );
$return = $first;
$return .= ! empty( $return ) && ! empty( $last ) ? " $last" : $last;
$return .= ! empty( $return ) && ! empty( $email ) ? " $email" : $email;
$return .= ! empty( $return ) && ! empty( $phone ) ? " $phone" : $phone;
} else {
$return = '';
}
if ( $format === 'html' ) {
$return = esc_html( $return );
}
return $return;
}
}
GF_Fields::register( new GF_Field_Attendees() );
I've been having difficulties getting the value from rgget for the fields and I had to change it to the following to get it to work:
rgget( 'input_' . $this->id . '_1', $value )

WordPress - How to fix WooCommerce breadcrumbs on shop category page?

In WooCommerce > Settings > Products, I have set "Shop Page Display" to "Show subcategories" - so that on my main shop page (http://example.com/shop/) only categories (and no individual products) are shown.
I have also used this code snippet to make the product categories show in my breadcrumbs as my theme uses WooTheme's "Simplicity" theme as its parent.
The problem I have is that the breadcrumbs are not displaying correctly. The breadcrumbs look fine on the shop home page...
You are here: Home > Products
But when I then click on a category from that page, the breadcrumbs change to...
You are here: Home > Chocolate
...when it should really be...
You are here: Home > Products > Chocolate
To confirm the issue, when I then click on a product, the breadcrumbs look fine again...
You are here: Home > Products > Chocolate > Vegan Chocolate bar
Does anyone know how I can fix the problematic breadcrumbs on the categories page?
As this seems like a bug, I have asked WooCommerce for their support, but they're not willing to fix it.
Thanks in advance.
Add this to your funtions.php file
// Breadcrumbs Display Category Name
// ====================================================================
function get_breadcrumb_category( $cat ) {
$post = get_post( $post->ID );
$post_type = $post->post_type;
$taxonomy = $cat;
$f_categories = wp_get_post_terms( $post->ID, $taxonomy );
$f_category = $f_categories[0];
if ( $f_category->parent != 0 ) {
$f_category_id = $f_category->parent;
$parent_array = get_term_by('id', $f_category_id, $taxonomy, 'ARRAY_A');
$f_category_name = $parent_array["name"];
$term_link = get_term_link( $f_category_id, $taxonomy );
} else {
$f_category_id = $f_category->term_id;
$f_category_name = $f_category->name;
$term_link = get_term_link( $f_category_id, $taxonomy );
}
if ( $f_categories && ! is_wp_error($f_categories) ) {
return '' . $f_category_name . '';
} else {
return '';
}
}
function x_breadcrumbs() {
if ( x_get_option( 'x_breadcrumb_display', '1' ) ) {
GLOBAL $post;
$is_ltr = ! is_rtl();
$stack = x_get_stack();
$delimiter = x_get_breadcrumb_delimiter();
$home_text = x_get_breadcrumb_home_text();
$home_link = home_url();
$current_before = x_get_breadcrumb_current_before();
$current_after = x_get_breadcrumb_current_after();
$page_title = get_the_title();
$blog_title = get_the_title( get_option( 'page_for_posts', true ) );
$post_parent = $post->post_parent;
if ( X_WOOCOMMERCE_IS_ACTIVE ) {
$shop_url = x_get_shop_link();
$shop_title = x_get_option( 'x_' . $stack . '_shop_title', __( 'The Shop', '__x__' ) );
$shop_link = '' . $shop_title . '';
}
echo '<div class="x-breadcrumbs">' . $home_text . '' . $delimiter;
if ( is_home() ) {
echo $current_before . $blog_title . $current_after;
} elseif ( is_category() ) {
$the_cat = get_category( get_query_var( 'cat' ), false );
if ( $the_cat->parent != 0 ) echo ''.get_the_title(102) .'';
echo $current_before . single_cat_title( '', false ) . $current_after;
} elseif ( x_is_product_category() ) {
if ( $is_ltr ) {
echo $shop_link . $delimiter . $current_before . single_cat_title( '', false ) . $current_after;
} else {
echo $current_before . single_cat_title( '', false ) . $current_after . $delimiter . $shop_link;
}
} elseif ( x_is_product_tag() ) {
if ( $is_ltr ) {
echo $shop_link . $delimiter . $current_before . single_tag_title( '', false ) . $current_after;
} else {
echo $current_before . single_tag_title( '', false ) . $current_after . $delimiter . $shop_link;
}
} elseif ( is_search() ) {
echo $current_before . __( 'Search Results for ', '__x__' ) . '“' . get_search_query() . '”' . $current_after;
} elseif ( is_singular( 'post' ) ) {
if ( get_option( 'page_for_posts' ) == is_front_page() ) {
echo $current_before . $page_title . $current_after;
} else {
if ( $is_ltr ) {
$f_category = get_the_category();
if ( $f_category[0]->parent != 0 ) {
$f_category_id = $f_category[0]->parent;
$f_category_name = get_cat_name( $f_category_id );
} else {
$f_category_id = $f_category[0]->term_id;
$f_category_name = $f_category[0]->name;
}
echo '' . $f_category_name . '' . $delimiter . $current_before . $page_title . $current_after;
} else {
echo $current_before . $page_title . $current_after . $delimiter . '' . $blog_title . '';
}
}
} elseif ( x_is_portfolio() ) {
echo $current_before . get_the_title() . $current_after;
} elseif ( x_is_portfolio_item() ) {
$link = x_get_parent_portfolio_link();
$title = x_get_parent_portfolio_title();
if ( $v = get_breadcrumb_category('portfolio-category') ) {
$portfolio_category = $delimiter . $v;
} else {
$portfolio_category = '';
}
if ( $is_ltr ) {
echo '' . $title . '' . $portfolio_category . $delimiter . $current_before . $page_title . $current_after;
} else {
echo $current_before . $page_title . $current_after . $portfolio_category . $delimiter . '' . $title . '';
}
} elseif ( x_is_product() ) {
if ( $v = get_breadcrumb_category('product_cat') ) {
$product_category = $delimiter . $v;
} else {
$product_category = '';
}
if ( $is_ltr ) {
echo $shop_link . $product_category . $delimiter . $current_before . $page_title . $current_after;
} else {
echo $current_before . $page_title . $current_after . $product_category . $delimiter . $shop_link;
}
} elseif ( x_is_buddypress() ) {
if ( bp_is_group() ) {
echo '' . x_get_option( 'x_buddypress_groups_title', __( 'Groups', '__x__' ) ) . '' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
} elseif ( bp_is_user() ) {
echo '' . x_get_option( 'x_buddypress_members_title', __( 'Members', '__x__' ) ) . '' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
} else {
echo $current_before . x_buddypress_get_the_title() . $current_after;
}
} elseif ( x_is_bbpress() ) {
remove_filter( 'bbp_no_breadcrumb', '__return_true' );
if ( bbp_is_forum_archive() ) {
echo $current_before . bbp_get_forum_archive_title() . $current_after;
} else {
echo bbp_get_breadcrumb();
}
add_filter( 'bbp_no_breadcrumb', '__return_true' );
} elseif ( is_page() && ! $post_parent ) {
echo $current_before . $page_title . $current_after;
} elseif ( is_page() && $post_parent ) {
$parent_id = $post_parent;
$breadcrumbs = array();
if ( is_rtl() ) {
echo $current_before . $page_title . $current_after . $delimiter;
}
while ( $parent_id ) {
$page = get_page( $parent_id );
$breadcrumbs[] = '' . get_the_title( $page->ID ) . '';
$parent_id = $page->post_parent;
}
if ( $is_ltr ) {
$breadcrumbs = array_reverse( $breadcrumbs );
}
for ( $i = 0; $i < count( $breadcrumbs ); $i++ ) {
echo $breadcrumbs[$i];
if ( $i != count( $breadcrumbs ) -1 ) echo $delimiter;
}
if ( $is_ltr ) {
echo $delimiter . $current_before . $page_title . $current_after;
}
} elseif ( is_tag() ) {
echo $current_before . single_tag_title( '', false ) . $current_after;
} elseif ( is_author() ) {
GLOBAL $author;
$userdata = get_userdata( $author );
echo $current_before . __( 'Posts by ', '__x__' ) . '“' . $userdata->display_name . $current_after . '”';
} elseif ( is_404() ) {
echo $current_before . __( '404 (Page Not Found)', '__x__' ) . $current_after;
} elseif ( is_archive() ) {
if ( x_is_shop() ) {
echo $current_before . $shop_title . $current_after;
} else {
echo $current_before . __( 'Archives ', '__x__' ) . $current_after;
}
}
echo '</div>';
}
}
starting from the } elseif ( x_is_product() ) { and finishing at the } elseif ( x_is_buddypress() ) {
} elseif ( x_is_product() ) {
$product_categories = wp_get_post_terms( get_the_ID(), 'product_cat' );
$parent = '';
$sub_category = '';
foreach ($product_categories as $category ) {
$term_id = $category->term_id;
$term_name = get_term( $term_id, 'product_cat' );
if ( $category->parent != 0 ) {
$sub_category .= $parent_id . '' . $term_name->name . '' . $delimiter ;
} else {
$parent .= '' . $term_name->name . '' . $delimiter ;
}
}
if ( $v = get_breadcrumb_category('product_cat') ) {
$product_category = $delimiter . $v;
} else {
$product_category = '';
}
if ( $is_ltr ) {
if(is_array($product_categories)){
echo $shop_link . $product_category . $delimiter . $sub_category . $current_before . $page_title . $current_after;
}
else {
echo $shop_link . $delimiter . $current_before . $page_title . $current_after;
}
} else {
echo $current_before . $page_title . $current_after . $delimiter . $shop_link;
}
} elseif ( x_is_buddypress() ) {

Adding pagination in WordPress Football Pool

I'm using a wordpress plugin to make a football pool. A really nice plugin but there is nog pagination in the ranking. So when you have over 1000 participants you will get a very long list.
The plugin author provided a class wich you can use to create pagination. My php knowledge is unfortunately to weak for this.
This is the pagination class:
<?php
class Football_Pool_Pagination {
public $show_total = true;
public $page_param = 'paged';
public $current_page = 1;
public $wrap = false;
private $total_pages = 0;
private $total_items = 0;
private $page_size = 20;
public function __construct( $num_items, $wrap = false ) {
$this->total_items = $num_items;
$this->total_pages = $this->calc_total_pages( $num_items, $this->page_size );
$this->current_page = $this->get_pagenum();
$this->wrap = $wrap;
}
public function get_page_size() {
return $this->page_size;
}
public function set_page_size( $size ) {
$this->page_size = $size;
$this->total_pages = $this->calc_total_pages( $this->total_items, $this->page_size );
$this->current_page = $this->get_pagenum();
}
public function show( $return = 'echo' ) {
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
if ( $this->total_pages ) {
$page_class = $this->total_pages < 2 ? ' one-page' : '';
} else {
$page_class = ' no-pages';
}
$output = '';
if ( $this->wrap ) $output .= sprintf( '<div class="tablenav top%s">', $page_class );
$output .= sprintf( '<div class="tablenav-pages%s">', $page_class );
if ( $this->show_total ) {
$output .= sprintf( '<span class="displaying-num">%s</span>'
, sprintf( _n( '1 item', '%s items', $this->total_items, FOOTBALLPOOL_TEXT_DOMAIN )
, $this->total_items
)
);
}
$disable_first = $disable_last = '';
if ( $this->current_page == 1 ) {
$disable_first = ' disabled';
}
if ( $this->current_page == $this->total_pages ) {
$disable_last = ' disabled';
}
$output .= '<span class="pagination-links">';
$output .= sprintf( '<a class="first-page%s" title="%s" href="%s">«</a>'
, $disable_first
, esc_attr__( 'Go to the first page' )
, esc_url( remove_query_arg( $this->page_param, $current_url ) )
);
$output .= sprintf( '<a class="prev-page%s" title="%s" href="%s">‹</a>'
, $disable_first
, esc_attr__( 'Go to the previous page' )
, esc_url( add_query_arg(
$this->page_param, max( 1, $this->current_page - 1 ),
$current_url ) )
);
$output .= sprintf( '<span class="paging-input"><input class="current-page" title="%s" type="text" name="%s" value="%d" size="%d"> of <span class="total-pages">%d</span></span>'
, esc_attr__( 'Current page' )
, $this->page_param
, $this->current_page
, strlen( $this->total_pages )
, $this->total_pages
);
$output .= sprintf( '<a class="next-page%s" title="%s" href="%s">›</a>'
, $disable_last
, esc_attr__( 'Go to the next page' )
, esc_url( add_query_arg(
$this->page_param, min( $this->total_pages, $this->current_page + 1 ),
$current_url ) )
);
$output .= sprintf( '<a class="last-page%s" title="%s" href="%s">»</a>'
, $disable_last
, esc_attr__( 'Go to the last page' )
, esc_url( add_query_arg( $this->page_param, $this->total_pages, $current_url ) )
);
$output .= '</span></div>';
if ( $this->wrap ) $output .= '</div>';
if ( $return == 'echo' ) {
echo $output;
} else {
return $output;
}
}
private function calc_total_pages( $num_items, $page_size ) {
return ceil( $num_items / $page_size );
}
private function get_pagenum() {
$page_num = Football_Pool_Utils::request_int( $this->page_param, 0 );
if( $page_num > $this->total_pages ) {
$page_num = $this->total_pages;
}
return max( 1, $page_num );
}
}
This is the class for ranking:
<?php
class Football_Pool_Ranking_Page {
public function page_content()
{
global $current_user;
get_currentuserinfo();
$output = '';
$pool = new Football_Pool_Pool;
// $userleague = get_the_author_meta( 'footballpool_league', $current_user->ID );
$userleague = $pool->get_league_for_user( $current_user->ID );
$userleague = ( isset( $userleague ) && is_integer( $userleague ) ) ? $userleague : FOOTBALLPOOL_LEAGUE_ALL;
$league = Football_Pool_Utils::post_string( 'league', $userleague );
$ranking_display = Football_Pool_Utils::get_fp_option( 'ranking_display', 0 );
if ( $ranking_display == 1 ) {
$ranking = Football_Pool_Utils::post_int( 'ranking', FOOTBALLPOOL_RANKING_DEFAULT );
} elseif ( $ranking_display == 2 ) {
$ranking = Football_Pool_Utils::get_fp_option( 'show_ranking', FOOTBALLPOOL_RANKING_DEFAULT );
} else {
$ranking = FOOTBALLPOOL_RANKING_DEFAULT;
}
$user_defined_rankings = $pool->get_rankings( 'user defined' );
if ( $pool->has_leagues || ( $ranking_display == 1 && count( $user_defined_rankings ) > 0 ) ) {
$output .= sprintf( '<form action="%s" method="post"><div style="margin-bottom: 1em;">'
, get_page_link()
);
if ( $pool->has_leagues ) {
$output .= sprintf( '%s: %s',
__( 'Choose league', FOOTBALLPOOL_TEXT_DOMAIN ),
$pool->league_filter( $league )
);
}
if ( $ranking_display == 1 && count( $user_defined_rankings ) > 0 ) {
$options = array();
$options[FOOTBALLPOOL_RANKING_DEFAULT] = '';
foreach( $user_defined_rankings as $user_defined_ranking ) {
$options[$user_defined_ranking['id']] = $user_defined_ranking['name'];
}
$output .= sprintf( '<br />%s: %s'
, __( 'Choose ranking', FOOTBALLPOOL_TEXT_DOMAIN )
, Football_Pool_Utils::select(
'ranking', $options, $ranking )
);
}
$output .= sprintf( '<input type="submit" name="_submit" value="%s" />'
, __( 'go', FOOTBALLPOOL_TEXT_DOMAIN )
);
$output .= '</div></form>';
}
$output .= $pool->print_pool_ranking( $league, $current_user->ID, $ranking );
return $output;
}
}
In another class I found a function that is printing the ranking:
public function print_pool_ranking( $league, $user, $ranking_id = FOOTBALLPOOL_RANKING_DEFAULT ) {
$output = '';
$rows = $this->get_pool_ranking( $league, $ranking_id );
$ranking = $users = array();
if ( count( $rows ) > 0 ) {
// there are results in the database, so get the ranking
foreach ( $rows as $row ) {
$ranking[] = $row;
$users[] = $row['user_id'];
}
} else {
// no results, show a list of users
$rows = $this->get_users( $league );
if ( count( $rows ) > 0 ) {
$output .= '<p>' . __( 'No results yet. Below is a list of all users.', FOOTBALLPOOL_TEXT_DOMAIN ) . '</p>';
foreach ( $rows as $row ) {
$ranking[] = $row;
$users[] = $row['user_id'];
}
} else {
$output .= '<p>'. __( 'No users have registered for this pool (yet).', FOOTBALLPOOL_TEXT_DOMAIN ) . '</p>';
}
}
if ( count( $ranking ) > 0 ) {
// get number of predictions per user if option is set
$show_num_predictions = ( Football_Pool_Utils::get_fp_option( 'show_num_predictions_in_ranking' ) == 1 );
if ( $show_num_predictions ) {
$predictions = $this->get_prediction_count_per_user( $users, $ranking_id );
}
$userpage = Football_Pool::get_page_link( 'user' );
$all_user_view = ( $league == FOOTBALLPOOL_LEAGUE_ALL && $this->has_leagues );
$i = 1;
$output .= '<table class="standen">';
if ( $show_num_predictions ) {
$output .= sprintf( '<tr>
<th>positie</th>
<th>%s</th>
<th>%s</th>
<th>%s</th>
%s</tr>'
, __( 'user', FOOTBALLPOOL_TEXT_DOMAIN )
, __( 'predictions', FOOTBALLPOOL_TEXT_DOMAIN )
, __( 'points', FOOTBALLPOOL_TEXT_DOMAIN )
, ( $all_user_view ? '<th></th>' : '' )
);
}
foreach ( $ranking as $row ) {
$class = ( $i % 2 != 0 ? 'even' : 'odd' );
if ( $all_user_view ) $class .= ' league-' . $row['league_id'];
if ( $row['user_id'] == $user ) $class .= ' currentuser';
if ( $show_num_predictions ) {
if ( array_key_exists( $row['user_id'], $predictions ) ) {
$num_predictions = $predictions[$row['user_id']];
} else {
$num_predictions = 0;
}
$num_predictions = sprintf( '<td>%d</td>', $num_predictions );
} else {
$num_predictions = '';
}
$output .= sprintf( '<tr class="%s"><td style="width:100px; text-align: center;">%d.</td>
<td>%s%s%s</td>
%s<td>%d</td>%s
</tr>',
$class,
$i++,
esc_url( add_query_arg( array( 'user' => $row['user_id'] ), $userpage ) ),
$this->get_avatar( $row['user_id'], 'medium' ),
$row['user_name'],
Football_Pool::user_name( $row['user_id'], 'label' ),
$num_predictions,
$row['points'],
( $all_user_view ? $this->league_image( $row['league_id'] ) : '' )
);
$output .= "\n";
}
$output .= '</table>';
}
return $output;
}
I know this is a lot of info and probably nobody can do something with this information but if somebody can help me that would be great.
I think you should work with this plugin:
it must save your time, and decrease complexity of your project.
Page Navigation
Thanks

Categories