0
0
Wordpressframework~10 mins

Custom endpoint registration 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 add a custom endpoint 'profile' to WordPress rewrite rules.

Wordpress
<?php
function add_custom_endpoint() {
    add_rewrite_endpoint('[1]', EP_ROOT);
}
add_action('init', 'add_custom_endpoint');
Drag options to blanks, or click blank then click option'
Asettings
Bdashboard
Cprofile
Daccount
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong endpoint name that does not match the intended URL part.
Forgetting to hook the function to 'init' action.
2fill in blank
medium

Complete the code to add the 'profile' endpoint to the query vars.

Wordpress
<?php
function add_query_vars_filter($vars) {
    $vars[] = '[1]';
    return $vars;
}
add_filter('query_vars', 'add_query_vars_filter');
Drag options to blanks, or click blank then click option'
Auser_profile
Bendpoint
Ccustom_profile
Dprofile
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a different string than the endpoint name to query vars.
Not returning the modified $vars array.
3fill in blank
hard

Fix the error in the code to flush rewrite rules after adding the endpoint.

Wordpress
<?php
function flush_rewrite_rules_on_activation() {
    [1];
}
register_activation_hook(__FILE__, 'flush_rewrite_rules_on_activation');
Drag options to blanks, or click blank then click option'
Aflush_rules()
Bflush_rewrite_rules()
Crewrite_flush()
Dflush_rewrites()
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent function like flush_rules() or flush_rewrites().
Not flushing rewrite rules on plugin activation.
4fill in blank
hard

Fill both blanks to check if the current query is for the 'profile' endpoint and display a message.

Wordpress
<?php
function check_profile_endpoint() {
    if (get_query_var('[1]') === '[2]') {
        echo 'This is the profile endpoint page.';
    }
}
add_action('template_redirect', 'check_profile_endpoint');
Drag options to blanks, or click blank then click option'
Aprofile
Buser_profile
Dcustom
Attempts:
3 left
💡 Hint
Common Mistakes
Using different strings for the query var and the comparison value.
Checking the wrong query var name.
5fill in blank
hard

Fill all three blanks to register a custom endpoint 'dashboard', add it to query vars, and flush rewrite rules on activation.

Wordpress
<?php
function add_dashboard_endpoint() {
    add_rewrite_endpoint('[1]', EP_ROOT);
}
add_action('init', 'add_dashboard_endpoint');

function add_dashboard_query_vars($vars) {
    $vars[] = '[2]';
    return $vars;
}
add_filter('query_vars', 'add_dashboard_query_vars');

function flush_rewrite_on_activation() {
    [3];
}
register_activation_hook(__FILE__, 'flush_rewrite_on_activation');
Drag options to blanks, or click blank then click option'
Adashboard
Cflush_rewrite_rules()
Dflush_rules()
Attempts:
3 left
💡 Hint
Common Mistakes
Using different strings for endpoint and query var.
Using incorrect function to flush rewrite rules.