-
Notifications
You must be signed in to change notification settings - Fork 0
/
shortlink-toolbar.php
86 lines (76 loc) · 2.76 KB
/
shortlink-toolbar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* Plugin Name: Shortlink Toolbar
* Plugin URI: http://www.bekarice.com/plugins/
* Description: Adds a menu to the admin toolbar to get the shortlink for a post or share the shortlink via Twitter, Buffer.
* Author: Beka Rice
* Author URI: http://www.bekarice.com/
* Version: 1.1.1
* Text Domain: shortlink-toolbar
*
* Copyright: (c) 2015 Yoast and 2015-2017 Beka Rice
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* This plugin is a derivative work of the Bit.ly Shortlinks plugin
* Credit: Joost de Valk
* http://yoast.com/wordpress/bitly-shortlinks/
*
* @package Shortlink-Toolbar
* @author Beka Rice
* @category Admin
* @copyright Copyright (c) 2015 Yoast, 2015-2017 Beka Rice
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
*
*/
defined( 'ABSPATH' ) or exit;
/**
* Plugin Description
*
* Adds a menu to the admin toolbar to get the shortlink for a post;
* if wp.me shortlinks are enabled via Jetpack, this will be used instead
*
*/
function shortlink_toolbar_menu() {
global $wp_admin_bar, $post;
if ( ! isset( $post->ID ) ) {
return;
}
$short_url = esc_url( wp_get_shortlink( $post->ID, 'query' ) );
$post_title = str_replace( '+', '%20', urlencode( $post->post_title ) );
$twitter_link = "https://twitter.com/intent/tweet?text={$post_title}%20{$short_url}&source=webclient";
$buffer_link = "https://buffer.com/add?url={$short_url}&source=admin&text={$post_title}";
// covers posts, pages, custom post types
if ( is_singular() ) {
$shortlink_prompt = esc_html__( "Here's your short link!", 'shortlink-toolbar' );
$wp_admin_bar->add_node( array(
'id' => 'shortlink',
'title' => __( 'Shortlinks', 'shortlink-toolbar' ),
'href' => '#',
'meta' => array( 'onclick' => 'javascript:prompt("' . $shortlink_prompt . '", "' . $short_url . '");' ),
) );
$wp_admin_bar->add_node( array(
'parent' => 'shortlink',
'id' => 'shortlink_shortened-link',
'title' => __( 'Get Shortlink', 'shortlink-toolbar' ),
'href' => '#',
'meta' => array( 'onclick' => 'javascript:prompt("' . $shortlink_prompt . '", "' . $short_url . '");' ),
) );
$wp_admin_bar->add_node( array(
'parent' => 'shortlink',
'id' => 'shortlink_twitterlink',
'title' => __( 'Share on Twitter', 'shortlink-toolbar' ),
'href' => esc_url( $twitter_link ),
'meta' => array( 'target' => '_blank' ),
) );
$wp_admin_bar->add_node( array(
'parent' => 'shortlink',
'id' => 'shortlink_bufferlink',
'title' => __( 'Share via Buffer', 'shortlink-toolbar' ),
'href' => esc_url( $buffer_link ),
'meta' => array( 'target' => '_blank' ),
) );
}
}
add_action( 'admin_bar_menu', 'shortlink_toolbar_menu', 95 );