Skip to content

Instantly share code, notes, and snippets.

View thierrypigot's full-sized avatar

Thierry Pigot thierrypigot

View GitHub Profile
@thierrypigot
thierrypigot / waw-create-admin-user.php
Created October 19, 2021 09:53
Add a WordPress Admin User to the Database via PHP
<?php
add_action( 'init', function () {
$username = 'wearewp';
$password = 'password';
$email_address = '[email protected]';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
@thierrypigot
thierrypigot / wp-endpoint-get-sites.php
Created September 17, 2021 07:02
WordPress Rest API - Ajout endpoint liste de tous les sites d'un multisites
<?php
function wearewp_api_custom_route_get_sites() {
$args = array(
'public' => 1, // I only want the sites marked Public
'archived' => 0,
'mature' => 0,
'spam' => 0,
'deleted' => 0,
);
@thierrypigot
thierrypigot / functions.php
Created May 31, 2021 09:34
Redirect uploads folder when import single website in WordPress multisite
<?php
/**
* 404
*/
function wearewp_redirect_404_uploads() {
if ( is_404() && preg_match( '/uploads/i', $_SERVER["REQUEST_URI"] ) ) {
$blog_id = get_current_blog_id();
$new_url = home_url( str_replace( '/uploads/', '/uploads/sites/'. $blog_id .'/', $_SERVER["REQUEST_URI"] ) );
wp_safe_redirect( $new_url, 301 );
exit;
<?php
class Eric{
function __construct(){
add_action( 'init', [ $this, 'remove_category_for_posts' ] );
add_action( 'init', [ $this, 'add_category_for_pages' ] );
add_filter( 'register_taxonomy_args', [ $this, 'rename_category' ], 10, 3);
add_action( 'pre_get_posts', [ $this, 'category_archives' ] );
}
/* Grille avec media queries */
.grids {
max-width: 1140px;
margin: 0 auto;
display: grid;
grid-gap: 0 1rem;
grid-template-columns: repeat(1, 1fr);
}
@thierrypigot
thierrypigot / demo.html
Created January 12, 2021 16:10
Automatically Adjust iFrame Height According to its Contents Using JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Auto Adjust iFrame Height Based on Content</title>
<style>
iframe{
width: 100%;
border: 2px solid #ccc;
}
@thierrypigot
thierrypigot / antispambot-mailto-menuLink.php
Created July 31, 2020 17:09
WordPress : auto add Antispambot on mailto email address inside menu links
INITIALISATION
==============
load wp-config.php
set up default constants
load wp-content/advanced-cache.php if it exists
load wp-content/db.php if it exists
connect to mysql, select db
load object cache (object-cache.php if it exists, or wp-include/cache.php if not)
load wp-content/sunrise.php if it exists (multisite only)
@thierrypigot
thierrypigot / wearewp-cpt-glance.php
Created September 16, 2019 10:38
Custom post type counts in 'Right now' Dashboard widget
<?php
/*
Plugin Name: Custom post type counts
Description: Custom post type counts in 'Right now' Dashboard widget
Plugin URI: https://www.wearewp.pro
Version: 1.0
Author: WeAre[WP]
Author URI: https://www.wearewp.pro
*/
@thierrypigot
thierrypigot / wpml-config.xml
Created August 23, 2019 09:54
Beaver Builder theme cutomizer translation with Polylang and WPML
<wpml-config>
<admin-texts>
<key name="theme_mods_{THEMENAME}">
<key name="fl-topbar-col1-text" />
<key name="fl-logo-image-retina" />
<key name="fl-logo-image" />
</key>
</admin-texts>
</wpml-config>