144 function get_page_templates( $post = null, $post_type = 'page' ) { |
144 function get_page_templates( $post = null, $post_type = 'page' ) { |
145 return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) ); |
145 return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) ); |
146 } |
146 } |
147 |
147 |
148 /** |
148 /** |
149 * Tidies a filename for url display by the theme editor. |
149 * Tidies a filename for url display by the theme file editor. |
150 * |
150 * |
151 * @since 2.9.0 |
151 * @since 2.9.0 |
152 * @access private |
152 * @access private |
153 * |
153 * |
154 * @param string $fullpath Full path to the theme file |
154 * @param string $fullpath Full path to the theme file |
269 |
269 |
270 return $html; |
270 return $html; |
271 } |
271 } |
272 |
272 |
273 /** |
273 /** |
274 * Retrieve list of WordPress theme features (aka theme tags). |
274 * Retrieves list of WordPress theme features (aka theme tags). |
275 * |
275 * |
276 * @since 3.1.0 |
276 * @since 3.1.0 |
277 * @since 3.2.0 Added 'Gray' color and 'Featured Image Header', 'Featured Images', |
277 * @since 3.2.0 Added 'Gray' color and 'Featured Image Header', 'Featured Images', |
278 * 'Full Width Template', and 'Post Formats' features. |
278 * 'Full Width Template', and 'Post Formats' features. |
279 * @since 3.5.0 Added 'Flexible Header' feature. |
279 * @since 3.5.0 Added 'Flexible Header' feature. |
519 $args = apply_filters( 'themes_api_args', $args, $action ); |
519 $args = apply_filters( 'themes_api_args', $args, $action ); |
520 |
520 |
521 /** |
521 /** |
522 * Filters whether to override the WordPress.org Themes API. |
522 * Filters whether to override the WordPress.org Themes API. |
523 * |
523 * |
524 * Passing a non-false value will effectively short-circuit the WordPress.org API request. |
524 * Returning a non-false value will effectively short-circuit the WordPress.org API request. |
525 * |
525 * |
526 * If `$action` is 'query_themes', 'theme_information', or 'feature_list', an object MUST |
526 * If `$action` is 'query_themes', 'theme_information', or 'feature_list', an object MUST |
527 * be passed. If `$action` is 'hot_tags', an array should be passed. |
527 * be passed. If `$action` is 'hot_tags', an array should be passed. |
528 * |
528 * |
529 * @since 2.8.0 |
529 * @since 2.8.0 |
600 if ( isset( $res->error ) ) { |
600 if ( isset( $res->error ) ) { |
601 $res = new WP_Error( 'themes_api_failed', $res->error ); |
601 $res = new WP_Error( 'themes_api_failed', $res->error ); |
602 } |
602 } |
603 } |
603 } |
604 |
604 |
605 // Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects. |
605 if ( ! is_wp_error( $res ) ) { |
606 if ( 'query_themes' === $action ) { |
606 // Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects. |
607 foreach ( $res->themes as $i => $theme ) { |
607 if ( 'query_themes' === $action ) { |
608 $res->themes[ $i ] = (object) $theme; |
608 foreach ( $res->themes as $i => $theme ) { |
|
609 $res->themes[ $i ] = (object) $theme; |
|
610 } |
609 } |
611 } |
610 } |
612 |
611 // Back-compat for info/1.2 API, downgrade the feature_list result back to an array. |
613 // Back-compat for info/1.2 API, downgrade the feature_list result back to an array. |
612 if ( 'feature_list' === $action ) { |
614 if ( 'feature_list' === $action ) { |
613 $res = (array) $res; |
615 $res = (array) $res; |
|
616 } |
614 } |
617 } |
615 } |
618 } |
616 |
619 |
617 /** |
620 /** |
618 * Filters the returned WordPress.org Themes API response. |
621 * Filters the returned WordPress.org Themes API response. |
619 * |
622 * |
620 * @since 2.8.0 |
623 * @since 2.8.0 |
621 * |
624 * |
622 * @param array|object|WP_Error $res WordPress.org Themes API response. |
625 * @param array|stdClass|WP_Error $res WordPress.org Themes API response. |
623 * @param string $action Requested action. Likely values are 'theme_information', |
626 * @param string $action Requested action. Likely values are 'theme_information', |
624 * 'feature_list', or 'query_themes'. |
627 * 'feature_list', or 'query_themes'. |
625 * @param object $args Arguments used to query for installer pages from the WordPress.org Themes API. |
628 * @param stdClass $args Arguments used to query for installer pages from the WordPress.org Themes API. |
626 */ |
629 */ |
627 return apply_filters( 'themes_api_result', $res, $action, $args ); |
630 return apply_filters( 'themes_api_result', $res, $action, $args ); |
628 } |
631 } |
629 |
632 |
630 /** |
633 /** |
631 * Prepare themes for JavaScript. |
634 * Prepares themes for JavaScript. |
632 * |
635 * |
633 * @since 3.8.0 |
636 * @since 3.8.0 |
634 * |
637 * |
635 * @param WP_Theme[] $themes Optional. Array of theme objects to prepare. |
638 * @param WP_Theme[] $themes Optional. Array of theme objects to prepare. |
636 * Defaults to all allowed themes. |
639 * Defaults to all allowed themes. |
648 * |
651 * |
649 * @since 4.2.0 |
652 * @since 4.2.0 |
650 * |
653 * |
651 * @param array $prepared_themes An associative array of theme data. Default empty array. |
654 * @param array $prepared_themes An associative array of theme data. Default empty array. |
652 * @param WP_Theme[]|null $themes An array of theme objects to prepare, if any. |
655 * @param WP_Theme[]|null $themes An array of theme objects to prepare, if any. |
653 * @param string $current_theme The current theme slug. |
656 * @param string $current_theme The active theme slug. |
654 */ |
657 */ |
655 $prepared_themes = (array) apply_filters( 'pre_prepare_themes_for_js', array(), $themes, $current_theme ); |
658 $prepared_themes = (array) apply_filters( 'pre_prepare_themes_for_js', array(), $themes, $current_theme ); |
656 |
659 |
657 if ( ! empty( $prepared_themes ) ) { |
660 if ( ! empty( $prepared_themes ) ) { |
658 return $prepared_themes; |
661 return $prepared_themes; |
659 } |
662 } |
660 |
663 |
661 // Make sure the current theme is listed first. |
664 // Make sure the active theme is listed first. |
662 $prepared_themes[ $current_theme ] = array(); |
665 $prepared_themes[ $current_theme ] = array(); |
663 |
666 |
664 if ( null === $themes ) { |
667 if ( null === $themes ) { |
665 $themes = wp_get_themes( array( 'allowed' => true ) ); |
668 $themes = wp_get_themes( array( 'allowed' => true ) ); |
666 if ( ! isset( $themes[ $current_theme ] ) ) { |
669 if ( ! isset( $themes[ $current_theme ] ) ) { |
696 $parents[ $slug ] = $parent->get_stylesheet(); |
699 $parents[ $slug ] = $parent->get_stylesheet(); |
697 $parent = $parent->display( 'Name' ); |
700 $parent = $parent->display( 'Name' ); |
698 } |
701 } |
699 |
702 |
700 $customize_action = null; |
703 $customize_action = null; |
701 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
704 |
|
705 $can_edit_theme_options = current_user_can( 'edit_theme_options' ); |
|
706 $can_customize = current_user_can( 'customize' ); |
|
707 $is_block_theme = $theme->is_block_theme(); |
|
708 |
|
709 if ( $is_block_theme && $can_edit_theme_options ) { |
|
710 $customize_action = esc_url( admin_url( 'site-editor.php' ) ); |
|
711 } elseif ( ! $is_block_theme && $can_customize && $can_edit_theme_options ) { |
702 $customize_action = esc_url( |
712 $customize_action = esc_url( |
703 add_query_arg( |
713 add_query_arg( |
704 array( |
714 array( |
705 'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ), |
715 'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ), |
706 ), |
716 ), |
770 'delete' => ( ! is_multisite() && current_user_can( 'delete_themes' ) ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null, |
780 'delete' => ( ! is_multisite() && current_user_can( 'delete_themes' ) ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null, |
771 'autoupdate' => wp_is_auto_update_enabled_for_type( 'theme' ) && ! is_multisite() && current_user_can( 'update_themes' ) |
781 'autoupdate' => wp_is_auto_update_enabled_for_type( 'theme' ) && ! is_multisite() && current_user_can( 'update_themes' ) |
772 ? wp_nonce_url( admin_url( 'themes.php?action=' . $auto_update_action . '&stylesheet=' . $encoded_slug ), 'updates' ) |
782 ? wp_nonce_url( admin_url( 'themes.php?action=' . $auto_update_action . '&stylesheet=' . $encoded_slug ), 'updates' ) |
773 : null, |
783 : null, |
774 ), |
784 ), |
|
785 'blockTheme' => $theme->is_block_theme(), |
775 ); |
786 ); |
776 } |
787 } |
777 |
788 |
778 // Remove 'delete' action if theme has an active child. |
789 // Remove 'delete' action if theme has an active child. |
779 if ( ! empty( $parents ) && array_key_exists( $current_theme, $parents ) ) { |
790 if ( ! empty( $parents ) && array_key_exists( $current_theme, $parents ) ) { |
810 <button type="button" class="close dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Close details dialog' ); ?></span></button> |
821 <button type="button" class="close dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Close details dialog' ); ?></span></button> |
811 </div> |
822 </div> |
812 <div class="theme-about wp-clearfix"> |
823 <div class="theme-about wp-clearfix"> |
813 <div class="theme-screenshots"> |
824 <div class="theme-screenshots"> |
814 <# if ( data.screenshot && data.screenshot[0] ) { #> |
825 <# if ( data.screenshot && data.screenshot[0] ) { #> |
815 <div class="screenshot"><img src="{{ data.screenshot[0] }}" alt="" /></div> |
826 <div class="screenshot"><img src="{{ data.screenshot[0] }}?ver={{ data.version }}" alt="" /></div> |
816 <# } else { #> |
827 <# } else { #> |
817 <div class="screenshot blank"></div> |
828 <div class="screenshot blank"></div> |
818 <# } #> |
829 <# } #> |
819 </div> |
830 </div> |
820 |
831 |
821 <div class="theme-info"> |
832 <div class="theme-info"> |
822 <# if ( data.active ) { #> |
833 <# if ( data.active ) { #> |
823 <span class="current-label"><?php _e( 'Current Theme' ); ?></span> |
834 <span class="current-label"><?php _e( 'Active Theme' ); ?></span> |
824 <# } #> |
835 <# } #> |
825 <h2 class="theme-name">{{{ data.name }}}<span class="theme-version"> |
836 <h2 class="theme-name">{{{ data.name }}}<span class="theme-version"> |
826 <?php |
837 <?php |
827 /* translators: %s: Theme version. */ |
838 /* translators: %s: Theme version. */ |
828 printf( __( 'Version: %s' ), '{{ data.version }}' ); |
839 printf( __( 'Version: %s' ), '{{ data.version }}' ); |
864 <p> |
875 <p> |
865 <# if ( ! data.updateResponse.compatibleWP && ! data.updateResponse.compatiblePHP ) { #> |
876 <# if ( ! data.updateResponse.compatibleWP && ! data.updateResponse.compatiblePHP ) { #> |
866 <?php |
877 <?php |
867 printf( |
878 printf( |
868 /* translators: %s: Theme name. */ |
879 /* translators: %s: Theme name. */ |
869 __( 'There is a new version of %s available, but it doesn’t work with your versions of WordPress and PHP.' ), |
880 __( 'There is a new version of %s available, but it does not work with your versions of WordPress and PHP.' ), |
870 '{{{ data.name }}}' |
881 '{{{ data.name }}}' |
871 ); |
882 ); |
872 if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { |
883 if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { |
873 printf( |
884 printf( |
874 /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ |
885 /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ |
894 ?> |
905 ?> |
895 <# } else if ( ! data.updateResponse.compatibleWP ) { #> |
906 <# } else if ( ! data.updateResponse.compatibleWP ) { #> |
896 <?php |
907 <?php |
897 printf( |
908 printf( |
898 /* translators: %s: Theme name. */ |
909 /* translators: %s: Theme name. */ |
899 __( 'There is a new version of %s available, but it doesn’t work with your version of WordPress.' ), |
910 __( 'There is a new version of %s available, but it does not work with your version of WordPress.' ), |
900 '{{{ data.name }}}' |
911 '{{{ data.name }}}' |
901 ); |
912 ); |
902 if ( current_user_can( 'update_core' ) ) { |
913 if ( current_user_can( 'update_core' ) ) { |
903 printf( |
914 printf( |
904 /* translators: %s: URL to WordPress Updates screen. */ |
915 /* translators: %s: URL to WordPress Updates screen. */ |
909 ?> |
920 ?> |
910 <# } else if ( ! data.updateResponse.compatiblePHP ) { #> |
921 <# } else if ( ! data.updateResponse.compatiblePHP ) { #> |
911 <?php |
922 <?php |
912 printf( |
923 printf( |
913 /* translators: %s: Theme name. */ |
924 /* translators: %s: Theme name. */ |
914 __( 'There is a new version of %s available, but it doesn’t work with your version of PHP.' ), |
925 __( 'There is a new version of %s available, but it does not work with your version of PHP.' ), |
915 '{{{ data.name }}}' |
926 '{{{ data.name }}}' |
916 ); |
927 ); |
917 if ( current_user_can( 'update_php' ) ) { |
928 if ( current_user_can( 'update_php' ) ) { |
918 printf( |
929 printf( |
919 /* translators: %s: URL to Update PHP page. */ |
930 /* translators: %s: URL to Update PHP page. */ |
943 |
954 |
944 <# if ( ! data.compatibleWP || ! data.compatiblePHP ) { #> |
955 <# if ( ! data.compatibleWP || ! data.compatiblePHP ) { #> |
945 <div class="notice notice-error notice-alt notice-large"><p> |
956 <div class="notice notice-error notice-alt notice-large"><p> |
946 <# if ( ! data.compatibleWP && ! data.compatiblePHP ) { #> |
957 <# if ( ! data.compatibleWP && ! data.compatiblePHP ) { #> |
947 <?php |
958 <?php |
948 _e( 'This theme doesn’t work with your versions of WordPress and PHP.' ); |
959 _e( 'This theme does not work with your versions of WordPress and PHP.' ); |
949 if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { |
960 if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { |
950 printf( |
961 printf( |
951 /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ |
962 /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ |
952 ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ), |
963 ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ), |
953 self_admin_url( 'update-core.php' ), |
964 self_admin_url( 'update-core.php' ), |
969 wp_update_php_annotation( '</p><p><em>', '</em>' ); |
980 wp_update_php_annotation( '</p><p><em>', '</em>' ); |
970 } |
981 } |
971 ?> |
982 ?> |
972 <# } else if ( ! data.compatibleWP ) { #> |
983 <# } else if ( ! data.compatibleWP ) { #> |
973 <?php |
984 <?php |
974 _e( 'This theme doesn’t work with your version of WordPress.' ); |
985 _e( 'This theme does not work with your version of WordPress.' ); |
975 if ( current_user_can( 'update_core' ) ) { |
986 if ( current_user_can( 'update_core' ) ) { |
976 printf( |
987 printf( |
977 /* translators: %s: URL to WordPress Updates screen. */ |
988 /* translators: %s: URL to WordPress Updates screen. */ |
978 ' ' . __( '<a href="%s">Please update WordPress</a>.' ), |
989 ' ' . __( '<a href="%s">Please update WordPress</a>.' ), |
979 self_admin_url( 'update-core.php' ) |
990 self_admin_url( 'update-core.php' ) |
980 ); |
991 ); |
981 } |
992 } |
982 ?> |
993 ?> |
983 <# } else if ( ! data.compatiblePHP ) { #> |
994 <# } else if ( ! data.compatiblePHP ) { #> |
984 <?php |
995 <?php |
985 _e( 'This theme doesn’t work with your version of PHP.' ); |
996 _e( 'This theme does not work with your version of PHP.' ); |
986 if ( current_user_can( 'update_php' ) ) { |
997 if ( current_user_can( 'update_php' ) ) { |
987 printf( |
998 printf( |
988 /* translators: %s: URL to Update PHP page. */ |
999 /* translators: %s: URL to Update PHP page. */ |
989 ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), |
1000 ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), |
990 esc_url( wp_get_update_php_url() ) |
1001 esc_url( wp_get_update_php_url() ) |
992 wp_update_php_annotation( '</p><p><em>', '</em>' ); |
1003 wp_update_php_annotation( '</p><p><em>', '</em>' ); |
993 } |
1004 } |
994 ?> |
1005 ?> |
995 <# } #> |
1006 <# } #> |
996 </p></div> |
1007 </p></div> |
|
1008 <# } else if ( ! data.active && data.blockTheme ) { #> |
|
1009 <div class="notice notice-error notice-alt notice-large"><p> |
|
1010 <?php |
|
1011 _e( 'This theme doesn\'t support Customizer.' ); |
|
1012 ?> |
|
1013 <# if ( data.actions.activate ) { #> |
|
1014 <?php |
|
1015 printf( |
|
1016 /* translators: %s: URL to the themes page (also it activates the theme). */ |
|
1017 ' ' . __( 'However, you can still <a href="%s">activate this theme</a>, and use the Site Editor to customize it.' ), |
|
1018 '{{{ data.actions.activate }}}' |
|
1019 ); |
|
1020 ?> |
|
1021 <# } #> |
|
1022 </p></div> |
997 <# } #> |
1023 <# } #> |
998 |
1024 |
999 <p class="theme-description">{{{ data.description }}}</p> |
1025 <p class="theme-description">{{{ data.description }}}</p> |
1000 |
1026 |
1001 <# if ( data.tags ) { #> |
1027 <# if ( data.tags ) { #> |
1012 <# if ( data.actions && data.actions['delete'] ) { #> |
1038 <# if ( data.actions && data.actions['delete'] ) { #> |
1013 <a href="{{{ data.actions['delete'] }}}" data-slug="{{ data.id }}" class="button button-secondary delete-theme"><?php _e( 'Delete' ); ?></a> |
1039 <a href="{{{ data.actions['delete'] }}}" data-slug="{{ data.id }}" class="button button-secondary delete-theme"><?php _e( 'Delete' ); ?></a> |
1014 <# } #> |
1040 <# } #> |
1015 <?php } ?> |
1041 <?php } ?> |
1016 |
1042 |
1017 <# if ( data.compatibleWP && data.compatiblePHP ) { #> |
1043 <# if ( data.blockTheme ) { #> |
1018 <button type="button" class="button button-primary preview-theme" data-slug="{{ data.id }}"><?php _e( 'Live Preview' ); ?></button> |
1044 <?php |
|
1045 /* translators: %s: Theme name. */ |
|
1046 $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' ); |
|
1047 ?> |
|
1048 <# if ( data.compatibleWP && data.compatiblePHP && data.actions.activate ) { #> |
|
1049 <a href="{{{ data.actions.activate }}}" class="button button-primary activate" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a> |
|
1050 <# } #> |
1019 <# } else { #> |
1051 <# } else { #> |
1020 <button class="button button-primary disabled"><?php _e( 'Live Preview' ); ?></button> |
1052 <# if ( data.compatibleWP && data.compatiblePHP ) { #> |
|
1053 <button type="button" class="button button-primary preview-theme" data-slug="{{ data.id }}"><?php _e( 'Live Preview' ); ?></button> |
|
1054 <# } else { #> |
|
1055 <button class="button button-primary disabled"><?php _e( 'Live Preview' ); ?></button> |
|
1056 <# } #> |
1021 <# } #> |
1057 <# } #> |
1022 <# } else { #> |
1058 <# } else { #> |
1023 <# if ( data.compatibleWP && data.compatiblePHP ) { #> |
1059 <# if ( data.compatibleWP && data.compatiblePHP ) { #> |
1024 <button type="button" class="button theme-install" data-slug="{{ data.id }}"><?php _e( 'Install' ); ?></button> |
1060 <button type="button" class="button theme-install" data-slug="{{ data.id }}"><?php _e( 'Install' ); ?></button> |
1025 <button type="button" class="button button-primary theme-install preview" data-slug="{{ data.id }}"><?php _e( 'Install & Preview' ); ?></button> |
1061 <button type="button" class="button button-primary theme-install preview" data-slug="{{ data.id }}"><?php _e( 'Install & Preview' ); ?></button> |