If the plugin structure is:
plugins/
some-plugin/
some-plugin.php
data/
GeoIP.dat
then for PHP 5.3.0+, you could try the magic constant __DIR__
__DIR__
The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to
dirname(__FILE__)
. This directory name does not have a trailing slash
unless it is the root directory.
within the some-plugin.php
file:
// Full path of the GeoIP.dat file
$file = __DIR__ . '/data/GeoIP.dat';
// Open datafile
if( is_readable ( $file ) )
$gi = geoip_open( $file, GEOIP_STANDARD );
For wider PHP support you could use dirname( __FILE__ )
, where __FILE__
was added in PHP 4.0.2.
Related Posts:
- How to structure a plugin
- Add multiple plugin directories
- How long does it take for a new plugin to be approved?
- Is there a directory my plugin can write files to that cannot be viewed via the browser/url?
- How to get path or root of plugin folder, not file or dir?
- Minimize and Uglify WordPress Plugin Files
- Disable plugin visibility at the plugin directory
- Can we rename a plugin directory for a already launched plugin?
- Register additional wp plugin directory
- Change weird Wp File structure
- Custom pages with plugin
- Where is the best place to use add_filter
- How to delete custom taxonomy terms in plugin’s uninstall.php?
- Redirect to settings page after install
- What is the correct way for a theme to support plugin UIs?
- How does WordPress determine the primary plugin PHP file?
- Adding Featured Image in Post List
- translation does not work with text_domain
- Should I use RIPS tool to test my themes and plugins?
- Add Top-Level Menu that opens URL
- Custom url structure for custom template
- A way to sort WordPress themes? [closed]
- flush_rewrite_rules() not working on plugin activation
- Determine plugin name from within plugin_action_links filter
- Plugin Functionality Only for Editor and Administrator
- Plugin to hide admin menu (vertical menu bar)
- Having separate plugins and themes folder for multi-site setup
- action-scheduler vs wp-background-processing
- Many plugins making WordPress run slow by design?
- Do you clean up your self-written plugins’ at deactivation?
- How do I turn a custom post type into a plugin?
- Add keywords meta to index.php page
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- Does WP identify plugin by plugin name or plugin_basename?
- AJAX search posts and pages
- Combine scripts from all extensions of the plugin when an extension is activated
- Modifying Author Link to add Author Meta in URL
- Insert data from .sql file in wordpress plugin
- How can i get the post’s full html source by its ID?
- Force file download on plugin activation
- Checkbox conflict in my custom plugin admin page
- How to create a custom post type that contains another custom post type?
- How to change the name of the “edit my profile” link in the WordPress admin backend
- Can a Plugin Override New User Default Role Type
- Add action to fire when a published post is updated
- Great blogs site resources/tutorial for WordPress Developers? [closed]
- How to make multiple admin pages for one plugin?
- Create custom pages with a plugin
- Is it possible for a plugin to force reading and writing of uploaded images to a database instead of to a filesystem?
- Amazon.com intergration with WordPress?
- Change letters for day name
- How can I add IP address to my post?
- Set Multiple Meta Values as an Array Using dispatch( ‘core/editor’ ).editPost() Call in Gutenberg/JS
- add seperate suffix for low price and high price in woocommerce
- How to add/change (woocommerce) product tab icon
- Comment “like” problem – “users who like this” avatar linking to current user profile instead of “liker’s” profile
- I want to generate the pdf and save it in library?
- How do I make sure that my plugin only runs on article detail pages?
- Best way to retrieve data in custom api extended from wp-api
- WordPress API functions not working at AJAX functions.php call
- How do I show content from a plugin using the template the site is currently working with?
- How to check homepage contain blog post?
- auto activate plugin when theme is active
- Is it possible to pin a post in second position from top
- Activate Plugin Automatically After Set Time
- How to call function in WordPress on button click?
- Hide content for specific users with id
- adding dynamic/multiple slug values in ‘option_none_value’
- How can I see $post object in frontend from functions.php?
- Move plugin pages from dashboard to front-end
- Allow members to create groups on my site
- WordPress UPDATE queries on MySQL database stuck
- Checkbox field that add a subscription product and change prices of other products in checkout and cart page
- Get post content inside plugin class method
- Custom author page for custom role
- Dynamical slug on custom post type
- Ubermenu 3 Nav Bar Customization
- Storing Array of values into wordpress options
- Where do the section input fields values are stored in database
- WordPress Add advertising ads befor and after content with periority [closed]
- View more posts of a sub-category
- Update Plugin Without Overwriting Custom Settings
- How to customize ‘recurrance’ of’ wp_schedule_event’?
- woocommerce blank page after clicking add to cart [closed]
- Create Array from data in the OPTIONS table
- Saving plugin data returns “You do not have sufficient permissions to access this page.”
- How to create and use Custom hooks
- WordPress automatic plugin update
- Custom Function for SEO by Yoast plugin
- Call current post parameters inside a plugin
- How to list posts that appear in two categories
- Custom feed parameters / Template overriding
- Load my plugin before cache
- How to get current template file used by WordPress?
- Creating Event Builder Plugin [closed]
- Is it possible to debug plugins with Xcode?
- Hook for single product thumbnail
- Deprecated error notice
- Admin access to WordPress site with installing plugin
- Plugin to Display Content on Page