-
-
Save billerickson/5f203fe921439008df08be6b7224f5c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Production URL | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/code/use-production-url-in-shared-counts/ | |
* | |
* @param string $url (optional), URL to convert to production. | |
* @return string $url, converted to production. Uses home_url() if no url provided | |
* | |
*/ | |
function ea_production_url( $url = false ) { | |
$url = $url ? esc_url( $url ) : home_url(); | |
// Make it protocol-agnostic, for preserving http requests | |
$home = str_replace( array( 'http://', 'https://' ), '://', home_url() ); | |
$production = '://www.billerickson.net'; | |
$url = str_replace( $home, $production, $url ); | |
return esc_url( $url ); | |
} | |
/** | |
* Use Production URL for Share Count API | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/code/use-production-url-in-shared-counts/ | |
* | |
* @param array $params, API parameters used when fetching share counts | |
* @return array | |
*/ | |
function ea_production_url_share_count_api( $params ) { | |
$params['url'] = ea_production_url( $params['url'] ); | |
return $params; | |
} | |
add_filter( 'shared_counts_api_params', 'ea_production_url_share_count_api' ); | |
/** | |
* Use Production URL for Share Count link | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/code/use-production-url-in-shared-counts/ | |
* | |
* @param array $link, elements of the link | |
* @return array | |
*/ | |
function ea_production_url_share_count_link( $link ) { | |
$exclude = array( 'print', 'email' ); | |
if( ! in_array( $link['type'], $exclude ) ) | |
$link['link'] = ea_production_url( $link['link'] ); | |
return $link; | |
} | |
add_filter( 'shared_counts_link', 'ea_production_url_share_count_link' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment