the_lis()){ add_filter( 'manage_checker_posts_columns', [$this, 'filter_cpt_columns']); add_action( 'manage_checker_posts_custom_column', [$this, 'action_custom_columns_content'], 10, 2 ); add_action( 'add_meta_boxes', [$this, 'add_checker_metabox'] ); add_action( 'save_post_checker', [$this, 'save_checker_metabox'] ); add_action( 'wp_ajax_load_repeater_field_card', [$this, 'load_repeater_field_card'] ); add_action( 'wp_ajax_load_output_setting', [$this, 'load_output_setting'] ); require 'class-Shortcode.php'; new CHECKER_SHORTCODE(); } } public function create_custom_post_type() { $labels = array( 'name' => 'Checker', 'singular_name' => 'Checker', 'menu_name' => 'Checkers', 'add_new' => 'Add New', 'add_new_item' => 'Add New Checker', 'edit' => 'Edit', 'edit_item' => 'Edit Checker', 'new_item' => 'New Checker', 'view' => 'View', 'view_item' => 'View Checker', 'search_items' => 'Search Checkers', 'not_found' => 'No checkers found', 'not_found_in_trash' => 'No checkers found in trash', 'parent' => 'Parent Checker' ); $args = array( 'label' => 'Checkers', 'description' => 'Checkers for your sheet data', 'labels' => $labels, 'public' => false, 'menu_position' => 4, 'menu_icon' => SHEET_CHECKER_PRO_URL .'assets/icons8-validation-menu-icon.png', 'supports' => array( 'title' ), 'hierarchical' => true, 'taxonomies' => array( 'category' ), 'has_archive' => false, 'rewrite' => array( 'slug' => 'checkers' ), 'show_ui' => true, 'show_in_menu' => true, 'show_in_rest' => false, 'query_var' => true, ); register_post_type( 'checker', $args ); } public function enqueue_bootstrap_admin() { $screen = get_current_screen(); // Check that we are on the 'Checker' post editor screen if ( $screen && $screen->id === 'checker' ) { // Enqueue Bootstrap CSS wp_enqueue_style( 'bootstrap', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css' ); // wp_enqueue_style( 'bs-table', 'https://unpkg.com/bootstrap-table@1.22.1/dist/bootstrap-table.min.css' ); wp_enqueue_style( 'bs-icon', 'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css' ); wp_enqueue_style( 'checker-editor', SHEET_CHECKER_PRO_URL . 'assets/admin-editor.css' ); wp_enqueue_style( 'datatables', 'https://cdn.datatables.net/2.2.2/css/dataTables.dataTables.css' ); // Enqueue Bootstrap JS wp_enqueue_script( 'bootstrap', 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js', array( 'jquery' ), '4.5.2', true ); wp_enqueue_script( 'handlebarjs', 'https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.8/handlebars.min.js', ['jquery'], '4.7.8', true ); // wp_enqueue_script( 'bs-table', 'https://unpkg.com/bootstrap-table@1.22.1/dist/bootstrap-table.min.js', ['jquery'], '1.22.1', true ); wp_enqueue_script( 'checker-editor', SHEET_CHECKER_PRO_URL . 'assets/admin-editor-interactions.js', ['jquery', 'handlebarjs'], true ); wp_enqueue_script( 'datatables', 'https://cdn.datatables.net/2.2.2/js/dataTables.js', ['jquery'], true ); wp_enqueue_script( 'datatables', 'https://cdn.datatables.net/responsive/3.0.4/js/dataTables.responsive.js', ['jquery'], true ); wp_enqueue_script( 'datatables', 'https://cdn.datatables.net/responsive/3.0.4/js/responsive.dataTables.js', ['jquery'], true ); } wp_enqueue_style( 'checker-editor', SHEET_CHECKER_PRO_URL . 'assets/admin.css' ); } public function filter_cpt_columns( $columns ) { // this will add the column to the end of the array $columns['shortcode'] = 'Shortcode'; //add more columns as needed // as with all filters, we need to return the passed content/variable return $columns; } public function action_custom_columns_content ( $column_id, $post_id ) { //run a switch statement for all of the custom columns created switch( $column_id ) { case 'shortcode': echo ''; break; //add more items here as needed, just make sure to use the column_id in the filter for each new item. } } public function add_checker_metabox() { add_meta_box( 'checker_preview', 'Preview', [$this, 'preview_checker_metabox'], 'checker', 'normal', 'default' ); add_meta_box( 'checker_options', 'Options', [$this, 'render_checker_metabox'], 'checker', 'normal', 'default' ); if(isset($_GET['post']) && isset($_GET['action'])){ add_meta_box( 'checker_shortcode', 'Shortcode', [$this, 'shortcode_checker_metabox'], 'checker', 'side', 'high' ); } } public function shortcode_checker_metabox() { ?>
Use shortcode below:
"]' class="form-control border-dark" readonly> ID, 'checker', true ); $checker = wp_parse_args( $checker, [ 'link' => '', 'description' => '', 'card' => [ 'width' => 500, 'background' => '#cccccc', 'border_radius' => 1, 'box_shadow' => '10px 5px 15px -5px', 'box_shadow_color' => '#333333', 'title' => '#333333', 'title_align' => 'left', 'description' => '#333333', 'description_align' => 'left', 'divider' => '#333333', 'divider_width' => 1 ], 'field' => [ 'label' => 'block', 'label-color' => '#333333' ], 'fields' => [], 'search_button' => [ 'text' => 'Search', 'bg_color' => '#cccccc', 'text_color' => '#333333', 'position' => 'flex-end' ], 'back_button' => [ 'text' => 'Back', 'bg_color' => '#cccccc', 'text_color' => '#333333', 'position' => 'flex-start' ], 'result' => [ 'display' => 'tabel', 'header' => '#333333', 'value' => '#333333', 'columns' => [], 'border_width' => 1 ] ] ); require_once SHEET_CHECKER_PRO_PATH . 'templates/editor/preview.php'; } public function render_checker_metabox( $post ) { // Retrieve existing values from the database $checker = get_post_meta( $post->ID, 'checker', true ); $checker = wp_parse_args( $checker, [ 'link' => '', 'description' => '', 'card' => [ 'width' => 500, 'background' => '#cccccc', 'bg_opacity' => 100, 'border_radius' => 1, 'box_shadow' => '10px 5px 15px -5px', 'box_shadow_color' => '#333333', 'title' => '#333333', 'title_align' => 'left', 'description' => '#333333', 'description_align' => 'left', 'divider' => '#333333', 'divider_width' => 1 ], 'field' => [ 'label' => 'block', 'label-color' => '#333333' ], 'fields' => [], 'search_button' => [ 'text' => 'Search', 'bg_color' => '#cccccc', 'text_color' => '#333333', 'position' => 'flex-end' ], 'back_button' => [ 'text' => 'Back', 'bg_color' => '#cccccc', 'text_color' => '#333333', 'position' => 'flex-start' ], 'result' => [ 'display' => 'table', 'header' => '#333333', 'value' => '#333333', 'divider' => '#333333', 'divider_width' => 1 ] ] ); require_once SHEET_CHECKER_PRO_PATH . 'templates/editor/settings.php'; } public function save_checker_metabox( $post_id ) { // Save metabox data if ( isset( $_POST['checker'] ) ) { error_log(print_r($_POST['checker'], true)); update_post_meta( $post_id, 'checker', $_POST['checker'] ); } } public function load_repeater_field_card_depracated() { $post_id = $_REQUEST['pid']; $checker = get_post_meta( $post_id, 'checker', true ); $json = json_decode(stripslashes($_REQUEST['json']), true); if(isset($checker['fields']) && count($checker['fields']) > 0){ foreach($checker['fields'] as $key => $field){ ?>
0) { foreach ($checker['fields'] as $key => $field) { $response[$key] = $field; $rowHeader = []; foreach($headers as $index => $header){ $id = '_'.strtolower($header); $rowHeader[$index] = $id; } $response[$key]['selected_kolom'] = $response[$key]['kolom']; $response[$key]['kolom'] = $headers; } } wp_send_json($response); exit(); } public function load_column_checkbox() { $post_id = $_REQUEST['pid']; $checker = get_post_meta( $post_id, 'checker', true ); $json = json_decode(stripslashes($_REQUEST['json']), true); $header = $this->parse_header_kolom($json); if(count($header) > 0){ foreach($header as $key){ $checked = ''; if(isset($checker['result']['columns']) && in_array($key, $checker['result']['columns'])){ $checked = ' checked'; } ?>
>
parse_header_kolom($json); if (!empty($headers)) { $output_data = []; foreach ($headers as $key) { $id = strtolower(str_replace([' ', '.'], '_', $key)); $output_data[] = [ 'key' => $key, 'id' => $id, 'hide' => isset($checker['output'][$id]['hide']) ? $checker['output'][$id]['hide'] : 'no', 'type' => isset($checker['output'][$id]['type']) ? $checker['output'][$id]['type'] : 'text', 'button_text' => isset($checker['output'][$id]['button_text']) ? $checker['output'][$id]['button_text'] : '', 'prefix' => isset($checker['output'][$id]['prefix']) ? $checker['output'][$id]['prefix'] : '', 'bg_color' => isset($checker['output'][$id]['bg_color']) ? $checker['output'][$id]['bg_color'] : '#cccccc', 'text_color' => isset($checker['output'][$id]['text_color']) ? $checker['output'][$id]['text_color'] : '#000000', 'display' => isset($checker['result']['display']) && $checker['result']['display'] == 'card' ]; } wp_send_json_success(['data' => $output_data]); } else { wp_send_json_error('No headers found'); } exit(); } public function parse_options($json, $kolom) { $json = json_decode($json, true); $options = []; if($json){ foreach($json as $key => $value){ foreach($value as $name => $val){ if($name == $kolom){ if(!in_array($val, $options)){ $options[] = $val; } } } } } return $options; } public function parse_header_kolom($json) { $header = []; if(!is_array($json)){ $json = json_decode($json, true); } $header = array_keys($json[0]); return $header; } }