Completed
Push — master ( 45a001...92a1b3 )
by Jerome
62:35 queued 12s
created

actions/admin/plugins/set_priority.php (1 issue)

1
<?php
2
/**
3
 * Changes the load priority of a plugin.
4
 *
5
 * Plugin priority affects view, action, and page handler
6
 * overriding as well as the order of view extensions.  Plugins with higher
7
 * priority are loaded after and override plugins with lower priorities.
8
 *
9
 * NOTE: When viewing the plugin admin page, plugins LOWER on the page
10
 * have HIGHER priority and will override views, etc from plugins above them.
11
 */
12
13
$plugin_guid = (int) get_input('plugin_guid');
14
$priority = get_input('priority');
15
16
$plugin = get_entity($plugin_guid);
17
18
if (!($plugin instanceof ElggPlugin)) {
19
	return elgg_error_response(elgg_echo('admin:plugins:set_priority:no', [$plugin_guid]));
20
}
21
22
if (!$plugin->setPriority($priority)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $plugin->setPriority($priority) of type false|integer is loosely compared to false; this is ambiguous if the integer can be 0. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
23
	$msg = $plugin->getError();
24
	$string = ($msg) ? 'admin:plugins:set_priority:no_with_msg' : 'admin:plugins:set_priority:no';
25
26
	return elgg_error_response(elgg_echo($string, [$plugin->getDisplayName(), $msg]));
27
}
28
29
// don't regenerate the simplecache because the plugin won't be
30
// loaded until next run.  Just invalidate and let it regnerate as needed
31
elgg_flush_caches();
32
33
return elgg_ok_response();
34