| @@ -22,8 +22,30 @@ | ||
| 22 | 22 | defined( 'OPENSTATION_STANDALONE' ) || exit; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | + * The ids "Attached media" lists and counts: the post's attachments | |
| 27 | + * plus its featured image, each once. | |
| 28 | + * | |
| 29 | + * @param \WP_Post $post Post. | |
| 30 | + * @return int[] | |
| 31 | + */ | |
| 32 | +function media_ids( \WP_Post $post ) { | |
| 33 | + $ids = get_children( | |
| 34 | + array( | |
| 35 | + 'post_parent' => $post->ID, | |
| 36 | + 'post_type' => 'attachment', | |
| 37 | + 'fields' => 'ids', | |
| 38 | + ) | |
| 39 | + ); | |
| 40 | + $ids = array_map( 'intval', $ids ); | |
| 41 | + if ( has_post_thumbnail( $post ) ) { | |
| 42 | + $ids[] = (int) get_post_thumbnail_id( $post ); | |
| 43 | + } | |
| 44 | + return array_unique( $ids ); | |
| 45 | +} | |
| 46 | + | |
| 47 | +/** | |
| 26 | 48 | * The detail FOLDER a post navigates into: the rendered article plus |
| 27 | 49 | * one folder tile per related surface — Author, Contributors, |
| 28 | 50 | * Comments, Categories, Tags, Attached media, Revisions — with live |
| 29 | 51 | * counts. WP Explorer's detail view, as data. |
| @@ -45,17 +67,9 @@ | ||
| 45 | 67 | $categories = get_the_terms( $post, 'category' ); |
| 46 | 68 | $categories = is_array( $categories ) ? $categories : array(); |
| 47 | 69 | $tags = get_the_terms( $post, 'post_tag' ); |
| 48 | 70 | $tags = is_array( $tags ) ? $tags : array(); |
| 49 | - $media_count = count( | |
| 50 | - get_children( | |
| 51 | - array( | |
| 52 | - 'post_parent' => $id, | |
| 53 | - 'post_type' => 'attachment', | |
| 54 | - 'fields' => 'ids', | |
| 55 | - ) | |
| 56 | - ) | |
| 57 | - ) + ( has_post_thumbnail( $post ) ? 1 : 0 ); | |
| 71 | + $media_count = count( media_ids( $post ) ); | |
| 58 | 72 | $comments = (int) get_comments_number( $post ); |
| 59 | 73 | $revisions = wp_revisions_enabled( $post ) ? count( wp_get_post_revisions( $id, array( 'fields' => 'ids' ) ) ) : 0; |
| 60 | 74 | |
| 61 | 75 | $folders = array(); |
| @@ -110,9 +124,9 @@ | ||
| 110 | 124 | ); |
| 111 | 125 | |
| 112 | 126 | return array( |
| 113 | 127 | 'id' => $id, |
| 114 | - 'title' => '' !== $post->post_title ? (string) $post->post_title : __( '(no title)', 'desktop-mode' ), | |
| 128 | + 'title' => '' !== $post->post_title ? openstation_plain_text_title( $post->post_title ) : __( '(no title)', 'desktop-mode' ), | |
| 115 | 129 | 'status' => (string) $post->post_status, |
| 116 | 130 | // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Applying Core's own content pipeline, not declaring a hook. |
| 117 | 131 | 'content' => (string) apply_filters( 'the_content', (string) $post->post_content ), |
| 118 | 132 | 'folders' => $folders, |
| @@ -140,9 +154,9 @@ | ||
| 140 | 154 | $user_row = static function ( $user_id, $name = '', $avatar = '' ) { |
| 141 | 155 | $user = get_userdata( (int) $user_id ); |
| 142 | 156 | return array( |
| 143 | 157 | 'id' => (int) $user_id, |
| 144 | - 'title' => '' !== $name ? $name : ( $user ? (string) $user->display_name : sprintf( '#%d', $user_id ) ), | |
| 158 | + 'title' => openstation_plain_text_title( '' !== $name ? $name : ( $user ? (string) $user->display_name : sprintf( '#%d', $user_id ) ) ), | |
| 145 | 159 | 'subtitle' => $user ? (string) $user->user_email : '', |
| 146 | 160 | 'thumb' => '' !== $avatar ? $avatar : (string) get_avatar_url( (int) $user_id, array( 'size' => 96 ) ), |
| 147 | 161 | 'editUrl' => current_user_can( 'edit_user', (int) $user_id ) |
| 148 | 162 | ? admin_url( 'user-edit.php?user_id=' . (int) $user_id ) |
| @@ -172,10 +186,10 @@ | ||
| 172 | 186 | ) |
| 173 | 187 | ) as $comment ) { |
| 174 | 188 | $rows[] = array( |
| 175 | 189 | 'id' => (int) $comment->comment_ID, |
| 176 | - 'title' => (string) $comment->comment_author, | |
| 177 | - 'subtitle' => wp_trim_words( wp_strip_all_tags( (string) $comment->comment_content ), 12 ), | |
| 190 | + 'title' => openstation_plain_text_title( $comment->comment_author ), | |
| 191 | + 'subtitle' => openstation_plain_text_title( wp_trim_words( openstation_strip_all_tags( (string) $comment->comment_content ), 12 ) ), | |
| 178 | 192 | 'icon' => 'dashicons-admin-comments', |
| 179 | 193 | 'editUrl' => current_user_can( 'edit_comment', (int) $comment->comment_ID ) |
| 180 | 194 | ? admin_url( 'comment.php?action=editcomment&c=' . (int) $comment->comment_ID ) |
| 181 | 195 | : '', |
| @@ -189,9 +203,9 @@ | ||
| 189 | 203 | $terms = get_the_terms( $post, $taxonomy ); |
| 190 | 204 | foreach ( is_array( $terms ) ? $terms : array() as $term ) { |
| 191 | 205 | $rows[] = array( |
| 192 | 206 | 'id' => (int) $term->term_id, |
| 193 | - 'title' => (string) $term->name, | |
| 207 | + 'title' => openstation_plain_text_title( $term->name ), | |
| 194 | 208 | 'subtitle' => sprintf( |
| 195 | 209 | /* translators: %s: entry count. */ |
| 196 | 210 | _n( '%s entry', '%s entries', (int) $term->count, 'desktop-mode' ), |
| 197 | 211 | number_format_i18n( (int) $term->count ) |
| @@ -204,20 +218,9 @@ | ||
| 204 | 218 | } |
| 205 | 219 | break; |
| 206 | 220 | case 'media': |
| 207 | 221 | $label = __( 'Attached media', 'desktop-mode' ); |
| 208 | - $ids = get_children( | |
| 209 | - array( | |
| 210 | - 'post_parent' => $id, | |
| 211 | - 'post_type' => 'attachment', | |
| 212 | - 'fields' => 'ids', | |
| 213 | - ) | |
| 214 | - ); | |
| 215 | - $ids = array_map( 'intval', array_keys( $ids ) ); | |
| 216 | - if ( has_post_thumbnail( $post ) ) { | |
| 217 | - $ids[] = (int) get_post_thumbnail_id( $post ); | |
| 218 | - } | |
| 219 | - foreach ( array_unique( $ids ) as $media_id ) { | |
| 222 | + foreach ( media_ids( $post ) as $media_id ) { | |
| 220 | 223 | $media = get_post( $media_id ); |
| 221 | 224 | if ( ! $media ) { |
| 222 | 225 | continue; |
| 223 | 226 | } |
| @@ -222,9 +225,9 @@ | ||
| 222 | 225 | continue; |
| 223 | 226 | } |
| 224 | 227 | $rows[] = array( |
| 225 | 228 | 'id' => $media_id, |
| 226 | - 'title' => '' !== $media->post_title ? (string) $media->post_title : sprintf( '#%d', $media_id ), | |
| 229 | + 'title' => '' !== $media->post_title ? openstation_plain_text_title( $media->post_title ) : sprintf( '#%d', $media_id ), | |
| 227 | 230 | 'subtitle' => (string) $media->post_mime_type, |
| 228 | 231 | 'thumb' => (string) wp_get_attachment_image_url( $media_id, 'medium' ), |
| 229 | 232 | 'icon' => 'dashicons-format-image', |
| 230 | 233 | 'editUrl' => current_user_can( 'edit_post', $media_id ) |
| @@ -237,10 +240,10 @@ | ||
| 237 | 240 | $label = __( 'Revisions', 'desktop-mode' ); |
| 238 | 241 | foreach ( wp_get_post_revisions( $id ) as $revision ) { |
| 239 | 242 | $rows[] = array( |
| 240 | 243 | 'id' => (int) $revision->ID, |
| 241 | - 'title' => (string) wp_post_revision_title_expanded( $revision, false ), | |
| 242 | - 'subtitle' => (string) get_the_author_meta( 'display_name', (int) $revision->post_author ), | |
| 244 | + 'title' => openstation_plain_text_title( wp_post_revision_title_expanded( $revision, false ) ), // Core leads with an avatar <img>; the client prints a title as text. | |
| 245 | + 'subtitle' => openstation_plain_text_title( get_the_author_meta( 'display_name', (int) $revision->post_author ) ), | |
| 243 | 246 | 'icon' => 'dashicons-backup', |
| 244 | 247 | 'editUrl' => current_user_can( 'edit_post', $id ) |
| 245 | 248 | ? admin_url( 'revision.php?revision=' . (int) $revision->ID ) |
| 246 | 249 | : '', |
| @@ -350,10 +353,10 @@ | ||
| 350 | 353 | return null; |
| 351 | 354 | } |
| 352 | 355 | return array( |
| 353 | 356 | 'kind' => 'revision', |
| 354 | - 'title' => (string) wp_post_revision_title_expanded( $revision, false ), | |
| 355 | - 'author' => (string) get_the_author_meta( 'display_name', (int) $revision->post_author ), | |
| 357 | + 'title' => openstation_plain_text_title( wp_post_revision_title_expanded( $revision, false ) ), // Same as the row title: no avatar <img>. | |
| 358 | + 'author' => openstation_plain_text_title( get_the_author_meta( 'display_name', (int) $revision->post_author ) ), | |
| 356 | 359 | 'date' => (string) get_the_date( '', $revision ) . ' ' . get_the_time( '', $revision ), |
| 357 | 360 | 'content' => wp_kses_post( (string) apply_filters( 'the_content', (string) $revision->post_content ) ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Core's own content pipeline. |
| 358 | 361 | ); |
| 359 | 362 | } |
| @@ -379,9 +382,9 @@ | ||
| 379 | 382 | ) |
| 380 | 383 | ) as $user ) { |
| 381 | 384 | $authors[] = array( |
| 382 | 385 | 'id' => (int) $user->ID, |
| 383 | - 'name' => (string) $user->display_name, | |
| 386 | + 'name' => openstation_plain_text_title( $user->display_name ), | |
| 384 | 387 | ); |
| 385 | 388 | } |
| 386 | 389 | $categories = array(); |
| 387 | 390 | foreach ( get_terms( |
| @@ -393,9 +396,9 @@ | ||
| 393 | 396 | ) as $term ) { |
| 394 | 397 | if ( $term instanceof \WP_Term ) { |
| 395 | 398 | $categories[] = array( |
| 396 | 399 | 'id' => (int) $term->term_id, |
| 397 | - 'name' => (string) $term->name, | |
| 400 | + 'name' => openstation_plain_text_title( $term->name ), | |
| 398 | 401 | 'parent' => (int) $term->parent, |
| 399 | 402 | ); |
| 400 | 403 | } |
| 401 | 404 | } |
| @@ -409,9 +412,9 @@ | ||
| 409 | 412 | ) as $term ) { |
| 410 | 413 | if ( $term instanceof \WP_Term ) { |
| 411 | 414 | $tags[] = array( |
| 412 | 415 | 'id' => (int) $term->term_id, |
| 413 | - 'name' => (string) $term->name, | |
| 416 | + 'name' => openstation_plain_text_title( $term->name ), | |
| 414 | 417 | ); |
| 415 | 418 | } |
| 416 | 419 | } |
| 417 | 420 | return array( |