Created
August 13, 2021 11:55
-
-
Save TennousuAthena/96bb33fedbd979ed64fb167d5c60d0c3 to your computer and use it in GitHub Desktop.
WP_Hitokoto
This file contains hidden or 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 | |
/** | |
* @package Hello_Hitokoto | |
* @version 1.0.1 | |
*/ | |
/* | |
Plugin Name: Hello Hitokoto | |
Plugin URI: https://gist.github.com/TennousuAthena/96bb33fedbd979ed64fb167d5c60d0c3 | |
Description: 在管理界面添加一言 | |
Author: TennousuAthena | |
Version: 1.0.1 | |
Author URI: https://lemoe.cn | |
*/ | |
function hitokoto() { | |
printf( | |
'<p id="hitokoto"><span id="hitokoto_text">:D 获取中...</span></p>' | |
); | |
} | |
add_action( 'admin_notices', 'hitokoto' ); | |
function hitokoto_css() { | |
echo " | |
<style> | |
#hitokoto { | |
float: right; | |
padding: 5px 10px; | |
margin: 0; | |
font-size: 12px; | |
line-height: 1.6666; | |
} | |
</style> | |
"; | |
} | |
function hitokoto_js(){ | |
echo "<script> | |
fetch('https://v1.hitokoto.cn') | |
.then(response => response.json()) | |
.then(data => { | |
const hitokoto = document.getElementById('hitokoto_text') | |
hitokoto.innerText = data.hitokoto | |
}) | |
.catch(console.error) | |
</script>"; | |
} | |
add_action( 'admin_head', 'hitokoto_css' ); | |
add_action( 'admin_footer', 'hitokoto_js' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment