Changeset 3206846
- Timestamp:
- 12/12/2024 09:56:47 AM (16 months ago)
- Location:
- all-404-redirect-to-homepage
- Files:
-
- 22 added
- 3 edited
-
tags/4.9 (added)
-
tags/4.9/all-404-redirect-to-homepage.php (added)
-
tags/4.9/cf_dropdown.php (added)
-
tags/4.9/functions.php (added)
-
tags/4.9/images (added)
-
tags/4.9/images/action_success.png (added)
-
tags/4.9/images/dialog-warning.png (added)
-
tags/4.9/images/error.png (added)
-
tags/4.9/images/gradient_color_bg.gif (added)
-
tags/4.9/images/gray_bg.gif (added)
-
tags/4.9/images/large-info.png (added)
-
tags/4.9/images/seo-redirect.png (added)
-
tags/4.9/images/seopro.png (added)
-
tags/4.9/js (added)
-
tags/4.9/js/custom.js (added)
-
tags/4.9/license.txt (added)
-
tags/4.9/option_page.php (added)
-
tags/4.9/readme.txt (added)
-
tags/4.9/screenshot-1.png (added)
-
tags/4.9/screenshot-2.png (added)
-
tags/4.9/stylesheet.css (added)
-
tags/4.9/uninstall.php (added)
-
trunk/all-404-redirect-to-homepage.php (modified) (1 diff)
-
trunk/functions.php (modified) (9 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
all-404-redirect-to-homepage/trunk/all-404-redirect-to-homepage.php
r3197554 r3206846 5 5 Description: a plugin to redirect 404 pages to home page or any custom page 6 6 Author: wp-buy 7 Version: 4. 87 Version: 4.9 8 8 Author URI: https://www.wp-buy.com 9 9 */ -
all-404-redirect-to-homepage/trunk/functions.php
r3197554 r3206846 5 5 global $wpdb; 6 6 7 // Log activation hook8 error_log("setup_redirects_table_and_migrate: Activation hook triggered.");9 10 7 // Step 1: Create the redirects table 11 8 if (!create_redirects_table()) { 12 error_log("setup_redirects_table_and_migrate: Table creation failed.");13 9 return; 14 10 } … … 16 12 // Step 2: Migrate data from the old `redirected_links` option 17 13 migrate_redirected_links(); 18 19 error_log("setup_redirects_table_and_migrate: Migration process completed."); 20 } 21 22 23 24 25 function p404_customizer_admin_inline_styles() { 26 // Check if we are in the Customizer page 27 if (is_customize_preview()) { 28 ?> 29 <style> 30 .accordion-section-title button.accordion-trigger { 31 /* Add your desired styles for Customizer accordion button here */ 32 height:auto !important 14 } 15 16 function p404_customizer_admin_inline_styles() 17 { 18 // Check if we are in the Customizer page 19 if (is_customize_preview()) { 20 ?> 21 <style> 22 .accordion-section-title button.accordion-trigger { 23 /* Add your desired styles for Customizer accordion button here */ 24 height: auto !important 33 25 } 34 </style>35 <?php36 }26 </style> 27 <?php 28 } 37 29 } 38 30 add_action('customize_controls_print_styles', 'p404_customizer_admin_inline_styles'); 39 40 41 42 31 43 32 function create_redirects_table() … … 48 37 // Check if the table already exists 49 38 if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) { 50 error_log("create_redirects_table: Table `$table_name` already exists.");51 39 return true; 52 40 } … … 68 56 // Verify table creation 69 57 if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) { 70 error_log("create_redirects_table: Table `$table_name` created successfully.");71 58 return true; 72 59 } else { 73 error_log("create_redirects_table: Failed to create table `$table_name`.");74 60 return false; 75 61 } … … 85 71 // Check if there are any links to migrate 86 72 if (empty($option_value['redirected_links'])) { 87 error_log("migrate_redirected_links: No `redirected_links` data found to migrate.");88 73 return; 89 74 } 90 75 76 $counter = 0; // Initialize counter 91 77 foreach ($option_value['redirected_links'] as $redirect) { 78 // Break the loop if 3000 records have been processed 79 if ($counter >= 3000) { 80 break; 81 } 82 92 83 $url = $redirect['link']; 93 84 $date = date("Y-m-d H:i:s", strtotime($redirect['date'])); … … 106 97 ['id' => $existing->id] 107 98 ); 108 error_log("migrate_redirected_links: Updated URL `$url` with count " . ($existing->count + 1) . ".");109 99 } else { 110 100 // Insert new URL records … … 117 107 ] 118 108 ); 119 error_log("migrate_redirected_links: Inserted new URL `$url`.");120 109 } 121 } 122 123 // Remove `redirected_links` from the options 124 unset($option_value['redirected_links']); 125 update_option($option_name, $option_value); 126 error_log("migrate_redirected_links: `redirected_links` removed from `$option_name`."); 127 } 110 $counter++; // Increment counter 111 } 112 113 // Remove `redirected_links` from the options if all records were migrated 114 if ($counter < count($option_value['redirected_links'])) { 115 } else { 116 unset($option_value['redirected_links']); 117 update_option($option_name, $option_value); 118 } 119 } 120 128 121 129 122 function p404_migrate_options() 130 123 { 131 124 // Check if migration is already completed 132 $migration_status = get_option('p404_migration_status ', '0'); // Default: 0 (not migrated)125 $migration_status = get_option('p404_migration_status2', '0'); // Default: 0 (not migrated) 133 126 134 127 if ($migration_status === '0') { … … 144 137 setup_redirects_table_and_migrate(); 145 138 // Update the migration status to `1` (migrated) 146 update_option('p404_migration_status', '1'); 147 148 // Log migration 149 error_log("P404 Migration completed successfully."); 150 } else { 151 // Log that migration was skipped 152 error_log("P404 Migration skipped. Already completed."); 139 update_option('p404_migration_status2', '1'); 153 140 } 154 141 } … … 204 191 205 192 206 ?>193 ?> 207 194 <script type="text/javascript"> 208 195 jQuery(document).ready(function() { -
all-404-redirect-to-homepage/trunk/readme.txt
r3197554 r3206846 6 6 License URI: http://www.gnu.org/licenses/gpl-2.0.html 7 7 Tested up to: 6.7.1 8 Stable tag: 4. 88 Stable tag: 4.9 9 9 10 10 Using this plugin, you can fix all 404 error links by redirecting them to homepage using the SEO 301 redirection. Improve your SEO rank & pages speed … … 52 52 53 53 == Changelog == 54 55 = 4.9 = 56 * Bug fixing in the log 54 57 55 58 = 4.8 =
Note: See TracChangeset
for help on using the changeset viewer.