_x( 'Accordions', 'Post Type General Name', 'accordions-wp' ),
'singular_name' => _x( 'Accordion', 'Post Type Singular Name', 'accordions-wp' ),
'menu_name' => __( 'Accordion', 'accordions-wp' ),
'name_admin_bar' => __( 'Accordion', 'accordions-wp' ),
'all_items' => __( 'All Accordions', 'accordions-wp' ),
'add_new_item' => __( 'Add New Accordion', 'accordions-wp' ),
'add_new' => __( 'Add New Accordion', 'accordions-wp' ),
'new_item' => __( 'New Item Accordion', 'accordions-wp' ),
'edit_item' => __( 'Edit Accordion', 'accordions-wp' ),
'update_item' => __( 'Update Accordion', 'accordions-wp' ),
'view_item' => __( 'View Accordion', 'accordions-wp' ),
'search_items' => __( 'Search Accordion', 'accordions-wp' ),
'not_found' => __( 'Accordion Not found', 'accordions-wp' ),
'not_found_in_trash' => __( 'Accordion Not found in Trash', 'accordions-wp' ),
);
$args = array(
'label' => __( 'Accordion', 'accordions-wp' ),
'description' => __( 'Accordion Post Type', 'accordions-wp' ),
'labels' => $labels,
'supports' => array( 'title' ),
'menu_icon' => defined( 'TCACCORDION_PLUGIN_URL' ) ? TCACCORDION_PLUGIN_URL . 'assets/css/accordion.png' : 'dashicons-list-view',
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'accordion_tp', $args );
}
/**
* Check if the plugin is in Pro version.
*
* @return bool
*/
private function is_pro() {
return false;
}
/**
* Get the maximum item limit based on user license.
* A value of 0 means unlimited. Filterable via 'tcaccordion_max_items'.
*
* @return int
*/
private function get_max_items() {
return max( 0, (int) apply_filters( 'tcaccordion_max_items', 0 ) );
}
/**
* Register the Accordion metabox wrapper.
*
* @return void
*/
public function register_metabox() {
add_meta_box(
'custom_accordion_wordpress_feature',
__( 'Accordion Control Panel', 'accordions-wp' ),
array( $this, 'render_metabox_wrapper' ),
'accordion_tp',
'normal',
'high'
);
}
/**
* Enqueue admin scripts and styles.
*
* @param string $hook Current admin page hook.
* @return void
*/
public function enqueue_assets( $hook ) {
global $post_type;
if ( 'accordion_tp' !== $post_type ) {
return;
}
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_style(
'tcaccordion-metabox',
TCACCORDION_PLUGIN_URL . 'admin/css/accordion-metabox.css',
array(),
TCACCORDION_VERSION,
);
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_editor();
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script(
'tcaccordion-color-picker',
TCACCORDION_PLUGIN_URL . 'admin/js/color-picker.js',
array( 'wp-color-picker' ),
TCACCORDION_VERSION,
true
);
wp_enqueue_style(
'font-awesome-6',
TCACCORDION_PLUGIN_URL . 'assets/css/all.min.css',
array(),
'6.5.1'
);
wp_enqueue_script(
'tcaccordion-metabox',
TCACCORDION_PLUGIN_URL . 'admin/js/accordion-metabox.js',
array( 'jquery', 'jquery-ui-sortable' ),
TCACCORDION_VERSION,
true
);
wp_localize_script(
'tcaccordion-metabox',
'tcAccordion',
array(
'maxItems' => $this->get_max_items() > 0 ? $this->get_max_items() : 100000,
'isPro' => $this->is_pro(),
'addText' => __( 'Add Item', 'accordions-wp' ),
'removeText' => __( 'Remove', 'accordions-wp' ),
'copyText' => __( 'Copy', 'accordions-wp' ),
'i18n' => array(
'confirmRemove' => __( 'Remove this item?', 'accordions-wp' ),
'noRows' => __( 'No items were found in this file. Make sure it has a header row with the columns "title" and "description".', 'accordions-wp' ),
'readError' => __( 'The file could not be read.', 'accordions-wp' ),
'confirmReplace' => __( 'This removes all current items and replaces them with the content of the CSV file. Continue?', 'accordions-wp' ),
/* translators: %d: number of imported items */
'imported' => __( '%d items imported. Click Update to save them.', 'accordions-wp' ),
/* translators: %d: number of imported items */
'limited' => __( 'Only %d items could be imported because of the item limit.', 'accordions-wp' ),
'largeWarning' => __( 'Very large accordions can exceed your server\'s PHP max_input_vars limit and lose items when saving. If items are missing after saving, ask your host to raise max_input_vars.', 'accordions-wp' ),
),
'limitText' => sprintf(
/* translators: %d: maximum number of items */
__( 'You can add up to %d items to one accordion.', 'accordions-wp' ),
$this->get_max_items()
),
)
);
}
/**
* Main Tabbed Container Wrapper
*/
public function render_metabox_wrapper( $post ) {
wp_nonce_field( 'tcaccordion_save_action', 'tcaccordion_nonce_field' );
// Retrieve active tab from meta or default to '#tab-accordion-content'
$active_tab = get_post_meta( $post->ID, '_tc_active_tab', true );
if ( empty( $active_tab ) ) {
$active_tab = '#tab-accordion-content';
}
?>
render_accordion_content_tab( $post ); ?>
render_accordion_settings_tab( $post ); ?>
render_accordion_design_tab( $post ); ?>
get_items_from_db( $post->ID );
$max_limit = $this->get_max_items();
?>
$item ) {
$this->render_item( $index, $item );
}
}
?>
0 ) : ?>
' ), array( '<script', '</script' ), $template_content );
?>
ID, 'custom_accordion_columns_post_themes', true );
// Retrieve current saved meta values (with defaults)
$auto_open_item = get_post_meta( $post->ID, '_tcacc_auto_open_item', true );
$auto_open_item = ( '' !== $auto_open_item ) ? absint( $auto_open_item ) : 1; // Default: 1st item
$is_closeable = get_post_meta( $post->ID, '_tcacc_is_closeable', true );
$is_closeable = ( '' !== $is_closeable ) ? sanitize_text_field( $is_closeable ) : 'yes'; // Default: yes
// Fetch existing meta value (defaults to 'yes')
$close_others = get_post_meta( $post->ID, '_tcacc_close_others', true );
$close_others = ! empty( $close_others ) ? $close_others : 'yes';
// Fetch selected icon style (defaults to 'plus_minus')
$icon_style = get_post_meta( $post->ID, '_tcacc_icon_style', true );
$icon_style = ! empty( $icon_style ) ? $icon_style : 'plus_minus';
// Retrieve saved values or set defaults
$open_event = get_post_meta( $post->ID, '_tcacc_open_event', true );
$open_event = ! empty( $open_event ) ? $open_event : 'click';
// Retrieve FAQ Schema Setting (defaults to 'yes')
$enable_faq_schema = get_post_meta( $post->ID, '_tcacc_enable_faq_schema', true );
$enable_faq_schema = ( '' !== $enable_faq_schema ) ? $enable_faq_schema : 'no';
$anim_speed = get_post_meta( $post->ID, '_tcacc_anim_speed', true );
$anim_speed = ! empty( $anim_speed ) ? $anim_speed : '300';
// Search box, Expand/Collapse All and Deep Links (default: off).
$show_search = get_post_meta( $post->ID, '_tcacc_show_search', true );
$show_search = ( 'yes' === $show_search ) ? 'yes' : 'no';
$show_toggle_all = get_post_meta( $post->ID, '_tcacc_show_toggle_all', true );
$show_toggle_all = ( 'yes' === $show_toggle_all ) ? 'yes' : 'no';
$deep_link = get_post_meta( $post->ID, '_tcacc_deep_link', true );
$deep_link = ( 'yes' === $deep_link ) ? 'yes' : 'no';
$search_holder = get_post_meta( $post->ID, '_tcacc_search_placeholder', true );
// Layout. Extra layouts are added by the Pro add-on through the 'tcaccordion_layouts' filter.
$layout_options = TCAccordion_Renderer::get_available_layouts();
$layout = get_post_meta( $post->ID, '_tcacc_layout', true );
$layout = isset( $layout_options[ $layout ] ) ? $layout : 'accordion';
// Layout cards. Layouts that are not available are shown locked, with a PRO badge.
$layout_cards = array(
'accordion' => __( 'Accordion', 'accordions-wp' ),
'two-column' => __( 'Two-column FAQ', 'accordions-wp' ),
'tabs' => __( 'Tabs', 'accordions-wp' ),
'horizontal' => __( 'Horizontal', 'accordions-wp' ),
);
$layout_img_base = defined( 'TCACCORDION_PLUGIN_URL' ) ? TCACCORDION_PLUGIN_URL . 'admin/images/' : '';
$pro_ui = (bool) has_action( 'tcaccordion_save_settings' );
if ( empty( $custom_accordion_columns_post_themes ) ) {
$custom_accordion_columns_post_themes = 'theme1';
}
$themes = array(
'theme1' => array( 'label' => __( 'Sun Flower', 'accordions-wp' ), 'img' => 'theme1.png' ),
'theme2' => array( 'label' => __( 'Orange', 'accordions-wp' ), 'img' => 'theme2.png' ),
'theme3' => array( 'label' => __( 'Pumpkin', 'accordions-wp' ), 'img' => 'theme3.png' ),
'theme4' => array( 'label' => __( 'Alizarin', 'accordions-wp' ), 'img' => 'theme4.png' ),
'theme5' => array( 'label' => __( 'Carrot', 'accordions-wp' ), 'img' => 'theme5.png' ),
'theme-flat' => array(
'label' => __( 'Modern Flat', 'accordions-wp' ),
'img' => 'theme-flat.png',
),
'theme-shadow' => array(
'label' => __( 'Soft Shadow', 'accordions-wp' ),
'img' => 'theme-shadow.png',
),
'theme-dark' => array(
'label' => __( 'Dark Mode', 'accordions-wp' ),
'img' => 'theme-dark.png',
),
);
?>
ID, 'custom_accordion_title_bg_color', true );
$custom_accordion_title_font_color = get_post_meta( $post->ID, 'custom_accordion_title_font_color', true );
// Hover and open (active) state colors.
$state_colors = array(
'hover' => array(
'title_bg' => get_post_meta( $post->ID, 'custom_accordion_title_bg_color_hover', true ),
'title_color' => get_post_meta( $post->ID, 'custom_accordion_title_font_color_hover', true ),
'icon_color' => get_post_meta( $post->ID, 'custom_accordion_icon_color_hover', true ),
),
'active' => array(
'title_bg' => get_post_meta( $post->ID, 'custom_accordion_title_bg_color_active', true ),
'title_color' => get_post_meta( $post->ID, 'custom_accordion_title_font_color_active', true ),
'icon_color' => get_post_meta( $post->ID, 'custom_accordion_icon_color_active', true ),
),
);
$custom_accordion_title_font_size = get_post_meta( $post->ID, 'custom_accordion_title_font_size', true );
$custom_accordion_content_bg_color = get_post_meta( $post->ID, 'custom_accordion_content_bg_color', true );
$custom_accordion_content_font_color = get_post_meta( $post->ID, 'custom_accordion_content_font_color', true );
$custom_accordion_content_font_size = get_post_meta( $post->ID, 'custom_accordion_content_font_size', true );
$custom_accordion_content_padding = get_post_meta( $post->ID, 'custom_accordion_content_padding', true );
$_tpaccpro_wiki_acc_themes_title_position = get_post_meta( $post->ID, '_tpaccpro_wiki_acc_themes_title_position', true );
$_tpaccpro_wiki_acc_themes_show_hide_icons = get_post_meta( $post->ID, '_tpaccpro_wiki_acc_themes_show_hide_icons', true );
$_tpaccpro_wiki_acc_themes_icon_position = get_post_meta( $post->ID, '_tpaccpro_wiki_acc_themes_icon_position', true );
$_tpaccpro_wiki_acc_theme_content_margin = get_post_meta( $post->ID, '_tpaccpro_wiki_acc_theme_content_margin', true );
$custom_accordion_title_line_height = get_post_meta( $post->ID, 'custom_accordion_title_line_height', true );
$custom_accordion_content_line_height = get_post_meta( $post->ID, 'custom_accordion_content_line_height', true );
$custom_accordion_content_letter_spacing = get_post_meta( $post->ID, 'custom_accordion_content_letter_spacing', true );
// Retrieve existing icon color meta values
$custom_accordion_icon_color = get_post_meta( $post->ID, 'custom_accordion_icon_color', true );
$custom_accordion_icon_bg_color = get_post_meta( $post->ID, 'custom_accordion_icon_bg_color', true );
$custom_accordion_border_style = get_post_meta( $post->ID, 'custom_accordion_border_style', true );
$custom_accordion_border_style = ! empty( $custom_accordion_border_style ) ? $custom_accordion_border_style : 'none';
$custom_accordion_border_width = get_post_meta( $post->ID, 'custom_accordion_border_width', true );
$custom_accordion_border_width = ( '' !== $custom_accordion_border_width ) ? $custom_accordion_border_width : '1';
$custom_accordion_border_color = get_post_meta( $post->ID, 'custom_accordion_border_color', true );
?>
extract_item_fields( $sub_item );
if ( $item ) {
$items[] = $item;
}
}
}
} else {
$item = $this->extract_item_fields( $row );
if ( $item ) {
$items[] = $item;
}
}
}
return $items;
}
/**
* Extract title and description from multiple legacy field key variants.
*
* @param array $data Raw array row.
* @return array|false Formatted item or false if empty.
*/
private function extract_item_fields( $data ) {
$title = '';
if ( isset( $data['title'] ) ) {
$title = $data['title'];
} elseif ( isset( $data['custom_accordions_pro_title'] ) ) {
$title = $data['custom_accordions_pro_title'];
}
$details = '';
if ( isset( $data['description'] ) ) {
$details = $data['description'];
} elseif ( isset( $data['custom_accordions_pro_details'] ) ) {
$details = $data['custom_accordions_pro_details'];
}
if ( '' !== $title || '' !== $details ) {
return apply_filters(
'tcaccordion_admin_item',
array(
'title' => $title,
'description' => $details,
),
$data
);
}
return false;
}
/**
* Render Individual Item Markup.
*
* @param string|int $index Index key.
* @param array $item Item details.
* @return void
*/
private function render_item( $index, $item ) {
$title = isset( $item['title'] ) ? $item['title'] : '';
$content = isset( $item['description'] ) ? $item['description'] : '';
$editor_id = 'tcaccordion_editor_' . sanitize_html_class( $index );
?>
get_max_items();
$raw_posted_items = wp_unslash( $_POST[ self::META_KEY ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized per key/value inside foreach.
if ( is_array( $raw_posted_items ) ) {
foreach ( array_values( $raw_posted_items ) as $item ) {
if ( ! is_array( $item ) ) {
continue;
}
if ( $max_limit > 0 && count( $items ) >= $max_limit ) {
break;
}
$title = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : '';
// Updated sanitization to fully allow iframes and video embed attributes
$details = '';
if ( isset( $item['description'] ) ) {
$iframe_allowed = wp_kses_allowed_html( 'post' );
$iframe_allowed['iframe'] = array(
'src' => true,
'width' => true,
'height' => true,
'frameborder' => true,
'allow' => true,
'allowfullscreen' => true,
'title' => true,
'style' => true,
'class' => true,
'loading' => true,
'referrerpolicy' => true,
);
$details = wp_kses( $item['description'], $iframe_allowed );
}
if ( '' !== $title || '' !== $details ) {
$clean_item = array(
'title' => $title,
'description' => $details,
);
// Add-ons can keep extra per-item fields (for example a nested accordion).
$items[] = apply_filters( 'tcaccordion_sanitize_item', $clean_item, $item, $post_id );
}
}
}
delete_post_meta( $post_id, self::META_KEY );
if ( ! empty( $items ) ) {
update_post_meta( $post_id, self::META_KEY, $items );
}
}
// Save Active Tab State
if ( isset( $_POST['tc_active_tab_input'] ) ) {
$active_tab = sanitize_text_field( wp_unslash( $_POST['tc_active_tab_input'] ) );
update_post_meta( $post_id, '_tc_active_tab', $active_tab );
}
// Save Enable FAQ Schema Checkbox Setting
$enable_faq_schema = isset( $_POST['_tcacc_enable_faq_schema'] ) ? 'yes' : 'no';
update_post_meta( $post_id, '_tcacc_enable_faq_schema', $enable_faq_schema );
// Save Layout settings.
if ( isset( $_POST['_tcacc_layout'] ) ) {
$layout_val = sanitize_text_field( wp_unslash( $_POST['_tcacc_layout'] ) );
$layout_val = array_key_exists( $layout_val, TCAccordion_Renderer::get_available_layouts() ) ? $layout_val : 'accordion';
update_post_meta( $post_id, '_tcacc_layout', $layout_val );
}
// Save Search Box, Expand/Collapse All and Deep Link settings.
foreach ( array( '_tcacc_show_search', '_tcacc_show_toggle_all', '_tcacc_deep_link' ) as $toggle_key ) {
if ( isset( $_POST[ $toggle_key ] ) ) {
$toggle_val = sanitize_text_field( wp_unslash( $_POST[ $toggle_key ] ) );
update_post_meta( $post_id, $toggle_key, ( 'yes' === $toggle_val ) ? 'yes' : 'no' );
}
}
if ( isset( $_POST['_tcacc_search_placeholder'] ) ) {
update_post_meta( $post_id, '_tcacc_search_placeholder', sanitize_text_field( wp_unslash( $_POST['_tcacc_search_placeholder'] ) ) );
}
if ( isset( $_POST['_tcacc_woo_enable'] ) ) {
update_post_meta( $post_id, '_tcacc_woo_enable', 'yes' );
} else {
update_post_meta( $post_id, '_tcacc_woo_enable', 'no' );
}
if ( isset( $_POST['_tcacc_woo_tab_title'] ) ) {
update_post_meta( $post_id, '_tcacc_woo_tab_title', sanitize_text_field( wp_unslash( $_POST['_tcacc_woo_tab_title'] ) ) );
}
if ( isset( $_POST['_tcacc_woo_location'] ) ) {
update_post_meta( $post_id, '_tcacc_woo_location', sanitize_text_field( wp_unslash( $_POST['_tcacc_woo_location'] ) ) );
}
// 2. SAVE ACCORDION STYLE & OPTION METAS
$style_fields = array(
'custom_accordion_columns_post_themes' => 'sanitize_text_field',
'custom_accordion_title_font_size' => 'sanitize_text_field',
'custom_accordion_content_font_size' => 'sanitize_text_field',
'custom_accordion_content_padding' => 'sanitize_text_field',
'_tpaccpro_wiki_acc_themes_title_position' => 'sanitize_text_field',
'_tpaccpro_wiki_acc_themes_show_hide_icons' => 'sanitize_text_field',
'_tpaccpro_wiki_acc_themes_icon_position' => 'sanitize_text_field',
'_tpaccpro_wiki_acc_theme_content_margin' => 'sanitize_text_field',
'custom_accordion_title_line_height' => 'sanitize_text_field',
'custom_accordion_content_line_height' => 'sanitize_text_field',
'custom_accordion_content_letter_spacing' => 'sanitize_text_field',
'custom_accordion_title_bg_color' => 'sanitize_hex_color',
'custom_accordion_title_font_color' => 'sanitize_hex_color',
'custom_accordion_title_bg_color_hover' => 'sanitize_hex_color',
'custom_accordion_title_font_color_hover' => 'sanitize_hex_color',
'custom_accordion_icon_color_hover' => 'sanitize_hex_color',
'custom_accordion_title_bg_color_active' => 'sanitize_hex_color',
'custom_accordion_title_font_color_active' => 'sanitize_hex_color',
'custom_accordion_icon_color_active' => 'sanitize_hex_color',
'custom_accordion_content_bg_color' => 'sanitize_hex_color',
'custom_accordion_content_font_color' => 'sanitize_hex_color',
'custom_accordion_icon_color' => 'sanitize_hex_color', // Added Icon Color
'custom_accordion_icon_bg_color' => 'sanitize_hex_color', // Added Icon BG Color
'custom_accordion_border_style' => 'sanitize_text_field', // Added Border Style
'custom_accordion_border_width' => 'sanitize_text_field', // Added Border Width
'custom_accordion_border_color' => 'sanitize_hex_color',
);
foreach ( $style_fields as $field => $sanitize_callback ) {
if ( isset( $_POST[ $field ] ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Input is unslashed first and sanitized via the specific callback below.
$raw_val = wp_unslash( $_POST[ $field ] );
if ( 'sanitize_hex_color' === $sanitize_callback ) {
$val = sanitize_hex_color( $raw_val );
} elseif ( 'sanitize_text_field' === $sanitize_callback ) {
$val = sanitize_text_field( $raw_val );
} elseif ( is_callable( $sanitize_callback ) ) {
$val = call_user_func( $sanitize_callback, $raw_val );
} else {
$val = sanitize_text_field( $raw_val );
}
update_post_meta( $post_id, $field, $val );
}
}
if ( isset( $_POST['_tcacc_icon_style'] ) ) {
$icon_style = sanitize_text_field( wp_unslash( $_POST['_tcacc_icon_style'] ) );
$allowed_styles = array( 'plus_minus', 'chevron', 'angle', 'caret', 'folder', 'none' );
$icon_style = in_array( $icon_style, $allowed_styles, true ) ? $icon_style : 'plus_minus';
update_post_meta( $post_id, '_tcacc_icon_style', $icon_style );
}
// Behavior settings
if ( isset( $_POST['_tcacc_auto_open_item'] ) ) {
update_post_meta( $post_id, '_tcacc_auto_open_item', absint( wp_unslash( $_POST['_tcacc_auto_open_item'] ) ) );
}
if ( isset( $_POST['_tcacc_is_closeable'] ) ) {
$closeable = sanitize_text_field( wp_unslash( $_POST['_tcacc_is_closeable'] ) );
update_post_meta( $post_id, '_tcacc_is_closeable', in_array( $closeable, array( 'yes', 'no' ), true ) ? $closeable : 'yes' );
}
if ( isset( $_POST['_tcacc_close_others'] ) ) {
$close_others = sanitize_text_field( wp_unslash( $_POST['_tcacc_close_others'] ) );
update_post_meta( $post_id, '_tcacc_close_others', in_array( $close_others, array( 'yes', 'no' ), true ) ? $close_others : 'yes' );
}
/**
* Lets add-ons save their own settings. The nonce and permissions are already verified above.
*
* @param int $post_id Accordion ID.
*/
do_action( 'tcaccordion_save_settings', $post_id );
}
/**
* Custom Admin Post Columns
*/
public function register_admin_columns( $columns ) {
return array(
'cb' => '',
'title' => __( 'Shortcode Name', 'accordions-wp' ),
'shortcode' => __( 'Shortcode', 'accordions-wp' ),
'doshortcode' => __( 'Template Shortcode', 'accordions-wp' ),
'date' => __( 'Date', 'accordions-wp' ),
);
}
/**
* Display Admin Post Columns Content
*/
public function render_admin_columns( $column, $post_id ) {
if ( 'shortcode' === $column ) {
echo '';
}
if ( 'doshortcode' === $column ) {
echo '';
}
}
/**
* Display Shortcode Notice Below Title Input
*/
public function render_shortcode_section( $post ) {
if ( 'accordion_tp' !== $post->post_type ) {
return;
}
$shortcode = "[tcpaccordion id='" . $post->ID . "']";
$php_code = 'ID . ']"); ?>';
?>
post_type ) {
return __( 'Accordion Group Title', 'accordions-wp' );
}
return $title;
}
/**
* AJAX Handler to generate exact live frontend markup from unsaved form data.
*/
public function ajax_render_live_preview() {
check_ajax_referer( 'tcaccordion_save_action', 'security' );
if ( ! current_user_can( 'edit_posts' ) ) {
wp_send_json_error( array( 'message' => __( 'Permission denied.', 'accordions-wp' ) ) );
}
$post_id = isset( $_POST['post_id'] ) ? absint( wp_unslash( $_POST['post_id'] ) ) : 0;
// Parse serialized form data string sent from JavaScript
$posted_meta = array();
if ( ! empty( $_POST['form_data'] ) ) {
$raw_form_data = sanitize_text_field( wp_unslash( $_POST['form_data'] ) );
wp_parse_str( $raw_form_data, $posted_meta );
}
// Initialize the renderer
$renderer = new TCAccordion_Renderer( $post_id );
// Pass live unsaved form fields to the renderer instance
if ( ! empty( $posted_meta ) && method_exists( $renderer, 'set_preview_data' ) ) {
$renderer->set_preview_data( $posted_meta );
}
$html = $renderer->render();
wp_send_json_success( array( 'html' => $html ) );
}
/**
* Enqueue Admin Scripts & Styles for Preview
*/
public function enqueue_admin_preview_styles( $hook ) {
if ( 'post.php' !== $hook && 'post-new.php' !== $hook ) {
return;
}
$screen = get_current_screen();
if ( is_object( $screen ) && 'accordion_tp' === $screen->post_type ) {
wp_enqueue_style( 'tcaccordion-responsive', TCACCORDION_PLUGIN_URL . 'assets/css/responsive-accordion.css', array(), TCACCORDION_VERSION );
wp_enqueue_style( 'tcaccordion-style', TCACCORDION_PLUGIN_URL . 'assets/css/style.css', array(), TCACCORDION_VERSION );
}
}
}
new TCAccordion_Metabox();