| 2 | | |
|---|
| 3 | | function write_post() { |
|---|
| 4 | | $result = wp_write_post(); |
|---|
| 5 | | if( is_wp_error( $result ) ) |
|---|
| 6 | | wp_die( $result->get_error_message() ); |
|---|
| 7 | | else |
|---|
| 8 | | return $result; |
|---|
| 9 | | } |
|---|
| 10 | | |
|---|
| 11 | | // Creates a new post from the "Write Post" form using $_POST information. |
|---|
| 12 | | function wp_write_post() { |
|---|
| 13 | | global $user_ID; |
|---|
| 14 | | |
|---|
| 15 | | if ( 'page' == $_POST['post_type'] ) { |
|---|
| 16 | | if ( !current_user_can( 'edit_pages' ) ) |
|---|
| 17 | | return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this blog.' ) ); |
|---|
| 18 | | } else { |
|---|
| 19 | | if ( !current_user_can( 'edit_posts' ) ) |
|---|
| 20 | | return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) ); |
|---|
| 21 | | } |
|---|
| 22 | | |
|---|
| 23 | | |
|---|
| 24 | | // Check for autosave collisions |
|---|
| 25 | | $temp_id = false; |
|---|
| 26 | | if ( isset($_POST['temp_ID']) ) { |
|---|
| 27 | | $temp_id = (int) $_POST['temp_ID']; |
|---|
| 28 | | if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) |
|---|
| 29 | | $draft_ids = array(); |
|---|
| 30 | | foreach ( $draft_ids as $temp => $real ) |
|---|
| 31 | | if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then ) |
|---|
| 32 | | unset($draft_ids[$temp]); |
|---|
| 33 | | |
|---|
| 34 | | if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write |
|---|
| 35 | | $_POST['post_ID'] = $draft_ids[$temp_id]; |
|---|
| 36 | | unset($_POST['temp_ID']); |
|---|
| 37 | | update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids ); |
|---|
| 38 | | return edit_post(); |
|---|
| 39 | | } |
|---|
| 40 | | } |
|---|
| 41 | | |
|---|
| 42 | | // Rename. |
|---|
| 43 | | $_POST['post_content'] = $_POST['content']; |
|---|
| 44 | | $_POST['post_excerpt'] = $_POST['excerpt']; |
|---|
| 45 | | $_POST['post_parent'] = $_POST['parent_id']; |
|---|
| 46 | | $_POST['to_ping'] = $_POST['trackback_url']; |
|---|
| 47 | | |
|---|
| 48 | | if (!empty ( $_POST['post_author_override'] ) ) { |
|---|
| 49 | | $_POST['post_author'] = (int) $_POST['post_author_override']; |
|---|
| 50 | | } else { |
|---|
| 51 | | if (!empty ( $_POST['post_author'] ) ) { |
|---|
| 52 | | $_POST['post_author'] = (int) $_POST['post_author']; |
|---|
| 53 | | } else { |
|---|
| 54 | | $_POST['post_author'] = (int) $_POST['user_ID']; |
|---|
| 55 | | } |
|---|
| 56 | | |
|---|
| 57 | | } |
|---|
| 58 | | |
|---|
| 59 | | if ( $_POST['post_author'] != $_POST['user_ID'] ) { |
|---|
| 60 | | if ( 'page' == $_POST['post_type'] ) { |
|---|
| 61 | | if ( !current_user_can( 'edit_others_pages' ) ) |
|---|
| 62 | | return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) ); |
|---|
| 63 | | } else { |
|---|
| 64 | | if ( !current_user_can( 'edit_others_posts' ) ) |
|---|
| 65 | | return new WP_Error( 'edit_others_posts', __( 'You are not allowed to post as this user.' ) ); |
|---|
| 66 | | |
|---|
| 67 | | } |
|---|
| 68 | | } |
|---|
| 69 | | |
|---|
| 70 | | // What to do based on which button they pressed |
|---|
| 71 | | if ('' != $_POST['saveasdraft'] ) |
|---|
| 72 | | $_POST['post_status'] = 'draft'; |
|---|
| 73 | | if ('' != $_POST['saveasprivate'] ) |
|---|
| 74 | | $_POST['post_status'] = 'private'; |
|---|
| 75 | | if ('' != $_POST['publish'] ) |
|---|
| 76 | | $_POST['post_status'] = 'publish'; |
|---|
| 77 | | if ('' != $_POST['advanced'] ) |
|---|
| 78 | | $_POST['post_status'] = 'draft'; |
|---|
| 79 | | |
|---|
| 80 | | if ( 'page' == $_POST['post_type'] ) { |
|---|
| 81 | | if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) ) |
|---|
| 82 | | $_POST['post_status'] = 'draft'; |
|---|
| 83 | | } else { |
|---|
| 84 | | if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) ) |
|---|
| 85 | | $_POST['post_status'] = 'draft'; |
|---|
| 86 | | } |
|---|
| 87 | | |
|---|
| 88 | | if (!isset( $_POST['comment_status'] )) |
|---|
| 89 | | $_POST['comment_status'] = 'closed'; |
|---|
| 90 | | |
|---|
| 91 | | if (!isset( $_POST['ping_status'] )) |
|---|
| 92 | | $_POST['ping_status'] = 'closed'; |
|---|
| 93 | | |
|---|
| 94 | | if (!empty ( $_POST['edit_date'] ) ) { |
|---|
| 95 | | $aa = $_POST['aa']; |
|---|
| 96 | | $mm = $_POST['mm']; |
|---|
| 97 | | $jj = $_POST['jj']; |
|---|
| 98 | | $hh = $_POST['hh']; |
|---|
| 99 | | $mn = $_POST['mn']; |
|---|
| 100 | | $ss = $_POST['ss']; |
|---|
| 101 | | $jj = ($jj > 31 ) ? 31 : $jj; |
|---|
| 102 | | $hh = ($hh > 23 ) ? $hh -24 : $hh; |
|---|
| 103 | | $mn = ($mn > 59 ) ? $mn -60 : $mn; |
|---|
| 104 | | $ss = ($ss > 59 ) ? $ss -60 : $ss; |
|---|
| 105 | | $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); |
|---|
| 106 | | $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] ); |
|---|
| 107 | | } |
|---|
| 108 | | |
|---|
| 109 | | unset($_POST['no_filter']); |
|---|
| 110 | | |
|---|
| 111 | | // Create the post. |
|---|
| 112 | | $post_ID = wp_insert_post( $_POST ); |
|---|
| 113 | | |
|---|
| 114 | | add_meta( $post_ID ); |
|---|
| 115 | | |
|---|
| 116 | | // Reunite any orphaned attachments with their parent |
|---|
| 117 | | if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) |
|---|
| 118 | | $draft_ids = array(); |
|---|
| 119 | | if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) ) |
|---|
| 120 | | relocate_children( $draft_temp_id, $post_ID ); |
|---|
| 121 | | if ( $temp_id && $temp_id != $draft_temp_id ) |
|---|
| 122 | | relocate_children( $temp_id, $post_ID ); |
|---|
| 123 | | |
|---|
| 124 | | // Update autosave collision detection |
|---|
| 125 | | if ( $temp_id ) { |
|---|
| 126 | | $draft_ids[$temp_id] = $post_ID; |
|---|
| 127 | | update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids ); |
|---|
| 128 | | } |
|---|
| 129 | | |
|---|
| 130 | | // Now that we have an ID we can fix any attachment anchor hrefs |
|---|
| 131 | | fix_attachment_links( $post_ID ); |
|---|
| 132 | | |
|---|
| 133 | | return $post_ID; |
|---|
| 134 | | } |
|---|
| 135 | | |
|---|
| 136 | | // Move child posts to a new parent |
|---|
| 137 | | function relocate_children( $old_ID, $new_ID ) { |
|---|
| 138 | | global $wpdb; |
|---|
| 139 | | $old_ID = (int) $old_ID; |
|---|
| 140 | | $new_ID = (int) $new_ID; |
|---|
| 141 | | return $wpdb->query( "UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID" ); |
|---|
| 142 | | } |
|---|
| 143 | | |
|---|
| 144 | | // Replace hrefs of attachment anchors with up-to-date permalinks. |
|---|
| 145 | | function fix_attachment_links( $post_ID ) { |
|---|
| 146 | | global $wp_rewrite; |
|---|
| 147 | | |
|---|
| 148 | | $post = & get_post( $post_ID, ARRAY_A ); |
|---|
| 149 | | |
|---|
| 150 | | $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie"; |
|---|
| 151 | | |
|---|
| 152 | | // See if we have any rel="attachment" links |
|---|
| 153 | | if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER ) ) |
|---|
| 154 | | return; |
|---|
| 155 | | |
|---|
| 156 | | $i = 0; |
|---|
| 157 | | $search = "#[\s]+rel=(\"|')(.*?)wp-att-(\d+)\\1#i"; |
|---|
| 158 | | foreach ( $anchor_matches[0] as $anchor ) { |
|---|
| 159 | | if ( 0 == preg_match( $search, $anchor, $id_matches ) ) |
|---|
| 160 | | continue; |
|---|
| 161 | | |
|---|
| 162 | | $id = (int) $id_matches[3]; |
|---|
| 163 | | |
|---|
| 164 | | // While we have the attachment ID, let's adopt any orphans. |
|---|
| 165 | | $attachment = & get_post( $id, ARRAY_A ); |
|---|
| 166 | | if ( ! empty( $attachment) && ! is_object( get_post( $attachment['post_parent'] ) ) ) { |
|---|
| 167 | | $attachment['post_parent'] = $post_ID; |
|---|
| 168 | | // Escape data pulled from DB. |
|---|
| 169 | | $attachment = add_magic_quotes( $attachment); |
|---|
| 170 | | wp_update_post( $attachment); |
|---|
| 171 | | } |
|---|
| 172 | | |
|---|
| 173 | | $post_search[$i] = $anchor; |
|---|
| 174 | | $post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor ); |
|---|
| 175 | | ++$i; |
|---|
| 176 | | } |
|---|
| 177 | | |
|---|
| 178 | | $post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] ); |
|---|
| 179 | | |
|---|
| 180 | | // Escape data pulled from DB. |
|---|
| 181 | | $post = add_magic_quotes( $post); |
|---|
| 182 | | |
|---|
| 183 | | return wp_update_post( $post); |
|---|
| 184 | | } |
|---|
| 185 | | |
|---|
| 186 | | // Update an existing post with values provided in $_POST. |
|---|
| 187 | | function edit_post() { |
|---|
| 188 | | global $user_ID; |
|---|
| 189 | | |
|---|
| 190 | | $post_ID = (int) $_POST['post_ID']; |
|---|
| 191 | | |
|---|
| 192 | | if ( 'page' == $_POST['post_type'] ) { |
|---|
| 193 | | if ( !current_user_can( 'edit_page', $post_ID ) ) |
|---|
| 194 | | wp_die( __('You are not allowed to edit this page.' )); |
|---|
| 195 | | } else { |
|---|
| 196 | | if ( !current_user_can( 'edit_post', $post_ID ) ) |
|---|
| 197 | | wp_die( __('You are not allowed to edit this post.' )); |
|---|
| 198 | | } |
|---|
| 199 | | |
|---|
| 200 | | // Autosave shouldn't save too soon after a real save |
|---|
| 201 | | if ( 'autosave' == $_POST['action'] ) { |
|---|
| 202 | | $post =& get_post( $post_ID ); |
|---|
| 203 | | $now = time(); |
|---|
| 204 | | $then = strtotime($post->post_date_gmt . ' +0000'); |
|---|
| 205 | | // Keep autosave_interval in sync with autosave-js.php. |
|---|
| 206 | | $delta = apply_filters( 'autosave_interval', 120 ) / 2; |
|---|
| 207 | | if ( ($now - $then) < $delta ) |
|---|
| 208 | | return $post_ID; |
|---|
| 209 | | } |
|---|
| 210 | | |
|---|
| 211 | | // Rename. |
|---|
| 212 | | $_POST['ID'] = (int) $_POST['post_ID']; |
|---|
| 213 | | $_POST['post_content'] = $_POST['content']; |
|---|
| 214 | | $_POST['post_excerpt'] = $_POST['excerpt']; |
|---|
| 215 | | $_POST['post_parent'] = $_POST['parent_id']; |
|---|
| 216 | | $_POST['to_ping'] = $_POST['trackback_url']; |
|---|
| 217 | | |
|---|
| 218 | | if (!empty ( $_POST['post_author_override'] ) ) { |
|---|
| 219 | | $_POST['post_author'] = (int) $_POST['post_author_override']; |
|---|
| 220 | | } else |
|---|
| 221 | | if (!empty ( $_POST['post_author'] ) ) { |
|---|
| 222 | | $_POST['post_author'] = (int) $_POST['post_author']; |
|---|
| 223 | | } else { |
|---|
| 224 | | $_POST['post_author'] = (int) $_POST['user_ID']; |
|---|
| 225 | | } |
|---|
| 226 | | |
|---|
| 227 | | if ( $_POST['post_author'] != $_POST['user_ID'] ) { |
|---|
| 228 | | if ( 'page' == $_POST['post_type'] ) { |
|---|
| 229 | | if ( !current_user_can( 'edit_others_pages' ) ) |
|---|
| 230 | | wp_die( __('You are not allowed to edit pages as this user.' )); |
|---|
| 231 | | } else { |
|---|
| 232 | | if ( !current_user_can( 'edit_others_posts' ) ) |
|---|
| 233 | | wp_die( __('You are not allowed to edit posts as this user.' )); |
|---|
| 234 | | |
|---|
| 235 | | } |
|---|
| 236 | | } |
|---|
| 237 | | |
|---|
| 238 | | // What to do based on which button they pressed |
|---|
| 239 | | if ('' != $_POST['saveasdraft'] ) |
|---|
| 240 | | $_POST['post_status'] = 'draft'; |
|---|
| 241 | | if ('' != $_POST['saveasprivate'] ) |
|---|
| 242 | | $_POST['post_status'] = 'private'; |
|---|
| 243 | | if ('' != $_POST['publish'] ) |
|---|
| 244 | | $_POST['post_status'] = 'publish'; |
|---|
| 245 | | if ('' != $_POST['advanced'] ) |
|---|
| 246 | | $_POST['post_status'] = 'draft'; |
|---|
| 247 | | |
|---|
| 248 | | if ( 'page' == $_POST['post_type'] ) { |
|---|
| 249 | | if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_pages' )) |
|---|
| 250 | | $_POST['post_status'] = 'draft'; |
|---|
| 251 | | } else { |
|---|
| 252 | | if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_posts' )) |
|---|
| 253 | | $_POST['post_status'] = 'draft'; |
|---|
| 254 | | } |
|---|
| 255 | | |
|---|
| 256 | | if (!isset( $_POST['comment_status'] )) |
|---|
| 257 | | $_POST['comment_status'] = 'closed'; |
|---|
| 258 | | |
|---|
| 259 | | if (!isset( $_POST['ping_status'] )) |
|---|
| 260 | | $_POST['ping_status'] = 'closed'; |
|---|
| 261 | | |
|---|
| 262 | | if (!empty ( $_POST['edit_date'] ) ) { |
|---|
| 263 | | $aa = $_POST['aa']; |
|---|
| 264 | | $mm = $_POST['mm']; |
|---|
| 265 | | $jj = $_POST['jj']; |
|---|
| 266 | | $hh = $_POST['hh']; |
|---|
| 267 | | $mn = $_POST['mn']; |
|---|
| 268 | | $ss = $_POST['ss']; |
|---|
| 269 | | $jj = ($jj > 31 ) ? 31 : $jj; |
|---|
| 270 | | $hh = ($hh > 23 ) ? $hh -24 : $hh; |
|---|
| 271 | | $mn = ($mn > 59 ) ? $mn -60 : $mn; |
|---|
| 272 | | $ss = ($ss > 59 ) ? $ss -60 : $ss; |
|---|
| 273 | | $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; |
|---|
| 274 | | $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss" ); |
|---|
| 275 | | } |
|---|
| 276 | | |
|---|
| 277 | | // Meta Stuff |
|---|
| 278 | | if ( $_POST['meta'] ) { |
|---|
| 279 | | foreach ( $_POST['meta'] as $key => $value ) |
|---|
| 280 | | update_meta( $key, $value['key'], $value['value'] ); |
|---|
| 281 | | } |
|---|
| 282 | | |
|---|
| 283 | | if ( $_POST['deletemeta'] ) { |
|---|
| 284 | | foreach ( $_POST['deletemeta'] as $key => $value ) |
|---|
| 285 | | delete_meta( $key ); |
|---|
| 286 | | } |
|---|
| 287 | | |
|---|
| 288 | | unset($_POST['no_filter']); |
|---|
| 289 | | |
|---|
| 290 | | add_meta( $post_ID ); |
|---|
| 291 | | |
|---|
| 292 | | wp_update_post( $_POST ); |
|---|
| 293 | | |
|---|
| 294 | | // Reunite any orphaned attachments with their parent |
|---|
| 295 | | if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) |
|---|
| 296 | | $draft_ids = array(); |
|---|
| 297 | | if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) ) |
|---|
| 298 | | relocate_children( $draft_temp_id, $post_ID ); |
|---|
| 299 | | |
|---|
| 300 | | // Now that we have an ID we can fix any attachment anchor hrefs |
|---|
| 301 | | fix_attachment_links( $post_ID ); |
|---|
| 302 | | |
|---|
| 303 | | return $post_ID; |
|---|
| 304 | | } |
|---|
| 305 | | |
|---|
| 306 | | function edit_comment() { |
|---|
| 307 | | global $user_ID; |
|---|
| 308 | | |
|---|
| 309 | | $comment_ID = (int) $_POST['comment_ID']; |
|---|
| 310 | | $comment_post_ID = (int) $_POST['comment_post_ID']; |
|---|
| 311 | | |
|---|
| 312 | | if (!current_user_can( 'edit_post', $comment_post_ID )) |
|---|
| 313 | | wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.' )); |
|---|
| 314 | | |
|---|
| 315 | | $_POST['comment_author'] = $_POST['newcomment_author']; |
|---|
| 316 | | $_POST['comment_author_email'] = $_POST['newcomment_author_email']; |
|---|
| 317 | | $_POST['comment_author_url'] = $_POST['newcomment_author_url']; |
|---|
| 318 | | $_POST['comment_approved'] = $_POST['comment_status']; |
|---|
| 319 | | $_POST['comment_content'] = $_POST['content']; |
|---|
| 320 | | $_POST['comment_ID'] = (int) $_POST['comment_ID']; |
|---|
| 321 | | |
|---|
| 322 | | if (!empty ( $_POST['edit_date'] ) ) { |
|---|
| 323 | | $aa = $_POST['aa']; |
|---|
| 324 | | $mm = $_POST['mm']; |
|---|
| 325 | | $jj = $_POST['jj']; |
|---|
| 326 | | $hh = $_POST['hh']; |
|---|
| 327 | | $mn = $_POST['mn']; |
|---|
| 328 | | $ss = $_POST['ss']; |
|---|
| 329 | | $jj = ($jj > 31 ) ? 31 : $jj; |
|---|
| 330 | | $hh = ($hh > 23 ) ? $hh -24 : $hh; |
|---|
| 331 | | $mn = ($mn > 59 ) ? $mn -60 : $mn; |
|---|
| 332 | | $ss = ($ss > 59 ) ? $ss -60 : $ss; |
|---|
| 333 | | $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; |
|---|
| 334 | | } |
|---|
| 335 | | |
|---|
| 336 | | wp_update_comment( $_POST); |
|---|
| 337 | | } |
|---|
| 338 | | |
|---|
| 339 | | // Get an existing post and format it for editing. |
|---|
| 340 | | function get_post_to_edit( $id ) { |
|---|
| 341 | | |
|---|
| 342 | | $post = get_post( $id ); |
|---|
| 343 | | |
|---|
| 344 | | $post->post_content = format_to_edit( $post->post_content, user_can_richedit() ); |
|---|
| 345 | | $post->post_content = apply_filters( 'content_edit_pre', $post->post_content); |
|---|
| 346 | | |
|---|
| 347 | | $post->post_excerpt = format_to_edit( $post->post_excerpt); |
|---|
| 348 | | $post->post_excerpt = apply_filters( 'excerpt_edit_pre', $post->post_excerpt); |
|---|
| 349 | | |
|---|
| 350 | | $post->post_title = format_to_edit( $post->post_title ); |
|---|
| 351 | | $post->post_title = apply_filters( 'title_edit_pre', $post->post_title ); |
|---|
| 352 | | |
|---|
| 353 | | $post->post_password = format_to_edit( $post->post_password ); |
|---|
| 354 | | |
|---|
| 355 | | $post->menu_order = (int) $post->menu_order; |
|---|
| 356 | | |
|---|
| 357 | | if ( $post->post_type == 'page' ) |
|---|
| 358 | | $post->page_template = get_post_meta( $id, '_wp_page_template', true ); |
|---|
| 359 | | |
|---|
| 360 | | return $post; |
|---|
| 361 | | } |
|---|
| 362 | | |
|---|
| 363 | | // Default post information to use when populating the "Write Post" form. |
|---|
| 364 | | function get_default_post_to_edit() { |
|---|
| 365 | | if ( !empty( $_REQUEST['post_title'] ) ) |
|---|
| 366 | | $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] )); |
|---|
| 367 | | else if ( !empty( $_REQUEST['popuptitle'] ) ) { |
|---|
| 368 | | $post_title = wp_specialchars( stripslashes( $_REQUEST['popuptitle'] )); |
|---|
| 369 | | $post_title = funky_javascript_fix( $post_title ); |
|---|
| 370 | | } else { |
|---|
| 371 | | $post_title = ''; |
|---|
| 372 | | } |
|---|
| 373 | | |
|---|
| 374 | | if ( !empty( $_REQUEST['content'] ) ) |
|---|
| 375 | | $post_content = wp_specialchars( stripslashes( $_REQUEST['content'] )); |
|---|
| 376 | | else if ( !empty( $post_title ) ) { |
|---|
| 377 | | $text = wp_specialchars( stripslashes( urldecode( $_REQUEST['text'] ) ) ); |
|---|
| 378 | | $text = funky_javascript_fix( $text); |
|---|
| 379 | | $popupurl = clean_url($_REQUEST['popupurl']); |
|---|
| 380 | | $post_content = '<a href="'.$popupurl.'">'.$post_title.'</a>'."\n$text"; |
|---|
| 381 | | } |
|---|
| 382 | | |
|---|
| 383 | | if ( !empty( $_REQUEST['excerpt'] ) ) |
|---|
| 384 | | $post_excerpt = wp_specialchars( stripslashes( $_REQUEST['excerpt'] )); |
|---|
| 385 | | else |
|---|
| 386 | | $post_excerpt = ''; |
|---|
| 387 | | |
|---|
| 388 | | $post->post_status = 'draft'; |
|---|
| 389 | | $post->comment_status = get_option( 'default_comment_status' ); |
|---|
| 390 | | $post->ping_status = get_option( 'default_ping_status' ); |
|---|
| 391 | | $post->post_pingback = get_option( 'default_pingback_flag' ); |
|---|
| 392 | | $post->post_category = get_option( 'default_category' ); |
|---|
| 393 | | $post->post_content = apply_filters( 'default_content', $post_content); |
|---|
| 394 | | $post->post_title = apply_filters( 'default_title', $post_title ); |
|---|
| 395 | | $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt); |
|---|
| 396 | | $post->page_template = 'default'; |
|---|
| 397 | | $post->post_parent = 0; |
|---|
| 398 | | $post->menu_order = 0; |
|---|
| 399 | | |
|---|
| 400 | | return $post; |
|---|
| 401 | | } |
|---|
| 402 | | |
|---|
| 403 | | function get_comment_to_edit( $id ) { |
|---|
| 404 | | $comment = get_comment( $id ); |
|---|
| 405 | | |
|---|
| 406 | | $comment->comment_ID = (int) $comment->comment_ID; |
|---|
| 407 | | $comment->comment_post_ID = (int) $comment->comment_post_ID; |
|---|
| 408 | | |
|---|
| 409 | | $comment->comment_content = format_to_edit( $comment->comment_content ); |
|---|
| 410 | | $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content); |
|---|
| 411 | | |
|---|
| 412 | | $comment->comment_author = format_to_edit( $comment->comment_author ); |
|---|
| 413 | | $comment->comment_author_email = format_to_edit( $comment->comment_author_email ); |
|---|
| 414 | | $comment->comment_author_url = clean_url($comment->comment_author_url); |
|---|
| 415 | | $comment->comment_author_url = format_to_edit( $comment->comment_author_url ); |
|---|
| 416 | | |
|---|
| 417 | | return $comment; |
|---|
| 418 | | } |
|---|
| 419 | | |
|---|
| 420 | | function get_category_to_edit( $id ) { |
|---|
| 421 | | $category = get_category( $id ); |
|---|
| 422 | | |
|---|
| 423 | | $category->term_id = (int) $category->term_id; |
|---|
| 424 | | $category->parent = (int) $category->parent; |
|---|
| 425 | | |
|---|
| 426 | | return $category; |
|---|
| 427 | | } |
|---|
| 428 | | |
|---|
| 429 | | function wp_dropdown_roles( $default = false ) { |
|---|
| 430 | | global $wp_roles; |
|---|
| 431 | | $r = ''; |
|---|
| 432 | | foreach( $wp_roles->role_names as $role => $name ) |
|---|
| 433 | | if ( $default == $role ) // Make default first in list |
|---|
| 434 | | $p = "\n\t<option selected='selected' value='$role'>$name</option>"; |
|---|
| 435 | | else |
|---|
| 436 | | $r .= "\n\t<option value='$role'>$name</option>"; |
|---|
| 437 | | echo $p . $r; |
|---|
| 438 | | } |
|---|
| 439 | | |
|---|
| 440 | | |
|---|
| 441 | | function get_user_to_edit( $user_id ) { |
|---|
| 442 | | $user = new WP_User( $user_id ); |
|---|
| 443 | | $user->user_login = attribute_escape($user->user_login); |
|---|
| 444 | | $user->user_email = attribute_escape($user->user_email); |
|---|
| 445 | | $user->user_url = clean_url($user->user_url); |
|---|
| 446 | | $user->first_name = attribute_escape($user->first_name); |
|---|
| 447 | | $user->last_name = attribute_escape($user->last_name); |
|---|
| 448 | | $user->display_name = attribute_escape($user->display_name); |
|---|
| 449 | | $user->nickname = attribute_escape($user->nickname); |
|---|
| 450 | | $user->aim = attribute_escape($user->aim); |
|---|
| 451 | | $user->yim = attribute_escape($user->yim); |
|---|
| 452 | | $user->jabber = attribute_escape($user->jabber); |
|---|
| 453 | | $user->description = wp_specialchars($user->description); |
|---|
| 454 | | |
|---|
| 455 | | return $user; |
|---|
| 456 | | } |
|---|
| 457 | | |
|---|
| 458 | | // Creates a new user from the "Users" form using $_POST information. |
|---|
| 459 | | |
|---|
| 460 | | function add_user() { |
|---|
| 461 | | if ( func_num_args() ) { // The hackiest hack that ever did hack |
|---|
| 462 | | global $current_user, $wp_roles; |
|---|
| 463 | | $user_id = (int) func_get_arg( 0 ); |
|---|
| 464 | | |
|---|
| 465 | | if ( isset( $_POST['role'] ) ) { |
|---|
| 466 | | if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' ) ) { |
|---|
| 467 | | $user = new WP_User( $user_id ); |
|---|
| 468 | | $user->set_role( $_POST['role'] ); |
|---|
| 469 | | } |
|---|
| 470 | | } |
|---|
| 471 | | } else { |
|---|
| 472 | | add_action( 'user_register', 'add_user' ); // See above |
|---|
| 473 | | return edit_user(); |
|---|
| 474 | | } |
|---|
| 475 | | } |
|---|
| 476 | | |
|---|
| 477 | | function edit_user( $user_id = 0 ) { |
|---|
| 478 | | global $current_user, $wp_roles, $wpdb; |
|---|
| 479 | | if ( $user_id != 0 ) { |
|---|
| 480 | | $update = true; |
|---|
| 481 | | $user->ID = (int) $user_id; |
|---|
| 482 | | $userdata = get_userdata( $user_id ); |
|---|
| 483 | | $user->user_login = $wpdb->escape( $userdata->user_login ); |
|---|
| 484 | | } else { |
|---|
| 485 | | $update = false; |
|---|
| 486 | | $user = ''; |
|---|
| 487 | | } |
|---|
| 488 | | |
|---|
| 489 | | if ( isset( $_POST['user_login'] )) |
|---|
| 490 | | $user->user_login = wp_specialchars( trim( $_POST['user_login'] )); |
|---|
| 491 | | |
|---|
| 492 | | $pass1 = $pass2 = ''; |
|---|
| 493 | | if ( isset( $_POST['pass1'] )) |
|---|
| 494 | | $pass1 = $_POST['pass1']; |
|---|
| 495 | | if ( isset( $_POST['pass2'] )) |
|---|
| 496 | | $pass2 = $_POST['pass2']; |
|---|
| 497 | | |
|---|
| 498 | | if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) { |
|---|
| 499 | | if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' )) |
|---|
| 500 | | $user->role = $_POST['role']; |
|---|
| 501 | | } |
|---|
| 502 | | |
|---|
| 503 | | if ( isset( $_POST['email'] )) |
|---|
| 504 | | $user->user_email = wp_specialchars( trim( $_POST['email'] )); |
|---|
| 505 | | if ( isset( $_POST['url'] ) ) { |
|---|
| 506 | | $user->user_url = clean_url( trim( $_POST['url'] )); |
|---|
| 507 | | $user->user_url = preg_match('/^(https?|ftps?|mailto|news|irc|gopher|nntp|feed|telnet):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url; |
|---|
| 508 | | } |
|---|
| 509 | | if ( isset( $_POST['first_name'] )) |
|---|
| 510 | | $user->first_name = wp_specialchars( trim( $_POST['first_name'] )); |
|---|
| 511 | | if ( isset( $_POST['last_name'] )) |
|---|
| 512 | | $user->last_name = wp_specialchars( trim( $_POST['last_name'] )); |
|---|
| 513 | | if ( isset( $_POST['nickname'] )) |
|---|
| 514 | | $user->nickname = wp_specialchars( trim( $_POST['nickname'] )); |
|---|
| 515 | | if ( isset( $_POST['display_name'] )) |
|---|
| 516 | | $user->display_name = wp_specialchars( trim( $_POST['display_name'] )); |
|---|
| 517 | | if ( isset( $_POST['description'] )) |
|---|
| 518 | | $user->description = trim( $_POST['description'] ); |
|---|
| 519 | | if ( isset( $_POST['jabber'] )) |
|---|
| 520 | | $user->jabber = wp_specialchars( trim( $_POST['jabber'] )); |
|---|
| 521 | | if ( isset( $_POST['aim'] )) |
|---|
| 522 | | $user->aim = wp_specialchars( trim( $_POST['aim'] )); |
|---|
| 523 | | if ( isset( $_POST['yim'] )) |
|---|
| 524 | | $user->yim = wp_specialchars( trim( $_POST['yim'] )); |
|---|
| 525 | | if ( !$update ) |
|---|
| 526 | | $user->rich_editing = 'true'; // Default to true for new users. |
|---|
| 527 | | else if ( isset( $_POST['rich_editing'] ) ) |
|---|
| 528 | | $user->rich_editing = $_POST['rich_editing']; |
|---|
| 529 | | else |
|---|
| 530 | | $user->rich_editing = 'false'; |
|---|
| 531 | | |
|---|
| 532 | | $errors = new WP_Error(); |
|---|
| 533 | | |
|---|
| 534 | | /* checking that username has been typed */ |
|---|
| 535 | | if ( $user->user_login == '' ) |
|---|
| 536 | | $errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' )); |
|---|
| 537 | | |
|---|
| 538 | | /* checking the password has been typed twice */ |
|---|
| 539 | | do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 )); |
|---|
| 540 | | |
|---|
| 541 | | if (!$update ) { |
|---|
| 542 | | if ( $pass1 == '' || $pass2 == '' ) |
|---|
| 543 | | $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' )); |
|---|
| 544 | | } else { |
|---|
| 545 | | if ((empty ( $pass1 ) && !empty ( $pass2 ) ) || (empty ( $pass2 ) && !empty ( $pass1 ) ) ) |
|---|
| 546 | | $errors->add( 'pass', __( "<strong>ERROR</strong>: you typed your new password only once." )); |
|---|
| 547 | | } |
|---|
| 548 | | |
|---|
| 549 | | /* Check for "\" in password */ |
|---|
| 550 | | if( strpos( " ".$pass1, "\\" ) ) |
|---|
| 551 | | $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' )); |
|---|
| 552 | | |
|---|
| 553 | | /* checking the password has been typed twice the same */ |
|---|
| 554 | | if ( $pass1 != $pass2 ) |
|---|
| 555 | | $errors->add( 'pass', __( '<strong>ERROR</strong>: Please type the same password in the two password fields.' )); |
|---|
| 556 | | |
|---|
| 557 | | if (!empty ( $pass1 )) |
|---|
| 558 | | $user->user_pass = $pass1; |
|---|
| 559 | | |
|---|
| 560 | | if ( !$update && !validate_username( $user->user_login ) ) |
|---|
| 561 | | $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' )); |
|---|
| 562 | | |
|---|
| 563 | | if (!$update && username_exists( $user->user_login )) |
|---|
| 564 | | $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.' )); |
|---|
| 565 | | |
|---|
| 566 | | /* checking e-mail address */ |
|---|
| 567 | | if ( empty ( $user->user_email ) ) { |
|---|
| 568 | | $errors->add( 'user_email', __( "<strong>ERROR</strong>: please type an e-mail address" )); |
|---|
| 569 | | } else |
|---|
| 570 | | if (!is_email( $user->user_email ) ) { |
|---|
| 571 | | $errors->add( 'user_email', __( "<strong>ERROR</strong>: the email address isn't correct" )); |
|---|
| 572 | | } |
|---|
| 573 | | |
|---|
| 574 | | if ( $errors->get_error_codes() ) |
|---|
| 575 | | return $errors; |
|---|
| 576 | | |
|---|
| 577 | | if ( $update ) { |
|---|
| 578 | | $user_id = wp_update_user( get_object_vars( $user )); |
|---|
| 579 | | } else { |
|---|
| 580 | | $user_id = wp_insert_user( get_object_vars( $user )); |
|---|
| 581 | | wp_new_user_notification( $user_id ); |
|---|
| 582 | | } |
|---|
| 583 | | return $user_id; |
|---|
| 584 | | } |
|---|
| 585 | | |
|---|
| 586 | | |
|---|
| 587 | | function get_link_to_edit( $link_id ) { |
|---|
| 588 | | $link = get_link( $link_id ); |
|---|
| 589 | | |
|---|
| 590 | | $link->link_url = clean_url($link->link_url); |
|---|
| 591 | | $link->link_name = attribute_escape($link->link_name); |
|---|
| 592 | | $link->link_image = attribute_escape($link->link_image); |
|---|
| 593 | | $link->link_description = attribute_escape($link->link_description); |
|---|
| 594 | | $link->link_rss = clean_url($link->link_rss); |
|---|
| 595 | | $link->link_rel = attribute_escape($link->link_rel); |
|---|
| 596 | | $link->link_notes = wp_specialchars($link->link_notes); |
|---|
| 597 | | $link->post_category = $link->link_category; |
|---|
| 598 | | |
|---|
| 599 | | return $link; |
|---|
| 600 | | } |
|---|
| 601 | | |
|---|
| 602 | | function get_default_link_to_edit() { |
|---|
| 603 | | if ( isset( $_GET['linkurl'] ) ) |
|---|
| 604 | | $link->link_url = clean_url( $_GET['linkurl']); |
|---|
| 605 | | else |
|---|
| 606 | | $link->link_url = ''; |
|---|
| 607 | | |
|---|
| 608 | | if ( isset( $_GET['name'] ) ) |
|---|
| 609 | | $link->link_name = attribute_escape( $_GET['name']); |
|---|
| 610 | | else |
|---|
| 611 | | $link->link_name = ''; |
|---|
| 612 | | |
|---|
| 613 | | $link->link_visible = 'Y'; |
|---|
| 614 | | |
|---|
| 615 | | return $link; |
|---|
| 616 | | } |
|---|
| 617 | | |
|---|
| 618 | | function add_link() { |
|---|
| 619 | | return edit_link(); |
|---|
| 620 | | } |
|---|
| 621 | | |
|---|
| 622 | | function edit_link( $link_id = '' ) { |
|---|
| 623 | | if (!current_user_can( 'manage_links' )) |
|---|
| 624 | | wp_die( __( 'Cheatin’ uh?' )); |
|---|
| 625 | | |
|---|
| 626 | | $_POST['link_url'] = wp_specialchars( $_POST['link_url'] ); |
|---|
| 627 | | $_POST['link_url'] = clean_url($_POST['link_url']); |
|---|
| 628 | | $_POST['link_name'] = wp_specialchars( $_POST['link_name'] ); |
|---|
| 629 | | $_POST['link_image'] = wp_specialchars( $_POST['link_image'] ); |
|---|
| 630 | | $_POST['link_rss'] = clean_url($_POST['link_rss']); |
|---|
| 631 | | $_POST['link_category'] = $_POST['post_category']; |
|---|
| 632 | | |
|---|
| 633 | | if ( !empty( $link_id ) ) { |
|---|
| 634 | | $_POST['link_id'] = $link_id; |
|---|
| 635 | | return wp_update_link( $_POST); |
|---|
| 636 | | } else { |
|---|
| 637 | | return wp_insert_link( $_POST); |
|---|
| 638 | | } |
|---|
| 639 | | } |
|---|
| 640 | | |
|---|
| 641 | | function url_shorten( $url ) { |
|---|
| 642 | | $short_url = str_replace( 'http://', '', stripslashes( $url )); |
|---|
| 643 | | $short_url = str_replace( 'www.', '', $short_url ); |
|---|
| 644 | | if ('/' == substr( $short_url, -1 )) |
|---|
| 645 | | $short_url = substr( $short_url, 0, -1 ); |
|---|
| 646 | | if ( strlen( $short_url ) > 35 ) |
|---|
| 647 | | $short_url = substr( $short_url, 0, 32 ).'...'; |
|---|
| 648 | | return $short_url; |
|---|
| 649 | | } |
|---|
| 650 | | |
|---|
| 651 | | function selected( $selected, $current) { |
|---|
| 652 | | if ( $selected == $current) |
|---|
| 653 | | echo ' selected="selected"'; |
|---|
| 654 | | } |
|---|
| 655 | | |
|---|
| 656 | | function checked( $checked, $current) { |
|---|
| 657 | | if ( $checked == $current) |
|---|
| 658 | | echo ' checked="checked"'; |
|---|
| 659 | | } |
|---|
| 660 | | |
|---|
| 661 | | function return_categories_list( $parent = 0 ) { |
|---|
| 662 | | global $wpdb; |
|---|
| 663 | | return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( link_count = 0 OR category_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY category_count DESC" ); |
|---|
| 664 | | } |
|---|
| 665 | | |
|---|
| 666 | | function sort_cats( $cat1, $cat2 ) { |
|---|
| 667 | | if ( $cat1['checked'] || $cat2['checked'] ) |
|---|
| 668 | | return ( $cat1['checked'] && !$cat2['checked'] ) ? -1 : 1; |
|---|
| 669 | | else |
|---|
| 670 | | return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] ); |
|---|
| 671 | | } |
|---|
| 672 | | |
|---|
| 673 | | function get_nested_categories( $default = 0, $parent = 0 ) { |
|---|
| 674 | | global $post_ID, $link_id, $mode, $wpdb; |
|---|
| 675 | | |
|---|
| 676 | | if ( $post_ID ) { |
|---|
| 677 | | $checked_categories = $wpdb->get_col( " |
|---|
| 678 | | SELECT category_id |
|---|
| 679 | | FROM $wpdb->categories, $wpdb->post2cat |
|---|
| 680 | | WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' |
|---|
| 681 | | " ); |
|---|
| 682 | | |
|---|
| 683 | | if ( count( $checked_categories ) == 0 ) { |
|---|
| 684 | | // No selected categories, strange |
|---|
| 685 | | $checked_categories[] = $default; |
|---|
| 686 | | } |
|---|
| 687 | | } else if ( $link_id ) { |
|---|
| 688 | | $checked_categories = $wpdb->get_col( " |
|---|
| 689 | | SELECT category_id |
|---|
| 690 | | FROM $wpdb->categories, $wpdb->link2cat |
|---|
| 691 | | WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id' |
|---|
| 692 | | " ); |
|---|
| 693 | | |
|---|
| 694 | | if ( count( $checked_categories ) == 0 ) { |
|---|
| 695 | | // No selected categories, strange |
|---|
| 696 | | $checked_categories[] = $default; |
|---|
| 697 | | } |
|---|
| 698 | | } else { |
|---|
| 699 | | $checked_categories[] = $default; |
|---|
| 700 | | } |
|---|
| 701 | | |
|---|
| 702 | | $cats = return_categories_list( $parent); |
|---|
| 703 | | $result = array (); |
|---|
| 704 | | |
|---|
| 705 | | if ( is_array( $cats ) ) { |
|---|
| 706 | | foreach ( $cats as $cat) { |
|---|
| 707 | | if ( $cat == 0 ) { // HACK, added 2006-05-13 |
|---|
| 708 | | $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = 0"); |
|---|
| 709 | | continue; |
|---|
| 710 | | } |
|---|
| 711 | | $result[$cat]['children'] = get_nested_categories( $default, $cat); |
|---|
| 712 | | $result[$cat]['cat_ID'] = $cat; |
|---|
| 713 | | $result[$cat]['checked'] = in_array( $cat, $checked_categories ); |
|---|
| 714 | | $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); |
|---|
| 715 | | } |
|---|
| 716 | | } |
|---|
| 717 | | |
|---|
| 718 | | $result = apply_filters('get_nested_categories', $result); |
|---|
| 719 | | usort( $result, 'sort_cats' ); |
|---|
| 720 | | |
|---|
| 721 | | return $result; |
|---|
| 722 | | } |
|---|
| 723 | | |
|---|
| 724 | | function write_nested_categories( $categories ) { |
|---|
| 725 | | foreach ( $categories as $category ) { |
|---|
| 726 | | echo '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( apply_filters('the_category', $category['cat_name'] )), "</label></li>"; |
|---|
| 727 | | |
|---|
| 728 | | if ( $category['children'] ) { |
|---|
| 729 | | echo "<ul>\n"; |
|---|
| 730 | | write_nested_categories( $category['children'] ); |
|---|
| 731 | | echo "</ul>\n"; |
|---|
| 732 | | } |
|---|
| 733 | | } |
|---|
| 734 | | } |
|---|
| 735 | | |
|---|
| 736 | | function dropdown_categories( $default = 0 ) { |
|---|
| 737 | | write_nested_categories( get_nested_categories( $default) ); |
|---|
| 738 | | } |
|---|
| 739 | | |
|---|
| 740 | | function return_link_categories_list( $parent = 0 ) { |
|---|
| 741 | | global $wpdb; |
|---|
| 742 | | return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( category_count = 0 OR link_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY link_count DESC" ); |
|---|
| 743 | | } |
|---|
| 744 | | |
|---|
| 745 | | function get_nested_link_categories( $default = 0, $parent = 0 ) { |
|---|
| 746 | | global $post_ID, $link_id, $mode, $wpdb; |
|---|
| 747 | | |
|---|
| 748 | | if ( $link_id ) { |
|---|
| 749 | | $checked_categories = $wpdb->get_col( " |
|---|
| 750 | | SELECT category_id |
|---|
| 751 | | FROM $wpdb->categories, $wpdb->link2cat |
|---|
| 752 | | WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id' |
|---|
| 753 | | " ); |
|---|
| 754 | | |
|---|
| 755 | | if ( count( $checked_categories ) == 0 ) { |
|---|
| 756 | | // No selected categories, strange |
|---|
| 757 | | $checked_categories[] = $default; |
|---|
| 758 | | } |
|---|
| 759 | | } else { |
|---|
| 760 | | $checked_categories[] = $default; |
|---|
| 761 | | } |
|---|
| 762 | | |
|---|
| 763 | | $cats = return_link_categories_list( $parent); |
|---|
| 764 | | $result = array (); |
|---|
| 765 | | |
|---|
| 766 | | if ( is_array( $cats ) ) { |
|---|
| 767 | | foreach ( $cats as $cat) { |
|---|
| 768 | | $result[$cat]['children'] = get_nested_link_categories( $default, $cat); |
|---|
| 769 | | $result[$cat]['cat_ID'] = $cat; |
|---|
| 770 | | $result[$cat]['checked'] = in_array( $cat, $checked_categories ); |
|---|
| 771 | | $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); |
|---|
| 772 | | } |
|---|
| 773 | | } |
|---|
| 774 | | |
|---|
| 775 | | usort( $result, 'sort_cats' ); |
|---|
| 776 | | |
|---|
| 777 | | return $result; |
|---|
| 778 | | } |
|---|
| 779 | | |
|---|
| 780 | | function dropdown_link_categories( $default = 0 ) { |
|---|
| 781 | | write_nested_categories( get_nested_link_categories( $default) ); |
|---|
| 782 | | } |
|---|
| 783 | | |
|---|
| 784 | | // Dandy new recursive multiple category stuff. |
|---|
| 785 | | function cat_rows( $parent = 0, $level = 0, $categories = 0 ) { |
|---|
| 786 | | global $wpdb; |
|---|
| 787 | | |
|---|
| 788 | | if (!$categories ) |
|---|
| 789 | | $categories = get_categories( 'hide_empty=0' ); |
|---|
| 790 | | |
|---|
| 791 | | $children = _get_category_hierarchy(); |
|---|
| 792 | | |
|---|
| 793 | | if ( $categories ) { |
|---|
| 794 | | ob_start(); |
|---|
| 795 | | foreach ( $categories as $category ) { |
|---|
| 796 | | if ( $category->cat_ID == 0 ) { // HACK, added 2006-05-13 |
|---|
| 797 | | $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = 0"); |
|---|
| 798 | | continue; |
|---|
| 799 | | } |
|---|
| 800 | | if ( $category->category_parent == $parent) { |
|---|
| 801 | | echo "\t" . _cat_row( $category, $level ); |
|---|
| 802 | | if ( isset($children[$category->cat_ID]) ) |
|---|
| 803 | | cat_rows( $category->cat_ID, $level +1, $categories ); |
|---|
| 804 | | } |
|---|
| 805 | | } |
|---|
| 806 | | $output = ob_get_contents(); |
|---|
| 807 | | ob_end_clean(); |
|---|
| 808 | | |
|---|
| 809 | | $output = apply_filters('cat_rows', $output); |
|---|
| 810 | | |
|---|
| 811 | | echo $output; |
|---|
| 812 | | } else { |
|---|
| 813 | | return false; |
|---|
| 814 | | } |
|---|
| 815 | | } |
|---|
| 816 | | |
|---|
| 817 | | function _cat_row( $category, $level, $name_override = false ) { |
|---|
| 818 | | global $class; |
|---|
| 819 | | |
|---|
| 820 | | $pad = str_repeat( '— ', $level ); |
|---|
| 821 | | if ( current_user_can( 'manage_categories' ) ) { |
|---|
| 822 | | $edit = "<a href='categories.php?action=edit&cat_ID=$category->cat_ID' class='edit'>".__( 'Edit' )."</a></td>"; |
|---|
| 823 | | $default_cat_id = (int) get_option( 'default_category' ); |
|---|
| 824 | | $default_link_cat_id = (int) get_option( 'default_link_category' ); |
|---|
| 825 | | |
|---|
| 826 | | if ( ($category->cat_ID != $default_cat_id ) && ($category->cat_ID != $default_link_cat_id ) ) |
|---|
| 827 | | $edit .= "<td><a href='" . wp_nonce_url( "categories.php?action=delete&cat_ID=$category->cat_ID", 'delete-category_' . $category->cat_ID ) . "' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '" . js_escape(sprintf( __("You are about to delete the category '%s'.\nAll posts that were only assigned to this category will be assigned to the '%s' category.\nAll links that were only assigned to this category will be assigned to the '%s' category.\n'OK' to delete, 'Cancel' to stop." ), $category->cat_name, get_catname( $default_cat_id ), get_catname( $default_link_cat_id ) )) . "' );\" class='delete'>".__( 'Delete' )."</a>"; |
|---|
| 828 | | else |
|---|
| 829 | | $edit .= "<td style='text-align:center'>".__( "Default" ); |
|---|
| 830 | | } else |
|---|
| 831 | | $edit = ''; |
|---|
| 832 | | |
|---|
| 833 | | $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; |
|---|
| 834 | | |
|---|
| 835 | | $category->category_count = number_format( $category->category_count ); |
|---|
| 836 | | $category->link_count = number_format( $category->link_count ); |
|---|
| 837 | | $posts_count = ( $category->category_count > 0 ) ? "<a href='edit.php?cat=$category->cat_ID'>$category->category_count</a>" : $category->category_count; |
|---|
| 838 | | return "<tr id='cat-$category->cat_ID'$class> |
|---|
| 839 | | <th scope='row' style='text-align: center'>$category->cat_ID</th> |
|---|
| 840 | | <td>" . ( $name_override ? $name_override : $pad . ' ' . $category->cat_name ) . "</td> |
|---|
| 841 | | <td>$category->category_description</td> |
|---|
| 842 | | <td align='center'>$posts_count</td> |
|---|
| 843 | | <td align='center'>$category->link_count</td> |
|---|
| 844 | | <td>$edit</td>\n\t</tr>\n"; |
|---|
| 845 | | } |
|---|
| 846 | | |
|---|
| 847 | | function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) { |
|---|
| 848 | | global $wpdb, $class, $post; |
|---|
| 849 | | |
|---|
| 850 | | if (!$pages ) |
|---|
| 851 | | $pages = get_pages( 'sort_column=menu_order' ); |
|---|
| 852 | | |
|---|
| 853 | | if (! $pages ) |
|---|
| 854 | | return false; |
|---|
| 855 | | |
|---|
| 856 | | foreach ( $pages as $post) { |
|---|
| 857 | | setup_postdata( $post); |
|---|
| 858 | | if ( $hierarchy && ($post->post_parent != $parent) ) |
|---|
| 859 | | continue; |
|---|
| 860 | | |
|---|
| 861 | | $post->post_title = wp_specialchars( $post->post_title ); |
|---|
| 862 | | $pad = str_repeat( '— ', $level ); |
|---|
| 863 | | $id = (int) $post->ID; |
|---|
| 864 | | $class = ('alternate' == $class ) ? '' : 'alternate'; |
|---|
| | 2 | // Deprecated. Use includes/admin.php. |
|---|
| | 3 | require_once(ABSPATH . 'wp-admin/includes/admin.php'); |
|---|