Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Last active June 6, 2025 06:10
Show Gist options
  • Save Crocoblock/a43c04910b92f097fa21c6be07dbcff9 to your computer and use it in GitHub Desktop.
Save Crocoblock/a43c04910b92f097fa21c6be07dbcff9 to your computer and use it in GitHub Desktop.
JetEngine QR code macro for Dynamic Link label
<?php
class JetEngineDlUrlSaver {
private $url = '';
private static $instance = null;
private function __construct() {
add_filter( 'jet-engine/listings/dynamic-link/pre-render-link', array( $this, 'store_url' ), 100000, 4 );
}
public function get_url() {
return $this->url;
}
public function store_url( $link, $settings, $class, $render ) {
$this->url = $render->get_link_url( $settings );
return $link;
}
public static function instance() {
if ( self::$instance === null ) {
self::$instance = new self;
}
return self::$instance;
}
}
JetEngineDlUrlSaver::instance();
add_action( 'jet-engine/register-macros', function() {
if ( ! jet_engine()->modules->is_module_active( 'qr-code' ) ) {
return;
}
class QR_Code_Macro extends \Jet_Engine_Base_Macros {
public function macros_tag() {
return 'qr_code';
}
public function macros_name() {
return 'QR Code (Dynamic Link label only)';
}
public function macros_args() {
return array(
'qr_size' => array(
'label' => 'Size',
'type' => 'text',
'default' => '150',
),
);
}
public function macros_callback( $args = array() ) {
$value = JetEngineDlUrlSaver::instance()->get_url();
$size = ! empty( $args['qr_size'] ) ? $args['qr_size'] : 150;
return jet_engine_get_qr_code( $value, $size );
}
}
new QR_Code_Macro();
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment