Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#15853 closed defect (bug) (invalid)

Plugin Development: Inconsistent file include sources.

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

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
16 years ago

  • Milestone Awaiting Review
  • Resolution → invalid
  • Status new → 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
16 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.