Plugin Directory

Changeset 3481332


Ignore:
Timestamp:
03/12/2026 04:27:49 PM (2 weeks ago)
Author:
apos37
Message:

1.3.7.1

  • Tweak: Skipping internal pagination and reply links
  • Tweak: Performance update to not call get_current_user_id() on every link
  • Fix: Reporting sources that don't exist if bots are trying to go somewhere that don't exist and get a 404 page without redirecting
Location:
broken-link-notifier
Files:
56 added
4 edited

Legend:

Unmodified
Added
Removed
  • broken-link-notifier/trunk/broken-link-notifier.php

    r3475895 r3481332  
    44 * Plugin URI:          https://pluginrx.com/plugin/broken-link-notifier/
    55 * Description:         Get notified when someone loads a page with a broken link
    6  * Version:             1.3.7
     6 * Version:             1.3.7.1
    77 * Requires at least:   5.9
    88 * Tested up to:        6.9
  • broken-link-notifier/trunk/includes/helpers.php

    r3475895 r3481332  
    16461646        // If the match is local, easy check
    16471647        } elseif ( str_starts_with( $link, home_url() ) || ( str_starts_with( $link, '/' ) && !str_starts_with( $link, '//' ) ) ) {
     1648
     1649            // Skip replytocom and pagination links
     1650            if ( str_contains( $link, 'replytocom' ) || preg_match( '/\/page\/\d+(\/|$|\?)/', $link ) ) {
     1651                return [
     1652                    'type' => 'good',
     1653                    'code' => 200,
     1654                    'text' => 'Skipping internal pagination or reply link',
     1655                    'link' => $link
     1656                ];
     1657            }
    16481658           
    16491659            // Check locally first
     
    16511661
    16521662                // It may be redirected or an archive page, so let's check status anyway
    1653                 // return $this->check_url_status_code( $link );
    16541663                $status = $this->check_url_status_code( $link );
    16551664                $CACHE->set_cached_link( $status );
     
    16691678
    16701679            // Return the status
    1671             // return $this->check_url_status_code( $link );
    16721680            $status = $this->check_url_status_code( $link );
    16731681            $CACHE->set_cached_link( $status );
  • broken-link-notifier/trunk/includes/results.php

    r3475895 r3481332  
    295295    public function already_added( $link ) {
    296296        global $wpdb;
    297 
    298297        $table_name = $wpdb->prefix . $this->table_name;
    299298        $link_clean = sanitize_text_field( $link );
    300         $link_hash = md5( strtolower( untrailingslashit( $link_clean ) ) );
     299
     300        // 1. New Hash
     301        $url_parts = explode( '?', $link_clean );
     302        $url_parts[ 0 ] = untrailingslashit( $url_parts[ 0 ] );
     303        $new_hash = md5( strtolower( implode( '?', $url_parts ) ) );
     304
     305        // 2. Old Hash
     306        $old_hash = md5( strtolower( untrailingslashit( $link_clean ) ) );
    301307
    302308        $exists = $wpdb->get_var(
    303309            $wpdb->prepare(
    304                 "SELECT id FROM $table_name WHERE link_hash = %s LIMIT 1",
    305                 $link_hash
     310                "SELECT id FROM $table_name WHERE link_hash = %s OR link_hash = %s LIMIT 1",
     311                $new_hash,
     312                $old_hash
    306313            )
    307314        );
    308315
    309         return !empty( $exists );
     316        return ! empty( $exists );
    310317    } // End already_added()
    311318
     
    323330
    324331        $link = sanitize_text_field( $args[ 'link' ] );
    325         $link_normalized = strtolower( untrailingslashit( $link ) );
     332       
     333        $url_parts = explode( '?', $link );
     334        $url_parts[ 0 ] = untrailingslashit( $url_parts[ 0 ] );
     335        $link_normalized = strtolower( implode( '?', $url_parts ) );
    326336        $link_hash = md5( $link_normalized );
    327337
     
    335345        );
    336346
    337         if ( !$source_url ) {
     347        if ( ! $source_url ) {
    338348            return __( 'Invalid source:', 'broken-link-notifier' ) . ' ' . $source_url;
    339349        }
     
    354364                'created_at' => current_time( 'mysql' ),
    355365            ],
    356             [ '%s','%s','%s','%s','%d','%s','%s','%s','%d','%d','%s' ]
     366            [ '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%s', '%d', '%d', '%s' ]
    357367        );
    358368
     
    373383    public function remove( $link ) {
    374384        global $wpdb;
    375 
    376385        $table_name = $wpdb->prefix . $this->table_name;
    377         $link_hash = md5( strtolower( untrailingslashit( sanitize_text_field( $link ) ) ) );
    378 
    379         $deleted = $wpdb->delete(
    380             $table_name,
    381             [ 'link_hash' => $link_hash ],
    382             [ '%s' ]
     386        $link = sanitize_text_field( $link );
     387
     388        // 1. New Normalized Hash
     389        $url_parts = explode( '?', $link );
     390        $url_parts[ 0 ] = untrailingslashit( $url_parts[ 0 ] );
     391        $new_hash = md5( strtolower( implode( '?', $url_parts ) ) );
     392
     393        // 2. Old Logic Hash (Legacy)
     394        $old_hash = md5( strtolower( untrailingslashit( $link ) ) );
     395
     396        // Try to delete by either hash
     397        $deleted = $wpdb->query(
     398            $wpdb->prepare(
     399                "DELETE FROM $table_name WHERE link_hash = %s OR link_hash = %s",
     400                $new_hash,
     401                $old_hash
     402            )
    383403        );
    384404
    385         return ( $deleted > 0 );
     405        return ( false !== $deleted && $deleted > 0 );
    386406    } // End remove()
    387407
     
    605625            }
    606626
     627            // Validate that the URL belongs to this site and exists
     628            $site_url = site_url();
     629            if ( ! str_starts_with( $source_url, $site_url ) ) {
     630                wp_send_json_error( 'External source URLs are not permitted.' );
     631            }
     632
     633            // Check for Post ID with full URL
     634            $post_id = url_to_postid( $source_url );
     635
     636            // If not found, check without query parameters
     637            if ( ! $post_id ) {
     638                $clean_url = strtok( $source_url, '?' );
     639                $post_id  = url_to_postid( $clean_url );
     640            }
     641
     642            // If it's not a post/page and it's not the homepage, it's likely a 404 or invalid
     643            if ( ! $post_id && $source_url !== trailingslashit( $site_url ) && $source_url !== $site_url ) {
     644                wp_send_json_error( 'Source URL does not exist on this site.' );
     645            }
     646
    607647            // Initiate helpers
    608648            $HELPERS = new BLNOTIFIER_HELPERS;
     
    672712            $this->notify( $notify, $count_notify, $all_links, $source_url );
    673713
     714            $current_user_id = get_current_user_id();
     715
    674716            // Add posts
    675717            foreach ( $notify as $location => $n ) {
     
    681723                        'link'     => $status[ 'link' ],
    682724                        'source'   => $source_url,
    683                         'author'   => get_current_user_id(),
     725                        'author'   => $current_user_id,
    684726                        'location' => $location,
    685727                        'method'   => 'visit'
     
    698740                            'link'     => $status[ 'link' ],
    699741                            'source'   => $source_url,
    700                             'author'   => get_current_user_id(),
     742                            'author'   => $current_user_id,
    701743                            'location' => $location,
    702744                            'method'   => 'visit'
  • broken-link-notifier/trunk/readme.txt

    r3475895 r3481332  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 1.3.7
     7Stable tag: 1.3.7.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.txt
     
    127127
    128128== Changelog ==
     129= 1.3.7.1 =
     130* Tweak: Skipping internal pagination and reply links
     131* Tweak: Performance update to not call get_current_user_id() on every link
     132* Fix: Reporting sources that don't exist if bots are trying to go somewhere that don't exist and get a 404 page without redirecting
     133
    129134= 1.3.7 =
    130135* Update: Changed storage of broken links from custom post type to custom database table
Note: See TracChangeset for help on using the changeset viewer.