Skip to content

Instantly share code, notes, and snippets.

View thierrypigot's full-sized avatar

Thierry Pigot thierrypigot

View GitHub Profile
@thierrypigot
thierrypigot / functions.php
Created December 28, 2022 10:36
Beaver builder custom module
<?php
if ( class_exists( 'FLBuilderModule' ) ) {
class Beaver_Builder_Custom_Module extends FLBuilderModule {
public function __construct() {
parent::__construct( array(
'name' => __( 'Custom Module', 'fl-builder' ),
'description' => __( 'A custom Beaver Builder module.', 'fl-builder' ),
'category' => __( 'My Custom Modules', 'fl-builder' ),
@thierrypigot
thierrypigot / functions.php
Created December 28, 2022 10:22
Plugin to add metabox, field to select a date and a shortcode to use this value in my content
<?php
/*
Plugin Name: Metabox Date Select
Plugin URI: https://example.com
Description: Plugin to add metabox, field to select a date and a shortcode to use this value in my content.
Version: 1.0
Author: Your Name
Author URI: https://example.com
License: GPL2
SELECT *
FROM wp_posts
WHERE post_title = "Mon titre d'article"
AND post_status = 'publish'
<?php
<?php if ( have_posts() ) : ?>
<?php while (have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
?>
@thierrypigot
thierrypigot / action.php
Created December 19, 2022 15:11
Code qui ajoute un widget supplémentaire à la zone de widgets
<?php
function add_my_widget() {
register_widget( 'My_Widget' );
}
add_action( 'widgets_init', 'add_my_widget' );
?>
@thierrypigot
thierrypigot / action.php
Created December 19, 2022 15:11
Code qui ajoute un message personnalisé à toutes les notifications
<?php
function my_notification_message( $message ) {
$message .= 'Ceci est mon message personnalisé.';
return $message;
}
add_action( 'wp_mail', 'my_notification_message' );
?>
@thierrypigot
thierrypigot / action.php
Created December 19, 2022 15:10
Code qui vérifie le rôle de l'utilisateur lorsqu'il se connecte et qui affiche un message spécifique à l'utilisateur en fonction de son rôle
<?php
function my_login_message() {
global $current_user;
$role = $current_user->roles[0];
if ( $role == 'administrator' ) {
echo 'Bienvenue administrateur!';
} else {
echo 'Bienvenue à vous!';
}
}
@thierrypigot
thierrypigot / action.php
Created December 19, 2022 15:09
Ajoute un script supplémentaire à toutes les pages
<?php
function add_my_script() {
wp_enqueue_script( 'my-script', get_stylesheet_directory_uri() . '/script.js' );
}
add_action( 'wp_head', 'add_my_script' );
?>
@thierrypigot
thierrypigot / filtre.php
Created December 19, 2022 15:05
Ajouter ou modifier des variables lorsqu'elles sont passées à un script WordPress
<?php
function mon_filtre_personnalisé($valeur) {
// Modifier la valeur de la variable
return $valeur;
}
add_filter('nom_variable', 'mon_filtre_personnalisé');
?>
@thierrypigot
thierrypigot / filtre.php
Created December 19, 2022 15:05
Ajouter ou modifier des éléments dans le code HTML généré par WordPress
<?php
function ajout_attribut_lien($text) {
$text = preg_replace('/(&lt;a.*?)(&gt;)/','$1 target="_blank"$2',$text);
return $text;
}
add_filter('the_content','ajout_attribut_lien');
?>