7 // Ugly recursive category stuff.
8 function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20 ) {
10 _cat_rows($categories, $count, $parent, $level, $page, $per_page);
13 function _cat_rows( $categories, &$count, $parent = 0, $level = 0, $page = 1, $per_page = 20 ) {
14 if ( empty($categories) ) {
15 $args = array('hide_empty' => 0);
16 if ( !empty($_GET['s']) )
17 $args['search'] = $_GET['s'];
18 $categories = get_categories( $args );
24 $children = _get_term_hierarchy('category');
26 $start = ($page - 1) * $per_page;
27 $end = $start + $per_page;
30 foreach ( $categories as $category ) {
36 if ( $category->parent != $parent )
39 // If the page starts in a subtree, print the parents.
40 if ( $count == $start && $category->parent > 0 ) {
41 $my_parents = array();
42 $my_parent = $category->parent;
44 $my_parent = get_category($my_parent);
45 $my_parents[] = $my_parent;
46 if ( !$my_parent->parent )
48 $my_parent = $my_parent->parent;
50 $num_parents = count($my_parents);
51 while( $my_parent = array_pop($my_parents) ) {
52 echo "\t" . _cat_row( $my_parent, $level - $num_parents );
57 if ( $count >= $start )
58 echo "\t" . _cat_row( $category, $level );
60 unset($categories[$i]); // Prune the working set
63 if ( isset($children[$category->term_id]) )
64 _cat_rows( $categories, $count, $category->term_id, $level + 1, $page, $per_page );
68 $output = ob_get_contents();
71 $output = apply_filters('cat_rows', $output);
76 function _cat_row( $category, $level, $name_override = false ) {
79 $category = get_category( $category );
81 $pad = str_repeat( '— ', $level );
82 $name = ( $name_override ? $name_override : $pad . ' ' . $category->name );
83 if ( current_user_can( 'manage_categories' ) ) {
84 $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>";
89 $class = " class='alternate'" == $class ? '' : " class='alternate'";
91 $category->count = number_format_i18n( $category->count );
92 $posts_count = ( $category->count > 0 ) ? "<a href='edit.php?cat=$category->term_id'>$category->count</a>" : $category->count;
93 $output = "<tr id='cat-$category->term_id'$class>
94 <th scope='row' class='check-column'>";
95 if ( absint(get_option( 'default_category' ) ) != $category->term_id ) {
96 $output .= "<input type='checkbox' name='delete[]' value='$category->term_id' />";
102 <td>$category->description</td>
103 <td class='num'>$posts_count</td>\n\t</tr>\n";
105 return apply_filters('cat_row', $output);
108 function link_cat_row( $category ) {
111 if ( !$category = get_term( $category, 'link_category' ) )
113 if ( is_wp_error( $category ) )
116 $name = ( $name_override ? $name_override : $category->name );
117 if ( current_user_can( 'manage_categories' ) ) {
118 $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>";
119 $default_cat_id = (int) get_option( 'default_link_category' );
124 $class = " class='alternate'" == $class ? '' : " class='alternate'";
126 $category->count = number_format_i18n( $category->count );
127 $count = ( $category->count > 0 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count;
128 $output = "<tr id='link-cat-$category->term_id'$class>
129 <th scope='row' class='check-column'>";
130 if ( absint( get_option( 'default_link_category' ) ) != $category->term_id ) {
131 $output .= "<input type='checkbox' name='delete[]' value='$category->term_id' />";
137 <td>$category->description</td>
138 <td class='num'>$count</td></tr>";
140 return apply_filters( 'link_cat_row', $output );
143 function checked( $checked, $current) {
144 if ( $checked == $current)
145 echo ' checked="checked"';
148 function selected( $selected, $current) {
149 if ( $selected == $current)
150 echo ' selected="selected"';
154 // Category Checklists
157 // Deprecated. Use wp_link_category_checklist
158 function dropdown_categories( $default = 0, $parent = 0, $popular_ids = array() ) {
160 wp_category_checklist($post_ID);
163 class Walker_Category_Checklist extends Walker {
164 var $tree_type = 'category';
165 var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
167 function start_lvl(&$output, $depth, $args) {
168 $indent = str_repeat("\t", $depth);
169 $output .= "$indent<ul class='children'>\n";
172 function end_lvl(&$output, $depth, $args) {
173 $indent = str_repeat("\t", $depth);
174 $output .= "$indent</ul>\n";
177 function start_el(&$output, $category, $depth, $args) {
180 $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
181 $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>';
184 function end_el(&$output, $category, $depth, $args) {
185 $output .= "</li>\n";
189 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false ) {
190 $walker = new Walker_Category_Checklist;
191 $descendants_and_self = (int) $descendants_and_self;
195 if ( is_array( $selected_cats ) )
196 $args['selected_cats'] = $selected_cats;
198 $args['selected_cats'] = wp_get_post_categories($post_id);
200 $args['selected_cats'] = array();
202 if ( is_array( $popular_cats ) )
203 $args['popular_cats'] = $popular_cats;
205 $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
207 if ( $descendants_and_self ) {
208 $categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" );
209 $self = get_category( $descendants_and_self );
210 array_unshift( $categories, $self );
212 $categories = get_categories('get=all');
215 // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
216 $checked_categories = array();
217 for ( $i = 0; isset($categories[$i]); $i++ ) {
218 if ( in_array($categories[$i]->term_id, $args['selected_cats']) ) {
219 $checked_categories[] = $categories[$i];
220 unset($categories[$i]);
224 // Put checked cats on top
225 echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
226 // Then the rest of them
227 echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
230 function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
233 $checked_categories = wp_get_post_categories($post_ID);
235 $checked_categories = array();
236 $categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
238 $popular_ids = array();
239 foreach ( (array) $categories as $category ) {
240 $popular_ids[] = $category->term_id;
241 if ( !$echo ) // hack for AJAX use
243 $id = "popular-category-$category->term_id";
246 <li id="<?php echo $id; ?>" class="popular-category">
247 <label class="selectit" for="in-<?php echo $id; ?>">
248 <input id="in-<?php echo $id; ?>" type="checkbox" value="<?php echo (int) $category->term_id; ?>" />
249 <?php echo wp_specialchars( apply_filters( 'the_category', $category->name ) ); ?>
258 // Deprecated. Use wp_link_category_checklist
259 function dropdown_link_categories( $default = 0 ) {
262 wp_link_category_checklist($link_id);
265 function wp_link_category_checklist( $link_id = 0 ) {
267 $checked_categories = wp_get_link_cats($link_id);
269 if ( count( $checked_categories ) == 0 ) {
270 // No selected categories, strange
271 $checked_categories[] = $default;
274 $checked_categories[] = $default;
277 $categories = get_terms('link_category', 'orderby=count&hide_empty=0');
279 if ( empty($categories) )
282 foreach ( $categories as $category ) {
283 $cat_id = $category->term_id;
284 $name = wp_specialchars( apply_filters('the_category', $category->name));
285 $checked = in_array( $cat_id, $checked_categories );
286 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>";
292 // Returns a single tag row (see tag_rows below)
293 // Note: this is also used in admin-ajax.php!
294 function _tag_row( $tag, $class = '' ) {
295 $count = number_format_i18n( $tag->count );
296 $count = ( $count > 0 ) ? "<a href='edit.php?tag=$tag->slug'>$count</a>" : $count;
298 $name = apply_filters( 'term_name', $tag->name );
300 $out .= '<tr id="tag-' . $tag->term_id . '"' . $class . '>';
301 $out .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>';
302 $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)) . '">' .
305 $out .= "<td class='num'>$count</td>";
311 // Outputs appropriate rows for the Nth page of the Tag Management screen,
312 // assuming M tags displayed at a time on the page
313 // Returns the number of tags displayed
314 function tag_rows( $page = 1, $pagesize = 20, $searchterms = '' ) {
316 // Get a page worth of tags
317 $start = ($page - 1) * $pagesize;
319 $args = array('offset' => $start, 'number' => $pagesize, 'hide_empty' => 0);
321 if ( !empty( $searchterms ) ) {
322 $args['search'] = $searchterms;
325 $tags = get_terms( 'post_tag', $args );
327 // convert it to table rows
331 foreach( $tags as $tag )
332 $out .= _tag_row( $tag, ++$count % 2 ? ' class="alternate"' : '' );
334 // filter and send to screen
335 $out = apply_filters('tag_rows', $out);
340 // define the columns to display, the syntax is 'internal name' => 'display name'
341 function wp_manage_posts_columns() {
342 $posts_columns = array();
343 $posts_columns['cb'] = '<input type="checkbox" />';
344 if ( 'draft' === $_GET['post_status'] )
345 $posts_columns['modified'] = __('Modified');
346 elseif ( 'pending' === $_GET['post_status'] )
347 $posts_columns['modified'] = __('Submitted');
349 $posts_columns['date'] = __('Date');
350 $posts_columns['title'] = __('Title');
351 $posts_columns['author'] = __('Author');
352 $posts_columns['categories'] = __('Categories');
353 $posts_columns['tags'] = __('Tags');
354 if ( !in_array($_GET['post_status'], array('pending', 'draft', 'future')) )
355 $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="images/comment-grey-bubble.png" /></div>';
356 $posts_columns['status'] = __('Status');
357 $posts_columns = apply_filters('manage_posts_columns', $posts_columns);
359 return $posts_columns;
362 // define the columns to display, the syntax is 'internal name' => 'display name'
363 function wp_manage_media_columns() {
364 $posts_columns = array();
365 $posts_columns['cb'] = '<input type="checkbox" />';
366 $posts_columns['icon'] = '';
367 $posts_columns['media'] = _c('Media|media column header');
368 $posts_columns['desc'] = _c('Description|media column header');
369 $posts_columns['date'] = _c('Date Added|media column header');
370 $posts_columns['parent'] = _c('Appears with|media column header');
371 $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="images/comment-grey-bubble.png" /></div>';
372 $posts_columns['location'] = _c('Location|media column header');
373 $posts_columns = apply_filters('manage_media_columns', $posts_columns);
375 return $posts_columns;
378 function wp_manage_pages_columns() {
379 $posts_columns = array();
380 $posts_columns['cb'] = '<input type="checkbox" />';
381 if ( 'draft' === $_GET['post_status'] )
382 $posts_columns['modified'] = __('Modified');
383 elseif ( 'pending' === $_GET['post_status'] )
384 $posts_columns['modified'] = __('Submitted');
386 $posts_columns['date'] = __('Date');
387 $posts_columns['title'] = __('Title');
388 $posts_columns['author'] = __('Author');
389 if ( !in_array($_GET['post_status'], array('pending', 'draft', 'future')) )
390 $posts_columns['comments'] = '<div class="vers"><img alt="" src="images/comment-grey-bubble.png" /></div>';
391 $posts_columns['status'] = __('Status');
392 $posts_columns = apply_filters('manage_pages_columns', $posts_columns);
394 return $posts_columns;
398 * display one row if the page doesn't have any children
399 * otherwise, display the row and its children in subsequent rows
401 function display_page_row( $page, $level = 0 ) {
406 setup_postdata($page);
408 $page->post_title = wp_specialchars( $page->post_title );
409 $pad = str_repeat( '— ', $level );
410 $id = (int) $page->ID;
411 $class = ('alternate' == $class ) ? '' : 'alternate';
412 $posts_columns = wp_manage_pages_columns();
413 $title = get_the_title();
415 $title = __('(no title)');
417 <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
422 foreach ($posts_columns as $column_name=>$column_display_name) {
424 switch ($column_name) {
428 <th scope="row" class="check-column"><input type="checkbox" name="delete[]" value="<?php the_ID(); ?>" /></th>
433 if ( '0000-00-00 00:00:00' == $page->post_date && 'date' == $column_name ) {
434 $t_time = $h_time = __('Unpublished');
436 if ( 'modified' == $column_name ) {
437 $t_time = get_the_modified_time(__('Y/m/d g:i:s A'));
438 $m_time = $page->post_modified;
439 $time = get_post_modified_time('G', true);
441 $t_time = get_the_time(__('Y/m/d g:i:s A'));
442 $m_time = $page->post_date;
443 $time = get_post_time('G', true);
445 if ( ( abs(time() - $time) ) < 86400 ) {
446 if ( ( 'future' == $page->post_status) )
447 $h_time = sprintf( __('%s from now'), human_time_diff( $time ) );
449 $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
451 $h_time = mysql2date(__('Y/m/d'), $m_time);
455 <td><abbr title="<?php echo $t_time ?>"><?php echo $h_time ?></abbr></td>
460 <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>
461 <?php if ('private' == $page->post_status) _e(' — <strong>Private</strong>'); ?></td>
467 <td class="num"><div class="post-com-count-wrapper">
469 $left = get_pending_comments_num( $page->ID );
470 $pending_phrase = sprintf( __('%s pending'), number_format( $left ) );
473 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>');
483 <td><a href="edit-pages.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
490 <a href="<?php the_permalink(); ?>" title="<?php echo attribute_escape(sprintf(__('View "%s"'), $title)); ?>" rel="permalink">
492 switch ( $page->post_status ) {
501 _e('Pending Review');
515 <td><?php do_action('manage_pages_custom_column', $column_name, $id); ?></td>
528 * displays pages in hierarchical order with paging support
530 function page_rows($pages, $pagenum = 1, $per_page = 20) {
534 $pages = get_pages( array('sort_column' => 'menu_order') );
541 * arrange pages into two parts: top level pages and children_pages
542 * children_pages is two dimensional array, eg.
543 * children_pages[10][] contains all sub-pages whose parent is 10.
544 * It only takes O(N) to arrange this and it takes O(1) for subsequent lookup operations
545 * If searching, ignore hierarchy and treat everything as top level
547 if ( empty($_GET['s']) ) {
549 $top_level_pages = array();
550 $children_pages = array();
552 foreach ( $pages as $page ) {
554 // catch and repair bad pages
555 if ( $page->post_parent == $page->ID ) {
556 $page->post_parent = 0;
557 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $page->ID) );
558 clean_page_cache( $page->ID );
561 if ( 0 == $page->post_parent )
562 $top_level_pages[] = $page;
564 $children_pages[ $page->post_parent ][] = $page;
567 $pages = &$top_level_pages;
571 $start = ($pagenum - 1) * $per_page;
572 $end = $start + $per_page;
574 foreach ( $pages as $page ) {
575 if ( $count >= $end )
578 if ( $count >= $start )
579 echo "\t" . display_page_row( $page, $level );
583 if ( isset($children_pages) )
584 _page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
587 // if it is the last pagenum and there are orphaned pages, display them with paging as well
588 if ( isset($children_pages) && $count < $end ){
589 foreach( $children_pages as $orphans ){
590 foreach ( $orphans as $op ) {
591 if ( $count >= $end )
593 if ( $count >= $start )
594 echo "\t" . display_page_row( $op, 0 );
602 * Given a top level page ID, display the nested hierarchy of sub-pages
603 * together with paging support
605 function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) {
607 if ( ! isset( $children_pages[$parent] ) )
610 $start = ($pagenum - 1) * $per_page;
611 $end = $start + $per_page;
613 foreach ( $children_pages[$parent] as $page ) {
615 if ( $count >= $end )
618 // If the page starts in a subtree, print the parents.
619 if ( $count == $start && $page->post_parent > 0 ) {
620 $my_parents = array();
621 $my_parent = $page->post_parent;
622 while ( $my_parent) {
623 $my_parent = get_post($my_parent);
624 $my_parents[] = $my_parent;
625 if ( !$my_parent->post_parent )
627 $my_parent = $my_parent->post_parent;
629 $num_parents = count($my_parents);
630 while( $my_parent = array_pop($my_parents) ) {
631 echo "\t" . display_page_row( $my_parent, $level - $num_parents );
636 if ( $count >= $start )
637 echo "\t" . display_page_row( $page, $level );
641 _page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
644 unset( $children_pages[$parent] ); //required in order to keep track of orphans
647 function user_row( $user_object, $style = '', $role = '' ) {
650 $current_user = wp_get_current_user();
652 if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
653 $user_object = new WP_User( (int) $user_object );
654 $email = $user_object->user_email;
655 $url = $user_object->user_url;
656 $short_url = str_replace( 'http://', '', $url );
657 $short_url = str_replace( 'www.', '', $short_url );
658 if ('/' == substr( $short_url, -1 ))
659 $short_url = substr( $short_url, 0, -1 );
660 if ( strlen( $short_url ) > 35 )
661 $short_url = substr( $short_url, 0, 32 ).'...';
662 $numposts = get_usernumposts( $user_object->ID );
663 if ( current_user_can( 'edit_user', $user_object->ID ) ) {
664 if ($current_user->ID == $user_object->ID) {
665 $edit = 'profile.php';
667 $edit = clean_url( add_query_arg( 'wp_http_referer', urlencode( clean_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ) );
669 $edit = "<a href=\"$edit\">$user_object->user_login</a>";
671 $edit = $user_object->user_login;
673 $role_name = $wp_roles->role_names[$role] ? translate_with_context($wp_roles->role_names[$role]) : __('None');
674 $r = "<tr id='user-$user_object->ID'$style>
675 <th scope='row' class='check-column'><input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' /></th>
676 <td><strong>$edit</strong></td>
677 <td>$user_object->first_name $user_object->last_name</td>
678 <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
679 <td>$role_name</td>";
680 $r .= "\n\t\t<td class='num'>";
681 if ( $numposts > 0 ) {
682 $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
688 $r .= "</td>\n\t</tr>";
692 function _wp_get_comment_list( $status = '', $s = false, $start, $num ) {
695 $start = abs( (int) $start );
698 if ( 'moderated' == $status )
699 $approved = "comment_approved = '0'";
700 elseif ( 'approved' == $status )
701 $approved = "comment_approved = '1'";
702 elseif ( 'spam' == $status )
703 $approved = "comment_approved = 'spam'";
705 $approved = "( comment_approved = '0' OR comment_approved = '1' )";
708 $s = $wpdb->escape($s);
709 $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE
710 (comment_author LIKE '%$s%' OR
711 comment_author_email LIKE '%$s%' OR
712 comment_author_url LIKE ('%$s%') OR
713 comment_author_IP LIKE ('%$s%') OR
714 comment_content LIKE ('%$s%') ) AND
716 ORDER BY comment_date_gmt DESC LIMIT $start, $num");
718 $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE $approved ORDER BY comment_date_gmt DESC LIMIT $start, $num" );
721 update_comment_cache($comments);
723 $total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
725 return array($comments, $total);
728 function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true ) {
729 global $comment, $post;
730 $comment = get_comment( $comment_id );
731 $post = get_post($comment->comment_post_ID);
732 $authordata = get_userdata($post->post_author);
733 $the_comment_status = wp_get_comment_status($comment->comment_ID);
734 $class = ('unapproved' == $the_comment_status) ? 'unapproved' : '';
736 if ( current_user_can( 'edit_post', $post->ID ) ) {
737 $post_link = "<a href='" . get_comment_link() . "'>";
739 $post_link .= get_the_title($comment->comment_post_ID) . '</a>';
741 $edit_link_start = "<a class='row-title' href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . __('Edit comment') . "'>";
742 $edit_link_end = '</a>';
744 $post_link = get_the_title($comment->comment_post_ID);
745 $edit_link_start = $edit_link_end ='';
748 $author_url = get_comment_author_url();
749 if ( 'http://' == $author_url )
751 $author_url_display = $author_url;
752 if ( strlen($author_url_display) > 50 )
753 $author_url_display = substr($author_url_display, 0, 49) . '...';
755 $ptime = date('G', strtotime( $comment->comment_date ) );
756 if ( ( abs(time() - $ptime) ) < 86400 )
757 $ptime = sprintf( __('%s ago'), human_time_diff( $ptime ) );
759 $ptime = mysql2date(__('Y/m/d \a\t g:i A'), $comment->comment_date );
761 $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" ) );
762 $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" ) );
763 $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" ) );
764 $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" ) );
767 <tr id="comment-<?php echo $comment->comment_ID; ?>" class='<?php echo $class; ?>'>
768 <?php if ( $checkbox ) : ?>
769 <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>
772 <p class="comment-author"><strong><?php echo $edit_link_start; comment_author(); echo $edit_link_end; ?></strong><br />
773 <?php if ( !empty($author_url) ) : ?>
774 <a href="<?php echo $author_url ?>"><?php echo $author_url_display; ?></a> |
776 <?php if ( current_user_can( 'edit_post', $post->ID ) ) : ?>
777 <?php if ( !empty($comment->comment_author_email) ): ?>
778 <?php comment_author_email_link() ?> |
780 <a href="edit-comments.php?s=<?php comment_author_IP() ?>&mode=detail"><?php comment_author_IP() ?></a>
781 <?php endif; //current_user_can?>
783 <?php if ( 'detail' == $mode ) comment_text(); ?>
784 <p><?php printf(__('From %1$s, %2$s'), $post_link, $ptime) ?></p>
786 <td><?php comment_date(__('Y/m/d')); ?></td>
787 <td class="action-links">
792 if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
793 $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a> | ';
794 $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a> | ';
796 // we're looking at list of only approved or only unapproved comments
797 if ( 'moderated' == $comment_status ) {
798 $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=approved' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a> | ';
799 unset($actions['unapprove']);
800 } elseif ( 'approved' == $comment_status ) {
801 $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=unapproved' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a> | ';
802 unset($actions['approve']);
805 $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> | ';
806 $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete'>" . __('Delete') . '</a>';
807 $actions = apply_filters( 'comment_row_actions', $actions, $comment );
808 foreach ( $actions as $action => $link )
809 echo "<span class='$action'>$link</span>";
817 function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {
819 $categories = get_categories( array('hide_empty' => 0) );
822 foreach ( $categories as $category ) {
823 if ( $currentcat != $category->term_id && $parent == $category->parent) {
824 $pad = str_repeat( '– ', $level );
825 $category->name = wp_specialchars( $category->name );
826 echo "\n\t<option value='$category->term_id'";
827 if ( $currentparent == $category->term_id )
828 echo " selected='selected'";
829 echo ">$pad$category->name</option>";
830 wp_dropdown_cats( $currentcat, $currentparent, $category->term_id, $level +1, $categories );
838 function list_meta( $meta ) {
841 echo '<tbody id="the-list" class="list:meta"><tr style="display: none;"><td> </td></tr></tbody>'; //TBODY needed for list-manipulation JS
848 <th><?php _e( 'Key' ) ?></th>
849 <th><?php _e( 'Value' ) ?></th>
850 <th colspan='2'><?php _e( 'Action' ) ?></th>
853 <tbody id='the-list' class='list:meta'>
855 foreach ( $meta as $entry )
856 echo _list_meta_row( $entry, $count );
860 function _list_meta_row( $entry, &$count ) {
861 static $update_nonce = false;
862 if ( !$update_nonce )
863 $update_nonce = wp_create_nonce( 'add-meta' );
868 $style = 'alternate';
871 if ('_' == $entry['meta_key'] { 0 } )
874 if ( is_serialized( $entry['meta_value'] ) ) {
875 if ( is_serialized_string( $entry['meta_value'] ) ) {
876 // this is a serialized string, so we should display it
877 $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
879 // this is a serialized array/object so we should NOT display it
885 $entry['meta_key'] = attribute_escape($entry['meta_key']);
886 $entry['meta_value'] = htmlspecialchars($entry['meta_value']); // using a <textarea />
887 $entry['meta_id'] = (int) $entry['meta_id'];
889 $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
891 $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
892 $r .= "\n\t\t<td valign='top'><label class='hidden' for='meta[{$entry['meta_id']}][key]'>" . __( 'Key' ) . "</label><input name='meta[{$entry['meta_id']}][key]' id='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>";
893 $r .= "\n\t\t<td><label class='hidden' for='meta[{$entry['meta_id']}][value]'>" . __( 'Value' ) . "</label><textarea name='meta[{$entry['meta_id']}][value]' id='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>";
894 $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 />";
895 $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' ";
896 $r .= "class='delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemeta' tabindex='6' value='".attribute_escape(__( 'Delete' ))."' />";
897 $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
898 $r .= "</td>\n\t</tr>";
902 function meta_form() {
904 $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
905 $keys = $wpdb->get_col( "
908 WHERE meta_key NOT LIKE '\_%'
910 ORDER BY meta_id DESC
915 <p><strong><?php _e( 'Add a new custom field:' ) ?></strong></p>
916 <table id="newmeta" cellspacing="3" cellpadding="3">
918 <th colspan="2"><label <?php if ( $keys ) : ?> for="metakeyselect" <?php else : ?> for="metakeyinput" <?php endif; ?>><?php _e( 'Key' ) ?></label></th>
919 <th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
922 <td style="width: 18%;" class="textright">
923 <?php if ( $keys ) : ?>
924 <select id="metakeyselect" name="metakeyselect" tabindex="7">
925 <option value="#NONE#"><?php _e( '- Select -' ); ?></option>
928 foreach ( $keys as $key ) {
929 $key = attribute_escape( $key );
930 echo "\n\t<option value='$key'>$key</option>";
933 </select> <label for="metakeyinput"><?php _e( 'or' ); ?></label>
936 <td><input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" /></td>
937 <td><textarea id="metavalue" name="metavalue" rows="3" cols="25" tabindex="8"></textarea></td>
939 <tr class="submit"><td colspan="3">
940 <?php wp_nonce_field( 'add-meta', '_ajax_nonce', false ); ?>
941 <input type="submit" id="addmetasub" name="addmeta" class="add:the-list:newmeta" tabindex="9" value="<?php _e( 'Add Custom Field' ) ?>" />
948 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) {
949 global $wp_locale, $post, $comment;
952 $edit = ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true;
954 $tab_index_attribute = '';
955 if ( (int) $tab_index > 0 )
956 $tab_index_attribute = " tabindex=\"$tab_index\"";
958 // 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 />';
960 $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 );
961 $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
962 $jj = ($edit) ? mysql2date( 'd', $post_date ) : gmdate( 'd', $time_adj );
963 $mm = ($edit) ? mysql2date( 'm', $post_date ) : gmdate( 'm', $time_adj );
964 $aa = ($edit) ? mysql2date( 'Y', $post_date ) : gmdate( 'Y', $time_adj );
965 $hh = ($edit) ? mysql2date( 'H', $post_date ) : gmdate( 'H', $time_adj );
966 $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj );
967 $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj );
969 $month = "<select id=\"mm\" name=\"mm\"$tab_index_attribute>\n";
970 for ( $i = 1; $i < 13; $i = $i +1 ) {
971 $month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
973 $month .= ' selected="selected"';
974 $month .= '>' . $wp_locale->get_month( $i ) . "</option>\n";
976 $month .= '</select>';
978 $day = '<input type="text" id="jj" name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
979 $year = '<input type="text" id="aa" name="aa" value="' . $aa . '" size="4" maxlength="5"' . $tab_index_attribute . ' autocomplete="off" />';
980 $hour = '<input type="text" id="hh" name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
981 $minute = '<input type="text" id="mn" name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
982 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);
984 foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit )
985 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
988 <input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" />
992 function page_template_dropdown( $default = '' ) {
993 $templates = get_page_templates();
995 foreach (array_keys( $templates ) as $template )
996 : if ( $default == $templates[$template] )
997 $selected = " selected='selected'";
1000 echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
1004 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
1005 global $wpdb, $post_ID;
1006 $items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) );
1009 foreach ( $items as $item ) {
1010 // A page cannot be its own parent.
1011 if (!empty ( $post_ID ) ) {
1012 if ( $item->ID == $post_ID ) {
1016 $pad = str_repeat( ' ', $level * 3 );
1017 if ( $item->ID == $default)
1018 $current = ' selected="selected"';
1022 echo "\n\t<option value='$item->ID'$current>$pad " . wp_specialchars($item->post_title) . "</option>";
1023 parent_dropdown( $default, $item->ID, $level +1 );
1030 function browse_happy() {
1031 $getit = __( 'WordPress recommends a better browser' );
1033 <span id="bh" class="alignright"><a href="http://browsehappy.com/" title="'.$getit.'"><img src="images/browse-happy.gif" alt="Browse Happy" /></a></span>
1037 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)
1038 add_action( 'in_admin_footer', 'browse_happy' );
1040 function the_attachment_links( $id = false ) {
1042 $post = & get_post( $id );
1044 if ( $post->post_type != 'attachment' )
1047 $icon = get_attachment_icon( $post->ID );
1048 $attachment_data = wp_get_attachment_metadata( $id );
1049 $thumb = isset( $attachment_data['thumb'] );
1051 <form id="the-attachment-links">
1054 <col class="widefat" />
1056 <th scope="row"><?php _e( 'URL' ) ?></th>
1057 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo wp_get_attachment_url(); ?></textarea></td>
1059 <?php if ( $icon ) : ?>
1061 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
1062 <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>
1065 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
1066 <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>
1070 <th scope="row"><?php _e( 'Link to file' ) ?></th>
1071 <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>
1074 <th scope="row"><?php _e( 'Link to page' ) ?></th>
1075 <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>
1083 function wp_dropdown_roles( $default = false ) {
1086 foreach( $wp_roles->role_names as $role => $name ) {
1087 $name = translate_with_context($name);
1088 if ( $default == $role ) // Make default first in list
1089 $p = "\n\t<option selected='selected' value='$role'>$name</option>";
1091 $r .= "\n\t<option value='$role'>$name</option>";
1096 function wp_convert_hr_to_bytes( $size ) {
1097 $size = strtolower($size);
1098 $bytes = (int) $size;
1099 if ( strpos($size, 'k') !== false )
1100 $bytes = intval($size) * 1024;
1101 elseif ( strpos($size, 'm') !== false )
1102 $bytes = intval($size) * 1024 * 1024;
1103 elseif ( strpos($size, 'g') !== false )
1104 $bytes = intval($size) * 1024 * 1024 * 1024;
1108 function wp_convert_bytes_to_hr( $bytes ) {
1109 $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
1110 $log = log( $bytes, 1024 );
1111 $power = (int) $log;
1112 $size = pow(1024, $log - $power);
1113 return $size . $units[$power];
1116 function wp_max_upload_size() {
1117 $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
1118 $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
1119 $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
1123 function wp_import_upload_form( $action ) {
1124 $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
1125 $size = wp_convert_bytes_to_hr( $bytes );
1127 <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo attribute_escape($action) ?>">
1129 <?php wp_nonce_field('import-upload'); ?>
1130 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
1131 <input type="file" id="upload" name="import" size="25" />
1132 <input type="hidden" name="action" value="save" />
1133 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
1136 <input type="submit" class="button" value="<?php _e( 'Upload file and import' ); ?>" />
1142 function wp_remember_old_slug() {
1144 $name = attribute_escape($post->post_name); // just in case
1145 if ( strlen($name) )
1146 echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />';
1150 * add_meta_box() - Add a meta box to an edit form
1154 * @param string $id String for use in the 'id' attribute of tags.
1155 * @param string $title Title of the meta box
1156 * @param string $callback Function that fills the box with the desired content. The function should echo its output.
1157 * @param string $page The type of edit page on which to show the box (post, page, link)
1158 * @param string $context The context within the page where the boxes should show ('normal', 'advanced')
1159 * @param string $priority The priority within the context where the boxes should show ('high', 'low')
1161 function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default') {
1162 global $wp_meta_boxes;
1165 if ( !isset($wp_meta_boxes) )
1166 $wp_meta_boxes = array();
1167 if ( !isset($wp_meta_boxes[$page]) )
1168 $wp_meta_boxes[$page] = array();
1169 if ( !isset($wp_meta_boxes[$page][$context]) )
1170 $wp_meta_boxes[$page][$context] = array();
1172 foreach ( array('high', 'core', 'default', 'low') as $a_priority ) {
1173 if ( !isset($wp_meta_boxes[$page][$context][$a_priority][$id]) )
1175 // If a core box was previously added or removed by a plugin, don't add.
1176 if ( 'core' == $priority ) {
1177 // If core box previously deleted, don't add
1178 if ( false === $wp_meta_boxes[$page][$context][$a_priority][$id] )
1180 // If box was added with default priority, give it core priority to maintain sort order
1181 if ( 'default' == $a_priority ) {
1182 $wp_meta_boxes[$page][$context]['core'][$id] = $wp_meta_boxes[$page][$context]['default'][$id];
1183 unset($wp_meta_boxes[$page][$context]['default'][$id]);
1187 // If no priority given and id already present, use existing priority
1188 if ( empty($priority) )
1189 $priority = $a_priority;
1190 // An id can be in only one priority
1191 if ( $priority != $a_priority )
1192 unset($wp_meta_boxes[$page][$context][$a_priority][$id]);
1195 if ( empty($priority) )
1198 if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
1199 $wp_meta_boxes[$page][$context][$priority] = array();
1201 $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
1204 function do_meta_boxes($page, $context, $object) {
1205 global $wp_meta_boxes;
1207 do_action('do_meta_boxes', $page, $context, $object);
1209 if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
1212 foreach ( array('high', 'core', 'default', 'low') as $priority ) {
1213 foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
1214 if ( false === $box )
1216 echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '">' . "\n";
1217 echo "<h3>{$box['title']}</h3>\n";
1218 echo '<div class="inside">' . "\n";
1219 call_user_func($box['callback'], $object, $box);
1227 * remove_meta_box() - Remove a meta box from an edit form
1231 * @param string $id String for use in the 'id' attribute of tags.
1232 * @param string $page The type of edit page on which to show the box (post, page, link)
1233 * @param string $context The context within the page where the boxes should show ('normal', 'advanced')
1235 function remove_meta_box($id, $page, $context) {
1236 global $wp_meta_boxes;
1238 if ( !isset($wp_meta_boxes) )
1239 $wp_meta_boxes = array();
1240 if ( !isset($wp_meta_boxes[$page]) )
1241 $wp_meta_boxes[$page] = array();
1242 if ( !isset($wp_meta_boxes[$page][$context]) )
1243 $wp_meta_boxes[$page][$context] = array();
1245 foreach ( array('high', 'core', 'default', 'low') as $priority )
1246 $wp_meta_boxes[$page][$context][$priority][$id] = false;