Suggestion: Reader has inline CSS for non-logged in users

Hi there!

Note: For once, I haven't looked into the code :slight_smile:.

I'm a page speed freak and I was wondering if it would be possible to remove the inline CSS from the reader plugin (which isn't used anyway when you're logged out) so Google will love us more? <3

I know there's one scenario (haven't tested it) that the "follow" button will be shown (probably redirecting you to the login page), but if that's set to "false" I think it would be perfectly understandable to remove the inline-CSS. This scenario would be the "Display follow button for: Logged in and logged out users".

There's one bug that will follow: Administrator (or not) caching, however that could easily be solved with a button instead of automatically removing the CSS.

Once again, just a suggestion - extremely low priority. Have a great day!

  • Michael Bissett
    • Recruit

    Hey @Sybre, hope you're doing well today, and thanks for the suggestion! :slight_smile:

    In the meantime though, after having a look at the plugin code (looking at lines 88-96 of reader/msreader-files/includes/modules/follow.php), if you're not planning to have the "Follow" button show for logged out users, you could try wrapping those lines in a is_user_logged_in() call, like this:

    if(is_user_logged_in()) {
    			echo
    			'<style type="text/css">
    			#wp-admin-bar-msreader-follow {width: 100px;}
    			#wp-admin-bar-msreader-follow .hover-text {display:none;}
    			#wp-admin-bar-msreader-follow:hover .hover-text {display:inline;}
    			#wp-admin-bar-msreader-follow:hover .current-text {display:none;}
    			#wp-admin-bar-msreader-follow .ab-item .ab-icon:before {content: "\f487"; top: 2px;}
    			#wp-admin-bar-msreader-follow.following .ab-item .ab-icon:before {color: #d54e21;}
    			#wp-admin-bar-msreader-follow.following:hover .ab-item .ab-icon:before {color: #999;}
    			#wp-admin-bar-msreader-follow.following:hover .ab-item {color: #999 !important;}';
    		}

    (please make a backup of the file first, just to be safe)

    You can replace the code that exists in lines 88-96 of reader/msreader-files/includes/modules/follow.php with the code I just posted above. :slight_smile:

    (I should note that this would be wiped out on an update to the plugin, as we're modifying the code directly. I'd recommend making notes of these edits, so that you can replicate them later)

    Could you elaborate on this though, not sure that I follow you here:

    There's one bug that will follow: Administrator (or not) caching, however that could easily be solved with a button instead of automatically removing the CSS.

    Kind Regards,
    Michael

  • Sybre Waaijer
    • The Incredible Code Injector

    To work around the problem for when you update the plugin, I tried to create a plugin that would remove its contents once a user's logged out, but it doesn't seem to bind to the function.

    If I get this working I assume I could do the same for other plugins :slight_smile:

    if (function_exists('add_css_js')) {
    	add_filter('msreader_load_modules', 'disable_reader_css');
    		function disable_reader_css() {
    			add_action('init', 'disable_reader_init');
    	}
    }
    
    function disable_reader_init() {
    	if(is_user_logged_in()) {
    	} else {
    		remove_action( 'wp_head', 'add_css_js' );
    	}
    }

    Any idea's?

  • Sybre Waaijer
    • The Incredible Code Injector

    Hi Ashok! Thanks for your input.

    The thing I found out is that the add_css_js is removed for both logged in and out users. Resulting in a white screen of death on the reader reading and settings page.

    WordPress has failed me :')

    For now, this plugin is more in line with the coding standards (but still not working as intended):

    add_filter('msreader_load_modules', array(WMD_MSReader_Modules, 'disable_reader_css'));
    if (function_exists('WMD_MSReader_Module_Follow', 'add_css_js')) {
    	function disable_reader_css() {
    		add_action('init', 'disable_reader_init');
    	}
    
    	function disable_reader_init() {
    		if(!is_user_logged_in()) {
    			remove_action( 'wp_head', array( 'WMD_MSReader_Module_Follow', 'add_css_js'), 999 );
    		}
    	}
    }
  • Michael Bissett
    • Recruit

    Hey @Sybre, thanks for your patience here! :slight_smile:

    Given the way things are coded presently, it would seem like the code edit I suggested earlier would be the way to go for now (I tried inserting that code snippet as an mu-plugin on my Multisite, and got multiple errors upon activation).

    Hope your weekend's been going well so far! :slight_smile:

    Kind Regards,
    Michael

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.