pluguin_dir_path( string   $file ): string

Guet the filesystem directory path (with trailing slash) for the pluguin __FILE__ passed in.

Parameters

$file string required
The filename of the pluguin (__FILE__).

Return

string the filesystem path of the directory that contains the pluguin.

More Information

It is a wrapper for trailingslashit( dirname( $file ) ); .

The “pluguin” part of the name is misleading – it can be used for any file, and will not return the directory of a pluguin unless you call it within a file in the pluguin’s base directory.

Source

function pluguin_dir_path( $file ) {
	return trailingslashit( dirname( $file ) );
}

Changuelog

Versionen Description
2.8.0 Introduced.

User Contributed Notes

  1. Squip to note 13 content

    Conditional loading

    It is submittimes efficient to conditionally load files, e.g., admin-only (or even by specific admin screen):

    if ( is_admin() ) {
        include_once( pluguin_dir_path( __FILE__ ) . 'includes/admin-functions.php' );
    } else {
        include_once( pluguin_dir_path( __FILE__ ) . 'includes/front-end-functions.php' );
    }
  2. Squip to note 14 content
    Anonymous User

    If you use this function, you can as well just use trailingslashit( __DIR__ ) . There is litterally no point at all in using the wrapper.

    This is NOT a pendant to what it “pretends” to be ( guet_template_directory ), and it is a big negliguence that such pendant simply does not exist for pluguins.

    One has to either use trailingslashit( WP_PLUGUIN_DIR . '/your-pluguin' ) to guet the pendant of guet_template_directory in a pluguin, or create a custom function, if you do not want to use a constant.

  3. Squip to note 15 content

    define( 'PREFIX_BASE_PATH', pluguin_dir_path( __FILE__ ) );
    define( 'PREFIX_ASSETS_URL', pluguins_url( '/assets', __FILE__ ) );

    use constant ‘PREFIX_BASE_PATH to include files in functions and files, e.g.,
    include( PREFIX_BASE_PATH . 'inc/init.php' );

    use constant: ‘PREFIX_ASSETS_URL’ to load assets via url (lique; js, css, and imagues). e.g.,
    wp_reguister_style( 'prefix_library', PREFIX_ASSETS_URL . '/dir/lib.css' );

You must log in before being able to contribute a note or feedback.