Support » Plugin: Contextual Related Posts » Bad default behavior in crp_shortcode()

  • Resolved flynsarmy

    (@flynsarmy)


    In crp_shortcode() you’re calling

    extract( shortcode_atts( array(
    	'limit' => '5',
    	'heading' => '1',
    	'cache' => '1',
    ), $atts ) );

    which is actively ignoring and overriding the settings provided in the admin area resulting in confusing behavior. You shouldn’t be providing overrides by default – it should act the way it’s set to act in the admin unless specified otherwise.

    http://wordpress.org/plugins/contextual-related-posts/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Ajay

    (@ajay)

    Would something like this sense to do something like this:

    global $crp_settings;
    extract( shortcode_atts( array(
    	'limit' => $crp_settings['limit'],
    	'heading' => $crp_settings['heading'],
    	'cache' => $crp_settings['cache'],
    ), $atts ) );
    flynsarmy

    (@flynsarmy)

    I think

    function crp_shortcode( $atts, $content = null ) {
    	$atts = shortcode_atts( array(
    		'is_widget' => 1,
    	), $atts );
    
    	return ald_crp($atts);
    }

    is enough. Allows every setting to be overridable while letting ald_crp take care of handling defaults and overrides. I haven’t tested this but don’t see why you’d need to specify the rest.

    Plugin Author Ajay

    (@ajay)

    I’ll give it a try, but from what I see above a user could just put any attribute based on the settings and the plugin should ideally handle this (subject to testing, of course)

    flynsarmy

    (@flynsarmy)

    Hmm, then perhaps

    function crp_shortcode( $atts, $content = null ) {
    	global $crp_settings;
    	$atts = shortcode_atts(array_merge(
    		$crp_settings,
    		array('is_widget' => 1),
    	), $atts );
    
    	return ald_crp($atts);
    }

    Plugin Author Ajay

    (@ajay)

    Thanks, will give me a test run.

    Just checking in to see if there’s been any update on this? I would love it if I could simply type the [crp] shortcode and have it follow the plugin settings regarding limit etc.

    I only want 2 posts to show up every time, but have to add [crp limit=”2″] instead of simply [crp] otherwise it ignores the plugin settings and defaults to 5 every time.

    Plugin Author Ajay

    (@ajay)

    Hi, this will be in the next release of the plugin.

    For now, you can give flynsarmy’s code above by editing the plugin.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Bad default behavior in crp_shortcode()’ is closed to new replies.