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 / get-jet-engine-gallery-images.php
Created September 26, 2019 08:37
Example how to get an array of images stored in JetEngine gallery field
@MjHead
MjHead / get-jet-engine-meta-fields.php
Last active April 6, 2024 17:55
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-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 / jet-engine-advanced-relations.php
Last active March 9, 2024 17:32
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 / init-jet-plugins-scripts.php
Created March 8, 2024 15:56
JetFormBuilder. Init JetPlugins scripts on Bricks AJAX Popup
<?php
add_action( 'wp_footer', function() {
?>
<script type="text/javascript">
document.addEventListener( 'bricks/ajax/popup/loaded', (event) => {
window.JetPlugins.init( jQuery( event.detail.popupElement ) )
});
</script>
<?php
<?php
add_filter( 'jet-form-builder/form-handler/form-data', function( $request ) {
if ( isset( $request['field_name_to_sanitize'] ) ) {
$request['field_name_to_sanitize'] = wp_strip_all_tags( $request['field_name_to_sanitize'] );
}
return $request;
} );
@MjHead
MjHead / jet-engine-cct-api.php
Last active February 28, 2024 17:16
API to interact with JetEngine CCT from directly PHP code
<?php
/**
* JetEngine CCT-related API functions to use in theme or plugin
*
* Theme usage - include get_theme_file_path( 'jet-engine-cct-api.php' );
* Plugin usage - include PLUGIN_PATH . 'path-to-file-inside-plugin/jet-engine-cct-api.php';
*/
/**
@MjHead
MjHead / options-values-in-code.php
Last active February 27, 2024 23:52
Get option values for JetEngine options pages inside the PHP code
<?php
/**
* Method 1
* Can be used for: Any storage type
*
* page-slug - replace this with your Option Page slug
* option-name - replace this with your option Name/ID
*/
$value = jet_engine()->listings->data->get_option( 'page-slug::option-name' );
@MjHead
MjHead / jet-search-rewrite.php
Last active February 5, 2024 14:48
JetSearch. Completely rewrite search query handler
<?php
add_action( 'wp_ajax_jet_ajax_search', 'my_get_search_results', 0 );
add_action( 'wp_ajax_nopriv_jet_ajax_search', 'my_get_search_results', 0 );
function my_get_search_results() {
$request = $_GET['data'];
$search_query = urldecode( $request['value'] );
$per_page = ( int ) $request['limit_query_in_result_area'];
@MjHead
MjHead / jetformbuilder-uid-to-request.php
Created February 2, 2024 11:04
JetFormBuilder. Add custom unique ID to request.
<?php
add_action( 'jet-form-builder/custom-action/iterate-submissions', function( $request, $action_handler ) {
$uid = get_option( '_my_uid', false );
if ( ! $uid ) {
$uid = 1;
}
jet_fb_context()->update_request( $uid, '_uid' );
$uid++;