Uses:
function Declaration:
wp_add_dashboard_widget()
function parameters:
wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback=null);
The Action:
add_action();
The Action hook:
wp_dashboard_setup
Example procedure:
open wp function.php and past this steps:
#dashboard setup:
add_action(‘wp_dashboard_setup’,’snd_dashboard_config’);
function snd_dashboard_config(){
wp_add_dashboard_widget(‘snd_dash_id’, __(‘Second Time Configure’,’fifteen’), ‘snd_dash_callback’,’snd_dash_callhandle’);
}
#function callback.
function snd_dash_callback(){
#get save data
if(!$widget_option=get_option(‘dashboard_widget_option’)){
$widget_option=array();
}
#default output
$output=sprintf(‘%s’,__(‘Second Configuration Area ☝’));
#check if save data contains contents
$save_widget_post=isset($widget_option[‘feature_post’])
? $widget_option[‘feature_post’] : false;
#custom content save by controll callback
if($save_widget_post){
$post=get_post($save_widget_post);
if($post){
$content=do_shortcode(html_entity_decode($post->post_content));
$output=”{$post->post_title}{$content}”;
}
}
echo “{$output}”;
}
#function step two
function snd_dash_callhandle(){
#get saved
if(!$widget_option=get_option(‘dashboard_widget_option’)){
$widget_option=array();
}
#process update
if(‘POST’ == $_SERVER[‘REQUEST_METHOD’] && isset($_POST[‘dashboard_widget_option’])){
#mini validation
$widget_option[‘feature_post’]=absint($_POST[‘dashboard_widget_option’][‘feature_post’]);
#save update
update_option(‘dashboard_widget_option’,$widget_option);
}
#set defaults
if(!isset($widget_option[‘feature_post’]))
$widget_option[‘feature_post’]=”;
#process output
echo “Available Pages Title”;
wp_dropdown_pages(array(
‘name’=>’dashboard_widget_option[feature_post]’,
‘id’=>’feature_post’,
‘show_option_none’=>’-Select-‘,
‘selected’=>$widget_option[‘feature_post’]
));
echo “”;
}
Figure link:
Reference link: wp codex