# =================================================================
# TOPIC: WORDPRESS PLUGIN FOUNDATION & FILE STRUCTURE
# =================================================================
# — ROLE AND GOAL —
# You are a senior WordPress developer specializing in modern plugin architecture and WordPress Coding Standards.
# Your primary goal is to generate a robust, secure, and scalable foundation for a new WordPress plugin. This includes the main plugin file with all necessary headers, essential security checks, and global constants for later use.
# — TASK —
# Generate the main plugin file (`[PLUGIN_SLUG].php`) and list the recommended directory structure based on the configuration variables and detailed logic provided below. The generated code must adhere strictly to WordPress best practices.
# —————————————————————–
# — CONFIGURATION VARIABLES —
# The generated code should pull all its configuration from these variables.
# =================================================================
# – PLUGIN META INFORMATION –
# The full name of the plugin.
PLUGIN_NAME=”[FILL_THIS_IN]” # Example: “Advanced Post Voting”
# The URL of the plugin’s homepage or marketplace listing.
PLUGIN_URI=”[FILL_THIS_IN]” # Example: “https://example.com/plugins/advanced-post-voting/”
# A short, descriptive summary of the plugin.
DESCRIPTION=”[FILL_THIS_IN]” # Example: “This plugin allows users to upvote or downvote posts and pages.”
# The current version of the plugin.
VERSION=”1.0.0″
# The name of the plugin author(s).
AUTHOR=”[FILL_THIS_IN]” # Example: “Your Name / Company Name”
# The URL of the author’s website.
AUTHOR_URI=”[FILL_THIS_IN]” # Example: “https://example.com”
# The plugin’s license (e.g., GPL-2.0-or-later).
LICENSE=”GPL-2.0-or-later”
# The full URI of the license text.
LICENSE_URI=”https://www.gnu.org/licenses/gpl-2.0.html”
# The plugin’s unique identifier for translation files (Text Domain). Usually the plugin slug.
TEXT_DOMAIN=”[FILL_THIS_IN]” # Example: “advanced-post-voting”
# The file name (slug) of the plugin. This MUST match the Text Domain.
PLUGIN_SLUG=”[FILL_THIS_IN]” # Example: “advanced-post-voting”
# —————————————————————–
# — DETAILED CODE LOGIC —
# The generated code must implement the following logic step-by-step.
# 1. Add the WordPress Plugin Header:
# – Use all the information from the `CONFIGURATION VARIABLES` section to generate the standard WordPress plugin header comment block.
# 2. Add Security Check:
# – Include the line `defined(‘ABSPATH’) or die(‘No script kiddies please!’);` to prevent direct file access.
# 3. Define Global Constants:
# – After the security check, define two important constants that will be used in subsequent steps:
# – A constant for the plugin’s main file path: `define(‘MY_AWESOME_PLUGIN_FILE’, __FILE__);`
# – A constant for the plugin’s version: `define(‘MY_AWESOME_PLUGIN_VERSION’, ‘[VERSION]’);` (use the version from the config).
# 4. Define Activation and Deactivation Hooks:
# – Use `register_activation_hook` and `register_deactivation_hook`, referencing the main plugin file constant. These will call methods within the main plugin class.
# 5. Create the Main Plugin Class:
# – To encapsulate all plugin functionality, create a main class (e.g., `Advanced_Post_Voting`).
# – The `register_activation_hook` should call a public static method within this class (e.g., `public static function activate()`).
# – The `__construct` method will register all necessary action and filter hooks for the plugin’s operation.
# 6. List the Recommended Directory Structure:
# – Provide a list of standard folders and explain their purpose: `/admin`, `/public`, `/includes`, `/assets`, `/languages`.
# — FINAL INSTRUCTION —
# Please generate the complete, self-contained, and well-commented PHP code for the main plugin file and the directory structure list based on all the requirements above. This code will serve as the foundation for all subsequent prompts.
# =================================================================
# TOPIC: CUSTOM WORDPRESS DATABASE TABLE CREATION
# =================================================================
# — ROLE AND GOAL —
# You are a senior WordPress and MySQL developer. You will now extend the plugin foundation created in the previous step.
# Your goal is to write a static method for the main plugin class that creates a custom database table. This method will be triggered by the `register_activation_hook` already defined in the foundation code.
# — TASK —
# Generate a complete, static PHP method named `activate` to be placed inside the main plugin class from Prompt 1. This method will create a custom database table using the configuration below. It must use WordPress’s `dbDelta()` function for safe table creation.
# —————————————————————–
# — CONTEXT FROM PREVIOUS STEP —
# You are adding this `activate` method to the main plugin class that was generated in Prompt 1.
# The `register_activation_hook` in the base file already calls `[YourMainClass]::activate();`.
# —————————————————————–
# — CONFIGURATION VARIABLES —
# =================================================================
# – TABLE CONFIGURATION –
# The name of the table without the WordPress database prefix (`wp_`).
TABLE_NAME=”[FILL_THIS_IN]” # Example: “post_votes”
# – TABLE COLUMNS –
# An array defining the columns and their properties for the table.
TABLE_COLUMNS=”[
‘id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT’,
‘post_id BIGINT(20) UNSIGNED NOT NULL’,
‘user_id BIGINT(20) UNSIGNED NOT NULL’,
‘vote_type VARCHAR(10) NOT NULL’,
‘ip_address VARCHAR(100) NOT NULL’,
‘voted_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP’,
‘PRIMARY KEY (id)’,
‘KEY idx_post_id (post_id)’,
‘UNIQUE KEY unq_user_post (user_id, post_id)’
]”
# —————————————————————–
# — DETAILED CODE LOGIC —
# The generated method must implement the following logic step-by-step.
# 1. Use the Global `$wpdb` Object:
# – Access the WordPress database object by declaring `global $wpdb;` at the beginning of the method.
# 2. Construct the Full Table Name:
# – Create the complete table name using the WordPress prefix: `$table_name = $wpdb->prefix . TABLE_NAME;`.
# 3. Get the Character Set:
# – Retrieve the database’s character set and collation information using `$charset_collate = $wpdb->get_charset_collate();`.
# 4. Form the SQL Query:
# – Build the `CREATE TABLE` SQL statement using the configured `TABLE_NAME` and `TABLE_COLUMNS`.
# 5. Use the `dbDelta()` Function:
# – Before calling `dbDelta()`, ensure it is available by including its file: `require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’);`.
# – Execute the table creation by passing the SQL query to `dbDelta()`.
# — FINAL INSTRUCTION —
# Please generate only the complete, secure, and well-commented `public static function activate()` method, ready to be inserted into the main class from the previous prompt.