-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.php
85 lines (59 loc) · 2.76 KB
/
admin.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
<?php
final class CAJ_ETPU_Admin {
public static function init() {
add_action( 'load-update.php', array( __CLASS__, 'set_hooks' ) );
}
public static function set_hooks() {
include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
add_action( 'admin_action_upload-theme', array( __CLASS__, 'update_theme' ) );
add_action( 'admin_action_upload-plugin', array( __CLASS__, 'update_plugin' ) );
}
public static function update_theme() {
if ( ! current_user_can( 'upload_themes' ) ) {
wp_die( esc_html__( 'Sorry, you are not allowed to install themes on this site.' ) );
}
check_admin_referer( 'theme-upload' );
$file_upload = new File_Upload_Upgrader( 'themezip', 'package' );
wp_enqueue_script( 'customize-loader' );
$title = __( 'Upload Theme' );
$parent_file = 'themes.php';
$submenu_file = 'theme-install.php';
require_once( ABSPATH . 'wp-admin/admin-header.php' );
$title = sprintf( __( 'Installing Theme from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
$nonce = 'theme-upload';
$url = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-theme' );
$type = 'upload'; // Install plugin type, From Web or an Upload.
require_once( dirname( __FILE__ ) . '/custom-theme-upgrader.php' );
$upgrader = new CAJ_ETPU_Theme_Upgrader( new Theme_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
$result = $upgrader->install( $file_upload->package );
if ( $result || is_wp_error( $result ) ) {
$file_upload->cleanup();
}
include( ABSPATH . 'wp-admin/admin-footer.php' );
exit();
}
public static function update_plugin() {
if ( ! current_user_can( 'upload_plugins' ) ) {
wp_die( esc_html__( 'Sorry, you are not allowed to install plugins on this site.' ) );
}
check_admin_referer( 'plugin-upload' );
$file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' );
$title = __( 'Upload Plugin' );
$parent_file = 'plugins.php';
$submenu_file = 'plugin-install.php';
require_once( ABSPATH . 'wp-admin/admin-header.php' );
$title = sprintf( __( 'Installing Plugin from uploaded file: %s' ), esc_html( basename( $file_upload->filename ) ) );
$nonce = 'plugin-upload';
$url = add_query_arg( array( 'package' => $file_upload->id ), 'update.php?action=upload-plugin' );
$type = 'upload'; // Install plugin type, From Web or an Upload.
require_once( dirname( __FILE__ ) . '/custom-plugin-upgrader.php' );
$upgrader = new CAJ_ETPU_Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
$result = $upgrader->install( $file_upload->package );
if ( $result || is_wp_error( $result ) ) {
$file_upload->cleanup();
}
include( ABSPATH . 'wp-admin/admin-footer.php' );
exit();
}
}
CAJ_ETPU_Admin::init();