Skip to content

Instantly share code, notes, and snippets.

@MjHead
Last active December 15, 2023 21:49
Show Gist options
  • Save MjHead/8c13c4758cb6df487dd25ecb755c9e2c to your computer and use it in GitHub Desktop.
Save MjHead/8c13c4758cb6df487dd25ecb755c9e2c to your computer and use it in GitHub Desktop.
Jet Engine, Dynamic Repeater: add new filter to allowed repeater filters
<?php
add_filter( 'jet-engine/listings/filters-list', 'jet_add_pdf_link_filter' );
/**
* Add 'get_pdf_link' to allowed filters list
*
* @param array $filters Registered filters
* @return array
*/
function jet_add_pdf_link_filter( $filters ) {
$filters['get_pdf_link'] = array(
'cb' => 'jet_get_pdf_link_by_id',
'args' => false,
);
return $filters;
}
/**
* Filter callback
*
* @param int $attachment_id Attachment ID
* @return string
*/
function jet_get_pdf_link_by_id( $attachment_id ) {
return wp_get_attachment_url( $attachment_id );
}
<?php
add_filter( 'jet-engine/listings/filters-list', 'jet_add_pdf_link_filter' );
/**
* Add 'get_pdf_link' to allowed filters list
*
* @param array $filters Registered filters
* @return array
*/
function jet_add_pdf_link_filter( $filters ) {
$filters['get_pdf_link'] = array(
'cb' => 'jet_get_pdf_link_by_id',
'args' => false,
);
return $filters;
}
/**
* Filter callback
*
* @param int $attachment_id Attachment ID
* @return string
*/
function jet_get_pdf_link_by_id( $attachment_id ) {
return sprintf(
'<a href="%1$s">%2$s</a>',
wp_get_attachment_url( $attachment_id ),
basename( get_attached_file( $attachment_id ) )
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment