Skip to content

Instantly share code, notes, and snippets.

@LZL0
Created June 18, 2020 16:35
Show Gist options
  • Save LZL0/9d09cff9f84006936c033a04be393ec9 to your computer and use it in GitHub Desktop.
Save LZL0/9d09cff9f84006936c033a04be393ec9 to your computer and use it in GitHub Desktop.
Granny Shots Dashboard Widget
<?php
if(!(defined('ABSPATH'))) exit;
add_action('wp_dashboard_setup', 'fs_bps_dashboard_widget');
add_action('wp_dashboard_setup', 'fs_bps_dashboard_update_box_handle');
function fs_bps_dashboard_widget()
{
if(current_user_can('edit_posts'))
{
global $wp_meta_boxes;
wp_add_dashboard_widget('fs-bps-update-box', 'Granny Shots bps', 'fs_bps_dashboard_update_box');
}
}
function fs_bps_dashboard_update_box()
{
if(!current_user_can('edit_posts'))
{
return;
}
?>
<form method="POST">
<table class="form-table">
<tbody>
<tr>
<th scope="row">
<label>
New Granny Shots number
</label>
</th>
<td>
<input autocomplete="off" id="fs_bps" name="fs_bps" value="<?php echo get_option('fs_bps'); ?>" style="box-shadow: 0 0 0 transparent;
border-radius: 4px;
border: 1px solid #7e8993;
background-color: #fff;
color: #32373c;
padding: 0 8px;
line-height: 2;
min-height: 30px;
margin-bottom: 15px;">
</td>
</tr>
</tbody>
</table>
<input class="button" type="submit" value="Save" />
</form>
<?php
}
function fs_bps_dashboard_update_box_handle()
{
$bps = sanitize_key($_POST['fs_bps'] ?? 0);
if(!($bps > 0))
{
return;
}
if(!current_user_can('edit_posts'))
{
return;
}
$year = date('Y');
$monthnum = date('m');
$month = date('F');
update_option('fs_bps', $bps, 'no');
update_option('fs_bps_year', $year, 'no');
update_option('fs_bps_monthnum', $monthnum, 'no');
update_option('fs_bps_month', $month, 'no');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment