move settings to template
This commit is contained in:
@@ -77,10 +77,10 @@ function go_form_get_forms()
|
|||||||
return $wpdb->get_results("SELECT * FROM {$wpdb->prefix}go_form_forms ORDER BY created_at DESC");
|
return $wpdb->get_results("SELECT * FROM {$wpdb->prefix}go_form_forms ORDER BY created_at DESC");
|
||||||
}
|
}
|
||||||
|
|
||||||
function go_form_get_form_name($id) {
|
function go_form_get_form_by_id($id)
|
||||||
|
{
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$form = $wpdb->get_row($wpdb->prepare("SELECT name FROM {$wpdb->prefix}go_form_forms WHERE id = %d", $id));
|
return $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}go_form_forms WHERE id = %d", intval($id)));
|
||||||
return $form ? $form->name : 'Unknown Form';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function go_form_get_entries($form_id)
|
function go_form_get_entries($form_id)
|
||||||
@@ -148,10 +148,16 @@ add_action('admin_post_go_form_handle_submission', 'go_form_handle_submission');
|
|||||||
function go_form_shortcode($atts)
|
function go_form_shortcode($atts)
|
||||||
{
|
{
|
||||||
global $ranks;
|
global $ranks;
|
||||||
$form_id = intval(shortcode_atts(['id' => 1], $atts)['id']);
|
$form_id = intval($atts['id']);
|
||||||
|
|
||||||
|
$form = go_form_get_form_by_id($form_id);
|
||||||
ob_start();
|
ob_start();
|
||||||
|
if ($form) {
|
||||||
include 'templates/form-shortcode.php';
|
include 'templates/form-shortcode.php';
|
||||||
|
} else {
|
||||||
|
echo '<p>WRONG FORM ID</p>';
|
||||||
|
}
|
||||||
|
|
||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
}
|
}
|
||||||
add_shortcode('go_form', 'go_form_shortcode');
|
add_shortcode('go_form', 'go_form_shortcode');
|
||||||
@@ -228,7 +234,8 @@ function go_form_export()
|
|||||||
}
|
}
|
||||||
|
|
||||||
$form_id = intval($_POST['value_one']);
|
$form_id = intval($_POST['value_one']);
|
||||||
$form_name = go_form_get_form_name($form_id);
|
$form = go_form_get_form_by_id($form_id);
|
||||||
|
$form_name = $form ? $form->name : 'Unknown Form';
|
||||||
$entries = go_form_get_entries($form_id);
|
$entries = go_form_get_entries($form_id);
|
||||||
|
|
||||||
header('Content-Type: text/csv; charset=utf-8');
|
header('Content-Type: text/csv; charset=utf-8');
|
||||||
@@ -269,69 +276,14 @@ function action_button($action, $name, $confirm_massage, $value_one)
|
|||||||
{
|
{
|
||||||
echo '
|
echo '
|
||||||
<form method="post" action="' . admin_url('admin-post.php') . '">
|
<form method="post" action="' . admin_url('admin-post.php') . '">
|
||||||
'. wp_nonce_field($action . '_action', $action . '_nonce', true, false) .'
|
' . wp_nonce_field($action . '_action', $action . '_nonce', true, false) . '
|
||||||
<input type="hidden" name="action" value="'.$action.'">
|
<input type="hidden" name="action" value="' . $action . '">
|
||||||
<input type="hidden" name="value_one" value="'. $value_one . '">
|
<input type="hidden" name="value_one" value="' . $value_one . '">
|
||||||
<input type="submit" value="'.$name .'" class="button" onclick="return confirm(\''.$confirm_massage .'\')">
|
<input type="submit" value="' . $name . '" class="button" onclick="return confirm(\'' . $confirm_massage . '\')">
|
||||||
</form>';
|
</form>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function go_form_settings_page()
|
function go_form_settings_page()
|
||||||
{
|
{
|
||||||
if (!current_user_can('manage_options'))
|
include_once 'templates/settings-page.php';
|
||||||
wp_die('No access.');
|
|
||||||
|
|
||||||
if (isset($_GET['deleted']))
|
|
||||||
echo '<div class="notice notice-success"><p>Deleted!</p></div>';
|
|
||||||
if (isset($_GET['created']))
|
|
||||||
echo '<div class="notice notice-success"><p>Form created!</p></div>';
|
|
||||||
|
|
||||||
echo '<div class="wrap"><h1>Go Form Settings</h1>
|
|
||||||
|
|
||||||
<h2>Create New Form</h2>
|
|
||||||
<form method="post" action="' . admin_url('admin-post.php') . '">
|
|
||||||
' . wp_nonce_field('go_form_create_form_action', 'go_form_create_form_nonce', true, false) . '
|
|
||||||
<input type="hidden" name="action" value="go_form_create_form">
|
|
||||||
<table class="form-table">
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<label for="form_name">Form Name:</label>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<input type="text" name="form_name" id="form_name" required>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<p class="submit"><input type="submit" class="button button-primary" value="Create Form"></p>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<h2>Manage Forms & Entries</h2>';
|
|
||||||
|
|
||||||
$selected_form_id = isset($_GET['form_id']) ? intval($_GET['form_id']) : 0;
|
|
||||||
if ($selected_form_id) {
|
|
||||||
|
|
||||||
$form_name = go_form_get_form_name($selected_form_id);
|
|
||||||
echo "<h3> $form_name Entries</h3>";
|
|
||||||
echo '<div style="margin-bottom:15px">';
|
|
||||||
|
|
||||||
action_button('go_form_delete_form','Delete Form', 'Delete this form and ALL entries?', $selected_form_id);
|
|
||||||
action_button('go_form_export', 'Export to CSV', 'Confrm Export', $selected_form_id);
|
|
||||||
|
|
||||||
echo '</div>';
|
|
||||||
$entries = go_form_get_entries($selected_form_id);
|
|
||||||
go_form_render_entries_table($entries, true);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$forms = go_form_get_forms();
|
|
||||||
echo '<h3>Forms</h3><ul>';
|
|
||||||
foreach ($forms as $f) {
|
|
||||||
|
|
||||||
$url = add_query_arg(array('page' => 'go-form-settings', 'form_id' => $f->id), admin_url('admin.php'));
|
|
||||||
echo '<li><a href="' . esc_url($url) . '">' . esc_html($f->name) . '</a> <span style="color:#888">(ID: ' . esc_html($f->id) . ')</span> - <small>Shortcode: <code>[go_form id=' . esc_html($f->id) . ']</code></small></li>';
|
|
||||||
}
|
|
||||||
echo '</ul>';
|
|
||||||
|
|
||||||
}
|
|
||||||
echo '</div>';
|
|
||||||
}
|
}
|
||||||
|
|||||||
64
go-form-plugin/templates/settings-page.php
Normal file
64
go-form-plugin/templates/settings-page.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (!current_user_can('manage_options'))
|
||||||
|
wp_die('No access.');
|
||||||
|
|
||||||
|
if (isset($_GET['deleted']))
|
||||||
|
echo '<div class="notice notice-success"><p>Deleted!</p></div>';
|
||||||
|
if (isset($_GET['created']))
|
||||||
|
echo '<div class="notice notice-success"><p>Form created!</p></div>';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="wrap">
|
||||||
|
<h1>Go Form Settings</h1>
|
||||||
|
|
||||||
|
<h2>Create New Form</h2>
|
||||||
|
<form method="post" action=" <?= admin_url('admin-post.php') ?> ">
|
||||||
|
<?= wp_nonce_field('go_form_create_form_action', 'go_form_create_form_nonce', true, false) ?>
|
||||||
|
<input type="hidden" name="action" value="go_form_create_form">
|
||||||
|
<table class="form-table">
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<label for="form_name">Form Name:</label>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="form_name" id="form_name" required>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<p class="submit"><input type="submit" class="button button-primary" value="Create Form"></p>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2>Manage Forms & Entries</h2>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$selected_form_id = isset($_GET['form_id']) ? intval($_GET['form_id']) : 0;
|
||||||
|
if ($selected_form_id) {
|
||||||
|
|
||||||
|
$form = go_form_get_form_by_id($selected_form_id);
|
||||||
|
$form_name = $form ? $form->name : 'Unknown Form';
|
||||||
|
echo "<h3> $form_name</h3>";
|
||||||
|
echo '<div style="margin-bottom:15px">';
|
||||||
|
|
||||||
|
action_button('go_form_delete_form', 'Delete Form', 'Delete this form and ALL entries?', $selected_form_id);
|
||||||
|
action_button('go_form_export', 'Export to CSV', 'Confrm Export', $selected_form_id);
|
||||||
|
|
||||||
|
echo '</div>';
|
||||||
|
$entries = go_form_get_entries($selected_form_id);
|
||||||
|
go_form_render_entries_table($entries, true);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$forms = go_form_get_forms();
|
||||||
|
echo '<h3>Forms</h3><ul>';
|
||||||
|
foreach ($forms as $f) {
|
||||||
|
|
||||||
|
$url = add_query_arg(array('page' => 'go-form-settings', 'form_id' => $f->id), admin_url('admin.php'));
|
||||||
|
echo '<li><a href="' . esc_url($url) . '">' . esc_html($f->name) . '</a> <span style="color:#888">(ID: ' . esc_html($f->id) . ')</span> - <small>Shortcode: <code>[go_form id=' . esc_html($f->id) . ']</code></small></li>';
|
||||||
|
}
|
||||||
|
echo '</ul>';
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user