7 // Dandy new recursive multiple category stuff.
8 function cat_rows( $parent = 0, $level = 0, $categories = 0 ) {
10 $args = array('hide_empty' => 0);
11 if ( !empty($_GET['s']) )
12 $args['search'] = $_GET['s'];
13 $categories = get_categories( $args );
16 $children = _get_term_hierarchy('category');
20 foreach ( $categories as $category ) {
21 if ( $category->parent == $parent) {
22 echo "\t" . _cat_row( $category, $level );
23 if ( isset($children[$category->term_id]) )
24 cat_rows( $category->term_id, $level +1, $categories );
27 $output = ob_get_contents();
30 $output = apply_filters('cat_rows', $output);
38 function _cat_row( $category, $level, $name_override = false ) {
41 $category = get_category( $category );
43 $pad = str_repeat( '— ', $level );
44 $name = ( $name_override ? $name_override : $pad . ' ' . $category->name );
45 if ( current_user_can( 'manage_categories' ) ) {
46 $edit = "<a class='row-title' href='categories.php?action=edit&cat_ID=$category->term_id' title='" . attribute_escape(sprintf(__('Edit "%s"'), $category->name)) . "'>$name</a>";
51 $class = " class='alternate'" == $class ? '' : " class='alternate'";
53 $category->count = number_format_i18n( $category->count );
54 $posts_count = ( $category->count > 0 ) ? "<a href='edit.php?cat=$category->term_id'>$category->count</a>" : $category->count;
55 $output = "<tr id='cat-$category->term_id'$class>
56 <th scope='row' class='check-column'>";
57 if ( absint(get_option( 'default_category' ) ) != $category->term_id ) {
58 $output .= "<input type='checkbox' name='delete[]' value='$category->term_id' />";
64 <td>$category->description</td>
65 <td class='num'>$posts_count</td>\n\t</tr>\n";
67 return apply_filters('cat_row', $output);
70 function link_cat_row( $category ) {
73 if ( !$category = get_term( $category, 'link_category' ) )
75 if ( is_wp_error( $category ) )
78 $name = ( $name_override ? $name_override : $category->name );
79 if ( current_user_can( 'manage_categories' ) ) {
80 $edit = "<a class='row-title' href='link-category.php?action=edit&cat_ID=$category->term_id' title='" . attribute_escape(sprintf(__('Edit "%s"'), $category->name)) . "' class='edit'>$name</a>";
81 $default_cat_id = (int) get_option( 'default_link_category' );
86 $class = " class='alternate'" == $class ? '' : " class='alternate'";
88 $category->count = number_format_i18n( $category->count );
89 $count = ( $category->count > 0 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count;
90 $output = "<tr id='link-cat-$category->term_id'$class>
91 <th scope='row' class='check-column'>";
92 if ( absint( get_option( 'default_link_category' ) ) != $category->term_id ) {
93 $output .= "<input type='checkbox' name='delete[]' value='$category->term_id' />";
99 <td>$category->description</td>
100 <td class='num'>$count</td></tr>";
102 return apply_filters( 'link_cat_row', $output );
105 function checked( $checked, $current) {
106 if ( $checked == $current)
107 echo ' checked="checked"';
110 function selected( $selected, $current) {
111 if ( $selected == $current)
112 echo ' selected="selected"';
116 // Category Checklists
119 // Deprecated. Use wp_link_category_checklist
120 function dropdown_categories( $default = 0, $parent = 0, $popular_ids = array() ) {
122 wp_category_checklist($post_ID);
125 class Walker_Category_Checklist extends Walker {
126 var $tree_type = 'category';
127 var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
129 function start_lvl(&$output, $depth, $args) {
130 $indent = str_repeat("\t", $depth);
131 $output .= "$indent<ul class='children'>\n";
134 function end_lvl(&$output, $depth, $args) {
135 $indent = str_repeat("\t", $depth);
136 $output .= "$indent</ul>\n";
139 function start_el(&$output, $category, $depth, $args) {
142 $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
143 $output .= "\n<li id='category-$category->term_id'$class>" . '<label for="in-category-' . $category->term_id . '" class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="post_category[]" id="in-category-' . $category->term_id . '"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . '/> ' . wp_specialchars( apply_filters('the_category', $category->name )) . '</label>';
146 function end_el(&$output, $category, $depth, $args) {
147 $output .= "</li>\n";
151 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false ) {
152 $walker = new Walker_Category_Checklist;
153 $descendants_and_self = (int) $descendants_and_self;
158 $args['selected_cats'] = wp_get_post_categories($post_id);
160 $args['selected_cats'] = array();
161 if ( is_array( $selected_cats ) )
162 $args['selected_cats'] = $selected_cats;
163 $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
164 if ( $descendants_and_self ) {
165 $categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" );
166 $self = get_category( $descendants_and_self );
167 array_unshift( $categories, $self );
169 $categories = get_categories('get=all');
172 $args = array($categories, 0, $args);
173 $output = call_user_func_array(array(&$walker, 'walk'), $args);
178 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) {
181 $checked_categories = wp_get_post_categories($post_ID);
183 $checked_categories = array();
184 $categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
186 $popular_ids = array();
187 foreach ( (array) $categories as $category ) {
188 $popular_ids[] = $category->term_id;
189 $id = "popular-category-$category->term_id";
192 <li id="<?php echo $id; ?>" class="popular-category">
193 <label class="selectit" for="in-<?php echo $id; ?>">
194 <input id="in-<?php echo $id; ?>" type="checkbox" value="<?php echo (int) $category->term_id; ?>" />
195 <?php echo wp_specialchars( apply_filters( 'the_category', $category->name ) ); ?>
204 // Deprecated. Use wp_link_category_checklist
205 function dropdown_link_categories( $default = 0 ) {
208 wp_link_category_checklist($link_id);
211 function wp_link_category_checklist( $link_id = 0 ) {
213 $checked_categories = wp_get_link_cats($link_id);
215 if ( count( $checked_categories ) == 0 ) {
216 // No selected categories, strange
217 $checked_categories[] = $default;
220 $checked_categories[] = $default;
223 $categories = get_terms('link_category', 'orderby=count&hide_empty=0');
225 if ( empty($categories) )
228 foreach ( $categories as $category ) {
229 $cat_id = $category->term_id;
230 $name = wp_specialchars( apply_filters('the_category', $category->name));
231 $checked = in_array( $cat_id, $checked_categories );
232 echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', ($checked ? ' checked="checked"' : "" ), '/> ', $name, "</label></li>";
238 // Returns a single tag row (see tag_rows below)
239 // Note: this is also used in admin-ajax.php!
240 function _tag_row( $tag, $class = '' ) {
241 $count = number_format_i18n( $tag->count );
242 $count = ( $count > 0 ) ? "<a href='edit.php?tag=$tag->slug'>$count</a>" : $count;
244 $name = apply_filters( 'term_name', $tag->name );
246 $out .= '<tr id="tag-' . $tag->term_id . '"' . $class . '>';
247 $out .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>';
248 $out .= '<td><strong><a class="row-title" href="edit-tags.php?action=edit&tag_ID=' . $tag->term_id . '" title="' . attribute_escape(sprintf(__('Edit "%s"'), $name)) . '">' .
251 $out .= "<td class='num'>$count</td>";
257 // Outputs appropriate rows for the Nth page of the Tag Management screen,
258 // assuming M tags displayed at a time on the page
259 // Returns the number of tags displayed
260 function tag_rows( $page = 1, $pagesize = 20, $searchterms = '' ) {
262 // Get a page worth of tags
263 $start = ($page - 1) * $pagesize;
265 $args = array('offset' => $start, 'number' => $pagesize, 'hide_empty' => 0);
267 if ( !empty( $searchterms ) ) {
268 $args['search'] = $searchterms;
271 $tags = get_terms( 'post_tag', $args );
273 // convert it to table rows
277 foreach( $tags as $tag )
278 $out .= _tag_row( $tag, ++$count % 2 ? ' class="alternate"' : '' );
280 // filter and send to screen
281 $out = apply_filters('tag_rows', $out);
286 // define the columns to display, the syntax is 'internal name' => 'display name'
287 function wp_manage_posts_columns() {
288 $posts_columns = array();
289 $posts_columns['cb'] = '<input type="checkbox" onclick="checkAll(document.getElementById(\'posts-filter\'));" />';
290 if ( 'draft' === $_GET['post_status'] )
291 $posts_columns['modified'] = __('Modified');
292 elseif ( 'pending' === $_GET['post_status'] )
293 $posts_columns['modified'] = __('Submitted');
295 $posts_columns['date'] = __('Date');
296 $posts_columns['title'] = __('Title');
297 $posts_columns['author'] = __('Author');
298 $posts_columns['categories'] = __('Categories');
299 $posts_columns['tags'] = __('Tags');
300 if ( !in_array($_GET['post_status'], array('pending', 'draft', 'future')) )
301 $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="images/comment-grey-bubble.png" /></div>';
302 $posts_columns['status'] = __('Status');
303 $posts_columns = apply_filters('manage_posts_columns', $posts_columns);
305 return $posts_columns;
308 // define the columns to display, the syntax is 'internal name' => 'display name'
309 function wp_manage_media_columns() {
310 $posts_columns = array();
311 $posts_columns['cb'] = '<input type="checkbox" onclick="checkAll(document.getElementById(\'posts-filter\'));" />';
312 $posts_columns['icon'] = '';
313 $posts_columns['media'] = _c('Media|media column header');
314 $posts_columns['desc'] = _c('Description|media column header');
315 $posts_columns['date'] = _c('Date Added|media column header');
316 $posts_columns['parent'] = _c('Appears with|media column header');
317 $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="images/comment-grey-bubble.png" /></div>';
318 $posts_columns['location'] = _c('Location|media column header');
319 $posts_columns = apply_filters('manage_media_columns', $posts_columns);
321 return $posts_columns;
324 function wp_manage_pages_columns() {
325 $posts_columns = array();
326 $posts_columns['cb'] = '<input type="checkbox" onclick="checkAll(document.getElementById(\'posts-filter\'));" />';
327 if ( 'draft' === $_GET['post_status'] )
328 $posts_columns['modified'] = __('Modified');
329 elseif ( 'pending' === $_GET['post_status'] )
330 $posts_columns['modified'] = __('Submitted');
332 $posts_columns['date'] = __('Date');
333 $posts_columns['title'] = __('Title');
334 $posts_columns['author'] = __('Author');
335 if ( !in_array($_GET['post_status'], array('pending', 'draft', 'future')) )
336 $posts_columns['comments'] = '<div class="vers"><img alt="" src="images/comment-grey-bubble.png" /></div>';
337 $posts_columns['status'] = __('Status');
338 $posts_columns = apply_filters('manage_pages_columns', $posts_columns);
340 return $posts_columns;
344 * display one row if the page doesn't have any children
345 * otherwise, display the row and its children in subsequent rows
347 function display_page_row( $page, &$children_pages, $level = 0 ) {
352 setup_postdata($page);
354 $page->post_title = wp_specialchars( $page->post_title );
355 $pad = str_repeat( '— ', $level );
356 $id = (int) $page->ID;
357 $class = ('alternate' == $class ) ? '' : 'alternate';
358 $posts_columns = wp_manage_pages_columns();
359 $title = get_the_title();
361 $title = __('(no title)');
363 <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
368 foreach ($posts_columns as $column_name=>$column_display_name) {
370 switch ($column_name) {
374 <th scope="row" class="check-column"><input type="checkbox" name="delete[]" value="<?php the_ID(); ?>" /></th>
379 if ( '0000-00-00 00:00:00' == $page->post_date && 'date' == $column_name ) {
380 $t_time = $h_time = __('Unpublished');
382 if ( 'modified' == $column_name ) {
383 $t_time = get_the_modified_time(__('Y/m/d g:i:s A'));
384 $m_time = $page->post_modified;
385 $time = get_post_modified_time('G', true);
387 $t_time = get_the_time(__('Y/m/d g:i:s A'));
388 $m_time = $page->post_date;
389 $time = get_post_time('G', true);
391 if ( ( abs(time() - $time) ) < 86400 ) {
392 if ( ( 'future' == $page->post_status) )
393 $h_time = sprintf( __('%s from now'), human_time_diff( $time ) );
395 $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
397 $h_time = mysql2date(__('Y/m/d'), $m_time);
401 <td><abbr title="<?php echo $t_time ?>"><?php echo $h_time ?></abbr></td>
406 <td><strong><a class="row-title" href="page.php?action=edit&post=<?php the_ID(); ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $title)); ?>"><?php echo $pad; echo $title ?></a></strong>
407 <?php if ('private' == $page->post_status) _e(' — <strong>Private</strong>'); ?></td>
413 <td class="num"><div class="post-com-count-wrapper">
415 $left = get_pending_comments_num( $page->ID );
416 $pending_phrase = sprintf( __('%s pending'), number_format( $left ) );
419 comments_number("<a href='edit-pages.php?page_id=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('0') . '</span></a>', "<a href='edit-pages.php?page_id=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('1') . '</span></a>', "<a href='edit-pages.php?page_id=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('%') . '</span></a>');
429 <td><a href="edit-pages.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
436 <a href="<?php the_permalink(); ?>" title="<?php echo attribute_escape(sprintf(__('View "%s"'), $title)); ?>" rel="permalink">
438 switch ( $page->post_status ) {
447 _e('Pending Review');
461 <td><?php do_action('manage_pages_custom_column', $column_name, $id); ?></td>
472 if ( ! $children_pages )
475 for ( $i = 0; $i < count($children_pages); $i++ ) {
477 $child = $children_pages[$i];
479 if ( $child->post_parent == $id ) {
480 array_splice($children_pages, $i, 1);
481 display_page_row($child, $children_pages, $level+1);
482 $i = -1; //as numeric keys in $children_pages are not preserved after splice
488 * displays pages in hierarchical order
490 function page_rows( $pages ) {
492 $pages = get_pages( 'sort_column=menu_order' );
497 // splice pages into two parts: those without parent and those with parent
499 $top_level_pages = array();
500 $children_pages = array();
502 foreach ( $pages as $page ) {
504 // catch and repair bad pages
505 if ( $page->post_parent == $page->ID ) {
506 $page->post_parent = 0;
507 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $page->ID) );
508 clean_page_cache( $page->ID );
511 if ( 0 == $page->post_parent )
512 $top_level_pages[] = $page;
514 $children_pages[] = $page;
517 foreach ( $top_level_pages as $page )
518 display_page_row($page, $children_pages, 0);
521 * display the remaining children_pages which are orphans
522 * having orphan requires parental attention
524 if ( count($children_pages) > 0 ) {
525 $empty_array = array();
526 foreach ( $children_pages as $orphan_page ) {
527 clean_page_cache( $orphan_page->ID);
528 display_page_row( $orphan_page, $empty_array, 0 );
533 function user_row( $user_object, $style = '', $role = '' ) {
536 $current_user = wp_get_current_user();
538 if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
539 $user_object = new WP_User( (int) $user_object );
540 $email = $user_object->user_email;
541 $url = $user_object->user_url;
542 $short_url = str_replace( 'http://', '', $url );
543 $short_url = str_replace( 'www.', '', $short_url );
544 if ('/' == substr( $short_url, -1 ))
545 $short_url = substr( $short_url, 0, -1 );
546 if ( strlen( $short_url ) > 35 )
547 $short_url = substr( $short_url, 0, 32 ).'...';
548 $numposts = get_usernumposts( $user_object->ID );
549 if ( current_user_can( 'edit_user', $user_object->ID ) ) {
550 if ($current_user->ID == $user_object->ID) {
551 $edit = 'profile.php';
553 $edit = clean_url( add_query_arg( 'wp_http_referer', urlencode( clean_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ) );
555 $edit = "<a href=\"$edit\">$user_object->user_login</a>";
557 $edit = $user_object->user_login;
559 $role_name = translate_with_context($wp_roles->role_names[$role]);
560 $r = "<tr id='user-$user_object->ID'$style>
561 <th scope='row' class='check-column'><input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' /></th>
562 <td><strong>$edit</strong></td>
563 <td>$user_object->first_name $user_object->last_name</td>
564 <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
565 <td>$role_name</td>";
566 $r .= "\n\t\t<td class='num'>";
567 if ( $numposts > 0 ) {
568 $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
574 $r .= "</td>\n\t</tr>";
578 function _wp_get_comment_list( $status = '', $s = false, $start, $num ) {
581 $start = abs( (int) $start );
584 if ( 'moderated' == $status )
585 $approved = "comment_approved = '0'";
586 elseif ( 'approved' == $status )
587 $approved = "comment_approved = '1'";
588 elseif ( 'spam' == $status )
589 $approved = "comment_approved = 'spam'";
591 $approved = "( comment_approved = '0' OR comment_approved = '1' )";
594 $s = $wpdb->escape($s);
595 $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE
596 (comment_author LIKE '%$s%' OR
597 comment_author_email LIKE '%$s%' OR
598 comment_author_url LIKE ('%$s%') OR
599 comment_author_IP LIKE ('%$s%') OR
600 comment_content LIKE ('%$s%') ) AND
602 ORDER BY comment_date_gmt DESC LIMIT $start, $num");
604 $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments USE INDEX (comment_date_gmt) WHERE $approved ORDER BY comment_date_gmt DESC LIMIT $start, $num" );
607 update_comment_cache($comments);
609 $total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
611 return array($comments, $total);
614 function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true ) {
615 global $comment, $post;
616 $comment = get_comment( $comment_id );
617 $post = get_post($comment->comment_post_ID);
618 $authordata = get_userdata($post->post_author);
619 $the_comment_status = wp_get_comment_status($comment->comment_ID);
620 $class = ('unapproved' == $the_comment_status) ? 'unapproved' : '';
622 if ( current_user_can( 'edit_post', $post->ID ) ) {
623 $post_link = "<a href='" . get_comment_link() . "'>";
625 $post_link .= get_the_title($comment->comment_post_ID) . '</a>';
627 $edit_link_start = "<a class='row-title' href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . __('Edit comment') . "'>";
628 $edit_link_end = '</a>';
630 $post_link = get_the_title($comment->comment_post_ID);
631 $edit_link_start = $edit_link_end ='';
634 $author_url = get_comment_author_url();
635 if ( 'http://' == $author_url )
637 $author_url_display = $author_url;
638 if ( strlen($author_url_display) > 50 )
639 $author_url_display = substr($author_url_display, 0, 49) . '...';
641 $ptime = date('G', strtotime( $comment->comment_date ) );
642 if ( ( abs(time() - $ptime) ) < 86400 )
643 $ptime = sprintf( __('%s ago'), human_time_diff( $ptime ) );
645 $ptime = mysql2date(__('Y/m/d \a\t g:i A'), $comment->comment_date );
647 $delete_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
648 $approve_url = clean_url( wp_nonce_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "approve-comment_$comment->comment_ID" ) );
649 $unapprove_url = clean_url( wp_nonce_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "unapprove-comment_$comment->comment_ID" ) );
650 $spam_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&dt=spam&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
653 <tr id="comment-<?php echo $comment->comment_ID; ?>" class='<?php echo $class; ?>'>
654 <?php if ( $checkbox ) : ?>
655 <td class="check-column"><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { ?><input type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /><?php } ?></td>
658 <p class="comment-author"><strong><?php echo $edit_link_start; comment_author(); echo $edit_link_end; ?></strong><br />
659 <?php if ( !empty($author_url) ) : ?>
660 <a href="<?php echo $author_url ?>"><?php echo $author_url_display; ?></a> |
662 <?php if ( current_user_can( 'edit_post', $post->ID ) ) : ?>
663 <?php if ( !empty($comment->comment_author_email) ): ?>
664 <?php comment_author_email_link() ?> |
666 <a href="edit-comments.php?s=<?php comment_author_IP() ?>&mode=detail"><?php comment_author_IP() ?></a>
667 <?php endif; //current_user_can?>
669 <?php if ( 'detail' == $mode ) comment_text(); ?>
670 <p><?php printf(__('From %1$s, %2$s'), $post_link, $ptime) ?></p>
672 <td><?php comment_date(__('Y/m/d')); ?></td>
673 <td class="action-links">
678 $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a> | ';
679 $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a> | ';
681 // we're looking at list of only approved or only unapproved comments
682 if ( 'moderated' == $comment_status ) {
683 $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a> | ';
684 unset($actions['unapprove']);
685 } elseif ( 'approved' == $comment_status ) {
686 $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a> | ';
687 unset($actions['approve']);
690 if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
691 $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1' title='" . __( 'Mark this comment as spam' ) . "'>" . __( 'Spam' ) . '</a> | ';
692 $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete'>" . __('Delete') . '</a>';
693 foreach ( $actions as $action => $link )
694 echo "<span class='$action'>$link</span>";
702 function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {
704 $categories = get_categories( 'hide_empty=0' );
707 foreach ( $categories as $category ) {
708 if ( $currentcat != $category->term_id && $parent == $category->parent) {
709 $pad = str_repeat( '– ', $level );
710 $category->name = wp_specialchars( $category->name );
711 echo "\n\t<option value='$category->term_id'";
712 if ( $currentparent == $category->term_id )
713 echo " selected='selected'";
714 echo ">$pad$category->name</option>";
715 wp_dropdown_cats( $currentcat, $currentparent, $category->term_id, $level +1, $categories );
723 function list_meta( $meta ) {
726 echo '<tbody id="the-list" class="list:meta"><tr style="display: none;"><td> </td></tr></tbody>'; //TBODY needed for list-manipulation JS
733 <th><?php _e( 'Key' ) ?></th>
734 <th><?php _e( 'Value' ) ?></th>
735 <th colspan='2'><?php _e( 'Action' ) ?></th>
738 <tbody id='the-list' class='list:meta'>
740 foreach ( $meta as $entry )
741 echo _list_meta_row( $entry, $count );
745 function _list_meta_row( $entry, &$count ) {
746 static $update_nonce = false;
747 if ( !$update_nonce )
748 $update_nonce = wp_create_nonce( 'add-meta' );
753 $style = 'alternate';
756 if ('_' == $entry['meta_key'] { 0 } )
759 if ( is_serialized( $entry['meta_value'] ) ) {
760 if ( is_serialized_string( $entry['meta_value'] ) ) {
761 // this is a serialized string, so we should display it
762 $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
764 // this is a serialized array/object so we should NOT display it
770 $entry['meta_key'] = attribute_escape($entry['meta_key']);
771 $entry['meta_value'] = htmlspecialchars($entry['meta_value']); // using a <textarea />
772 $entry['meta_id'] = (int) $entry['meta_id'];
774 $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
776 $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
777 $r .= "\n\t\t<td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>";
778 $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>";
779 $r .= "\n\t\t<td style='text-align: center;'><input name='updatemeta' type='submit' tabindex='6' value='".attribute_escape(__( 'Update' ))."' class='add:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$update_nonce updatemeta' /><br />";
780 $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' ";
781 $r .= "class='delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemeta' tabindex='6' value='".attribute_escape(__( 'Delete' ))."' />";
782 $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
783 $r .= "</td>\n\t</tr>";
787 function meta_form() {
789 $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
790 $keys = $wpdb->get_col( "
793 WHERE meta_key NOT LIKE '\_%'
795 ORDER BY meta_id DESC
800 <p><strong><?php _e( 'Add a new custom field:' ) ?></strong></p>
801 <table id="newmeta" cellspacing="3" cellpadding="3">
803 <th colspan="2"><?php _e( 'Key' ) ?></th>
804 <th><?php _e( 'Value' ) ?></th>
807 <td style="width: 18%;" class="textright">
808 <?php if ( $keys ) : ?>
809 <select id="metakeyselect" name="metakeyselect" tabindex="7">
810 <option value="#NONE#"><?php _e( '- Select -' ); ?></option>
813 foreach ( $keys as $key ) {
814 $key = attribute_escape( $key );
815 echo "\n\t<option value='$key'>$key</option>";
818 </select> <?php _e( 'or' ); ?>
821 <td><input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" /></td>
822 <td><textarea id="metavalue" name="metavalue" rows="3" cols="25" tabindex="8"></textarea></td>
824 <tr class="submit"><td colspan="3">
825 <?php wp_nonce_field( 'add-meta', '_ajax_nonce', false ); ?>
826 <input type="submit" id="addmetasub" name="addmeta" class="add:the-list:newmeta::post_id=<?php echo $GLOBALS['post_ID'] ? $GLOBALS['post_ID'] : $GLOBALS['temp_ID']; ?>" tabindex="9" value="<?php _e( 'Add Custom Field' ) ?>" />
833 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) {
834 global $wp_locale, $post, $comment;
837 $edit = ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true;
839 $tab_index_attribute = '';
840 if ( (int) $tab_index > 0 )
841 $tab_index_attribute = " tabindex=\"$tab_index\"";
843 // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
845 $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 );
846 $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
847 $jj = ($edit) ? mysql2date( 'd', $post_date ) : gmdate( 'd', $time_adj );
848 $mm = ($edit) ? mysql2date( 'm', $post_date ) : gmdate( 'm', $time_adj );
849 $aa = ($edit) ? mysql2date( 'Y', $post_date ) : gmdate( 'Y', $time_adj );
850 $hh = ($edit) ? mysql2date( 'H', $post_date ) : gmdate( 'H', $time_adj );
851 $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj );
852 $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj );
854 $month = "<select id=\"mm\" name=\"mm\"$tab_index_attribute>\n";
855 for ( $i = 1; $i < 13; $i = $i +1 ) {
856 $month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
858 $month .= ' selected="selected"';
859 $month .= '>' . $wp_locale->get_month( $i ) . "</option>\n";
861 $month .= '</select>';
863 $day = '<input type="text" id="jj" name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
864 $year = '<input type="text" id="aa" name="aa" value="' . $aa . '" size="4" maxlength="5"' . $tab_index_attribute . ' autocomplete="off" />';
865 $hour = '<input type="text" id="hh" name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
866 $minute = '<input type="text" id="mn" name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
867 printf(_c('%1$s%2$s, %3$s <br />@ %4$s : %5$s|1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input'), $month, $day, $year, $hour, $minute);
869 foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit )
870 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
873 <input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" />
877 function page_template_dropdown( $default = '' ) {
878 $templates = get_page_templates();
880 foreach (array_keys( $templates ) as $template )
881 : if ( $default == $templates[$template] )
882 $selected = " selected='selected'";
885 echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
889 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
890 global $wpdb, $post_ID;
891 $items = $wpdb->get_results( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_type = 'page' ORDER BY menu_order" );
894 foreach ( $items as $item ) {
895 // A page cannot be its own parent.
896 if (!empty ( $post_ID ) ) {
897 if ( $item->ID == $post_ID ) {
901 $pad = str_repeat( ' ', $level * 3 );
902 if ( $item->ID == $default)
903 $current = ' selected="selected"';
907 echo "\n\t<option value='$item->ID'$current>$pad " . wp_specialchars($item->post_title) . "</option>";
908 parent_dropdown( $default, $item->ID, $level +1 );
915 function browse_happy() {
916 $getit = __( 'WordPress recommends a better browser' );
918 <span id="bh" class="alignright"><a href="http://browsehappy.com/" title="'.$getit.'"><img src="images/browse-happy.gif" alt="Browse Happy" /></a></span>
922 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)
923 add_action( 'in_admin_footer', 'browse_happy' );
925 function the_attachment_links( $id = false ) {
927 $post = & get_post( $id );
929 if ( $post->post_type != 'attachment' )
932 $icon = get_attachment_icon( $post->ID );
933 $attachment_data = wp_get_attachment_metadata( $id );
934 $thumb = isset( $attachment_data['thumb'] );
936 <form id="the-attachment-links">
939 <col class="widefat" />
941 <th scope="row"><?php _e( 'URL' ) ?></th>
942 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo wp_get_attachment_url(); ?></textarea></td>
944 <?php if ( $icon ) : ?>
946 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
947 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>"><?php echo $icon ?></a></textarea></td>
950 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
951 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID; ?>"><?php echo $icon ?></a></textarea></td>
955 <th scope="row"><?php _e( 'Link to file' ) ?></th>
956 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>" class="attachmentlink"><?php echo basename( wp_get_attachment_url() ); ?></a></textarea></td>
959 <th scope="row"><?php _e( 'Link to page' ) ?></th>
960 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID ?>"><?php the_title(); ?></a></textarea></td>
968 function wp_dropdown_roles( $default = false ) {
971 foreach( $wp_roles->role_names as $role => $name ) {
972 $name = translate_with_context($name);
973 if ( $default == $role ) // Make default first in list
974 $p = "\n\t<option selected='selected' value='$role'>$name</option>";
976 $r .= "\n\t<option value='$role'>$name</option>";
981 function wp_convert_hr_to_bytes( $size ) {
982 $size = strtolower($size);
983 $bytes = (int) $size;
984 if ( strpos($size, 'k') !== false )
985 $bytes = intval($size) * 1024;
986 elseif ( strpos($size, 'm') !== false )
987 $bytes = intval($size) * 1024 * 1024;
988 elseif ( strpos($size, 'g') !== false )
989 $bytes = intval($size) * 1024 * 1024 * 1024;
993 function wp_convert_bytes_to_hr( $bytes ) {
994 $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
995 $log = log( $bytes, 1024 );
997 $size = pow(1024, $log - $power);
998 return $size . $units[$power];
1001 function wp_max_upload_size() {
1002 $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
1003 $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
1004 $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
1008 function wp_import_upload_form( $action ) {
1009 $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
1010 $size = wp_convert_bytes_to_hr( $bytes );
1012 <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo attribute_escape($action) ?>">
1014 <?php wp_nonce_field('import-upload'); ?>
1015 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
1016 <input type="file" id="upload" name="import" size="25" />
1017 <input type="hidden" name="action" value="save" />
1018 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
1021 <input type="submit" class="button" value="<?php _e( 'Upload file and import' ); ?>" />
1027 function wp_remember_old_slug() {
1029 $name = attribute_escape($post->post_name); // just in case
1030 if ( strlen($name) )
1031 echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />';
1035 * add_meta_box() - Add a meta box to an edit form
1039 * @param string $id String for use in the 'id' attribute of tags.
1040 * @param string $title Title of the meta box
1041 * @param string $callback Function that fills the box with the desired content. The function should echo its output.
1042 * @param string $page The type of edit page on which to show the box (post, page, link)
1043 * @param string $context The context within the page where the boxes should show ('normal', 'advanced')
1045 function add_meta_box($id, $title, $callback, $page, $context = 'advanced') {
1046 global $wp_meta_boxes;
1048 if ( !isset($wp_meta_boxes) )
1049 $wp_meta_boxes = array();
1050 if ( !isset($wp_meta_boxes[$page]) )
1051 $wp_meta_boxes[$page] = array();
1052 if ( !isset($wp_meta_boxes[$page][$context]) )
1053 $wp_meta_boxes[$page][$context] = array();
1055 $wp_meta_boxes[$page][$context][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
1058 function do_meta_boxes($page, $context, $object) {
1059 global $wp_meta_boxes;
1061 if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
1064 foreach ( (array) $wp_meta_boxes[$page][$context] as $box ) {
1065 echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '">' . "\n";
1066 echo "<h3>{$box['title']}</h3>\n";
1067 echo '<div class="inside">' . "\n";
1068 call_user_func($box['callback'], $object, $box);