mirror of
https://ghproxy.net/https://github.com/elementor/wp2static.git
synced 2025-09-08 10:40:37 +08:00
WIP separate ajaxy generation function
This commit is contained in:
parent
e639e9e775
commit
5e54a11709
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'));
|
||||
}
|
||||
|
||||
|
@ -186,6 +192,7 @@ class StaticHtmlOutput
|
|||
->assign('ftpRemotePath', $this->_options->getOption('ftpRemotePath'))
|
||||
->assign('onceAction', self::HOOK . '-options')
|
||||
->render();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,8 +230,17 @@ 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,6 +259,8 @@ class StaticHtmlOutput
|
|||
}
|
||||
}
|
||||
|
||||
echo 'Archive has been created... log...';
|
||||
/*
|
||||
$this->_view->setTemplate('message')
|
||||
->assign('message', $message)
|
||||
->render();
|
||||
|
|
|
@ -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