PluginProbe
Polylang / 3.7
Polylang v3.7
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 3.7, at settings/table-settings.php

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