🎯 By the end of this lesson you can…
- Write a plugin header
- Structure a plugin folder
- Guard files and use activation hooks
🐘 PHP
wp-content/plugins/hello-cadet/hello-cadet.php
👆 Tap a line to explain it
1<?php2/**3 * Plugin Name: Hello Cadet4 * Description: Says hello to every visitor.5 * Version: 1.0.06 * Author: Your Name7 * Text Domain: hello-cadet8 */9 10defined( 'ABSPATH' ) || exit;11 12add_action( 'wp_footer', function () {13 echo '<p class="hello-cadet">👋 Hello, cadet!</p>';14} );
📄 Text
plugin-structure.txt
1hello-cadet/2├─ hello-cadet.php main file with the header3├─ includes/ PHP classes and functions4├─ assets/ css / js / images5├─ languages/ translation files6└─ readme.txt for WordPress.org
🔌 WordPress PHP
activation.php
👆 Tap a line to explain it
1<?php2register_activation_hook( __FILE__, function () {3 add_option( 'hello_cadet_count', 0 );4} );5call_user_func( $GLOBALS['__wp_activation'] ); // (WordPress runs it on activation — we trigger it here)6var_dump( get_option( 'hello_cadet_count' ) );
💡 Concept check
Why prefix function names like
hellocadet_greet()?📌 Key takeaways
- A plugin = a folder in
wp-content/pluginswith a PHP file whose header hasPlugin Name:. - Start every file with
defined( 'ABSPATH' ) || exit;to block direct access. - Prefix everything (
lw_,myplug_) so names never clash with other plugins.
Finished reading & practising?
Saved in this browser. Create a free account to keep it forever.