PluginProbe
Theme Check / 20210921
Theme Check v20210921
trunk 20190208.1 20190801.1 20200612.1 20200731.1 20200922.1 20210617 20210921 20211203 20220929 20230412 20230417 20231220 20260821
theme-check / main.php

main.php in Theme Check 20210921, at main.php

232 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions for displaying theme information, test results, and the form
4 *
5 * @package Theme Check
6 */
7
8 /**
9 * Present theme information and test results.
10 *
11 * @param string $theme_slug theme slug of the theme to be tested.
12 */
13 function check_main( $theme_slug ) {
14 global $checkcount;
15
16 /**
17 * Get theme data. Return early if the theme is not found.
18 *
19 * @link https://developer.wordpress.org/reference/functions/wp_get_theme/
20 */
21 $theme = wp_get_theme( $theme_slug );
22 if ( ! $theme->exists() ) {
23 return;
24 }
25
26 // Run the checks.
27 $success = run_themechecks_against_theme( $theme, $theme_slug );
28
29 // Display theme info.
30 echo '<h2>' . esc_html__( 'Theme Info', 'theme-check' ) . ': </h2>';
31 echo '<div class="theme-info">';
32
33 $screenshot = $theme->get_screenshot( 'relative' );
34 if ( $screenshot ) {
35 $screenshot_file = $theme->get_stylesheet_directory() . '/' . $screenshot;
36 $image_size = getimagesize( $screenshot_file );
37 $image_filesize = filesize( $screenshot_file );
38
39 echo '<div style="float:right" class="theme-info"><img style="max-height:180px;" src="' . esc_url( $theme->get_screenshot() ) . '" />';
40 echo '<br /><div style="text-align:center">' . intval( $image_size[0] ) . 'x' . intval( $image_size[1] ) . ' ' . round( $image_filesize / 1024 ) . 'k</div></div>';
41 }
42
43 echo ( ! empty( $theme['Title'] ) ) ? '<p><label>' . esc_html__( 'Title', 'theme-check' ) . '</label><span class="info">' . esc_html( $theme['Title'] ) . '</span></p>' : '';
44 echo ( ! empty( $theme['Version'] ) ) ? '<p><label>' . esc_html__( 'Version', 'theme-check' ) . '</label><span class="info">' . esc_html( $theme['Version'] ) . '</span></p>' : '';
45 echo ( ! empty( $theme->get( 'Author' ) ) ) ? '<p><label>' . esc_html__( 'Author', 'theme-check' ) . '</label><span class="info">' . esc_html( $theme->get( 'Author' ) ) . '</span></p>' : '';
46 echo ( ! empty( $theme->get( 'AuthorURI' ) ) ) ? '<p><label>' . esc_html__( 'Author URI', 'theme-check' ) . '</label><span class="info"><a href="' . esc_url( $theme->get( 'AuthorURI' ) ) . '">' . esc_html( $theme->get( 'AuthorURI' ) ) . '</a></span></p>' : '';
47 echo ( ! empty( $theme->get( 'ThemeURI' ) ) ) ? '<p><label>' . esc_html__( 'Theme URI', 'theme-check' ) . '</label><span class="info"><a href="' . esc_url( $theme->get( 'ThemeURI' ) ) . '">' . esc_html( $theme->get( 'ThemeURI' ) ) . '</a></span></p>' : '';
48 echo ( ! empty( $theme->get( 'License' ) ) ) ? '<p><label>' . esc_html__( 'License', 'theme-check' ) . '</label><span class="info">' . esc_html( $theme->get( 'License' ) ) . '</span></p>' : '';
49 echo ( ! empty( $theme->get( 'License URI' ) ) ) ? '<p><label>' . esc_html__( 'License URI', 'theme-check' ) . '</label><span class="info">' . esc_html( $theme->get( 'License URI' ) ) . '</span></p>' : '';
50 echo ( ! empty( $theme['Tags'] ) ) ? '<p><label>' . esc_html__( 'Tags', 'theme-check' ) . '</label><span class="info">' . esc_html( implode( ', ', $theme['Tags'] ) ) . '</span></p>' : '';
51 echo ( ! empty( $theme['Description'] ) ) ? '<p><label>' . esc_html__( 'Description', 'theme-check' ) . '</label><span class="info">' . esc_html( $theme['Description'] ) . '</span></p>' : '';
52
53 if ( $theme->parent() ) {
54 echo '<p>';
55 printf(
56 /* translators: %s: Name of the parent theme. */
57 esc_html__( 'This is a child theme. The parent theme is: %s. These files have been included automatically!', 'theme-check' ),
58 '<strong>' . esc_html( $theme['Template'] ) . '</strong>'
59 );
60 echo '</p>';
61 }
62
63 if ( $theme['Template Version'] /* Not supported by WordPress */ ) {
64 $parent_theme = $theme->parent();
65 if ( $theme['Template Version'] > $parent_theme['Version'] ) {
66 echo '<p>';
67 printf(
68 esc_html__( 'This child theme requires at least version %1$s of theme %2$s to be installed. You only have %3$s please update the parent theme.', 'theme-check' ),
69 '<strong>' . esc_html( $theme['Template Version'] ) . '</strong>',
70 '<strong>' . esc_html( $parent_theme['Title'] ) . '</strong>',
71 '<strong>' . esc_html( $parent_theme['Version'] ) . '</strong>'
72 );
73 echo '</p>';
74 }
75
76 if ( empty( $theme['Template Version'] ) ) {
77 echo '<p>' . __( 'Child theme does not have the <strong>Template Version</strong> tag in style.css.', 'theme-check' ) . '</p>';
78 } elseif ( $theme['Template Version'] < $parent_theme['Version'] ) {
79 echo '<p>';
80 printf(
81 esc_html__( 'Child theme is only tested up to version %1$s of %2$s breakage may occur! %3$s installed version is %4$s', 'theme-check' ),
82 esc_html( $theme['Template Version'] ),
83 esc_html( $parent_theme['Title'] ),
84 esc_html( $parent_theme['Title'] ),
85 esc_html( $parent_theme['Version'] )
86 );
87 echo '</p>';
88 }
89 }
90 echo '</div><!-- .theme-info-->';
91 echo '<p>' . sprintf(
92 esc_html__( 'Running %1$s tests against %2$s.', 'theme-check' ),
93 '<strong>' . esc_html( $checkcount ) . '</strong>',
94 '<strong>' . esc_html( $theme['Title'] ) . '</strong>'
95 ) . '</p>';
96
97 $results = display_themechecks();
98
99 if ( ! $success ) {
100 echo '<h2>' . sprintf( __( 'One or more errors were found for %1$s.', 'theme-check' ), esc_html( $theme['Title'] ) ) . '</h2>';
101 } else {
102 echo '<h2>' . sprintf( __( '%1$s passed the tests', 'theme-check' ), esc_html( $theme['Title'] ) ) . '</h2>';
103 tc_success();
104 }
105
106 if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
107 echo '<div class="updated">';
108 echo '<span class="tc-fail">';
109 echo esc_html__( 'WARNING', 'theme-check' );
110 echo '</span> ';
111 echo '<strong>';
112 echo esc_html__( 'WP_DEBUG is not enabled!', 'theme-check' );
113 echo '</strong>';
114 printf(
115 /* translators: %1$s is an opening anchor tag. %2$s is the closing part of the tag. */
116 esc_html__( 'Please test your theme with %1$sdebug enabled%2$s before you upload!', 'theme-check' ),
117 '<a href="https://wordpress.org/support/article/editing-wp-config-php/">',
118 '</a>'
119 );
120 echo '</div>';
121 }
122
123 echo '<div class="tc-box">';
124 echo '<ul class="tc-result">';
125 echo wp_kses(
126 $results,
127 array(
128 'li' => array(),
129 'span' => array(
130 'class' => array(),
131 ),
132 'strong' => array(),
133 'code' => array(),
134 'pre' => array(),
135 'a' => array(
136 'href' => array(),
137 ),
138 )
139 );
140 echo '</ul></div>';
141 }
142
143 /**
144 * Present information about the plugin.
145 */
146 function tc_intro() {
147 ?>
148 <h2><?php esc_html_e( 'About', 'theme-check' ); ?></h2>
149 <p><?php esc_html_e( "The Theme Check plugin is an easy way to test your theme and make sure it's up to date with the latest theme review standards. With it, you can run all the same automated testing tools on your theme that WordPress.org uses for theme submissions.", 'theme-check' ); ?></p>
150 <h2><?php esc_html_e( 'Contact', 'theme-check' ); ?></h2>
151 <p>
152 <?php
153 printf(
154 esc_html__( 'Theme Check is maintained by %s.', 'theme-check' ),
155 '<a href="https://make.wordpress.org/themes/">' . esc_html__( 'The WordPress Themes Team', 'theme-check' ) . '</a>'
156 );
157 ?>
158 </p>
159 <p>
160 <?php
161 printf(
162 __( 'If you have found a bug or would like to make a suggestion or contribution, please leave a post on the <a href="%1$s">WordPress forums</a>, or talk about it with the Themes Team on <a href="%2$s">Make WordPress Themes</a> site.', 'theme-check' ),
163 'https://wordpress.org/support/plugin/theme-check/',
164 'https://make.wordpress.org/themes/'
165 );
166 ?>
167 </p>
168 <p>
169 <?php
170 printf(
171 __( 'The code for Theme Check can be contributed to on <a href="%s">GitHub</a>.', 'theme-check' ),
172 'https://github.com/WordPress/theme-check'
173 );
174 ?>
175 </p>
176 <?php
177 }
178
179 /**
180 * Present information about submitting themes.
181 */
182 function tc_success() {
183 ?>
184 <div class="tc-success"><p><?php esc_html_e( 'Now that your theme has passed the basic tests you need to check it properly using the test data before you upload it to the WordPress Themes Directory.', 'theme-check' ); ?></p>
185 <p>
186 <?php
187 printf(
188 /* translators: %1$s is an opening anchor tag. %2$s is the closing part of the tag. */
189 esc_html__( 'Make sure to review the guidelines at %1$sTheme Review%2$s before uploading a Theme.', 'theme-check' ),
190 '<a href="https://make.wordpress.org/themes/handbook/review/required/">',
191 '</a>'
192 );
193 ?>
194 </p>
195 <h3><?php esc_html_e( 'Useful Links', 'theme-check' ); ?></h3>
196 <ul>
197 <li><a href="https://developer.wordpress.org/themes/"><?php esc_html_e( 'Theme Handbook', 'theme-check' ); ?></a></li>
198 <li><a href="https://wordpress.org/support/forum/wp-advanced/"><?php esc_html_e( 'Developing with WordPress Forum', 'theme-check' ); ?></a></li>
199 <li><a href="https://github.com/WPTRT/theme-unit-test"><?php esc_html_e( 'Theme Unit Tests', 'theme-check' ); ?></a></li>
200 </ul></div>
201 <?php
202 }
203
204 /**
205 * Print the form for selecting the theme to test.
206 */
207 function tc_form() {
208 echo '<form action="themes.php?page=themecheck" method="post">';
209 echo '<select name="themename">';
210
211 $selected_theme = isset( $_POST['themename'] ) ? wp_unslash( $_POST['themename'] ) : get_stylesheet();
212 foreach ( wp_get_themes() as $theme ) {
213 printf(
214 '<option %s value="%s">%s</option>',
215 selected( $selected_theme, $theme['Stylesheet'], false ),
216 esc_attr( $theme['Stylesheet'] ),
217 esc_html( $theme['Name'] )
218 );
219 }
220
221 echo '</select>';
222
223 echo '<input class="button" type="submit" value="' . esc_attr__( 'Check it!', 'theme-check' ) . '" />';
224 if ( defined( 'TC_PRE' ) || defined( 'TC_POST' ) ) {
225 echo ' <input name="trac" type="checkbox" /> ' . esc_html__( 'Output in Trac format.', 'theme-check' );
226 }
227 echo '<input name="s_info" type="checkbox" /> ' . esc_html__( 'Suppress INFO.', 'theme-check' );
228 wp_nonce_field( 'themecheck-nonce' );
229 echo '</form>';
230 }
231
232