1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_Endpoint { |
4
|
|
|
// POST /sites/%s/themes/%s |
5
|
|
|
// POST /sites/%s/themes |
6
|
|
|
|
7
|
|
|
protected $needed_capabilities = 'update_themes'; |
8
|
|
|
protected $action = 'default_action'; |
9
|
|
|
protected $expected_actions = array( 'update' ); |
10
|
|
|
|
11
|
|
View Code Duplication |
public function default_action() { |
12
|
|
|
$args = $this->input(); |
13
|
|
|
if ( isset( $args['autoupdate'] ) && is_bool( $args['autoupdate'] ) ) { |
14
|
|
|
if ( $args['autoupdate'] ) { |
15
|
|
|
$this->autoupdate_on(); |
16
|
|
|
} else { |
17
|
|
|
$this->autoupdate_off(); |
18
|
|
|
} |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
return true; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
function autoupdate_on() { |
25
|
|
|
$autoupdate_themes = Jetpack_Options::get_option( 'autoupdate_themes', array() ); |
26
|
|
|
$autoupdate_themes = array_unique( array_merge( $autoupdate_themes, $this->themes ) ); |
27
|
|
|
Jetpack_Options::update_option( 'autoupdate_themes', $autoupdate_themes ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function autoupdate_off() { |
31
|
|
|
$autoupdate_themes = Jetpack_Options::get_option( 'autoupdate_themes', array() ); |
32
|
|
|
$autoupdate_themes = array_diff( $autoupdate_themes, $this->themes ); |
33
|
|
|
Jetpack_Options::update_option( 'autoupdate_themes', $autoupdate_themes ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function update() { |
37
|
|
|
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
38
|
|
|
|
39
|
|
|
// Clear the cache. |
40
|
|
|
wp_update_themes(); |
41
|
|
|
|
42
|
|
|
foreach ( $this->themes as $theme ) { |
43
|
|
|
/** |
44
|
|
|
* Pre-upgrade action |
45
|
|
|
* |
46
|
|
|
* @since 3.9.3 |
47
|
|
|
* |
48
|
|
|
* @param object $theme WP_Theme object |
49
|
|
|
* @param array $themes Array of theme objects |
50
|
|
|
*/ |
51
|
|
|
do_action('jetpack_pre_theme_upgrade', $theme, $this->themes); |
52
|
|
|
// Objects created inside the for loop to clean the messages for each theme |
53
|
|
|
$skin = new Automatic_Upgrader_Skin(); |
54
|
|
|
$upgrader = new Theme_Upgrader( $skin ); |
55
|
|
|
$upgrader->init(); |
56
|
|
|
$result = $upgrader->upgrade( $theme ); |
57
|
|
|
$this->log[ $theme ][] = $upgrader->skin->get_upgrade_messages(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
if ( ! $this->bulk && ! $result ) { |
|
|
|
|
61
|
|
|
return new WP_Error( 'update_fail', __( 'There was an error updating your theme', 'jetpack' ), 400 ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return true; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: