Changeset 10874
- Timestamp:
- 04/07/2021 01:56:31 AM (5 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory
- Files:
-
- 2 edited
-
class-wporg-themes-upload.php (modified) (1 diff)
-
theme-directory.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php
r10872 r10874 925 925 if ( ! empty( $this->theme_post ) ) { 926 926 $post_id = $this->theme_post->ID; 927 // see wporg_themes_approve_version() for where the post is updated. 927 928 928 929 // Otherwise create it for this new theme. -
sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php
r10807 r10874 456 456 function wporg_themes_approve_version( $post_id, $version, $old_status ) { 457 457 $post = get_post( $post_id ); 458 458 if ( ! $post ) { 459 // Should never happen. 460 return; 461 } 462 463 // Update wp-themes.com with this version. 459 464 wporg_themes_update_wpthemescom( $post->post_name, $version ); 460 465 461 // Update the post with this version's description and tags. 462 $theme_data = wporg_themes_get_header_data( sprintf( 'https://themes.svn.wordpress.org/%1$s/%2$s/style.css', $post->post_name, $version ) ); 463 wp_update_post( array( 464 'ID' => $post_id, 465 'post_content' => $theme_data['Description'], 466 'tags_input' => $theme_data['Tags'], 466 // Update the post with this version's name, parent theme, description, and tags. 467 $theme_data = wporg_themes_get_header_data( sprintf( 468 'https://themes.svn.wordpress.org/%1$s/%2$s/style.css', 469 $post->post_name, 470 $version 467 471 ) ); 472 473 if ( $theme_data ) { 474 475 // Find the parent theme for this version. 476 $theme_parent_post_id = $post->post_parent; 477 if ( ! $theme_data['Template'] ) { 478 // No parent theme. 479 $theme_parent_post_id = 0; 480 481 } else if ( 482 $post->post_parent && 483 $theme_data['Template'] === get_post( $post->post_parent )->post_name 484 ) { 485 // The post_parent field is currently set correctly, since that post_id matches the template header. 486 $theme_parent_post_id = $post->post_parent; 487 488 } else { 489 // Theme headers say it has a parent, but we don't have the correct one set, search for it. 490 $parent_theme = get_posts( array( 491 'name' => $theme_data['Template'], 492 'post_type' => 'repopackage', 493 'post_status' => 'any', 494 'posts_per_page' => 1, 495 'orderby' => 'ID', 496 'suppress_filters' => false, 497 'fields' => 'ids', 498 ) ); 499 500 if ( $parent_theme ) { 501 $theme_parent_post_id = $parent_theme[0]; 502 } else { 503 // We don't host the theme? Temporary problem? Assume it's right for now. 504 } 505 } 506 507 $theme_post_name = $post->post_title; 508 // Allow theme titles to change in case or accent: `ThemeName` => `Themename` + `ThemeName` => `ThemèName` 509 if ( $theme_post_name !== $theme_data['Name'] ) { 510 // Theme name has been updated. Make sure it still sanitizes to the same post. 511 $name_slugified = remove_accents( $theme_data['Name'] ); 512 $name_slugified = preg_replace( '/%[a-f0-9]{2}/i', '', $name_slugified ); 513 $name_slugified = sanitize_title_with_dashes( $name_slugified ); 514 515 if ( $name_slugified === $post->post_name ) { 516 // The new name still ends up at the same post_name slug value, let them have it. 517 $theme_post_name = $theme_data['Name']; 518 } 519 } 520 521 wp_update_post( array( 522 'ID' => $post_id, 523 'post_title' => $theme_post_name, 524 'post_content' => $theme_data['Description'], 525 'post_parent' => $theme_parent_post_id, 526 'tags_input' => $theme_data['Tags'], 527 ) ); 528 529 // Refresh the $post object for notifications. 530 $post = get_post( $post_id ); 531 } 468 532 469 533 // Update current version. Used to prioritize localized themes. … … 648 712 * 649 713 * @param string $theme_file Path to the file. 650 * @return array File headers.714 * @return array|false File headers, or false on failure. 651 715 */ 652 716 function wporg_themes_get_header_data( $theme_file ) { … … 674 738 675 739 $theme_data = file_get_contents( $theme_file, false, $context ); 740 if ( ! $theme_data ) { 741 // Failure reading, or empty style.css file. 742 return false; 743 } 676 744 677 745 $theme_data = str_replace( '\r', '\n', $theme_data ); 678 preg_match( '|^[ \t\/*#@]*Theme Name:(.*)$|mi', $theme_data, $theme_name ); 679 preg_match( '|^[ \t\/*#@]*Theme URI:(.*)$|mi', $theme_data, $theme_uri ); 680 preg_match( '|^[ \t\/*#@]*Description:(.*)$|mi', $theme_data, $description ); 681 682 if ( preg_match( '|^[ \t\/*#@]*Author URI:(.*)$|mi', $theme_data, $author_uri ) ) { 683 $author_uri = esc_url( trim( $author_uri[1] ) ); 684 } else { 685 $author_uri = ''; 686 } 687 688 if ( preg_match( '|^[ \t\/*#@]*Template:(.*)$|mi', $theme_data, $template ) ) { 689 $template = wp_kses( trim( $template[1] ), $themes_allowed_tags ); 690 } else { 691 $template = ''; 692 } 693 694 if ( preg_match( '|^[ \t\/*#@]*Version:(.*)$|mi', $theme_data, $version ) ) { 695 $version = wp_kses( trim( $version[1] ), $themes_allowed_tags ); 696 } else { 697 $version = ''; 698 } 699 700 if ( preg_match( '|^[ \t\/*#@]*Status:(.*)$|mi', $theme_data, $status ) ) { 701 $status = wp_kses( trim( $status[1] ), $themes_allowed_tags ); 702 } else { 703 $status = 'publish'; 704 } 705 706 if ( preg_match( '|^[ \t\/*#@]*Tags:(.*)$|mi', $theme_data, $tags ) ) { 707 $tags = array_map( 'trim', explode( ',', wp_kses( trim( $tags[1] ), array() ) ) ); 708 } else { 709 $tags = array(); 710 } 711 712 if ( preg_match( '|^[ \t\/*#@]*Author:(.*)$|mi', $theme_data, $author_name ) ) { 713 $author = wp_kses( trim( $author_name[1] ), $themes_allowed_tags ); 714 } else { 715 $author = 'Anonymous'; 716 } 717 718 $name = $theme = wp_kses( trim( $theme_name[1] ), $themes_allowed_tags ); 719 $theme_uri = esc_url( trim( $theme_uri[1] ) ); 720 $description = wp_kses( trim( $description[1] ), $themes_allowed_tags ); 746 747 // Set defaults. 748 $author_uri = ''; 749 $template = ''; 750 $version = ''; 751 $status = 'publish'; 752 $tags = array(); 753 $author = 'Anonymous'; 754 $name = ''; 755 $theme_uri = ''; 756 $description = ''; 757 758 if ( preg_match( '|^[ \t\/*#@]*Theme Name:(.*)$|mi', $theme_data, $m ) ) { 759 $name = wp_strip_all_tags( trim( $m[1] ) ); 760 } 761 762 if ( preg_match( '|^[ \t\/*#@]*Theme URI:(.*)$|mi', $theme_data, $m ) ) { 763 $theme_uri = esc_url( trim( $m[1] ) ); 764 } 765 766 if ( preg_match( '|^[ \t\/*#@]*Description:(.*)$|mi', $theme_data, $m ) ) { 767 $description = wp_kses( trim( $m[1] ), $themes_allowed_tags ); 768 } 769 770 if ( preg_match( '|^[ \t\/*#@]*Author:(.*)$|mi', $theme_data, $m ) ) { 771 $author = wp_kses( trim( $m[1] ), $themes_allowed_tags ); 772 } 773 774 if ( preg_match( '|^[ \t\/*#@]*Author URI:(.*)$|mi', $theme_data, $m ) ) { 775 $author_uri = esc_url( trim( $m[1] ) ); 776 } 777 778 if ( preg_match( '|^[ \t\/*#@]*Version:(.*)$|mi', $theme_data, $m ) ) { 779 $version = wp_strip_all_tags( trim( $m[1] ) ); 780 } 781 782 if ( preg_match( '|^[ \t\/*#@]*Template:(.*)$|mi', $theme_data, $m ) ) { 783 $template = wp_strip_all_tags( trim( $m[1] ) ); 784 } 785 786 if ( preg_match( '|^[ \t\/*#@]*Status:(.*)$|mi', $theme_data, $m ) ) { 787 $status = wp_strip_all_tags( trim( $meta_key[1] ) ); 788 } 789 790 if ( preg_match( '|^[ \t\/*#@]*Tags:(.*)$|mi', $theme_data, $m ) ) { 791 $tags = array_map( 'trim', explode( ',', wp_strip_all_tags( trim( $m[1] ) ) ) ); 792 } 721 793 722 794 return array( 723 795 'Name' => $name, 724 'Title' => $ theme,796 'Title' => $name, 725 797 'URI' => $theme_uri, 726 798 'Description' => $description,
Note: See TracChangeset
for help on using the changeset viewer.