Skip to content

Instantly share code, notes, and snippets.

View MaximeCulea's full-sized avatar
🇨🇭
New life begining.

Maxime CULEA MaximeCulea

🇨🇭
New life begining.
View GitHub Profile
@MaximeCulea
MaximeCulea / favicons.php
Created April 30, 2020 12:30
(WIP) Easily generate the favicons for your WordPress theme.
<?php class Favicons {
/**
* The path suffix for the icons
*
* @var string
*/
private $path_suffix = '/html/src/assets/img/favicons/';
public function _init() {
@MaximeCulea
MaximeCulea / customize-wp-mail.php
Created April 30, 2020 11:16
Hooks in order to customize WordPress WP Mail headers.
<?php class MC_Customize_WP_Mail {
private $sender_mail;
private $sender_name;
private $reply_mail;
private $replay_name;
/**
* Set custom sender mail and name for all sent emails
* and add a reply to mail and name to allow people replying to your sent emails
@MaximeCulea
MaximeCulea / wp-cli-dummy-thumbnails.sh
Last active April 22, 2020 07:28
Generate and add dummy thumbnails to a wanted post type using WP CLI.
#!/bin/bash
# 1. Generate a bunch of dummy images, for that I use http://unsample.net
# 2. Upload it via sftp or whatever
# 3. Import the images into the WordPress library using the uploaded path
wp media import media-to-import/*
# 3.1 It will import the images by generating the following prompt :
@MaximeCulea
MaximeCulea / load-assets.php
Created April 8, 2020 14:50
Exemple on how load assets depending on the theme version.
<?php
/**
* This is a basic exemple on how to load assets depending on the version of the theme
* On a fresh delevery, it allows to refresh the assets on client sides
* It could have been implementeed as a class (todo)
* @author Maxime CULEA
*/
add_action( 'wp', 'mc_register_assets' );
function mc_register_assets() {
@MaximeCulea
MaximeCulea / better-gutenberg.php
Created April 3, 2020 10:09
Gutenberg tweaks
<?php
add_action( 'enqueue_block_editor_assets', 'disable_editor_fullscreen' );
function disable_editor_fullscreen() {
if ( ! is_admin() ) {
return;
}
wp_add_inline_script( 'wp-blocks', "jQuery( window ).load(function() { const isFullscreenMode = wp.data.select( 'core/edit-post' ).isFeatureActive( 'fullscreenMode' ); if ( isFullscreenMode ) { wp.data.dispatch( 'core/edit-post' ).toggleFeature( 'fullscreenMode' ); } });" );
}
@MaximeCulea
MaximeCulea / file_mod_allowed.php
Created April 3, 2020 10:05
Allow to download a lang despite DISALLOW_FILE_MODS to true
<?php
/**
* Allow to download a lang despite DISALLOW_FILE_MODS to true
* @author Maxime Culea
*/
add_filter( 'file_mod_allowed', function ( $value, $context ) {
if ( $context == 'can_install_language_pack' ) {
return true;
}
@MaximeCulea
MaximeCulea / admin-menu.php
Created February 28, 2020 17:31
Create a custom admin menu in order to attach a post type and taxonomy.
<?php class Custom_Admin_Menu {
/**
* I have an e-sport section with is related to a program and players (as post types)
* Also related to theses, we specify scenes and games (as taxonomies)
* In fine the idea is to gather all this into a single admin menu :
* E-Sport
* |-- Programs
* |-- Players
* |-- Scenes
* |-- Games
@MaximeCulea
MaximeCulea / social.php
Created February 17, 2020 10:30
Get social icon depending on the social network (for wp)
<?php
function get_social_icon( $social_url ) {
$default_icon = 'access';
if ( empty( $social_url ) ) {
return sprintf( 'icon-%s', $default_icon );
}
$parse_social = wp_parse_url( $social_url );
// Get the social's sld in order to use the corresponding icon
@MaximeCulea
MaximeCulea / template-part.php
Created February 17, 2020 08:17
Handle variables when working with template parts.
<?php class MC_Template_Part_Var {
/**
* @author Maxime Culea
* @var MC_Template_Part_Var
*/
public static $instance;
/**
* Vars to store
*
@MaximeCulea
MaximeCulea / body-class.php
Last active February 17, 2020 09:12
Ease the use of body classes into template.
<?php class MC_Body_Class {
private static $instance;
private $body_class = [];
private $delete_class = [];
private function __construct() {
self::$instance = $this;
add_filter( 'body_class', array( $this, 'body_class' ) );