mirror of
https://ghproxy.net/https://github.com/elementor/wp2static.git
synced 2025-09-07 22:46:25 +08:00
WIP saving all form data to backend
This commit is contained in:
parent
1402ae939c
commit
d279786f39
2 changed files with 23 additions and 27 deletions
|
@ -181,12 +181,14 @@ class StaticHtmlOutput
|
|||
}
|
||||
else
|
||||
{
|
||||
error_log('about to do saveOptions hook');
|
||||
|
||||
do_action(self::HOOK . '-saveOptions');
|
||||
|
||||
$this->_view
|
||||
->setTemplate('options-page')
|
||||
->assign('exportLog', $this->_exportLog)
|
||||
->assign('staticExportOption', $this->_options->getOption('static-export-options'))
|
||||
->assign('staticExportSettings', $this->_options->getOption('static-export-settings'))
|
||||
/*
|
||||
->assign('baseUrl', $this->_options->getOption('baseUrl'))
|
||||
->assign('additionalUrls', $this->_options->getOption('additionalUrls'))
|
||||
|
@ -209,17 +211,22 @@ class StaticHtmlOutput
|
|||
*/
|
||||
public function saveOptions()
|
||||
{
|
||||
error_log('saveOptions');
|
||||
// Protection
|
||||
if (!isset($_POST['action']) || 'generate' != $_POST['action'])
|
||||
{
|
||||
error_log('didnt detect the generate action');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!check_admin_referer(self::HOOK . '-options') || !current_user_can('manage_options'))
|
||||
{
|
||||
error_log('user didnt have permissions to change options');
|
||||
exit('You cannot change WP Static HTML Output Plugin options.');
|
||||
}
|
||||
|
||||
|
||||
error_log('met conditions, starting to save');
|
||||
|
||||
// Save options
|
||||
$this->_options
|
||||
->setOption('static-export-settings', filter_input(INPUT_POST, 'staticExportSettings', FILTER_SANITIZE_URL))
|
||||
|
@ -235,6 +242,8 @@ class StaticHtmlOutput
|
|||
*/
|
||||
->save();
|
||||
|
||||
error_log('saving options!!!');
|
||||
|
||||
$message = 'Options have been updated successfully.';
|
||||
|
||||
$this->_view->setTemplate('message')
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
*
|
||||
* Copyright (c) 2011 Leon Stafford
|
||||
*/
|
||||
|
||||
error_log('loading options page');
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
@ -71,32 +73,17 @@ jQuery(document).ready(function($){
|
|||
console.log('number of archives: ' + numberOfArchives);
|
||||
|
||||
|
||||
var newSettings = {};
|
||||
$(".options-form").serializeArray().map(function(x){newSettings[x.name] = x.value;});
|
||||
//var newSettings = {};
|
||||
//$(".options-form").serializeArray().map(function(x){newSettings[x.name] = x.value;});
|
||||
var newSettings = $(".options-form").serialize();
|
||||
|
||||
console.log(newSettings);
|
||||
|
||||
// stick json encoded settings into hidden field within form(s)
|
||||
$(".hiddenSettingsField").val(newSettings);
|
||||
|
||||
// base data on first form, so as to include nonces
|
||||
data = $(archives[0]).serialize();
|
||||
|
||||
|
||||
console.log(data);
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
data: data,
|
||||
dataType: 'html',
|
||||
method: 'POST',
|
||||
success: function(serverResponse) {
|
||||
console.log('options saved');
|
||||
$('#results').append(serverResponse);
|
||||
}
|
||||
});
|
||||
|
||||
$('#progress').hide();
|
||||
// just submit form as usual
|
||||
$(archives[0]).submit();
|
||||
}
|
||||
|
||||
$('#generateArchiveButton').click(function() {
|
||||
|
@ -112,22 +99,22 @@ jQuery(document).ready(function($){
|
|||
//$('#formActionHiddenField').val('generate')
|
||||
});
|
||||
|
||||
$('#saveSettingsButton').click(function() {
|
||||
$('.wrap').on('click', '.saveSettingsButton', function(event) {
|
||||
// TODO: needed prevention?
|
||||
event.preventDefault();
|
||||
|
||||
$('#progress').show();
|
||||
|
||||
saveOptions();
|
||||
|
||||
$('#results').html('');
|
||||
|
||||
});
|
||||
|
||||
// TODO: set to on body event with button class as target, else need to reattach handler!
|
||||
$('.wrap').on('click', '.addAnotherTargetButton', function(event) {
|
||||
// TODO: needed prevention?
|
||||
event.preventDefault();
|
||||
|
||||
// check for max of 5 forms (in DB)
|
||||
|
||||
// append copy of form below current one
|
||||
$('.options-form:last').clone().insertAfter('.options-form:last');
|
||||
|
||||
|
@ -210,7 +197,7 @@ jQuery(document).ready(function($){
|
|||
<?php wp_nonce_field($this->onceAction) ?>
|
||||
<input id="formActionHiddenField" class="hiddenActionField" type="hidden" name="action" value="generate" />
|
||||
<input name="staticExportSettings" class="hiddenSettingsField" type="hidden" name="action" value="" />
|
||||
<input id="saveSettingsButton" class="button-primary" value="Save current options" />
|
||||
<input class="saveSettingsButton button-primary" value="Save current options" />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue