<?php
/*
Plugin Name: My Plugin
Description: This plugin retrieves content from another website using an API call.
*/
function my_plugin_shortcode( $atts ) {
// Extract the attributes
extract( shortcode_atts( array(
'url' => 'https://example.com',
), $atts ) );
// Make the API call using fetch
$response = wp_remote_fetch( $url );
// If the API call is successful, display the content
if ( ! is_wp_error( $response ) ) {
return wp_remote_retrieve_body( $response );
}
}
add_shortcode( 'my_plugin', 'my_plugin_shortcode' );
To use this plugin, you would simply add the [my_plugin] shortcode to a post or page, like this: [my_plugin url="https://example.com"].
This plugin will make an API call to the specified URL using the fetch function, and if the call is successful, it will display the content on the WordPress site.
