Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ibrahim-kardi/54d23c88047cdadcd260d66613d12916 to your computer and use it in GitHub Desktop.
Save ibrahim-kardi/54d23c88047cdadcd260d66613d12916 to your computer and use it in GitHub Desktop.
Registers wordpress dashboard widget
<?php
add_action( 'wp_dashboard_setup', 'test_dashboard_widget' );
/**
* Registers dashboard widget.
*/
function test_dashboard_widget() {
wp_add_dashboard_widget(
'test_dashboard_widget',
esc_html( 'Test widget' ),
'test_dashboard_widget_func',
null,
null,
'normal',
'high'
);
}
/**
* Renders "Test widget" data at dashboard.
*/
function test_dashboard_widget_func() {
echo '<h1>Our top users:</h1>';
$response = wp_remote_get( 'https://jsonplaceholder.typicode.com/users' );
$response = wp_remote_retrieve_body( $response );
$response = json_decode( $response );
foreach ( $response as $key => $values ) {
$escaped_text = esc_html( $values->username );
echo "<p>{$escaped_text}</p>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment