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 / default-add-to-any.php
Created October 16, 2017 06:58
Default Add To Any config.
<?php
/**
* Disable autodisplay after `the_content`
* @author Maxime Culea
*/
function addtoany_disable_sharing_on_my_custom_post_type() {
return true;
}
add_filter( 'addtoany_sharing_disabled', 'addtoany_disable_sharing_on_my_custom_post_type' );
@MaximeCulea
MaximeCulea / default-mlp.php
Created October 16, 2017 07:00
Default Multilingual Press config.
<?php
/**
* Deactivate almost all network options.
* @author Maxime Culea
*/
add_filter( 'pre_site_option_state_modules', function () {
return [
'class-Mlp_Cpt_Translator' => 'off',
'class-Mlp_Advanced_Translator' => 'off',
'class-Mlp_Alternative_Language_Title_Module' => 'off',
@MaximeCulea
MaximeCulea / default-pto.php
Created October 16, 2017 07:01
Default Post Types Order config.
<?php
/**
* Add default options for post type order.
* Custom cases with my post types, maybe use a filterable option.
*
* @author Maxime CULEA
*/
add_filter( 'pto/get_options', function () {
return [
'show_reorder_interfaces' => [
@MaximeCulea
MaximeCulea / back-top.js
Last active October 22, 2017 16:01
Change the back-top div's position depending on current scroll in order to not overwrite the footer.
$(window).scroll(function () {
// This is the div ( class="container-full site-info" ) not to overwrite
var footer_height = $(".container-full.site-info").outerHeight();
// This it the button margin from bottom of the window
var margin_to_footer = 3;
// Dynamicly set the fixed bottom with the margin :
// - window height - ( footer div height + footermargin )
// - just the footer margin
@MaximeCulea
MaximeCulea / date.php
Last active October 27, 2017 12:23
Sample for playing with dates.
<?php
// In one line, get the last day (date formatted in Y-m-d) of the previous current month
$last_day_of_previous_month = date(
'Y-m-d',
mktime(
0,
0,
0,
date( 'm' ) - 1,
date( 't',
@MaximeCulea
MaximeCulea / inc-menu.php
Created November 10, 2017 11:48
Dynamically add nav menus and associated menus.
<?php class BEA_Menu {
static $menu_localisations;
static $menu_names;
function __construct() {
$this->init();
add_action( 'after_setup_theme', [ $this, 'init_menu' ] );
}
@MaximeCulea
MaximeCulea / acf-wysiwyg-buttons.php
Last active November 16, 2017 11:02
Manage acf's wysiwyg buttons.
<?php
/*
* Keep in mind that it will apply on all acf's wysiwygs
* @auhtor Maxime CULEA
*/
function mc_acf_wysiwyg_buttons( $toolbars ) {
// blockquote
unset( $toolbars['Basic'][1][3] );
// strikethrough
unset( $toolbars['Basic'][1][4] );
@MaximeCulea
MaximeCulea / is-rest-request.php
Created November 24, 2017 14:43
Allow to check if doing a REST Api Request or just a simple WP_Query.
<?php
/**
* Check if is rest api or not
*
* @see : https://github.com/WP-API/WP-API/issues/926
*
* @author Maxime CULEA
*/
function mc_is_rest_api_request() {
return defined( 'REST_REQUEST' ) && REST_REQUEST;
@MaximeCulea
MaximeCulea / fix-ip-address.php
Last active November 25, 2017 15:37
Set current user IP address over proxy for HTTP servers.
<?php
/**
* Set the IP address from the current visitor
*
* Maybe to be improved :
* @see https://github.com/BoiteAWeb/secupress/blob/master/inc/functions/ip.php#L5
*
* @author Maxime CULEA
*
* @return string $ip
@MaximeCulea
MaximeCulea / rewrite-slug.php
Last active January 24, 2018 09:06
Change on the fly the permastructure for a content.
<?php namespace BEA\CPT_Section;
/*
* /!\ Warnings /!\
* - Only working with https://github.com/BeAPI/hm-rewrite class which must be loaded
* - PHP5.6+
* - The custom "Post" class is loaded as model and used, so it would break your site if you don't delete the related code
* - There is a namesapce declared, you might not use it, so simply delete it
*/