![]() ![]() (but can also be done by script, webserver, etc.) Using CLI '$ php -a' the result is in the next line To avoid mistyping a path on cp or mv with a same filename instead of a directory Or just to keep that of the command line completion by , With Linux I am used, to add a trailing slash, Unexpected, but longtime (all versions?) consistent, behaviour with trailing slash (Linux): '/css/sac.css' Īgain, the best way to see how these snippets work is to copy/paste them into your WordPress plugin or PHP script (depending on the snippet), and then check the results.Īlso check out this useful post at the WP Codex.Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Enumerations Errors Exceptions Fibers Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting User Submitted Data Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts ? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search "\n" // = Įxample: Combining these different techniques, here is a way to get the current plugin URL from a script that is included in a subdirectory, say, /simple-ajax-chat/inc/myscript.phpĮcho plugins_url(basename(dirname(dirname(_FILE_)))). ![]() plugins_url('images/wp.png', dirname(_FILE_)). Working with WordPress, and assuming we are including the following snippets in a plugin directory named /simple-ajax-chat/ (this is just an example, you can include these snippets in any WordPress plugin): echo 'plugins_url()'. But if you need to get the path of a some other plugin, you can use WP_PLUGIN_DIR. Note: to get the path for the plugin in which the script is included, use plugin_dir_path(). "\n" // = /var/www/path//httpdocs/wp-content/plugins/simple-ajax-chat/ "\n" // = simple-ajax-chat/simple-ajax-chat.phpĮcho 'WP_PLUGIN_DIR = '. "\n" // = simple-ajax-chatĮcho 'plugin_basename(_FILE_) = '. "\n" // = simple-ajax-chatĮcho 'plugin_basename(dirname(_FILE_)) = '. Working with WordPress, and assuming we are including the following snippets in a plugin directory named /simple-ajax-chat/ (this is just an example, you can include these snippets in any WordPress plugin): echo 'dirname(plugin_basename(_FILE_)) = '. Note however that basename(dirname(_FILE_)) returns the current directory name, so if your script is in a subdirectory, you can get the parent directory name by adding another dirname(), like so: basename(dirname(dirname(_FILE_))). "\n" // = /var/These snippets are entirely PHP, so they work in any directory, with or without WordPress. Working with or without WordPress, and assuming we are including the following snippets in a plugin directory named /simple-ajax-chat/ (this is just an example you can include these snippets in any PHP script located in any directory): echo 'basename(dirname(_FILE_)) = '. The results should be well-formatted and easy to read. Note: these snippets are designed for straight-up copy/pasting into any PHP or plugin script. This is a mega-reference aimed at PHP/WordPress developers. ![]() Massive round-up of PHP and WordPress techniques for getting various directory and file path information.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |