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

180 lines 4.5 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 $column_info = $this->get_column_info();
96 $columns = $column_info[0];
97 $primary = $column_info[3];
98
99 foreach ( array_keys( $columns ) as $column_name ) {
100 $classes = "$column_name column-$column_name";
101 if ( $primary === $column_name ) {
102 $classes .= ' column-primary';
103 }
104
105 if ( 'cb' == $column_name ) {
106 echo '<th scope="row" class="check-column">';
107 echo $this->column_cb( $item ); // phpcs:ignore WordPress.Security.EscapeOutput
108 echo '</th>';
109 } else {
110 printf( '<td class="%s">', esc_attr( $classes ) );
111 echo $this->column_default( $item, $column_name ); // phpcs:ignore WordPress.Security.EscapeOutput
112 echo '</td>';
113 }
114 }
115 }
116
117 /**
118 * Displays the item information in a column ( default case )
119 *
120 * @since 1.8
121 *
122 * @param object $item
123 * @param string $column_name
124 * @return string
125 */
126 protected function column_default( $item, $column_name ) {
127 if ( 'plugin-title' == $column_name ) {
128 return sprintf( '<strong>%s</strong>', esc_html( $item->title ) ) . $this->row_actions( $item->get_action_links(), true /*always visible*/ );
129 }
130 return $item->$column_name;
131 }
132
133 /**
134 * Gets the list of columns
135 *
136 * @since 1.8
137 *
138 * @return array the list of column titles
139 */
140 public function get_columns() {
141 return array(
142 'cb' => '', // For the 4px border inherited from plugins when the module is activated
143 'plugin-title' => esc_html__( 'Module', 'polylang' ), // plugin-title for styling
144 'description' => esc_html__( 'Description', 'polylang' ),
145 );
146 }
147
148 /**
149 * Gets the name of the primary column.
150 *
151 * @since 1.8
152 *
153 * @return string The name of the primary column.
154 */
155 protected function get_primary_column_name() {
156 return 'plugin-title';
157 }
158
159 /**
160 * Prepares the list of items for displaying
161 *
162 * @since 1.8
163 *
164 * @param array $items
165 */
166 public function prepare_items( $items = array() ) {
167 $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns(), $this->get_primary_column_name() );
168 $this->items = $items;
169 }
170
171 /**
172 * Avoids displaying an empty tablenav
173 *
174 * @since 2.1
175 *
176 * @param string $which 'top' or 'bottom'
177 */
178 protected function display_tablenav( $which ) {}
179 }
180