Skip to content

Instantly share code, notes, and snippets.

View MjHead's full-sized avatar

Andrew Shevchenko MjHead

  • Crocoblock
  • Ukraine
View GitHub Profile
@MjHead
MjHead / validate-cct-item.php
Created August 15, 2022 15:53
Insert new CCT item with JetFormBuilder only if similar item not exists
<?php
/**
* 1. Add action Hook before Insert/update CCT, set 'validate-cct' as hook name - https://i.imgur.com/48wcTA4.png
* 2. Replace 'tournaments' with your actual CCT slug
* 3. Replace 'name' with actual parameters to find similar items
*/
add_filter( 'jet-form-builder/custom-filter/validate-cct', function( $result, $request, $action ) {
$cct_slug = 'tournaments';
$cct = \Jet_Engine\Modules\Custom_Content_Types\Module::instance()->manager->get_content_types( $cct_slug );
<?php
namespace Jet_Engine\Query_Builder\Queries;
// put this file into jet-engine\includes\components\query-builder\queries\ and replace initial file
// this comment is actual until 3.0.3 version
abstract class Base_Query {
public $id = false;
public $name = false;
@MjHead
MjHead / base-arg.php
Last active June 3, 2022 10:18
JSF dynamic query args prototype
<?php
// Base arg class. all args must extend it
abstract class Base_Arg {
// returns main arg
abstract public function get_arg();
// returns main arg label for UI control
abstract public function get_name();
@MjHead
MjHead / jet-form-builder-custom-preset.php
Created May 27, 2022 15:39
JetFormBuilder. Use custom data as default value
<?php
add_action( 'init', function() {
// Check if need to do an API request
if ( empty( $_GET['test_api_request'] ) ) {
return;
}
// get remote data
@MjHead
MjHead / ajax-listing-url.php
Created February 2, 2022 11:21
JetEngine. Replace URL of ajax callback to get Listing items
<?php
add_filter( 'jet-engine/listings/ajax-listing-url', function( $url ) {
return esc_url( admin_url( 'admin-ajax.php' ) );
} );
@MjHead
MjHead / jet-engine-relations-update.php
Created February 2, 2022 09:27
JetEngine. Relations. Update related items
<?php
/**
* Update related item from form action/notification
*
* @param array $args [description]
* @return [type] [description]
*/
function my_update_related_items( $args = array() ) {
$relation = ! empty( $args['relation'] ) ? $args['relation'] : false;
@MjHead
MjHead / get-jet-engine-meta-fields.php
Last active June 11, 2024 15:07
JetEngine. Get registered meta fields by given context - post type, taxonomy or user
<?php
/**
* Get fields for the given context and object
* Should be called on hook 'init' with priority 11 or later
*/
// Fields for Post post type
$post_fields = jet_engine()->meta_boxes->get_fields_for_context( 'post_type', 'post' );
// Fields for Product post type
@MjHead
MjHead / jet-engine-advanced-relations.php
Last active September 12, 2024 14:27
JetEngine Relations. Add custom fields into create new item popup. Add custom columns into related item table
<?php
/**
* Adds custom fields into the insert new related item popup.
* Hook name - jet-engine/relations/types/posts/create-fields - depends on type of created item,
* for CPT it will be - jet-engine/relations/types/posts/create-fields
* for terms - jet-engine/relations/types/terms/create-fields
* for users - jet-engine/relations/types/mix/create-fields/users
*
* just replace 'jobs' in the example with your actual post type/taxonomy slug
@MjHead
MjHead / gist:ce5c649bbe725a49ecd6f623d49a1a2f
Created November 26, 2021 13:20
Add own parameters into JetEngine Listing query args
<?php
add_filter( 'jet-engine/listing/grid/posts-query-args', function( $args, $widget, $settings ) {
if ( 'custom-query' === $settings['_css_classes'] ) {
$args['meta_query'][] = array(
'relation' => 'OR',
0 => array(
'key' => 'submission-date',
@MjHead
MjHead / include-class.php
Created November 26, 2021 11:48
JetEngine. Custom macros registration with 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();
} );