Easy Webinar Plugin on Steroids

Easy Webinar Plugin: getRemote_version() Speed Up

If you already use Easy Webinar Plugin (4.2.7 or older) within your WordPress website, you probably notice a kind of slow dashboard.

In this article, you can learn how to speed up EWP with a piece of code snippet. All you need to have is basic knowledge of PHP editing, and FTP access to website host.

4 Simple Steps

Step One: Go to FTP where you have installed the WordPress website and backup file /wp-content/plugins/webinar_plugin/webinar-plugin.php

Step Two: Open file /wp-content/plugins/webinar_plugin/webinar-plugin.php in some text editor (even Notepad can help, but I recommend Sublime Text 3).

Step Three: Find method getRemote_version() which is located at line 939 in plugin version EWP(4.2.7)

Step Four: Replace the complete original function getRemote_version() with a cacheable version. So this:

public function getRemote_version(){
  global $wpdb;
  $wpdb->webinar_license = "webinar_license";
  $license_key_arr = $wpdb->get_results("Select * FROM $wpdb->webinar_license");
  $license_key = $license_key_arr[0]->key;
  $client_site = get_site_url();
  $request = wp_remote_post($this->update_path, array('body' => array('action' => 'ewp-version','license_series' => $license_key,'client_site' => $client_site)));
  
  if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200){
    return $request['body'];
  }
  else {
    echo 'heena';
  }
  return false;
}

becomes this:

public function getRemote_version() {
  if ( false === ( $request = get_transient( 'ewp_latest_version' ) ) ) {
    global $wpdb;
    $wpdb->webinar_license = 'webinar_license';
    $license_key_arr = $wpdb->get_results( "SELECT * FROM $wpdb->webinar_license" );
    $license_key = $license_key_arr[0]->key;
    $client_site = get_site_url();
    $request = wp_remote_post(
      $this->update_path,
      array(
        'body' => array(
          'action'         => 'ewp-version',
          'license_series' => $license_key,
          'client_site'    => $client_site,
        ),
      )
    );

    if ( ! is_wp_error( $request ) || 200 === wp_remote_retrieve_response_code( $request ) ) {
      set_transient( 'ewp_latest_version', $request['body'], 6 * HOUR_IN_SECONDS );
      return $request['body'];
    } else {
      echo 'heena';
    }
  } else {
    return $request;
  }
  return false;
}

Explanation of code

By default, EWP does multiple checks for the latest version of the plugin by calling the home (remote) server to get the latest version number. This can slow down code execution (waiting response from a remote server, multiplied by numerous calls per single page load). My idea was to prevent this and optimize calls, by involving the local WordPress cache for the plugin’s latest version data, through Transients API.

A new plugin version can’t be released on each second, minute, or even hour. Because of that, 1+ remote call per page load is a waste of bandwidth and time. So we can, for a while, locally store the latest version number fetched from the remote server and simply check local data on the same page loads.

In this tweak, I store the latest version info for 6 hours. Simple as that.

Please note, that Easy Webinar support confirmed that they’ll apply this enhancement to upcoming releases. I’m expecting EWP(4.2.8) to come with a fix already implemented. If not, simply refactor my version of the method getRemote_version() and tweak the core plugin file.