PHP and Wordpress Integration Flashcards

1
Q

Q: What is the primary role of PHP in WordPress?

A

A: To process data, interact with the database, and generate dynamic HTML for web pages.

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

Q: What is the name of the WordPress core PHP configuration file?

A

A: wp-config.php.

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

Q: What global object is used to interact with the database in WordPress?

A

A: $wpdb.

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

Q: How do you include a PHP file in a WordPress theme?

A

A: Use get_template_part() or require_once().

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

Q: How do you add PHP code to a WordPress page or post?

A

A: Use a plugin like “Insert PHP Code Snippet” or write a custom shortcode.

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

Q: How do you define a WordPress theme?

A

A: By creating a directory in /wp-content/themes/ with at least style.css and index.php.

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

Q: What function is used to enqueue styles in a theme?

A

A: wp_enqueue_style().

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

Q: What function is used to enqueue scripts in a theme?

A

A: wp_enqueue_script().

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

Q: How do you add a theme support feature, like post thumbnails?

A

A: Use add_theme_support().

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

Q: What PHP function outputs the content of the <title> tag?</title>

A

A: wp_title() (deprecated, use add_theme_support( ‘title-tag’ ) instead).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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
12
Q

Q: How do you add an admin menu in a plugin?

A

A: Use add_menu_page() or add_submenu_page().

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

Q: How do you register a plugin’s custom settings?

A

A: Use register_setting().

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

Q: How do you enqueue plugin-specific scripts or styles?

A

A: Use wp_enqueue_scripts or admin_enqueue_scripts.

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

Q: What PHP function activates a WordPress plugin?

A

A: Use the register_activation_hook() function.

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

Q: What is an action hook in WordPress?

A

A: A point in the WordPress execution where a function can be hooked to perform an action.

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

Q: What is a filter hook in WordPress?

A

A: A hook that allows you to modify data before it is used or displayed.

18
Q

Q: How do you attach a function to an action hook?

A

A: Use add_action().

19
Q

Q: How do you attach a function to a filter hook?

A

A: Use add_filter().

20
Q

Q: How do you remove a function from a hook?

A

A: Use remove_action() or remove_filter().

21
Q

Q: What function retrieves data from the WordPress database?

A

A: $wpdb->get_results().

22
Q

Q: How do you safely include variables in SQL queries?

A

A: Use $wpdb->prepare().

23
Q

Q: How do you insert data into the WordPress database?

A

A: Use $wpdb->insert().

24
Q

Q: How do you update data in the WordPress database?

A

A: Use $wpdb->update().

25
Q

Q: How do you delete data from the WordPress database?

A

A: Use $wpdb->delete().

26
Q

Q: What is a shortcode in WordPress?

A

A: A small piece of text in square brackets that executes PHP functions.

27
Q

Q: How do you register a new shortcode?

A

A: Use add_shortcode().

28
Q

Q: What is the syntax for a basic shortcode function?

A

function my_shortcode() {
return ‘Content to display’;
}
add_shortcode( ‘shortcode_name’, ‘my_shortcode’ );

29
Q

Q: How can you add attributes to a shortcode?

A

A: Use the $atts parameter in the shortcode function.

30
Q

Q: How do you output dynamic data in a shortcode?

A

A: Use PHP to retrieve and format the data inside the shortcode function.

31
Q

Q: What function registers a custom post type?

A

A: register_post_type().

32
Q

Q: How do you associate a taxonomy with a custom post type?

A

A: Use the taxonomies argument in register_post_type().

33
Q

Q: How do you set up custom capabilities for a post type?

A

A: Use the capability_type and capabilities arguments in register_post_type().

34
Q

Q: How do you create an archive page for a custom post type?

A

A: Create a archive-{post-type}.php file in the theme.

35
Q

Q: How do you flush rewrite rules after registering a custom post type?

A

A: Use flush_rewrite_rules() in the activation hook.

36
Q

Q: How do you register a custom REST API route in WordPress?

A

A: Use register_rest_route().

37
Q

Q: What is the hook for registering custom REST API routes?

A

A: rest_api_init.

38
Q

Q: What is the purpose of the callback argument in register_rest_route()?

A

A: Defines the function to execute when the endpoint is accessed.

39
Q

Q: How do you secure a custom REST API route?

A

A: Use the permission_callback argument.

40
Q

Q: How do you send a JSON response in the REST API?

A

A: Use the wp_send_json() or wp_send_json_success() function.