| 368 | function get_plugin_actions( $plugin_file ) { |
| 369 | global $status; |
| 370 | |
| 371 | $args = wp_parse_args( $args, array( |
| 372 | 'plural' => '', |
| 373 | 'singular' => '', |
| 374 | 'ajax' => false, |
| 375 | 'screen' => null, |
| 376 | ) ); |
| 377 | |
| 378 | $screen = convert_to_screen( $args[ 'screen' ] ); |
| 379 | $context = $status; |
| 380 | // Do not restrict by default |
| 381 | $restrict_network_active = false; |
| 382 | $restrict_network_only = false; |
| 383 | |
| 384 | if ( 'mustuse' === $context ) { |
| 385 | $is_active = true; |
| 386 | } elseif ( 'dropins' === $context ) { |
| 387 | $dropins = _get_dropins(); |
| 388 | $plugin_name = $plugin_file; |
| 389 | if ( $plugin_file != $plugin_data[ 'Name' ] ) |
| 390 | $plugin_name .= '<br/>' . $plugin_data[ 'Name' ]; |
| 391 | |
| 392 | if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant |
| 393 | $is_active = true; |
| 394 | $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; |
| 395 | } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true |
| 396 | $is_active = true; |
| 397 | $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; |
| 398 | } else { |
| 399 | $is_active = false; |
| 400 | $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="error-message">' . __( 'Inactive:' ) . '</span></strong> ' . |
| 401 | /* translators: 1: drop-in constant name, 2: wp-config.php */ |
| 402 | sprintf( __( 'Requires %1$s in %2$s file.' ), |
| 403 | "<code>define('" . $dropins[ $plugin_file ][1] . "', true);</code>", |
| 404 | '<code>wp-config.php</code>' |
| 405 | ) . '</p>'; |
| 406 | } |
| 407 | |
| 408 | if ( $plugin_data[ 'Description' ] ) |
| 409 | $description .= '<p>' . $plugin_data[ 'Description' ] . '</p>'; |
| 410 | } else { |
| 411 | |
| 412 | if ( $screen->in_admin( 'network' ) ) { |
| 413 | $is_active = is_plugin_active_for_network( $plugin_file ); |
| 414 | } else { |
| 415 | $is_active = is_plugin_active( $plugin_file ); |
| 416 | $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) ); |
| 417 | $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active ); |
| 418 | } |
| 419 | |
| 420 | if ( $screen->in_admin( 'network' ) ) { |
| 421 | if ( $is_active ) { |
| 422 | if ( current_user_can( 'manage_network_plugins' ) ) { |
| 423 | /* translators: %s: plugin name */ |
| 424 | $actions[ 'deactivate' ] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Network Deactivate' ) . '</a>'; |
| 425 | } |
| 426 | } else { |
| 427 | if ( current_user_can( 'manage_network_plugins' ) ) { |
| 428 | $button_text = __( 'Activate' ); |
| 429 | /* translators: %s: Plugin name */ |
| 430 | $button_label = _x( 'Activate %s', 'plugin' ); |
| 431 | $activate_url = add_query_arg( array( |
| 432 | '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ), |
| 433 | 'action' => 'activate', |
| 434 | 'plugin' => $status['file'], |
| 435 | ), network_admin_url( 'plugins.php' ) ); |
| 436 | |
| 437 | if ( is_network_admin() ) { |
| 438 | $button_text = __( 'Network Activate' ); |
| 439 | /* translators: %s: Plugin name */ |
| 440 | $button_label = _x( 'Network Activate %s', 'plugin' ); |
| 441 | $activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url ); |
| 442 | } |
| 443 | |
| 444 | $actions['deactivate'] = sprintf( |
| 445 | '<a href="%1$s" class="button activate-now" aria-label="%2$s">%3$s</a>', |
| 446 | esc_url( $activate_url ), |
| 447 | esc_attr( sprintf( $button_label, $plugin['name'] ) ), |
| 448 | $button_text |
| 449 | ); |
| 450 | } |
| 451 | if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) { |
| 452 | /* translators: %s: plugin name */ |
| 453 | $actions[ 'delete' ] = '<a href="' . wp_nonce_url( 'plugins.php?action=delete-selected&checked[]=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins' ) . '" class="delete" aria-label="' . esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>'; |
| 454 | } |
| 455 | } |
| 456 | } else { |
| 457 | if ( $restrict_network_active ) { |
| 458 | $actions = array( |
| 459 | 'network_active' => __( 'Network Active' ), |
| 460 | ); |
| 461 | } elseif ( $restrict_network_only ) { |
| 462 | $actions = array( |
| 463 | 'network_only' => __( 'Network Only' ), |
| 464 | ); |
| 465 | } elseif ( $is_active ) { |
| 466 | if ( current_user_can( 'deactivate_plugin', $plugin_file ) ) { |
| 467 | /* translators: %s: plugin name */ |
| 468 | $actions[ 'deactivate' ] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( _x( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Deactivate' ) . '</a>'; |
| 469 | } |
| 470 | } else { |
| 471 | if ( current_user_can( 'activate_plugin', $plugin_file ) ) { |
| 472 | /* translators: %s: plugin name */ |
| 473 | $actions[ 'activate' ] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Activate' ) . '</a>'; |
| 474 | } |
| 475 | |
| 476 | if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) { |
| 477 | /* translators: %s: plugin name */ |
| 478 | $actions[ 'delete' ] = '<a href="' . wp_nonce_url( 'plugins.php?action=delete-selected&checked[]=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins' ) . '" class="delete" aria-label="' . esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ) . '">' . __( 'Delete' ) . '</a>'; |
| 479 | } |
| 480 | } // end if $is_active |
| 481 | |
| 482 | } // end if $screen->in_admin( 'network' ) |
| 483 | |
| 484 | } // end if $context |
| 485 | |
| 486 | $actions = array_filter( $actions ); |
| 487 | |
| 488 | if ( $screen->in_admin( 'network' ) ) { |
| 489 | |
| 490 | /** |
| 491 | * Filters the action links displayed for each plugin in the Network Admin Plugins list table. |
| 492 | * |
| 493 | * @since 3.1.0 |
| 494 | * |
| 495 | * @param array $actions An array of plugin action links. By default this can include 'activate', |
| 496 | * 'deactivate', and 'delete'. |
| 497 | * @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 498 | * @param array $plugin_data An array of plugin data. See `get_plugin_data()`. |
| 499 | * @param string $context The plugin context. By default this can include 'all', 'active', 'inactive', |
| 500 | * 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'. |
| 501 | */ |
| 502 | $actions = apply_filters( 'network_admin_plugin_action_links', $actions, $plugin_file, $plugin_data, $context ); |
| 503 | |
| 504 | /** |
| 505 | * Filters the list of action links displayed for a specific plugin in the Network Admin Plugins list table. |
| 506 | * |
| 507 | * The dynamic portion of the hook name, `$plugin_file`, refers to the path |
| 508 | * to the plugin file, relative to the plugins directory. |
| 509 | * |
| 510 | * @since 3.1.0 |
| 511 | * |
| 512 | * @param array $actions An array of plugin action links. By default this can include 'activate', |
| 513 | * 'deactivate', and 'delete'. |
| 514 | * @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 515 | * @param array $plugin_data An array of plugin data. See `get_plugin_data()`. |
| 516 | * @param string $context The plugin context. By default this can include 'all', 'active', 'inactive', |
| 517 | * 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'. |
| 518 | */ |
| 519 | $actions = apply_filters( "network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context ); |
| 520 | |
| 521 | } else { |
| 522 | |
| 523 | /** |
| 524 | * Filters the action links displayed for each plugin in the Plugins list table. |
| 525 | * |
| 526 | * @since 2.5.0 |
| 527 | * @since 2.6.0 The `$context` parameter was added. |
| 528 | * @since 4.9.0 The 'Edit' link was removed from the list of action links. |
| 529 | * |
| 530 | * @param array $actions An array of plugin action links. By default this can include 'activate', |
| 531 | * 'deactivate', and 'delete'. With Multisite active this can also include |
| 532 | * 'network_active' and 'network_only' items. |
| 533 | * @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 534 | * @param array $plugin_data An array of plugin data. See `get_plugin_data()`. |
| 535 | * @param string $context The plugin context. By default this can include 'all', 'active', 'inactive', |
| 536 | * 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'. |
| 537 | */ |
| 538 | $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context ); |
| 539 | |
| 540 | /** |
| 541 | * Filters the list of action links displayed for a specific plugin in the Plugins list table. |
| 542 | * |
| 543 | * The dynamic portion of the hook name, `$plugin_file`, refers to the path |
| 544 | * to the plugin file, relative to the plugins directory. |
| 545 | * |
| 546 | * @since 2.7.0 |
| 547 | * @since 4.9.0 The 'Edit' link was removed from the list of action links. |
| 548 | * |
| 549 | * @param array $actions An array of plugin action links. By default this can include 'activate', |
| 550 | * 'deactivate', and 'delete'. With Multisite active this can also include |
| 551 | * 'network_active' and 'network_only' items. |
| 552 | * @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 553 | * @param array $plugin_data An array of plugin data. See `get_plugin_data()`. |
| 554 | * @param string $context The plugin context. By default this can include 'all', 'active', 'inactive', |
| 555 | * 'recently_activated', 'upgrade', 'mustuse', 'dropins', and 'search'. |
| 556 | */ |
| 557 | $actions = apply_filters( "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context ); |
| 558 | |
| 559 | } |
| 560 | |
| 561 | return $actions; |
| 562 | } |