• Resolved renatoornelas

    (@renatoornelas)


    Hi,

    Great plugin!

    I had a page with several items i’d like to share. I made a change to the shortcode code, so you can pass the url attribute to set the url shared, for example:

    [ngfb buttons=”facebook, linkedin, twitter” url=”http://www.uol.com.br”%5D

    --- ngfb.php.orig	2013-06-19 22:35:58.999505171 -0300
    +++ ngfb.php	2013-06-19 22:35:51.207557720 -0300
    @@ -42,6 +42,7 @@
     				'buttons' => null,
     				'css_class' => 'button',
     				'css_id' => 'shortcode',
    +				'url' => $this->ngfb->util->get_sharing_url( 'notrack', null, $use_post ),
     			), $atts ) );
    
     			global $post;
    @@ -50,19 +51,20 @@
    
     			if ( ! empty( $buttons ) ) {
     				$ids = array_map( 'trim', explode( ',', $buttons ) );	// trim white spaces during explode
    -				$cache_salt = __METHOD__ . '(post:' . $post->ID . '_buttons:' . ( implode( '_', $ids ) ) . '_css:' . $css_class . '_' . $css_id . ')';
    +				$cache_salt = __METHOD__ . '(post:' . $post->ID . '_buttons:' . ( implode( '_', $ids ) ) . '_css:' . $css_class . '_' . $css_id . '_url:' . $url . ')';
     				$cache_id = 'ngfb_' . md5( $cache_salt );
     				$cache_type = 'object cache';
     				$html = get_transient( $cache_id );
     				$this->ngfb->debug->log( $cache_type . ' : shortcode transient id salt "' . $cache_salt . '"' );
    
     				if ( $html !== false ) {
     					$this->ngfb->debug->log( $cache_type . ' : html retrieved from transient for id "' . $cache_id . '"' );
     				} else {
     					$html .= "\n<!-- " . $this->ngfb->fullname . " shortcode BEGIN -->\n";
     					$html .= $this->ngfb->social->get_js( 'pre-shortcode', $ids );
     					$html .= "<div class=\"" . $this->ngfb->acronym . "-shortcode-buttons\">\n" .
    -						$this->ngfb->social->get_html( $ids, array( 'css_class' => $css_class, 'css_id' => $css_id ) ) . "</div>\n";
    +						$this->ngfb->social->get_html( $ids, array( 'css_class' => $css_class, 'css_id' => $css_id, 'url' => $url ) ) . "</div>\n";
     					$html .= $this->ngfb->social->get_js( 'post-shortcode', $ids );
     					$html .= "<!-- " . $this->ngfb->fullname . " shortcode END -->\n";

    http://wordpress.org/extend/plugins/nextgen-facebook/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author JS Morisset

    (@jsmoriss)

    Lol! Excellent!

    I’m surprised you found your way around my code — it’s fairly clean and tight, but I don’t use many comments. 😉

    The only change I’ve made is from this:

    'url' => $this->ngfb->util->get_sharing_url( 'notrack', null, $use_post )

    to this:

    'url' => $this->ngfb->util->get_sharing_url( 'notrack', null, true )

    That last argument is to force the use the $post permalink instead of the current URL — essential if the buttons appear on each entry on an index page, and since shortcodes don’t appear anywhere outside of a post (like in a widget, for example), then it can always be true.

    Your change has been added to the next version.

    Thanks,

    js.

    Thread Starter renatoornelas

    (@renatoornelas)

    I made another change..

    I discovered that i cannot pass a shortcode as a parameter, so i had to use the $content.

    I’m using this way:

    [ngfb buttons=”facebook, linkedin, twitter”][job_url][/ngfb]

    I didn’t know the correct place, so for now I used:

    extract( shortcode_atts( array(
                                    'buttons' => null,
                                    'css_class' => 'button',
                                    'css_id' => 'shortcode',
                                    'url' => do_shortcode($content),
                            ), $atts ) );
    Thread Starter renatoornelas

    (@renatoornelas)

    Found a solution for now (if there’s content to the shortcode, it overrides the url attribute):

    if($content) $url = do_shortcode($content);

    after

    $html = '';

    Plugin Author JS Morisset

    (@jsmoriss)

    Well, I think there’s probably a more elegant way to do this…

    Download and install the latest DEV version from http://downloads.wordpress.org/plugin/nextgen-facebook.zip.

    This will give you access to a new filter called ‘ngfb_shortcode’. You should be able to use it like this:

    add_filter( 'ngfb_shortcode', 'my_ngfb_shortcode_filter', 10, 2 );
    
    function my_ngfb_shortcode_filter( $atts = array(), $content = null ) {
            /*
             * manipulate / extract content here
             */
            $atts['url'] = $content;        // use content text as sharing url
            return $atts;
    }

    FYI – Filters are a Pro version feature, but I’ve left this one in the Free version for you (until v5.4 is released).

    js.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Passing URL for shortcode’ is closed to new replies.