Install   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 12

4 Methods

Rating   Name   Duplication   Size   Complexity  
A php_ver_incompatible() 0 14 2
A menu_page_link() 0 17 6
A text_domain_cb() 0 8 3
A execute() 0 5 1
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' ) );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
			/** @scrutinizer ignore-call */ 
43
   add_action( 'plugins_loaded', array( $this, 'text_domain_cb' ) );
Loading history...
43
			add_action( 'admin_notices', array( $this, 'php_ver_incompatible' ) );
44
			add_filter( 'plugin_action_links', array( $this, 'menu_page_link' ), 10, 2 );
0 ignored issues
show
Bug introduced by
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
			/** @scrutinizer ignore-call */ 
45
   add_filter( 'plugin_action_links', array( $this, 'menu_page_link' ), 10, 2 );
Loading history...
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();
0 ignored issues
show
Bug introduced by
The function get_locale was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
			$locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : /** @scrutinizer ignore-call */ get_locale();
Loading history...
Bug introduced by
The function is_admin was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
			$locale = /** @scrutinizer ignore-call */ is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
Loading history...
56
			$locale = apply_filters('plugin_locale', $locale, $this->text_domain);
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
			$locale = /** @scrutinizer ignore-call */ apply_filters('plugin_locale', $locale, $this->text_domain);
Loading history...
57
58
			unload_textdomain($this->text_domain);
0 ignored issues
show
Bug introduced by
The function unload_textdomain was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
			/** @scrutinizer ignore-call */ 
59
   unload_textdomain($this->text_domain);
Loading history...
59
			load_textdomain($this->text_domain, PLUGIN_LN . 'textdomain-' . $locale . '.mo');
0 ignored issues
show
Bug introduced by
The constant NirjharLo\WP_Plugin_Framework\Src\PLUGIN_LN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function load_textdomain was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
			/** @scrutinizer ignore-call */ 
60
   load_textdomain($this->text_domain, PLUGIN_LN . 'textdomain-' . $locale . '.mo');
Loading history...
60
			load_plugin_textdomain( $this->text_domain, false, PLUGIN_LN );
0 ignored issues
show
Bug introduced by
The function load_plugin_textdomain was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
			/** @scrutinizer ignore-call */ 
61
   load_plugin_textdomain( $this->text_domain, false, PLUGIN_LN );
Loading history...
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' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
				$text = /** @scrutinizer ignore-call */ __( 'The Plugin can\'t be activated because your PHP version', 'textdomain' );
Loading history...
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) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->plugin_page_links of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
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