Plugin Directory

Changeset 3206846


Ignore:
Timestamp:
12/12/2024 09:56:47 AM (16 months ago)
Author:
wp-buy
Message:

bug fixing

Location:
all-404-redirect-to-homepage
Files:
22 added
3 edited

Legend:

Unmodified
Added
Removed
  • all-404-redirect-to-homepage/trunk/all-404-redirect-to-homepage.php

    r3197554 r3206846  
    55Description: a plugin to redirect 404 pages to home page or any custom page
    66Author: wp-buy
    7 Version: 4.8
     7Version: 4.9
    88Author URI: https://www.wp-buy.com
    99*/
  • all-404-redirect-to-homepage/trunk/functions.php

    r3197554 r3206846  
    55    global $wpdb;
    66
    7     // Log activation hook
    8     error_log("setup_redirects_table_and_migrate: Activation hook triggered.");
    9 
    107    // Step 1: Create the redirects table
    118    if (!create_redirects_table()) {
    12         error_log("setup_redirects_table_and_migrate: Table creation failed.");
    139        return;
    1410    }
     
    1612    // Step 2: Migrate data from the old `redirected_links` option
    1713    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
     16function 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
    3325            }
    34         </style>
    35         <?php
    36     }
     26        </style>
     27    <?php
     28    }
    3729}
    3830add_action('customize_controls_print_styles', 'p404_customizer_admin_inline_styles');
    39 
    40 
    41 
    4231
    4332function create_redirects_table()
     
    4837    // Check if the table already exists
    4938    if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
    50         error_log("create_redirects_table: Table `$table_name` already exists.");
    5139        return true;
    5240    }
     
    6856    // Verify table creation
    6957    if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
    70         error_log("create_redirects_table: Table `$table_name` created successfully.");
    7158        return true;
    7259    } else {
    73         error_log("create_redirects_table: Failed to create table `$table_name`.");
    7460        return false;
    7561    }
     
    8571    // Check if there are any links to migrate
    8672    if (empty($option_value['redirected_links'])) {
    87         error_log("migrate_redirected_links: No `redirected_links` data found to migrate.");
    8873        return;
    8974    }
    9075
     76    $counter = 0; // Initialize counter
    9177    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
    9283        $url = $redirect['link'];
    9384        $date = date("Y-m-d H:i:s", strtotime($redirect['date']));
     
    10697                ['id' => $existing->id]
    10798            );
    108             error_log("migrate_redirected_links: Updated URL `$url` with count " . ($existing->count + 1) . ".");
    10999        } else {
    110100            // Insert new URL records
     
    117107                ]
    118108            );
    119             error_log("migrate_redirected_links: Inserted new URL `$url`.");
    120109        }
    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
    128121
    129122function p404_migrate_options()
    130123{
    131124    // 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)
    133126
    134127    if ($migration_status === '0') {
     
    144137        setup_redirects_table_and_migrate();
    145138        // 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');
    153140    }
    154141}
     
    204191
    205192
    206 ?>
     193    ?>
    207194        <script type="text/javascript">
    208195            jQuery(document).ready(function() {
  • all-404-redirect-to-homepage/trunk/readme.txt

    r3197554 r3206846  
    66License URI: http://www.gnu.org/licenses/gpl-2.0.html
    77Tested up to: 6.7.1
    8 Stable tag: 4.8
     8Stable tag: 4.9
    99
    1010Using 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
     
    5252
    5353== Changelog ==
     54
     55= 4.9 =
     56* Bug fixing in the log
    5457
    5558= 4.8 =
Note: See TracChangeset for help on using the changeset viewer.