Last active
December 15, 2023 21:49
-
-
Save MjHead/8c13c4758cb6df487dd25ecb755c9e2c to your computer and use it in GitHub Desktop.
Jet Engine, Dynamic Repeater: add new filter to allowed repeater filters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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