[wp-trac] [WordPress Trac] #59832: Deprecation warnings for resulting from a call to plugin_dir_url

WordPress Trac noreply at wordpress.org
Fri Feb 9 16:43:20 UTC 2024


#59832: Deprecation warnings for resulting from a call to plugin_dir_url
----------------------------+-----------------------
 Reporter:  geistesblitzer  |       Owner:  (none)
     Type:  defect (bug)    |      Status:  reopened
 Priority:  normal          |   Milestone:
Component:  Plugins         |     Version:  6.4.2
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:
----------------------------+-----------------------
Changes (by charlestonsw):

 * status:  closed => reopened
 * version:  6.4 => 6.4.2
 * resolution:  invalid =>


Comment:

 **User Story**
 Determining the fully qualified URL of a must-use plugin main loader file
 is necessary to build future links within the app.

 **Use Case**
 After plugins have been loaded set the URL:

 mu-plugins/pluginname/pluginname.php

 defined( 'SLPLUS_FILE' ) || define( 'SLPLUS_FILE', __FILE__ ); // set the
 file to full path of running code


 mu-plugins/pluginsname/include/otherclass.php

 defined( 'SLPLUS_PLUGINURL' ) || define( 'SLPLUS_PLUGINURL', plugins_url(
 '', SLPLUS_FILE ) );


 Result with PHP 8.2.3 - PHP deprecated warning "null passed".


 **Call Stack
 **
 plugins_url( '' , <fully_qualified_filename> )
 wp_normalize_path( '' )
 wp_is_stream( '' )


 **Possible Resolutions**

 A) Remove optional status on first param of plugins_url()

 plugins_url() has the first optional parameter set to a default of ''.
 This will fail with the above warning if no parameters are passed.

 Make first param required.  Not desired, will break backwards
 compatibility.

 Make first param required only if second param is present.  Not desired,
 will break backwards compatibility.

 Fire "doing it wrong" if second param is set but not first param.

 B) wp_normalize_path() modify processing if incoming path is ''

 Skip wp_is_stream() test if path is '':

         if ( ($path !== '') && wp_is_stream( $path ) ) {
                 list( $wrapper, $path ) = explode( '://', $path, 2 );

                 $wrapper .= '://';
         }




 C) wp_is_stream() short circuit if path is empty string ''

 At start of wp_is_stream add:
 if ( $path === '') { return false; }

 or is_null($path) or empty($path) -- the above matches the specificity if
 the real world situation.

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


More information about the wp-trac mailing list