Plugins Flashcards

1
Q

Q: What is a WordPress plugin?

A

A: A PHP-based tool that extends the functionality of a WordPress site.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: Where are plugins stored in a WordPress installation?

A

A: In the wp-content/plugins directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: What is the minimum requirement for a WordPress plugin?

A

A: A PHP file with a plugin header comment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: How are plugins activated?

A

A: Via the Plugins menu in the WordPress Admin dashboard.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: What happens when a plugin is deactivated?

A

A: The plugin’s functionality stops, but its data is typically retained.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: What is the purpose of the plugin header comment?

A

A: To define metadata like the plugin name, description, author, and version.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: How do you create a plugin header?

A

/*
Plugin Name: My Plugin
Description: A brief description of the plugin.
Version: 1.0
Author: Your Name
*/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: What is the add_action() function used for in a plugin?

A

A: To attach a function to a specific action hook.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: What is the add_filter() function used for in a plugin?

A

A: To modify the output or behaviour of specific WordPress functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: Where should plugin-specific styles and scripts be enqueued?

A

A: In the wp_enqueue_scripts or admin_enqueue_scripts hooks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: What is the recommended folder structure for a plugin?

A

my-plugin/
├── my-plugin.php
├── includes/
├── assets/
│ ├── css/
│ └── js/
└── languages/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q: What is the main plugin file?

A

A: The PHP file that contains the plugin header and is used to initialise the plugin.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q: How can you organise reusable functions in a plugin?

A

A: Place them in a separate file within an includes/ directory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q: What is the purpose of the languages/ folder in a plugin?

A

A: To store translation files for internationalisation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Q: How do you load translation files in a plugin?

A

A: Use the load_plugin_textdomain() function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Q: Why should you use namespacing in plugins?

A

A: To avoid naming conflicts with other plugins or themes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Q: What is the purpose of register_activation_hook()?

A

A: To define a function that runs when the plugin is activated.

18
Q

Q: What is the purpose of register_deactivation_hook()?

A

A: To define a function that runs when the plugin is deactivated.

19
Q

Q: Why should you check for dependencies before activating a plugin?

A

A: To ensure the plugin functions properly and doesn’t break the site.

20
Q

Q: Why is it important to sanitise input in plugins?

A

A: To prevent security vulnerabilities such as XSS or SQL injection.

21
Q

Q: What is the wp_schedule_event() function used for?

A

A: To create a recurring scheduled event in WordPress.

22
Q

Q: What is the shortcode_atts() function used for?

A

A: To set default attributes for shortcodes.

23
Q

Q: How do you add a settings page to a plugin?

A

A: Use the add_options_page() or add_menu_page() functions.

24
Q

Q: What hook should you use to add custom database tables when activating a plugin?

A

A: The register_activation_hook() hook.

25
Q

Q: How do you register a custom post type in a plugin?

A

A: Use the register_post_type() function in the init hook.

26
Q

Q: What is a shortcode?

A

A: A small piece of text (enclosed in square brackets) that executes a specific function in WordPress.

27
Q

Q: How do you create a shortcode in a plugin?

A

A: Use the add_shortcode() function.

28
Q

Q: How can you create a custom widget in a plugin?

A

A: Extend the WP_Widget class and register it using register_widget().

29
Q

Q: How do you register custom taxonomies in a plugin?

A

A: Use the register_taxonomy() function in the init hook.

30
Q

Q: How can you create an admin notice in WordPress?

A

A: Use the admin_notices hook and display the notice with HTML.

31
Q

Q: How can you prevent direct access to a plugin file?

A

A: Use the defined( ‘ABSPATH’ ) || exit; check at the top of the file.

32
Q

Q: Why is it important to escape output in plugins?

A

A: To prevent XSS attacks by ensuring safe display of data.

33
Q

Q: What function should you use to validate nonces?

A

A: check_admin_referer() or wp_verify_nonce().

34
Q

Q: How can you optimise plugin performance?

A

A: Use efficient database queries and enqueue only necessary assets.

35
Q

Q: Why should you avoid using global variables in plugins?

A

A: To reduce conflicts and improve code maintainability.

36
Q

Q: How can you create a custom API endpoint in a plugin?

A

A: Use the register_rest_route() function in the rest_api_init hook.

37
Q

Q: What is a must-use plugin?

A

A: A plugin stored in the wp-content/mu-plugins directory that is automatically activated.

38
Q

Q: How do you make a plugin compatible with multisite?

A

A: Use multisite-specific hooks like is_multisite() and switch_to_blog().

39
Q

Q: What is an autoloader in PHP, and how is it used in plugins?

A

A: An autoloader dynamically loads classes when needed, often implemented via Composer.

40
Q

Q: What is the WordPress Plugin Boilerplate?

A

A: A project template that provides a standardised foundation for building plugins.