nirjharlo /
wp-plugin-framework
| 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
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
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
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
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
Loading history...
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
Loading history...
|
|||||||
| 56 | $locale = apply_filters('plugin_locale', $locale, $this->text_domain); |
||||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||||
| 57 | |||||||
| 58 | unload_textdomain($this->text_domain); |
||||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||||
| 59 | load_textdomain($this->text_domain, PLUGIN_LN . 'textdomain-' . $locale . '.mo'); |
||||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||||
| 60 | load_plugin_textdomain( $this->text_domain, false, PLUGIN_LN ); |
||||||
|
0 ignored issues
–
show
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
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
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
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
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 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 |