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 / esc-textarea.php
Last active April 15, 2019 09:44
Escape textarea by preserving returning lines.
<?php
/**
* Escape by preserving the newlines : <br />
* By applying wp_kses on a textarea
*
* @param $string
*
* @return mixed
* @author Maxime CULEA
*/
@MaximeCulea
MaximeCulea / check-acf-activation.php
Last active June 23, 2016 18:05
Require ACF activation for a custom theme.
<?php
if ( ! function_exists( 'get_field' ) ) {
add_action( 'template_redirect', 'template_redirect_warning_missing_acf', 0 );
function template_redirect_warning_missing_acf() {
wp_die( sprintf( 'This theme can\'t work without ACF plugin. <a href="%s">Please login to admin</a>, and activate it !', wp_login_url() ) );
}
}
@MaximeCulea
MaximeCulea / get-the-excerpt.php
Created June 23, 2016 18:20
Get the excerpt.
<?php
/**
* Get the given post_id excerpt
* @param $post_id
*
* @return string
* @author Maxime CULEA
*/
public static function get_the_excerpt( $post_id ) {
$post = get_post( $post_id );
@MaximeCulea
MaximeCulea / generate-tiny-url.php
Created June 23, 2016 18:23
Handle to generate a tiny url with tinyurl.com api.
<?php
/**
* Generate tiny url
*
* @author Maxime Culea
*
* @param string $post_id
*
* @return string
*/
<?php class BEA_ACF_Customizer_Plugin {
/**
* Register hooks
*/
public function __construct() {
add_filter( 'acf/fields/relationship/query/name=space_port_page', array( __CLASS__, 'space_port_page' ), 10, 3 );
add_filter( 'acf/fields/relationship/query/name=timeline_page', array( __CLASS__, 'timeline_page' ), 10, 3 );
}
@MaximeCulea
MaximeCulea / allow-users-to-edit-their-comments.php
Last active September 6, 2017 09:17
Allow users to edit their own comments through REST API.
<?php
add_filter( 'user_has_cap', 'bea_add_edit_comment', 10, 4 );
/**
* Allow users to edit their own comments
*
* @param array $allcaps An array of all the user's capabilities.
* @param array $caps Actual capabilities for meta capability.
* @param array $args Optional parameters passed to has_cap(), typically object ID.
* @param \WP_User $user The user object.
*
@MaximeCulea
MaximeCulea / bea-prefix-pages-slug.php
Last active September 6, 2017 09:10
Prefix page's slug like "/page/{slug}"
<?php
/**
* Change post type single slug
*/
add_filter( 'register_post_type_args', 'bea_edit_page', 20, 2 );
function bea_edit_page( $args, $post_type ) {
if ( 'page' !== $post_type ) {
return $args;
}
@MaximeCulea
MaximeCulea / git-clean-all-po-mo-backup
Last active April 19, 2024 09:36
Easily delete translations backups and json.
/**
* Easily delete locotranslate backup po/mo, while originals are gitted.
* No need to keep them.
*
* @author Maxime CULEA
*/
find ./ -type f -name "*.po~" -exec git clean -df {} +
find ./ -type f -name "*.mo~" -exec git clean -df {} +
find ./ -type f -name "*.pot~" -exec git clean -df {} +
find ./ -type f -name "*.json" -exec rm -rf {} +
@MaximeCulea
MaximeCulea / install-all-languages.sh
Created March 16, 2017 22:49 — forked from johnbillion/install-all-languages.sh
Install all available languages on a WordPress site with WP-CLI
wp core language list --field=language | xargs -n 1 wp core language install
@MaximeCulea
MaximeCulea / i18n-acf.php
Last active September 6, 2017 09:09
i18n ACF
<?php
/**
* Load the theme textdomain
*
* @author Maxime CULEA
*/
public static function mc_load_theme_textdomain() {
load_theme_textdomain( self::textdomain, get_template_directory() . '/languages' );
}
add_filter( 'acf/settings/export_textdomain', 'mc_load_theme_textdomain' );