diff --git a/admin/js/admin-scripts.js b/admin/js/admin-scripts.js index 76ec836..d0f4337 100644 --- a/admin/js/admin-scripts.js +++ b/admin/js/admin-scripts.js @@ -4,122 +4,132 @@ * @package WPALLSTARS\PluginStarterTemplate */ -(function($) { - 'use strict'; +(function ($) { + 'use strict'; - /** - * Admin functionality - */ - const WPSTAdmin = { - /** - * Initialize - */ - init: function() { - // Initialize components - this.initComponents(); - - // Bind events - this.bindEvents(); - }, + /** + * Admin functionality + */ + const WPSTAdmin = { + /** + * Initialize + */ + init: function () { + // Initialize components + this.initComponents(); - /** - * Initialize components - */ - initComponents: function() { - // Initialize any components here - }, + // Bind events + this.bindEvents(); + }, - /** - * Bind events - */ - bindEvents: function() { - // Example: Toggle sections - $('.wpst-toggle-section').on('click', this.toggleSection); - - // Example: Form submission - $('#wpst-settings-form').on('submit', this.handleFormSubmit); - }, + /** + * Initialize components + */ + initComponents: function () { + // Initialize any components here + }, - /** - * 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'); - }, + /** + * Bind events + */ + bindEvents: function () { + // Example: Toggle sections + $( '.wpst-toggle-section' ).on( 'click', this.toggleSection ); - /** - * 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'); - } - }); - }, + // Example: Form submission + $( '#wpst-settings-form' ).on( 'submit', this.handleFormSubmit ); + }, - /** - * Show admin notice - * - * @param {string} type Notice type (success, error, warning) - * @param {string} message Notice message - */ - showNotice: function(type, message) { - const $notice = $('

' + message + '

'); - - // Add notice to the page - $('.wpst-notices').html($notice); - - // Automatically remove notice after 5 seconds - setTimeout(function() { - $notice.fadeOut(300, function() { - $(this).remove(); - }); - }, 5000); - } - }; + /** + * Toggle section visibility + * + * @param {Event} e Click event + */ + toggleSection: function (e) { + e.preventDefault(); - // Initialize when document is ready - $(document).ready(function() { - WPSTAdmin.init(); - }); + const $this = $( this ); + const target = $this.data( 'target' ); -})(jQuery); + $( 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 = $( '

' + message + '

' ); + + // 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 ); diff --git a/admin/js/update-source-selector.js b/admin/js/update-source-selector.js index 96696ea..ce55df7 100644 --- a/admin/js/update-source-selector.js +++ b/admin/js/update-source-selector.js @@ -4,161 +4,175 @@ * @package WPALLSTARS\PluginStarterTemplate */ -(function($) { - 'use strict'; +(function ($) { + 'use strict'; - /** - * Update Source Selector functionality - */ - const WPSTUpdateSourceSelector = { - /** - * Modal element - */ - $modal: null, + /** + * Update Source Selector functionality + */ + const WPSTUpdateSourceSelector = { + /** + * Modal element + */ + $modal: null, - /** - * Selected source - */ - selectedSource: '', + /** + * Selected source + */ + selectedSource: '', - /** - * Initialize - */ - init: function() { - // Cache DOM elements - this.$modal = $('#wpst-update-source-modal'); - - // Bind events - this.bindEvents(); - }, + /** + * Initialize + */ + init: function () { + // Cache DOM elements + this.$modal = $( '#wpst-update-source-modal' ); - /** - * 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)); - }, + // Bind events + this.bindEvents(); + }, - /** - * Open the modal - * - * @param {Event} e Click event - */ - openModal: function(e) { - e.preventDefault(); - this.$modal.show(); - }, + /** + * 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 the modal - */ - closeModal: function() { - this.$modal.hide(); - }, + // 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 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(); - }, + // Select source option + this.$modal.on( 'click', '.wpst-source-option', this.selectSource.bind( this ) ); - /** - * 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(' 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); - } - }); - }, + // Save source selection + this.$modal.on( 'click', '#wpst-save-source', this.saveSource.bind( this ) ); + }, - /** - * 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); - } - } - }; + /** + * Open the modal + * + * @param {Event} e Click event + */ + openModal: function (e) { + e.preventDefault(); + this.$modal.show(); + }, - // Initialize when document is ready - $(document).ready(function() { - WPSTUpdateSourceSelector.init(); - }); + /** + * Close the modal + */ + closeModal: function () { + this.$modal.hide(); + }, -})(jQuery); + /** + * 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( ' 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 ); diff --git a/admin/templates/modal.php b/admin/templates/modal.php index 72ec63e..6eeaa17 100644 --- a/admin/templates/modal.php +++ b/admin/templates/modal.php @@ -6,60 +6,60 @@ */ // If this file is called directly, abort. -if (!defined('WPINC')) { - die; +if ( ! defined( 'WPINC' ) ) { + die; } ?>
-
-
-

- × -
- -
-

- -
- -
- - - - - - - -
-
- - -
+
+
+

+ × +
+ +
+

+ +
+ +
+ + + + + + + +
+
+ + +
diff --git a/includes/plugin.php b/includes/plugin.php index cf307f8..d804ab6 100644 --- a/includes/plugin.php +++ b/includes/plugin.php @@ -12,43 +12,43 @@ namespace WPALLSTARS\PluginStarterTemplate; */ class Plugin { - /** - * Core instance - * - * @var Core - */ - private $core; + /** + * Core instance + * + * @var Core + */ + private $core; - /** - * Plugin file - * - * @var string - */ - private $plugin_file; + /** + * Plugin file + * + * @var string + */ + private $plugin_file; - /** - * Plugin version - * - * @var string - */ - private $version; + /** + * Plugin version + * + * @var string + */ + private $version; - /** - * Constructor - * - * @param string $plugin_file Main plugin file path. - * @param string $version Plugin version. - */ - public function __construct($plugin_file, $version) { - $this->plugin_file = $plugin_file; - $this->version = $version; - $this->core = new Core(); - } + /** + * Constructor + * + * @param string $plugin_file Main plugin file path. + * @param string $version Plugin version. + */ + public function __construct( $plugin_file, $version ) { + $this->plugin_file = $plugin_file; + $this->version = $version; + $this->core = new Core(); + } - /** - * Initialize the plugin - */ - public function init() { - // Initialize plugin - } + /** + * Initialize the plugin + */ + public function init() { + // Initialize plugin + } } diff --git a/wp-plugin-starter-template.php b/wp-plugin-starter-template.php index 42744de..427e003 100644 --- a/wp-plugin-starter-template.php +++ b/wp-plugin-starter-template.php @@ -27,12 +27,12 @@ */ // If this file is called directly, abort. -if (!defined('WPINC')) { - die; +if ( ! defined( 'WPINC' ) ) { + die; } // Load the main plugin class require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin.php'; // Initialize the plugin -new WPALLSTARS\PluginStarterTemplate\Plugin(__FILE__, '0.1.7'); +new WPALLSTARS\PluginStarterTemplate\Plugin( __FILE__, '0.1.7' );