phpwordpressphp-include

How Hello Dolly plugin uses Wordpress functions?


I am just starting to learn PHP and WordPress. there is a default simple plugin in WordPress called Hello Dolly.In its file hello.php I can see some WordPress functions like wptexturize() or add_action() but there isn't any include or require expression in that file. How that plugin can uses WordPress functions without including theme?


Solution

  • add_action() and others (see https://codex.wordpress.org/Plugin_API) are part of the Wordpress Plugin API and available in the global execution space of your plugin.

    There are tons of tutorials on plugin development online or check this out https://codex.wordpress.org/Writing_a_Plugin

    Edit:

    Simplified flow:

    Request --> index.php --> wp-settings.php -> (checks for active plugins) -> List of active plugins -> each list item (plugin) is included (basically your plugin index file) --> plugin index file uses plugin API

    So you can think of your plugin code as a part of the wp index file... everything loaded before is available to your plugin code as well.