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 / 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 / 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

Installation

To install, you need to have the WordPress i18n library on your computer. Check it out using SVN:

sudo svn co http://i18n.svn.wordpress.org/tools/trunk/ /usr/lib/wpi18n

You don't have to put the library in /usr/lib/wpi18n, but if you don't put it there, make sure to set the $WP_I18N_LIB environment variable in your .bashrc or .bash_profile file (with no trailing slash):

export WP_I18N_LIB="/path/to/i18n/lib"

@MaximeCulea
MaximeCulea / wp-media-api-not-in-collection.php
Last active September 6, 2017 09:09
WP Media API - not in collection case
<?php
/**
* Here the element is an input with the media ID that we hide to keep the value for POST
* But we still want an other display, so add html after
* @author Maxime CULEA
*/
function transform_qrcode_p2p_meta(element) {
element.hide();
/**
@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' );
@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 / 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.
*