• Resolved lflier

    (@lflier)


    Found a bug in the shortcode — the show_author=0 and show_source=0 attributes don’t work. The shortcode displays the author and source regardless.

    The problem is with the inconsistent use of variable names in the code: one function uses “$author” and “$source” and another function uses “$show_author” and “$show_source.”

    Here’s how to fix it…

    1. Open the quotes-collection-shortcodes.php file in a text editor.
    2. In lines 21-22 and 43-46 change every instance of “$author” to “$show_author” and every instance of “$source” to “$show_source”. There should be three instances of each.

    When you’re done, it should look like this:

    function quotescollection_shortcodes($atts = array())
    {
    	extract( shortcode_atts( array(
    		'limit' => 0,
    		'id' => 0,
    		'show_author' => '',
    		'show_source' => '',
    		'tags' => '',
    		'orderby' => 'quote_id',
    		'order' => 'ASC',
    		'paging' => false,
    		'limit_per_page' => 10
    	), $atts ) );
    
    	$condition = " WHERE public = 'yes'";
    
    	if(isset($quote_id) && is_numeric($quote_id)) $id = $quote_id;
    
    	if($id && is_numeric($id)) {
    		$condition .= " AND quote_id = ".$id;
    
    		if ($quote = quotescollection_get_quotes($condition))
    			return quotescollection_shortcode_output_format($quote);
    		else
    			return "";
    	}
    
    	if($show_author)
    		$condition .= " AND author = '".$show_author."'";
    	if($show_source)
    		$condition .= " AND source = '".$show_source."'";

    After that, it should work as expected.

    https://wordpress.org/plugins/quotes-collection/

Viewing 1 replies (of 1 total)
  • Thread Starter lflier

    (@lflier)

    Sorry, disregard the above. I know just enough PHP to be dangerous. Hiding the author is not a feature of the shortcode; it is only supported for the template function. Do not do what I just suggested; it will cause the “author” and “source” attributes to fail.

    But here is some code that is working for me. It adds three new attributes to the shortcode function of the plugin: “show_author”, “show_source”, and “show_blockquote”. Set them to “1” for on and “0” for off. For example the shortcode “[quotcoll orderby=”random” tags=”tagline” limit=1 show_author=0 show_source=0 show_blockquote=0]” displays a single random quote with the tag “tagline” and does not show the author, source, or blockquote HTML tag.

    To make this work, replace the first two functions in quotes-collection-shortcodes.php as follows:

    function quotescollection_shortcode_output_format($quotes, $options)
    {
    	$display = "";
    
    	foreach($quotes as $quote_data) {
    
    		//* Show blockquote
    		if($options['show_blockquote'])
    			$display .= "<blockquote class=\"quotescollection\" id=\"quote-".$quote_data['quote_id']."\">";
    
    		$quote_data = quotescollection_txtfmt($quote_data);
    		$display .= "<p><q>".$quote_data['quote']."</q>";
    
    		//* Show author and source
    		$cite = "";
    
    		if($options['show_author'] && $quote_data['author'])
    			$cite = '<span class="quotescollection_author">'. $quote_data['author'] .'</span>';
    
    		if($options['show_source'] && $quote_data['source']) {
    			if($cite) $cite .= ", ";
    			$cite .= '<span class="quotescollection_source">'. $quote_data['source'] .'</span>';
    		}
    
    		if($cite) $cite = " <cite>— {$cite}</cite>";
    
    			$display .= $cite."</p>";
    
    		if($options['show_blockquote'])
    			$display .= "</blockquote>\n";
    
    	}
    
    	return apply_filters( 'quotescollection_shortcode_output_format', $display );
    }
    
    function quotescollection_shortcodes($atts = array())
    {
    	extract( shortcode_atts( array(
    		'limit' => 0,
    		'id' => 0,
    		'author' => '',
    		'source' => '',
    		'tags' => '',
    		'orderby' => 'quote_id',
    		'order' => 'ASC',
    		'paging' => false,
    		'limit_per_page' => 10,
    		'show_author' => 1,
    		'show_source' => 1,
    		'show_blockquote' => 1
    
    	), $atts ) );
    
    	//* Show author, source, and blockquote
    	$options = array(
    		'show_author' => $show_author,
    		'show_source' => $show_source,
    		'show_blockquote' => $show_blockquote
    		);
    
    	$condition = " WHERE public = 'yes'";
    
    	if(isset($quote_id) && is_numeric($quote_id)) $id = $quote_id;
    
    	if($id && is_numeric($id)) {
    		$condition .= " AND quote_id = ".$id;
    
    		if ($quote = quotescollection_get_quotes($condition))
    			return quotescollection_shortcode_output_format($quote);
    		else
    			return "";
    	}
    
    	if($author)
    		$condition .= " AND author = '".$author."'";
    	if($source)
    		$condition .= " AND source = '".$source."'";
    	if ($tags) {
    		$tags = html_entity_decode($tags);
    		if(!$tags)
    			break;
    		$taglist = explode(',', $tags);
    		$tags_condition = "";
    		foreach($taglist as $tag) {
    			$tag = trim($tag);
    			if($tags_condition) $tags_condition .= " OR ";
    			$tags_condition .= "tags = '{$tag}' OR tags LIKE '{$tag},%' OR tags LIKE '%,{$tag},%' OR tags LIKE '%,{$tag}'";
    		}
    		if($tags_condition) $condition .= " AND ".$tags_condition;
    	}
    
    	if($orderby == 'id' || !$orderby) $orderby = 'quote_id';
    	else if ($orderby == 'date_added') $orderby = 'time_added';
    	else if($orderby == 'random' || $orderby == 'rand') {
    		$orderby = 'RAND(UNIX_TIMESTAMP(NOW()))';
    		$order = '';
    		$paging = false;
    	};
    	$order = strtoupper($order);
    	if($order && $order != 'DESC')
    		$order = 'ASC';
    
    	$condition .= " ORDER BY {$orderby} {$order}";
    
    	if($paging == true || $paging == 1) {
    
    		$num_quotes = quotescollection_count($condition);
    
    		$total_pages = ceil($num_quotes / $limit_per_page);
    
    		if(!isset($_GET['quotes_page']) || !$_GET['quotes_page'] || !is_numeric($_GET['quotes_page']))
    			$page = 1;
    		else
    			$page = $_GET['quotes_page'];
    
    		if($page > $total_pages) $page = $total_pages;
    
    		if($page_nav = quotescollection_pagenav($total_pages, $page, 0, 'quotes_page'))
    			$page_nav = '<div class="quotescollection_pagenav">'.$page_nav.'</div>';
    
    		$start = ($page - 1) * $limit_per_page;
    
    		$condition .= " LIMIT {$start}, {$limit_per_page}"; 
    
    //		return $condition;
    
    		if($quotes = quotescollection_get_quotes($condition))
    			return $page_nav.quotescollection_shortcode_output_format($quotes, $options).$page_nav;
    		else
    			return "";
    
    	}
    
    	else if($limit && is_numeric($limit))
    		$condition .= " LIMIT ".$limit;
    
    //	return $condition;
    
    	if($quotes = quotescollection_get_quotes($condition))
    		return quotescollection_shortcode_output_format($quotes, $options);
    	else
    		return "";
    }

    That should do the trick.

Viewing 1 replies (of 1 total)
  • The topic ‘Bug in shortcode attributes "show_author" and "show_source"’ is closed to new replies.