-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpstorm-url-shortener.php
118 lines (100 loc) · 2.71 KB
/
wpstorm-url-shortener.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* Plugin Name: Wpstorm Url Shortener
* Plugin URI: https://wpstorm.ir/url-shortener
* Description: Complete plugin for generate short links with your own custom domain.
* Version: 1.0
* Author: Wpstorm
* Author URI: https://wpstorm.ir
* Text Domain: wpstorm-shortener
* Domain Path: /languages
* License: GPL v2
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Farazsms.
*/
class Wpstorm_Shortener {
/**
* Instance
*
* @access private
* @var object Class object.
* @since 2.0.0
*/
private static object $instance;
/**
* Initiator
*
* @return object Initialized object of class.
* @since 2.0.0
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
public function __construct() {
$this->define_constants();
$this->wpstorm_url_shortener_loader();
register_activation_hook( __FILE__, [ $this, 'activate_farazsms' ] );
add_action( 'activated_plugin', [ $this, 'farazsms_activation_redirect' ] );
}
/**
* Defines all constants
*
* @since 2.0.0
*/
public function define_constants() {
/**
* Defines all constants
*
* @since 2.0.0
*/
define( 'WPSTORM_SHORTENER_VER', '1.0.0' );
define( 'WPSTORM_SHORTENER_FILE', __FILE__ );
define( 'WPSTORM_SHORTENER_PATH', plugin_dir_path( WPSTORM_SHORTENER_FILE ) );
define( 'WPSTORM_SHORTENER_BASE', plugin_basename( WPSTORM_SHORTENER_FILE ) );
define( 'WPSTORM_SHORTENER_SLUG', 'wpstorm_shortener_link_settings' );
define( 'WPSTORM_SHORTENER_SETTINGS_LINK', admin_url( 'admin.php?page=' . WPSTORM_SHORTENER_SLUG ) );
define( 'WPSTORM_SHORTENER_URL', plugins_url( '/', WPSTORM_SHORTENER_FILE ) );
define( 'WPSTORM_SHORTENER_WEB_MAIN', 'https://wpstorm.ir/' );
define( 'WPSTORM_SHORTENER_WEB_MAIN_DOC', WPSTORM_SHORTENER_WEB_MAIN . 'url-shortener/' );
}
/**
* Require loader farazsms class.
*
* @return void
*/
public function wpstorm_url_shortener_loader() {
require WPSTORM_SHORTENER_PATH . 'classes/wpstorm-shortener-loader.php';
}
/**
* Require farazsms activator class.
*
* @return void
*/
public function activate_farazsms() {
require_once WPSTORM_SHORTENER_PATH . 'classes/wpstorm-shortener-activator.php';
Wpstorm_Shortener_Activator::activate();
}
/**
* Redirect user to plugin settings page after plugin activated.
*
* @return void
*/
public function farazsms_activation_redirect() {
if ( get_option( 'wpstorm_shortener_do_activation_redirect', false ) ) {
delete_option( 'wpstorm_shortener_do_activation_redirect' );
exit( wp_redirect( WPSTORM_SHORTENER_SETTINGS_LINK ) );
}
}
}
Wpstorm_Shortener::get_instance();