[wp-trac] [WordPress Trac] #55489: Defining SHORTINIT creates an error when index.php is loaded

WordPress Trac noreply at wordpress.org
Mon May 23 20:35:05 UTC 2022


#55489: Defining SHORTINIT creates an error when index.php is loaded
-----------------------------------------------+---------------------------
 Reporter:  gerendo                            |       Owner:  (none)
     Type:  defect (bug)                       |      Status:  new
 Priority:  normal                             |   Milestone:  Awaiting
                                               |  Review
Component:  Bootstrap/Load                     |     Version:  5.9.2
 Severity:  normal                             |  Resolution:
 Keywords:  has-screenshots close 2nd-opinion  |     Focuses:  rest-api
-----------------------------------------------+---------------------------

Comment (by johnjamesjacoby):

 Hello everyone! 👋

 Please correct me if I am mistaken, but I believe the error message that
 @gerendo is seeing is not specific to the ''REST API'' using `SHORTINIT` –
 rather, I believe this error message can be expected to be thrown on
 ''every'' non-`wp-admin` request. 😬

 (`wp-admin/profile.php` – for example sake – shows a different missing
 function:

 {{{
 Fatal error: Uncaught Error: Call to undefined function
 is_customize_preview() in wp-admin/includes/admin-filters.php:56
 Stack trace:
 #0 wp-admin/includes/admin.php(20)
 #1 wp-admin/admin.php(97)
 #2 wp-admin/user-edit.php(10)
 #3 wp-admin/profile.php(18)
 }}}
 )

 ----

 I'd like to politely suggest to @gerendo that he simply not use
 `SHORTINIT` inside of `wp-config.php` 🥷

 While `wp-config.php` is ''generally'' where WordPress documentation all
 over the web recommends that developers put their configuration constants,
 `SHORTINIT` is quite unique in that its usage should typically be
 ''outside'' of the ''global'' WordPress configuration, so that WordPress
 itself (and all of its innards) continue to work as intended (including
 the REST API) – not-much ''inside'' of WordPress is coded with `SHORTINIT`
 support directly in mind.

 When using `SHORTINIT` you are basically "on your own" when it comes to
 including & requiring all of the files you need to avoid PHP fatal errors
 while also achieving your goal of loading fewer files to keep your memory
 usage low. To do this, traditionally, you would start with what is in the
 root `index.php`, `wp-blog-header.php`, `wp-settings.php`, etc... cherry-
 picking the parts of those files that you do-or-do-not need.

 As you've identified, this is not very straightforward 😅 but I do think
 it is a fun challenge and can be a rewarding exercise, especially on long-
 running requests that do not require plugins or themes to be loaded, need
 to avoid `wp_magic_quotes()`, run a custom application, or something even
 more fun 🛝

 See also: https://wordpress.stackexchange.com/a/28347/3588

 ----

 To @SergeyBiryukov, @TimothyBlynJacobs, and @sabernhardt, I think it would
 be OK to close this ticket, as it's not quite as accurate of a report as
 maybe it could be. I would personally like to see some version of an
 improved `SHORTINIT` experience (autoloading or otherwise) but I also
 think that's a bit outside the scope of what's being discussed here.

 Thoughts? 🧐

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


More information about the wp-trac mailing list