Skip to content

Instantly share code, notes, and snippets.

@bahiirwa
Last active May 8, 2019
Embed
What would you like to do?
<?php
/*
Plugin Name: Query APIs
Plugin URI: https://omukiguy.com
Description: Plugin Working with External API calls in WordPress.
Version: 0.1.0
Author: Laurence Bahiirwa
Author URI: https://omukiguy.com/
License: GPL-3.0+
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
Text-Domain: woougsms
*/
// If this file is called firectly, abort!!!
defined( 'ABSPATH' ) or die( 'Unauthorized Access!' );
/**
* Register a custom menu page.
*/
function woougsms_create_admin_page() {
add_menu_page(
'SMS Plugin Settings',
'SMS Plugin',
'manage_options',
'woougsms_plugin',
'create_menu_page',
'dashicons-testimonial',
85
);
//call register settings function
}
add_action( 'admin_menu', 'woougsms_create_admin_page' );
function register_woougsms_settings() {
$defaults = array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => false,
);
//Sidebar Options
register_setting( 'sunset-settings-group', 'profile_picture', $defaults );
add_settings_section( 'sunset-sidebar-options', 'Sidebar Option', 'sunset_sidebar_options', 'woougsms_plugin');
add_settings_field( 'sidebar-profile-picture', 'Profile Picture', 'sunset_sidebar_profile', 'woougsms_plugin', 'sunset-sidebar-options');
}
// Sidebar Options Functions
function sunset_sidebar_options() {
echo 'Customize your Sidebar Information';
}
function sunset_sidebar_profile() {
$picture = esc_attr( get_option( 'profile_picture' ) );
echo '<input type="text" name="last_name" value="'.$picture.'" placeholder="Last Name" />';
}
function create_menu_page() {
?>
<div class="wrap">
<h1>Your Plugin Name</h1>
<form method="post" action="options.php">
<?php settings_fields( 'sunset-settings-group' ); ?>
<?php do_settings_sections( 'woougsms_plugin' ); ?>
<?php submit_button( 'Save Changes', 'primary', 'btnSubmit' ); ?>
</form>
</div>
<?php
}
add_action( 'admin_init', 'register_woougsms_settings' );
function external_api_call() {
$url = 'https://jsonplaceholder.typicode.com/users';
$arguments = array (
'method' => 'GET'
);
$response = wp_remote_get( $url, $arguments);
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
}
echo '<pre>';
var_dump(wp_remote_retrieve_body($response));
echo '</pre>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment