PluginProbe
DoLogin Security / trunk
DoLogin Security vtrunk
5.0.10 4.8.3 trunk 1.0 1.1 1.1.1 1.2 1.2.1 1.2.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 1.6 All 64 releases
dologin / src / installer.cls.php

installer.cls.php in DoLogin Security trunk, at src/installer.cls.php

151 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Installer class
4 *
5 * @since 3.5
6 */
7 namespace dologin;
8
9 defined( 'WPINC' ) || exit;
10
11 class Installer extends Instance {
12 const TYPE_INSTALL_3RD = 'install_3rd';
13
14 /**
15 * Auto install 3rd
16 *
17 * @since 3.5
18 */
19 private function _install_3rd() {
20 $this->dash_notifier_install_3rd();
21
22 wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url() );
23 exit;
24 }
25
26 /**
27 * Detect if the plugin is active or not
28 *
29 * @since 1.0
30 */
31 public function dash_notifier_is_plugin_active( $plugin ) {
32 include_once ABSPATH . 'wp-admin/includes/plugin.php';
33
34 $plugin_path = $plugin . '/' . $plugin . '.php';
35
36 return is_plugin_active( $plugin_path );
37 }
38
39 /**
40 * Detect if the plugin is installed or not
41 *
42 * @since 1.0
43 */
44 public function dash_notifier_is_plugin_installed( $plugin ) {
45 include_once ABSPATH . 'wp-admin/includes/plugin.php';
46
47 $plugin_path = $plugin . '/' . $plugin . '.php';
48
49 $valid = validate_plugin( $plugin_path );
50
51 return ! is_wp_error( $valid );
52 }
53
54 /**
55 * Grab a plugin info from WordPress
56 *
57 * @since 1.0
58 */
59 public function dash_notifier_get_plugin_info( $slug ) {
60 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
61 $result = plugins_api( 'plugin_information', array( 'slug' => $slug ) );
62
63 if ( is_wp_error( $result ) ) {
64 return false;
65 }
66
67 return $result;
68 }
69
70 /**
71 * Install the 3rd party plugin
72 *
73 * @since 1.0
74 */
75 public function dash_notifier_install_3rd() {
76 if ( ! current_user_can( 'install_plugins' ) || ! current_user_can( 'activate_plugins' ) || ( is_multisite() && ! is_super_admin() ) ) {
77 return;
78 }
79
80 ! defined( 'SILENCE_INSTALL' ) && define( 'SILENCE_INSTALL', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- documented public API constant toggling silent install.
81
82 $slug = ! empty( $_GET['plugin'] ) && is_string( $_GET['plugin'] ) ? sanitize_key( wp_unslash( $_GET['plugin'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce verified by verify_nonce().
83 if ( 'doqrcode' !== $slug ) {
84 return;
85 }
86
87 // Check if plugin is installed already
88 if ( ! $slug || $this->dash_notifier_is_plugin_active( $slug ) ) {
89 return;
90 }
91
92 /**
93 * @see wp-admin/update.php
94 */
95 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
96 include_once ABSPATH . 'wp-admin/includes/file.php';
97 include_once ABSPATH . 'wp-admin/includes/misc.php';
98
99 $plugin_path = $slug . '/' . $slug . '.php';
100
101 if ( ! $this->dash_notifier_is_plugin_installed( $slug ) ) {
102 $plugin_info = $this->dash_notifier_get_plugin_info( $slug );
103 if ( ! $plugin_info ) {
104 return;
105 }
106 // Try to install plugin
107 try {
108 ob_start();
109 $skin = new \Automatic_Upgrader_Skin();
110 $upgrader = new \Plugin_Upgrader( $skin );
111 $result = $upgrader->install( $plugin_info->download_link );
112 ob_end_clean();
113 } catch ( \Exception $e ) {
114 ob_get_level() && ob_end_clean();
115 return;
116 } catch ( \Throwable $e ) {
117 ob_get_level() && ob_end_clean();
118 return;
119 }
120 if ( ! $result || is_wp_error( $result ) ) {
121 return;
122 }
123 }
124
125 if ( ! is_plugin_active( $plugin_path ) ) {
126 $result = activate_plugin( $plugin_path );
127 if ( is_wp_error( $result ) ) {
128 return;
129 }
130 }
131 }
132
133 /**
134 * Handler
135 *
136 * @since 3.5
137 */
138 public function handler() {
139 $type = Router::verify_type();
140
141 switch ( $type ) {
142 case self::TYPE_INSTALL_3RD:
143 $this->_install_3rd();
144 break;
145
146 default:
147 break;
148 }
149 }
150 }
151