Im trying to host a js script locally, need some help with code

Im trying to host a js script locally, need some help with code

So I use the zopim plugin, and its great, but a certain code it loads, loads really slowly, I wanted to host it locally so it uses my fast cdn, and ultimately speeds up my load time.

So the js it loads is here:

And it loads from a php file within the plugin (see code below)

I tried uploading the js file to my site, and changing the source " code to point to it, but it doesnt work.



class Zopim_Widget
  // We need some CSS to position the paragraph
  public static function zopimme()
    $subdomain = get_option( Zopim_Options::ZENDESK_OPTION_SUBDOMAIN );

    if ($subdomain) {
      echo Zopim_Widget::get_widget_code_using_subdomain($subdomain);

    $current_user = wp_get_current_user();

    $code = get_option( Zopim_Options::ZOPIM_OPTION_CODE );

    if ( ( $code == "" || $code == "zopim" ) && !( isset( $_GET[ 'page' ] ) && preg_match( "/zopim/", $_GET[ 'page' ] ) ) && ( !preg_match( "/zopim/", $_SERVER[ "SERVER_NAME" ] ) ) ) {

    echo "<!--Embed from Zendesk Chat Chat Wordpress Plugin v" . VERSION_NUMBER . "-->
    <!--Start of Zopim Live Chat Script-->
    <script type=\"text/javascript\">
    window.\$zopim||(function(d,s){var z=\$zopim=function(c){z._.push(c)},$=z.s=
      $.src='//" . $code . "';z.t=+new Date;$.

      echo '<script>';
      if ( isset( $current_user ) ):
        $firstname = $current_user->display_name;
        $useremail = $current_user->user_email;
        if ( $firstname != "" && $useremail != "" ):
          echo "\$zopim(function(){\$zopim.livechat.set({name: '$firstname', email: '$useremail'}); });";

      echo Zopim_Options::get_widget_options();
      echo '</script>';
      echo "<!--End of Zendesk Chat Script-->";

    public static function get_widget_code_using_subdomain( $subdomain )
      $url = "" . $subdomain ."";
      $response = wp_remote_get($url, array());

      if ( is_wp_error( $response ) ) {
        $error = array( 'wp_error' => $response->get_error_message() );
        return json_encode( $error );

      return $response['body'];

I’d check the contents of the variables when the script runs.

Is $zopim just name spacing to avoid conflicts?

This might be your problem $.src='//" Shouldn’t it agree with your local script location?

I tried changing $.src=’//" to point to my local file…so $.src=’//" but it didnt work…there is also another thing happening:

I think that is my account key

That’s all I got. It looks like it’s building strings for a document head, but there’s lots of things that we don’t know the value of. I’d post it somewhere as a wordpress or wordpress + plugin question. Probably won’t be answered here.