Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move is_robot function to javascript #266

Merged
merged 2 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions classes/class-wpcom-liveblog-lazyloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public static function is_enabled() {
*/
self::$enabled = (bool) apply_filters( 'liveblog_enable_lazyloader', true );

// Disable lazy loading for robots
if ( self::$enabled && self::is_robot() ) {
self::$enabled = false;
}

// Disable lazy loading on archived liveblogs
if ( 'enable' != WPCOM_Liveblog::get_liveblog_state() ) {
self::$enabled = false;
Expand All @@ -51,23 +46,6 @@ public static function is_enabled() {
return self::$enabled;
}

/**
* Checks if the current user is a robot.
*
* @return bool
*/
private static function is_robot() {

// Variant determiner for caches.
if ( function_exists( 'vary_cache_on_function' ) ) {
vary_cache_on_function(
'return isset( $_SERVER[\'HTTP_USER_AGENT\'] ) && preg_match( \'/bot|crawl|slurp|spider/i\', $_SERVER[\'HTTP_USER_AGENT\'] );'
);
}

return isset( $_SERVER['HTTP_USER_AGENT'] ) && preg_match( '/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'] );
}

/**
* Returns the number of initially displayed Liveblog entries.
*
Expand Down
5 changes: 5 additions & 0 deletions js/liveblog-lazyloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
initialize: function() {
lazyloader.entrySets = [];

if ( navigator.userAgent.match(/bot|crawl|slurp|spider/i) ) {
$( '.liveblog-load-more' ).hide();
return; //no lazy loading for robots
}

lazyloader.setBusy();
lazyloader.fetchEntries();

Expand Down