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

183 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 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 * Added for backward compatibility with WP < 4.2
122 *
123 * @since 1.8.2
124 *
125 * @param object $item
126 */
127 protected function column_cb( $item ) {}
128
129 /**
130 * Displays the item information in a column ( default case )
131 *
132 * @since 1.8
133 *
134 * @param object $item
135 * @param string $column_name
136 * @return string
137 */
138 protected function column_default( $item, $column_name ) {
139 if ( 'plugin-title' == $column_name ) {
140 return sprintf( '<strong>%s</strong>', esc_html( $item->title ) ) . $this->row_actions( $item->get_action_links(), true /*always visible*/ );
141 }
142 return $item->$column_name;
143 }
144
145 /**
146 * Gets the list of columns
147 *
148 * @since 1.8
149 *
150 * @return array the list of column titles
151 */
152 public function get_columns() {
153 return array(
154 'cb' => '', // For the 4px border inherited from plugins when the module is activated
155 'plugin-title' => esc_html__( 'Module', 'polylang' ), // plugin-title for styling
156 'description' => esc_html__( 'Description', 'polylang' ),
157 );
158 }
159
160 /**
161 * Gets the name of the primary column.
162 *
163 * @since 1.8
164 *
165 * @return string The name of the primary column.
166 */
167 protected function get_primary_column_name() {
168 return 'plugin-title';
169 }
170
171 /**
172 * Prepares the list of items for displaying
173 *
174 * @since 1.8
175 *
176 * @param array $items
177 */
178 public function prepare_items( $items = array() ) {
179 $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns(), $this->get_primary_column_name() );
180 $this->items = $items;
181 }
182 }
183