//----- Pause Détente -----//
// Supprimer commentaires dans code HTML
function callback($buffer) {$buffer = preg_replace('//', '', $buffer);return $buffer;}
function buffer_start() {ob_start("callback");}
function buffer_end() {ob_end_flush();}
add_action('get_header', 'buffer_start');
add_action('wp_footer', 'buffer_end');
// Thème parent
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
// Nettoyage de la balise meta generator MyArcade
//function myarcade_generator_tag() { echo "\n" . '' . "\n"; } add_action('wp_head', 'myarcade_generator_tag');
remove_action('wp_head', 'myarcade_generator_tag');
// Miniature screenshot
add_image_size( 'pause-screenshot', 264, 264, array( 'center', 'center' ) );
// Fonction screenshots
function pause_all_screenshots ($width = 264, $height = 264, $class = '') {
global $post;
if ( !empty($class) ) { $class = 'class="'.$class.'"'; }
for ($screen_nr = 1; $screen_nr <= 4; $screen_nr++) {
$screenshot = get_post_meta($post->ID, "mabp_screen".$screen_nr."_url", true); // Recuperation URL screenshot
$extension_screenshot = strrchr($screenshot,'.'); // Recuperation extension screnshot
if (preg_match('`.png`',$screenshot)) : $screenshot_thumbnail = str_replace('.png', '-264x264.png' , $screenshot); // Si extension XX alors modification nom fichier pour recuperer la miniature
elseif (preg_match('`.jpg`',$screenshot)) : $screenshot_thumbnail = str_replace('.jpg', '-264x264.jpg' , $screenshot);
elseif (preg_match('`.jpeg`',$screenshot)) : $screenshot_thumbnail = str_replace('.jpeg', '-264x264.jpeg' , $screenshot);
elseif (preg_match('`.gif`',$screenshot)) : $screenshot_thumbnail = str_replace('.gif', '-264x264.gif' , $screenshot);
endif;
// MyArcadeTheme
if ( preg_match( '|^(http).*|i', $screenshot ) ) { ob_start(); ?>
ob_end_flush(); } } }
// Menu pour footer
register_nav_menus( array(
'footer_menu' => 'Menu footer',
) );
// Sidebar pour la page d'accueil
register_sidebars( 1,array('name' => 'Widget Homepage','description' => 'Widget de la page d\'accueil.','id' => 'widget-homepage','before_widget' => '','after_widget' => '
','before_title' => '','after_title' => '
'));
// Force the embed width for YouTube videos
function pausedetente_force_oembed_dimensions($html, $url, $args) {
// Set the height of the video
$height_pattern = "/height=\"[0-9]*\"/";
$html = preg_replace($height_pattern, "height='400'", $html);
// Set the width of the video
$width_pattern = "/width=\"[0-9]*\"/";
$html = preg_replace($width_pattern, "width='100%'", $html);
// Now return the updated markup
return $html;
}
add_filter('embed_oembed_html', 'pausedetente_force_oembed_dimensions', 10, 3);
// Custom excerpt from ACF
function pausedetente_excerpt_news() {
global $post;
$text = get_field( "a-propos" );
if ( '' != $text ) {
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = 120; // 120 words
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
return apply_filters('the_excerpt', $text);
}
// Custom excerpt from ACF
function pausedetente_excerpt_home() {
global $post;
$text = get_field( "a-propos" );
if ( '' != $text ) {
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = 20; // 120 words
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
return apply_filters('the_excerpt', $text);
}
// Ajout d'un fichier langue supplémentaire
load_child_theme_textdomain('pausedetente', get_stylesheet_directory().'/langues');
// Forcer le HTTPS dans l'administration
define('FORCE_SSL_ADMIN', true);
// Ajout des shortcodes dans Contact form 7
add_filter( 'wpcf7_form_elements', 'do_shortcode' );
//----- Divers -----//
// Supprimer menus si non admin
function tipi_clean_menu_items() {
if ( !current_user_can( 'update_core' ) ) :
remove_menu_page( 'index.php' ); // Index
// remove_menu_page( 'edit.php?post_type=forum' ); // Forums
// remove_menu_page( 'post-new.php?post_type=forum' ); // Forums
remove_menu_page( 'edit-comments.php' ); // Commentaires
remove_menu_page( 'edit.php?post_type=page' ); // Pages
remove_menu_page( 'plugins.php' ); // Plugins
remove_menu_page( 'themes.php' ); // Apparence
//remove_menu_page( 'users.php' ); // Utilisateurs
remove_menu_page( 'tools.php' ); // Outils
remove_menu_page( 'options-general.php' ); // Configuration
remove_menu_page( 'wpcf7' ); // WPCF7
endif;
}
add_action( 'admin_menu', 'tipi_clean_menu_items' );
// Supprimer affichages dashboard
function tipi_clean_dashboard() {
/* Si non admin */
if ( !current_user_can( 'update_core' ) ) :
// remove_meta_box( 'bbp-dashboard-right-now', 'dashboard', 'side' ); // BBPress
// remove_meta_box( 'bbp-dashboard-right-now', 'dashboard', 'normal' );
// remove_meta_box( 'bbp-dashboard-right-now', 'dashboard', 'advanced' );
remove_meta_box( 'an_dashboard_widgets', 'dashboard', 'side' ); // AdBlock notify
remove_meta_box( 'an_dashboard_widgets', 'dashboard', 'normal' );
remove_meta_box( 'an_dashboard_widgets', 'dashboard', 'advanced' );
endif;
/* Tout le monde */
remove_meta_box( 'wpseo-dashboard-overview', 'dashboard', 'side' ); // WPSEO
remove_meta_box( 'wpseo-dashboard-overview', 'dashboard', 'normal' );
remove_meta_box( 'wpseo-dashboard-overview', 'dashboard', 'advanced' );
remove_meta_box( 'prli_dashboard_widget', 'dashboard', 'side' ); // Pretty link
remove_meta_box( 'prli_dashboard_widget', 'dashboard', 'normal' );
remove_meta_box( 'prli_dashboard_widget', 'dashboard', 'advanced' );
remove_action( 'welcome_panel', 'wp_welcome_panel' ); // Welcome
}
add_action('wp_dashboard_setup', 'tipi_clean_dashboard' );
// Supprimer liens rapides
add_action( 'admin_bar_menu', 'remove_wp_nodes', 999 );
function remove_wp_nodes()
{
global $wp_admin_bar;
$wp_admin_bar->remove_node( 'new-media' ); // Media
$wp_admin_bar->remove_node( 'new-reply' ); // BBPress réponse
}
// Supprimer affichages article/page
function tipi_remove_metaboxes() {
if ( !current_user_can( 'update_core' ) ) :
// Commentaires
remove_meta_box( 'commentstatusdiv', 'post', 'side' );
remove_meta_box( 'commentstatusdiv', 'post', 'normal' );
remove_meta_box( 'commentstatusdiv', 'post', 'advanced' );
remove_meta_box( 'commentstatusdiv', 'forum', 'side' );
remove_meta_box( 'commentstatusdiv', 'forum', 'normal' );
remove_meta_box( 'commentstatusdiv', 'forum', 'advanced' );
remove_meta_box( 'commentstatusdiv', 'topic', 'side' );
remove_meta_box( 'commentstatusdiv', 'topic', 'normal' );
remove_meta_box( 'commentstatusdiv', 'topic', 'advanced' );
remove_meta_box( 'commentstatusdiv', 'reply', 'side' );
remove_meta_box( 'commentstatusdiv', 'reply', 'normal' );
remove_meta_box( 'commentstatusdiv', 'reply', 'advanced' );
// Champs personnalisés
remove_meta_box( 'postcustom', 'post', 'side' );
remove_meta_box( 'postcustom', 'post', 'normal' );
remove_meta_box( 'postcustom', 'post', 'advanced' );
remove_meta_box( 'postcustom', 'page', 'side' );
remove_meta_box( 'postcustom', 'page', 'normal' );
remove_meta_box( 'postcustom', 'page', 'advanced' );
remove_meta_box( 'postcustom', 'forum', 'side' );
remove_meta_box( 'postcustom', 'forum', 'normal' );
remove_meta_box( 'postcustom', 'forum', 'advanced' );
remove_meta_box( 'postcustom', 'topic', 'side' );
remove_meta_box( 'postcustom', 'topic', 'normal' );
remove_meta_box( 'postcustom', 'topic', 'advanced' );
remove_meta_box( 'postcustom', 'reply', 'side' );
remove_meta_box( 'postcustom', 'reply', 'normal' );
remove_meta_box( 'postcustom', 'reply', 'advanced' );
// Slug
remove_meta_box( 'slugdiv', 'post', 'side' );
remove_meta_box( 'slugdiv', 'post', 'normal' );
remove_meta_box( 'slugdiv', 'post', 'advanced' );
remove_meta_box( 'slugdiv', 'page', 'side' );
remove_meta_box( 'slugdiv', 'page', 'normal' );
remove_meta_box( 'slugdiv', 'page', 'advanced' );
remove_meta_box( 'slugdiv', 'topic', 'side' );
remove_meta_box( 'slugdiv', 'topic', 'normal' );
remove_meta_box( 'slugdiv', 'topic', 'advanced' );
remove_meta_box( 'slugdiv', 'reply', 'side' );
remove_meta_box( 'slugdiv', 'reply', 'normal' );
remove_meta_box( 'slugdiv', 'reply', 'advanced' );
endif;
// Extrait
remove_meta_box( 'postexcerpt', 'post', 'side' );
remove_meta_box( 'postexcerpt', 'post', 'normal' );
remove_meta_box( 'postexcerpt', 'post', 'advanced' );
remove_meta_box( 'postexcerpt', 'page', 'side' );
remove_meta_box( 'postexcerpt', 'page', 'normal' );
remove_meta_box( 'postexcerpt', 'page', 'advanced' );
remove_meta_box( 'postexcerpt', 'forum', 'side' );
remove_meta_box( 'postexcerpt', 'forum', 'normal' );
remove_meta_box( 'postexcerpt', 'forum', 'advanced' );
remove_meta_box( 'postexcerpt', 'topic', 'side' );
remove_meta_box( 'postexcerpt', 'topic', 'normal' );
remove_meta_box( 'postexcerpt', 'topic', 'advanced' );
remove_meta_box( 'postexcerpt', 'reply', 'side' );
remove_meta_box( 'postexcerpt', 'reply', 'normal' );
remove_meta_box( 'postexcerpt', 'reply', 'advanced' );
// Comments
remove_meta_box( 'commentstatusdiv', 'page', 'side' );
remove_meta_box( 'commentstatusdiv', 'page', 'normal' );
remove_meta_box( 'commentstatusdiv', 'page', 'advanced' );
remove_meta_box( 'commentsdiv', 'page', 'side' );
remove_meta_box( 'commentsdiv', 'page', 'normal' );
remove_meta_box( 'commentsdiv', 'page', 'advanced' );
// Trackback
remove_meta_box( 'trackbacksdiv', 'post', 'side' );
remove_meta_box( 'trackbacksdiv', 'post', 'normal' );
remove_meta_box( 'trackbacksdiv', 'post', 'advanced' );
remove_meta_box( 'trackbacksdiv', 'page', 'side' );
remove_meta_box( 'trackbacksdiv', 'page', 'normal' );
remove_meta_box( 'trackbacksdiv', 'page', 'advanced' );
remove_meta_box( 'trackbacksdiv', 'forum', 'side' );
remove_meta_box( 'trackbacksdiv', 'forum', 'normal' );
remove_meta_box( 'trackbacksdiv', 'forum', 'advanced' );
remove_meta_box( 'trackbacksdiv', 'topic', 'side' );
remove_meta_box( 'trackbacksdiv', 'topic', 'normal' );
remove_meta_box( 'trackbacksdiv', 'topic', 'advanced' );
remove_meta_box( 'trackbacksdiv', 'reply', 'side' );
remove_meta_box( 'trackbacksdiv', 'reply', 'normal' );
remove_meta_box( 'trackbacksdiv', 'reply', 'advanced' );
// Akismet
remove_meta_box( 'bbp_akismet_topic_history', 'reply', 'side' );
remove_meta_box( 'bbp_akismet_topic_history', 'reply', 'normal' );
remove_meta_box( 'bbp_akismet_topic_history', 'reply', 'advanced' );
}
add_action('admin_menu','tipi_remove_metaboxes');
// Suppression de l'affichage de la version WP si non admin
function tipi_clean_footer_version_wordpress() {
if ( !current_user_can('update_core') ) {
remove_filter( 'update_footer', 'core_update_footer' );
}
}
add_action( 'admin_menu', 'tipi_clean_footer_version_wordpress' );
// Interdire le back-office aux membres non administrateurs
function tipi_block_dashboard() {
$file = basename($_SERVER['PHP_SELF']);
if (is_user_logged_in() && is_admin() && !current_user_can('edit_posts') && $file != 'admin-ajax.php') {
wp_redirect( home_url() );
exit();
}
}
add_action('init', 'tipi_block_dashboard');
// Supprimer la barre
function tipi_disable_admin_bar() {
if( ! current_user_can('edit_posts') )
add_filter('show_admin_bar', '__return_false');
}
add_action( 'after_setup_theme', 'tipi_disable_admin_bar' );
// WordPress V 4.4 et les post embed par defaut
// Disable Embeds for others since WP 4.4
function disable_embeds_init() {
// Remove oEmbed discovery links.
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
// Remove all embeds rewrite rules.
add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
}
add_action( 'init', 'disable_embeds_init', 9999 );
// Remove all rewrite rules related to embeds.
function disable_embeds_rewrites( $rules ) {
foreach ( $rules as $rule => $rewrite ) {
if ( false !== strpos( $rewrite, 'embed=true' ) ) {
unset( $rules[ $rule ] );
}
}
return $rules;
}
// Remove embeds rewrite rules on plugin activation.
function disable_embeds_remove_rewrite_rules() {
add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'disable_embeds_remove_rewrite_rules' );
// Flush rewrite rules on plugin deactivation.
function disable_embeds_flush_rewrite_rules() {
remove_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'disable_embeds_flush_rewrite_rules' );
// Disable Embeds posts for me since WP 4.4
add_filter( 'embed_oembed_html', 'hack_embed_oembed_html', 10, 2 );
function hack_embed_oembed_html( $html, $url ) {
if ( ! class_exists( 'WP_oEmbed' ) ) {
include( ABSPATH . WPINC . '/class-oembed.php' );
}
$WP_oEmbed = new WP_oEmbed();
if ( ! $WP_oEmbed->get_provider( $url, array( 'discover' => false ) ) ) {
return '';
}
return $html;
}
// Disable Thumbnails Embeds since WP 4.4
add_filter( 'embed_thumbnail_image_shape', '__return_false' );
// Disable Embeds Cache since WP 4.4
add_filter( 'oembed_ttl', 'one_hundred_years_embed_cache_ttl' );
function one_hundred_years_embed_cache_ttl() {
return 100 * YEAR_IN_SECONDS;
}
// Empty Embeds cache since WP 4.4
add_action( 'plugins_loaded', 'empty_embed_cache' );
function empty_embed_cache() {
global $wpdb;
$wpdb->query( 'DELETE from ' . $wpdb->postmeta . ' WHERE meta_key LIKE "_oembed_%"' );
wp_die( 'Cache emptied, please now remove this file : ' . __FILE__ . '' );
}
// Add post embed in commets since WP 4.4
add_filter( 'get_comment_text', 'add_post_oembed_comment_support', 0 );
function add_post_oembed_comment_support( $comment_text ) {
global $wp_embed;
if ( ! class_exists( 'WP_oEmbed' ) ) {
include( ABSPATH . WPINC . '/class-oembed.php' );
}
$WP_oEmbed = new WP_oEmbed();
if ( $WP_oEmbed->get_provider( $comment_text, array( 'discover' => false ) ) ) {
return $comment_text;
}
if ( $wp_embed ) {
return $GLOBALS['wp_embed']->autoembed( $comment_text );
}
return $comment_text;
}
// Logo back-office personnel
function my_custom_login_logo() {
$login_background = '#eee';
$login_text = '#eee';
$form_background = '#e72a35';
$login_accent = '#17a79c';
echo '';
}
add_action('login_head', 'my_custom_login_logo');
// Page d'identification de l'administration
function wp_url_login(){
return "/";
}
function wp_url_title(){
return esc_attr(get_bloginfo('name', 'display'));
}
add_filter('login_headerurl', 'wp_url_login');
add_filter('login_headertitle', 'wp_url_title');
// Modifier l'éditeur visuel TinyMCE et interdire des titres http://www.tinymce.com/wiki.php/Configuration:block_formats
function customformatTinyMCE($init) {
$init['block_formats'] = 'Paragraphe=p; Adresse=pre; Code=code; Titre=h2; Sous-titre=h3; Sous-titre secondaire=h4';
return $init;
}
add_filter('tiny_mce_before_init', 'customformatTinyMCE' );
// Supprimer des options de l'éditeur visuel http://wordpress.stackexchange.com/questions/103347/removing-buttons-from-the-editor
// Ligne 1 : bold, italic, strikethrough, bullist, numlist, blockquote, alignleft, aligncenter, alignright, link, unlink, wp_more, spellchecker, wp_fullscreen, wp_adv, separator
// Ligne 2 : formatselect, underline, alignjustify, forecolor, pastetext, pasteword, removeformat, charmap, outdent, indent, undo, redo, wp_help
add_filter("mce_buttons", "tinymce_editor_buttons", 99); //targets the first line
add_filter("mce_buttons_2", "tinymce_editor_buttons_second_row", 99); //targets the second line
function tinymce_editor_buttons($buttons) {
return array(
"undo", "redo", "separator", "formatselect", "bold", "italic", "blockquote", "separator", "bullist", "numlist", "separator", "link", "unlink", "pastetext", "removeformat", "separator", "wp_help", "code"
);
}
function tinymce_editor_buttons_second_row($buttons) {
//return an empty array to remove this line
return array();
}
// Widgets voulus ou pas
add_action('wp_dashboard_setup', 'wpc_dashboard_widgets');
function wpc_dashboard_widgets() {
global $wp_meta_boxes;
// Today widget unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
// Last comments unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
// Incoming links
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
// Plugins
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
// Press-minute
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
// Brouillons recents
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
// Blog WordPress
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
// Actualites WordPress
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}
// Suppression des menus WordPress dans le back-office
function tipi_links_admin_bar_remove() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo'); // Remove the WordPress logo
$wp_admin_bar->remove_menu('about'); // Remove the about WordPress link
$wp_admin_bar->remove_menu('wporg'); // Remove the WordPress.org link
$wp_admin_bar->remove_menu('documentation'); // Remove the WordPress documentation link
$wp_admin_bar->remove_menu('support-forums'); // Remove the support forums link
$wp_admin_bar->remove_menu('feedback'); // Remove the feedback link
// $wp_admin_bar->remove_menu('site-name'); // Remove the site name menu
$wp_admin_bar->remove_menu('view-site'); // Remove the view site link
$wp_admin_bar->remove_menu('comments'); // Remove the comments link
// $wp_admin_bar->remove_menu('new-content'); // Remove the content link
$wp_admin_bar->remove_menu('wpseo-menu'); // Remove the WPSEO menu
if (!current_user_can( 'update_core' )) {
$wp_admin_bar->remove_menu('updates'); // Remove the updates link
}
}
add_action('wp_before_admin_bar_render', 'tipi_links_admin_bar_remove', 0);
// Supprimer le menu aide
add_filter( 'contextual_help', 'mycontext_remove_help', 999, 3 );
function mycontext_remove_help($old_help, $screen_id, $screen){
$screen->remove_help_tabs();
return $old_help;
}
//----- Footer -----//
// Footer de l'administration personnalisé
function remove_footer_admin () {
echo 'Site web réalisé par Thibaut Parent de l\'agence TiPi Com and Web';
}
add_filter('admin_footer_text', 'remove_footer_admin');
//----- Dashboard -----//
// Widget webmastering
function tipi_dashboard_widget_function() {
echo "";
}
function tipi_add_dashboard_widgets() {
wp_add_dashboard_widget('wp_dashboard_widget', 'Informations techniques', 'wp_dashboard_widget_function');
}
add_action('wp_dashboard_setup', 'tipi_add_dashboard_widgets' );
// Suppression des notifications YoastSEO
if (!defined('ABSPATH')) die('Restricted Area');
add_action('admin_init', 'wpc_disable_yoast_notifications');
function wpc_disable_yoast_notifications() {
if (is_plugin_active('wordpress-seo/wp-seo.php')) {
remove_action('admin_notices', array(Yoast_Notification_Center::get(), 'display_notifications'));
remove_action('all_admin_notices', array(Yoast_Notification_Center::get(), 'display_notifications'));
}
}
// Avec celui-ci on pousse la metabox de Yoast en bas
add_filter( 'wpseo_metabox_prio', 'myprefix_wpseo_prio_low' );
function myprefix_wpseo_prio_low( $priority ) {
$priority = 'low';
return $priority;
}
// Là on désactive les pointers, qui vont sinon nous refaire le parcours de découverte à chaque mise à jour…
class WPSEO_Pointers {
public static function get_instance() {}
}
// … et ici on enlève l'horrible redirection vers la page "Vous avez mis à jour Yoast"
add_filter( 'option_wpseo', 'filter_yst_wpseo_option' );
function filter_yst_wpseo_option( $option ) {
$option['seen_about'] = true;
return $option;
}
?>