Initial commit of WordPress Plugin Starter Template for AI Coding
Some checks failed
Tests / PHP 7.0 (push) Has been cancelled
Tests / PHP 7.4 (push) Has been cancelled
Tests / PHP 8.0 (push) Has been cancelled
Tests / Code Style (push) Has been cancelled
Sync Wiki / Sync Wiki to GitHub (push) Has been cancelled
Release / Build and Release (push) Has been cancelled

This commit is contained in:
2025-04-18 03:09:39 +01:00
commit c7b590870c
46 changed files with 3198 additions and 0 deletions

145
admin/css/admin-styles.css Normal file
View File

@ -0,0 +1,145 @@
/**
* Admin Styles
*
* @package WPALLSTARS\PluginStarterTemplate
*/
/* General Admin Styles */
.wpst-admin-page {
max-width: 1200px;
margin: 20px auto;
padding: 20px;
background: #fff;
border-radius: 5px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.wpst-admin-header {
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #eee;
}
.wpst-admin-header h1 {
margin-top: 0;
color: #23282d;
}
/* Admin Form Styles */
.wpst-form-table {
width: 100%;
border-collapse: collapse;
}
.wpst-form-table th {
text-align: left;
padding: 15px 10px 15px 0;
width: 200px;
vertical-align: top;
}
.wpst-form-table td {
padding: 15px 0;
vertical-align: middle;
}
.wpst-form-table input[type="text"],
.wpst-form-table input[type="number"],
.wpst-form-table select,
.wpst-form-table textarea {
width: 400px;
max-width: 100%;
}
.wpst-form-table textarea {
min-height: 100px;
}
.wpst-form-description {
color: #666;
font-style: italic;
margin-top: 5px;
}
/* Admin Notices */
.wpst-notice {
padding: 10px 15px;
margin: 15px 0;
border-radius: 3px;
border-left: 4px solid #00a0d2;
background: #f7fcff;
}
.wpst-notice.success {
border-left-color: #46b450;
background: #ecf7ed;
}
.wpst-notice.error {
border-left-color: #dc3232;
background: #fbeaea;
}
.wpst-notice.warning {
border-left-color: #ffb900;
background: #fff8e5;
}
/* Admin Cards */
.wpst-card-container {
display: flex;
flex-wrap: wrap;
margin: 0 -10px;
}
.wpst-card {
flex: 1 0 300px;
margin: 10px;
padding: 20px;
background: #fff;
border-radius: 3px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.wpst-card-header {
margin-bottom: 15px;
padding-bottom: 15px;
border-bottom: 1px solid #eee;
}
.wpst-card-title {
margin: 0;
font-size: 16px;
font-weight: 600;
}
.wpst-card-content {
margin-bottom: 15px;
}
.wpst-card-footer {
padding-top: 15px;
border-top: 1px solid #eee;
text-align: right;
}
/* Responsive Styles */
@media screen and (max-width: 782px) {
.wpst-form-table th {
width: 100%;
display: block;
padding-bottom: 0;
}
.wpst-form-table td {
width: 100%;
display: block;
}
.wpst-form-table input[type="text"],
.wpst-form-table input[type="number"],
.wpst-form-table select,
.wpst-form-table textarea {
width: 100%;
}
}

View File

@ -0,0 +1,143 @@
/**
* Update Source Selector Styles
*
* @package WPALLSTARS\PluginStarterTemplate
*/
/* Modal Styles */
.wpst-modal {
display: none;
position: fixed;
z-index: 100000;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
}
.wpst-modal-content {
position: relative;
background-color: #fefefe;
margin: 10% auto;
padding: 20px;
border-radius: 5px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
width: 500px;
max-width: 90%;
}
.wpst-modal-header {
padding-bottom: 15px;
border-bottom: 1px solid #eee;
margin-bottom: 15px;
}
.wpst-modal-title {
margin: 0;
font-size: 18px;
font-weight: 600;
}
.wpst-modal-close {
position: absolute;
top: 10px;
right: 15px;
font-size: 20px;
font-weight: bold;
color: #666;
cursor: pointer;
}
.wpst-modal-close:hover,
.wpst-modal-close:focus {
color: #000;
text-decoration: none;
}
.wpst-modal-body {
margin-bottom: 20px;
}
.wpst-modal-footer {
padding-top: 15px;
border-top: 1px solid #eee;
text-align: right;
}
/* Source Selection Styles */
.wpst-source-options {
margin: 15px 0;
}
.wpst-source-option {
display: block;
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 3px;
cursor: pointer;
}
.wpst-source-option:hover {
background-color: #f9f9f9;
}
.wpst-source-option.selected {
border-color: #0073aa;
background-color: #f0f6fc;
}
.wpst-source-option input[type="radio"] {
margin-right: 10px;
}
.wpst-source-option-label {
font-weight: 600;
}
.wpst-source-option-description {
margin-top: 5px;
color: #666;
font-size: 13px;
}
/* Loading Indicator */
.wpst-loading {
display: inline-block;
width: 20px;
height: 20px;
border: 2px solid rgba(0, 0, 0, 0.1);
border-radius: 50%;
border-top-color: #0073aa;
animation: wpst-spin 1s ease-in-out infinite;
margin-right: 10px;
vertical-align: middle;
}
@keyframes wpst-spin {
to {
transform: rotate(360deg);
}
}
/* Message Styles */
.wpst-modal-message {
padding: 10px;
margin: 10px 0;
border-radius: 3px;
display: none;
}
.wpst-modal-message.success {
background-color: #ecf7ed;
border: 1px solid #46b450;
color: #2a6f31;
}
.wpst-modal-message.error {
background-color: #fbeaea;
border: 1px solid #dc3232;
color: #8a1f1f;
}

125
admin/js/admin-scripts.js Normal file
View File

@ -0,0 +1,125 @@
/**
* Admin Scripts
*
* @package WPALLSTARS\PluginStarterTemplate
*/
(function($) {
'use strict';
/**
* Admin functionality
*/
const WPSTAdmin = {
/**
* Initialize
*/
init: function() {
// Initialize components
this.initComponents();
// Bind events
this.bindEvents();
},
/**
* Initialize components
*/
initComponents: function() {
// Initialize any components here
},
/**
* Bind events
*/
bindEvents: function() {
// Example: Toggle sections
$('.wpst-toggle-section').on('click', this.toggleSection);
// Example: Form submission
$('#wpst-settings-form').on('submit', this.handleFormSubmit);
},
/**
* Toggle section visibility
*
* @param {Event} e Click event
*/
toggleSection: function(e) {
e.preventDefault();
const $this = $(this);
const target = $this.data('target');
$(target).slideToggle(200);
$this.toggleClass('open');
},
/**
* Handle form submission
*
* @param {Event} e Submit event
*/
handleFormSubmit: function(e) {
e.preventDefault();
const $form = $(this);
const $submitButton = $form.find('input[type="submit"]');
const formData = $form.serialize();
// Disable submit button and show loading state
$submitButton.prop('disabled', true).addClass('loading');
// Send AJAX request
$.ajax({
url: wpstData.ajaxUrl,
type: 'POST',
data: {
action: 'wpst_save_settings',
nonce: wpstData.nonce,
formData: formData
},
success: function(response) {
if (response.success) {
WPSTAdmin.showNotice('success', response.data.message);
} else {
WPSTAdmin.showNotice('error', response.data.message);
}
},
error: function() {
WPSTAdmin.showNotice('error', 'An error occurred. Please try again.');
},
complete: function() {
// Re-enable submit button and remove loading state
$submitButton.prop('disabled', false).removeClass('loading');
}
});
},
/**
* Show admin notice
*
* @param {string} type Notice type (success, error, warning)
* @param {string} message Notice message
*/
showNotice: function(type, message) {
const $notice = $('<div class="wpst-notice ' + type + '"><p>' + message + '</p></div>');
// Add notice to the page
$('.wpst-notices').html($notice);
// Automatically remove notice after 5 seconds
setTimeout(function() {
$notice.fadeOut(300, function() {
$(this).remove();
});
}, 5000);
}
};
// Initialize when document is ready
$(document).ready(function() {
WPSTAdmin.init();
});
})(jQuery);

View File

@ -0,0 +1,164 @@
/**
* Update Source Selector Scripts
*
* @package WPALLSTARS\PluginStarterTemplate
*/
(function($) {
'use strict';
/**
* Update Source Selector functionality
*/
const WPSTUpdateSourceSelector = {
/**
* Modal element
*/
$modal: null,
/**
* Selected source
*/
selectedSource: '',
/**
* Initialize
*/
init: function() {
// Cache DOM elements
this.$modal = $('#wpst-update-source-modal');
// Bind events
this.bindEvents();
},
/**
* Bind events
*/
bindEvents: function() {
// Open modal when clicking on the update source link
$(document).on('click', '.wpst-update-source-selector', this.openModal.bind(this));
// Close modal when clicking on the close button or outside the modal
this.$modal.on('click', '.wpst-modal-close', this.closeModal.bind(this));
$(document).on('click', '.wpst-modal', function(e) {
if ($(e.target).hasClass('wpst-modal')) {
WPSTUpdateSourceSelector.closeModal();
}
});
// Select source option
this.$modal.on('click', '.wpst-source-option', this.selectSource.bind(this));
// Save source selection
this.$modal.on('click', '#wpst-save-source', this.saveSource.bind(this));
},
/**
* Open the modal
*
* @param {Event} e Click event
*/
openModal: function(e) {
e.preventDefault();
this.$modal.show();
},
/**
* Close the modal
*/
closeModal: function() {
this.$modal.hide();
},
/**
* Select a source option
*
* @param {Event} e Click event
*/
selectSource: function(e) {
const $option = $(e.currentTarget);
// Update selected state
this.$modal.find('.wpst-source-option').removeClass('selected');
$option.addClass('selected');
// Update radio button
$option.find('input[type="radio"]').prop('checked', true);
// Store selected source
this.selectedSource = $option.find('input[type="radio"]').val();
},
/**
* Save the selected source
*/
saveSource: function() {
// Validate selection
if (!this.selectedSource) {
this.showMessage('error', 'Please select an update source.');
return;
}
// Show loading state
const $saveButton = $('#wpst-save-source');
$saveButton.prop('disabled', true).html('<span class="wpst-loading"></span> Saving...');
// Send AJAX request
$.ajax({
url: wpstModalData.ajaxUrl,
type: 'POST',
data: {
action: 'wpst_set_update_source',
nonce: wpstModalData.nonce,
source: this.selectedSource
},
success: function(response) {
if (response.success) {
WPSTUpdateSourceSelector.showMessage('success', response.data.message);
// Close modal after a short delay
setTimeout(function() {
WPSTUpdateSourceSelector.closeModal();
}, 1500);
} else {
WPSTUpdateSourceSelector.showMessage('error', response.data.message);
}
},
error: function() {
WPSTUpdateSourceSelector.showMessage('error', 'An error occurred. Please try again.');
},
complete: function() {
// Reset button state
$saveButton.prop('disabled', false).text(wpstModalData.i18n.confirm);
}
});
},
/**
* Show a message in the modal
*
* @param {string} type Message type (success, error)
* @param {string} message Message text
*/
showMessage: function(type, message) {
const $message = this.$modal.find('.wpst-modal-message');
// Set message content and type
$message.html(message).removeClass('success error').addClass(type).show();
// Hide message after a delay for success messages
if (type === 'success') {
setTimeout(function() {
$message.fadeOut(300);
}, 3000);
}
}
};
// Initialize when document is ready
$(document).ready(function() {
WPSTUpdateSourceSelector.init();
});
})(jQuery);

1
admin/lib/admin.php Normal file
View File

@ -0,0 +1 @@
<?php

1
admin/lib/modal.php Normal file
View File

@ -0,0 +1 @@
<?php

65
admin/templates/modal.php Normal file
View File

@ -0,0 +1,65 @@
<?php
/**
* Modal Template
*
* @package WPALLSTARS\PluginStarterTemplate
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
?>
<!-- Update Source Modal -->
<div id="wpst-update-source-modal" class="wpst-modal">
<div class="wpst-modal-content">
<div class="wpst-modal-header">
<h2 class="wpst-modal-title"><?php esc_html_e('Select Update Source', 'wp-plugin-starter-template'); ?></h2>
<span class="wpst-modal-close">&times;</span>
</div>
<div class="wpst-modal-body">
<p><?php esc_html_e('Choose your preferred source for plugin updates:', 'wp-plugin-starter-template'); ?></p>
<div class="wpst-modal-message"></div>
<div class="wpst-source-options">
<?php
// Get current update source
$current_source = get_option('wpst_update_source', 'wordpress.org');
?>
<label class="wpst-source-option <?php echo $current_source === 'wordpress.org' ? 'selected' : ''; ?>">
<input type="radio" name="update_source" value="wordpress.org" <?php checked($current_source, 'wordpress.org'); ?>>
<span class="wpst-source-option-label"><?php esc_html_e('WordPress.org', 'wp-plugin-starter-template'); ?></span>
<div class="wpst-source-option-description">
<?php esc_html_e('Receive updates from the official WordPress.org repository. Recommended for most users.', 'wp-plugin-starter-template'); ?>
</div>
</label>
<label class="wpst-source-option <?php echo $current_source === 'github' ? 'selected' : ''; ?>">
<input type="radio" name="update_source" value="github" <?php checked($current_source, 'github'); ?>>
<span class="wpst-source-option-label"><?php esc_html_e('GitHub', 'wp-plugin-starter-template'); ?></span>
<div class="wpst-source-option-description">
<?php esc_html_e('Receive updates from the GitHub repository. May include pre-release versions.', 'wp-plugin-starter-template'); ?>
</div>
</label>
<label class="wpst-source-option <?php echo $current_source === 'gitea' ? 'selected' : ''; ?>">
<input type="radio" name="update_source" value="gitea" <?php checked($current_source, 'gitea'); ?>>
<span class="wpst-source-option-label"><?php esc_html_e('Gitea', 'wp-plugin-starter-template'); ?></span>
<div class="wpst-source-option-description">
<?php esc_html_e('Receive updates from the Gitea repository. May include pre-release versions.', 'wp-plugin-starter-template'); ?>
</div>
</label>
</div>
</div>
<div class="wpst-modal-footer">
<button type="button" id="wpst-save-source" class="button button-primary">
<?php esc_html_e('Save', 'wp-plugin-starter-template'); ?>
</button>
</div>
</div>
</div>