Confirm Action

How to implement a confirmation dialog with actions?

 

 

Minimal Implementation:
public function __construct() {
		new ActionType("my_action_confirm", $this, Constants::CALLBACK_TYPE_STRING);
	}


	/**
	 * The execute callback function from the AJAX Call wr_ajax_process_entry.
	 *
	 * @return string
	 */
	public function execute_callback() : string {
		//Get Payload from Post
		$payload = $_POST['data'];

		// Change action to my_action
		$payload['action'] = "my_action";

		return "<script>
					let config = new ConfirmObject('" . __('Attention!', 'wonderful-relations') . "', 'red', '" . __('Delete all Formidable Entries and Rebuild it?', 'wonderful-relations') . "');
					config.addButton('cancel', '" . __('Abort', 'wonderful-relations') . "', function() {});
					config.addAjaxButton('confirm', '" . __('Yes', 'wonderful-relations') . "', ". wp_json_encode($payload) .");
					console.log(config.getJQueryConfirmConfig());
					jQuery.confirm(config.getJQueryConfirmConfig());
				</script>";
	}