PluginProbe
Table Sorter / 2.3
Table Sorter v2.3
trunk 1.0 2.0 2.1 2.2 2.3
table-sorter / table-sorter.php

table-sorter.php in Table Sorter 2.3, at table-sorter.php

98 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Table Sorter
4 * Plugin URI: https://wpreloaded.com/plugins/table-sorter
5 * Description: This plugin makes your standard HTML tables sortable. For more details, check plugin's docs.
6 * Version: 2.3
7 * Author: Farhan Noor
8 * Author URI: https://linkedin.com/in/farhan-noor
9 * License: GPLv2 or later
10 */
11
12 function tablesorter_enque_scripts(){
13 wp_register_script('table-sorter',plugins_url('table-sorter/jquery.tablesorter.min.js'),array('jquery'));
14 wp_enqueue_script('table-sorter-metadata',plugins_url('table-sorter/jquery.metadata.js'),array('table-sorter'), '2.2');
15 wp_enqueue_script('table-sorter-custom-js',plugins_url('table-sorter/wp-script.js'),array('table-sorter'), '2.2');
16 wp_enqueue_style('table-sorter-custom-css',plugins_url('table-sorter/wp-style.css'));
17 }
18 add_action( 'wp_enqueue_scripts', 'tablesorter_enque_scripts' );
19 if( get_option('tablesorter_admin') ) add_action( 'admin_enqueue_scripts', 'tablesorter_enque_scripts' );
20
21 function tablesorter_register_settings(){
22 register_setting('tablesorter_settings_group', 'tablesorter_admin', array('type' => 'boolean'));
23 }
24 add_action('admin_init', 'tablesorter_register_settings');
25
26 function tablesorter_settings(){
27 echo '<form class="wrap" action="options.php" method="post">';
28 settings_fields( 'tablesorter_settings_group' );
29 do_settings_sections( 'tablesorter_settings_group' );
30 echo '<h1>Table Sorter</h1>';
31 if(get_option('tablesorter_admin') ){
32 $yes = "checked";
33 $no = NULL;
34 } else {
35 $yes = NULL;
36 $no = "checked";
37 }
38 echo '<p><span class="label">Sorte Tables in WordPress Admin &nbsp; </span> ';
39 echo '<label><input type="radio" name="tablesorter_admin" value="0" '.$no.' >Disabled</label> &nbsp; &nbsp; ';
40 echo '<label><input type="radio" name="tablesorter_admin" value="1" '.$yes.' >Enabled</label> &nbsp; &nbsp; <input type="submit" class="button-primary" />';
41 echo "</p></form>";
42 echo '<br /><hr>';
43 echo tablesorter_docs();
44 }
45
46 function tablesorter_menu(){
47 add_options_page('Table Sorter', 'Table Sorter', 'manage_options', 'table-sorter', 'tablesorter_settings');
48 }
49 add_action('admin_menu', 'tablesorter_menu');
50
51 function tablesorter_row_meta( $links, $file ) {
52 if ( strpos( $file, 'table-sorter.php' ) !== false ) {
53 $new_links = array('<a href="http://wpreloaded.com/plugins/table-sorter/how-to/" target="_blank">Docs</a>');
54 $links = array_merge( $links, $new_links );
55 }
56 return $links;
57 }
58 add_filter( 'plugin_row_meta', 'tablesorter_row_meta', 10, 2 );
59
60 function tablesorter_add_action_links ( $links ) {
61 $mylinks = array('<a href="' . admin_url( 'tools.php?page=table-sorter' ) . '">Docs</a>');
62 return array_merge( $links, $mylinks );
63 }
64 add_filter( 'plugin_action_links_table-sorter/table-sorter.php', 'tablesorter_add_action_links' );
65
66 function tablesorter_docs(){
67 ob_start();
68 ?>
69 <style>
70 ul{list-style:inherit; padding-left:20px} .label{font-size: 15px; font-weight: 600; line-height: 1.3}
71 </style>
72 <h2 class="title">How To</h2>
73 <b>Table Sorter</b> turns standard HTML table with THEAD and TBODY tags into a sortable table without page refresh. It works on every table, whether it is coded in the wordpress template(theme) file or generated from the wordpress editor. This plugin is very handy for theme developers. It has many useful features including :
74 <ul>
75 <li><b>Multi-column sorting :</b> add "tablesorter" class to the required table</li>
76 <li><b>Disable sorting from particular column :</b> add "sortless" class to the required TH column within THEAD tag.</li>
77 <li><b>Sort multiple columns simultaneously :</b> by holding down the shift key and clicking a second, third or even fourth column header! </li>
78 <li><b>Cross-browser support :</b> IE 6.0+, FF 2+, Safari 2.0+, Opera 9.0+</li>
79 </ul>
80 <h2 class="title">IMPORTANT</h2>
81 <ol>
82 <li><b>THEAD</b> and <b>TBODY</b> tags are compulsory in the desired table, otherwise this plugin will not work.</li>
83 <li>Add <b><u>tablesorter</u></b> class in the desired <b>TABLE</b> tag.</li>
84 <li>For column heading, use <b>TH</b> tag within <b>THEAD</b> tag.</li>
85 <li>If you want to exclude a particular column, add <b><u>sortless</u></b> class to that <b>TH</b> tag.</li>
86 </ol>
87 <h2 class="title">Initial Sorting</h2>
88 <p>You can add initial sorting by adding instructions in the CLASS attribute of the HTML table in the format: {sortlist: [[columnIndex, sortDirection], ]} where columnIndex is a zero-based index for your columns left-to-right and sortDirection is 0 for Ascending and 1 for Descending. A valid argument that sorts ascending first by column 1 and then column 2 looks like: {sortlist: [[0,0],[1,0]]}</p>
89 <p><strong>Example : </strong>&lt;table id="myTable" class="tablesorter {sortlist: [[2,0]]}"&gt;</p>
90 <h2 class="title">Sort by date</h2>
91 <p>To make your date columns sortable, add class <code>dateFormat-dd/mm/yyyy</code> in your Date column head. You can change date format according to your own need.</p>
92 <p><b>Example: </b><code>&lt;th class="dateFormat-dd/mm/yyyy"&gt;Date&lt;/th&gt;</code></p>
93 <p>All Done. Have fun!</p>
94 <!--Generating Table HTML to show-->
95 <p><strong>For complete documentation and demo, please visit <a href="http://wpreloaded.com/plugins/table-sorter/how-to/" target="_blank">WP Table Sorter</a> plugin support page. Happy coding!</strong></p>
96 <?php
97 return ob_get_clean();
98 }