Skip to main content

Patching the Broken Link Checker for Wordpress. (WPMU DEV)

It is possible to patch the official broken link checker for WordPress to use the legacy version only.

Alternative is to use the forked Broken Link Checker for Wordpress

With the plugin installed, fire up a ftp client and navigate to:

[WP-ROOT]/wp-content/plugins/broken-link_checker/core/utils

Open class-utilities.php for editing.

Find  public static function is_subsite(), should be around line 100 and add a return true; as first line. This will pretend that your website is a multisite installation.  The current version of the broken link checker does not support multisite. And the plugin will use the legacy version without nagging menu's and screens.

public static function is_subsite() {
		//pretend to be multisite 
		return true;
		if ( ! is_multisite() ) {
			return false;
		}

		/**
		 * Filter to change subsite admin flag.
		 *
		 * @since 2.0.0
		 *
		 * @param bool Is subsite.
		 */
		return apply_filters(
			'wpmudev_blc_is_subsite',
			! ( self::is_network_admin() || is_main_site() )
		);
	}

Navigate to [WP-ROOT]/ and open broken-link-checker.php. Add to the bottom:

//this will remove unused Cloud functionality and naging modals.
//can be edited in core/class-loader.php init_app directly as well.
add_filter(
    'wpmudev_blc_load_components',
    function () {
        return [ 'Admin_Pages',];
    }
);

Other bug fixes

Count Bubble

The old version had a small counter bubble in the menu showing the broken links. This one is not displayed anymore. While the query to get the number of broken links is still executed!

To fix this, navigate to [WP-ROOT]/legacy/core/ and open core.php and change the function admin_menu

public function admin_menu() {
    if ( current_user_can( 'manage_options' ) ) {
        add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
    }

    $menu_title = __( 'Broken Links', 'broken-link-checker' );  #<-------CHANGE ME ---------
    if ( $this->conf->options['show_link_count_bubble'] ) {
        // To make it easier to notice when broken links appear, display the current number of
        // broken links in a little bubble notification in the "Broken Links" menu.
        // (Similar to how the number of plugin updates and unmoderated comments is displayed).
        $blc_link_query = blcLinkQuery::getInstance();
        $broken_links   = $blc_link_query->get_filter_links( 'broken', array( 'count_only' => true ) );
        if ( WPMUDEV_BLC\App\Options\Settings\Model::instance()->get( 'use_legacy_blc_version' ) && $broken_links > 0 ) {
            // TODO: Appropriating existing CSS classes for my own purposes is hacky. Fix eventually.
            $menu_title .= sprintf(
            ' <span class="update-plugins"><span class="update-count blc-menu-bubble">%d</span></span>',
            $broken_links
            );
        }
    }

    /**
    * Until multisites are officially supported, BLC v2 menus are disabled in subsites.
    * Legacy menus are loaded instead.
    */
    if ( WPMUDEV_BLC\Core\Utils\Utilities::is_subsite() ) {
        $page_controler_cloud = WPMUDEV_BLC\App\Admin_Pages\Cloud_Page\Controller::instance();
        $links_page_hook      = add_menu_page(
                __( 'Broken Links', 'broken-link-checker' ),
                $menu_title, #<-------CHANGE ME ---------
                'edit_others_posts',
                WPMUDEV_BLC\App\Admin_Pages\Local_Submenu\Controller::instance()->get_menu_slug(),
                array( WPMUDEV_BLC\App\Admin_Pages\Local_Submenu\Controller::instance(), 'output' ),
                $page_controler_cloud->__get( 'icon_url' )
                );

            // Add plugin-specific scripts and CSS only to its own pages.
            add_action( 'admin_print_styles-' . $links_page_hook, array( $this, 'options_page_css' ) );
            add_action( 'admin_print_styles-' . $links_page_hook, array( $this, 'links_page_css' ) );

            add_action( 'admin_print_scripts-' . $links_page_hook, array( $this, 'enqueue_settings_scripts' ) );
            add_action( 'admin_print_scripts-' . $links_page_hook, array( $this, 'enqueue_link_page_scripts' ) );
    }
}

If you want to disable the bubble to save a database query:

public function admin_menu() {
    if ( current_user_can( 'manage_options' ) ) {
        add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
    }

     /*  REMOVED CODE - the rest is unchanged */

    /**
    * Until multisites are officially supported, BLC v2 menus are disabled in subsites.
    * Legacy menus are loaded instead.
    */
    if ( WPMUDEV_BLC\Core\Utils\Utilities::is_subsite() ) {
        $page_controler_cloud = WPMUDEV_BLC\App\Admin_Pages\Cloud_Page\Controller::instance();
        $links_page_hook      = add_menu_page(
                __( 'Broken Links', 'broken-link-checker' ),
                 __( 'Broken Links', 'broken-link-checker' ),
                'edit_others_posts',
                WPMUDEV_BLC\App\Admin_Pages\Local_Submenu\Controller::instance()->get_menu_slug(),
                array( WPMUDEV_BLC\App\Admin_Pages\Local_Submenu\Controller::instance(), 'output' ),
                $page_controler_cloud->__get( 'icon_url' )
                );

            // Add plugin-specific scripts and CSS only to its own pages.
            add_action( 'admin_print_styles-' . $links_page_hook, array( $this, 'options_page_css' ) );
            add_action( 'admin_print_styles-' . $links_page_hook, array( $this, 'links_page_css' ) );

            add_action( 'admin_print_scripts-' . $links_page_hook, array( $this, 'enqueue_settings_scripts' ) );
            add_action( 'admin_print_scripts-' . $links_page_hook, array( $this, 'enqueue_link_page_scripts' ) );
    }
}

 

Missing Screen Options

The Screen options settings menu on top of the page is missing. To fix this open  [WP-ROOT]/legacy/core/core.php and change the function __construct change the string below

 if (empty($_GET['local-settings'])) {
                        // Add a "Screen Options" panel to the "Broken Links" page.
                        add_screen_options_panel(
                                'blc-screen-options',
                                '',
                                array($this, 'screen_options_html'),
                                'toplevel_page_blc_local', #<------ CHANGE ME ----
                                array($this, 'ajax_save_screen_options'),
                                true
                        );
  }

 

 

Email notifications

 

Then go to [WP-ROOT]/wp-content/plugins/broken-link-checker/app/options/settings/class-model.php. Find the function get and remove the if statement. This solves an issue with the email notifications.

public function get( string $settings_key = null, string $option_name = null, $default = null, bool $force = false ) {

		return parent::get( $settings_key, $option_name, $default, $force );
	}

Disadvantage is that you will have to add the code with every update. And malware scanners like Wordfence will mark the change as suspicious.