Skip to content

Instantly share code, notes, and snippets.

View Crocoblock's full-sized avatar

Crocoblock Crocoblock

View GitHub Profile
@Crocoblock
Crocoblock / include-class.php
Last active July 11, 2022 13:27 — forked from MjHead/include-class.php
JetEngine. Example of custom macros registration based on Jet_Engine_Base_Macros class
<?php
/**
* Note! Always include mcros file only on 'jet-engine/register-macros' hook - before base class is not avaialable,
* after - all macros already registered and you can't insert a new one.
*/
add_action( 'jet-engine/register-macros', function() {
require_once get_theme_file_path( 'macros.php' );
new My_JE_Macros();
} );
@Crocoblock
Crocoblock / macro-example.php
Last active June 22, 2024 20:42
Add custom macro for JetEngine. Example - get the current user property, such as ID, user_email, etc.
<?php
/**
* 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(){
@Crocoblock
Crocoblock / get-meta.php
Last active February 19, 2024 09:11
Get current JetEngine listing object meta value ( somewhat similar to ACF get_field() )
<?php
//You may just use get_post_meta() to get post/term/user meta
//However, in Listing Grid, you may use get_meta() method for convenience
$value = jet_engine()->listings->data->get_meta( $meta_key, $object );
/**
* Get object meta value. Works for Posts, Terms, Users, Comments
* $object defaults to null, then the value will be retrieved from the current listing object
@Crocoblock
Crocoblock / custom-column-callback.php
Last active March 3, 2024 17:54
Add custom admin column callback to post type
<?php
/**
* Functions may be used as a custom post type column callback
*/
/**
* If the function name does not contain 'jet_engine_custom_cb' prefix,
* the callback takes only two arguments: column name and post ID
* You may use such callbacks if you do not need to specify any arguments
* Example: show post author in a column
@Crocoblock
Crocoblock / rest-api-args.php
Created July 12, 2022 20:03
JetEngine REST API modify request arguments (e. g. when you need to set more than one header for the request)
<?php
/**
* Some APIs required more than one header to be sent,
* or they need to give out some token first, and only after that to get the actual info
* Here we show only example with setting additional header,
* but you may run some code to do what you need in a specific case
*
* Here we have an API, which requires setting not pnly Authorization token (which may be set in REST API endpoiny options)
* but also a header with the version - that was a real-life example from our user
@Crocoblock
Crocoblock / custom-dynamic-field-callback.php
Last active February 8, 2024 09:57
JetEngine Dynamic Field add custom callback (for example, add callback that partially masks an email with * or other symbols)
<?php
//filter to add a callback to the list
add_filter( 'jet-engine/listings/allowed-callbacks', 'add_custom_dynamic_field_callbacks' );
//filter to specify which arguments will the callback have
add_filter( 'jet-engine/listing/dynamic-field/callback-args', 'add_custom_dynamic_field_callbacks_args', 0, 3 );
//filter to add controls
//controls arguments are set as in Elementor controls
@Crocoblock
Crocoblock / purchased-products-macro.php
Last active March 18, 2024 16:41
JetEngine Get purchased Woocommerce products macro
<?php
add_action( 'jet-engine/register-macros', function() {
/**
* Return purchased products.
*/
class Purchased_Products_Macro extends \Jet_Engine_Base_Macros {
public function macros_tag() {
@Crocoblock
Crocoblock / custom-profile-builder-rewrite.php
Last active July 22, 2022 06:47
JetEngine. Profile Builder. Allow to add single user page without base page slug in the URL. Final URL format will be - site.url/<username|id|nicename>/<profile-subpage>/
<?php
/**
* You need to set up single user base page in the settings anyway, because it need to grab a content.
* The only limitation - will not work without subpage slug in the URL.
*/
// add rewrite rules
add_filter( 'jet-engine/profile-builder/rewrite-rules', function( $rules, $manager ) {
$pages = \Jet_Engine\Modules\Profile_Builder\Module::instance()->settings->get_pages();
@Crocoblock
Crocoblock / format-date-string-macro.php
Last active October 13, 2023 01:09
JetEngine Format date string macro
<?php
add_action( 'jet-engine/register-macros', function() {
/**
* Format date string.
*/
class Format_Date_String extends \Jet_Engine_Base_Macros {
public function macros_tag() {
@Crocoblock
Crocoblock / booking-calendar-api-doc.md
Last active April 12, 2024 12:12
JetBooking. JavaScript API documentation

Documentation for JetBooking calendar JS API

Filter jet-booking.input.config

Allows to change initial set up of booking calendar. Usage example:

window.JetPlugins.hooks.addFilter( "jet-booking.input.config", "jetBooking", ( config ) => {

	const validateDay = config.beforeShowDay;