WordPress includes many functions for determining paths and URLs to files or directories within plugins, themes, and WordPress itself.
$plugin_dir = plugin_dir_path( __DIR__ ); // wp-content/plugins/
require_once($plugin_dir.'WPNonce/WPNonce.php');
While using plugin_dir_path()
, keep in mind that the “plugin” part of the name is misleading – it can be used for any file, and will not return the directory of a plugin unless you call it within a file in the plugin’s base directory.
or alternatively, you can also use WordPress constant WP_PLUGIN_DIR
require_once(WP_PLUGIN_DIR.'/WPNonce/WPNonce.php');
I hope this helps.
Related Posts:
- Creating directory in uploads – wp_mkdir_p() or WP_Filesystem?
- Convenient way to use wp_filesystem
- Is there a WP Way of getting a filehandle?
- Is fopen() forbidden in WP?
- Converting fopen/fwrite operations to WP_filesystem
- Is it bad to store many files in a single folder?
- External pages redirecting back to wordpress
- WordPress Login doesnt respond after using Filezilla to upload my files on the server
- List of files/folders writable by the web server?
- Save PDF File From Plugin to Filesystem /wp_upload
- accessing files in custom folder in wordpress
- What dependencies should I load and to use the WP_Filesystem?
- What files are safe to delete after a security breach in WP content folder?
- Correct file permissions for in-browser updates using WP-CLI
- WordPress installation on digitalocean eating the server storage
- Serve contents from Nextcloud / WebDAV
- temphangle variable missing when using wp_filesystem copy
- File ownership for file tree php user ID – Folder permission 775
- How to write to a text file and save it in a folder for later download?
- 403 Error on “/”
- Get names and paths from unzip_file()
- Should I use Filesystem API for reading files or listing directories?
- saving file to external server vip
- Time limited file download upon form submit
- Does unzip_file() over-write by default?
- What is the difference between the .po .mo and .pot localization files?
- How to convert the file path to a URL of the same file?
- Do WordPress Core Filenames Work as Hooks?
- add/apend templates ‘transparently’ via plugin to currently active theme or child theme?
- delete uploaded file
- Necessary user, group and permissions for core updates
- Moving wp-content outside of web root?
- Why do I get undefined function export_wp()?
- How do I edit the php/html for a particular post?
- Setting wp_temp_dir and permissions not working for “Missing A Temporary Folder” error
- Which actions can update/change .php files?
- sanitize attachment filename
- How to move WordPress theme files into a subfolder without breaking the theme?
- How do I maintain static directories on multisite subdomains?
- Uploading Media gives error “Missing a temporary folder.”
- What are the hierarchy of filenames while initialising a WordPress plugin?
- What is the best way to move a plugin´s subdirectory+files to wp-content/uploads-directory?
- Securing a multi-user permission structure
- Relative file paths in CSS when linking directly (not enqueuing)
- Placing assets for external use
- How to check if txt file exists inside template folder?
- Can I delete `wp-config-sample.php` after installing and configuring WordPress?
- Files automatically added
- WordPress HTTP Error on File upload
- What permissions should I give directories if I want to make WordPress more secure?
- Where do I save widget code for wordpress?
- Plugin writing: access file that was just uploaded
- How to implement filesystem cache in WordPress
- Interface for logged-in users to upload/download files
- Image URLs stopped working due to Permalinks?
- “dashboard”-named PHP file doesn’t get included
- WordPress and plugins can’t update (“inconsistent file permissions” error)?
- How to block access to files without modifying .htaccess or ngnix config? [closed]
- Why is server preventing admin styles? (Was: Where are WordPress sessions saved?)
- Alternative to file_get_contents() for theme operations
- How to replace file_get_contents() with a WordPress Filesystem call
- How to edit php code in WordPress Post file?
- Theme, WordPress Version, MySQL Version, PHP Version Update affected files and folders
- Running rmdir function on post save
- WordPress Creates Unused (Unregistered) Image Sizes
- Why does WP load so many files in the head of source code? How do I optimize it?
- Adding regular php file to site
- Look for a file in a theme before loading from plugin
- Removing the references to the wp-content folder
- Right way to download file from source to destination
- get_template_directory() returns wrong address on VPS
- Cleaning a filename after image sideloading a url that contains `%20`
- Generating and downloading files with WP API
- Page to show a link to every file in an directory
- Uploaded images result in a file url with full path on disk appended
- How to prevent users to view server files using WP File Manager plugin?
- Save media files (images) to database instead of the filesystem
- Downloadable content file structure
- Creating an .ics calendar subscription service with wordpress
- How to include all files within a folder & its sub folders to functions.php?
- How to Call Function From Separate WordPress Install on Same Server?
- Can’t Install WordPress (local) Failed to open file wp-includes/wp-db.php
- FS method direct on NGINX
- Avoid ‘uploads’ 777 permissions: Potential threat or clean solution?
- Using external file with WP_USE_THEMES set to false causing 404
- Private file system for attachments
- Get original path of user’s filesystem of an uploaded media
- Making a custom upload form and page in the admin section
- Displaying $_FILES data (simlar to $_POST)
- wp_redirect to file:// location results in blank page/cannot be displayed page
- No error in debug mode, wordpress template can not be loaded
- Accessing a file saved outside webroot in a wordpress post
- Plugin installation works only with FTP – how to debug?
- How do I upload my WordPress code files from previous website onto local host WordPress website?
- File doesn’t exist! in wordpress function.php file while creating new post or page
- WordPress files owner changed silently
- How can I get blog content from SFTP?
- Do Not Back Up? Is there any accepted way to tell backup and clone plugins to skip a certain file? [closed]
- Hook on opening a media/document
- WordPress – tracking options