Skip to content

Instantly share code, notes, and snippets.

@LaxusCroco
LaxusCroco / inserted_cct_id.php
Last active June 22, 2024 22:05
Inserted CCT ID option for JetFormBuilder forms
<?php
/**
* Pay attention!
* The 'main_cct' part must be replaced with the slug of the CCT from your website.
*/
add_action( 'jet-engine/custom-content-types/created-item/main_cct', function ( $item, $item_id, $item_handler ) {
jet_form_builder()->form_handler->action_handler->request_data['inserted_cct_id'] = $item_id;
}, 10, 3 );
@LaxusCroco
LaxusCroco / items_with_relation.php
Last active April 7, 2023 07:19
Items with Relation macro
<?php
add_action( 'jet-engine/register-macros', function(){
class Items_With_Relation extends \Jet_Engine_Base_Macros {
public function macros_tag() {
return 'items_with_relation';
}
@LaxusCroco
LaxusCroco / add_google_tag_manager_to_jtc.php
Created April 7, 2023 07:27
Add Google Tag Manager to JetThemeCore
<?php
/**
* Add Google Tag Manager code for the <head> tag.
*/
function custom_add_gtm_code() {
?>
<!-- Add your GTM code snippet below this line -->
<?php
@LaxusCroco
LaxusCroco / let-guests-upload-images-to-media-library.php
Last active May 10, 2023 06:50
Let guests upload images to Media Library in JFB. Add the 'allow-insert-attachments' custom class to the Media field
<?php
add_action(
'jet-form-builder/media-field/before-upload',
/**
* @var \Jet_Form_Builder\Request\Fields\Media_Field_Parser $parser
*/
function ( $parser ) {
$class_name = $parser->get_context()->get_class_name();
@LaxusCroco
LaxusCroco / jsf-inverse-meta-filter.php
Created May 12, 2023 15:41
JSF Filter posts that do not have any of the checked values
<?php
class JSF_Inverse_Meta_Filter {
public function __construct() {
add_filter( 'jet-smart-filters/query/final-query', array( $this, 'change_query' ) );
}
public function change_query( $query ) {
@LaxusCroco
LaxusCroco / jet_engine_custom_cb_download_button.php
Last active July 17, 2023 13:39
JetEngine CPT admin callback download button for Media meta field (supports all value types)
<?php
add_filter( 'jet-engine/post-type/predifined-columns-cb-for-js', function( $callbacks ) {
$callbacks['jet_engine_custom_cb_download_button'] = array(
'description' => 'Download media file',
'args' => array(
'media' => array(
'label' => __( 'Set field', 'jet-engine' ),
'description' => __( 'Meta field to get media from', 'jet-engine' ),
@LaxusCroco
LaxusCroco / queried_user_roles.php
Last active November 24, 2023 00:52
Adds the macro %queried_user_roles%. The macro returns a list of user roles (lowercase) separated with commas
<?php
add_action( 'jet-engine/register-macros', function(){
class Queried_User_Roles extends \Jet_Engine_Base_Macros {
public function macros_tag() {
return 'queried_user_roles';
@LaxusCroco
LaxusCroco / get_post_type_name.php
Last active August 14, 2023 20:03
Shortcode 'get_post_type_name' to get post type name/slug on single post pages and inside post listings. Accepts the parameter 'display' with 2 values = "name" and "slug". "name" returns CPT name, "slug" returns CPT slug. Example: [get_post_type_name display="name"]
<?php
add_shortcode( 'get_post_type_name', 'get_post_type_name' );
function get_post_type_name( $args ) {
$display = $args['display'];
if ( ! $display ) {
return 'No data found';
@LaxusCroco
LaxusCroco / jec_repeater_callback.php
Last active June 22, 2024 22:04
Adds a callback for Dynamic Field "Get value from repeater field". It allows getting the value from the specified sub-field and row number of the repeater on the single post page and in listings.
add_action( 'jet-engine/callbacks/register', function( $callbacks ) {
$args = array(
'repeater_name' => array(
'label' => 'Repeater Field key',
'type' => 'text',
),
'sub_field_name' => array(
'label' => 'Sub-field name',
'type' => 'text',
@LaxusCroco
LaxusCroco / average_value_for_calculated.php
Last active September 13, 2023 18:49
Additional callback 'average_value' for the Calculated Callback addon. Returns the average value of all specified post meta fields (default and additional fields)
<?php
add_filter( 'jet-engine-calculated-callback/config', function( $callbacks = array() ) {
$callbacks['average_value'] = function( $field_value, $additional ) {
if ( empty( $additional ) ) {
return 'Please set additional meta fields names to calculate';
}