Skip to content

Instantly share code, notes, and snippets.

View taricco's full-sized avatar

taricco

  • Seattle, WA
View GitHub Profile
/*** Set ACF field default as Post ID for the modal_id field for the video and match CPTs
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function wsv_post_id_default_for_modal_id($post_id) {
// Check if we're saving a 'video' or 'match' post type
$post_type = get_post_type($post_id);
if ($post_type == 'video' || $post_type == 'match') {
// Retrieve the current value of the 'modal_id' field
$current_value = get_field('modal_id', $post_id);
// If the 'modal_id' field is empty, set it to the post ID
[presto_player custom_field="video_url" preset="7" poster="{{field.video_posterframe}}"]
https://prestoplayer.com/docs/presto-player-shortcode/
/*** Create "Event Tag" for Event CPT
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function create_event_tags_taxonomy() {
register_taxonomy(
'event_tags', // Taxonomy key
'event', // Post type name
array(
'label' => __( 'Event Tags' ),
'rewrite' => array( 'slug' => 'event-tag' ),
'hierarchical' => false, // Set to false for tags, true for categories
/*** Hide default taxonomy panels for Match CPT taxonomies
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function hide_match_taxonomy_metaboxes() {
echo '
<style type="text/css">
#custom_match-status,
.components-panel__body:has(>.css-1n451hs.e19lxcc00) {
display: none;
}
</style>
/*** Hide default taxonomy panels for Match CPT taxonomies
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function hide_match_taxonomy_metaboxes() {
$screen = get_current_screen();
// Check if the current screen is the 'match' custom post type
if ( $screen->post_type === 'match' ) {
echo '
<style type="text/css">
#custom_match-status,
/*** ACF filter to allow unsafe html in certain fields (updated for ACF 6.2.5 Security Release)
@link https://wpfieldwork.com/diving-into-acfs-latest-security-release/
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
add_filter('acf/the_field/allow_unsafe_html', function ($allowed, $atts) {
// Ensure $atts is an array and has the 'field' key
if (!is_array($atts) || !isset($atts['field'])) {
return $allowed;
}
// List of ACF field names
/*** ACF 6.2.5 Security Fix
@link https://wpfieldwork.com/diving-into-acfs-latest-security-release/
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
add_filter('acf/shortcode/allow_unsafe_html', function ($allowed, $atts) {
// Array of field names that allow unsafe HTML
$allowed_fields = [
'global_after_body_code',
'footer_code',
'global_footer_code',
'header_code',
Replace the **formid** and **fieldid**
/*** Gravity Forms - Restrict the file upload size for Guest Blog form
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
add_filter( 'gform_validation', 'validate_file_size_form_name' );
function validate_file_size_form_name( $validation_result ) {
$form = $validation_result['form'];
// Specify your target form ID