Changeset 3185074
- Timestamp:
- 11/10/2024 11:27:08 AM (5 months ago)
- Location:
- ultimate-redirect-manager
- Files:
-
- 20 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified ultimate-redirect-manager/trunk/assets/css/ultimate-404-style.css ¶
r3145944 r3185074 1 /* Tab wrapper*/2 .ultimate-404-wrap{ 3 margin: 20px; 4 } 5 .ultimate-404-wrap .nav-tab-wrapper { 6 margin-bottom: 20px;7 b order-bottom: none;8 display: flex;9 flex-flow: wrap;10 gap: 10px;1 /* ultimate-404-style.css */ 2 3 .ultimate-404-wrap { 4 font-family: Arial, sans-serif; 5 margin-top: 20px; 6 padding: 15px; 7 background-color: #f9f9f9; 8 border: 1px solid #e1e1e1; 9 border-radius: 5px; 10 box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); 11 11 } 12 12 13 /* Tab links */ 14 .ultimate-404-nav-tab { 15 padding: 10px 20px; 16 background-color: #f0f0f0; 17 border: 1px solid #ccc; 18 cursor: pointer; 19 text-decoration: none; 20 color: #333; 21 transition: background-color 0.3s; 13 .nav-tab-wrapper { 14 margin-bottom: 15px; 15 border-bottom: 1px solid #ddd; 22 16 } 23 17 24 .ultimate-404-nav-tab:hover,.ultimate-404-nav-tab.nav-tab-active { 25 background-color: #16acac; 26 color: #fff; 18 .ultimate-404-nav-tab { 19 display: inline-block; 20 padding: 10px 20px; 21 margin-right: 5px; 22 font-weight: bold; 23 color: #0073aa; 24 text-decoration: none; 25 border: 1px solid #ddd; 26 border-bottom: none; 27 background-color: #f1f1f1; 28 border-top-left-radius: 5px; 29 border-top-right-radius: 5px; 30 transition: background-color 0.3s, color 0.3s; 27 31 } 28 32 29 /* Tab content */ 33 .ultimate-404-nav-tab:hover { 34 background-color: #e1e1e1; 35 color: #555; 36 } 37 38 .ultimate-404-nav-tab-active { 39 background-color: #fff; 40 color: #000; 41 border-bottom: 1px solid #fff; 42 } 43 30 44 .ultimate-404-tab-content { 31 45 display: none; 32 46 padding: 20px; 33 border: 1px solid # ccc;47 border: 1px solid #ddd; 34 48 background-color: #fff; 49 border-radius: 5px; 35 50 } 36 51 37 /* Only show active tab content */38 52 .ultimate-404-tab-content.active { 39 53 display: block; 40 54 } 41 55 42 /*ULTIMATE PRO TABS*/ 43 /* Style for the pricing table */ 44 .ultimate-404-pricing-table { 45 display: flex; 46 justify-content: space-between; 47 align-items: flex-start; 48 margin-top: 20px; 56 /* Form and table styling for a classic look */ 57 .ultimate-404-wrap form { 58 margin: 15px 0; 49 59 } 50 60 51 .ultimate-404-pricing-column { 52 width: 30%; 53 padding: 20px; 54 border: 1px solid #ccc; 55 border-radius: 5px; 61 .ultimate-404-wrap table { 62 width: 100%; 63 border-collapse: collapse; 64 margin-top: 15px; 56 65 } 57 66 58 .ultimate-404-pricing-column h3 { 59 margin-top: 0; 60 font-size: 20px; 67 .ultimate-404-wrap table th, 68 .ultimate-404-wrap table td { 69 padding: 8px; 70 text-align: left; 71 border-bottom: 1px solid #ddd; 61 72 } 62 73 63 .ultimate-404- price{64 font-size: 18px;65 margin-bottom: 10px;74 .ultimate-404-wrap table th { 75 background-color: #f1f1f1; 76 font-weight: bold; 66 77 } 67 78 68 .ultimate-404-pricing-column ul { 69 list-style-type: none; 70 padding: 0; 79 .ultimate-404-wrap input[type="text"], 80 .ultimate-404-wrap select { 81 padding: 8px; 82 width: 100%; 83 max-width: 300px; 84 border: 1px solid #ddd; 85 border-radius: 3px; 86 margin-right: 10px; 71 87 } 72 88 73 .ultimate-404-pricing-column ul li { 74 margin-bottom: 10px; 75 display: flex; 76 align-items: center; 89 .ultimate-404-wrap input[type="submit"] { 90 padding: 8px 15px; 91 background-color: #0073aa; 92 color: #fff; 93 border: none; 94 border-radius: 3px; 95 cursor: pointer; 96 transition: background-color 0.3s; 77 97 } 78 98 79 .ultimate-404-pricing-column ul li .dashicons { 80 margin-right: 5px; 81 color: #00b894; /* Change color as needed */ 99 .ultimate-404-wrap input[type="submit"]:hover { 100 background-color: #005177; 82 101 } 83 102 84 .ultimate-404-popup-button { 85 margin-top: 20px; 86 margin-top: 20px; 87 border: none; 88 padding: 0; 103 /* Style the table */ 104 /* Base table styling for larger screens */ 105 .ultimate-redirect-table { 106 width: 100%; 107 border-collapse: collapse; 108 margin-bottom: 20px; 109 background-color: #f9f9f9; 110 border: 1px solid #ddd; 89 111 } 90 112 91 .ultimate-404-popup-button a { 92 text-decoration: none; 113 .ultimate-redirect-table th, 114 .ultimate-redirect-table td { 115 padding: 10px; 116 text-align: left; 117 border: 1px solid #ddd; 118 } 119 120 .ultimate-redirect-table th { 121 background-color: #e5e5e5; 122 font-weight: bold; 123 } 124 125 /* Enhanced button styling */ 126 .ultimate-redirect-table .button { 127 background-color: #0073aa; 93 128 color: #fff; 94 background-color: #00b894; /* Change color as needed */ 95 padding: 10px 20px; 96 border-radius: 5px; 129 border: none; 130 padding: 8px 12px; 131 font-size: 13px; 132 margin-right: 5px; 133 border-radius: 4px; 134 cursor: pointer; 97 135 transition: background-color 0.3s ease; 98 136 } 99 137 100 .ultimate-404-popup-button a:hover { 101 background-color: #00796b; /* Change color as needed */ 138 .ultimate-redirect-table .button:hover { 139 background-color: #005a9e; 140 color: #fff; 102 141 } 142 143 /* Smaller screens: 768px and below */ 144 @media (max-width: 768px) { 145 .ultimate-redirect-table th, 146 .ultimate-redirect-table td { 147 padding: 8px; 148 font-size: 12px; 149 } 150 151 .ultimate-redirect-table .button { 152 padding: 6px 10px; 153 font-size: 12px; 154 } 155 } 156 157 /* Extra-small screens: 480px and below */ 158 @media (max-width: 480px) { 159 .ultimate-redirect-table th, 160 .ultimate-redirect-table td { 161 font-size: 11px; 162 padding: 6px; 163 } 164 165 .ultimate-redirect-table th, .ultimate-redirect-table td { 166 display: block; 167 width: 100%; 168 } 169 170 .ultimate-redirect-table th { 171 background-color: #f1f1f1; 172 } 173 174 .ultimate-redirect-table .button { 175 display: block; 176 width: 100%; 177 padding: 8px; 178 font-size: 12px; 179 margin: 5px 0; 180 } 181 } -
TabularUnified ultimate-redirect-manager/trunk/assets/js/ultimate-404-script.js ¶
r3145944 r3185074 1 1 jQuery(document).ready(function($) { 2 // Handle tab navigation 3 $('.nav-tab-wrapper a').click(function(e) { 2 // Tab navigation 3 const $tabs = $('.nav-tab-wrapper a'); 4 const $tabContents = $('.ultimate-404-tab-content'); 5 6 $tabs.on('click', function(e) { 4 7 e.preventDefault(); 5 var tabId = $(this).attr('href'); // Get the href attribute of the clicked tab 6 $('.nav-tab-wrapper a').removeClass('nav-tab-active'); // Remove active class from all tabs 7 $(this).addClass('nav-tab-active'); // Add active class to the clicked tab 8 $('.ultimate-404-tab-content').hide(); // Hide all tab contents 9 $(tabId).show(); // Show the tab content corresponding to the clicked tab 10 // Update the URL slug based on the tab 11 var currentSlug = window.location.href.split('#')[0]; // Get the current URL without the hash 12 var newSlug = currentSlug + tabId; // Append the tabId to the current URL 13 history.pushState({}, '', newSlug); // Update the URL without reloading the page 14 8 9 // Get the href attribute of the clicked tab 10 const tabId = $(this).attr('href'); 11 12 // Update tab classes and show relevant content 13 $tabs.removeClass('nav-tab-active'); 14 $(this).addClass('nav-tab-active'); 15 $tabContents.hide(); 16 $(tabId).show(); 17 18 // Update URL without reloading the page 19 const currentUrl = window.location.href.split('#')[0]; 20 history.pushState({}, '', currentUrl + tabId); 21 15 22 // Store the active tab ID in local storage 16 23 localStorage.setItem('activeTabId', tabId); 17 24 }); 18 25 19 // Trigger click event on the tab specified in the URL 20 var activeTabId = window.location.hash; // Get the tab ID from the URL hash 21 if (activeTabId) { 22 $('.nav-tab-wrapper a[href="' + activeTabId + '"]').trigger('click'); // Trigger click event on the tab with the specified ID 23 } else { 26 // Load tab based on URL hash or local storage 27 const activeTabId = window.location.hash || localStorage.getItem('activeTabId') || $tabs.first().attr('href'); 28 $tabs.filter(`[href="${activeTabId}"]`).trigger('click'); 24 29 25 // If no tab ID in the URL, trigger click event on the stored active tab or the first tab 26 var storedActiveTabId = localStorage.getItem('activeTabId'); 27 if (storedActiveTabId) { 28 $('.nav-tab-wrapper a[href="' + storedActiveTabId + '"]').trigger('click'); // Trigger click event on the stored active tab 29 } else { 30 $('.nav-tab-wrapper a:first').trigger('click'); // Trigger click event on the first tab 30 // Handle row deletion with AJAX 31 $(document).on('click', '.delete-row', function(e) { 32 e.preventDefault(); 33 const rowId = $(this).data('rule-id'); 34 35 if (!rowId) { 36 alert('Invalid row ID'); 37 return; 31 38 } 32 }33 39 34 $('.delete-row').on('click', function() { 35 var rowId = $(this).data('rule-id'); 36 var data = { 37 'action': 'delete_rule', 38 'rule_id': rowId 40 // Confirmation popup before deletion 41 const confirmDelete = confirm("Are you sure you want to delete this row?"); 42 if (!confirmDelete) return; 43 44 const data = { 45 action: 'delete_rule', 46 rule_id: rowId 39 47 }; 40 48 … … 44 52 data: data, 45 53 success: function(response) { 46 // Handle success47 alert('Row deleted successfully');48 // Optionally, you can remove the deleted row from the table49 // $(this).closest('tr').remove();50 // Reload the page to reflect the changes51 location.reload();54 if (response.success) { 55 alert('Row deleted successfully'); 56 $(`[data-rule-id="${rowId}"]`).remove(); 57 } else { 58 alert('Error deleting row: ' + response.data); 59 } 52 60 }, 53 61 error: function(xhr, status, error) { 54 // Handle error55 62 alert('Error deleting row: ' + error); 56 63 } 57 64 }); 58 65 }); 66 67 // Edit functionality 68 $(document).on('click', '.edit-row', function(e) { 69 e.preventDefault(); 70 const row = $(this).closest('tr'); 71 row.find('.rule-source-url, .rule-destination-url, .rule-redirect-type').hide(); 72 row.find('.edit-source-url, .edit-destination-url, .edit-redirect-type').show(); 73 row.find('.edit-row').hide(); 74 row.find('.save-row').show(); 75 }); 76 77 // Save functionality with AJAX 78 $(document).on('click', '.save-row', function(e) { 79 e.preventDefault(); 80 const row = $(this).closest('tr'); 81 const ruleId = row.data('rule-id'); 82 const sourceUrl = row.find('.edit-source-url').val(); 83 const destinationUrl = row.find('.edit-destination-url').val(); 84 const redirectType = row.find('.edit-redirect-type').val(); 85 86 // AJAX request to save the updated rule 87 $.ajax({ 88 url: ajaxurl, 89 type: 'POST', 90 data: { 91 action: 'update_redirect_rule', 92 rule_id: ruleId, 93 source_url: sourceUrl, 94 destination_url: destinationUrl, 95 redirect_type: redirectType 96 }, 97 success: function(response) { 98 if (response.success) { 99 alert('Rule updated successfully'); 100 reloadRedirectRulesTable(); 101 } else { 102 alert('Error updating the rule: ' + response.data); 103 } 104 }, 105 error: function(xhr, status, error) { 106 alert('AJAX error: ' + error); 107 } 108 }); 109 }); 110 111 // Function to reload the table with updated data 112 function reloadRedirectRulesTable() { 113 $.ajax({ 114 url: ajaxurl, 115 type: 'POST', 116 data: { 117 action: 'get_redirect_rules' 118 }, 119 success: function(response) { 120 if (response.success) { 121 $('.ultimate-redirect-table').html(response.data); // Replace table content 122 } else { 123 alert('Error loading updated data: ' + response.data); 124 } 125 }, 126 error: function(xhr, status, error) { 127 alert('AJAX error: ' + error); 128 } 129 }); 130 } 131 59 132 }); -
TabularUnified ultimate-redirect-manager/trunk/readme.txt ¶
r3149259 r3185074 7 7 **Contributors:** rstheme2017, rubrash 8 8 **Tags:** error 404, page not found, redirect, 301 redirect, permanent redirect 9 **Version:** 1.0. 09 **Version:** 1.0.1 10 10 **License:** GPLv2 or later 11 11 **License URI:** http://www.gnu.org/licenses/gpl-2.0.html 12 **Stable tag:** 1.0. 013 **Tested up to:** 6.6. 112 **Stable tag:** 1.0.1 13 **Tested up to:** 6.6.2 14 14 **Requires PHP:** 7.0.0 15 15 **Requires at least:** 5.5 … … 134 134 ## Changelog ## 135 135 136 = 1.0.1 31-10-2024 = 137 138 * Bug Fixing 139 * Normalize URLs for comparison 140 * Improve URL matching 141 136 142 = 1.0.0 02-09-2024 = 137 143 -
TabularUnified ultimate-redirect-manager/trunk/ultimate-class/class-ultimate-404-script.php ¶
r3145944 r3185074 4 4 class Ultimate_404_Script { 5 5 // Define the plugin version as a constant 6 const PLUGIN_VERSION = '1.0. 0';6 const PLUGIN_VERSION = '1.0.1'; 7 7 8 8 public function __construct() { … … 19 19 public function enqueue_scripts() { 20 20 wp_enqueue_style( 'ultimate-404-style', plugins_url( 'assets/css/ultimate-404-style.css', ULTIMATE_404_FILE_LITE ), array(), self::PLUGIN_VERSION ); 21 wp_enqueue_script( 'ultimate-404-script', plugins_url( 'assets/js/ultimate-404-script.js', ULTIMATE_404_FILE_LITE ), array( 'jquery' ), self::PLUGIN_VERSION, true );21 22 22 } 23 23 } -
TabularUnified ultimate-redirect-manager/trunk/ultimate-class/class-ultimate-404-settings.php ¶
r3145944 r3185074 1 1 <?php 2 2 3 namespace Ultimate_Solution\Ultimate; 3 4 4 5 class Ultimate_404_Settings { 5 6 public function __construct() { 6 // Register hooks7 7 add_action('admin_init', array($this, 'ultimate_404_register_settings')); 8 8 add_action('admin_init', array($this, 'ultimate_404_redirect_rules_settings')); 9 } 10 9 add_action('wp_ajax_update_redirect_rule', array($this, 'handle_update_redirect_rule')); 10 add_action('wp_ajax_delete_rule', array($this, 'handle_delete_rule')); 11 add_action('wp_ajax_get_redirect_rules', array($this, 'get_redirect_rules')); 12 add_action('admin_init', array($this, 'clear_cache')); 13 14 } 15 16 public function clear_cache() 17 { 18 header("Cache-Control: no-cache, must-revalidate"); 19 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 20 header("Content-Type: application/xml; charset=utf-8"); 21 } 22 23 // Registering settings for 404 redirect page 11 24 public function ultimate_404_register_settings() { 12 // Define a new settings section for page settings13 25 add_settings_section( 14 'ultimate_404_page_settings_section', // Section ID 15 '404 Page Redirection', // Section Title 16 array($this, 'ultimate_section_callback'), // Callback for rendering section description 17 'ultimate_404_page_settings' // Page where the section will be displayed 18 ); 19 20 // Register a new settings field for selecting the custom 404 page 26 'ultimate_404_page_settings_section', 27 '404 Page Redirection', 28 array($this, 'ultimate_section_callback'), 29 'ultimate_404_page_settings' 30 ); 31 21 32 add_settings_field( 22 'custom_404_page_dropdown', // Field ID 23 'Select Page', // Field Title 24 array($this, 'ultimate_dropdown_callback'), // Callback for rendering the dropdown 25 'ultimate_404_page_settings', // Page where the field will be displayed 26 'ultimate_404_page_settings_section' // Section to which the field belongs 27 ); 28 29 // Register the setting for the custom 404 page 33 'custom_404_page_dropdown', 34 'Select Page', 35 array($this, 'ultimate_dropdown_callback'), 36 'ultimate_404_page_settings', 37 'ultimate_404_page_settings_section' 38 ); 39 30 40 register_setting( 31 'ultimate_custom_404_page_options', // Option group32 'custom_ultimate_404_page_id', // Option name33 array($this, 'ultimate_sanitize_page_id') // Sanitization callback41 'ultimate_custom_404_page_options', 42 'custom_ultimate_404_page_id', 43 array($this, 'ultimate_sanitize_page_id') 34 44 ); 35 45 } 36 46 37 47 public function ultimate_sanitize_page_id($input) { 38 // Sanitize page ID here if needed 39 return $input; 48 return intval($input); 40 49 } 41 50 42 51 public function ultimate_section_callback() { 43 // Section description (if any) 44 echo '<p>' . esc_html__( 'Select a page to serve as your custom 404 error page.', 'ultimate-redirect-manager' ) . '</p>'; 45 52 echo '<p>' . esc_html__('Select a page to serve as your custom 404 error page.', 'ultimate-redirect-manager') . '</p>'; 46 53 } 47 54 48 55 public function ultimate_dropdown_callback() { 49 // Output the dropdown menu for selecting page50 56 $pages = get_pages(); 51 57 $selected_page = get_option('custom_ultimate_404_page_id'); 52 58 echo '<select id="custom_404_page_dropdown" name="custom_ultimate_404_page_id">'; 53 echo '<option value="">' . esc_html__( 'Select Page', 'ultimate-redirect-manager' ) . '</option>'; // Add a default option59 echo '<option value="">' . esc_html__('Select Page', 'ultimate-redirect-manager') . '</option>'; 54 60 foreach ($pages as $page) { 55 61 $selected = ($selected_page == $page->ID) ? 'selected' : ''; 56 echo '<option value="' . esc_attr($page->ID) . '" ' . esc_attr($selected) . '>' . esc_html( $page->post_title) . '</option>';62 echo '<option value="' . esc_attr($page->ID) . '" ' . esc_attr($selected) . '>' . esc_html($page->post_title) . '</option>'; 57 63 } 58 64 echo '</select>'; 59 65 } 60 66 61 67 // Registering settings for manual redirect rules 62 68 public function ultimate_404_redirect_rules_settings() { 63 // Define a new settings section for redirect rules64 69 add_settings_section( 65 'ultimate_404_redirect_rules_section', // Section ID 66 'Manual Redirect Table', // Section Title 67 array($this, 'ultimate_redirect_rules_section_callback'), // Callback for rendering section description 68 'ultimate_404_page_settings' // Page where the section will be displayed 69 ); 70 71 // Add fields for managing redirect rules 70 'ultimate_404_redirect_rules_section', 71 'Manual Redirect Table', 72 array($this, 'ultimate_redirect_rules_section_callback'), 73 'ultimate_404_page_settings' 74 ); 75 72 76 add_settings_field( 73 'redirect_rules_field', // Field ID 74 'Add a Manual Redirect', // Field Title 75 array($this, 'ultimate_redirect_rules_field_callback'), // Callback for rendering the field 76 'ultimate_404_page_settings', // Page where the field will be displayed 77 'ultimate_404_redirect_rules_section' // Section to which the field belongs 78 ); 79 } 80 81 // Callback function for rendering the section description for redirect rules 77 'redirect_rules_field', 78 'Add a Manual Redirect', 79 array($this, 'ultimate_redirect_rules_field_callback'), 80 'ultimate_404_page_settings', 81 'ultimate_404_redirect_rules_section' 82 ); 83 } 84 82 85 public function ultimate_redirect_rules_section_callback() { 83 // Section description (if any)84 echo '<p>' . esc_html__( 'Manual Redirect Table is here.', 'ultimate-redirect-manager' ) . '</p>';85 // Display existing redirect rules from the database86 86 global $wpdb; 87 87 $table_name = $wpdb->prefix . 'ultimate_redirect_rules'; 88 88 $redirect_rules = $wpdb->get_results("SELECT * FROM $table_name", ARRAY_A); 89 // Display the table for displaying existing redirect rules 90 echo '<table class="wp-list-table widefat fixed">'; 91 // Add table headers for displaying existing redirect rules 92 echo '<thead>'; 93 echo '<tr style="text-align: left;">'; 94 echo '<th style="width: 20%;">' . esc_html__('Source URL', 'ultimate-redirect-manager') . '</th>'; 95 echo '<th style="width:15%;">' . esc_html__('Status', 'ultimate-redirect-manager') . '</th>'; 96 echo '<th style="width:15%;">' . esc_html__('Type', 'ultimate-redirect-manager') . '</th>'; 97 echo '<th style="width: 20%;">' . esc_html__('Destination URL', 'ultimate-redirect-manager') . '</th>'; 98 echo '<th style="width: 10%;">' . esc_html__('Redirect Type', 'ultimate-redirect-manager') . '</th>'; 99 100 echo '<th style="width: 15%;">' . esc_html__('Created', 'ultimate-redirect-manager') . '</th>'; 101 102 echo '<th style="width: 5%;">' . esc_html__('Action', 'ultimate-redirect-manager') . '</th>'; 103 echo '</tr>'; 104 echo '</thead>'; 105 echo '<tbody>'; 106 foreach ( $redirect_rules as $rule ) { 107 echo '<tr>'; 108 echo '<td>' . esc_attr( $rule['source_url'] ) . '</td>'; 109 echo '<td>' . esc_attr( $rule['status'] ) . '</td>'; 110 echo '<td>' . esc_attr( $rule['type'] ) . '</td>'; 111 echo '<td>' . esc_attr( $rule['destination_url'] ) . '</td>'; 112 echo '<td>' . esc_attr( $rule['redirect_type'] ) . '</td>'; 113 114 echo '<td>' . esc_attr( $rule['created'] ) . '</td>'; 115 116 echo '<td><button class="delete-row" data-rule-id="' . esc_attr( $rule['id'] ) . '">Delete</button></td>'; 89 90 // Change class name here to avoid conflicts 91 echo '<table class="ultimate-redirect-table widefat fixed">'; 92 echo '<thead><tr>'; 93 echo '<th>' . esc_html__('Source URL', 'ultimate-redirect-manager') . '</th>'; 94 echo '<th>' . esc_html__('Status', 'ultimate-redirect-manager') . '</th>'; 95 echo '<th>' . esc_html__('Type', 'ultimate-redirect-manager') . '</th>'; 96 echo '<th>' . esc_html__('Destination URL', 'ultimate-redirect-manager') . '</th>'; 97 echo '<th>' . esc_html__('Redirect Type', 'ultimate-redirect-manager') . '</th>'; 98 echo '<th>' . esc_html__('Created', 'ultimate-redirect-manager') . '</th>'; 99 echo '<th>' . esc_html__('Action', 'ultimate-redirect-manager') . '</th>'; 100 echo '</tr></thead><tbody>'; 101 102 foreach ($redirect_rules as $rule) { 103 echo '<tr data-rule-id="' . esc_attr($rule['id']) . '" class="redirect-rule">'; 104 echo '<td><span class="rule-source-url">' . esc_html($rule['source_url']) . '</span>'; 105 echo '<input type="text" class="edit-source-url" value="' . esc_attr($rule['source_url']) . '" style="display:none;" /></td>'; 106 echo '<td>' . esc_html($rule['status']) . '</td>'; 107 echo '<td>' . esc_html($rule['type']) . '</td>'; 108 echo '<td><span class="rule-destination-url">' . esc_html($rule['destination_url']) . '</span>'; 109 echo '<input type="text" class="edit-destination-url" value="' . esc_attr($rule['destination_url']) . '" style="display:none;" /></td>'; 110 echo '<td><span class="rule-redirect-type">' . esc_html($rule['redirect_type']) . '</span>'; 111 echo '<select class="edit-redirect-type" style="display:none;">'; 112 echo '<option value="301"' . selected($rule['redirect_type'], '301', false) . '>301 (Permanent)</option>'; 113 echo '<option value="302"' . selected($rule['redirect_type'], '302', false) . '>302 (Temporary)</option>'; 114 echo '</select></td>'; 115 echo '<td>' . esc_html(date('Y-m-d H:i:s', strtotime($rule['created']))) . '</td>'; 116 echo '<td><button class="button edit-row">Edit</button>'; 117 echo '<button class="button save-row" style="display:none;">Save</button>'; 118 echo '<button class="button delete-row" data-rule-id="' . esc_attr($rule['id']) . '">Delete</button></td>'; 117 119 echo '</tr>'; 118 120 } 119 echo '</tbody>'; 120 echo '</table>'; 121 121 122 echo '</tbody></table>'; 123 } 124 125 126 public function ultimate_redirect_rules_field_callback() { 127 // Form for adding a new redirect rule 128 echo '<input type="text" name="source_url" placeholder="Source URL" />'; 129 echo '<input type="text" name="destination_url" placeholder="Destination URL" />'; 130 echo '<select name="redirect_type" >'; 131 echo '<option value="301">301 (Permanent)</option>'; 132 echo '<option value="302">302 (Temporary)</option>'; 133 echo '</select>'; 122 134 123 135 } 124 136 125 // Callback function for rendering the field to manage redirect rules 126 public function ultimate_redirect_rules_field_callback() { 127 128 if (isset($_POST['submit'])) { 129 // Form submitted, insert data into the database 130 $source_url = sanitize_text_field($_POST['source_url']); 131 $destination_url = sanitize_text_field($_POST['destination_url']); 132 $redirect_type = sanitize_text_field($_POST['redirect_type']); 133 134 global $wpdb; 135 $table_name = $wpdb->prefix . 'ultimate_redirect_rules'; 136 $wpdb->insert( 137 $table_name, 138 array( 139 'source_url' => $source_url, 140 'destination_url' => $destination_url, 141 'redirect_type' => $redirect_type, 142 // Set default values for other columns 143 'status' => 'Active', 144 'type' => 'Manual', // Assuming this is a custom rule 145 ), 146 array( 147 '%s', 148 '%s', 149 '%s', 150 '%s', 151 '%s', 152 '%d', 153 '%s', 154 155 ) 156 ); 137 // Handle AJAX request for updating redirect rules 138 public function handle_update_redirect_rule() { 139 global $wpdb; 140 $table_name = $wpdb->prefix . 'ultimate_redirect_rules'; 141 142 $rule_id = intval($_POST['rule_id']); 143 $source_url = sanitize_text_field($_POST['source_url']); 144 $destination_url = sanitize_text_field($_POST['destination_url']); 145 $redirect_type = sanitize_text_field($_POST['redirect_type']); 146 147 $wpdb->update( 148 $table_name, 149 array( 150 'source_url' => $source_url, 151 'destination_url' => $destination_url, 152 'redirect_type' => $redirect_type, 153 ), 154 array('id' => $rule_id) 155 ); 156 157 wp_send_json_success(); 158 } 159 160 // Handle AJAX request for deleting redirect rules 161 public function handle_delete_rule() { 162 global $wpdb; 163 $table_name = $wpdb->prefix . 'ultimate_redirect_rules'; 164 165 $rule_id = intval($_POST['rule_id']); 166 $wpdb->delete($table_name, array('id' => $rule_id)); 167 168 wp_send_json_success(); 169 } 170 171 // Handle AJAX request to get the updated redirect rules table 172 public function get_redirect_rules() { 173 global $wpdb; 174 $table_name = $wpdb->prefix . 'ultimate_redirect_rules'; 175 $redirect_rules = $wpdb->get_results("SELECT * FROM $table_name", ARRAY_A); 176 177 ob_start(); 178 echo '<table class="wp-list-table widefat fixed">'; 179 echo '<thead><tr>'; 180 echo '<th>' . esc_html__('Source URL', 'ultimate-redirect-manager') . '</th>'; 181 echo '<th>' . esc_html__('Status', 'ultimate-redirect-manager') . '</th>'; 182 echo '<th>' . esc_html__('Type', 'ultimate-redirect-manager') . '</th>'; 183 echo '<th>' . esc_html__('Destination URL', 'ultimate-redirect-manager') . '</th>'; 184 echo '<th>' . esc_html__('Redirect Type', 'ultimate-redirect-manager') . '</th>'; 185 echo '<th>' . esc_html__('Created', 'ultimate-redirect-manager') . '</th>'; 186 echo '<th>' . esc_html__('Action', 'ultimate-redirect-manager') . '</th>'; 187 echo '</tr></thead><tbody>'; 188 189 foreach ($redirect_rules as $rule) { 190 echo '<tr data-rule-id="' . esc_attr($rule['id']) . '" class="redirect-rule">'; 191 echo '<td><span class="rule-source-url">' . esc_html($rule['source_url']) . '</span>'; 192 echo '<input type="text" class="edit-source-url" value="' . esc_attr($rule['source_url']) . '" style="display:none;" /></td>'; 193 echo '<td>' . esc_html($rule['status']) . '</td>'; 194 echo '<td>' . esc_html($rule['type']) . '</td>'; 195 echo '<td><span class="rule-destination-url">' . esc_html($rule['destination_url']) . '</span>'; 196 echo '<input type="text" class="edit-destination-url" value="' . esc_attr($rule['destination_url']) . '" style="display:none;" /></td>'; 197 echo '<td><span class="rule-redirect-type">' . esc_html($rule['redirect_type']) . '</span>'; 198 echo '<select class="edit-redirect-type" style="display:none;">'; 199 echo '<option value="301"' . selected($rule['redirect_type'], '301', false) . '>301 (Permanent)</option>'; 200 echo '<option value="302"' . selected($rule['redirect_type'], '302', false) . '>302 (Temporary)</option>'; 201 echo '</select></td>'; 202 echo '<td>' . esc_html(date('Y-m-d H:i:s', strtotime($rule['created']))) . '</td>'; 203 echo '<td><button class="button edit-row">Edit</button>'; 204 echo '<button class="button save-row" style="display:none;">Save</button>'; 205 echo '<button class="button delete-row" data-rule-id="' . esc_attr($rule['id']) . '">Delete</button></td>'; 206 echo '</tr>'; 157 207 } 158 208 159 // Output the form and table for managing redirect rules 160 $this->output_redirect_rules_form(); 161 162 } 163 164 public function output_redirect_rules_form() { 165 166 echo '<form method="post" action="">'; 167 echo '<table class="form-table">'; 168 // Add fields for managing redirect rules (source URL, destination URL, redirect type) 169 echo '<tr>'; 170 echo '<th scope="row">' . esc_html__('Source URL', 'ultimate-redirect-manager') . '</th>'; 171 echo '<td><input type="text" name="source_url" placeholder="/page-url/" value="" /></td>'; 172 echo '</tr>'; 173 echo '<tr>'; 174 echo '<th scope="row">' . esc_html__('Destination URL', 'ultimate-redirect-manager') . '</th>'; 175 echo '<td><input type="text" name="destination_url" placeholder="/page-url/" value="" /></td>'; 176 echo '</tr>'; 177 echo '<tr>'; 178 echo '<th scope="row">' . esc_html__('Redirect Type', 'ultimate-redirect-manager') . '</th>'; 179 echo '<td>'; 180 echo '<select name="redirect_type">'; 181 echo '<option value="301">' . esc_html__('Default', 'ultimate-redirect-manager') . '</option>'; 182 echo '<option value="301">' . esc_html__('301 Moved Permanently', 'ultimate-redirect-manager') . '</option>'; 183 echo '<option value="302">' . esc_html__('302 Temporary Redirect', 'ultimate-redirect-manager') . '</option>'; 184 185 echo '</select>'; 186 echo '</td>'; 187 echo '</tr>'; 188 echo '</table>'; 189 echo '<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="' . esc_html__('Save Rule', 'ultimate-redirect-manager') . '"></p>'; 190 echo '</form>'; 191 } 192 209 echo '</tbody></table>'; 210 $html = ob_get_clean(); 211 wp_send_json_success($html); 212 } 193 213 194 214 } 195 ?> 215 216 // Initialize the plugin 217 if (is_admin()) { 218 new Ultimate_404_Settings(); 219 } -
TabularUnified ultimate-redirect-manager/trunk/ultimate-class/class-ultimate-404-solution.php ¶
r3145944 r3185074 17 17 } 18 18 19 if (!is_404()) { 20 // Manual redirection for specific source URLs 19 // Check if it’s not a 404 page and not in Elementor preview mode 20 if (!is_404() && !isset($_GET['elementor-preview'])) { 21 global $wpdb; 22 $current_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 23 $parsed_current_url = parse_url($current_url); 24 $table_name = $wpdb->prefix . 'ultimate_redirect_rules'; 25 $redirect_rules = $wpdb->get_results("SELECT * FROM $table_name WHERE status = 'Active'", ARRAY_A); 21 26 22 // Sanitize the requested URL 23 $raw_url = sanitize_text_field( $_SERVER['REQUEST_URI'] ); 24 25 // Parse the sanitized URL to get the path 26 $source_url = wp_parse_url( $raw_url, PHP_URL_PATH ); 27 28 global $wpdb; 29 $table_name = $wpdb->prefix . 'ultimate_redirect_rules'; 30 31 // Prepare and execute the SQL query to fetch the destination URL based on the source URL 32 $sql = $wpdb->prepare("SELECT destination_url FROM {$table_name} WHERE source_url = %s", $source_url); 33 $destination_url = $wpdb->get_var($sql); 34 35 36 // Initialize the redirect rules array 37 $redirect_rules = array(); 38 39 // Check if the destination URL exists 40 if ($destination_url) { 41 $redirect_rules[$source_url] = $destination_url; 42 } 43 44 // Check if the source URL matches any manual redirect 45 if (array_key_exists($source_url, $redirect_rules)) { 46 // Redirect manually 47 wp_redirect(home_url($redirect_rules[$source_url]), 301); 48 exit(); 27 foreach ($redirect_rules as $rule) { 28 $parsed_rule_url = parse_url($rule['source_url']); 29 if (($parsed_rule_url['path'] ?? '') === ($parsed_current_url['path'] ?? '')) { 30 wp_redirect($rule['destination_url'], $rule['redirect_type']); 31 exit; 32 } 49 33 } 50 34 } -
TabularUnified ultimate-redirect-manager/trunk/ultimate-redirect-manager.php ¶
r3145944 r3185074 3 3 * Plugin Name: Ultimate Redirect Manager 4 4 * Description: Ultimate Redirect Manager is the most advanced redirection tool for WordPress. This Redirect tool will redirect your website's error links and URLs to the pages you select. 5 * Version: 1.0. 05 * Version: 1.0.1 6 6 * Plugin URI: https://wordpress.org/plugins/ultimate-redirect-manager/ 7 7 * License: GPL v2 or later … … 17 17 defined('ABSPATH') or die('Hey, what are you doing here? You silly human!'); 18 18 19 // Define Custom Constant Variables 20 define('ULTIMATE_404_VERSION_LITE', '1.0.0'); 19 define('ULTIMATE_404_VERSION_LITE', '1.0.1'); 21 20 define('ULTIMATE_404_PLUGIN_DIR_LITE', plugin_dir_path(__FILE__)); 22 21 define('ULTIMATE_404_PLUGIN_URL_LITE', plugin_dir_url(__FILE__)); … … 31 30 use Ultimate_Solution\Ultimate\Ultimate_404_Activation; 32 31 33 require_once ULTIMATE_404_PLUGIN_DIR_LITE . ' /ultimate-class/class-ultimate-404-menu.php';34 require_once ULTIMATE_404_PLUGIN_DIR_LITE . ' /ultimate-class/class-ultimate-404-settings.php';35 require_once ULTIMATE_404_PLUGIN_DIR_LITE . ' /ultimate-class/class-ultimate-404-solution.php';36 require_once ULTIMATE_404_PLUGIN_DIR_LITE . ' /ultimate-class/class-ultimate-404-script.php';37 require_once ULTIMATE_404_PLUGIN_DIR_LITE . ' /ultimate-class/class-ultimate-404-textdomain.php';38 require_once ULTIMATE_404_PLUGIN_DIR_LITE . ' /ultimate-class/class-ultimate-404-activation.php';32 require_once ULTIMATE_404_PLUGIN_DIR_LITE . 'ultimate-class/class-ultimate-404-menu.php'; 33 require_once ULTIMATE_404_PLUGIN_DIR_LITE . 'ultimate-class/class-ultimate-404-settings.php'; 34 require_once ULTIMATE_404_PLUGIN_DIR_LITE . 'ultimate-class/class-ultimate-404-solution.php'; 35 require_once ULTIMATE_404_PLUGIN_DIR_LITE . 'ultimate-class/class-ultimate-404-script.php'; 36 require_once ULTIMATE_404_PLUGIN_DIR_LITE . 'ultimate-class/class-ultimate-404-textdomain.php'; 37 require_once ULTIMATE_404_PLUGIN_DIR_LITE . 'ultimate-class/class-ultimate-404-activation.php'; 39 38 39 // Instantiate classes 40 40 $ultimate_404_menu = new Ultimate_404_Menu(); 41 41 $ultimate_404_settings = new Ultimate_404_Settings(); … … 45 45 $ultimate_404_activation = new Ultimate_404_Activation(); 46 46 47 // Database setup on plugin activation 47 48 register_activation_hook(__FILE__, array('Ultimate_Solution\Ultimate\Ultimate_404_Activation', 'ultimate_404_database_table')); 48 49 register_activation_hook(__FILE__, array('Ultimate_Solution\Ultimate\Ultimate_404_Activation', 'ultimate_404_captured_url_table')); 49 50 register_activation_hook(__FILE__, array('Ultimate_Solution\Ultimate\Ultimate_404_Activation', 'ultimate_404_redirect_rules_table')); 51 52 // Disable debug display if WP_DEBUG is enabled 53 if (defined('WP_DEBUG') && WP_DEBUG) { 54 add_filter('wp_debug_display', function($display) { 55 return false; 56 }); 57 }
Note: See TracChangeset
for help on using the changeset viewer.