70 <?php |
99 <?php |
71 $dropdown_options = array( |
100 $dropdown_options = array( |
72 'selected' => $cat_id, |
101 'selected' => $cat_id, |
73 'name' => 'cat_id', |
102 'name' => 'cat_id', |
74 'taxonomy' => 'link_category', |
103 'taxonomy' => 'link_category', |
75 'show_option_all' => __( 'All categories' ), |
104 'show_option_all' => get_taxonomy( 'link_category' )->labels->all_items, |
76 'hide_empty' => true, |
105 'hide_empty' => true, |
77 'hierarchical' => 1, |
106 'hierarchical' => 1, |
78 'show_count' => 0, |
107 'show_count' => 0, |
79 'orderby' => 'name', |
108 'orderby' => 'name', |
80 ); |
109 ); |
81 |
110 |
82 echo '<label class="screen-reader-text" for="cat_id">' . __( 'Filter by category' ) . '</label>'; |
111 echo '<label class="screen-reader-text" for="cat_id">' . __( 'Filter by category' ) . '</label>'; |
83 wp_dropdown_categories( $dropdown_options ); |
112 wp_dropdown_categories( $dropdown_options ); |
84 submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); |
113 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); |
85 ?> |
114 ?> |
86 </div> |
115 </div> |
87 <?php |
116 <?php |
88 } |
117 } |
89 |
118 |
|
119 /** |
|
120 * |
|
121 * @return array |
|
122 */ |
90 public function get_columns() { |
123 public function get_columns() { |
91 return array( |
124 return array( |
92 'cb' => '<input type="checkbox" />', |
125 'cb' => '<input type="checkbox" />', |
93 'name' => _x( 'Name', 'link name' ), |
126 'name' => _x( 'Name', 'link name' ), |
94 'url' => __( 'URL' ), |
127 'url' => __( 'URL' ), |
97 'visible' => __( 'Visible' ), |
130 'visible' => __( 'Visible' ), |
98 'rating' => __( 'Rating' ) |
131 'rating' => __( 'Rating' ) |
99 ); |
132 ); |
100 } |
133 } |
101 |
134 |
|
135 /** |
|
136 * |
|
137 * @return array |
|
138 */ |
102 protected function get_sortable_columns() { |
139 protected function get_sortable_columns() { |
103 return array( |
140 return array( |
104 'name' => 'name', |
141 'name' => 'name', |
105 'url' => 'url', |
142 'url' => 'url', |
106 'visible' => 'visible', |
143 'visible' => 'visible', |
107 'rating' => 'rating' |
144 'rating' => 'rating' |
108 ); |
145 ); |
109 } |
146 } |
110 |
147 |
|
148 /** |
|
149 * Get the name of the default primary column. |
|
150 * |
|
151 * @since 4.3.0 |
|
152 * |
|
153 * @return string Name of the default primary column, in this case, 'name'. |
|
154 */ |
|
155 protected function get_default_primary_column_name() { |
|
156 return 'name'; |
|
157 } |
|
158 |
|
159 /** |
|
160 * Handles the checkbox column output. |
|
161 * |
|
162 * @since 4.3.0 |
|
163 * |
|
164 * @param object $link The current link object. |
|
165 */ |
|
166 public function column_cb( $link ) { |
|
167 ?> |
|
168 <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label> |
|
169 <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" /> |
|
170 <?php |
|
171 } |
|
172 |
|
173 /** |
|
174 * Handles the link name column output. |
|
175 * |
|
176 * @since 4.3.0 |
|
177 * |
|
178 * @param object $link The current link object. |
|
179 */ |
|
180 public function column_name( $link ) { |
|
181 $edit_link = get_edit_bookmark_link( $link ); |
|
182 printf( '<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong>', |
|
183 $edit_link, |
|
184 /* translators: %s: link name */ |
|
185 esc_attr( sprintf( __( 'Edit “%s”' ), $link->link_name ) ), |
|
186 $link->link_name |
|
187 ); |
|
188 } |
|
189 |
|
190 /** |
|
191 * Handles the link URL column output. |
|
192 * |
|
193 * @since 4.3.0 |
|
194 * |
|
195 * @param object $link The current link object. |
|
196 */ |
|
197 public function column_url( $link ) { |
|
198 $short_url = url_shorten( $link->link_url ); |
|
199 echo "<a href='$link->link_url'>$short_url</a>"; |
|
200 } |
|
201 |
|
202 /** |
|
203 * Handles the link categories column output. |
|
204 * |
|
205 * @since 4.3.0 |
|
206 * |
|
207 * @global int $cat_id |
|
208 * |
|
209 * @param object $link The current link object. |
|
210 */ |
|
211 public function column_categories( $link ) { |
|
212 global $cat_id; |
|
213 |
|
214 $cat_names = array(); |
|
215 foreach ( $link->link_category as $category ) { |
|
216 $cat = get_term( $category, 'link_category', OBJECT, 'display' ); |
|
217 if ( is_wp_error( $cat ) ) { |
|
218 echo $cat->get_error_message(); |
|
219 } |
|
220 $cat_name = $cat->name; |
|
221 if ( $cat_id != $category ) { |
|
222 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>"; |
|
223 } |
|
224 $cat_names[] = $cat_name; |
|
225 } |
|
226 echo implode( ', ', $cat_names ); |
|
227 } |
|
228 |
|
229 /** |
|
230 * Handles the link relation column output. |
|
231 * |
|
232 * @since 4.3.0 |
|
233 * |
|
234 * @param object $link The current link object. |
|
235 */ |
|
236 public function column_rel( $link ) { |
|
237 echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; |
|
238 } |
|
239 |
|
240 /** |
|
241 * Handles the link visibility column output. |
|
242 * |
|
243 * @since 4.3.0 |
|
244 * |
|
245 * @param object $link The current link object. |
|
246 */ |
|
247 public function column_visible( $link ) { |
|
248 if ( 'Y' === $link->link_visible ) { |
|
249 _e( 'Yes' ); |
|
250 } else { |
|
251 _e( 'No' ); |
|
252 } |
|
253 } |
|
254 |
|
255 /** |
|
256 * Handles the link rating column output. |
|
257 * |
|
258 * @since 4.3.0 |
|
259 * |
|
260 * @param object $link The current link object. |
|
261 */ |
|
262 public function column_rating( $link ) { |
|
263 echo $link->link_rating; |
|
264 } |
|
265 |
|
266 /** |
|
267 * Handles the default column output. |
|
268 * |
|
269 * @since 4.3.0 |
|
270 * |
|
271 * @param object $link Link object. |
|
272 * @param string $column_name Current column name. |
|
273 */ |
|
274 public function column_default( $link, $column_name ) { |
|
275 /** |
|
276 * Fires for each registered custom link column. |
|
277 * |
|
278 * @since 2.1.0 |
|
279 * |
|
280 * @param string $column_name Name of the custom column. |
|
281 * @param int $link_id Link ID. |
|
282 */ |
|
283 do_action( 'manage_link_custom_column', $column_name, $link->link_id ); |
|
284 } |
|
285 |
111 public function display_rows() { |
286 public function display_rows() { |
112 global $cat_id; |
|
113 |
|
114 foreach ( $this->items as $link ) { |
287 foreach ( $this->items as $link ) { |
115 $link = sanitize_bookmark( $link ); |
288 $link = sanitize_bookmark( $link ); |
116 $link->link_name = esc_attr( $link->link_name ); |
289 $link->link_name = esc_attr( $link->link_name ); |
117 $link->link_category = wp_get_link_cats( $link->link_id ); |
290 $link->link_category = wp_get_link_cats( $link->link_id ); |
118 |
|
119 $short_url = url_shorten( $link->link_url ); |
|
120 |
|
121 $visible = ( $link->link_visible == 'Y' ) ? __( 'Yes' ) : __( 'No' ); |
|
122 $rating = $link->link_rating; |
|
123 |
|
124 $edit_link = get_edit_bookmark_link( $link ); |
|
125 ?> |
291 ?> |
126 <tr id="link-<?php echo $link->link_id; ?>"> |
292 <tr id="link-<?php echo $link->link_id; ?>"> |
127 <?php |
293 <?php $this->single_row_columns( $link ) ?> |
128 |
|
129 list( $columns, $hidden ) = $this->get_column_info(); |
|
130 |
|
131 foreach ( $columns as $column_name => $column_display_name ) { |
|
132 $class = "class='column-$column_name'"; |
|
133 |
|
134 $style = ''; |
|
135 if ( in_array( $column_name, $hidden ) ) |
|
136 $style = ' style="display:none;"'; |
|
137 |
|
138 $attributes = $class . $style; |
|
139 |
|
140 switch ( $column_name ) { |
|
141 case 'cb': ?> |
|
142 <th scope="row" class="check-column"> |
|
143 <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"><?php echo sprintf( __( 'Select %s' ), $link->link_name ); ?></label> |
|
144 <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" /> |
|
145 </th> |
|
146 <?php |
|
147 break; |
|
148 |
|
149 case 'name': |
|
150 echo "<td $attributes><strong><a class='row-title' href='$edit_link' title='" . esc_attr( sprintf( __( 'Edit “%s”' ), $link->link_name ) ) . "'>$link->link_name</a></strong><br />"; |
|
151 |
|
152 $actions = array(); |
|
153 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; |
|
154 $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ) . "' onclick=\"if ( confirm( '" . esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ) . "' ) ) { return true;}return false;\">" . __( 'Delete' ) . "</a>"; |
|
155 echo $this->row_actions( $actions ); |
|
156 |
|
157 echo '</td>'; |
|
158 break; |
|
159 case 'url': |
|
160 echo "<td $attributes><a href='$link->link_url' title='". esc_attr( sprintf( __( 'Visit %s' ), $link->link_name ) )."'>$short_url</a></td>"; |
|
161 break; |
|
162 case 'categories': |
|
163 ?><td <?php echo $attributes ?>><?php |
|
164 $cat_names = array(); |
|
165 foreach ( $link->link_category as $category ) { |
|
166 $cat = get_term( $category, 'link_category', OBJECT, 'display' ); |
|
167 if ( is_wp_error( $cat ) ) |
|
168 echo $cat->get_error_message(); |
|
169 $cat_name = $cat->name; |
|
170 if ( $cat_id != $category ) |
|
171 $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>"; |
|
172 $cat_names[] = $cat_name; |
|
173 } |
|
174 echo implode( ', ', $cat_names ); |
|
175 ?></td><?php |
|
176 break; |
|
177 case 'rel': |
|
178 ?><td <?php echo $attributes ?>><?php echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; ?></td><?php |
|
179 break; |
|
180 case 'visible': |
|
181 ?><td <?php echo $attributes ?>><?php echo $visible; ?></td><?php |
|
182 break; |
|
183 case 'rating': |
|
184 ?><td <?php echo $attributes ?>><?php echo $rating; ?></td><?php |
|
185 break; |
|
186 default: |
|
187 ?> |
|
188 <td <?php echo $attributes ?>><?php |
|
189 /** |
|
190 * Fires for each registered custom link column. |
|
191 * |
|
192 * @since 2.1.0 |
|
193 * |
|
194 * @param string $column_name Name of the custom column. |
|
195 * @param int $link_id Link ID. |
|
196 */ |
|
197 do_action( 'manage_link_custom_column', $column_name, $link->link_id ); |
|
198 ?></td> |
|
199 <?php |
|
200 break; |
|
201 } |
|
202 } |
|
203 ?> |
|
204 </tr> |
294 </tr> |
205 <?php |
295 <?php |
206 } |
296 } |
207 } |
297 } |
|
298 |
|
299 /** |
|
300 * Generates and displays row action links. |
|
301 * |
|
302 * @since 4.3.0 |
|
303 * |
|
304 * @param object $link Link being acted upon. |
|
305 * @param string $column_name Current column name. |
|
306 * @param string $primary Primary column name. |
|
307 * @return string Row action output for links. |
|
308 */ |
|
309 protected function handle_row_actions( $link, $column_name, $primary ) { |
|
310 if ( $primary !== $column_name ) { |
|
311 return ''; |
|
312 } |
|
313 |
|
314 $edit_link = get_edit_bookmark_link( $link ); |
|
315 |
|
316 $actions = array(); |
|
317 $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>'; |
|
318 $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id) . "' onclick=\"if ( confirm( '" . esc_js(sprintf(__("You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete."), $link->link_name)) . "' ) ) { return true;}return false;\">" . __('Delete') . "</a>"; |
|
319 return $this->row_actions( $actions ); |
|
320 } |
208 } |
321 } |