Repository navigation
Expand file tree
/
Copy pathwp-bitly-views.php
More file actions
65 lines (50 loc) · 1.83 KB
/
Copy pathwp-bitly-views.php
File metadata and controls
65 lines (50 loc) · 1.83 KB
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
<?php
/**
* Plugin metabox functions
*/
/**
* Globalize Plugin options
*/
global $wpbitly_options;
$wpbitly_options = wpbitly_get_options();
/**
* Hook Plugin metabox into the edit
* page for each post for which shortlinks
* are enabled.
*/
foreach ( $wpbitly_options['post_types'] as $post_type ) {
add_action( 'add_meta_boxes_' . $post_type, 'wpbitly_add_metaboxes' );
}
/**
* Callback for add_meta_boxes-{posttype}
*/
function wpbitly_add_metaboxes( $post ) {
global $post;
$shortlink = wp_get_shortlink();
if ( empty( $shortlink ) )
return;
add_meta_box( 'wpbitly-meta', 'WP Bit.ly', 'wpbitly_build_metabox', $post->post_type, 'side', 'default', array( $shortlink ) );
}
/**
* Build Plugin Metabox
*/
function wpbitly_build_metabox( $post, $args )
{
global $wpbitly;
$shortlink = $args['args'][0];
echo '<label class="screen-reader-text" for="new-tag-post_tag">WP Bit.ly</label>';
echo '<p style="margin-top: 8px;"><input type="text" id="wpbitly-shortlink" name="_wpbitly" size="32" autocomplete="off" value="'.$shortlink.'" style="margin-right: 4px; color: #aaa;" /></p>';
$url = sprintf( $wpbitly->url['clicks'], $shortlink, $wpbitly->options['bitly_username'], $wpbitly->options['bitly_api_key'] );
$bitly_response = wpbitly_curl( $url );
echo '<h4 style="margin-left: 4px; margin-right: 4px; padding-bottom: 3px; border-bottom: 4px solid #eee;">Shortlink Stats</h4>';
if ( is_array( $bitly_response ) && $bitly_response['status_code'] == 200 )
{
echo "<p>Global Clicks: <strong>{$bitly_response['data']['clicks'][0]['global_clicks']}</strong><br/>";
echo "<p>User Clicks: <strong>{$bitly_response['data']['clicks'][0]['user_clicks']}</strong></p>";
}
else
{
echo '<p class="error" style="padding: 4px;">There was a problem retrieving stats!</p>';
}
}
?>