Gists

7 months ago
<?php

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'website-link' == $item['settings']['name'] ) { // adjust website-link to name of your layout field https://d.pr/i/gL3rjA
        if ( !empty( $value ) ) {
	    	$value = '<a href="' . esc_url( $value ) . '">website</a>';
        } else {
            $value = '';
        }
    }
    return $value;
}, 10, 2 );
2 weeks ago
<?php
/** allows string translation from pll_register_string in layout builder **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'my-item' == $item['settings']['name'] ) {
        $current = ( !empty( FWP()->facet->http_params['lang'] ) ) ? FWP()->facet->http_params['lang'] : pll_current_language();
    	$value = pll_translate_string( 'Read More', $current );
    }
    return $value;
}, 10, 2 );
5 months ago
<?php
/** convert time sources for wp recipe manager to hour / min values **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( preg_match( '/wprm\/([a-zA-Z]+)_time/', $item['source'], $matches ) ) {

		if ( !empty( $matches ) ) {
			$type = $matches[1];
		} else {
			return $value;
		}		
        
		$recipe_id = get_the_ID();

		if ( 'post' == get_post_type( get_the_ID() ) ) {
			$recipe_ids = WPRM_Recipe_Manager::get_recipe_ids_from_post( get_the_ID() );
			if ( !empty( $recipe_ids ) ) {
				$recipe_id = array_shift( $recipe_ids );
			}
			
		}

		if ( 0 < $recipe_id) {
			return do_shortcode( '[wprm-recipe-time type="' . $type . '" id=" ' . $recipe_id . '"]' );
		}
		
    }
    return $value;
}, 10, 2 );
11 months ago
<?php
/**
 ** for creating custom image sizes
 ** https://developer.wordpress.org/reference/functions/add_image_size/
 **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
	if ( 'my-image' == $item['settings']['name'] && !empty( $value ) ) { // change 'my-image' to the unique name of your field
		$image = get_field('acf_image_field'); // change 'acf_image_field' to the name of your acf field
			if ( $image ) $value = wp_get_attachment_image( $image, 'thumbnail' ); // 'thumbnail' can be changed to other image sizes you have available
		}
	return $value;
}, 10, 2 );
1 year ago
<?php

/** use do_shortcode on all layout builder items
 ** it is preferrable to target specific items
 ** as in https://facetwp.com/documentation/developers/output/facetwp_builder_item_value/
 ** if possible
 **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    $value = do_shortcode( $value ); 
    return $value;
}, 10, 2 );
2 years ago
<?php

// Insert the following code into your (child) theme's functions.php

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
	if ( 'personal-photo' == $item['settings']['name'] && !empty( $value ) ) {
		$value = wp_get_attachment_image( $value, 'full' ); // 'full' can be changed to other image sizes
	}
	return $value;
}, 10, 2 );
2 years ago
<?php

/**
 * This pulls the avatar (profile photo) from the "User Profile Picture" plugin
 * Add a layout builder item (named "avatar") and using the data source of "User ID"
 */
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'avatar' == $item['settings']['name'] ) {
        $value = get_avatar( $value );
    }
    return $value;
}, 10, 2 );
2 years ago
<?php

/**
 * Add to your (child) theme's functions.php
 *
 * We've added a layout builder item (named "email-md5"), based on the "User Email" field, and set to Hidden
 * We've also added a new HTML item with the following content:
 *
 * <img src="https://www.gravatar.com/avatar/{{ email-md5 }}?s=200" />
 *
 * This generates the user's profile image (based on Gravatar)
 */
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'email-md5' == $item['settings']['name'] ) {
        $value = md5( $value );
    }
    return $value;
}, 10, 2 );
2 years ago
<?php

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'el-z9v5wp' == $item['settings']['name'] ) {
        $shortcode = '[awts-total-sales product_id="' . $value . '" include_setting="true"]';
        $value = do_shortcode( $shortcode );
    }
    return $value;
}, 10, 2 );
2 years ago
<?php

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'actu-date' == $item['settings']['name'] ) {
        $find = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Opt', 'Nov', 'Dec' ];
        $replace = [ 'janv', 'févr', 'mars', 'avril', 'mai', 'juin', 'juil', 'août', 'sept', 'oct', 'nov', 'déc' ];
        return str_replace( $find, $replace, $value );
    }
    return $value;
}, 10, 2 );