Changeset 3505977
- Timestamp:
- 04/14/2026 11:09:34 AM (6 months ago)
- Location:
- ajax-admin-navigation-sidebar-menus-by-ajax/trunk
- Files:
-
- 3 edited
-
ajax-admin-navigation-sidebar-menus-by-ajax.php (modified) (3 diffs)
-
js/custom-admin-ajax.js (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ajax-admin-navigation-sidebar-menus-by-ajax/trunk/ajax-admin-navigation-sidebar-menus-by-ajax.php
r3215562 r3505977 1 1 <?php 2 2 /* 3 Plugin Name: AJAX Admin Navigation Sidebar AJAX3 Plugin Name: AJAX Admin Navigation Sidebar 4 4 Description: Adds AJAX navigation to the WordPress admin dashboard to prevent full page reloads. 5 Version: 1. 05 Version: 1.1 6 6 Author: Vaibhav Gangrade 7 Author URI:8 Stable Version: 1.09 Tested Up To: 6.610 7 License: GPL v2 or later 11 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html 12 Short Description: Plugin for controlling admin menus sideabr with ajax for prevnting extra server load.13 9 */ 14 15 10 16 11 if (!defined('ABSPATH')) { … … 21 16 class AJAX_Admin_Navigation_Menus { 22 17 23 // Calling constructor24 18 public function __construct() { 25 19 add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); … … 27 21 } 28 22 29 // Enqueue ing script files23 // Enqueue scripts and styles 30 24 public function enqueue_scripts() { 31 wp_enqueue_script('custom-admin-ajax', plugin_dir_url(__FILE__) . 'js/custom-admin-ajax.js', array('jquery'), null, true); 25 wp_enqueue_script( 26 'custom-admin-ajax', 27 plugin_dir_url(__FILE__) . 'js/custom-admin-ajax.js', 28 array('jquery'), 29 null, 30 true 31 ); 32 32 33 wp_localize_script('custom-admin-ajax', 'ajax_admin_nav_object', array(33 wp_localize_script('custom-admin-ajax', 'ajax_admin_nav_object', array( 34 34 'ajax_url' => admin_url('admin-ajax.php'), 35 35 'nonce' => wp_create_nonce('custom-admin-ajax-nonce'), 36 36 )); 37 37 38 39 // Enqueue the custom CSS file 40 wp_enqueue_style('custom-admin-style', plugin_dir_url(__FILE__) . 'css/style.css'); 38 wp_enqueue_style( 39 'custom-admin-style', 40 plugin_dir_url(__FILE__) . 'css/style.css' 41 ); 41 42 } 42 43 44 // Load admin assets during AJAX requests 43 45 public function load_admin_assets() { 44 46 if (defined('DOING_AJAX') && DOING_AJAX) { 45 // Enqueue WordPress admin scripts for navigation and content management 46 wp_enqueue_script('post'); // For post/page editing screens 47 wp_enqueue_script('editor'); // The editor script (TinyMCE) 48 wp_enqueue_script('nav-menu'); // Navigation menus management 49 wp_enqueue_script('media'); // Media manager (for uploading images and files) 50 wp_enqueue_script('link'); // Internal linking feature 51 wp_enqueue_script('wplink'); // WordPress link editor 52 wp_enqueue_script('wp-color-picker'); // Color picker tool 53 wp_enqueue_script('customize-controls'); // Customizer controls 54 wp_enqueue_script('dashboard'); // Dashboard widgets 55 wp_enqueue_script('wp-api'); // REST API integration 56 wp_enqueue_script('autosave'); // Autosave feature for posts/pages 57 wp_enqueue_script('media-views'); // Media views for the media library 58 wp_enqueue_script('tags-box'); // Tag and category boxes 59 wp_enqueue_script('wp-block-editor'); // Gutenberg block editor (if needed) 47 wp_enqueue_script('post'); 48 wp_enqueue_script('editor'); 49 wp_enqueue_script('nav-menu'); 50 wp_enqueue_script('media'); 51 wp_enqueue_script('link'); 52 wp_enqueue_script('wplink'); 53 wp_enqueue_script('wp-color-picker'); 54 wp_enqueue_script('customize-controls'); 55 wp_enqueue_script('dashboard'); 56 wp_enqueue_script('wp-api'); 57 wp_enqueue_script('autosave'); 58 wp_enqueue_script('media-views'); 59 wp_enqueue_script('tags-box'); 60 wp_enqueue_script('wp-block-editor'); 60 61 61 // Enqueue WordPress admin styles for navigation and content management 62 wp_enqueue_style('editor-buttons'); // Styles for editor buttons 63 wp_enqueue_style('wp-jquery-ui-dialog'); // jQuery UI dialog styles 64 wp_enqueue_style('nav-menu'); // Navigation menus styles 65 wp_enqueue_style('wp-color-picker'); // Color picker styles 66 wp_enqueue_style('customize-controls'); // Customizer controls styles 67 wp_enqueue_style('dashboard'); // Dashboard widgets styles 68 wp_enqueue_style('media-views'); // Styles for media views 69 wp_enqueue_style('wp-block-editor'); // Styles for Gutenberg block editor (if needed) 70 71 // Add more scripts or styles if needed 62 wp_enqueue_style('editor-buttons'); 63 wp_enqueue_style('wp-jquery-ui-dialog'); 64 wp_enqueue_style('nav-menu'); 65 wp_enqueue_style('wp-color-picker'); 66 wp_enqueue_style('customize-controls'); 67 wp_enqueue_style('dashboard'); 68 wp_enqueue_style('media-views'); 69 wp_enqueue_style('wp-block-editor'); 72 70 } 73 71 } 74 75 76 77 78 }//end of class 72 } 79 73 } 80 74 81 75 new AJAX_Admin_Navigation_Menus(); 82 83 -
ajax-admin-navigation-sidebar-menus-by-ajax/trunk/js/custom-admin-ajax.js
r3215562 r3505977 1 1 jQuery(document).ready(function($) { 2 // Handle menu item clicks3 $('#adminmenu a').on('click', function(e) {4 e.preventDefault();5 2 6 var url = $(this).attr('href'); 7 8 // Show the full-page overlay with spinner 3 // Centralized AJAX loader 4 function loadAjaxContent(url, $link) { 9 5 $('body').append('<div class="full-page-overlay"><div class="spinner"></div></div>'); 10 6 11 // Load the content via AJAX12 7 $.ajax({ 13 8 url: url, 14 9 type: 'GET', 15 10 success: function(response) { 16 // Extract the content from the response 17 var content = $(response).find('#wpbody-content').html(); 18 $('#wpbody-content').html(content); 11 var content = $(response).find('#wpbody-content').html(); 12 $('#wpbody-content').html(content); 19 13 20 // Update the browser's URL without reloading the page 21 history.pushState(null, null, url); 14 history.pushState(null, null, url); 22 15 23 // Reinitialize scripts if needed (e.g., for forms, buttons, etc.)24 $(document).trigger('ajaxPageLoad');16 // Trigger reinit 17 $(document).trigger('ajaxPageLoad'); 25 18 26 // Special handling for post-new.php 27 if (url.indexOf('post-new.php') !== -1) { 28 initializePostEditor(); 29 } 19 if (url.indexOf('post-new.php') !== -1) { 20 initializePostEditor(); 21 } 30 22 31 // Remove the full-page overlay with spinner 32 $('.full-page-overlay').remove(); 33 }, 23 // ✅ Update active class in sidebar 24 $('#adminmenu li').removeClass('current wp-has-current-submenu'); 25 if ($link && $link.closest('li').length) { 26 $link.closest('li').addClass('current wp-has-current-submenu'); 27 // Also mark parent if it’s a submenu 28 $link.closest('li.wp-has-submenu').addClass('wp-has-current-submenu'); 29 } 30 31 $('.full-page-overlay').remove(); 32 }, 34 33 error: function() { 35 34 alert('Failed to load content.'); 36 37 // Remove the full-page overlay with spinner38 35 $('.full-page-overlay').remove(); 39 36 } 40 37 }); 38 } 41 39 42 return false; 40 // Handle clicks on admin menu + inner links 41 $(document).on('click', '#adminmenu a, .wrap a', function(e) { 42 var url = $(this).attr('href'); 43 44 // Skip external links or anchors 45 if (!url || url.startsWith('#') || $(this).attr('target') === '_blank') { 46 return; 47 } 48 49 e.preventDefault(); 50 loadAjaxContent(url, $(this)); 43 51 }); 44 52 45 // Handle browser back/forward buttons53 // Handle browser back/forward 46 54 $(window).on('popstate', function() { 47 55 var url = window.location.href; 48 49 // Show the full-page overlay with spinner 50 $('body').append('<div class="full-page-overlay"><div class="spinner"></div></div>'); 51 52 // Load the content via AJAX 53 $.ajax({ 54 url: url, 55 type: 'GET', 56 success: function(response) { 57 var content = $(response).find('#wpbody-content').html(); 58 $('#wpbody-content').html(content); 59 60 // Reinitialize scripts if needed 61 $(document).trigger('ajaxPageLoad'); 62 63 // Special handling for post-new.php 64 if (url.indexOf('post-new.php') !== -1) { 65 initializePostEditor(); 66 } 67 68 // Remove the full-page overlay with spinner 69 $('.full-page-overlay').remove(); 70 }, 71 error: function() { 72 alert('Failed to load content.'); 73 74 // Remove the full-page overlay with spinner 75 $('.full-page-overlay').remove(); 76 } 77 }); 56 loadAjaxContent(url, null); 78 57 }); 79 58 80 // Function to reinitialize the post editor59 // Reinitialize post editor 81 60 function initializePostEditor() { 82 // Reinitialize the WordPress editor components for post-new.php83 61 if (typeof tinymce !== 'undefined') { 84 tinymce.init({ 85 selector: '#content', // Ensure the correct selector is used 86 // Add other TinyMCE options as needed 87 }); 62 tinymce.init({ selector: '#content' }); 88 63 } 89 90 // Reinitialize other scripts for post editor, e.g., Quicktags, media, etc.91 64 if (typeof quicktags !== 'undefined') { 92 65 quicktags({id: 'content'}); … … 95 68 wp.media.editor.initialize('content'); 96 69 } 97 98 // Trigger any other required WordPress actions99 70 $(document).trigger('wp-editor-reinit'); 100 71 } 72 73 // Re-bind WP list table scripts after AJAX load 74 $(document).on('ajaxPageLoad', function() { 75 if (typeof listTable !== 'undefined' && listTable.init) { 76 listTable.init(); 77 } 78 }); 101 79 }); 102 103 104 105 -
ajax-admin-navigation-sidebar-menus-by-ajax/trunk/readme.txt
r3215562 r3505977 3 3 Tags: AJAX Navigation, Navigation with AJAX, AJAX Menu, AJAX Menu Plugin 4 4 Requires at least: 4.6 5 Tested up to: 6. 75 Tested up to: 6.9 6 6 Stable tag: 1.0 7 7 Requires PHP: 5.2.4 … … 49 49 = 1.1 = 50 50 * Fixed a security-related bug. Upgrade immediately. 51 * Fixed loading post and pages inner menus 51 52 52 53 = 1.0 =
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)