-
Notifications
You must be signed in to change notification settings - Fork 1
/
easy-plugin-installation.php
123 lines (76 loc) · 3.2 KB
/
easy-plugin-installation.php
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
<?php
/*
Easy Plugin Installation.
This plugin allows users to directly install the download package from CodeCanyon (or any other similar marketplace) which contains the actual plugin. It's something to prevent the "missing stylesheet" problem but only form plugins.
Installation:
Simple place this file in the root of your zip file you upload to Envato. Make sure your plugin is also in the package and zipped.
Update the Plugin information down below with your plugins info.
Readme: https://github.com/revaxarts/Easy-Plugin-Installation
*/
/*
!! UPDATE THIS INFO WITH THE DETAILS OF YOUR PLUGIN !!
Plugin Name: Easy Plugin Installation
Plugin URI: https://github.com/revaxarts/Easy-Plugin-Installation
Description: This plugin allows users to directly install the download package from CodeCanyon (or any other similar marketplace)
Author: revaxarts.com
Author URI: https://revaxarts.com
*/
class easy_plugin_installation {
public function __construct(){
//make it nice and inline
add_action('admin_notices', array( $this, 'plugin_activation' ) );
add_filter('upgrader_package_options', array( $this, 'upgrader_package_options' ) );
}
public function upgrader_package_options($options){
$options['clear_destination'] = true;
$options['abort_if_destination_exists'] = false;
return $options;
}
public function plugin_activation(){
//the slug of this plugin
$plugin = basename(dirname(__FILE__)).'/'.basename(__FILE__);
//include some function
if(!function_exists('list_files'))
include( ABSPATH . 'wp-admin/includes/file.php' );
if(!function_exists('show_message'))
include( ABSPATH . 'wp-admin/includes/misc.php' );
if(!function_exists('get_plugin_data'))
include( ABSPATH . 'wp-admin/includes/plugin.php' );
if(!class_exists('Plugin_Upgrader'))
include( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
//create a new upgrader
$upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin( ));
//get all zips in the plugins directory
$files = list_files(dirname( __FILE__ ));
$files = preg_grep('#\.zip$#', $files);
foreach($files as $file){
//try to install the plugin
if($upgrader->install( $file )){
//get all php files of the installed plugin
$source_files = preg_grep('#\.php$#', $upgrader->result['source_files']);
foreach($source_files as $source_file){
//try to get the plugin data of the file
$plugin_data = get_plugin_data($upgrader->result['destination'].$source_file);
//this is the plugin file
if(!empty($plugin_data['Name'])){
//the slug of the new plugin
$plugin_slug = basename($upgrader->result['destination']).'/'.$source_file;
//activate it
if(!is_wp_error(activate_plugin( $plugin_slug ))){
//deactivate and remove this plugin
deactivate_plugins( __FILE__ );
//comment this line out if you do some testings
delete_plugins( array($plugin) );
//echo some javascript to reload the page
echo '<script>try{location.reload();}catch(e){}</script>';
exit;
}
}
}
}
}
show_message('<div class="error"><p>No valid plugin has been found!</p></div>' );
deactivate_plugins( __FILE__ );
}
}
new easy_plugin_installation();