Skip to content

Commit c4be03a

Browse files
committed
Meta Box added in Post Edit Page, now you can share link from your post page
1 parent cc78177 commit c4be03a

9 files changed

+156
-19
lines changed

assets/css/wbitly.css

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
.wbitly-mt-5{
2+
margin-top: 25px;
3+
}
4+
.wbitly-meta-bg-link{
5+
background: #eee;
6+
padding: 5px 20px;
7+
}
18
th.manage-column.column-wbitly_url {
29
text-align: center;
310
}

codehaveli-bitly-url-shortener.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
/*
44
Plugin Name: Codehaveli Bitly URL Shortener
55
Plugin URI: https://github.com/codehaveli/
6-
Description: This Plugin is used for shorten the newly published post url, Plugin use the api functionality of https://bitly.com/ to achive this URL shorten process.
7-
Version: 1.1.3
6+
Description: Codehaveli Bitly URL Shortener uses the functionality of Bitly API to generate Bitly short link without leaving your WordPress site.
7+
Version: 1.1.4
88
Author: Codehaveli
99
Author URI: https://www.codehaveli.com/
1010
License: GPLv2 or later
1111
Text Domain: wbitly
1212
*/
1313

14-
14+
if ( ! defined( 'ABSPATH' ) ) {
15+
exit; // Exit if accessed directly.
16+
}
1517

1618

1719
define( 'WBITLY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
1820
define( 'WBITLY_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
19-
define( 'WBITLY_PLUGIN_VERSION', '1.1.3' );
21+
define( 'WBITLY_PLUGIN_VERSION', '1.1.4' );
2022
define( 'WBITLY_API_URL', 'https://api-ssl.bitly.com' );
2123
define( 'WBITLY_BASENAME', plugin_basename( __FILE__ ) );
2224
define( 'WBITLY_SETTINGS_URL', admin_url( 'tools.php?page=wbitly' ) );
@@ -61,4 +63,7 @@
6163

6264
require_once 'inc/wbitly-wp-functions.php';
6365

64-
66+
/**
67+
* Meta Box
68+
*/
69+
require_once 'inc/wbitly-metabox.php';

inc/wbitly-assets.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
* @Last Modified by: Codehaveli
77
* @Website: www.codehaveli.com
88
* @Email: hello@codehaveli.com
9-
* @Last Modified time: 2020-06-29 19:57:26
9+
* @Last Modified time: 2020-11-22 23:16:02
1010
*/
1111

1212

13+
if ( ! defined( 'ABSPATH' ) ) {
14+
exit; // Exit if accessed directly.
15+
}
16+
17+
1318
function wbitly_load_admin_script() {
14-
wp_enqueue_script( 'wbitly-js', WBITLY_PLUGIN_URL . '/assets/js/wbitly.js', array( 'jquery' ), WBITLY_PLUGIN_VERSION , true );
15-
wp_enqueue_style( 'wbitly-css', WBITLY_PLUGIN_URL . '/assets/css/wbitly.css',[], WBITLY_PLUGIN_VERSION , 'all' );
19+
wp_enqueue_script( 'wbitly-js', WBITLY_PLUGIN_URL . 'assets/js/wbitly.js', array( 'jquery' ), WBITLY_PLUGIN_VERSION , true );
20+
wp_enqueue_style( 'wbitly-css', WBITLY_PLUGIN_URL . 'assets/css/wbitly.css',[], WBITLY_PLUGIN_VERSION , 'all' );
1621
wp_localize_script( 'wbitly-js', 'wbitlyJS' , ['ajaxurl' => admin_url( 'admin-ajax.php' )]);
1722

1823

inc/wbitly-integration.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
* @Last Modified by: Codehaveli
77
* @Website: www.codehaveli.com
88
* @Email: hello@codehaveli.com
9-
* @Last Modified time: 2020-09-27 19:25:49
9+
* @Last Modified time: 2020-11-22 21:26:53
1010
*/
1111

12+
if ( ! defined( 'ABSPATH' ) ) {
13+
exit; // Exit if accessed directly.
14+
}
1215

1316
/**
1417
* Generate short URL from permalink
@@ -138,9 +141,7 @@ function wbitly_shorten_url ($permalink) {
138141
if(!$access_token || !$guid){
139142

140143
$plugin_url = admin_url( 'tools.php?page=wbitly');
141-
echo ' <a class="wbitly_settings" href="'.$plugin_url .'">
142-
Setup Bitly URL
143-
</a>';
144+
echo '<a class="wbitly_settings" href="'.$plugin_url .'">Get Started</a>';
144145
}else{
145146

146147
echo '<div class="wbitly_column_container">';

inc/wbitly-metabox.php

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
/**
4+
* @Author: Codehaveli
5+
* @Date: 2020-11-19 17:32:34
6+
* @Last Modified by: Codehaveli
7+
* @Website: www.codehaveli.com
8+
* @Email: hello@codehaveli.com
9+
* @Last Modified time: 2020-11-22 21:26:57
10+
*/
11+
12+
if ( ! defined( 'ABSPATH' ) ) {
13+
exit; // Exit if accessed directly.
14+
}
15+
16+
function wbitly_add_meta_box_to_post_types() {
17+
18+
19+
$wbitly_settings = new WbitlyURLSettings();
20+
$active_post_types = $wbitly_settings->get_wbitly_active_post_status();
21+
22+
23+
foreach ( $active_post_types as $post_type ) {
24+
add_meta_box(
25+
'wbitly-bitly-url-metabox',
26+
__( 'Bitly Short URL', 'wbitly' ),
27+
'wbitly_add_meta_box_content',
28+
$post_type,
29+
'side',
30+
'default'
31+
);
32+
}
33+
}
34+
add_action( 'add_meta_boxes', 'wbitly_add_meta_box_to_post_types' );
35+
36+
37+
function wbitly_add_meta_box_content($post){
38+
39+
$post_id = $post->ID;
40+
41+
if( 'publish' != get_post_status($post_id)){
42+
43+
echo '<h4>Publish to Generate Bitly URL<h4>';
44+
45+
return;
46+
}
47+
48+
$wbitly_settings = new WbitlyURLSettings();
49+
$access_token = $wbitly_settings->get_wbitly_access_token();
50+
$guid = $wbitly_settings->get_wbitly_guid();
51+
52+
if(!$access_token || !$guid){
53+
54+
$plugin_url = admin_url( 'tools.php?page=wbitly');
55+
echo '<a class="wbitly_settings" href="'.$plugin_url .'">Get Started</a>';
56+
57+
}else{
58+
59+
echo '<div class="wbitly_metabox_container wbitly-mt-5">';
60+
61+
$bitly_url = get_wbitly_short_url($post_id);
62+
if ($bitly_url) {
63+
?>
64+
<div class="wbitly_tooltip wbitly copy_bitly">
65+
<p><span class="copy_bitly_link wbitly-meta-bg-link"><?php echo $bitly_url; ?></span> <span class="wbitly_tooltiptext">Click to Copy</span></p>
66+
</div>
67+
<?php
68+
69+
$wbitly_socal_share_status = $wbitly_settings->get_wbitly_socal_share_status();
70+
71+
if( $wbitly_socal_share_status){
72+
wbitly_get_template('share.php');
73+
}
74+
75+
?>
76+
<?php
77+
78+
} else {
79+
?>
80+
<div class="wbitly_tooltip">
81+
<p><?php echo $bitly_url; ?></p>
82+
<button class="wbitly generate_bitly" data-post_id="<?php echo $post_id;?>">
83+
<span class="wbitly_tooltiptext">Click to Generate</span>Generate URL
84+
</button>
85+
</div>
86+
87+
88+
<?php
89+
}
90+
91+
echo "</div>";
92+
93+
}
94+
95+
96+
}

inc/wbitly-settings.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
* @Last Modified by: Codehaveli
77
* @Website: www.codehaveli.com
88
* @Email: hello@codehaveli.com
9-
* @Last Modified time: 2020-09-28 10:35:31
9+
* @Last Modified time: 2020-11-22 23:06:50
1010
*/
1111

12-
12+
if ( ! defined( 'ABSPATH' ) ) {
13+
exit; // Exit if accessed directly.
14+
}
1315

1416
class WbitlyURLSettings {
1517

@@ -322,6 +324,7 @@ public function access_token_callback() {
322324
'<input class="regular-text" type="text" name="wbitly_url_option_name[access_token]" id="access_token" value="%s">',
323325
isset( $this->bitly_url_options['access_token'] ) ? esc_attr( $this->bitly_url_options['access_token']) : ''
324326
);
327+
echo '<p> <small>Tutorial: </small><a href="https://www.codehaveli.com/how-to-generate-bitly-oauth-access-token/?utm_source=Wordpress%20Plugin&utm_medium=Tutorial%20Link&utm_campaign=Codehaveli%20Bitly%20URL%20Shortener" target="_blank"><small>How to generate Bitly OAuth access token?</small></a></p>';
325328
}
326329

327330
public function group_guid_callback() {
@@ -333,7 +336,7 @@ public function group_guid_callback() {
333336
isset( $this->bitly_url_options['group_guid'] ) ? esc_attr( $this->bitly_url_options['group_guid']) : ''
334337
);
335338
echo "<a href=".$guid_url." class='button button-primary'>Get GUID</a>";
336-
echo "<p> <small>First save the access token then click Get GUID button to fill Group Guid from your account automatically. </small></p>";
339+
337340
}
338341

339342
public function bitly_domain_callback() {
@@ -353,7 +356,7 @@ public function add_wbitly_social_share_button() {
353356
}
354357

355358
printf('<label><input name="wbitly_url_option_name[wbitly_socal_share]" id="wbitly_socal_share" type="checkbox" value="enable" %s> Enable </label>', $wbitly_social_share);
356-
echo '<p><small>If you enable this you can share the link from your post list</small></p>';
359+
echo '<p><small>If you enable this you can share the link from your post list/edit screen.</small></p>';
357360
}
358361

359362

inc/wbitly-util.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
* @Last Modified by: Codehaveli
77
* @Website: www.codehaveli.com
88
* @Email: hello@codehaveli.com
9-
* @Last Modified time: 2020-08-27 13:36:38
9+
* @Last Modified time: 2020-11-22 21:27:03
1010
*/
1111

12+
if ( ! defined( 'ABSPATH' ) ) {
13+
exit; // Exit if accessed directly.
14+
}
1215

1316
function get_wbitly_short_url($post_id = null){
1417

inc/wbitly-wp-functions.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
* @Last Modified by: Codehaveli
77
* @Website: www.codehaveli.com
88
* @Email: hello@codehaveli.com
9-
* @Last Modified time: 2020-06-29 20:09:58
9+
* @Last Modified time: 2020-11-22 21:27:07
1010
*/
1111

12-
12+
if ( ! defined( 'ABSPATH' ) ) {
13+
exit; // Exit if accessed directly.
14+
}
1315

1416

1517
add_action( 'wp_ajax_generate_wbitly_url_via_ajax', 'generate_wbitly_url_via_ajax');

index.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/**
4+
* @Author: Codehaveli
5+
* @Date: 2020-11-22 21:23:31
6+
* @Last Modified by: Codehaveli
7+
* @Website: www.codehaveli.com
8+
* @Email: hello@codehaveli.com
9+
* @Last Modified time: 2020-11-22 23:15:53
10+
*/
11+
12+
13+
?>
14+
15+
<h3 style="text-align: center; margin-top: 10px;">Generated by <a target="_blank" href="https://wordpress.org/plugins/codehaveli-bitly-url-shortener/">Codehaveli Bitly URL Shortener</a></h3>

0 commit comments

Comments
 (0)