| 1 |
<?php |
|---|
| 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 |
function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { |
|---|
| 69 |
|
|---|
| 70 |
$fp = fopen($plugin_file, 'r'); |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
$plugin_data = fread( $fp, 8192 ); |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
fclose($fp); |
|---|
| 77 |
|
|---|
| 78 |
preg_match( '|Plugin Name:(.*)$|mi', $plugin_data, $name ); |
|---|
| 79 |
preg_match( '|Plugin URI:(.*)$|mi', $plugin_data, $uri ); |
|---|
| 80 |
preg_match( '|Version:(.*)|i', $plugin_data, $version ); |
|---|
| 81 |
preg_match( '|Description:(.*)$|mi', $plugin_data, $description ); |
|---|
| 82 |
preg_match( '|Author:(.*)$|mi', $plugin_data, $author_name ); |
|---|
| 83 |
preg_match( '|Author URI:(.*)$|mi', $plugin_data, $author_uri ); |
|---|
| 84 |
preg_match( '|Text Domain:(.*)$|mi', $plugin_data, $text_domain ); |
|---|
| 85 |
preg_match( '|Domain Path:(.*)$|mi', $plugin_data, $domain_path ); |
|---|
| 86 |
|
|---|
| 87 |
foreach ( array( 'name', 'uri', 'version', 'description', 'author_name', 'author_uri', 'text_domain', 'domain_path' ) as $field ) { |
|---|
| 88 |
if ( !empty( ${$field} ) ) |
|---|
| 89 |
${$field} = trim(${$field}[1]); |
|---|
| 90 |
else |
|---|
| 91 |
${$field} = ''; |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
$plugin_data = array( |
|---|
| 95 |
'Name' => $name, 'Title' => $name, 'PluginURI' => $uri, 'Description' => $description, |
|---|
| 96 |
'Author' => $author_name, 'AuthorURI' => $author_uri, 'Version' => $version, |
|---|
| 97 |
'TextDomain' => $text_domain, 'DomainPath' => $domain_path |
|---|
| 98 |
); |
|---|
| 99 |
if ( $markup || $translate ) |
|---|
| 100 |
$plugin_data = _get_plugin_data_markup_translate($plugin_data, $markup, $translate); |
|---|
| 101 |
return $plugin_data; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
function _get_plugin_data_markup_translate($plugin_data, $markup = true, $translate = true) { |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
if( $translate && ! empty($plugin_data['TextDomain']) ) { |
|---|
| 108 |
if( ! empty( $plugin_data['DomainPath'] ) ) |
|---|
| 109 |
load_plugin_textdomain($plugin_data['TextDomain'], dirname($plugin_file). $plugin_data['DomainPath']); |
|---|
| 110 |
else |
|---|
| 111 |
load_plugin_textdomain($plugin_data['TextDomain'], dirname($plugin_file)); |
|---|
| 112 |
|
|---|
| 113 |
foreach ( array('Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version') as $field ) |
|---|
| 114 |
$plugin_data[ $field ] = translate($plugin_data[ $field ], $plugin_data['TextDomain']); |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
if ( $markup ) { |
|---|
| 119 |
if ( ! empty($plugin_data['PluginURI']) && ! empty($plugin_data['Name']) ) |
|---|
| 120 |
$plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __( 'Visit plugin homepage' ) . '">' . $plugin_data['Name'] . '</a>'; |
|---|
| 121 |
else |
|---|
| 122 |
$plugin_data['Title'] = $plugin_data['Name']; |
|---|
| 123 |
|
|---|
| 124 |
if ( ! empty($plugin_data['AuthorURI']) ) |
|---|
| 125 |
$plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>'; |
|---|
| 126 |
|
|---|
| 127 |
$plugin_data['Description'] = wptexturize( $plugin_data['Description'] ); |
|---|
| 128 |
if( ! empty($plugin_data['Author']) ) |
|---|
| 129 |
$plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s'), $plugin_data['Author'] ) . '.</cite>'; |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
$plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
$plugin_data['Title'] = wp_kses($plugin_data['Title'], $plugins_allowedtags); |
|---|
| 136 |
$plugin_data['Version'] = wp_kses($plugin_data['Version'], $plugins_allowedtags); |
|---|
| 137 |
$plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags); |
|---|
| 138 |
$plugin_data['Author'] = wp_kses($plugin_data['Author'], $plugins_allowedtags); |
|---|
| 139 |
|
|---|
| 140 |
return $plugin_data; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
function get_plugins($plugin_folder = '') { |
|---|
| 164 |
|
|---|
| 165 |
if ( ! $cache_plugins = wp_cache_get('plugins', 'plugins') ) |
|---|
| 166 |
$cache_plugins = array(); |
|---|
| 167 |
|
|---|
| 168 |
if ( isset($cache_plugins[ $plugin_folder ]) ) |
|---|
| 169 |
return $cache_plugins[ $plugin_folder ]; |
|---|
| 170 |
|
|---|
| 171 |
$wp_plugins = array (); |
|---|
| 172 |
$plugin_root = WP_PLUGIN_DIR; |
|---|
| 173 |
if( !empty($plugin_folder) ) |
|---|
| 174 |
$plugin_root .= $plugin_folder; |
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
$plugins_dir = @ opendir( $plugin_root); |
|---|
| 178 |
if ( $plugins_dir ) { |
|---|
| 179 |
while (($file = readdir( $plugins_dir ) ) !== false ) { |
|---|
| 180 |
if ( substr($file, 0, 1) == '.' ) |
|---|
| 181 |
continue; |
|---|
| 182 |
if ( is_dir( $plugin_root.'/'.$file ) ) { |
|---|
| 183 |
$plugins_subdir = @ opendir( $plugin_root.'/'.$file ); |
|---|
| 184 |
if ( $plugins_subdir ) { |
|---|
| 185 |
while (($subfile = readdir( $plugins_subdir ) ) !== false ) { |
|---|
| 186 |
if ( substr($subfile, 0, 1) == '.' ) |
|---|
| 187 |
continue; |
|---|
| 188 |
if ( substr($subfile, -4) == '.php' ) |
|---|
| 189 |
$plugin_files[] = "$file/$subfile"; |
|---|
| 190 |
} |
|---|
| 191 |
} |
|---|
| 192 |
} else { |
|---|
| 193 |
if ( substr($file, -4) == '.php' ) |
|---|
| 194 |
$plugin_files[] = $file; |
|---|
| 195 |
} |
|---|
| 196 |
} |
|---|
| 197 |
} |
|---|
| 198 |
@closedir( $plugins_dir ); |
|---|
| 199 |
@closedir( $plugins_subdir ); |
|---|
| 200 |
|
|---|
| 201 |
if ( !$plugins_dir || !$plugin_files ) |
|---|
| 202 |
return $wp_plugins; |
|---|
| 203 |
|
|---|
| 204 |
foreach ( $plugin_files as $plugin_file ) { |
|---|
| 205 |
if ( !is_readable( "$plugin_root/$plugin_file" ) ) |
|---|
| 206 |
continue; |
|---|
| 207 |
|
|---|
| 208 |
$plugin_data = get_plugin_data( "$plugin_root/$plugin_file", false, false ); |
|---|
| 209 |
|
|---|
| 210 |
if ( empty ( $plugin_data['Name'] ) ) |
|---|
| 211 |
continue; |
|---|
| 212 |
|
|---|
| 213 |
$wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; |
|---|
| 214 |
} |
|---|
| 215 |
|
|---|
| 216 |
uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' )); |
|---|
| 217 |
|
|---|
| 218 |
$cache_plugins[ $plugin_folder ] = $wp_plugins; |
|---|
| 219 |
wp_cache_set('plugins', $cache_plugins, 'plugins'); |
|---|
| 220 |
|
|---|
| 221 |
return $wp_plugins; |
|---|
| 222 |
} |
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
function is_plugin_active($plugin) { |
|---|
| 233 |
return in_array($plugin, get_option('active_plugins')); |
|---|
| 234 |
} |
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
function activate_plugin($plugin, $redirect = '') { |
|---|
| 261 |
$current = get_option('active_plugins'); |
|---|
| 262 |
$plugin = plugin_basename(trim($plugin)); |
|---|
| 263 |
|
|---|
| 264 |
$valid = validate_plugin($plugin); |
|---|
| 265 |
if ( is_wp_error($valid) ) |
|---|
| 266 |
return $valid; |
|---|
| 267 |
|
|---|
| 268 |
if ( !in_array($plugin, $current) ) { |
|---|
| 269 |
if ( !empty($redirect) ) |
|---|
| 270 |
wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); |
|---|
| 271 |
ob_start(); |
|---|
| 272 |
@include(WP_PLUGIN_DIR . '/' . $plugin); |
|---|
| 273 |
$current[] = $plugin; |
|---|
| 274 |
sort($current); |
|---|
| 275 |
update_option('active_plugins', $current); |
|---|
| 276 |
do_action('activate_' . $plugin); |
|---|
| 277 |
ob_end_clean(); |
|---|
| 278 |
} |
|---|
| 279 |
|
|---|
| 280 |
return null; |
|---|
| 281 |
} |
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
function deactivate_plugins($plugins, $silent= false) { |
|---|
| 295 |
$current = get_option('active_plugins'); |
|---|
| 296 |
|
|---|
| 297 |
if ( !is_array($plugins) ) |
|---|
| 298 |
$plugins = array($plugins); |
|---|
| 299 |
|
|---|
| 300 |
foreach ( $plugins as $plugin ) { |
|---|
| 301 |
$plugin = plugin_basename($plugin); |
|---|
| 302 |
if( ! is_plugin_active($plugin) ) |
|---|
| 303 |
continue; |
|---|
| 304 |
array_splice($current, array_search( $plugin, $current), 1 ); |
|---|
| 305 |
if ( ! $silent ) |
|---|
| 306 |
do_action('deactivate_' . trim( $plugin )); |
|---|
| 307 |
} |
|---|
| 308 |
|
|---|
| 309 |
update_option('active_plugins', $current); |
|---|
| 310 |
} |
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
function activate_plugins($plugins, $redirect = '') { |
|---|
| 327 |
if ( !is_array($plugins) ) |
|---|
| 328 |
$plugins = array($plugins); |
|---|
| 329 |
|
|---|
| 330 |
$errors = array(); |
|---|
| 331 |
foreach ( (array) $plugins as $plugin ) { |
|---|
| 332 |
if ( !empty($redirect) ) |
|---|
| 333 |
$redirect = add_query_arg('plugin', $plugin, $redirect); |
|---|
| 334 |
$result = activate_plugin($plugin, $redirect); |
|---|
| 335 |
if ( is_wp_error($result) ) |
|---|
| 336 |
$errors[$plugin] = $result; |
|---|
| 337 |
} |
|---|
| 338 |
|
|---|
| 339 |
if ( !empty($errors) ) |
|---|
| 340 |
return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors); |
|---|
| 341 |
|
|---|
| 342 |
return true; |
|---|
| 343 |
} |
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
function delete_plugins($plugins, $redirect = '' ) { |
|---|
| 358 |
global $wp_filesystem; |
|---|
| 359 |
|
|---|
| 360 |
if( empty($plugins) ) |
|---|
| 361 |
return false; |
|---|
| 362 |
|
|---|
| 363 |
$checked = array(); |
|---|
| 364 |
foreach( $plugins as $plugin ) |
|---|
| 365 |
$checked[] = 'checked[]=' . $plugin; |
|---|
| 366 |
|
|---|
| 367 |
ob_start(); |
|---|
| 368 |
$url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-manage-plugins'); |
|---|
| 369 |
if ( false === ($credentials = request_filesystem_credentials($url)) ) { |
|---|
| 370 |
$data = ob_get_contents(); |
|---|
| 371 |
ob_end_clean(); |
|---|
| 372 |
if( ! empty($data) ){ |
|---|
| 373 |
include_once( ABSPATH . 'wp-admin/admin-header.php'); |
|---|
| 374 |
echo $data; |
|---|
| 375 |
include( ABSPATH . 'wp-admin/admin-footer.php'); |
|---|
| 376 |
exit; |
|---|
| 377 |
} |
|---|
| 378 |
return; |
|---|
| 379 |
} |
|---|
| 380 |
|
|---|
| 381 |
if ( ! WP_Filesystem($credentials) ) { |
|---|
| 382 |
request_filesystem_credentials($url, '', true); |
|---|
| 383 |
$data = ob_get_contents(); |
|---|
| 384 |
ob_end_clean(); |
|---|
| 385 |
if( ! empty($data) ){ |
|---|
| 386 |
include_once( ABSPATH . 'wp-admin/admin-header.php'); |
|---|
| 387 |
echo $data; |
|---|
| 388 |
include( ABSPATH . 'wp-admin/admin-footer.php'); |
|---|
| 389 |
exit; |
|---|
| 390 |
} |
|---|
| 391 |
return; |
|---|
| 392 |
} |
|---|
| 393 |
|
|---|
| 394 |
if ( $wp_filesystem->errors->get_error_code() ) { |
|---|
| 395 |
return $wp_filesystem->errors; |
|---|
| 396 |
} |
|---|
| 397 |
|
|---|
| 398 |
if ( ! is_object($wp_filesystem) ) |
|---|
| 399 |
return new WP_Error('fs_unavailable', __('Could not access filesystem.')); |
|---|
| 400 |
|
|---|
| 401 |
if ( $wp_filesystem->errors->get_error_code() ) |
|---|
| 402 |
return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); |
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
$plugins_dir = $wp_filesystem->wp_plugins_dir(); |
|---|
| 406 |
if ( empty($plugins_dir) ) |
|---|
| 407 |
return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.')); |
|---|
| 408 |
|
|---|
| 409 |
$plugins_dir = trailingslashit( $plugins_dir ); |
|---|
| 410 |
|
|---|
| 411 |
$errors = array(); |
|---|
| 412 |
|
|---|
| 413 |
foreach( $plugins as $plugin_file ) { |
|---|
| 414 |
|
|---|
| 415 |
if ( is_uninstallable_plugin( $plugin_file ) ) |
|---|
| 416 |
uninstall_plugin($plugin_file); |
|---|
| 417 |
|
|---|
| 418 |
$this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin_file) ); |
|---|
| 419 |
|
|---|
| 420 |
if ( strpos($plugin_file, '/') && $this_plugin_dir != $plugins_dir ) |
|---|
| 421 |
$deleted = $wp_filesystem->delete($this_plugin_dir, true); |
|---|
| 422 |
else |
|---|
| 423 |
$deleted = $wp_filesystem->delete($plugins_dir . $plugin_file); |
|---|
| 424 |
|
|---|
| 425 |
if ( ! $deleted ) |
|---|
| 426 |
$errors[] = $plugin_file; |
|---|
| 427 |
} |
|---|
| 428 |
|
|---|
| 429 |
if( ! empty($errors) ) |
|---|
| 430 |
return new WP_Error('could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s'), implode(', ', $errors)) ); |
|---|
| 431 |
|
|---|
| 432 |
return true; |
|---|
| 433 |
} |
|---|
| 434 |
|
|---|
| 435 |
function validate_active_plugins() { |
|---|
| 436 |
$check_plugins = get_option('active_plugins'); |
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 |
// empty array. |
|---|
| 440 |
if ( !is_array($check_plugins) ) { |
|---|
| 441 |
update_option('active_plugins', array()); |
|---|
| 442 |
return; |
|---|
| 443 |
} |
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
$invalid = array(); |
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
// plugins. |
|---|
| 450 |
foreach ( $check_plugins as $check_plugin ) { |
|---|
| 451 |
$result = validate_plugin($check_plugin); |
|---|
| 452 |
if ( is_wp_error( $result ) ) { |
|---|
| 453 |
$invalid[$check_plugin] = $result; |
|---|
| 454 |
deactivate_plugins( $check_plugin, true); |
|---|
| 455 |
} |
|---|
| 456 |
} |
|---|
| 457 |
return $invalid; |
|---|
| 458 |
} |
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
function validate_plugin($plugin) { |
|---|
| 471 |
if ( validate_file($plugin) ) |
|---|
| 472 |
return new WP_Error('plugin_invalid', __('Invalid plugin path.')); |
|---|
| 473 |
if ( ! file_exists(WP_PLUGIN_DIR . '/' . $plugin) ) |
|---|
| 474 |
return new WP_Error('plugin_not_found', __('Plugin file does not exist.')); |
|---|
| 475 |
|
|---|
| 476 |
return 0; |
|---|
| 477 |
} |
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
function is_uninstallable_plugin($plugin) { |
|---|
| 488 |
$file = plugin_basename($plugin); |
|---|
| 489 |
|
|---|
| 490 |
$uninstallable_plugins = (array) get_option('uninstall_plugins'); |
|---|
| 491 |
if ( isset( $uninstallable_plugins[$file] ) || file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) |
|---|
| 492 |
return true; |
|---|
| 493 |
|
|---|
| 494 |
return false; |
|---|
| 495 |
} |
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
function uninstall_plugin($plugin) { |
|---|
| 507 |
$file = plugin_basename($plugin); |
|---|
| 508 |
|
|---|
| 509 |
$uninstallable_plugins = (array) get_option('uninstall_plugins'); |
|---|
| 510 |
if ( file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) { |
|---|
| 511 |
if ( isset( $uninstallable_plugins[$file] ) ) { |
|---|
| 512 |
unset($uninstallable_plugins[$file]); |
|---|
| 513 |
update_option('uninstall_plugins', $uninstallable_plugins); |
|---|
| 514 |
} |
|---|
| 515 |
unset($uninstallable_plugins); |
|---|
| 516 |
|
|---|
| 517 |
define('WP_UNINSTALL_PLUGIN', $file); |
|---|
| 518 |
include WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php'; |
|---|
| 519 |
|
|---|
| 520 |
return true; |
|---|
| 521 |
} |
|---|
| 522 |
|
|---|
| 523 |
if ( isset( $uninstallable_plugins[$file] ) ) { |
|---|
| 524 |
$callable = $uninstallable_plugins[$file]; |
|---|
| 525 |
unset($uninstallable_plugins[$file]); |
|---|
| 526 |
update_option('uninstall_plugins', $uninstallable_plugins); |
|---|
| 527 |
unset($uninstallable_plugins); |
|---|
| 528 |
|
|---|
| 529 |
include WP_PLUGIN_DIR . '/' . $file; |
|---|
| 530 |
|
|---|
| 531 |
add_action( 'uninstall_' . $file, $callable ); |
|---|
| 532 |
do_action( 'uninstall_' . $file ); |
|---|
| 533 |
} |
|---|
| 534 |
} |
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '' ) { |
|---|
| 541 |
global $menu, $admin_page_hooks; |
|---|
| 542 |
|
|---|
| 543 |
$file = plugin_basename( $file ); |
|---|
| 544 |
|
|---|
| 545 |
$admin_page_hooks[$file] = sanitize_title( $menu_title ); |
|---|
| 546 |
|
|---|
| 547 |
$hookname = get_plugin_page_hookname( $file, '' ); |
|---|
| 548 |
if (!empty ( $function ) && !empty ( $hookname )) |
|---|
| 549 |
add_action( $hookname, $function ); |
|---|
| 550 |
|
|---|
| 551 |
if ( empty($icon_url) ) |
|---|
| 552 |
$icon_url = 'images/generic.png'; |
|---|
| 553 |
|
|---|
| 554 |
$menu[] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); |
|---|
| 555 |
|
|---|
| 556 |
|
|---|