<?php 
/**
 * Plugin Name: Tableau de bord
 * Plugin URI: https://btobdesign.com
 * Description: Création de boutons personnalisés donnant accès aux fonctions courantes et affichage des types de contenus personnalisés dans la fenêtre "Aujourd'hui"
 * Version: 1.0
 * Author: B-to-B Design
 * Author URI: https:///btobdesign.com
 *
 */
 

/*
///////////////////////////////////////////////////////////

// Enlever des widgets

 -----------------------------------------------------------------
*/
function disable_default_dashboard_widgets() {
	//remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
	remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
	remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
	remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' );
	remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
}
add_action('admin_menu', 'disable_default_dashboard_widgets');




// Styles dashboard	
function styleadmin() {
	wp_enqueue_style( 'b2b-admin-style', plugins_url( '/css/admin.css', __FILE__ ), false, '1.0', 'all' ); // Inside a plugin
}
add_action('admin_head', 'styleadmin');


/*
///////////////////////////////////////////////////////////

// Ajouter des boutons sur le dashboard pour faciliter la mise à jour du site

 -----------------------------------------------------------------
*/
// Ajouter des boutons sur le dashboard pour faciliter la mise à jour du site
	// Les icones sont dans le dossier img du theme. 
	// Le set d'icones est Fugue Icons http://p.yusukekamiyamane.com/
function example_dashboard_widget_function() {
echo '<div class="accueil">

<a href="http://surgimab.com/wp-admin/post-new.php" id="articleAdd" class="bouton"><h4>Articles</h4><p>Ajouter</p></a>
<a href="http://surgimab.com/wp-admin/edit.php" id="articleEdit" class="bouton"><h4>Articles</h4><p>Modifier</p>
<a href="http://surgimab.com/wp-admin/post-new.php?post_type=page" id="pageAdd" class="bouton"><h4>Pages</h4><p>Ajouter</p></a>
<a href="http://surgimab.com/wp-admin/edit.php?post_type=page" id="pageEdit" class="bouton"><h4>Pages</h4><p>Modifier</p></a>
<a href="http://surgimab.com/wp-admin/nav-menus.php" id="menuEdit" class="bouton"><h4>Menus</h4><p>Modifier</p></a>
<a href="http://surgimab.com/wp-admin/widgets.php" id="widgetEdit" class="bouton"><h4>Widgets</h4><p>Modifier</p></a>
<table width="100%">
	<tr>
		<td style="background:#5b2264;padding:3px;color:#eee">#5b2264</td>
		<td style="background:#6a2875;padding:3px;color:#eee">#6a2875</td>
		<td style="background:#e99500;padding:3px">#e99500</td>
		<td style="background:#efbf59;padding:3px">#efbf59</td>
	</tr>
	<tr>
		<td style="background:#555555;padding:3px;color:#eee">#555555</td>
		<td style="background:#beb9b2;padding:3px">#beb9b2</td>
		<td style="background:#dcdcdc;padding:3px">#dcdcdc</td>
		<td style="background:#e7e7e7;padding:3px">#e7e7e7</td>
	</tr>
</table>
</div>
<div class="clear"></div>
';
}
function example_add_dashboard_widgets() {
	wp_add_dashboard_widget('example_dashboard_widget', 'Fonctions courantes', 'example_dashboard_widget_function');
}
add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );



/*
///////////////////////////////////////////////////////////

// Display custom post types and taxonomies on the "At a Glance" bloc on the dashbard
 --
 */

function b2b_right_now_content_table_end() {
	$args = array(
		'public' => true ,
		'_builtin' => false
	);
	$output = 'object';
	$operator = 'and';
	$post_types = get_post_types( $args , $output , $operator );
	foreach( $post_types as $post_type ) {
		$num_posts = wp_count_posts( $post_type->name );
		$num = number_format_i18n( $num_posts->publish );
		$text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) );
		if ( current_user_can( 'edit_posts' ) ) {
			$num = "<a href='edit.php?post_type=$post_type->name'>$num</a>";
			$text = "<a href='edit.php?post_type=$post_type->name'>$text</a>";
		}
		echo '<tr><td class="first b b-' . $post_type->name . '">' . $num . '</td>';
		echo '<td class="t ' . $post_type->name . '">' . $text . '</td></tr>';
	}
	$taxonomies = get_taxonomies( $args , $output , $operator );
	foreach( $taxonomies as $taxonomy ) {
		$num_terms  = wp_count_terms( $taxonomy->name );
		$num = number_format_i18n( $num_terms );
		$text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms ));
		if ( current_user_can( 'manage_categories' ) ) {
			$num = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>";
			$text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>";
	}
	echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>';
	echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>';
	 }
}
add_action( 'right_now_content_table_end' , 'b2b_right_now_content_table_end' );