| | 902 | |
| | 903 | $installed_plugin = get_plugins( '/' . $api->slug ); |
| | 904 | $key = array_keys( $installed_plugin ); |
| | 905 | // Use the first plugin regardless of the name. |
| | 906 | // Could have issues for multiple plugins in one directory if they share different version numbers. |
| | 907 | $key = reset( $key ); |
| | 908 | $plugin_file = $api->slug . '/' . $key; |
| | 909 | |
| | 910 | if ( is_network_admin() ) { |
| | 911 | $is_active = is_plugin_active_for_network( $plugin_file ); |
| | 912 | } else { |
| | 913 | $is_active = is_plugin_active( $plugin_file ); |
| | 914 | } |
| | 915 | $link = ''; |
| | 916 | if ( ! $is_active && $installed_plugin && current_user_can( 'activate_plugin', $plugin_file ) ) { |
| | 917 | if ( $compatible_php && $compatible_wp ) { |
| | 918 | $button_label = _x( 'Activate', 'plugin' ); |
| | 919 | $activate_url = add_query_arg( |
| | 920 | array( |
| | 921 | '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $status['file'] ), |
| | 922 | 'action' => 'activate', |
| | 923 | 'plugin' => $plugin_file, |
| | 924 | ), |
| | 925 | network_admin_url( 'plugins.php' ) |
| | 926 | ); |
| | 927 | |
| | 928 | if ( is_network_admin() ) { |
| | 929 | $button_label = _x( 'Network Activate', 'plugin' ); |
| | 930 | $activate_url = add_query_arg( array( 'networkwide' => 1 ), $activate_url ); |
| | 931 | } |
| | 932 | |
| | 933 | $link = sprintf( |
| | 934 | '<a href="%1$s" class="button right activate-now" target="_parent">%2$s</a>', |
| | 935 | esc_url( $activate_url ), |
| | 936 | $button_label |
| | 937 | ); |
| | 938 | } else { |
| | 939 | $link = sprintf( |
| | 940 | '<button type="button" class="button right button-disabled" disabled="disabled">%s</button>', |
| | 941 | _x( 'Cannot Activate', 'plugin' ) |
| | 942 | ); |
| | 943 | } |
| | 944 | } |
| | 945 | echo $link; |