Example #1
0
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;
}
?>

		<p>Add more bible references by typing them into the post, or adding them to the post tags.</p>

		<div id="bible-form" class="bfox-tool-form">
			<input type="text" id="bfox-tool-ref-global" class="field bfox-tool-ref bfox-tool-ref-refresh" name="ref" placeholder="<?php 
esc_attr_e('Search');
?>
" value="<?php 
echo bfox_ref_str(BibleMeta::name_short);
?>
" />
			<select class="bfox-tool-name" id="bfox-tool-name-main" name="tool"><?php 
echo bfox_tool_select_options();
?>
</select>
		</div>

		<div class="depends-bfox-tool-ref-global depends-bfox-tool-name-main" data-url="<?php 
echo bfox_tool_context_ajax_url('main');
?>
">
			<?php 
/* Content loaded later by AJAX (speeds up page load) */
// load_bfox_template('content-bfox_tool');
?>
		</div>

	<?php 
pop_bfox_ref_link_defaults();
// #bfox-tool-ref-global