Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save nextab/fbb24e017c868eef6d9809cacc9d9560 to your computer and use it in GitHub Desktop.

Select an option

Save nextab/fbb24e017c868eef6d9809cacc9d9560 to your computer and use it in GitHub Desktop.
#region Macro for JetEngine that looks up CCT values
/* This macro allows you to look up a CCT value from the connected CPT. Every custom content type that's connected to a CPT in JetEngine has a data column "cct_single_post_id" in which it saves the ID of the corresponding custom post type. Knowing that, you can access all the CCT keys with a custom lookup function and create a macro that wraps it and makes it relatively easy to use
*
* @param $prop_key - the CCT key you want to look up - defaults to "zmmt_email"
* @param $lookup_column - the column in the CCT table that contains the ID of the corresponding CPT - defaults to "cct_single_post_id"
* @param $table - the CCT table name - defaults to "zmmt_contacts"
*
* If you want to look up the field "zmmt_email" for a custom post type "contact", all you need to use is %get_cct_value% thanks to the defaults
* If you wanted to look up the field "zmmt_phone" for a custom post type "contact", you'd use %get_cct_value|zmmt_phone|cct_single_post_id|zmmt_contacts% or in short: %get_cct_value|zmmt_phone%
*
* Note!
* Register macros on jet-engine/register-macros action only,
* as the base macro class \Jet_Engine_Base_Macros is not available before that action;
* after it - all macros are registered already
*/
add_action( 'jet-engine/register-macros', function(){
class Get_CCT_Value extends \Jet_Engine_Base_Macros {
/**
* Macros tag - this macro will look like %get_cct_value|key|needle|table% if typed manually
*/
public function macros_tag() {
return 'get_cct_value';
}
/**
* Macros name in UI
*/
public function macros_name() {
return 'Get CCT value';
}
/**
* Macros arguments - see this https://developers.elementor.com/docs/controls/regular-control/ for reference
* An empty array may be returned if the macro has no arguments
*/
public function macros_args() {
return array(
'prop_key' => array(
'label' => 'Key',
'type' => 'text',
'default' => 'zmmt_email',
),
'lookup_column' => array(
'label' => 'Lookup Column',
'type' => 'text',
'default' => 'cct_single_post_id',
),
'table' => array(
'label' => 'Table',
'type' => 'text',
'default' => 'zmmt_contacts',
),
);
}
/**
* Macros callback - gets existing property from the current logged in user
*/
public function macros_callback( $args = array() ) {
$prop_key = ! empty( $args['prop_key'] ) ? $args['prop_key'] : 'zmmt_email';
$lookup_column = ! empty( $args['lookup_column'] ) ? $args['lookup_column'] : 'cct_single_post_id';
$table = ! empty( $args['table'] ) ? $args['table'] : 'zmmt_contacts';
$id = get_the_ID();
return get_jet_field($prop_key, $id, $lookup_column, $table);
}
}
/**
* Create an instance of Get_CCT_Key to add get_cct_key macro
* of course you may create a separate file with the class, include it instead of declaring the class right in the action,
* and then create an instance of it
*/
new Get_CCT_Value();
} );
#endregion Macro for JetEngine that looks up CCT values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment