Skip to content

Instantly share code, notes, and snippets.

View lelandf's full-sized avatar

Leland Fiegel lelandf

View GitHub Profile
@lelandf
lelandf / snippet.php
Created September 13, 2021 22:01
Change "View Event Website" label in The Events Calendar
<?php
add_filter( 'tribe_get_event_website_link_label', function() {
return "Change website link label here";
}, 11 );
@lelandf
lelandf / snippet.php
Created September 13, 2021 20:16
Sample of outputting tickets additional fields elsewhere in theme
<?php
// Assuming 75 is the WordPress post ID
// Assuming 80 is the ticket ID
add_action( 'tribe_events_single_meta_details_section_end', function() {
if ( is_single( 75 ) ) {
$url_in_person = tribe_ext_tickets_additional_fields_get_meta( 80, 'url_in_person' );
$url_virtual = tribe_ext_tickets_additional_fields_get_meta( 80, 'url_virtual' );
echo '<dd class="url-in-person"><a href="' . esc_url( $url_in_person ) . '" target="_self" rel="external">In-Person Event Link</a>';
@lelandf
lelandf / snippet.php
Created September 9, 2021 18:48
Remove organizer phone numbers from TEC REST API
<?php
add_filter( 'tribe_rest_organizer_data', function( $data ) {
if ( isset( $data["phone"] ) ) {
unset( $data["phone"] );
}
if ( isset( $data["json_ld"]->telephone ) ) {
unset( $data["json_ld"]->telephone );
}
@lelandf
lelandf / snippet.php
Created August 19, 2021 16:21
Add custom field support to LearnDash post types
// https://developer.wordpress.org/reference/functions/add_post_type_support/
add_action( 'init', 'lelandf_custom_fields_support_learndash' );
function lelandf_custom_fields_support_learndash() {
$post_types = [
'sfwd-courses',
'sfwd-lessons',
'sfwd-topic',
];
@lelandf
lelandf / gist:6bed3475fc8d9a5e86f33773d7ed5c5b
Last active July 13, 2021 17:04
learndash_courseinfo filter example
add_filter( 'learndash_courseinfo', function( $return, $shortcode_atts ) {
if ( 'completed_on' === $shortcode_atts['show'] ) {
$time_string = learndash_user_get_course_completed_date( $shortcode_atts['user_id'], $shortcode_atts['course_id'] );
return date( $shortcode_atts['format'], $time_string );;
}
return $return;
}, 10, 2 );
@lelandf
lelandf / snippet.php
Created February 13, 2021 16:34
Remove WordPress body class
add_filter( 'body_class', 'leland_remove_tag_body_class' );
function leland_remove_tag_body_class( $classes ) {
$class_to_remove = 'tag';
$remove = array_search( $class_to_remove, $classes );
if ( $remove ) {
unset( $classes[$remove] );
}
@lelandf
lelandf / leland_learndash_obscure_license_key.php
Last active August 25, 2021 22:28
obscure LearnDash license key (no jQuery)
<?php
/*
* Snippet provided as-is with no warranty and no support.
* Not an ironclad way of preventing license key exposure. Note word "obscure."
* Test on staging/development environment to ensure needs are met prior to applying to production
* Inspired by https://gist.github.com/rali14/3407a1b3efe149cfa3f17caff8743eda
*/
function leland_learndash_obscure_license_key() {
?>
@lelandf
lelandf / themetry_woocommerce_spatial_search_fix.php
Last active July 31, 2020 19:11
Fix search in Spatial theme when Woo products are present
add_filter( 'post_class', 'themetry_woocommerce_spatial_search_fix' );
function themetry_woocommerce_spatial_search_fix( $classes ) {
// Check if we are on a search results page, and check if post is a Woo product
if ( is_search() && in_array( 'type-product', $classes, true ) ) {
$classes[] = 'hentry';
}
// Return the array
return $classes;
}
add_action( 'learndash_lesson_completed', function( $lesson_data ) {
error_log( 'course id: ' . $lesson_data["course"]->ID );
error_log( 'course title: ' . $lesson_data["course"]->post_title );
error_log( 'lesson id: ' . $lesson_data["lesson"]->ID );
error_log( 'lesson title: ' . $lesson_data["lesson"]->post_title );
} );
function leland_add_excerpt_support_for_learndash_post_types() {
add_post_type_support( 'sfwd-courses', 'excerpt' );
}
add_action( 'init', 'leland_add_excerpt_support_for_learndash_post_types' );