From 8271edf9763c25b7aaf4fc9ce549a9599fe9a3ce Mon Sep 17 00:00:00 2001 From: jrangel Date: Wed, 20 Nov 2024 10:44:03 +0000 Subject: [PATCH] Initial --- .../check_cpts_for_gallery.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 jet_engine/get_jet_fields_data/check_cpts_for_gallery.php diff --git a/jet_engine/get_jet_fields_data/check_cpts_for_gallery.php b/jet_engine/get_jet_fields_data/check_cpts_for_gallery.php new file mode 100644 index 0000000..2bfb4c7 --- /dev/null +++ b/jet_engine/get_jet_fields_data/check_cpts_for_gallery.php @@ -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' );