AnsPress_Admin_Ajax::ap_toggle_addon()

Description #

Toggle addons.

Source #

File: admin/ajax.php

	public static function ap_toggle_addon() {
		check_ajax_referer( 'toggle_addon', '__nonce' );

		if ( ! current_user_can( 'manage_options' ) ) {
			ap_ajax_json(
				array(
					'success'  => false,
					'snackbar' => array( 'message' => __( 'Sorry, you do not have permission!', 'anspress-question-answer' ) ),
				)
			);
		}

		$addon_id = ap_sanitize_unslash( 'addon_id', 'r' );
		if ( ap_is_addon_active( $addon_id ) ) {
			$message = __( 'Successfully disabled addon. Redirecting!', 'anspress-question-answer' );
			ap_deactivate_addon( $addon_id );
		} else {
			$message = __( 'Successfully enabled addon. Redirecting!', 'anspress-question-answer' );
			ap_activate_addon( $addon_id );
		}

		// Delete page check transient.
		delete_transient( 'ap_pages_check' );

		ap_ajax_json(
			array(
				'success'  => true,
				'addon_id' => $addon_id,
				'snackbar' => array( 'message' => $message ),
				'cb'       => 'toggleAddon',
			)
		);
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment