Created
August 19, 2023 06:53
-
-
Save ibrahim-kardi/54d23c88047cdadcd260d66613d12916 to your computer and use it in GitHub Desktop.
Registers wordpress dashboard widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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