1

Is there a better way of retrieving the path of admin.php and the url of wp-admin.css?

What I can think of is:

$adminphppath = ABSPATH . '\wp-admin\admin.php';
$admincssurl = get_bloginfo('wpurl') . '/wp-admin/css/wp-admin.css";

But, some may be changing the admin path for security. So I need a more reliable way.

[Edit] I need the system path for admin.php, not url. Because I need to include it.

  • You cannot change the wp-admin folder name. You can rewrite it url wise but it ain't going to make anything more secure. – Wyck Aug 20 '12 at 3:30
  • So is ABSPATH the most reliable way? – Teno Aug 20 '12 at 5:17
  • yes, yes it is. – Wyck Aug 20 '12 at 5:31
6

You can use admin_url() function for wp-admin.css file and ABSPATH for admin.php.

$admin_php_path = ABSPATH . '/wp-admin/admin.php';
$admin_css_url = admin_url( 'css/wp-admin.css' );
  • For the css file it works thanks but for admin.php, actually I need to use include() so I need the system path, not the url. If I include with url, I get Warning: require() [function.require]: http:// wrapper is disabled in the server configuration by allow_url_include=0 – Teno Aug 20 '12 at 2:59
  • O, sorry about that. admin_url() will return URL which is useless with require or include, so as @Wyck said you should use ABSPATH. Updated answer. – Mamaduka Aug 20 '12 at 7:43
1

Old question I know, but this accounts for installs where wp-admin is not the admin directory

$admin_abspath = str_replace( site_url(), ABSPATH, admin_url() );
$admin_php_path = $admin_abspath . '/wp-admin/admin.php';
  • Close, but results in duplicate slashes right at wp-admin.... (as in /my/path/to//wp-admin) – cale_b Nov 3 '16 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.