0
0
Wordpressframework~10 mins

Plugin file structure in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the main plugin file header.

Wordpress
<?php
/*
Plugin Name: [1]
*/
Drag options to blanks, or click blank then click option'
Aadd_action
Bfunction my_plugin() {}
CMy Custom Plugin
Dwp_enqueue_scripts
Attempts:
3 left
💡 Hint
Common Mistakes
Using function names instead of plugin name in header
Omitting the plugin header comment block
2fill in blank
medium

Complete the code to enqueue a stylesheet in the plugin.

Wordpress
<?php
function my_plugin_styles() {
    wp_enqueue_style('[1]', plugin_dir_url(__FILE__) . 'css/style.css');
}
add_action('wp_enqueue_scripts', 'my_plugin_styles');
Drag options to blanks, or click blank then click option'
Aenqueue_style
Bstyle.css
Cplugin_url
Dmy-plugin-style
Attempts:
3 left
💡 Hint
Common Mistakes
Using the filename instead of a unique handle
Using incorrect function names
3fill in blank
hard

Fix the error in the plugin main file to prevent direct access.

Wordpress
<?php
if (!defined('[1]')) {
    exit;
}
// Plugin code continues here
Drag options to blanks, or click blank then click option'
AABSPATH
BWPINC
CPLUGIN_DIR
DWP_PLUGIN_DIR
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect constants
Not preventing direct access
4fill in blank
hard

Fill both blanks to register a shortcode in the plugin.

Wordpress
<?php
function [1]() {
    return 'Hello, World!';
}
add_shortcode('[2]', '[1]');
Drag options to blanks, or click blank then click option'
Ahello_world_shortcode
Bhello_world
Cmy_shortcode
Dgreeting
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching function and shortcode names
Using invalid shortcode tags
5fill in blank
hard

Fill both blanks to create a plugin activation hook.

Wordpress
<?php
function [1]() {
    // Activation code here
}
register_activation_hook(__FILE__, '[1]');
add_action('[2]', '[1]');
Drag options to blanks, or click blank then click option'
Amy_plugin_activate
Bactivate_my_plugin
Cinit
Dplugin_loaded
Attempts:
3 left
💡 Hint
Common Mistakes
Using different function names in hook registration
Using wrong hook names