function bfox_tool_content_ajax() { header('Content-Type: application/json'); $context = $_REQUEST['context']; if (empty($context)) { echo json_encode(array('html' => 'Invalid Context')); exit; } if (!wp_verify_nonce($_REQUEST['nonce'], 'bfox-tool-context-' . $context)) { echo json_encode(array('html' => 'Context failed nonce verification')); exit; } bfox_tool_update_ref_str(urldecode($_REQUEST['ref'])); bfox_tool_update_tool(urldecode($_REQUEST['tool'])); if (!empty($_REQUEST['id'])) { // Bible links update the same id that was just updated push_bfox_ref_link_defaults(bfox_ref_link_defaults_update_selector('#' . $_REQUEST['id'])); } ob_start(); load_bfox_template('content-bfox_tool'); $html = ob_get_clean(); $nonce = bfox_tool_context_nonce($context); $response = json_encode(array('html' => $html, 'dataUrl' => bfox_tool_context_ajax_url($context, $nonce), 'nonce' => $nonce)); echo $response; exit; }
function bfox_tool_context_ajax_url($context, $nonce = '') { if (empty($nonce)) { $nonce = bfox_tool_context_nonce($context); } $url = add_query_arg(array('action' => 'bfox-tool-content', 'context' => $context, 'nonce' => $nonce), admin_url('admin-ajax.php')); return $url; }