BSF_Extension_Installer::activate_plugin()

Activates plugin.


Description


Return

(void)


Source

File: admin/bsf-core/classes/class-bsf-extension-installer.php

	public function activate_plugin() {

		if ( ! wp_verify_nonce( $_POST['security'], 'bsf_activate_extension_nonce' ) ) {

			wp_send_json_error(
				array(
					'success' => false,
					'message' => __( 'You are not authorized to perform this action.', 'bsf' ),
				)
			);
		}

		if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['init'] ) || ! $_POST['init'] ) {
			wp_send_json_error(
				array(
					'success' => false,
					'message' => __( 'No plugin specified', 'bsf' ),
				)
			);
		}

		$plugin_init = ( isset( $_POST['init'] ) ) ? esc_attr( $_POST['init'] ) : '';
		$activate    = activate_plugin( $plugin_init, '', false, true );

		if ( is_wp_error( $activate ) ) {
			wp_send_json_error(
				array(
					'success' => false,
					'message' => $activate->get_error_message(),
				)
			);
		}

		wp_send_json_success(
			array(
				'success' => true,
				'message' => __( 'Plugin Activated', 'bsf' ),
			)
		);
	}

User Contributed Notes

You must log in before being able to contribute a note or feedback.