Here is the code on how to delete all dashboard widgets - the default, and plugin widgets but I want to change the code to only delete custom dashboard widgets not the default ones.
// Create the function to use in the action hook
function remove_dashboard_widgets() {
global $wp_meta_boxes;
if ( !array( $wp_meta_boxes ) ) return;
foreach ( $wp_meta_boxes as $widget_section => $widget_locations ) {
if ( $widget_section == 'dashboard' ) {
foreach ( $widget_locations as $widget_location => $widget_types ) {
foreach ( $widget_types as $widget_type => $widgets ) {
foreach ( $widgets as $widget_name => $widget ) {
remove_meta_box( $widget_name, $widget_section, $widget_location );
}
}
}
}
}
}
// Hook into the 'wp_dashboard_setup' action to register our function
add_action('wp_dashboard_setup', 'remove_dashboard_widgets', 11 );