Skip to content

Commit

Permalink
convert to social shortlink function to avoid returning empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
jondavidjohn committed May 31, 2013
1 parent b1cd512 commit 43c9cd3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/social/controller/aggregation.php
Expand Up @@ -35,7 +35,7 @@ public function action_run() {
$default_urls = array(
home_url('?p='.$post->ID)
);
$url = wp_get_shortlink($post->ID);
$url = social_get_shortlink($post->ID);
if (strpos($url, '?p=') === false) {
$default_urls[] = $url;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/social/service.php
Expand Up @@ -395,7 +395,7 @@ public function format_content($post, $format) {
$content = '';
switch ($token) {
case '{url}':
$url = wp_get_shortlink($post->ID);
$url = social_get_shortlink($post->ID);
if (empty($url)) {
$url = home_url('?p='.$post->ID);
}
Expand Down Expand Up @@ -477,7 +477,7 @@ public function format_comment_content($comment, $format) {
foreach ($used_tokens as $token => $content) {
switch ($token) {
case '{url}':
$url = wp_get_shortlink($comment->comment_post_ID);
$url = social_get_shortlink($comment->comment_post_ID);
if (empty($url)) {
$url = home_url('?p='.$comment->comment_post_ID);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/social/service/facebook.php
Expand Up @@ -45,7 +45,7 @@ public function get_broadcast_extras($account_id, $post, $args = array()) {
if (get_post_format($post->ID) !== 'status') {
setup_postdata($post);
$link_args = array(
'link' => wp_get_shortlink($post->ID),
'link' => social_get_shortlink($post->ID),
'title' => get_the_title($post->ID),
'description' => get_the_excerpt(),
);
Expand Down Expand Up @@ -144,7 +144,7 @@ public function broadcast($account, $message, array $args = array(), $post_id =
$post = get_post($comment->comment_post_ID);
setup_postdata($post);
$link_args = array(
'link' => wp_get_shortlink($post->ID),
'link' => social_get_shortlink($post->ID),
'title' => get_the_title($post->ID),
'description' => get_the_excerpt(),
);
Expand Down
16 changes: 14 additions & 2 deletions social.php
Expand Up @@ -137,7 +137,7 @@ public static function broadcast_tokens() {
'posts_per_page' => 1
));
if (count($query->posts) and $post = $query->posts[0]) {
$url = wp_get_shortlink($post->ID);
$url = social_get_shortlink($post->ID);
$date = get_date_from_gmt($post->post_date_gmt);
}
else {
Expand Down Expand Up @@ -1165,7 +1165,7 @@ public function add_broadcasted_id($post_id, $service, $broadcasted_id, $message
get_permalink($post_id)
);

$shortlink = wp_get_shortlink($post_id);
$shortlink = social_get_shortlink($post_id);
if (!in_array($shortlink, $urls)) {
$urls[] = $shortlink;
}
Expand Down Expand Up @@ -2261,6 +2261,18 @@ function social_wp_mail_indicator() {
define('SOCIAL_MAIL_PUBLISH', true);
}

/**
* Social Get Shortlink
*
* This is required because wp_get_shortlink sometimes returns nothing. If no shortlink is available we want to default to the permalink.
*
* @param int Post ID
* @return string
*/
function social_get_shortlink($post_id) {
return (wp_get_shortlink($post_id)) ? wp_get_shortlink($post_id) : get_permalink($post_id);
}

$social_file = __FILE__;
if (isset($plugin)) {
$social_file = $plugin;
Expand Down

0 comments on commit 43c9cd3

Please sign in to comment.