WordPress.org

Ready to get started?Download WordPress

Forums

Basic Comment Quicktags
[resolved] Change Quicktags JavaScript File URL (13 posts)

  1. Aahan Krish
    Member
    Posted 2 years ago #

    I am serving all my static content from a different domain, and am facing one small problem with the plugin (NOT a bug, just my problem).

    The quicktags JS file (http://example.com/wp-includes/js/quicktags.js) is being served from the same domain as my website. How can I have it served from a different domain, say, example2.com?

    I tried deregistering, then changing the src of the file, and enqueuing quicktags, but that seems to be messing with the plugin.

    It would be great if someone can provide me the function that allows me to properly change the URL of the quicktags core JS file.

    http://wordpress.org/extend/plugins/basic-comment-quicktags/

  2. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod
    Plugin Author

    Posted 2 years ago #

    Huh. Well, the catch there is that most (well written) plugins are relatively looking for your wp-content folder. In this case, I used plugin_dir_url:

    wp_enqueue_script("bcq_quicktags", plugin_dir_url(__FILE__) . "quicktags.js", array("quicktags","jquery"), "1.8", 1);

    It should be rendering as http://example.com/wp-content/plugins/basic-comment-quicktags/quicktags.js by the way...

    So is the issue that your wp-content is in another location? How are you telling WP right now where to go for Static Content? If you'd used a define in your wp-config, that should have been picked up.

  3. Aahan Krish
    Member
    Posted 2 years ago #

    Hello Mika,

    I am talking about wp-includes and NOT wp-content directory. And since you asked, I've set a different domain for the wp-content directory by adding this in my wp-config.php:

    define( 'WP_CONTENT_URL', 'http://static-content.com/wp-content');

    But that doesn't change the URLs of JavaScript files loaded from wp-includes to the new domain. And as there's no such thing as WP_INCLUDES_URL, I have to manually un/de-register each handle and have it enqueued with the static domain (from the e.g. static-content.com).

    The handle for http://example.com/wp-includes/js/quicktags.js which the Basic Comment Quicktags plugin uses (as a dependency) is quicktags, and trying to un/de-register the handle and enqueuing it with the static domain somehow breaks the plugin's CDATA JS output in the footer.

    What I am asking is, what is the proper way to have this file — http://example.com/wp-includes/js/quicktags.js — served from the domain that serves static files, i.e. like this — http://static-domain.com/wp-includes/js/quicktags.js

    I would be very helpful if you can give me the proper function/code to un-register and enqueue the handle (quicktags), as my method seems to break the plugin.

    Hope I am clear enough this time. :)

  4. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod
    Plugin Author

    Posted 2 years ago #

    Yeah, that's this part array("quicktags","jquery")

    That's WP's own code, and ... you'd have to move it. You'd have to deregister quicktags itself and register your own for that.

  5. Aahan Krish
    Member
    Posted 2 years ago #

    Yes, that's what I am asking. How do I do that? Something's wrong with the way I am doing it. This is what I've tried (and some variants of it as well, actually):

    add_action('wp_enqueue_scripts','aahan_register_script');
    function aahan_register_script(){
    
    	wp_deregister_script('quicktags');
    	wp_register_script('quicktags', 'http://static-domain.com/wp-includes/js/quicktags.js', false, false);
    	wp_enqueue_script( 'quicktags' );
    
    }

    Is something wrong with the way I am doing it?

  6. Aahan Krish
    Member
    Posted 2 years ago #

    OR it would be great if you can tell me how to replace this function (from your plugin) with some code in my function.php (sorry, I am not that good with PHP, but I am just into learning it):

    function ippy_bcq_add_scripts() {
    
    $options = get_option('ippy_bcq_options');
    $valuebb = $options['bbpress'];
    $valueco = $options['comments'];
    $ippy_bcq_bbp_fancy = get_option( '_bbp_use_wp_editor' );
    
      if ( function_exists('is_bbpress') ) {
              if ( is_bbpress()  && ( $valuebb != '0') && !is_null($valuebb) && ($ippy_bcq_bbp_fancy == '0') ) {
                wp_enqueue_script("bcq_quicktags", plugin_dir_url(__FILE__) . "quicktags.js", array("quicktags","jquery"), "1.8", 1);
                wp_enqueue_style("bcq_quicktags", plugin_dir_url(__FILE__) . "quicktags.css", false, "1.8");
                wp_print_styles('editor-buttons');
            }
      }
      if ( comments_open() && is_singular() && ( $valueco != '0') && !is_null($valueco) ) {
                        wp_enqueue_script("bcq_quicktags", plugin_dir_url(__FILE__) . "quicktags.js", array("quicktags","jquery"), "1.8", 1);
                        wp_enqueue_style("bcq_quicktags", plugin_dir_url(__FILE__) . "quicktags.css", false, "1.8");
                        wp_print_styles('editor-buttons');
      }
    }
    
    if( !is_admin() ) {
    	add_action('wp_print_styles', 'ippy_bcq_add_scripts');
    }
  7. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod
    Plugin Author

    Posted 2 years ago #

    What you have two posts up should work.

    I wonder if my code is getting called before yours and that's why...I'd try setting a lower priority.

    Or if I was really lazy, an .htaccess rule to redirect that file.

    What file are you putting that code in? Your themes functions.php?

  8. Aahan Krish
    Member
    Posted 2 years ago #

    Yes, in my theme functions.php.

    EDIT: I also tried lower priority numbers (as low as 1). Doesn't change anything.

  9. Aahan Krish
    Member
    Posted 2 years ago #

    By the way, I also tried using wp_print_styles instead of wp_enqueue_scripts, still no luck.

  10. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod
    Plugin Author

    Posted 2 years ago #

    *ponder*

    Why not move the plugins directory back?

    define( 'WP_PLUGIN_URL', 'http://example/wp-content/plugins');

    I suggest this because plugins (and themes) aren't 'static' content. The intent of the WP_CONTENT_URL changability is to move your content from /home/aahan/public_html/wp-content/ to /home/aahan/wp-content/ (i.e. outside of 'root') which makes things unlinkable and more secure (arguably). I'm not entirely sure totally changing the domain was the intent.

  11. Aahan Krish
    Member
    Posted 2 years ago #

    :( Sad, but kinda makes sense. Thanks for your time Mika :)

  12. Aahan Krish
    Member
    Posted 2 years ago #

    After lots of looking into files, and asking questions, it finally struck me... this is how it needs to be done:

    add_action('wp_enqueue_scripts','aahank_register_script');
    function aahank_register_script(){
    
    //Re-register quicktags script
    wp_deregister_script('quicktags');
    wp_register_script('quicktags', 'http://static-content.com/wp-includes/js/quicktags.js', false, false, true);
    wp_localize_script( 'quicktags', 'quicktagsL10n', array(
    	'wordLookup' => __('Enter a word to look up:'),
    	'dictionaryLookup' => esc_attr(__('Dictionary lookup')),
    	'lookup' => esc_attr(__('lookup')),
    	'closeAllOpenTags' => esc_attr(__('Close all open tags')),
    	'closeTags' => esc_attr(__('close tags')),
    	'enterURL' => __('Enter the URL'),
    	'enterImageURL' => __('Enter the URL of the image'),
    	'enterImageDescription' => __('Enter a description of the image'),
    	'fullscreen' => __('fullscreen'),
    	'toggleFullscreen' => esc_attr( __('Toggle fullscreen mode') ),
    	'textdirection' => esc_attr( __('text direction') ),
    	'toggleTextdirection' => esc_attr( __('Toggle Editor Text Direction') )
    ));
    
    }

    As for the code used in wp_localize_script, I got it straight from source: http://core.svn.wordpress.org/trunk/wp-includes/media.php

    PS: Cross-posted from http://wordpress.stackexchange.com/q/56742/10691

  13. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod
    Plugin Author

    Posted 2 years ago #

    Yow! What a hassle :(

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic