$module_active = jet_engine()->modules->is_module_active( 'custom-content-types' );
$type_object is an instance of \jet-engine\includes\modules\custom-content-types\inc\factory.php
get_content_types() should be called on init with priority 12 or higher,
or at any action later than init (there are no registered CCTs before that action)
$handler is an instance of \jet-engine\includes\modules\custom-content-types\inc\item-handler.php
$cct_slug = 'test_cct';
$type_object = \Jet_Engine\Modules\Custom_Content_Types\Module::instance()->manager->get_content_types( $cct_slug );
//or:
//$type_object = jet_engine()->modules->get_module( 'custom-content-types' )->instance->manager->get_content_types( $cct_slug );
$handler = $type_object->get_item_handler();
$flag = \ARRAY_A;
$type_object->db->set_format_flag( $flag );
$item_id = 4;
$item = $type_object->db->get_item( $item_id );
$item is an associative array of CCT item fields
Get 3 items where f1 is equal to 1 and f2 LIKE 2, order by f2 DESC
$args = $type_object->prepare_query_args( array(
array(
'field' => 'f1',
'operator' => '=',
'value' => 1,
),
array(
'field' => 'f2',
'operator' => 'LIKE',
'value' => 2,
'type' => 'CHAR',
),
) );
$limit = 3;
$offset = 0;
$order = array(
array(
'orderby' => 'f2',
'order' => 'DESC',
'type' => 'CHAR',
),
);
$rel = 'AND';
$items = $type_object->db->query( $args, $limit, $offset, $order, $rel );
Returns an array of items in a format (ARRAY_A | ARRAY_N | OBJECT | OBJECT_K) set by $type_object->db->set_format_flag()
$item_id = $handler->update_item( array( 'f1' => 'test' ) );
$item_id = $handler->update_item( array( '_ID' => 1, 'f1' => 'test' ) );
update_item() method expects an associative array of CCT fields that need to be updated
If '_ID' in array is a CCT item ID, the item with that ID will be updated, if there is no ID passed - new item gets created
$cct_item_id - ID of CCT item, $redirect - whether to redirect to CCT admin page, default true
$cct_item_id = 1;
$redirect = false;
$item_id = $handler->delete_item( $cct_item_id, $redirect );
Whether the user can delete CCT item is determined by user_has_access() method
So, if you do not want to duplicate delete_item() functionality -
use 'jet-engine/custom-content-types/user-has-access' filter from \jet-engine\includes\modules\custom-content-types\inc\factory.php
to override user permissions (be sure to do this in a secure way)
or
use $handler->raw_delete_item( $item_id );
to avoid user check
See \jet-engine\includes\modules\custom-content-types\inc\item-handler.php
add_filter(
'jet-engine/custom-content-types/item-to-update',
function( $item, $fields, $item_handler ) {
//do something with $item
return $item;
},
0,
3
);
add_action(
'jet-engine/custom-content-types/update-item/' . $cct_slug,
function( $item, $prev_item, $item_handler ) {
//do something
},
0,
3
);
add_action(
'jet-engine/custom-content-types/updated-item/' . $cct_slug,
function( $item, $prev_item, $item_handler ) {
//do something
},
0,
3
);
add_action(
'jet-engine/custom-content-types/create-item/' . $cct_slug,
function( $item, $item_handler ) {
//do something
},
0,
2
);
add_action(
'jet-engine/custom-content-types/created-item/' . $cct_slug,
function( $item, $item_id, $item_handler ) {
//do something
},
0,
3
);
add_action(
'jet-engine/custom-content-types/delete-item/' . $cct_slug,
function( $item_id, $item, $item_handler ) {
//do something
},
0,
3
);