Aggregate img url function not functional with one blog built with blogger - php

I am trying to aggregate the latest posts by several blogs using their rss feed. The code below is working fine for most platforms including blogg.se . Although it is strangely not working with a blog from blogg.se called, http://sofiasinredning.blogg.se/index.rss .
function wpse_187819_get_feed_html( $url, $bloggauthor ) {
if ( !is_admin() ) {
if ( is_wp_error( $rss = fetch_feed( $url ) ) )
return;
$maxitems = $rss->get_item_quantity( 1 );
$rss_items = $rss->get_items( 0, $maxitems );
$html = '<ul class="rss-items rss-old" id="wows-feeds">';
if (!empty($bloggauthor)) {
$authorcredit = '<span class="field-label">' . $bloggauthor . '</span>';
} else { $authorcredit = '<span class="field-label"> Name </span>';}
if ( $maxitems ) {
foreach ( $rss_items as $item ) {
$title = esc_attr( $item->get_title() );
$link = esc_url( $item->get_permalink() );
$stringses = $item-> get_description();
global $wp_query;
$lengthses = '';
if ( $wp_query->is_page ) {
$lengthses = '100';
} elseif ( $wp_query->is_home ) {
$lengthses = '100';
} elseif ( $wp_query->is_single ) {
$lengthses = '700';
} elseif ( $wp_query->is_category ) {
$lengthses = '100';
} elseif ( $wp_query->is_tag ) {
$lengthses = '50';
} elseif ( $wp_query->is_tax ) {
$lengthses = '30';
} elseif ( $wp_query->is_archive ) {
if ( $wp_query->is_day ) {
$lengthses = '60';
} elseif ( $wp_query->is_month ) {
$lengthses = '60';
} elseif ( $wp_query->is_year ) {
$lengthses = '60';
} elseif ( $wp_query->is_author ) {
$lengthses = '400';
} else {
$lengthses = '500';
}
} elseif ( $wp_query->is_search ) {
$lengthses = '400';
} elseif ( $wp_query->is_404 ) {
$lengthses = '';
}
$date = $item->get_date('F Y');
$suffix = '…';
$short_desc = trim(str_replace(array(" ", "/r", "/n", "/t"), '', strip_tags($stringses)));
$desc = trim(substr($short_desc, 0, $lengthses));
$lastchar = substr($desc, 0, 1);
if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
$desc .= $suffix;
$html .= '<li class="item"><a target="_blanc" href="' . $link . '" title="' . $title . '">';
if ( preg_match( '/<img.+?src="(.+?)"/', $item->get_content(), $matches ) ) {
$html .= '<span class="rss-image"><div class="square attachment-special" style="background-image: url(' . $matches[1] . ');"><img style="opacity: 0;" class="attachment-special" src="' . $matches[1] . '"/></div></span></a>';
}
elseif ($enclosure = $item->get_enclosure()) {
$html .= '<span class="rss-image"><div class="square attachment-special" style="background-image: url(' . $enclosure->get_link() . ');"><img style="opacity: 0;" class="attachment-special" src="' . $enclosure->get_link() . '"/></div></span></a>';
}
else {
$html .= '<img class="attachment-special" src="' . get_stylesheet_directory_uri() . '/img/logga/500x500.png"/></a>';
}
$html .= '<div class="item-content"><h5 class="pink-text">' . $authorcredit . '</h5><a target="_blanc" href="' . $link . '" title="' . $title . '"><span class="data"><h1 class="entry-title">' . $title . '</h1></span></a>';
$html .= '<p>' . $desc . '</p>';
$html .= '</li>';
}
} else {
$html .= '<li>No items</li>';
}
$html .= '</ul>';
echo $html;
}
}
Thanks in advance

Related

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;
}

How can I have this custom shortcode display within the page content (Divi Builder)?

I am using the Divi Theme.
The shortcode is working, however it is displaying directly under the header rather than where I place the shortcode within the Divi Builder.
I read more about WP shortcodes and it looked like we should be using return rather than echo, but when I change it to return it does not display at all on the page.
Thanks!
function breadcrumb() {
$delimiter = '»'; // delimiter between crumbs
$home = 'Home'; // text for the 'Home' link
$showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
$before = '<span class="current">'; // tag before the current crumb
$after = '</span>'; // tag after the current crumb
global $post;
$homeLink = get_bloginfo('url');
echo '<div id="crumbs">' . $home . ' ' . $delimiter . ' ';
if (is_single() && !is_attachment()) {
if (get_post_type() != 'post') {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
return '' . $post_type->labels->singular_name . '';
if ($showCurrent == 1) {
return ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
} else {
$cat = get_the_category();
$cat = $cat[0];
$cats = get_category_parents($cat, true, ' ' . $delimiter . ' ');
if ($showCurrent == 0) {
$cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
}
echo $cats;
if ($showCurrent == 1) {
echo $before . get_the_title() . $after;
}
}
} elseif (!is_single() && !is_page() && get_post_type() != 'post' && !is_404()) {
$post_type = get_post_type_object(get_post_type());
return $before . $post_type->labels->singular_name . $after;
} elseif (is_attachment()) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID);
$cat = $cat[0];
return get_category_parents($cat, true, ' ' . $delimiter . ' ');
echo '' . $parent->post_title . '';
if ($showCurrent == 1) {
echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
} elseif (is_page() && !$post->post_parent) {
if ($showCurrent == 1) {
return $before . get_the_title() . $after;
}
} elseif (is_page() && $post->post_parent) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '' . get_the_title($page->ID) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
for ($i = 0; $i < count($breadcrumbs); $i++) {
return $breadcrumbs[$i];
if ($i != count($breadcrumbs)-1) {
return ' ' . $delimiter . ' ';
}
}
if ($showCurrent == 1) {
return ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
}
return '</div>';
}
function breadcrumb() {
$delimiter = '»'; // delimiter between crumbs
$home = 'Home'; // text for the 'Home' link
$showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
$before = '<span class="current">'; // tag before the current crumb
$after = '</span>'; // tag after the current crumb
global $post;
$homeLink = get_bloginfo('url');
$bredcrumb = '<div id="crumbs">' . $home . ' ' . $delimiter . ' ';
if (is_single() && !is_attachment()) {
if (get_post_type() != 'post') {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
$bredcrumb .='' . $post_type->labels->singular_name . '';
if ($showCurrent == 1) {
$bredcrumb .=' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
} else {
$cat = get_the_category();
$cat = $cat[0];
$cats = get_category_parents($cat, true, ' ' . $delimiter . ' ');
if ($showCurrent == 0) {
$cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
}
$bredcrumb .= $cats;
if ($showCurrent == 1) {
$bredcrumb .= $before . get_the_title() . $after;
}
}
} elseif (!is_single() && !is_page() && get_post_type() != 'post' && !is_404()) {
$post_type = get_post_type_object(get_post_type());
$bredcrumb .= $before . $post_type->labels->singular_name . $after;
} elseif (is_attachment()) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID);
$cat = $cat[0];
$bredcrumb .= get_category_parents($cat, true, ' ' . $delimiter . ' ');
$bredcrumb .= '' . $parent->post_title . '';
if ($showCurrent == 1) {
$bredcrumb .= ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
} elseif (is_page() && !$post->post_parent) {
if ($showCurrent == 1) {
$bredcrumb .= $before . get_the_title() . $after;
}
} elseif (is_page() && $post->post_parent) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '' . get_the_title($page->ID) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
for ($i = 0; $i < count($breadcrumbs); $i++) {
$bredcrumb .= $breadcrumbs[$i];
if ($i != count($breadcrumbs)-1) {
$bredcrumb .= ' ' . $delimiter . ' ';
}
}
if ($showCurrent == 1) {
$bredcrumb .= ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
}
$bredcrumb .= '</div>';
echo $bredcrumb;
return $bredcrumb;

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() ) {

using an image for a button on php

I have a php script which creates its own button, as I am using an open source framework. What I want is to use an image to create a button instead of a the link the is created. Here is the line for which I need the button:
<td class="main button_marg"><?php echo tep_draw_button(IMAGE_BUTTON_REVIEWS . (($reviews['count'] > 0) ? ' (' . $reviews['count'] . ')' : ''), 'comment', tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params())); ?></td>
That is the script I am using to create the review button, but I would like to insert an image into it. Any ideas would be most appreciative.
This is the code for tep_draw_button() function:
function tep_draw_button($title = null, $icon = null, $link = null, $priority = null, $params = null) {
static $button_counter = 1;
$types = array('submit', 'button', 'reset');
if ( !isset($params['type']) ) {
$params['type'] = 'submit';
}
if ( !in_array($params['type'], $types) ) {
$params['type'] = 'submit';
}
if ( ($params['type'] == 'submit') && isset($link) ) {
$params['type'] = 'button';
}
if (!isset($priority)) {
$priority = 'secondary';
}
$button = '<span class="tdbLink">';
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '<a id="tdb' . $button_counter . '" href="' . $link . '"';
if ( isset($params['newwindow']) ) {
$button .= ' target="_blank"';
}
} else {
$button .= '<button id="tdb' . $button_counter . '" type="' . tep_output_string($params['type']) . '"';
}
if ( isset($params['params']) ) {
$button .= ' ' . $params['params'];
}
$button .= '>' . $title;
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '</a>';
} else {
$button .= '</button>';
}
$button .= '</span><script type="text/javascript">$("#tdb' . $button_counter . '").button(';
$args = array();
if ( isset($icon) ) {
if ( !isset($params['iconpos']) ) {
$params['iconpos'] = 'left';
}
if ( $params['iconpos'] == 'left' ) {
$args[] = 'icons:{primary:"ui-icon-' . $icon . '"}';
} else {
$args[] = 'icons:{secondary:"ui-icon-' . $icon . '"}';
}
}
if (empty($title)) {
$args[] = 'text:false';
}
if (!empty($args)) {
$button .= '{' . implode(',', $args) . '}';
}
$button .= ').addClass("ui-priority-' . $priority . '").parent().removeClass("tdbLink");</script>';
$button_counter++;
return $button;
}
?>
You can probably override the style by using some css:
#your_button_id{ background: url(); height: x; width: x; etc... }
.your_button_class{ background: url(); height: x; width: x; etc... }
Try this:
To call the button, use the function with the parameters as they are below:
$image['src'] = 'http://yoururl.com/image.jpg'; // Image Source
$image['height'] = 600; // Image Height
$image['width'] = 300; // Image Width
tep_draw_button(IMAGE_BUTTON_REVIEWS . (($reviews['count'] > 0) ? ' (' . $reviews['count'] . ')' : ''), 'comment', tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params()), null, null, $image);
Then modify the tep_draw_button function like so. If you have an image source in the function parameter, the image will be placed in as a link rather than as a button.
<?
function tep_draw_button($title = null, $icon = null, $link = null, $priority = null, $params = null, $image = null) {
static $button_counter = 1;
if($image != null){
$button = '<span class="tdbLink">';
$button .= '<a id="tdb' . $button_counter . '" href="' . $link . '"';
$button .= '><img src="'. $image['src'] .'"';
if(is_numeric($image['height'])) $button .= ' height="'.$image['height'].'"';
if(is_numeric($image['width'])) $button .= ' width="'.$image['width'].'"';
$button .= 'alt="'.$title.'" /></a></span>';
}else{
$types = array('submit', 'button', 'reset');
if ( !isset($params['type']) ) {
$params['type'] = 'submit';
}
if ( !in_array($params['type'], $types) ) {
$params['type'] = 'submit';
}
if ( ($params['type'] == 'submit') && isset($link) ) {
$params['type'] = 'button';
}
if (!isset($priority)) {
$priority = 'secondary';
}
$button = '<span class="tdbLink">';
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '<a id="tdb' . $button_counter . '" href="' . $link . '"';
if ( isset($params['newwindow']) ) {
$button .= ' target="_blank"';
}
} else {
$button .= '<button id="tdb' . $button_counter . '" type="' . tep_output_string($params['type']) . '"';
}
if ( isset($params['params']) ) {
$button .= ' ' . $params['params'];
}
$button .= '>' . $title;
if ( ($params['type'] == 'button') && isset($link) ) {
$button .= '</a>';
} else {
$button .= '</button>';
}
$button .= '</span><script type="text/javascript">$("#tdb' . $button_counter . '").button(';
$args = array();
if ( isset($icon) ) {
if ( !isset($params['iconpos']) ) {
$params['iconpos'] = 'left';
}
if ( $params['iconpos'] == 'left' ) {
$args[] = 'icons:{primary:"ui-icon-' . $icon . '"}';
} else {
$args[] = 'icons:{secondary:"ui-icon-' . $icon . '"}';
}
}
if (empty($title)) {
$args[] = 'text:false';
}
if (!empty($args)) {
$button .= '{' . implode(',', $args) . '}';
}
$button .= ').addClass("ui-priority-' . $priority . '").parent().removeClass("tdbLink");</script>';
$button_counter++;
}
return $button;
}
?>
Let me know if this works, or if you need it tweaked at all. It's hard for me to test since I don't have an oscommerce instance on my machine to test on.

Categories