[wp-trac] [WordPress Trac] #52575: get_home_path() returns "/" instead of path to WordPress directory

WordPress Trac noreply at wordpress.org
Tue Jul 18 01:34:51 UTC 2023


#52575: get_home_path() returns "/" instead of path to WordPress directory
--------------------------------------------+------------------------------
 Reporter:  pixellogik                      |       Owner:  (none)
     Type:  defect (bug)                    |      Status:  new
 Priority:  normal                          |   Milestone:  Awaiting Review
Component:  Filesystem API                  |     Version:  5.6.1
 Severity:  major                           |  Resolution:
 Keywords:  reporter-feedback dev-feedback  |     Focuses:
--------------------------------------------+------------------------------

Comment (by arnolp):

 @peterwilsoncc thank you very much for your explanation, indeed.

 I was confused by a (bad) plugin, which was flushing rules on front end
 pages.
 Thus, calling :
 {{{#!php
 WP_Rewrite->flush_rules(true)
 --> /public/wp/wp-includes/class-wp-rewrite.php(1875):
 save_mod_rewrite_rules()
 --> /public/wp/wp-admin/includes/misc.php(278): file_exists('/.htaccess')
 <--- uses get_home_path() from front-end
 }}}


 (Well I could argue, if I was really in bad faith, that class-wp-rewrite
 is not in /wp-admin, thus "allowing" front-end use, but I really can't see
 a usecase of flushing rewrite rules on front end pages , seems to be a bad
 idea !)

 --> All good on my side. Not sure about the op's usecase, but that's a
 different one.

 Replying to [comment:6 peterwilsoncc]:
 > @arnolp Gotcha, thanks for your patience.
 >
 > I think we're all in agreement on the ticket that it's returning the
 correct value within the admin for WP in it's own directory:
 >
 > {{{
 > Home page: example.com
 > WP Install: example.com/wp
 > Path to WP: /path/to/site/wp
 > Expected get_home_path() result: /path/to/site
 > }}}
 >
 > > I don't get why this code would ever work apart from admin pages
 context;
 >
 > As the function is located within `wp-admin/includes/file.php`, I think
 it was only ever designed to work within the admin. To modify it to work
 on the front-end as well would be considered an enhancement.
 >
 > That may be possible using the magic constant `__DIR__` if there is the
 desire to make it a front-end friendly function.
 >

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52575#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list