From 5902050221f707defe34a6f06eddaad841a78396 Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Mon, 4 May 2026 23:58:26 +0200 Subject: [PATCH] init --- .gitignore | 3 + go-form-plugin/go-form-plugin.php | 257 ++++++++++++++++++++++++++++++ restart_wp.sh | 39 +++++ setup_wp.sh | 44 +++++ start_wp.sh | 4 + stop_wp.sh | 4 + zip.sh | 4 + 7 files changed, 355 insertions(+) create mode 100644 .gitignore create mode 100644 go-form-plugin/go-form-plugin.php create mode 100755 restart_wp.sh create mode 100755 setup_wp.sh create mode 100755 start_wp.sh create mode 100755 stop_wp.sh create mode 100755 zip.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..20da133 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/database +/html +*.zip \ No newline at end of file diff --git a/go-form-plugin/go-form-plugin.php b/go-form-plugin/go-form-plugin.php new file mode 100644 index 0000000..afd221e --- /dev/null +++ b/go-form-plugin/go-form-plugin.php @@ -0,0 +1,257 @@ +get_charset_collate(); + $forms = $wpdb->prefix . 'go_form_forms'; + $entries = $wpdb->prefix . 'go_form_entries'; + + dbDelta("CREATE TABLE $forms ( + id mediumint(9) NOT NULL AUTO_INCREMENT, + name varchar(255) NOT NULL, + created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, + PRIMARY KEY (id) + ) $charset;"); + + dbDelta("CREATE TABLE $entries ( + id mediumint(9) NOT NULL AUTO_INCREMENT, + form_id mediumint(9) DEFAULT 1, + first_name varchar(100) NOT NULL, + last_name varchar(100) NOT NULL, + country varchar(100) DEFAULT NULL, + club varchar(100) DEFAULT NULL, + rank tinyint(2) DEFAULT 0, + email varchar(255) DEFAULT NULL, + egd_number varchar(50) DEFAULT NULL, + created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, + PRIMARY KEY (id), + KEY form_id (form_id) + ) $charset;"); +} +register_activation_hook(__FILE__, 'go_form_activate'); + +function go_form_uninstall() { + global $wpdb; + $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}go_form_entries"); + $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}go_form_forms"); +} +register_uninstall_hook(__FILE__, 'go_form_uninstall'); + +// ========== Helpers ========== +function go_form_get_forms() { + global $wpdb; + return $wpdb->get_results("SELECT * FROM {$wpdb->prefix}go_form_forms ORDER BY name ASC"); +} + +function go_form_get_entries($form_id) { + global $wpdb; + return $wpdb->get_results($wpdb->prepare( + "SELECT * FROM {$wpdb->prefix}go_form_entries WHERE form_id = %d ORDER BY created_at DESC", + $form_id + )); +} + +function go_form_render_entries_table($entries, $show_delete = false) { + if (empty($entries)) { + echo '

No entries yet.

'; + return; + } + + $headers = ['ID', 'First Name', 'Last Name', 'Country', 'Club', 'Rank', 'Email', 'EGD Number', 'Date Added']; + if ($show_delete) $headers[] = 'Action'; + + echo ' + '; + + foreach ($entries as $e) { + echo ' + + '; + + if ($show_delete) { + echo ''; + } + echo ''; + } + echo '
'.implode('', $headers).'
'.esc_html($e->id).''.esc_html($e->first_name).''.esc_html($e->last_name).''.esc_html($e->country).''.esc_html($e->club).''.esc_html($e->rank).''.esc_html($e->email).''.esc_html($e->egd_number).''.esc_html($e->created_at).'
+ '.wp_nonce_field('go_form_delete_action', 'go_form_delete_nonce', true, false).' + + + +
'; +} + +// ========== Form Handling ========== +function go_form_handle_submission() { + if (!isset($_POST['go_form_nonce']) || !wp_verify_nonce($_POST['go_form_nonce'], 'go_form_action')) + wp_die('Security check failed'); + + global $wpdb; + $data = [ + 'form_id' => isset($_POST['form_id']) ? intval($_POST['form_id']) : 1, + 'first_name' => sanitize_text_field($_POST['first_name']), + 'last_name' => sanitize_text_field($_POST['last_name']), + 'country' => sanitize_text_field($_POST['country'] ?? ''), + 'club' => sanitize_text_field($_POST['club'] ?? ''), + 'rank' => intval($_POST['rank']), + 'email' => sanitize_email($_POST['email'] ?? ''), + 'egd_number' => sanitize_text_field($_POST['egd_number'] ?? '') + ]; + + if (empty($data['first_name']) || empty($data['last_name'])) { + wp_redirect($_SERVER['HTTP_REFERER'] . '?form_error=1#form'); exit; + } + if ($data['rank'] < 0 || $data['rank'] > 40) { + wp_redirect($_SERVER['HTTP_REFERER'] . '?form_error=rank#form'); exit; + } + if (!empty($data['email']) && !is_email($data['email'])) { + wp_redirect($_SERVER['HTTP_REFERER'] . '?form_error=email#form'); exit; + } + + $wpdb->insert("{$wpdb->prefix}go_form_entries", $data); + wp_redirect($_SERVER['HTTP_REFERER'] . '?form_success=1#form'); + exit; +} +add_action('admin_post_go_form_submit', 'go_form_handle_submission'); +add_action('admin_post_nopriv_go_form_submit', 'go_form_handle_submission'); + +// ========== Shortcode ========== +function go_form_shortcode($atts) { + $form_id = intval(shortcode_atts(['id' => 1], $atts)['id']); + + $msg = ''; + if (isset($_GET['form_success']) && $_GET['form_success'] == 1) + $msg = '
Entry added successfully!
'; + elseif (isset($_GET['form_error'])) { + $errors = ['1' => 'Please fill in all required fields.', 'rank' => 'Rank must be 0-40.', 'email' => 'Please enter a valid email.']; + $msg = '
'.esc_html($errors[$_GET['form_error']] ?? $errors['1']).'
'; + } + + ob_start(); + echo $msg; + echo '
+

Add New Player

+
+ '.wp_nonce_field('go_form_action', 'go_form_nonce', true, false).' + + + + + + + + + + +
+

* Required fields

+ +
+

Players

'; + go_form_render_entries_table(go_form_get_entries($form_id)); + echo '
'; + return ob_get_clean(); +} +add_shortcode('go_form', 'go_form_shortcode'); + +// ========== Admin Actions ========== +function go_form_admin_action($type) { + if (!isset($_POST["go_form_{$type}_nonce"]) || !wp_verify_nonce($_POST["go_form_{$type}_nonce"], "go_form_{$type}_action")) + wp_die('Security check failed'); + if (!current_user_can('manage_options')) + wp_die('Insufficient permissions.'); +} + +function go_form_delete_entry() { + go_form_admin_action('delete'); + if (isset($_POST['entry_id'])) { + global $wpdb; + $wpdb->delete("{$wpdb->prefix}go_form_entries", ['id' => intval($_POST['entry_id'])]); + } + wp_redirect(admin_url('admin.php?page=go-form-settings&deleted=1')); + exit; +} +add_action('admin_post_go_form_delete_entry', 'go_form_delete_entry'); + +function go_form_create_form() { + go_form_admin_action('create'); + if (isset($_POST['form_name']) && !empty($_POST['form_name'])) { + global $wpdb; + $wpdb->insert("{$wpdb->prefix}go_form_forms", ['name' => sanitize_text_field($_POST['form_name'])]); + } + wp_redirect(admin_url('admin.php?page=go-form-settings&created=1')); + exit; +} +add_action('admin_post_go_form_create_form', 'go_form_create_form'); + +function go_form_delete_form() { + go_form_admin_action('delete_form'); + if (isset($_POST['form_id'])) { + global $wpdb; + $id = intval($_POST['form_id']); + $wpdb->delete("{$wpdb->prefix}go_form_entries", ['form_id' => $id]); + $wpdb->delete("{$wpdb->prefix}go_form_forms", ['id' => $id]); + } + wp_redirect(admin_url('admin.php?page=go-form-settings&deleted=1')); + exit; +} +add_action('admin_post_go_form_delete_form', 'go_form_delete_form'); + +// ========== Admin Page ========== +function go_form_admin_menu() { + add_menu_page('Go Form Settings', 'Go Form', 'manage_options', 'go-form-settings', 'go_form_settings_page', 'dashicons-admin-generic'); +} +add_action('admin_menu', 'go_form_admin_menu'); + +function go_form_settings_page() { + if (!current_user_can('manage_options')) wp_die('No access.'); + + $forms = go_form_get_forms(); + $entries_by_form = []; + foreach ($forms as $f) $entries_by_form[$f->id] = go_form_get_entries($f->id); + + if (isset($_GET['deleted'])) echo '

Deleted!

'; + if (isset($_GET['created'])) echo '

Form created!

'; + + echo '

Go Form Settings

+ +

Create New Form

+
+ '.wp_nonce_field('go_form_create_action', 'go_form_create_nonce', true, false).' + + + +
+

+
+ +

Manage Forms & Entries

'; + if (empty($forms)) { echo '

No forms yet.

'; return; } + + foreach ($forms as $f) { + $entries = $entries_by_form[$f->id] ?? []; + echo '
+

'.esc_html($f->name).' (ID: '.esc_html($f->id).')

+

Shortcode: [go_form id='.esc_html($f->id).']

+ +
+ '.wp_nonce_field('go_form_delete_form_action', 'go_form_delete_form_nonce', true, false).' + + + +
'; + + go_form_render_entries_table($entries, true); + echo '
'; + } + echo '
'; +} diff --git a/restart_wp.sh b/restart_wp.sh new file mode 100755 index 0000000..333bb7c --- /dev/null +++ b/restart_wp.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# restart_wp.sh - Fully restart WordPress pod and containers + +DB_NAME='wordpress_db' +DB_PASS='mysupersecurepass' +DB_USER='justbeauniqueuser' +POD_NAME='wordpress_with_mariadb' +CONTAINER_NAME_DB='wordpress_db' +CONTAINER_NAME_WP='wordpress' + +# Stop and remove containers +podman stop $CONTAINER_NAME_DB $CONTAINER_NAME_WP 2>/dev/null || true +podman rm $CONTAINER_NAME_DB $CONTAINER_NAME_WP 2>/dev/null || true + +# Remove pod +podman pod rm -f $POD_NAME 2>/dev/null || true + +# Recreate pod +podman pod create -n $POD_NAME -p 8090:80 + +# Start MariaDB +podman run --detach --pod $POD_NAME \ + -e MYSQL_ROOT_PASSWORD=$DB_PASS \ + -e MYSQL_PASSWORD=$DB_PASS \ + -e MYSQL_DATABASE=$DB_NAME \ + -e MYSQL_USER=$DB_USER \ + --name $CONTAINER_NAME_DB -v "$PWD/database":/var/lib/mysql \ + docker.io/mariadb:latest + +# Start WordPress +podman run --detach --pod $POD_NAME \ + -e WORDPRESS_DB_HOST=127.0.0.1:3306 \ + -e WORDPRESS_DB_NAME=$DB_NAME \ + -e WORDPRESS_DB_USER=$DB_USER \ + -e WORDPRESS_DB_PASSWORD=$DB_PASS \ + --name $CONTAINER_NAME_WP -v "$PWD/html":/var/www/html \ + docker.io/wordpress + +echo "WordPress restarted on http://localhost:8090" diff --git a/setup_wp.sh b/setup_wp.sh new file mode 100755 index 0000000..65ed71a --- /dev/null +++ b/setup_wp.sh @@ -0,0 +1,44 @@ +# Source - https://stackoverflow.com/a/74956385 +# Posted by tiemco +# Retrieved 2026-05-04, License - CC BY-SA 4.0 + +#!/bin/bash +# https://stackoverflow.com/questions/74054932/how-to-install-and-setup-wordpress-using-podman + +# Set environment variables: +DB_NAME='wordpress_db' +DB_PASS='mysupersecurepass' +DB_USER='justbeauniqueuser' +POD_NAME='wordpress_with_mariadb' +CONTAINER_NAME_DB='wordpress_db' +CONTAINER_NAME_WP='wordpress' + +mkdir -p html +mkdir -p database + +# Remove previous attempts +podman pod rm -f $POD_NAME + +# Pull before run, bc: invalid reference format error +podman pull docker.io/mariadb:latest +podman pull docker.io/wordpress + +# Create a pod instead of --link. +# So both containers are able to reach each others. +podman pod create -n $POD_NAME -p 8090:80 + +podman run --detach --pod $POD_NAME \ +-e MYSQL_ROOT_PASSWORD=$DB_PASS \ +-e MYSQL_PASSWORD=$DB_PASS \ +-e MYSQL_DATABASE=$DB_NAME \ +-e MYSQL_USER=$DB_USER \ +--name $CONTAINER_NAME_DB -v "$PWD/database":/var/lib/mysql \ +docker.io/mariadb:latest + +podman run --detach --pod $POD_NAME \ +-e WORDPRESS_DB_HOST=127.0.0.1:3306 \ +-e WORDPRESS_DB_NAME=$DB_NAME \ +-e WORDPRESS_DB_USER=$DB_USER \ +-e WORDPRESS_DB_PASSWORD=$DB_PASS \ +--name $CONTAINER_NAME_WP -v "$PWD/html":/var/www/html \ +docker.io/wordpress diff --git a/start_wp.sh b/start_wp.sh new file mode 100755 index 0000000..327741e --- /dev/null +++ b/start_wp.sh @@ -0,0 +1,4 @@ +#!/bin/bash +POD_NAME='wordpress_with_mariadb' + +podman pod start $POD_NAME diff --git a/stop_wp.sh b/stop_wp.sh new file mode 100755 index 0000000..687ab75 --- /dev/null +++ b/stop_wp.sh @@ -0,0 +1,4 @@ +#!/bin/bash +POD_NAME='wordpress_with_mariadb' + +podman pod stop $POD_NAME diff --git a/zip.sh b/zip.sh new file mode 100755 index 0000000..9eee3ec --- /dev/null +++ b/zip.sh @@ -0,0 +1,4 @@ +sudo rm -rf html/wp-content/plugins/go-form-plugin +sudo cp -r go-form-plugin html/wp-content/plugins/ +rm go-form-plugin.zip +zip -r go-form-plugin.zip go-form-plugin/*