Skip to content

Instantly share code, notes, and snippets.

Avatar

Thierry Pigot thierrypigot

View GitHub Profile
@thierrypigot
thierrypigot / functions.php
Created Dec 28, 2022
Custom Gutenberg bloc
View functions.php
<?php
// Register the hero block
function register_hero_block() {
register_block_type('my-plugin/hero', array(
'render_callback' => 'render_hero_block',
'attributes' => array(
'title' => array(
'type' => 'string',
'default' => '',
),
@thierrypigot
thierrypigot / functions.php
Created Dec 28, 2022
Beaver builder custom module
View functions.php
<?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 Dec 28, 2022
Plugin to add metabox, field to select a date and a shortcode to use this value in my content
View functions.php
<?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
View query.sql
SELECT *
FROM wp_posts
WHERE post_title = 'Mon titre d'article'
AND post_status = 'publié'
View boucle.php
<?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 Dec 19, 2022
Code qui ajoute un widget supplémentaire à la zone de widgets
View action.php
<?php
function add_my_widget() {
register_widget( 'My_Widget' );
}
add_action( 'widgets_init', 'add_my_widget' );
?>
@thierrypigot
thierrypigot / action.php
Created Dec 19, 2022
Code qui ajoute un message personnalisé à toutes les notifications
View action.php
<?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 Dec 19, 2022
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
View action.php
<?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 Dec 19, 2022
Ajoute un script supplémentaire à toutes les pages
View action.php
<?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 Dec 19, 2022
Ajouter ou modifier des variables lorsqu'elles sont passées à un script WordPress
View filtre.php
<?php
function mon_filtre_personnalisé($valeur) {
// Modifier la valeur de la variable
return $valeur;
}
add_filter('nom_variable', 'mon_filtre_personnalisé');
?>