PluginProbe
Polylang / 2.6.2
Polylang v2.6.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.6.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 public function __construct() {
20 parent::__construct(
21 array(
22 'plural' => 'Settings', // Do not translate ( used for css class )
23 'ajax' => false,
24 )
25 );
26 }
27
28 /**
29 * Get the table classes for styling
30 *
31 * @since 1.8
32 */
33 protected function get_table_classes() {
34 return array( 'wp-list-table', 'widefat', 'plugins', 'pll-settings' ); // get the style of the plugins list table + one specific class
35 }
36
37 /**
38 * Displays a single row
39 *
40 * @since 1.8
41 *
42 * @param object $item PLL_Settings_Module object
43 */
44 public function single_row( $item ) {
45 // Classes to reuse css from the plugins list table
46 $classes = $item->is_active() ? 'active' : 'inactive';
47 if ( $message = $item->get_upgrade_message() ) {
48 $classes .= ' update';
49 }
50
51 // Display the columns
52 printf( '<tr id="pll-module-%s" class="%s">', esc_attr( $item->module ), esc_attr( $classes ) );
53 $this->single_row_columns( $item );
54 echo '</tr>';
55
56 // Display an upgrade message if there is any, reusing css from the plugins updates
57 if ( $message = $item->get_upgrade_message() ) {
58 printf(
59 '<tr class="plugin-update-tr">
60 <td colspan="3" class="plugin-update colspanchange">%s</td>
61 </tr>',
62 sprintf( '<div class="update-message notice inline notice-warning notice-alt"><p>%s</p></div>', $message ) // phpcs:ignore WordPress.Security.EscapeOutput
63 );
64 }
65
66 // The settings if there are
67 // "inactive" class to reuse css from the plugins list table
68 if ( $form = $item->get_form() ) {
69 printf(
70 '<tr id="pll-configure-%s" class="pll-configure inactive inline-edit-row" style="display: none;">
71 <td colspan="3">
72 <legend>%s</legend>
73 %s
74 <p class="submit inline-edit-save">
75 %s
76 </p>
77 </td>
78 </tr>',
79 esc_attr( $item->module ),
80 esc_html( $item->title ),
81 $form, // phpcs:ignore
82 implode( $item->get_buttons() ) // phpcs:ignore
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 ); // phpcs:ignore WordPress.Security.EscapeOutput
110 echo '</th>';
111 }
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 $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