• Resolved Kris Nelson

    (@webnelly)


    I have a page that uses a custom URL via the rewrite rules, and what I noticed was that the Jetpack Sharing code was using the URL for my page (returned from get_permalink) and not the rewritten URL I was expecting.

    I found the hooks for sharing_permalink, but it appears that it’s not being implemented consistently in the latest Jetpack release.

    Specifically, I’m looking at code like this in:
    jetpack/modules/sharedaddy/sharing-sources.php

    if ( $this->smart == 'smart' )
    			return '<div class="twitter_button"><iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html?url=' . rawurlencode( apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ) ) . '&counturl=' . rawurlencode( str_replace( 'https://', 'http://', get_permalink( $post->ID ) ) ) . '&count=horizontal&text=' . rawurlencode( apply_filters( 'sharing_post_title', $post->post_title, $post->ID, $this->id ) ) . ': " style="width:97px; height:20px;"></iframe></div>';
    		else
    			return $this->get_link( get_permalink( $post->ID ), _x( 'Twitter', 'share to', 'jetpack' ), __( 'Click to share on Twitter', 'jetpack' ), 'share=twitter' );

    In the first case above, you see that apply_filters( ‘sharing_permalink’, …) is called for the “url” query string variable for tweet_button.html, but not for the “counturl” query string variable in the same URL. That means for my case, the counturl address is different than what’s being shared, so my counts will always show as zero.

    In the second case (where $this->smart != ‘smart’) the get_link() function is called in the else statement using get_permalink() directly and not using the filter at all.

    It’s worse in the Facebook portion of that same code file, too:

    public function get_display( $post ) {
    		if ( $this->share_type == 'share' ) {
    			return '<div class="facebook_button"><a name="fb_share" rel="nofollow" type="button" share_url="' . apply_filters( 'sharing_permalink', get_permalink( $post->ID ), $post->ID, $this->id ) . '" href="http://www.facebook.com/sharer.php?u=' . rawurlencode( get_permalink( $post->ID ) ) . '&t=' . rawurlencode( apply_filters( 'sharing_post_title', $post->post_title, $post->ID, $this->id ) ) . '">'.__( 'Share' , 'jetpack' ).'</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script></div>';
    		} else if ( $this->share_type == 'like' ) {
    			$url = 'http://www.facebook.com/plugins/like.php?href=' . rawurlencode( get_permalink( $post->ID ) ) . '&layout=button_count&show_faces=false&action=like&colorscheme=light&height=21';

    You’ll see here that if the share type is ‘share’, the code uses the sharing_permalink filter, but if the share type is ‘like’, it uses the get_permalink() function instead.

    I’m making changes to the version installed in my hosted instance of WordPress to work for me, but if this isn’t fixed in future versions of Jetpack, I’ll have to keep re-applying it each time.

    Thanks,
    – Kris

    http://wordpress.org/extend/plugins/jetpack/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Tim Moore

    (@tmoorewp)

    Thanks for the report. We’ll take a look and get this fixed.

    Plugin Contributor Michael Adams (mdawaffe)

    (@mdawaffe)

    We’re fixing the inconsistencies now; thanks for bringing them to our attention.

    A few notes, though.

    1. get_permalink() should always return the canonical URL of your page. If you have some custom setup, you should make sure get_permalink() reflects that.
    2. Jetpack’s ::get_link( $url, ... ) really should be using get_permalink(). Those links take the visitor to a page hosted on your site (and generated by Jetpack), which then redirects to the correct sharing service. That redirection is typically handled in ::process_request(). So it’s the code in ::process_request() that should be using the sharing_permalink filter, not the code in ::get_link() (usually).
    3. Twitter defines the “counturl” as the URL the shared URL resolves to. That is, if you share a shortlink (bit.ly, for example), you would pass the canonical URL as the counturl. As I mentioned above, the canonical URL is the result of get_permalink(), so the counturl code is correct.

    So our fix may not be exactly what you’re looking for 🙂 It sounds like you’ll still have to write a baby plugin for your site that fixes the results of get_permalink() for your page.

    Plugin Contributor Michael Adams (mdawaffe)

    (@mdawaffe)

    This has been fixed in the in-development version of Jetpack: http://plugins.trac.wordpress.org/changeset/587002

    I’m not sure when the next bug fix release will be, but my guess is sometime next week.

    Hello. Are there a simple way to force sharing/liking buttons to work properly on gallery image pages with filters like these:

    http://wordpress.org/support/topic/plugin-jetpack-by-wordpresscom-sharing-url-filter-broken?replies=3

    ?

    Michael Adams,

    Do you or any of your devs have any idea how we can modify the results of get_permalink? I havent found a way and I have the same need to modify what url that jetpack sharing uses. Why does it even use get_permalink? Shouldnt it rather respect the url of the article its on?

    nevermind, looks like it can be fixed with: add_filter(‘pre_post_link’,’fix_campus’);

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Jetpack by WordPress.com] Support for sharing_permalink filter inconsistent’ is closed to new replies.