PluginProbe
Polylang / 2.9
Polylang v2.9
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.9, at settings/table-settings.php

191 lines 4.8 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 object $item PLL_Settings_Module object
46 */
47 public function single_row( $item ) {
48 // Classes to reuse css from the plugins list table
49 $classes = $item->is_active() ? 'active' : 'inactive';
50 if ( $message = $item->get_upgrade_message() ) {
51 $classes .= ' update';
52 }
53
54 // Display the columns
55 printf( '<tr id="pll-module-%s" class="%s">', esc_attr( $item->module ), esc_attr( $classes ) );
56 $this->single_row_columns( $item );
57 echo '</tr>';
58
59 // Display an upgrade message if there is any, reusing css from the plugins updates
60 if ( $message = $item->get_upgrade_message() ) {
61 printf(
62 '<tr class="plugin-update-tr">
63 <td colspan="3" class="plugin-update colspanchange">%s</td>
64 </tr>',
65 sprintf( '<div class="update-message notice inline notice-warning notice-alt"><p>%s</p></div>', $message ) // phpcs:ignore WordPress.Security.EscapeOutput
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 ),
83 esc_html( $item->title ),
84 $form, // phpcs:ignore
85 implode( $item->get_buttons() ) // phpcs:ignore
86 );
87 }
88 }
89
90 /**
91 * Generates the columns for a single row of the table
92 *
93 * @since 1.8
94 *
95 * @param object $item The current item
96 */
97 protected function single_row_columns( $item ) {
98 $column_info = $this->get_column_info();
99 $columns = $column_info[0];
100 $primary = $column_info[3];
101
102 foreach ( array_keys( $columns ) as $column_name ) {
103 $classes = "$column_name column-$column_name";
104 if ( $primary === $column_name ) {
105 $classes .= ' column-primary';
106 }
107
108 if ( 'cb' == $column_name ) {
109 echo '<th scope="row" class="check-column">';
110 echo $this->column_cb( $item ); // phpcs:ignore WordPress.Security.EscapeOutput
111 echo '</th>';
112 } else {
113 printf( '<td class="%s">', esc_attr( $classes ) );
114 echo $this->column_default( $item, $column_name ); // phpcs:ignore WordPress.Security.EscapeOutput
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
172 // Sort rows, lowest priority on top.
173 usort(
174 $items,
175 function( $a, $b ) {
176 return $a->priority > $b->priority ? 1 : -1;
177 }
178 );
179 $this->items = $items;
180 }
181
182 /**
183 * Avoids displaying an empty tablenav
184 *
185 * @since 2.1
186 *
187 * @param string $which 'top' or 'bottom'
188 */
189 protected function display_tablenav( $which ) {} // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
190 }
191