1
|
|
|
<?php |
2
|
|
|
namespace NirjharLo\WP_Plugin_Framework\Src; |
3
|
|
|
|
4
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Implimentation of WordPress inbuilt functions for plugin activation. |
8
|
|
|
* |
9
|
|
|
* @author Nirjhar Lo |
10
|
|
|
* @package wp-plugin-framework |
11
|
|
|
*/ |
12
|
|
|
if ( ! class_exists( 'Install' ) ) { |
13
|
|
|
|
14
|
|
|
final class Install { |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var String |
19
|
|
|
*/ |
20
|
|
|
public $text_domain; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var String |
25
|
|
|
*/ |
26
|
|
|
public $php_ver_allowed; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Array |
31
|
|
|
*/ |
32
|
|
|
public $plugin_page_links; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Execute plugin setup |
37
|
|
|
* |
38
|
|
|
* @return Void |
39
|
|
|
*/ |
40
|
|
|
public function execute() { |
41
|
|
|
|
42
|
|
|
add_action( 'plugins_loaded', array( $this, 'text_domain_cb' ) ); |
|
|
|
|
43
|
|
|
add_action( 'admin_notices', array( $this, 'php_ver_incompatible' ) ); |
44
|
|
|
add_filter( 'plugin_action_links', array( $this, 'menu_page_link' ), 10, 2 ); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Load plugin textdomain |
50
|
|
|
* |
51
|
|
|
* @return Void |
52
|
|
|
*/ |
53
|
|
|
public function text_domain_cb() { |
54
|
|
|
|
55
|
|
|
$locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
|
|
|
56
|
|
|
$locale = apply_filters('plugin_locale', $locale, $this->text_domain); |
|
|
|
|
57
|
|
|
|
58
|
|
|
unload_textdomain($this->text_domain); |
|
|
|
|
59
|
|
|
load_textdomain($this->text_domain, PLUGIN_LN . 'textdomain-' . $locale . '.mo'); |
|
|
|
|
60
|
|
|
load_plugin_textdomain( $this->text_domain, false, PLUGIN_LN ); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Define low php verson errors |
66
|
|
|
* |
67
|
|
|
* @return String |
68
|
|
|
*/ |
69
|
|
|
public function php_ver_incompatible() { |
70
|
|
|
|
71
|
|
|
if ( version_compare( phpversion(), $this->php_ver_allowed, '<' ) ) : |
72
|
|
|
$text = __( 'The Plugin can\'t be activated because your PHP version', 'textdomain' ); |
|
|
|
|
73
|
|
|
$text_last = __( 'is less than required '.$this->php_ver_allowed.'. See more information', 'textdomain' ); |
74
|
|
|
$text_link = 'php.net/eol.php'; ?> |
75
|
|
|
|
76
|
|
|
<div id="message" class="updated notice notice-success is-dismissible"> |
77
|
|
|
<p><?php echo $text . ' ' . phpversion() . ' ' . $text_last . ': '; ?> |
78
|
|
|
<a href="http://php.net/eol.php/" target="_blank"><?php echo $text_link; ?></a> |
79
|
|
|
</p> |
80
|
|
|
</div> |
81
|
|
|
|
82
|
|
|
<?php endif; return; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Add settings link to plugin page |
88
|
|
|
* |
89
|
|
|
* @param Array $links |
90
|
|
|
* @param String $file |
91
|
|
|
* |
92
|
|
|
* @return Array |
93
|
|
|
*/ |
94
|
|
|
public function menu_page_link( $links, $file ) { |
95
|
|
|
|
96
|
|
|
if ($this->plugin_page_links) { |
|
|
|
|
97
|
|
|
static $this_plugin; |
98
|
|
|
if ( ! $this_plugin ) { |
99
|
|
|
$this_plugin = PLUGIN_FILE; |
100
|
|
|
} |
101
|
|
|
if ( $file == $this_plugin ) { |
102
|
|
|
$shift_link = array(); |
103
|
|
|
foreach ($this->plugin_page_links as $value) { |
104
|
|
|
$shift_link[] = '<a href="'.$value['slug'].'">'.$value['label'].'</a>'; |
105
|
|
|
} |
106
|
|
|
foreach( $shift_link as $val ) { |
107
|
|
|
array_unshift( $links, $val ); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
return $links; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} ?> |
115
|
|
|
|