Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#15853 closed defect (bug) (invalid)

Plugin Development: Inconsistent file include sources.

Reported by: sterlo's profile sterlo Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0.3
Component: General Keywords:
Focuses: Cc:

Description

Story: I was building a plugin and created an options page.
Here are the relevant functions:

In the constructor:

add_action( 'admin_menu' , array( &$this , 'add_menu' ) , 1 );

In the function:

add_options_page( 'XXX_options' , 'XXX' , 'manage_options' , 'XXX_options' , array( &$this , 'options' ) );

In the other function:

include( 'options.php' );

Results: Instead of including /wp-content/plugins/myplugin/options.php it includes /wp-admin/options.php

If I change the include path to this:

include( 'afolderinmyplugin/options.php' );

Then it now pulls from /wp-content/plugins/myplugin/afolderinmyplugin/options.php

Seems like inconsistent functionality to me and should probably be fixed.

Change History (2)

#1 follow-up: @scribu
14 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

From the PHP manual:

Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include() will finally check in the calling script's own directory and the current working directory before failing. The include() construct will emit a warning if it cannot find a file; this is different behavior from require(), which will emit a fatal error.

To make sure you always get the correct path, do this:

include( dirname(__FILE__) . '/options.php' );

#2 in reply to: ↑ 1 @sterlo
14 years ago

Replying to scribu:

From the PHP manual:

Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include() will finally check in the calling script's own directory and the current working directory before failing. The include() construct will emit a warning if it cannot find a file; this is different behavior from require(), which will emit a fatal error.

To make sure you always get the correct path, do this:

include( dirname(__FILE__) . '/options.php' );

My bad!

Note: See TracTickets for help on using tickets.