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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
<?php
class SiteOrigin_Panels_Admin_Widgets_Bundle {
function __construct() { if ( isset( $_GET['siteorigin-pa-install'] ) ) { add_action( 'admin_menu', array( $this, 'activation_page' ) ); } }
public static function single() { static $single; return empty( $single ) ? $single = new self() : $single; }
function activation_page() { add_plugins_page( __( 'Install Page Builder Plugin', 'siteorigin-panels' ), __( 'Install Page Builder Plugin', 'siteorigin-panels' ), 'install_plugins', 'siteorigin_panels_plugin_activation', array( $this, 'render_page' ) ); }
function render_page() { ?> <div class="wrap"> <?php /** All plugin information will be stored in an array for processing */ $plugin = array();
/** Checks for actions from hover links to process the installation */ if ( isset( $_GET[ sanitize_key( 'plugin' ) ] ) && ( isset( $_GET[ sanitize_key( 'siteorigin-pa-install' ) ] ) && 'install-plugin' == $_GET[ sanitize_key( 'siteorigin-pa-install' ) ] ) && current_user_can( 'install_plugins' ) ) { check_admin_referer( 'siteorigin-pa-install' );
$plugin['name'] = $_GET['plugin_name']; // Plugin name $plugin['slug'] = $_GET['plugin']; // Plugin slug
if ( ! empty( $_GET['plugin_source'] ) ) { $plugin['source'] = $_GET['plugin_source']; } else { $plugin['source'] = false; }
/** Pass all necessary information via URL if WP_Filesystem is needed */ $url = wp_nonce_url( add_query_arg( array( 'page' => 'siteorigin_panels_plugin_activation', 'plugin' => urlencode( $plugin['slug'] ), 'plugin_name' => urlencode( $plugin['name'] ), 'plugin_source' => urlencode( $plugin['source'] ), 'siteorigin-pa-install' => 'install-plugin', ), admin_url( 'themes.php' ) ), 'siteorigin-pa-install' ); $method = ''; // Leave blank so WP_Filesystem can populate it as necessary $fields = array( sanitize_key( 'siteorigin-pa-install' ) ); // Extra fields to pass to WP_Filesystem
if ( false === ( $creds = request_filesystem_credentials( $url, $method, false, false, $fields ) ) ) { return true; }
if ( ! WP_Filesystem( $creds ) ) { request_filesystem_credentials( $url, $method, true, false, $fields ); // Setup WP_Filesystem return true; }
require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Need for plugins_api require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // Need for upgrade classes
/** Prep variables for Plugin_Installer_Skin class */ $title = sprintf( __( 'Installing %s', 'siteorigin-panels' ), $plugin['name'] ); $url = add_query_arg( array( 'action' => 'install-plugin', 'plugin' => urlencode( $plugin['slug'] ) ), 'update.php' ); if ( isset( $_GET['from'] ) ) { $url .= add_query_arg( 'from', urlencode( stripslashes( $_GET['from'] ) ), $url ); }
$nonce = 'install-plugin_' . $plugin['slug'];
// Find the source of the plugin $source = ! empty( $plugin['source'] ) ? $plugin['source'] : 'http://downloads.wordpress.org/plugin/' . urlencode( $plugin['slug'] ) . '.zip';
/** Create a new instance of Plugin_Upgrader */ $upgrader = new Plugin_Upgrader( $skin = new Plugin_Installer_Skin( compact( 'type', 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
/** Perform the action and install the plugin from the $source urldecode() */ $upgrader->install( $source );
/** Flush plugins cache so we can make sure that the installed plugins list is always up to date */ wp_cache_flush(); } ?> </div> <?php }
static function install_url( $plugin, $plugin_name, $source = false ) { // This is to prevent the issue where this URL is called from outside the admin if ( ! is_admin() || ! function_exists( 'get_plugins' ) ) { return false; }
$plugins = get_plugins(); $plugins = array_keys( $plugins );
$installed = false; foreach ( $plugins as $plugin_path ) { if ( strpos( $plugin_path, $plugin . '/' ) === 0 ) { $installed = true; break; } }
if ( $installed && ! is_plugin_active( $plugin ) ) { return wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $plugin_path ), 'activate-plugin_' . $plugin_path ); } elseif ( $installed && is_plugin_active( $plugin ) ) { return '#'; } else { return wp_nonce_url( add_query_arg( array( 'page' => 'siteorigin_panels_plugin_activation', 'plugin' => $plugin, 'plugin_name' => $plugin_name, 'plugin_source' => ! empty( $source ) ? urlencode( $source ) : false, 'siteorigin-pa-install' => 'install-plugin', ), admin_url( 'plugins.php' ) ), 'siteorigin-pa-install' ); } }
}
|