Make WordPress Core

Opened 8 years ago

Last modified 7 years ago

#38800 new enhancement

add WP_ADMIN_URL and WP_INCLUDES_URL constants

Reported by: petersplugins's profile petersplugins Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Script Loader Keywords:
Focuses: Cc:

Description

If WP is installed in a sub directory we can use a subdomain pointing to wp-content directory and set the WP_CONTENT_URL in wp-config.php to hide the path WP is installed in.

But the HTML code still yields information about the path because the WP default scripts and styles are loaded from wp-includes resp. wp-admin directory. Of course those URLs can be changed using the script_loader_src filter.

But to obviate the need for using this filter and to remove this lack of consistency it should be possible to define WP_ADMIN_URL and WP_INCLUDES_URL in wp-config.php

Sample Code

For testing I've added two functions

function wp_get_admin_url() {
  if ( defined( 'WP_ADMIN_URL' ) ) {
    return trailingslashit( WP_ADMIN_URL );
  }
  return '/wp-admin/';
}

function wp_get_includes_url() {
  if ( defined( 'WP_INCLUDES_URL' ) ) {
    return trailingslashit( WP_INCLUDES_URL );
  }
  return '/wp-includes/';
}

Also I've made changes to wp-includes/script-loader.php. I've added the following lines to functions wp_default_scripts() and wp_default_styles()

$admin_src = wp_get_admin_url();
$includes_src = wp_get_includes_url();

Then I've changed every occurrence of $scripts->add() and $styles->add() to use those variables instead of the fixed path.

This works as expected to hide the directory WP is installed in from the WP default scripts and styles.

I'm pretty sure there's a lot more to change but I wanted to bring this up for discussion first and I'm eagerly waiting for feedback.

Notes: I'm a newbie here so please excuse if I did't follow the usual procedure and let me know how to do better. And second please be bear with me that I'm not a native english speaker.

Peter

Change History (3)

#2 @petersplugins
8 years ago

Remark: different from other approaches I do not propose changing the physical path but only the outputted URLs of scripts and styles. No need to change anything in back-end because the paths would still work but are not guessable.

#3 @screamingdev
7 years ago

This is the best moment to consider equal naming format for constants maybe.

WP_LANG_DIR
WP_PLUGIN_URL
WP_HOME

aaaaaand

WPINC vs WP_INC
ABSPATH vs WP_ABSPATH
BLOGUPLOADDIR vs WP_BLOG_UPLOAD_DIR

yw

Note: See TracTickets for help on using tickets.