forked from szepeviktor/plugin-installer-speedup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin-installer-speedup.php
133 lines (100 loc) · 3.71 KB
/
plugin-installer-speedup.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
123
124
125
126
127
128
129
130
131
132
133
<?php
/*
Plugin Name: Plugin Installer Speedup
Version: 0.2.2
Description: Speedups: dont't load featured plugins, make Search Plugins button visible, skip plugin install confirmation.
Plugin URI: https://wordpress.org/plugins/plugin-installer-speedup/
Author: Viktor Szépe
Author URI: http://www.online1.hu/webdesign/
License: GNU General Public License (GPL) version 2
GitHub Plugin URI: https://github.com/szepeviktor/plugin-installer-speedup
*/
if ( ! function_exists( 'add_filter' ) ) {
ob_get_level() && ob_end_clean();
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
class O1_Plugin_Speedups {
private $admin_menu;
public function __construct() {
add_filter( 'install_plugins_table_api_args_featured', '__return_false' );
add_action( 'admin_init', array( $this, 'upload_fav_menu' ) );
add_action( 'admin_bar_menu', array( $this, 'new_content' ), 71 );
add_action( 'admin_enqueue_scripts', array( $this, 'install_script_styles' ) );
add_action( 'load-update.php', array( $this, 'hook_modify_source' ) );
}
public function install_script_styles( $hook ) {
if ( 'plugin-install.php' !== $hook ) {
return;
}
$style = '.plugin-install-php #search-submit { display: inline-block;
clip:auto; height:28px; position:static; vertical-align:baseline;
width:auto; }';
wp_add_inline_style( 'wp-admin', $style );
wp_enqueue_script(
'plugin-installer-speedup',
plugin_dir_url( __FILE__ ) . 'js/installer.js',
array( 'jquery' ),
'1.0.1',
true
);
}
public function upload_fav_menu() {
global $submenu;
if ( ! is_multisite() ) {
// Hack into the Settings menu
$submenu['plugins.php'][9] = array(
_x( 'Favorites', 'Plugin Installer' ),
'install_plugins',
'plugin-install.php?tab=favorites',
);
$submenu['plugins.php'][11] = array(
__( 'Upload Plugin' ),
'install_plugins',
'plugin-install.php?tab=upload',
);
ksort( $submenu['plugins.php'] );
}
}
public function new_content() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'parent' => 'new-content',
'id' => 'plugin-install',
'title' => __( 'Plugin' ),
'href' => self_admin_url( 'plugin-install.php' ),
) );
}
public function hook_modify_source() {
if ( 'upload-plugin' !== $_GET['action'] ) {
return;
}
// Remove "-master" from GitHub URL-s
add_filter( 'upgrader_source_selection', array( $this, 'remove_github_master' ), 9, 3 );
}
public function remove_github_master( $source, $remote_source, $that ) {
global $wp_filesystem;
$ghm = '-master';
$new_source = $this->remove_trailing_part( $source, $ghm );
if ( $wp_filesystem->move( $source, $new_source ) ) {
return $new_source;
}
return $source;
}
private function remove_trailing_part( $haystack, $needle ) {
$length = strlen( $needle );
if ( 0 === $length ) {
return $haystack;
}
if ( substr( $haystack, -$length ) !== $needle ) {
// Try with a slash too
if ( substr( $haystack, -$length - 1 ) === $needle . '/' ) {
return substr( $haystack, 0, -$length - 1 ) . '/';
}
return $haystack;
}
return substr( $haystack, 0, -$length );
}
}
new O1_Plugin_Speedups();