'example', 'info' => get_option('wp_jdt_info', 'true'), 'paging' => get_option('wp_jdt_paging', 'true'), 'page_length' => get_option('wp_jdt_page_length', '10'), 'paging_type' => get_option('wp_jdt_paging_type', 'simple'), 'b_length_change' => get_option('wp_jdt_b_length_change', 'true'), 'ordering' => get_option('wp_jdt_ordering', 'true'), 'order_row_number' => get_option('wp_jdt_order_row', '0'), 'order_row_number_sort' => get_option('wp_jdt_order_row_sort', 'desc'), 'searching' => get_option('wp_jdt_searching', 'true'), ); // Combines user attributes with known attributes and fill in defaults when needed $atts = shortcode_atts($defaults, $atts, 'wp_jdt'); // Sanitize and fall back to defaults when setting from shortcode is unknown $table_id = preg_replace('/[^a-zA-Z0-9_\-]/', '', $atts['id']); $table_info = ($atts['info'] === 'true') ? 'true' : 'false'; $table_paging = ($atts['paging'] === 'true') ? 'true' : 'false'; $table_page_length = absint($atts['page_length']); $allowed_table_paging_types = array('simple', 'simple_numbers', 'full', 'full_numbers'); $table_paging_type = in_array($atts['paging_type'], $allowed_table_paging_types, true) ? $atts['paging_type'] : 'simple'; $table_b_length_change = ($atts['b_length_change'] === 'true') ? 'true' : 'false'; $table_ordering = ($atts['ordering'] === 'true') ? 'true' : 'false'; $table_order_row_number = absint($atts['order_row_number']); $table_order_sort = (strtolower($atts['order_row_number_sort']) === 'asc') ? 'asc' : 'desc'; $table_searching = ($atts['searching'] === 'true') ? 'true' : 'false'; $table_length_menu = array(10, 25, 50, 100, -1); if (!in_array($table_page_length, $table_length_menu)) { // Add the missing page length option to the array $table_length_menu[] = (int)$table_page_length; // Temporarily remove -1 ("All") if present to preserve its position at the end $has_all = false; if (($key = array_search(-1, $table_length_menu)) !== false) { unset($table_length_menu[$key]); $has_all = true; } // Sort the remaining numeric options in ascending order sort($table_length_menu); // Append -1 back to the end of the array if ($has_all) { $table_length_menu[] = -1; } } // css and js wp_enqueue_style('jdt-style-data-tables'); wp_enqueue_script('jdt-js-datatables'); // Load JS script via wp_footer anonymous function add_action('wp_footer', function () use ( $table_id, $table_info, $table_paging, $table_page_length, $table_length_menu, $table_paging_type, $table_b_length_change, $table_ordering, $table_order_row_number, $table_order_sort, $table_searching ) { ?>