WordPress APIs and Integrations Flashcards
(25 cards)
What is the WordPress REST API?
The WordPress REST API allows external applications to interact with WordPress data via JSON.
Introduced in WordPress 4.7, the REST API enables CRUD (Create, Read, Update, Delete) operations for posts, users, and more. Freelancers use it to build mobile apps or integrations for clients, while enterprise architects leverage it for headless CMS or system connectivity in large-scale deployments.
What is a REST API endpoint in WordPress?
An endpoint is a specific URL route that handles a REST API request, like /wp-json/wp/v2/posts. Explanation: Endpoints define actions (e.g., retrieving posts) and return JSON data. Freelancers use default endpoints for client integrations, while enterprise architects create custom endpoints for complex system interactions.
How do you access the WordPress REST API?
Send HTTP requests (GET, POST, etc.) to /wp-json/ endpoints using tools like cURL or Postman. Explanation: For example, a GET request to /wp-json/wp/v2/posts retrieves posts. Freelancers test APIs for client projects, while enterprise architects use authenticated requests for secure integrations.
What is the purpose of register_rest_route()?
register_rest_route() creates custom REST API endpoints in WordPress. Explanation: For example, register_rest_route(‘myplugin/v1’, ‘/data’, array(‘methods’ => ‘GET’, ‘callback’ => ‘my_callback’)) adds a custom route. Freelancers build endpoints for client-specific data, while enterprise architects use them for scalable API integrations.
What is a REST API callback function?
A callback function processes requests and returns data for a custom REST endpoint. Explanation: Defined in register_rest_route(), it handles logic (e.g., querying data). Freelancers create callbacks for custom APIs, while enterprise architects ensure they’re secure and optimized for performance.
How do you secure WordPress REST API endpoints?
Use authentication (e.g., OAuth, API keys) and permissions callbacks.
The permission_callback in register_rest_route() restricts access (e.g., current_user_can(‘edit_posts’)). Freelancers secure APIs for clients, while enterprise architects enforce enterprise-grade authentication like JWT.
What is the WP REST API authentication?
Authentication verifies the identity of API users, using methods like OAuth or API keys.
Plugins like Application Passwords or JWT Authentication enable secure access. Freelancers implement authentication for client APIs, while enterprise architects integrate with SSO systems for enterprise use.
What is an API key in WordPress?
An API key is a unique token used to authenticate REST API requests.
Generated via plugins or custom code, keys ensure secure access. Freelancers use keys for client integrations, while enterprise architects manage them for large-scale API security.
What is the WP_REST_Response class?
WP_REST_Response formats and returns data for REST API responses.
For example, return new WP_REST_Response($data, 200) sends JSON data with a status code. Freelancers use it for clean API responses, while enterprise architects ensure standardized, scalable output.
What is the WordPress HTTP API?
The HTTP API handles external HTTP requests from WordPress, like fetching data from third-party APIs.
Functions like wp_remote_get() make requests (e.g., to a weather API). Freelancers use it for client integrations, while enterprise architects leverage it for system-to-system communication.
What is wp_remote_get()?
wp_remote_get() sends a GET request to an external API and returns the response.
For example, wp_remote_get(‘https://api.example.com/data’) fetches data. Freelancers use it for third-party integrations, while enterprise architects ensure secure, efficient API calls.
What is wp_remote_post()?
wp_remote_post() sends a POST request to an external API.
For example, wp_remote_post(‘https://api.example.com/submit’, array(‘body’ => $data)) sends data. Freelancers use it for form submissions, while enterprise architects integrate it with external services.
What is a webhook in WordPress?
A webhook sends data to an external URL when a WordPress event occurs.
For example, a webhook notifies a CRM on new user registration. Freelancers set up webhooks for clients, while enterprise architects use them for real-time system syncing.
How do you create a custom webhook in WordPress?
Use wp_remote_post() with an action hook to send data on events.
For example, add_action(‘user_register’, ‘send_webhook’) triggers a webhook on user signup. Freelancers build webhooks for client needs, while enterprise architects ensure reliable data delivery.
What is the WordPress Transients API?
The Transients API caches external API data temporarily in the WordPress database.
Using set_transient() and get_transient(), it reduces API calls. Freelancers use transients for performance, while enterprise architects optimize caching for scalability.
What is set_transient()?
set_transient() stores temporary data with an expiration time.
For example, set_transient(‘api_data’, $data, HOUR_IN_SECONDS) caches data for an hour. Freelancers use it for efficient integrations, while enterprise architects pair it with object caching.
What is get_transient()?
get_transient() retrieves cached data from the WordPress database.
For example, get_transient(‘api_data’) fetches cached API results. Freelancers use it to speed up client sites, while enterprise architects ensure efficient data retrieval.
What is GraphQL in WordPress?
GraphQL is an alternative API for querying WordPress data with flexible requests.
Plugins like WPGraphQL enable GraphQL queries over REST. Freelancers use it for modern integrations, while enterprise architects leverage it for efficient, client-driven data fetching.
What is the WPGraphQL plugin?
WPGraphQL provides a GraphQL interface for WordPress data.
It allows precise queries (e.g., fetching specific post fields). Freelancers use it for headless CMS projects, while enterprise architects integrate it with modern frontends like React.
What is a third-party API integration?
It connects WordPress to external services like Mailchimp or Google Maps.
Using the HTTP API or plugins, developers fetch or send data. Freelancers offer integrations as a service, while enterprise architects ensure seamless connectivity with enterprise systems.
How do you integrate Mailchimp with WordPress?
Use the Mailchimp API or a plugin like MC4WP to sync users or forms.
The API requires an API key and wp_remote_post() for requests. Freelancers integrate it for client email marketing, while enterprise architects automate it for large-scale campaigns.
What is OAuth in WordPress integrations?
OAuth is an authentication protocol for secure API access.
It uses tokens to grant access without sharing credentials. Freelancers implement OAuth for client APIs, while enterprise architects use it for secure, enterprise-grade integrations.
What is the rest_pre_dispatch filter?
rest_pre_dispatch modifies REST API requests before processing.
For example, add_filter(‘rest_pre_dispatch’, ‘modify_request’) alters request data. Freelancers use it for custom API logic, while enterprise architects ensure flexible, secure API handling.
What is the rest_authentication_errors filter?
rest_authentication_errors handles REST API authentication errors.
For example, add_filter(‘rest_authentication_errors’, ‘custom_error’) customizes error messages. Freelancers use it for client APIs, while enterprise architects enforce strict error handling.