Gists

by mgibbs189 - 1 month ago

<?php

// Add to your (child) theme's functions.php
// Change "audio-mp3" to your layout builder's item name (which defaults to "el-XXXXX")

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'audio-mp3' == $item['settings']['name'] && ! empty( $value ) ) {
		ob_start();
?>
 <audio controls>
  <source src="<?php echo $value; ?>" type="audio/mpeg">
  Your browser does not support the audio element.
</audio> 
<?php
		$value = ob_get_clean();
    }
    return $value;
}, 10, 2 );

by mgibbs189 - 3 months 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 );

by mgibbs189 - 4 months 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 );

by mgibbs189 - 4 months 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 );

by mgibbs189 - 7 months 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 );
by djrmom - 7 months ago

<?php
/** shorten text to a specified length and add ellipses
 ** may need adjusting if you need to support multi-byte characers
 ** https://www.php.net/manual/en/function.mb-substr.php
 ** https://www.php.net/manual/en/function.mb-strlen.php
 **/
add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'el-ymud8n' == $item['settings']['name'] ) {
        if ( strlen( $value ) > 50 )
           $value = substr( $value, 0, 50 ) . " &hellip";
    }
    return $value;
}, 10, 2 );
by mgibbs189 - 9 months 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 );
by mgibbs189 - 9 months ago

<?php

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'phone-colors' == $item['settings']['name'] ) {
        if ( is_array( $value ) ) {
        	$temp = '<style>.color-square { display: inline-block; width: 20px; height: 20px; border: 1px solid #000; border-radius: 50%; margin-right:5px; }</style>';
        	$value = wp_list_pluck( $value, 'color' );
        	foreach ( $value as $val ) {
        		$temp .= '<div class="color-square" style="background-color:' . $val . '"></div>';
        	}
        	$value = $temp;
        }
    }
    return $value;
}, 10, 2 );

by mgibbs189 - 10 months ago

<?php

// Add the following into the custom-hooks.php file

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    global $post;

    if ( 'attachment' == $item['settings']['name'] ) {
        $value = wp_get_attachment_image( $post->ID );
    }
    return $value;
}, 10, 2 );
by mgibbs189 - 1 year ago

<?php

// Add the following to custom-hooks.php or into your (child) theme's functions.php

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'add-to-cart' == $item['settings']['name'] ) {
        global $post;
        $value = do_shortcode( '[add_to_cart id="' . $post->ID . '"]' );
    }
    return $value;
}, 10, 2 );