| 2924 | | if ( ! is_multisite() ) { |
| 2925 | | activate_plugin( $plugin_status['file'] ); |
| | 2929 | $url = admin_url( 'admin-ajax.php' ); |
| | 2930 | $args = array( |
| | 2931 | /** This filter is documented in wp-includes/class-http.php */ |
| | 2932 | 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), |
| | 2933 | 'body' => array( |
| | 2934 | 'action' => 'activate-plugin', |
| | 2935 | 'nonce' => wp_create_nonce( 'ajax-activate-plugin_' . $plugin ), |
| | 2936 | 'plugin' => $plugin, |
| | 2937 | ), |
| | 2938 | 'cookies' => array( |
| | 2939 | AUTH_COOKIE => $_COOKIE[ AUTH_COOKIE ], |
| | 2940 | LOGGED_IN_COOKIE => $_COOKIE[ LOGGED_IN_COOKIE ], |
| | 2941 | ), |
| | 2942 | ); |
| | 2943 | |
| | 2944 | if ( isset( $_COOKIE[ SECURE_AUTH_COOKIE ] ) ) { |
| | 2945 | $args['cookies'][ SECURE_AUTH_COOKIE ] = $_COOKIE[ SECURE_AUTH_COOKIE ]; |
| | 2948 | $response = wp_remote_post( $url, $args ); |
| | 2949 | |
| | 2950 | if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) { |
| | 2951 | $status['error'] = __( 'Could not activate plugin.' ); |
| | 2952 | wp_send_json_error( $status ); |
| | 2953 | } |
| | 2954 | |
| | 2955 | $body = wp_remote_retrieve_body( $response ); |
| | 2956 | $activate_result = json_decode( $body ); |
| | 2957 | |
| | 2958 | if ( null === $activate_result ) { |
| | 2959 | $status['error'] = __( 'Could not activate plugin.' ); |
| | 2960 | wp_send_json_error( $status ); |
| | 2961 | } |
| | 2962 | |
| | 2963 | if ( false === $activate_result->success ) { |
| | 2964 | $status['error'] = $activate_result->data; |
| | 2965 | wp_send_json_error( $status ); |
| | 2966 | } |
| | 2967 | |
| | 2968 | $url = admin_url( 'plugin-install.php' ); |
| | 2969 | $args = array( |
| | 2970 | /** This filter is documented in wp-includes/class-http.php */ |
| | 2971 | 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), |
| | 2972 | 'cookies' => array( |
| | 2973 | AUTH_COOKIE => $_COOKIE[ AUTH_COOKIE ], |
| | 2974 | LOGGED_IN_COOKIE => $_COOKIE[ LOGGED_IN_COOKIE ], |
| | 2975 | ), |
| | 2976 | ); |
| | 2977 | |
| | 2978 | if ( isset( $_COOKIE[ SECURE_AUTH_COOKIE ] ) ) { |
| | 2979 | $args['cookies'][ SECURE_AUTH_COOKIE ] = $_COOKIE[ SECURE_AUTH_COOKIE ]; |
| | 2980 | } |
| | 2981 | |
| | 2982 | $response = wp_remote_get( $url, $args ); |
| | 2983 | |
| | 2984 | if ( ! is_wp_error( $response ) && 200 == wp_remote_retrieve_response_code( $response ) ) { |
| | 2985 | $body = wp_remote_retrieve_body( $response ); |
| | 2986 | list( $ignore, $menu ) = explode( '<div id="adminmenuwrap">', $body ); |
| | 2987 | list( $menu, $ignore ) = explode( '<div id="wpcontent">', $menu ); |
| | 2988 | $menu = preg_replace( '|</div>\s+$|', '', $menu ); |
| | 2989 | |
| | 2990 | $status['menu'] = $menu; |
| | 2991 | } |
| | 2992 | |
| | 2997 | * AJAX handler for activating a plugin. |
| | 2998 | * |
| | 2999 | * @since 4.2.0 |
| | 3000 | */ |
| | 3001 | function wp_ajax_activate_plugin() { |
| | 3002 | $plugin = $_POST['plugin']; |
| | 3003 | |
| | 3004 | $verify = wp_verify_nonce( $_POST['nonce'], 'ajax-activate-plugin_' . $plugin ); |
| | 3005 | |
| | 3006 | if ( ! $verify ) { |
| | 3007 | wp_send_json_error( __( 'Could not activate plugin.' ) ); |
| | 3008 | } |
| | 3009 | |
| | 3010 | include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
| | 3011 | |
| | 3012 | $result = activate_plugin( $plugin ); |
| | 3013 | |
| | 3014 | if ( is_wp_error( $result ) ) { |
| | 3015 | wp_send_json_error( $result->get_error_message() ); |
| | 3016 | } |
| | 3017 | |
| | 3018 | wp_send_json_success( true ); |
| | 3019 | } |
| | 3020 | |
| | 3021 | /** |