Skip to content

Instantly share code, notes, and snippets.

View w-jerome's full-sized avatar
💻
coding…

Jérôme Wohlschlegel w-jerome

💻
coding…
View GitHub Profile
@w-jerome
w-jerome / excerpt.php
Last active May 24, 2019 15:24
WordPress - get post excerpt from Gutenberg
<?php
function get_excerpt($post) {
$excerpt = $post->post_excerpt;
if (empty($post->post_excerpt)) {
$_html = explode("\n", trim(strip_tags($post->post_content, '<p>')));
$_html = array_filter($_html, function($var) {
return (is_int(stripos($var, '<p'))) ? true : false;
});
$_html = array_values($_html);
if (!empty($_html)) {
@w-jerome
w-jerome / wordpress-constant.php
Created May 15, 2019 16:36
WordPress - Constant list (defined)
<?php
var_dump(get_defined_constants(true));
$user_const = array(
'WP_USE_THEMES' => true,
'ABSPATH' => '/Users/currentusername/Sites/wordpress/',
'DB_NAME' => 'wordpress',
'DB_USER' => 'root',
'DB_PASSWORD' => 'root',
'DB_HOST' => 'localhost',
@w-jerome
w-jerome / electron.js
Created April 13, 2019 18:48
Electron - Import Electron renderer with ES6 synthax
const electron = window.require('electron');
const clipboard = electron.clipboard;
const crashReporter = electron.crashReporter;
const desktopCapturer = electron.desktopCapturer;
const ipcRenderer = electron.ipcRenderer;
const nativeImage = electron.nativeImage;
const remote = electron.remote;
const screen = electron.screen;
const shell = electron.shell;
@w-jerome
w-jerome / placeholder.php
Last active September 11, 2020 09:03
PHP - Get placeholder for Lazyload
<?php
/**
* Image placeholder
*
* @param integer $width Placeholder width.
* @param integer $height Placeholder height.
* @param string $color Placeholder color.
* @return string Data ULR
*/
function get_placeholder(int $width = 0, int $height = 0, string $color = 'transparent') {
@w-jerome
w-jerome / gravity-forms-utm-field-custom.php
Last active March 22, 2022 20:57
Gravity Forms - UTM fields
<?php
// Doc : https://stackoverflow.com/questions/43009398/custom-gravity-forms-field-with-multiple-inputs
class GF_Field_UTM extends GF_Field {
public $type = 'utm';
private $fields_name = array(
'referrer',
'last_referrer',
'utm_campaign',
@w-jerome
w-jerome / .htaccess
Created February 19, 2019 09:16
Htaccess - protect domain by htpasswd
Order deny,allow
Allow from 192.168.1.1
Deny from all
Satisfy any
AuthUserFile /path/to/.htpasswd
AuthType Basic
AuthName "My restricted Area"
Require valid-user
@w-jerome
w-jerome / clean-up.php
Created January 14, 2019 19:46
WordPress - Theme Clean Up
<?php
/* ================================================================
* Clean up functions
* Remove & clean all the stuff added by wordpress
* ================================================================ */
/**
* WP Theme Clean Up
*/
if (! function_exists('wp_theme_start_cleanup')) {
@w-jerome
w-jerome / wordpress-get-image.php
Last active May 13, 2019 09:25
WordPress - get image object with all sizes
<?php
function getImage ($image_id) {
if (!$image_id) { return null; }
$base_url = get_site_url().'/wp-content/uploads/';
$sizes = get_intermediate_image_sizes();
$image = array(
'meta' => array(),
'sizes' => array(),
@w-jerome
w-jerome / date-format.js
Last active January 2, 2019 13:49
Javascript, PHP — Format date by language
function formatDateText(date_start, date_end) {
date_start = (date_start) ? new Date(date_start) : null;
date_end = (date_end) ? new Date(date_end) : null;
var date_text = '';
var lang = 'fr-FR';
if (!date_end) {
date_text = date_start.toLocaleDateString(lang, {
year: 'numeric',
@w-jerome
w-jerome / detect-is-mobile.php
Created August 27, 2018 15:02
WordPress and PHP — Detect is Mobile
function isMobile() {
if (function_exists('wp_is_mobile')) {
if (wp_is_mobile()) {
return true;
} else {
return false;
}
} else {
if (preg_match('/(android|webos|avantgo|iphone|ipad|ipod|blackberry|iemobile|bolt|boost|cricket|docomo|fone|hiptop|mini|opera mini|kitkat|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i', $_SERVER['HTTP_USER_AGENT'])) {