Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Created October 7, 2022 12:10
Show Gist options
  • Save Crocoblock/4d3c3c77f741be82306b3e4103aa16e4 to your computer and use it in GitHub Desktop.
Save Crocoblock/4d3c3c77f741be82306b3e4103aa16e4 to your computer and use it in GitHub Desktop.
Add new Source to JetEngine Dynamic Field
<?php
class Dynamic_Filed_Source_Maybe_Unserialize {
public function __construct() {
add_filter( 'jet-engine/listings/dynamic-field/field-value', array( $this, 'process_value' ), 0, 2 );
add_filter( 'jet-engine/listings/data/sources', array( $this, 'add_source' ) );
}
public function process_value( $value, $settings ) {
$source = $settings['dynamic_field_source'] ?? '';
if ( $source === 'maybe_unserialize' ) {
$object_prop = $settings['dynamic_field_post_meta_custom'] ?? '';
$object_context = $settings['object_context'] ?? '';
$value = jet_engine()->listings->data->get_prop(
$object_prop,
jet_engine()->listings->data->get_object_by_context( $object_context )
);
$value = maybe_unserialize( $value );
}
return $value;
}
public function add_source( $sources ) {
$sources['maybe_unserialize'] = 'Maybe unserialize object property';
return $sources;
}
}
new Dynamic_Filed_Source_Maybe_Unserialize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment