PageRenderTime 78ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/template.php

https://github.com/schr/wordpress
PHP | 3560 lines | 2425 code | 446 blank | 689 comment | 465 complexity | 4703f69c51ef6e02df6008c60649cdc6 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Template WordPress Administration API.
  4. *
  5. * A Big Mess. Also some neat functions that are nicely written.
  6. *
  7. * @package WordPress
  8. * @subpackage Administration
  9. */
  10. // Ugly recursive category stuff.
  11. /**
  12. * {@internal Missing Short Description}}
  13. *
  14. * @since unknown
  15. *
  16. * @param unknown_type $parent
  17. * @param unknown_type $level
  18. * @param unknown_type $categories
  19. * @param unknown_type $page
  20. * @param unknown_type $per_page
  21. */
  22. function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20 ) {
  23. $count = 0;
  24. _cat_rows($categories, $count, $parent, $level, $page, $per_page);
  25. }
  26. /**
  27. * {@internal Missing Short Description}}
  28. *
  29. * @since unknown
  30. *
  31. * @param unknown_type $categories
  32. * @param unknown_type $count
  33. * @param unknown_type $parent
  34. * @param unknown_type $level
  35. * @param unknown_type $page
  36. * @param unknown_type $per_page
  37. * @return unknown
  38. */
  39. function _cat_rows( $categories, &$count, $parent = 0, $level = 0, $page = 1, $per_page = 20 ) {
  40. if ( empty($categories) ) {
  41. $args = array('hide_empty' => 0);
  42. if ( !empty($_GET['s']) )
  43. $args['search'] = $_GET['s'];
  44. $categories = get_categories( $args );
  45. }
  46. if ( !$categories )
  47. return false;
  48. $children = _get_term_hierarchy('category');
  49. $start = ($page - 1) * $per_page;
  50. $end = $start + $per_page;
  51. $i = -1;
  52. ob_start();
  53. foreach ( $categories as $category ) {
  54. if ( $count >= $end )
  55. break;
  56. $i++;
  57. if ( $category->parent != $parent )
  58. continue;
  59. // If the page starts in a subtree, print the parents.
  60. if ( $count == $start && $category->parent > 0 ) {
  61. $my_parents = array();
  62. while ( $my_parent) {
  63. $my_parent = get_category($my_parent);
  64. $my_parents[] = $my_parent;
  65. if ( !$my_parent->parent )
  66. break;
  67. $my_parent = $my_parent->parent;
  68. }
  69. $num_parents = count($my_parents);
  70. while( $my_parent = array_pop($my_parents) ) {
  71. echo "\t" . _cat_row( $my_parent, $level - $num_parents );
  72. $num_parents--;
  73. }
  74. }
  75. if ( $count >= $start )
  76. echo "\t" . _cat_row( $category, $level );
  77. unset($categories[$i]); // Prune the working set
  78. $count++;
  79. if ( isset($children[$category->term_id]) )
  80. _cat_rows( $categories, $count, $category->term_id, $level + 1, $page, $per_page );
  81. }
  82. $output = ob_get_contents();
  83. ob_end_clean();
  84. echo $output;
  85. }
  86. /**
  87. * {@internal Missing Short Description}}
  88. *
  89. * @since unknown
  90. *
  91. * @param unknown_type $category
  92. * @param unknown_type $level
  93. * @param unknown_type $name_override
  94. * @return unknown
  95. */
  96. function _cat_row( $category, $level, $name_override = false ) {
  97. static $row_class = '';
  98. $category = get_category( $category, OBJECT, 'display' );
  99. $default_cat_id = (int) get_option( 'default_category' );
  100. $pad = str_repeat( '&#8212; ', $level );
  101. $name = ( $name_override ? $name_override : $pad . ' ' . $category->name );
  102. $edit_link = "categories.php?action=edit&amp;cat_ID=$category->term_id";
  103. if ( current_user_can( 'manage_categories' ) ) {
  104. $edit = "<a class='row-title' href='$edit_link' title='" . attribute_escape(sprintf(__('Edit "%s"'), $category->name)) . "'>" . attribute_escape( $name ) . '</a><br />';
  105. $actions = array();
  106. $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
  107. $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
  108. if ( $default_cat_id != $category->term_id )
  109. $actions['delete'] = "<a class='delete:the-list:cat-$category->term_id submitdelete' href='" . wp_nonce_url("categories.php?action=delete&amp;cat_ID=$category->term_id", 'delete-category_' . $category->term_id) . "'>" . __('Delete') . "</a>";
  110. $actions = apply_filters('cat_row_actions', $actions, $category);
  111. $action_count = count($actions);
  112. $i = 0;
  113. $edit .= '<div class="row-actions">';
  114. foreach ( $actions as $action => $link ) {
  115. ++$i;
  116. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  117. $edit .= "<span class='$action'>$link$sep</span>";
  118. }
  119. $edit .= '</div>';
  120. } else {
  121. $edit = $name;
  122. }
  123. $row_class = 'alternate' == $row_class ? '' : 'alternate';
  124. $qe_data = get_category_to_edit($category->term_id);
  125. $category->count = number_format_i18n( $category->count );
  126. $posts_count = ( $category->count > 0 ) ? "<a href='edit.php?cat=$category->term_id'>$category->count</a>" : $category->count;
  127. $output = "<tr id='cat-$category->term_id' class='iedit $row_class'>";
  128. $columns = get_column_headers('categories');
  129. $hidden = get_hidden_columns('categories');
  130. foreach ( $columns as $column_name => $column_display_name ) {
  131. $class = "class=\"$column_name column-$column_name\"";
  132. $style = '';
  133. if ( in_array($column_name, $hidden) )
  134. $style = ' style="display:none;"';
  135. $attributes = "$class$style";
  136. switch ($column_name) {
  137. case 'cb':
  138. $output .= "<th scope='row' class='check-column'>";
  139. if ( $default_cat_id != $category->term_id ) {
  140. $output .= "<input type='checkbox' name='delete[]' value='$category->term_id' />";
  141. } else {
  142. $output .= "&nbsp;";
  143. }
  144. $output .= '</th>';
  145. break;
  146. case 'name':
  147. $output .= "<td $attributes>$edit";
  148. $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
  149. $output .= '<div class="name">' . $qe_data->name . '</div>';
  150. $output .= '<div class="slug">' . $qe_data->slug . '</div>';
  151. $output .= '<div class="cat_parent">' . $qe_data->parent . '</div></div></td>';
  152. break;
  153. case 'description':
  154. $output .= "<td $attributes>$category->description</td>";
  155. break;
  156. case 'slug':
  157. $output .= "<td $attributes>$category->slug</td>";
  158. break;
  159. case 'posts':
  160. $attributes = 'class="posts column-posts num"' . $style;
  161. $output .= "<td $attributes>$posts_count</td>\n";
  162. break;
  163. default:
  164. $output .= "<td $attributes>";
  165. $output .= apply_filters('manage_categories_custom_column', '', $column_name, $category->term_id);
  166. $output .= "</td>";
  167. }
  168. }
  169. $output .= '</tr>';
  170. return $output;
  171. }
  172. /**
  173. * {@internal Missing Short Description}}
  174. *
  175. * @since 2.7
  176. *
  177. * Outputs the HTML for the hidden table rows used in Categories, Link Caregories and Tags quick edit.
  178. *
  179. * @param string $type "tag", "category" or "link-category"
  180. * @return
  181. */
  182. function inline_edit_term_row($type) {
  183. if ( ! current_user_can( 'manage_categories' ) )
  184. return;
  185. $is_tag = $type == 'edit-tags';
  186. $columns = get_column_headers($type);
  187. $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($type) ) );
  188. $col_count = count($columns) - count($hidden);
  189. ?>
  190. <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
  191. <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $col_count; ?>">
  192. <fieldset><div class="inline-edit-col">
  193. <h4><?php _e( 'Quick Edit' ); ?></h4>
  194. <label>
  195. <span class="title"><?php _e( 'Name' ); ?></span>
  196. <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
  197. </label>
  198. <label>
  199. <span class="title"><?php _e( 'Slug' ); ?></span>
  200. <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
  201. </label>
  202. <?php if ( 'category' == $type ) : ?>
  203. <label>
  204. <span class="title"><?php _e( 'Parent' ); ?></span>
  205. <?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('None'))); ?>
  206. </label>
  207. <?php endif; // $type ?>
  208. </div></fieldset>
  209. <?php
  210. $core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true );
  211. foreach ( $columns as $column_name => $column_display_name ) {
  212. if ( isset( $core_columns[$column_name] ) )
  213. continue;
  214. do_action( 'quick_edit_custom_box', $column_name, $type );
  215. }
  216. ?>
  217. <p class="inline-edit-save submit">
  218. <a accesskey="c" href="#inline-edit" title="<?php _e('Cancel'); ?>" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a>
  219. <?php $update_text = ( $is_tag ) ? __( 'Update Tag' ) : __( 'Update Category' ); ?>
  220. <a accesskey="s" href="#inline-edit" title="<?php echo attribute_escape( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a>
  221. <img class="waiting" style="display:none;" src="images/loading.gif" alt="" />
  222. <span class="error" style="display:none;"></span>
  223. <?php wp_nonce_field( 'taxinlineeditnonce', '_inline_edit', false ); ?>
  224. <br class="clear" />
  225. </p>
  226. </td></tr>
  227. </tbody></table></form>
  228. <?php
  229. }
  230. /**
  231. * {@internal Missing Short Description}}
  232. *
  233. * @since unknown
  234. *
  235. * @param unknown_type $category
  236. * @param unknown_type $name_override
  237. * @return unknown
  238. */
  239. function link_cat_row( $category, $name_override = false ) {
  240. static $row_class = '';
  241. if ( !$category = get_term( $category, 'link_category', OBJECT, 'display' ) )
  242. return false;
  243. if ( is_wp_error( $category ) )
  244. return $category;
  245. $default_cat_id = (int) get_option( 'default_link_category' );
  246. $name = ( $name_override ? $name_override : $category->name );
  247. $edit_link = "link-category.php?action=edit&amp;cat_ID=$category->term_id";
  248. if ( current_user_can( 'manage_categories' ) ) {
  249. $edit = "<a class='row-title' href='$edit_link' title='" . attribute_escape(sprintf(__('Edit "%s"'), $category->name)) . "'>$name</a><br />";
  250. $actions = array();
  251. $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
  252. $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
  253. if ( $default_cat_id != $category->term_id )
  254. $actions['delete'] = "<a class='delete:the-list:link-cat-$category->term_id submitdelete' href='" . wp_nonce_url("link-category.php?action=delete&amp;cat_ID=$category->term_id", 'delete-link-category_' . $category->term_id) . "'>" . __('Delete') . "</a>";
  255. $actions = apply_filters('link_cat_row_actions', $actions, $category);
  256. $action_count = count($actions);
  257. $i = 0;
  258. $edit .= '<div class="row-actions">';
  259. foreach ( $actions as $action => $link ) {
  260. ++$i;
  261. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  262. $edit .= "<span class='$action'>$link$sep</span>";
  263. }
  264. $edit .= '</div>';
  265. } else {
  266. $edit = $name;
  267. }
  268. $row_class = 'alternate' == $row_class ? '' : 'alternate';
  269. $qe_data = get_term_to_edit($category->term_id, 'link_category');
  270. $category->count = number_format_i18n( $category->count );
  271. $count = ( $category->count > 0 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count;
  272. $output = "<tr id='link-cat-$category->term_id' class='iedit $row_class'>";
  273. $columns = get_column_headers('edit-link-categories');
  274. $hidden = get_hidden_columns('edit-link-categories');
  275. foreach ( $columns as $column_name => $column_display_name ) {
  276. $class = "class=\"$column_name column-$column_name\"";
  277. $style = '';
  278. if ( in_array($column_name, $hidden) )
  279. $style = ' style="display:none;"';
  280. $attributes = "$class$style";
  281. switch ($column_name) {
  282. case 'cb':
  283. $output .= "<th scope='row' class='check-column'>";
  284. if ( absint( get_option( 'default_link_category' ) ) != $category->term_id ) {
  285. $output .= "<input type='checkbox' name='delete[]' value='$category->term_id' />";
  286. } else {
  287. $output .= "&nbsp;";
  288. }
  289. $output .= "</th>";
  290. break;
  291. case 'name':
  292. $output .= "<td $attributes>$edit";
  293. $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
  294. $output .= '<div class="name">' . $qe_data->name . '</div>';
  295. $output .= '<div class="slug">' . $qe_data->slug . '</div>';
  296. $output .= '<div class="cat_parent">' . $qe_data->parent . '</div></div></td>';
  297. break;
  298. case 'description':
  299. $output .= "<td $attributes>$category->description</td>";
  300. break;
  301. case 'slug':
  302. $output .= "<td $attributes>$category->slug</td>";
  303. break;
  304. case 'links':
  305. $attributes = 'class="links column-links num"' . $style;
  306. $output .= "<td $attributes>$count</td>";
  307. break;
  308. default:
  309. $output .= "<td $attributes>";
  310. $output .= apply_filters('manage_link_categories_custom_column', '', $column_name, $category->term_id);
  311. $output .= "</td>";
  312. }
  313. }
  314. $output .= '</tr>';
  315. return $output;
  316. }
  317. /**
  318. * Outputs the html checked attribute.
  319. *
  320. * Compares the first two arguments and if identical marks as checked
  321. *
  322. * @since unknown
  323. *
  324. * @param any $checked One of the values to compare
  325. * @param any $current (true) The other value to compare if not just true
  326. * @param bool $echo Whether or not to echo or just return the string
  327. */
  328. function checked( $checked, $current = true, $echo = true) {
  329. return __checked_selected_helper( $checked, $current, $echo, 'checked' );
  330. }
  331. /**
  332. * Outputs the html selected attribute.
  333. *
  334. * Compares the first two arguments and if identical marks as selected
  335. *
  336. * @since unknown
  337. *
  338. * @param any $checked One of the values to compare
  339. * @param any $current (true) The other value to compare if not just true
  340. * @param bool $echo Whether or not to echo or just return the string
  341. */
  342. function selected( $selected, $current = true, $echo = true) {
  343. return __checked_selected_helper( $selected, $current, $echo, 'selected' );
  344. }
  345. /**
  346. * Private helper function for checked and selected.
  347. *
  348. * Compares the first two arguments and if identical marks as $type
  349. *
  350. * @since unknown
  351. * @access private
  352. *
  353. * @param any $checked One of the values to compare
  354. * @param any $current (true) The other value to compare if not just true
  355. * @param bool $echo Whether or not to echo or just return the string
  356. * @param string $type The type of checked|selected we are doing.
  357. */
  358. function __checked_selected_helper( $helper, $current, $echo, $type) {
  359. if ( $helper == $current)
  360. $result = " $type='$type'";
  361. else
  362. $result = '';
  363. if ($echo)
  364. echo $result;
  365. return $result;
  366. }
  367. //
  368. // Category Checklists
  369. //
  370. /**
  371. * {@internal Missing Short Description}}
  372. *
  373. * @since unknown
  374. * @deprecated Use {@link wp_link_category_checklist()}
  375. * @see wp_link_category_checklist()
  376. *
  377. * @param unknown_type $default
  378. * @param unknown_type $parent
  379. * @param unknown_type $popular_ids
  380. */
  381. function dropdown_categories( $default = 0, $parent = 0, $popular_ids = array() ) {
  382. global $post_ID;
  383. wp_category_checklist($post_ID);
  384. }
  385. /**
  386. * {@internal Missing Short Description}}
  387. *
  388. * @since unknown
  389. */
  390. class Walker_Category_Checklist extends Walker {
  391. var $tree_type = 'category';
  392. var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
  393. function start_lvl(&$output, $depth, $args) {
  394. $indent = str_repeat("\t", $depth);
  395. $output .= "$indent<ul class='children'>\n";
  396. }
  397. function end_lvl(&$output, $depth, $args) {
  398. $indent = str_repeat("\t", $depth);
  399. $output .= "$indent</ul>\n";
  400. }
  401. function start_el(&$output, $category, $depth, $args) {
  402. extract($args);
  403. $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
  404. $output .= "\n<li id='category-$category->term_id'$class>" . '<label 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>';
  405. }
  406. function end_el(&$output, $category, $depth, $args) {
  407. $output .= "</li>\n";
  408. }
  409. }
  410. /**
  411. * {@internal Missing Short Description}}
  412. *
  413. * @since unknown
  414. *
  415. * @param unknown_type $post_id
  416. * @param unknown_type $descendants_and_self
  417. * @param unknown_type $selected_cats
  418. * @param unknown_type $popular_cats
  419. */
  420. function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null ) {
  421. if ( empty($walker) || !is_a($walker, 'Walker') )
  422. $walker = new Walker_Category_Checklist;
  423. $descendants_and_self = (int) $descendants_and_self;
  424. $args = array();
  425. if ( is_array( $selected_cats ) )
  426. $args['selected_cats'] = $selected_cats;
  427. elseif ( $post_id )
  428. $args['selected_cats'] = wp_get_post_categories($post_id);
  429. else
  430. $args['selected_cats'] = array();
  431. if ( is_array( $popular_cats ) )
  432. $args['popular_cats'] = $popular_cats;
  433. else
  434. $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
  435. if ( $descendants_and_self ) {
  436. $categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" );
  437. $self = get_category( $descendants_and_self );
  438. array_unshift( $categories, $self );
  439. } else {
  440. $categories = get_categories('get=all');
  441. }
  442. // 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)
  443. $checked_categories = array();
  444. for ( $i = 0; isset($categories[$i]); $i++ ) {
  445. if ( in_array($categories[$i]->term_id, $args['selected_cats']) ) {
  446. $checked_categories[] = $categories[$i];
  447. unset($categories[$i]);
  448. }
  449. }
  450. // Put checked cats on top
  451. echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args));
  452. // Then the rest of them
  453. echo call_user_func_array(array(&$walker, 'walk'), array($categories, 0, $args));
  454. }
  455. /**
  456. * {@internal Missing Short Description}}
  457. *
  458. * @since unknown
  459. *
  460. * @param unknown_type $taxonomy
  461. * @param unknown_type $default
  462. * @param unknown_type $number
  463. * @param unknown_type $echo
  464. * @return unknown
  465. */
  466. function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
  467. global $post_ID;
  468. if ( $post_ID )
  469. $checked_categories = wp_get_post_categories($post_ID);
  470. else
  471. $checked_categories = array();
  472. $categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );
  473. $popular_ids = array();
  474. foreach ( (array) $categories as $category ) {
  475. $popular_ids[] = $category->term_id;
  476. if ( !$echo ) // hack for AJAX use
  477. continue;
  478. $id = "popular-category-$category->term_id";
  479. ?>
  480. <li id="<?php echo $id; ?>" class="popular-category">
  481. <label class="selectit">
  482. <input id="in-<?php echo $id; ?>" type="checkbox" value="<?php echo (int) $category->term_id; ?>" />
  483. <?php echo wp_specialchars( apply_filters( 'the_category', $category->name ) ); ?>
  484. </label>
  485. </li>
  486. <?php
  487. }
  488. return $popular_ids;
  489. }
  490. /**
  491. * {@internal Missing Short Description}}
  492. *
  493. * @since unknown
  494. * @deprecated Use {@link wp_link_category_checklist()}
  495. * @see wp_link_category_checklist()
  496. *
  497. * @param unknown_type $default
  498. */
  499. function dropdown_link_categories( $default = 0 ) {
  500. global $link_id;
  501. wp_link_category_checklist($link_id);
  502. }
  503. /**
  504. * {@internal Missing Short Description}}
  505. *
  506. * @since unknown
  507. *
  508. * @param unknown_type $link_id
  509. */
  510. function wp_link_category_checklist( $link_id = 0 ) {
  511. $default = 1;
  512. if ( $link_id ) {
  513. $checked_categories = wp_get_link_cats($link_id);
  514. if ( count( $checked_categories ) == 0 ) {
  515. // No selected categories, strange
  516. $checked_categories[] = $default;
  517. }
  518. } else {
  519. $checked_categories[] = $default;
  520. }
  521. $categories = get_terms('link_category', 'orderby=count&hide_empty=0');
  522. if ( empty($categories) )
  523. return;
  524. foreach ( $categories as $category ) {
  525. $cat_id = $category->term_id;
  526. $name = wp_specialchars( apply_filters('the_category', $category->name));
  527. $checked = in_array( $cat_id, $checked_categories );
  528. 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>";
  529. }
  530. }
  531. // Tag stuff
  532. // Returns a single tag row (see tag_rows below)
  533. // Note: this is also used in admin-ajax.php!
  534. /**
  535. * {@internal Missing Short Description}}
  536. *
  537. * @since unknown
  538. *
  539. * @param unknown_type $tag
  540. * @param unknown_type $class
  541. * @return unknown
  542. */
  543. function _tag_row( $tag, $class = '', $taxonomy = 'post_tag' ) {
  544. $count = number_format_i18n( $tag->count );
  545. $count = ( $count > 0 ) ? "<a href='edit.php?tag=$tag->slug'>$count</a>" : $count;
  546. $name = apply_filters( 'term_name', $tag->name );
  547. $qe_data = get_term($tag->term_id, $taxonomy, object, 'edit');
  548. $edit_link = "edit-tags.php?action=edit&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id";
  549. $out = '';
  550. $out .= '<tr id="tag-' . $tag->term_id . '"' . $class . '>';
  551. $columns = get_column_headers('edit-tags');
  552. $hidden = get_hidden_columns('edit-tags');
  553. foreach ( $columns as $column_name => $column_display_name ) {
  554. $class = "class=\"$column_name column-$column_name\"";
  555. $style = '';
  556. if ( in_array($column_name, $hidden) )
  557. $style = ' style="display:none;"';
  558. $attributes = "$class$style";
  559. switch ($column_name) {
  560. case 'cb':
  561. $out .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>';
  562. break;
  563. case 'name':
  564. $out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_link . '" title="' . attribute_escape(sprintf(__('Edit "%s"'), $name)) . '">' . $name . '</a></strong><br />';
  565. $actions = array();
  566. $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
  567. $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
  568. $actions['delete'] = "<a class='delete:the-list:tag-$tag->term_id submitdelete' href='" . wp_nonce_url("edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id) . "'>" . __('Delete') . "</a>";
  569. $actions = apply_filters('tag_row_actions', $actions, $tag);
  570. $action_count = count($actions);
  571. $i = 0;
  572. $out .= '<div class="row-actions">';
  573. foreach ( $actions as $action => $link ) {
  574. ++$i;
  575. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  576. $out .= "<span class='$action'>$link$sep</span>";
  577. }
  578. $out .= '</div>';
  579. $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
  580. $out .= '<div class="name">' . $qe_data->name . '</div>';
  581. $out .= '<div class="slug">' . $qe_data->slug . '</div></div></td>';
  582. break;
  583. case 'slug':
  584. $out .= "<td $attributes>$tag->slug</td>";
  585. break;
  586. case 'posts':
  587. $attributes = 'class="posts column-posts num"' . $style;
  588. $out .= "<td $attributes>$count</td>";
  589. break;
  590. default:
  591. $out .= "<td $attributes>";
  592. $out .= apply_filters("manage_${taxonomy}_custom_column", '', $column_name, $tag->term_id);
  593. $out .= "</td>";
  594. }
  595. }
  596. $out .= '</tr>';
  597. return $out;
  598. }
  599. // Outputs appropriate rows for the Nth page of the Tag Management screen,
  600. // assuming M tags displayed at a time on the page
  601. // Returns the number of tags displayed
  602. /**
  603. * {@internal Missing Short Description}}
  604. *
  605. * @since unknown
  606. *
  607. * @param unknown_type $page
  608. * @param unknown_type $pagesize
  609. * @param unknown_type $searchterms
  610. * @return unknown
  611. */
  612. function tag_rows( $page = 1, $pagesize = 20, $searchterms = '', $taxonomy = 'post_tag' ) {
  613. // Get a page worth of tags
  614. $start = ($page - 1) * $pagesize;
  615. $args = array('offset' => $start, 'number' => $pagesize, 'hide_empty' => 0);
  616. if ( !empty( $searchterms ) ) {
  617. $args['search'] = $searchterms;
  618. }
  619. $tags = get_terms( $taxonomy, $args );
  620. // convert it to table rows
  621. $out = '';
  622. $count = 0;
  623. foreach( $tags as $tag )
  624. $out .= _tag_row( $tag, ++$count % 2 ? ' class="iedit alternate"' : ' class="iedit"', $taxonomy );
  625. // filter and send to screen
  626. echo $out;
  627. return $count;
  628. }
  629. // define the columns to display, the syntax is 'internal name' => 'display name'
  630. /**
  631. * {@internal Missing Short Description}}
  632. *
  633. * @since unknown
  634. *
  635. * @return unknown
  636. */
  637. function wp_manage_posts_columns() {
  638. $posts_columns = array();
  639. $posts_columns['cb'] = '<input type="checkbox" />';
  640. /* translators: manage posts column name */
  641. $posts_columns['title'] = _x('Post', 'column name');
  642. $posts_columns['author'] = __('Author');
  643. $posts_columns['categories'] = __('Categories');
  644. $posts_columns['tags'] = __('Tags');
  645. if ( !isset($_GET['post_status']) || !in_array($_GET['post_status'], array('pending', 'draft', 'future')) )
  646. $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="images/comment-grey-bubble.png" /></div>';
  647. $posts_columns['date'] = __('Date');
  648. $posts_columns = apply_filters('manage_posts_columns', $posts_columns);
  649. return $posts_columns;
  650. }
  651. // define the columns to display, the syntax is 'internal name' => 'display name'
  652. /**
  653. * {@internal Missing Short Description}}
  654. *
  655. * @since unknown
  656. *
  657. * @return unknown
  658. */
  659. function wp_manage_media_columns() {
  660. $posts_columns = array();
  661. $posts_columns['cb'] = '<input type="checkbox" />';
  662. $posts_columns['icon'] = '';
  663. /* translators: column name */
  664. $posts_columns['media'] = _x('File', 'column name');
  665. $posts_columns['author'] = __('Author');
  666. //$posts_columns['tags'] = _x('Tags', 'column name');
  667. /* translators: column name */
  668. $posts_columns['parent'] = _x('Attached to', 'column name');
  669. $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="images/comment-grey-bubble.png" /></div>';
  670. //$posts_columns['comments'] = __('Comments');
  671. /* translators: column name */
  672. $posts_columns['date'] = _x('Date', 'column name');
  673. $posts_columns = apply_filters('manage_media_columns', $posts_columns);
  674. return $posts_columns;
  675. }
  676. /**
  677. * {@internal Missing Short Description}}
  678. *
  679. * @since unknown
  680. *
  681. * @return unknown
  682. */
  683. function wp_manage_pages_columns() {
  684. $posts_columns = array();
  685. $posts_columns['cb'] = '<input type="checkbox" />';
  686. $posts_columns['title'] = __('Title');
  687. $posts_columns['author'] = __('Author');
  688. $post_status = 'all';
  689. if ( !empty($_GET['post_status']) )
  690. $post_status = $_GET['post_status'];
  691. if ( !in_array($post_status, array('pending', 'draft', 'future')) )
  692. $posts_columns['comments'] = '<div class="vers"><img alt="" src="images/comment-grey-bubble.png" /></div>';
  693. $posts_columns['date'] = __('Date');
  694. $posts_columns = apply_filters('manage_pages_columns', $posts_columns);
  695. return $posts_columns;
  696. }
  697. /**
  698. * {@internal Missing Short Description}}
  699. *
  700. * @since unknown
  701. *
  702. * @param unknown_type $page
  703. * @return unknown
  704. */
  705. function get_column_headers($page) {
  706. global $_wp_column_headers;
  707. if ( !isset($_wp_column_headers) )
  708. $_wp_column_headers = array();
  709. // Store in static to avoid running filters on each call
  710. if ( isset($_wp_column_headers[$page]) )
  711. return $_wp_column_headers[$page];
  712. switch ($page) {
  713. case 'edit':
  714. $_wp_column_headers[$page] = wp_manage_posts_columns();
  715. break;
  716. case 'edit-pages':
  717. $_wp_column_headers[$page] = wp_manage_pages_columns();
  718. break;
  719. case 'edit-comments':
  720. $_wp_column_headers[$page] = array(
  721. 'cb' => '<input type="checkbox" />',
  722. 'author' => __('Author'),
  723. /* translators: column name */
  724. 'comment' => _x('Comment', 'column name'),
  725. //'date' => __('Submitted'),
  726. 'response' => __('In Response To')
  727. );
  728. break;
  729. case 'link-manager':
  730. $_wp_column_headers[$page] = array(
  731. 'cb' => '<input type="checkbox" />',
  732. 'name' => __('Name'),
  733. 'url' => __('URL'),
  734. 'categories' => __('Categories'),
  735. 'rel' => __('rel'),
  736. 'visible' => __('Visible')
  737. );
  738. break;
  739. case 'upload':
  740. $_wp_column_headers[$page] = wp_manage_media_columns();
  741. break;
  742. case 'categories':
  743. $_wp_column_headers[$page] = array(
  744. 'cb' => '<input type="checkbox" />',
  745. 'name' => __('Name'),
  746. 'description' => __('Description'),
  747. 'slug' => __('Slug'),
  748. 'posts' => __('Posts')
  749. );
  750. break;
  751. case 'edit-link-categories':
  752. $_wp_column_headers[$page] = array(
  753. 'cb' => '<input type="checkbox" />',
  754. 'name' => __('Name'),
  755. 'description' => __('Description'),
  756. 'slug' => __('Slug'),
  757. 'links' => __('Links')
  758. );
  759. break;
  760. case 'edit-tags':
  761. $_wp_column_headers[$page] = array(
  762. 'cb' => '<input type="checkbox" />',
  763. 'name' => __('Name'),
  764. 'slug' => __('Slug'),
  765. 'posts' => __('Posts')
  766. );
  767. break;
  768. case 'users':
  769. $_wp_column_headers[$page] = array(
  770. 'cb' => '<input type="checkbox" />',
  771. 'username' => __('Username'),
  772. 'name' => __('Name'),
  773. 'email' => __('E-mail'),
  774. 'role' => __('Role'),
  775. 'posts' => __('Posts')
  776. );
  777. break;
  778. default :
  779. $_wp_column_headers[$page] = array();
  780. }
  781. $_wp_column_headers[$page] = apply_filters('manage_' . $page . '_columns', $_wp_column_headers[$page]);
  782. return $_wp_column_headers[$page];
  783. }
  784. /**
  785. * {@internal Missing Short Description}}
  786. *
  787. * @since unknown
  788. *
  789. * @param unknown_type $type
  790. * @param unknown_type $id
  791. */
  792. function print_column_headers( $type, $id = true ) {
  793. $type = str_replace('.php', '', $type);
  794. $columns = get_column_headers( $type );
  795. $hidden = get_hidden_columns($type);
  796. $styles = array();
  797. // $styles['tag']['posts'] = 'width: 90px;';
  798. // $styles['link-category']['links'] = 'width: 90px;';
  799. // $styles['category']['posts'] = 'width: 90px;';
  800. // $styles['link']['visible'] = 'text-align: center;';
  801. foreach ( $columns as $column_key => $column_display_name ) {
  802. $class = ' class="manage-column';
  803. $class .= " column-$column_key";
  804. if ( 'cb' == $column_key )
  805. $class .= ' check-column';
  806. elseif ( in_array($column_key, array('posts', 'comments', 'links')) )
  807. $class .= ' num';
  808. $class .= '"';
  809. $style = '';
  810. if ( in_array($column_key, $hidden) )
  811. $style = 'display:none;';
  812. if ( isset($styles[$type]) && isset($styles[$type][$column_key]) )
  813. $style .= ' ' . $styles[$type][$column_key];
  814. $style = ' style="' . $style . '"';
  815. ?>
  816. <th scope="col" <?php echo $id ? "id=\"$column_key\"" : ""; echo $class; echo $style; ?>><?php echo $column_display_name; ?></th>
  817. <?php }
  818. }
  819. /**
  820. * Register column headers for a particular screen. The header names will be listed in the Screen Options.
  821. *
  822. * @since 2.7.0
  823. *
  824. * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
  825. * @param array $columns An array of columns with column IDs as the keys and translated column names as the values
  826. * @see get_column_headers(), print_column_headers(), get_hidden_columns()
  827. */
  828. function register_column_headers($screen, $columns) {
  829. global $_wp_column_headers;
  830. if ( !isset($_wp_column_headers) )
  831. $_wp_column_headers = array();
  832. $_wp_column_headers[$screen] = $columns;
  833. }
  834. /**
  835. * {@internal Missing Short Description}}
  836. *
  837. * @since unknown
  838. *
  839. * @param unknown_type $page
  840. */
  841. function get_hidden_columns($page) {
  842. $page = str_replace('.php', '', $page);
  843. return (array) get_user_option( 'manage-' . $page . '-columns-hidden', 0, false );
  844. }
  845. /**
  846. * {@internal Missing Short Description}}
  847. *
  848. * Outputs the quick edit and bulk edit table rows for posts and pages
  849. *
  850. * @since 2.7
  851. *
  852. * @param string $type 'post' or 'page'
  853. */
  854. function inline_edit_row( $type ) {
  855. global $current_user, $mode;
  856. $is_page = 'page' == $type;
  857. if ( $is_page ) {
  858. $screen = 'edit-pages';
  859. $post = get_default_page_to_edit();
  860. } else {
  861. $screen = 'edit';
  862. $post = get_default_post_to_edit();
  863. }
  864. $columns = $is_page ? wp_manage_pages_columns() : wp_manage_posts_columns();
  865. $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($screen) ) );
  866. $col_count = count($columns) - count($hidden);
  867. $m = ( isset($mode) && 'excerpt' == $mode ) ? 'excerpt' : 'list';
  868. $can_publish = current_user_can("publish_{$type}s");
  869. $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
  870. ?>
  871. <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
  872. <?php
  873. $bulk = 0;
  874. while ( $bulk < 2 ) { ?>
  875. <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$type ";
  876. echo $bulk ? "bulk-edit-row bulk-edit-row-$type" : "quick-edit-row quick-edit-row-$type";
  877. ?>" style="display: none"><td colspan="<?php echo $col_count; ?>">
  878. <fieldset class="inline-edit-col-left"><div class="inline-edit-col">
  879. <h4><?php echo $bulk ? ( $is_page ? __( 'Bulk Edit Pages' ) : __( 'Bulk Edit Posts' ) ) : __( 'Quick Edit' ); ?></h4>
  880. <?php if ( $bulk ) : ?>
  881. <div id="bulk-title-div">
  882. <div id="bulk-titles"></div>
  883. </div>
  884. <?php else : // $bulk ?>
  885. <label>
  886. <span class="title"><?php _e( 'Title' ); ?></span>
  887. <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
  888. </label>
  889. <?php endif; // $bulk ?>
  890. <?php if ( !$bulk ) : ?>
  891. <label>
  892. <span class="title"><?php _e( 'Slug' ); ?></span>
  893. <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
  894. </label>
  895. <label><span class="title"><?php _e( 'Date' ); ?></span></label>
  896. <div class="inline-edit-date">
  897. <?php touch_time(1, 1, 4, 1); ?>
  898. </div>
  899. <br class="clear" />
  900. <?php endif; // $bulk
  901. ob_start();
  902. $authors = get_editable_user_ids( $current_user->id, true, $type ); // TODO: ROLE SYSTEM
  903. if ( $authors && count( $authors ) > 1 ) :
  904. $users_opt = array('include' => $authors, 'name' => 'post_author', 'class'=> 'authors', 'multi' => 1);
  905. if ( $bulk )
  906. $users_opt['show_option_none'] = __('- No Change -');
  907. ?>
  908. <label>
  909. <span class="title"><?php _e( 'Author' ); ?></span>
  910. <?php wp_dropdown_users( $users_opt ); ?>
  911. </label>
  912. <?php
  913. endif; // authors
  914. $authors_dropdown = ob_get_clean();
  915. ?>
  916. <?php if ( !$bulk ) : echo $authors_dropdown; ?>
  917. <div class="inline-edit-group">
  918. <label class="alignleft">
  919. <span class="title"><?php _e( 'Password' ); ?></span>
  920. <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
  921. </label>
  922. <em style="margin:5px 10px 0 0" class="alignleft">
  923. <?php
  924. /* translators: Between password field and private checkbox on post quick edit interface */
  925. echo __( '&ndash;OR&ndash;' );
  926. ?>
  927. </em>
  928. <label class="alignleft inline-edit-private">
  929. <input type="checkbox" name="keep_private" value="private" />
  930. <span class="checkbox-title"><?php echo $is_page ? __('Private page') : __('Private post'); ?></span>
  931. </label>
  932. </div>
  933. <?php endif; ?>
  934. </div></fieldset>
  935. <?php if ( !$is_page && !$bulk ) : ?>
  936. <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
  937. <span class="title inline-edit-categories-label"><?php _e( 'Categories' ); ?>
  938. <span class="catshow"><?php _e('[more]'); ?></span>
  939. <span class="cathide" style="display:none;"><?php _e('[less]'); ?></span>
  940. </span>
  941. <ul class="cat-checklist">
  942. <?php wp_category_checklist(); ?>
  943. </ul>
  944. </div></fieldset>
  945. <?php endif; // !$is_page && !$bulk ?>
  946. <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
  947. <?php
  948. if ( $bulk )
  949. echo $authors_dropdown;
  950. ?>
  951. <?php if ( $is_page ) : ?>
  952. <label>
  953. <span class="title"><?php _e( 'Parent' ); ?></span>
  954. <?php
  955. $dropdown_args = array('selected' => $post->post_parent, 'name' => 'post_parent', 'show_option_none' => __('Main Page (no parent)'), 'option_none_value' => 0, 'sort_column'=> 'menu_order, post_title');
  956. if ( $bulk )
  957. $dropdown_args['show_option_no_change'] = __('- No Change -');
  958. $dropdown_args = apply_filters('quick_edit_dropdown_pages_args', $dropdown_args);
  959. wp_dropdown_pages($dropdown_args);
  960. ?>
  961. </label>
  962. <?php if ( !$bulk ) : ?>
  963. <label>
  964. <span class="title"><?php _e( 'Order' ); ?></span>
  965. <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
  966. </label>
  967. <?php endif; // !$bulk ?>
  968. <label>
  969. <span class="title"><?php _e( 'Template' ); ?></span>
  970. <select name="page_template">
  971. <?php if ( $bulk ) : ?>
  972. <option value="-1"><?php _e('- No Change -'); ?></option>
  973. <?php endif; // $bulk ?>
  974. <option value="default"><?php _e( 'Default Template' ); ?></option>
  975. <?php page_template_dropdown() ?>
  976. </select>
  977. </label>
  978. <?php elseif ( !$bulk ) : // $is_page ?>
  979. <label class="inline-edit-tags">
  980. <span class="title"><?php _e( 'Tags' ); ?></span>
  981. <textarea cols="22" rows="1" name="tags_input" class="tags_input"></textarea>
  982. </label>
  983. <?php endif; // $is_page ?>
  984. <?php if ( $bulk ) : ?>
  985. <div class="inline-edit-group">
  986. <label class="alignleft">
  987. <span class="title"><?php _e( 'Comments' ); ?></span>
  988. <select name="comment_status">
  989. <option value=""><?php _e('- No Change -'); ?></option>
  990. <option value="open"><?php _e('Allow'); ?></option>
  991. <option value="closed"><?php _e('Do not allow'); ?></option>
  992. </select>
  993. </label>
  994. <label class="alignright">
  995. <span class="title"><?php _e( 'Pings' ); ?></span>
  996. <select name="ping_status">
  997. <option value=""><?php _e('- No Change -'); ?></option>
  998. <option value="open"><?php _e('Allow'); ?></option>
  999. <option value="closed"><?php _e('Do not allow'); ?></option>
  1000. </select>
  1001. </label>
  1002. </div>
  1003. <?php else : // $bulk ?>
  1004. <div class="inline-edit-group">
  1005. <label class="alignleft">
  1006. <input type="checkbox" name="comment_status" value="open" />
  1007. <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
  1008. </label>
  1009. <label class="alignleft">
  1010. <input type="checkbox" name="ping_status" value="open" />
  1011. <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
  1012. </label>
  1013. </div>
  1014. <?php endif; // $bulk ?>
  1015. <div class="inline-edit-group">
  1016. <label class="inline-edit-status alignleft">
  1017. <span class="title"><?php _e( 'Status' ); ?></span>
  1018. <select name="_status">
  1019. <?php if ( $bulk ) : ?>
  1020. <option value="-1"><?php _e('- No Change -'); ?></option>
  1021. <?php endif; // $bulk ?>
  1022. <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
  1023. <option value="publish"><?php _e( 'Published' ); ?></option>
  1024. <option value="future"><?php _e( 'Scheduled' ); ?></option>
  1025. <?php if ( $bulk ) : ?>
  1026. <option value="private"><?php _e('Private') ?></option>
  1027. <?php endif; // $bulk ?>
  1028. <?php endif; ?>
  1029. <option value="pending"><?php _e( 'Pending Review' ); ?></option>
  1030. <option value="draft"><?php _e( 'Draft' ); ?></option>
  1031. </select>
  1032. </label>
  1033. <?php if ( !$is_page && $can_publish && current_user_can( 'edit_others_posts' ) ) : ?>
  1034. <?php if ( $bulk ) : ?>
  1035. <label class="alignright">
  1036. <span class="title"><?php _e( 'Sticky' ); ?></span>
  1037. <select name="sticky">
  1038. <option value="-1"><?php _e( '- No Change -' ); ?></option>
  1039. <option value="sticky"><?php _e( 'Sticky' ); ?></option>
  1040. <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
  1041. </select>
  1042. </label>
  1043. <?php else : // $bulk ?>
  1044. <label class="alignleft">
  1045. <input type="checkbox" name="sticky" value="sticky" />
  1046. <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
  1047. </label>
  1048. <?php endif; // $bulk ?>
  1049. <?php endif; // !$is_page && $can_publish && current_user_can( 'edit_others_posts' ) ?>
  1050. </div>
  1051. </div></fieldset>
  1052. <?php
  1053. foreach ( $columns as $column_name => $column_display_name ) {
  1054. if ( isset( $core_columns[$column_name] ) )
  1055. continue;
  1056. do_action( $bulk ? 'bulk_edit_custom_box' : 'quick_edit_custom_box', $column_name, $type);
  1057. }
  1058. ?>
  1059. <p class="submit inline-edit-save">
  1060. <a accesskey="c" href="#inline-edit" title="<?php _e('Cancel'); ?>" class="button-secondary cancel alignleft"><?php _e('Cancel'); ?></a>
  1061. <?php if ( ! $bulk ) {
  1062. wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
  1063. $update_text = ( $is_page ) ? __( 'Update Page' ) : __( 'Update Post' );
  1064. ?>
  1065. <a accesskey="s" href="#inline-edit" title="<?php _e('Update'); ?>" class="button-primary save alignright"><?php echo attribute_escape( $update_text ); ?></a>
  1066. <img class="waiting" style="display:none;" src="images/loading.gif" alt="" />
  1067. <?php } else {
  1068. $update_text = ( $is_page ) ? __( 'Update Pages' ) : __( 'Update Posts' );
  1069. ?>
  1070. <input accesskey="s" class="button-primary alignright" type="submit" name="bulk_edit" value="<?php echo attribute_escape( $update_text ); ?>" />
  1071. <?php } ?>
  1072. <input type="hidden" name="post_view" value="<?php echo $m; ?>" />
  1073. <br class="clear" />
  1074. </p>
  1075. </td></tr>
  1076. <?php
  1077. $bulk++;
  1078. } ?>
  1079. </tbody></table></form>
  1080. <?php
  1081. }
  1082. // adds hidden fields with the data for use in the inline editor for posts and pages
  1083. /**
  1084. * {@internal Missing Short Description}}
  1085. *
  1086. * @since unknown
  1087. *
  1088. * @param unknown_type $post
  1089. */
  1090. function get_inline_data($post) {
  1091. if ( ! current_user_can('edit_' . $post->post_type, $post->ID) )
  1092. return;
  1093. $title = attribute_escape($post->post_title);
  1094. echo '
  1095. <div class="hidden" id="inline_' . $post->ID . '">
  1096. <div class="post_title">' . $title . '</div>
  1097. <div class="post_name">' . $post->post_name . '</div>
  1098. <div class="post_author">' . $post->post_author . '</div>
  1099. <div class="comment_status">' . $post->comment_status . '</div>
  1100. <div class="ping_status">' . $post->ping_status . '</div>
  1101. <div class="_status">' . $post->post_status . '</div>
  1102. <div class="jj">' . mysql2date( 'd', $post->post_date ) . '</div>
  1103. <div class="mm">' . mysql2date( 'm', $post->post_date ) . '</div>
  1104. <div class="aa">' . mysql2date( 'Y', $post->post_date ) . '</div>
  1105. <div class="hh">' . mysql2date( 'H', $post->post_date ) . '</div>
  1106. <div class="mn">' . mysql2date( 'i', $post->post_date ) . '</div>
  1107. <div class="ss">' . mysql2date( 's', $post->post_date ) . '</div>
  1108. <div class="post_password">' . wp_specialchars($post->post_password, 1) . '</div>';
  1109. if( $post->post_type == 'page' )
  1110. echo '
  1111. <div class="post_parent">' . $post->post_parent . '</div>
  1112. <div class="page_template">' . wp_specialchars(get_post_meta( $post->ID, '_wp_page_template', true ), 1) . '</div>
  1113. <div class="menu_order">' . $post->menu_order . '</div>';
  1114. if( $post->post_type == 'post' )
  1115. echo '
  1116. <div class="tags_input">' . wp_specialchars( str_replace( ',', ', ', get_tags_to_edit($post->ID) ), 1) . '</div>
  1117. <div class="post_category">' . implode( ',', wp_get_post_categories( $post->ID ) ) . '</div>
  1118. <div class="sticky">' . (is_sticky($post->ID) ? 'sticky' : '') . '</div>';
  1119. echo '</div>';
  1120. }
  1121. /**
  1122. * {@internal Missing Short Description}}
  1123. *
  1124. * @since unknown
  1125. *
  1126. * @param unknown_type $posts
  1127. */
  1128. function post_rows( $posts = array() ) {
  1129. global $wp_query, $post, $mode;
  1130. add_filter('the_title','wp_specialchars');
  1131. // Create array of post IDs.
  1132. $post_ids = array();
  1133. if ( empty($posts) )
  1134. $posts = &$wp_query->posts;
  1135. foreach ( $posts as $a_post )
  1136. $post_ids[] = $a_post->ID;
  1137. $comment_pending_count = get_pending_comments_num($post_ids);
  1138. if ( empty($comment_pending_count) )
  1139. $comment_pending_count = array();
  1140. foreach ( $posts as $post ) {
  1141. if ( empty($comment_pending_count[$post->ID]) )
  1142. $comment_pending_count[$post->ID] = 0;
  1143. _post_row($post, $comment_pending_count[$post->ID], $mode);
  1144. }
  1145. }
  1146. /**
  1147. * {@internal Missing Short Description}}
  1148. *
  1149. * @since unknown
  1150. *
  1151. * @param unknown_type $a_post
  1152. * @param unknown_type $pending_comments
  1153. * @param unknown_type $mode
  1154. */
  1155. function _post_row($a_post, $pending_comments, $mode) {
  1156. global $post;
  1157. static $rowclass;
  1158. $global_post = $post;
  1159. $post = $a_post;
  1160. setup_postdata($post);
  1161. $rowclass = 'alternate' == $rowclass ? '' : 'alternate';
  1162. global $current_user;
  1163. $post_owner = ( $current_user->ID == $post->post_author ? 'self' : 'other' );
  1164. $edit_link = get_edit_post_link( $post->ID );
  1165. $title = _draft_or_post_title();
  1166. ?>
  1167. <tr id='post-<?php echo $post->ID; ?>' class='<?php echo trim( $rowclass . ' author-' . $post_owner . ' status-' . $post->post_status ); ?> iedit' valign="top">
  1168. <?php
  1169. $posts_columns = get_column_headers('edit');
  1170. $hidden = get_hidden_columns('edit');
  1171. foreach ( $posts_columns as $column_name=>$column_display_name ) {
  1172. $class = "class=\"$column_name column-$column_name\"";
  1173. $style = '';
  1174. if ( in_array($column_name, $hidden) )
  1175. $style = ' style="display:none;"';
  1176. $attributes = "$class$style";
  1177. switch ($column_name) {
  1178. case 'cb':
  1179. ?>
  1180. <th scope="row" class="check-column"><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /><?php } ?></th>
  1181. <?php
  1182. break;
  1183. case 'date':
  1184. if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
  1185. $t_time = $h_time = __('Unpublished');
  1186. $time_diff = 0;
  1187. } else {
  1188. $t_time = get_the_time(__('Y/m/d g:i:s A'));
  1189. $m_time = $post->post_date;
  1190. $time = get_post_time('G', true, $post);
  1191. $time_diff = time() - $time;
  1192. if ( $time_diff > 0 && $time_diff < 24*60*60 )
  1193. $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
  1194. else
  1195. $h_time = mysql2date(__('Y/m/d'), $m_time);
  1196. }
  1197. echo '<td ' . $attributes . '>';
  1198. if ( 'excerpt' == $mode )
  1199. echo apply_filters('post_date_column_time', $t_time, $post, $column_name, $mode);
  1200. else
  1201. echo '<abbr title="' . $t_time . '">' . apply_filters('post_date_column_time', $h_time, $post, $column_name, $mode) . '</abbr>';
  1202. echo '<br />';
  1203. if ( 'publish' == $post->post_status ) {
  1204. _e('Published');
  1205. } elseif ( 'future' == $post->post_status ) {
  1206. if ( $time_diff > 0 )
  1207. echo '<strong class="attention">' . __('Missed schedule') . '</strong>';
  1208. else
  1209. _e('Scheduled');
  1210. } else {
  1211. _e('Last Modified');
  1212. }
  1213. echo '</td>';
  1214. break;
  1215. case 'title':
  1216. $attributes = 'class="post-title column-title"' . $style;
  1217. ?>
  1218. <td <?php echo $attributes ?>><strong><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; }; _post_states($post); ?></strong>
  1219. <?php
  1220. if ( 'excerpt' == $mode )
  1221. the_excerpt();
  1222. $actions = array();
  1223. if ( current_user_can('edit_post', $post->ID) ) {
  1224. $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '" title="' . attribute_escape(__('Edit this post')) . '">' . __('Edit') . '</a>';
  1225. $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . attribute_escape(__('Edit this post inline')) . '">' . __('Quick&nbsp;Edit') . '</a>';
  1226. $actions['delete'] = "<a class='submitdelete' title='" . attribute_escape(__('Delete this post')) . "' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "' onclick=\"if ( confirm('" . js_escape(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this draft '%s'\n 'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this post '%s'\n 'Cancel' to stop, 'OK' to delete."), $post->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
  1227. }
  1228. if ( in_array($post->post_status, array('pending', 'draft')) ) {
  1229. if ( current_user_can('edit_post', $post->ID) )
  1230. $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . attribute_escape(sprintf(__('Preview "%s"'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
  1231. } else {
  1232. $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . attribute_escape(sprintf(__('View "%s"'), $title)) . '" rel="permalink">' . __('View') . '</a>';
  1233. }
  1234. $actions = apply_filters('post_row_actions', $actions, $post);
  1235. $action_count = count($actions);
  1236. $i = 0;
  1237. echo '<div class="row-actions">';
  1238. foreach ( $actions as $action => $link ) {
  1239. ++$i;
  1240. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  1241. echo "<span class='$action'>$link$sep</span>";
  1242. }
  1243. echo '</div>';
  1244. get_inline_data($post);
  1245. ?>
  1246. </td>
  1247. <?php
  1248. break;
  1249. case 'categories':
  1250. ?>
  1251. <td <?php echo $attributes ?>><?php
  1252. $categories = get_the_category();
  1253. if ( !empty( $categories ) ) {
  1254. $out = array();
  1255. foreach ( $categories as $c )
  1256. $out[] = "<a href='edit.php?category_name=$c->slug'> " . wp_specialchars(sanitize_term_field('name', $c->name, $c->term_id, 'category', 'display')) . "</a>";
  1257. echo join( ', ', $out );
  1258. } else {
  1259. _e('Uncategorized');
  1260. }
  1261. ?></td>
  1262. <?php
  1263. break;
  1264. case 'tags':
  1265. ?>
  1266. <td <?php echo $attributes ?>><?php
  1267. $tags = get_the_tags($post->ID);
  1268. if ( !empty( $tags ) ) {
  1269. $out = array();
  1270. foreach ( $tags as $c )
  1271. $out[] = "<a href='edit.php?tag=$c->slug'> " . wp_specialchars(sanitize_term_field('name', $c->name, $c->term_id, 'post_tag', 'display')) . "</a>";
  1272. echo join( ', ', $out );
  1273. } else {
  1274. _e('No Tags');
  1275. }
  1276. ?></td>
  1277. <?php
  1278. break;
  1279. case 'comments':
  1280. ?>
  1281. <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
  1282. <?php
  1283. $pending_phrase = sprintf( __('%s pending'), number_format( $pending_comments ) );
  1284. if ( $pending_comments )
  1285. echo '<strong>';
  1286. comments_number("<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('0') . '</span></a>', "<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('1') . '</span></a>', "<a href='edit-comments.php?p=$post->ID' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('%') . '</span></a>');
  1287. if ( $pending_comments )
  1288. echo '</strong>';
  1289. ?>
  1290. </div></td>
  1291. <?php
  1292. break;
  1293. case 'author':
  1294. ?>
  1295. <td <?php echo $attributes ?>><a href="edit.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
  1296. <?php
  1297. break;
  1298. case 'control_view':
  1299. ?>
  1300. <td><a href="<?php the_permalink(); ?>" rel="permalink" class="view"><?php _e('View'); ?></a></td>
  1301. <?php
  1302. break;
  1303. case 'control_edit':
  1304. ?>
  1305. <td><?php if ( current_user_can('edit_post', $post->ID) ) { echo "<a href='$edit_link' class='edit'>" . __('Edit') . "</a>"; } ?></td>
  1306. <?php
  1307. break;
  1308. case 'control_delete':
  1309. ?>
  1310. <td><?php if ( current_user_can('delete_post', $post->ID) ) { echo "<a href='" . wp_nonce_url("post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "' class='delete'>" . __('Delete') . "</a>"; } ?></td>
  1311. <?php
  1312. break;

Large files files are truncated, but you can click here to view the full file