post_content); if (isset($custom_table_setting[ACF_CT_ENABLE]) && $custom_table_setting[ACF_CT_ENABLE] != "1") { return false; } $custom_table_name = $custom_table_setting[ACF_CT_TABLE_NAME] ?? ''; if (empty(trim($custom_table_name)) === false) { // prepend prefix global $wpdb; $prefix = ($prepend_prefix) ? $wpdb->prefix : ''; return $prefix . $custom_table_name; } return false; } public static function get_acf_field_group_id($field_group_key) { global $wpdb; $sql = "SELECT ID FROM {$wpdb->prefix}posts WHERE post_name='{$field_group_key}' AND post_type='acf-field-group'"; $results = $wpdb->get_results($sql); if (is_array($results) && !empty($results)) { return (isset($results[0]->ID)) ? $results[0]->ID : null; } return null; } public static function acf_get_field_groups_id($post_id) { $acf_groups = acf_get_field_groups(self::get_field_groups_filter_array($post_id)); $groups_id = array(); foreach ($acf_groups as $group) { array_push($groups_id, $group['ID']); } return $groups_id; } /** * Get ACF field group id and associated custom table name * * @param $post_id * @param bool $with_prefix - table prefix * @param bool $only_active_custom_tables * @return array */ public static function get_acf_field_groups_meta($post_id, $with_prefix = true, $only_active_custom_tables = true) { $cache_key = "acf_ct:$post_id:acf_field_group_meta"; /** * Process if id is numeric */ $formatted_post_id = self::format_post_id($post_id); if (is_numeric($formatted_post_id) === false) { return array(); } /** * Check in cache */ $acf_field_group_meta = wp_cache_get($cache_key); if ($acf_field_group_meta !== false) { return $acf_field_group_meta; } $acf_groups = acf_get_field_groups(self::get_field_groups_filter_array($post_id)); $acf_field_group_meta = array_reduce($acf_groups, function ($meta, $field_group) use ($with_prefix, $only_active_custom_tables) { if ((isset($field_group[ACF_CT_ENABLE]) && $field_group[ACF_CT_ENABLE] == 1) || $only_active_custom_tables === false) { $custom_table_name = trim($field_group[ACF_CT_TABLE_NAME]); if (empty($custom_table_name) === false) { global $wpdb; $prefix = ($with_prefix) ? $wpdb->prefix : ''; array_push($meta, array( 'id' => $field_group['ID'], 'table' => $prefix . $custom_table_name, 'active' => $field_group[ACF_CT_ENABLE], 'key' => $field_group['key'] )); } } return $meta; }, array()); /** * Save in cache */ wp_cache_set($cache_key, $acf_field_group_meta); return $acf_field_group_meta; } /** * Get all custom tables associated with post * @param $post_id * @return mixed */ public static function get_custom_table_names_of_post($post_id) { $acf_post_ids = Acfct_utils::acf_get_field_groups_id($post_id); return array_reduce($acf_post_ids, function ($custom_table_names, $acf_post_id) { $table_name = Acfct_utils::get_custom_table_name($acf_post_id, true); if ($table_name !== false) { $custom_table_names[$acf_post_id] = $table_name; } return $custom_table_names; }, array()); } public static function maybe_prefix_table_name($table_name) { global $wpdb; $prefix = $wpdb->prefix; if (strpos($table_name, $prefix) === 0) { return $table_name; } return $prefix . $table_name; } /** * Eg: [a,b,c] ==> ab * @param $keywords * @return string */ public static function get_span_tags_from_array($keywords) { $tags = array_map(function ($keyword) { return "" . esc_html($keyword) . ""; }, $keywords); return implode("", $tags); } /** * Set Page Header Title in UI * @param $title * @param bool $show_back_button */ public static function set_page_title($title, $show_back_button = true) { echo "