This commit is contained in:
2024-11-20 10:44:03 +00:00
parent 09e8f4819f
commit 8271edf976

View File

@ -0,0 +1,39 @@
// Example of field stored in wp_jet_post_types (even if it's a CCT)
// a:1:{i:0;a:12:{s:5:"title";s:9:"mygallery";s:4:"name";s:9:"mygallery";s:11:"object_type";s:5:"field";s:5:"width";s:4:"100%";s:7:"options";a:0:{}s:15:"repeater-fields";a:0:{}s:4:"type";s:7:"gallery";s:9:"collapsed";b:0;s:2:"id";i:3591;s:8:"isNested";b:0;s:14:"options_source";s:6:"manual";s:12:"value_format";s:2:"id";}}
// Function to check for the gallery field in JetEngine post types
function check_jetengine_gallery_field() {
// Make sure the JetEngine plugin is loaded
if ( class_exists( 'Jet_Engine' ) ) {
global $wpdb;
// Query the wp_jet_post_types table
$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}jet_post_types", ARRAY_A );
// Loop through each row in the table
foreach ( $results as $row ) {
// Get the 'meta_fields' column which contains the serialized data
$meta_fields = maybe_unserialize( $row['meta_fields'] );
// Check if 'meta_fields' is an array (in case it's serialized)
if ( is_array( $meta_fields ) ) {
// Loop through the meta_fields to check if any contain a serialized field with 'type' => 'gallery'
foreach ( $meta_fields as $field ) {
// Check if the 'type' of the field is 'gallery'
if ( isset( $field['type'] ) && $field['type'] === 'gallery' ) {
// Log to the debug log (safe method)
/// PUT CODE HERE
echo "I have one!!!"; // For debugging
}
}
}
}
} else {
// Log if JetEngine plugin is not active
error_log( 'JetEngine plugin is not active.' );
}
}
// Hook into WordPress 'wp' action, which occurs after WordPress has finished loading
add_action( 'wp', 'check_jetengine_gallery_field' );