PluginProbe
Polylang / 2.3.2
Polylang v2.3.2
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / settings / table-settings.php

table-settings.php in Polylang 2.3.2, at settings/table-settings.php

183 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! class_exists( 'WP_List_Table' ) ) {
4 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; // since WP 3.1
5 }
6
7 /**
8 * A class to create a table to list all settings modules
9 *
10 * @since 1.8
11 */
12 class PLL_Table_Settings extends WP_List_Table {
13
14 /**
15 * Constructor
16 *
17 * @since 1.8
18 */
19 function __construct() {
20 parent::__construct( array(
21 'plural' => 'Settings', // Do not translate ( used for css class )
22 'ajax' => false,
23 ) );
24 }
25
26 /**
27 * Get the table classes for styling
28 *
29 * @since 1.8
30 */
31 protected function get_table_classes() {
32 return array( 'wp-list-table', 'widefat', 'plugins', 'pll-settings' ); // get the style of the plugins list table + one specific class
33 }
34
35 /**
36 * Displays a single row
37 *
38 * @since 1.8
39 *
40 * @param object $item PLL_Settings_Module object
41 */
42 public function single_row( $item ) {
43 // Classes to reuse css from the plugins list table
44 $classes = $item->is_active() ? 'active' : 'inactive';
45 if ( $message = $item->get_upgrade_message() ) {
46 $classes .= ' update';
47 }
48
49 // Display the columns
50 printf( '<tr id="pll-module-%s" class="%s">', esc_attr( $item->module ), esc_attr( $classes ) );
51 $this->single_row_columns( $item );
52 echo '</tr>';
53
54 // Display an upgrade message if there is any, reusing css from the plugins updates
55 if ( $message = $item->get_upgrade_message() ) {
56 printf( '
57 <tr class="plugin-update-tr">
58 <td colspan="3" class="plugin-update colspanchange">%s</td>
59 </tr>',
60 sprintf(
61 version_compare( $GLOBALS['wp_version'], '4.6', '<' ) ?
62 '<div class="update-message">%s</div>' : // backward compatibility with WP < 4.6
63 '<div class="update-message notice inline notice-warning notice-alt"><p>%s</p></div>',
64 $message
65 )
66 );
67 }
68
69 // The settings if there are
70 // "inactive" class to reuse css from the plugins list table
71 if ( $form = $item->get_form() ) {
72 printf( '
73 <tr id="pll-configure-%s" class="pll-configure inactive inline-edit-row" style="display: none;">
74 <td colspan="3">
75 <legend>%s</legend>
76 %s
77 <p class="submit inline-edit-save">
78 %s
79 </p>
80 </td>
81 </tr>',
82 esc_attr( $item->module ), esc_html( $item->title ), $form, implode( $item->get_buttons() )
83 );
84 }
85 }
86
87 /**
88 * Generates the columns for a single row of the table
89 *
90 * @since 1.8
91 *
92 * @param object $item The current item
93 */
94 protected function single_row_columns( $item ) {
95 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
96
97 foreach ( $columns as $column_name => $column_display_name ) {
98 $classes = "$column_name column-$column_name";
99 if ( $primary === $column_name ) {
100 $classes .= ' column-primary';
101 }
102
103 if ( in_array( $column_name, $hidden ) ) {
104 $classes .= ' hidden';
105 }
106
107 if ( 'cb' == $column_name ) {
108 echo '<th scope="row" class="check-column">';
109 echo $this->column_cb( $item );
110 echo '</th>';
111 }
112 else {
113 printf( '<td class="%s">', esc_attr( $classes ) );
114 echo $this->column_default( $item, $column_name );
115 echo '</td>';
116 }
117 }
118 }
119
120 /**
121 * Displays the item information in a column ( default case )
122 *
123 * @since 1.8
124 *
125 * @param object $item
126 * @param string $column_name
127 * @return string
128 */
129 protected function column_default( $item, $column_name ) {
130 if ( 'plugin-title' == $column_name ) {
131 return sprintf( '<strong>%s</strong>', esc_html( $item->title ) ) . $this->row_actions( $item->get_action_links(), true /*always visible*/ );
132 }
133 return $item->$column_name;
134 }
135
136 /**
137 * Gets the list of columns
138 *
139 * @since 1.8
140 *
141 * @return array the list of column titles
142 */
143 public function get_columns() {
144 return array(
145 'cb' => '', // For the 4px border inherited from plugins when the module is activated
146 'plugin-title' => esc_html__( 'Module', 'polylang' ), // plugin-title for styling
147 'description' => esc_html__( 'Description', 'polylang' ),
148 );
149 }
150
151 /**
152 * Gets the name of the primary column.
153 *
154 * @since 1.8
155 *
156 * @return string The name of the primary column.
157 */
158 protected function get_primary_column_name() {
159 return 'plugin-title';
160 }
161
162 /**
163 * Prepares the list of items for displaying
164 *
165 * @since 1.8
166 *
167 * @param array $items
168 */
169 public function prepare_items( $items = array() ) {
170 $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns(), $this->get_primary_column_name() );
171 $this->items = $items;
172 }
173
174 /**
175 * Avoids displaying an empty tablenav
176 *
177 * @since 2.1
178 *
179 * @param string $which 'top' or 'bottom'
180 */
181 protected function display_tablenav( $which ) {}
182 }
183