mirror of
https://ghproxy.net/https://github.com/elementor/wp2static.git
synced 2025-08-30 13:43:54 +08:00
WIP separate ajaxy generation function
This commit is contained in:
parent
2dda2c07b2
commit
547e3bf2d6
3 changed files with 54 additions and 24 deletions
|
@ -132,7 +132,13 @@ class StaticHtmlOutput
|
|||
*/
|
||||
public function registerOptionsPage()
|
||||
{
|
||||
/*
|
||||
add_submenu_page( string $parent_slug, string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '' )
|
||||
*/
|
||||
$page = add_submenu_page('tools.php', __('WP Static HTML Output', 'static-html-output-plugin'), __('WP Static HTML Output', 'static-html-output-plugin'), 'manage_options', self::HOOK . '-options', array($this, 'renderOptionsPage'));
|
||||
/*
|
||||
add_action( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 )
|
||||
*/
|
||||
add_action('admin_print_styles-' . $page, array($this, 'enqueueAdminStyles'));
|
||||
}
|
||||
|
||||
|
@ -172,20 +178,21 @@ class StaticHtmlOutput
|
|||
else
|
||||
{
|
||||
do_action(self::HOOK . '-saveOptions');
|
||||
|
||||
$this->_view
|
||||
->setTemplate('options-page')
|
||||
->assign('exportLog', $this->_exportLog)
|
||||
->assign('baseUrl', $this->_options->getOption('baseUrl'))
|
||||
->assign('additionalUrls', $this->_options->getOption('additionalUrls'))
|
||||
->assign('cleanMeta', $this->_options->getOption('cleanMeta'))
|
||||
->assign('retainStaticFiles', $this->_options->getOption('retainStaticFiles'))
|
||||
->assign('sendViaFTP', $this->_options->getOption('sendViaFTP'))
|
||||
->assign('ftpServer', $this->_options->getOption('ftpServer'))
|
||||
->assign('ftpUsername', $this->_options->getOption('ftpUsername'))
|
||||
->assign('ftpRemotePath', $this->_options->getOption('ftpRemotePath'))
|
||||
->assign('onceAction', self::HOOK . '-options')
|
||||
->render();
|
||||
|
||||
$this->_view
|
||||
->setTemplate('options-page')
|
||||
->assign('exportLog', $this->_exportLog)
|
||||
->assign('baseUrl', $this->_options->getOption('baseUrl'))
|
||||
->assign('additionalUrls', $this->_options->getOption('additionalUrls'))
|
||||
->assign('cleanMeta', $this->_options->getOption('cleanMeta'))
|
||||
->assign('retainStaticFiles', $this->_options->getOption('retainStaticFiles'))
|
||||
->assign('sendViaFTP', $this->_options->getOption('sendViaFTP'))
|
||||
->assign('ftpServer', $this->_options->getOption('ftpServer'))
|
||||
->assign('ftpUsername', $this->_options->getOption('ftpUsername'))
|
||||
->assign('ftpRemotePath', $this->_options->getOption('ftpRemotePath'))
|
||||
->assign('onceAction', self::HOOK . '-options')
|
||||
->render();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,9 +230,18 @@ class StaticHtmlOutput
|
|||
$this->_view->setTemplate('message')
|
||||
->assign('message', $message)
|
||||
->render();
|
||||
}
|
||||
|
||||
/*
|
||||
public function genArch()
|
||||
{
|
||||
|
||||
// Protection
|
||||
if (!isset($_POST['action']) || 'genArchive' != $_POST['action'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Generate archive
|
||||
$archiveUrl = $this->_generateArchive();
|
||||
|
||||
|
@ -243,11 +259,13 @@ class StaticHtmlOutput
|
|||
}
|
||||
}
|
||||
|
||||
echo 'Archive has been created... log...';
|
||||
/*
|
||||
$this->_view->setTemplate('message')
|
||||
->assign('message', $message)
|
||||
->render();
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates ZIP archive
|
||||
|
|
|
@ -10,14 +10,18 @@
|
|||
jQuery(document).ready(function($){
|
||||
$('#generateArchiveButton').click(function() {
|
||||
console.log('Generating archive...');
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '',
|
||||
data: $('#general-options').serialize(),
|
||||
success: function(response) {
|
||||
|
||||
// set form action for generation vs saving options
|
||||
$('#formActionHiddenField').val('my_action')
|
||||
|
||||
data = $('#general-options').serialize();
|
||||
|
||||
jQuery.post(ajaxurl, data, function(response) {
|
||||
$('#results').html(response);
|
||||
}
|
||||
});
|
||||
|
||||
// revert form action for saving options vs generation
|
||||
$('#formActionHiddenField').val('generate')
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
@ -98,7 +102,7 @@ jQuery(document).ready(function($){
|
|||
|
||||
<p class="submit">
|
||||
<?php wp_nonce_field($this->onceAction) ?>
|
||||
<input type="hidden" name="action" value="generate" />
|
||||
<input id="formActionHiddenField" type="hidden" name="action" value="generate" />
|
||||
<input class="button-primary" type="submit" name="submit" value="Save current options" />
|
||||
</p>
|
||||
</div>
|
||||
|
@ -121,7 +125,6 @@ jQuery(document).ready(function($){
|
|||
|
||||
<p class="submit">
|
||||
<?php wp_nonce_field($this->onceAction) ?>
|
||||
<input type="hidden" name="action" value="generate" />
|
||||
<input id="generateArchiveButton" class="button-primary" value="Start static site export (AJAX)" />
|
||||
</p>
|
||||
</p>
|
||||
|
|
|
@ -42,3 +42,12 @@ function myplugin_init() {
|
|||
load_plugin_textdomain( 'static-html-output-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
||||
}
|
||||
add_action('plugins_loaded', 'myplugin_init');
|
||||
|
||||
add_action( 'wp_ajax_my_action', 'my_action_callback' );
|
||||
|
||||
function my_action_callback() {
|
||||
|
||||
echo 'some response this is!';
|
||||
|
||||
wp_die(); // this is required to terminate immediately and return a proper response
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue