Skip to content

Commit

Permalink
Sharing: Change WhatsApp URL for Firefox for desktop (Automattic#12269)
Browse files Browse the repository at this point in the history
* Add is_firefox_desktop function to Jetpack_User_Agent_Info

* Sharing: Change WhatsApp URL for Firefox for desktop
  • Loading branch information
kbrown9 authored and jeherve committed May 10, 2019
1 parent ae32198 commit 3699f34
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
22 changes: 22 additions & 0 deletions class.jetpack-user-agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,28 @@ static function is_firefox_mobile( ) {
return false;
}

/*
* Detects if the current browser is Firefox for desktop
*
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox
* Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion
* The platform section will include 'Mobile' for phones and 'Tablet' for tablets.
*
*/
static function is_firefox_desktop() {

if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
return false;
}

$ua = strtolower( $_SERVER['HTTP_USER_AGENT'] );

if ( false !== strpos( $ua, 'firefox' ) && false === strpos( $ua, 'mobile' ) && false === strpos( $ua, 'tablet' ) ) {
return true;
} else {
return false;
}
}

/*
* Detects if the current browser is FirefoxOS Native browser
Expand Down
10 changes: 9 additions & 1 deletion modules/sharedaddy/sharing-sources.php
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,15 @@ public function get_display( $post ) {
public function process_request( $post, array $post_data ) {
// Record stats
parent::process_request( $post, $post_data );
$url = 'https://api.whatsapp.com/send?text=' . rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) );

// Firefox for desktop doesn't handle the "api.whatsapp.com" URL properly, so use "web.whatsapp.com"
if ( Jetpack_User_Agent_Info::is_firefox_desktop() ) {
$url = 'https://web.whatsapp.com/send?text=';
} else {
$url = 'https://api.whatsapp.com/send?text=';
}

$url .= rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) );
wp_redirect( $url );
exit;
}
Expand Down

0 comments on commit 3699f34

Please sign in to comment.