| 23 | /** |
| 24 | * Given that the parameter; "shown_file_editor_warning" is present in the URL and set to true, we'll |
| 25 | * update the currently logged in users meta to include a flag that they have seen the "Edit Themes" |
| 26 | * message. |
| 27 | * |
| 28 | * This support to show a message to first time visitors of the treacherous "Editor" screen is |
| 29 | * introduced in ticket: 31779. |
| 30 | * |
| 31 | * See additional scattered comments. |
| 32 | */ |
| 33 | $meta_key = 'shown_file_editor_warning'; |
| 34 | $meta = get_user_meta( get_current_user_id(), $meta_key, true ); |
| 35 | |
| 36 | if ( isset( $_GET['shown_file_editor_warning'] ) && true === (bool) $_GET['shown_file_editor_warning'] ) { |
| 37 | add_user_meta( get_current_user_id(), $meta_key, true, true ); |
| 38 | wp_redirect( admin_url( get_current_screen()->id . '.php') ); |
| 39 | exit; |
| 40 | } |
| 41 | |
167 | | <div class="fileedit-sub"> |
168 | | <div class="alignleft"> |
169 | | <h2><?php echo $theme->display( 'Name' ); if ( $description ) echo ': ' . $description; ?></h2> |
170 | | </div> |
171 | | <div class="alignright"> |
172 | | <form action="theme-editor.php" method="post"> |
173 | | <strong><label for="theme"><?php _e('Select theme to edit:'); ?> </label></strong> |
174 | | <select name="theme" id="theme"> |
175 | | <?php |
176 | | foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) { |
177 | | if ( $a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code() ) |
178 | | continue; |
179 | | |
180 | | $selected = $a_stylesheet == $stylesheet ? ' selected="selected"' : ''; |
181 | | echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display('Name') . '</option>'; |
182 | | } |
183 | | ?> |
184 | | </select> |
185 | | <?php submit_button( __( 'Select' ), '', 'Submit', false ); ?> |
186 | | </form> |
187 | | </div> |
188 | | <br class="clear" /> |
189 | | </div> |
190 | | <?php |
191 | | if ( $theme->errors() ) |
192 | | echo '<div class="error"><p><strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message() . '</p></div>'; |
193 | | ?> |
194 | | <div id="templateside"> |
199 | | foreach ( $allowed_files as $filename => $absolute_filename ) : |
200 | | $file_type = substr( $filename, strrpos( $filename, '.' ) ); |
| 188 | /** |
| 189 | * If this is the first time the user has visited the "Editor" page of the WordPress admin |
| 190 | * we'll show them a message. Additional detail can be found in ticket: 31779. |
| 191 | */ |
| 192 | if ( empty( $meta ) ) : |
| 193 | $learn_more_url = ''; |
| 194 | $shown_message_url = admin_url( add_query_arg( |
| 195 | array( 'shown_file_editor_warning' => true ), |
| 196 | get_current_screen()->id . '.php' |
| 197 | ) ); |
| 198 | ?> |
| 199 | <p><?php esc_attr_e( 'Warning: Editing files directly in the WordPress dashboard is risky and your changes may be lost when themes are updated.' ); ?></p> |
| 200 | <p><a href="<?php echo esc_url( $learn_more_url ); ?>"><?php esc_attr_e( 'Learn more about safely editing your theme.' ); ?></a></p> |
| 201 | <p><a href="<?php echo esc_url( $shown_message_url ); ?>" class="button-primary"><?php esc_attr_e( 'I got this.' ); ?></a></p> |
| 202 | <p><?php esc_attr_e( 'This message will not appear again.' ); ?></p> |
202 | | if ( $file_type !== $previous_file_type ) { |
203 | | if ( '' !== $previous_file_type ) { |
204 | | echo "\t</ul>\n"; |
| 204 | <?php |
| 205 | /** |
| 206 | * Any subsequent request to the "Editor" page will show the below code. Additional |
| 207 | * detail can be found in ticket: 31779. |
| 208 | */ |
| 209 | else : ?> |
| 210 | <div class="fileedit-sub"> |
| 211 | <div class="alignleft"> |
| 212 | <h2><?php echo $theme->display( 'Name' ); if ( $description ) echo ': ' . $description; ?></h2> |
| 213 | </div> |
| 214 | <div class="alignright"> |
| 215 | <form action="theme-editor.php" method="post"> |
| 216 | <strong><label for="theme"><?php _e('Select theme to edit:'); ?> </label></strong> |
| 217 | <select name="theme" id="theme"> |
| 218 | <?php |
| 219 | foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) { |
| 220 | if ( $a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code() ) |
| 221 | continue; |
| 222 | |
| 223 | $selected = $a_stylesheet == $stylesheet ? ' selected="selected"' : ''; |
| 224 | echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display('Name') . '</option>'; |
| 225 | } |
| 226 | ?> |
| 227 | </select> |
| 228 | <?php submit_button( __( 'Select' ), '', 'Submit', false ); ?> |
| 229 | </form> |
| 230 | </div> |
| 231 | <br class="clear" /> |
| 232 | </div> |
| 233 | <?php |
| 234 | if ( $theme->errors() ) |
| 235 | echo '<div class="error"><p><strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message() . '</p></div>'; |
| 236 | ?> |
| 237 | <div id="templateside"> |
| 238 | <?php |
| 239 | if ( $allowed_files ) : |
| 240 | $previous_file_type = ''; |
| 241 | |
| 242 | foreach ( $allowed_files as $filename => $absolute_filename ) : |
| 243 | $file_type = substr( $filename, strrpos( $filename, '.' ) ); |
| 244 | |
| 245 | if ( $file_type !== $previous_file_type ) { |
| 246 | if ( '' !== $previous_file_type ) { |
| 247 | echo "\t</ul>\n"; |
| 248 | } |
| 249 | |
| 250 | switch ( $file_type ) { |
| 251 | case '.php': |
| 252 | if ( $has_templates || $theme->parent() ) : |
| 253 | echo "\t<h2>" . __( 'Templates' ) . "</h2>\n"; |
| 254 | if ( $theme->parent() ) { |
| 255 | echo '<p class="howto">' . sprintf( __( 'This child theme inherits templates from a parent theme, %s.' ), |
| 256 | sprintf( '<a href="%s">%s</a>', |
| 257 | self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ), |
| 258 | $theme->parent()->display( 'Name' ) |
| 259 | ) |
| 260 | ) . "</p>\n"; |
| 261 | } |
| 262 | endif; |
| 263 | break; |
| 264 | case '.css': |
| 265 | echo "\t<h2>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h2>\n"; |
| 266 | break; |
| 267 | default: |
| 268 | /* translators: %s: file extension */ |
| 269 | echo "\t<h2>" . sprintf( __( '%s files' ), $file_type ) . "</h2>\n"; |
| 270 | break; |
| 271 | } |
| 272 | |
| 273 | echo "\t<ul>\n"; |
207 | | switch ( $file_type ) { |
208 | | case '.php': |
209 | | if ( $has_templates || $theme->parent() ) : |
210 | | echo "\t<h2>" . __( 'Templates' ) . "</h2>\n"; |
211 | | if ( $theme->parent() ) { |
212 | | echo '<p class="howto">' . sprintf( __( 'This child theme inherits templates from a parent theme, %s.' ), |
213 | | sprintf( '<a href="%s">%s</a>', |
214 | | self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ), |
215 | | $theme->parent()->display( 'Name' ) |
216 | | ) |
217 | | ) . "</p>\n"; |
218 | | } |
219 | | endif; |
220 | | break; |
221 | | case '.css': |
222 | | echo "\t<h2>" . _x( 'Styles', 'Theme stylesheets in theme editor' ) . "</h2>\n"; |
223 | | break; |
224 | | default: |
225 | | /* translators: %s: file extension */ |
226 | | echo "\t<h2>" . sprintf( __( '%s files' ), $file_type ) . "</h2>\n"; |
227 | | break; |
| 276 | $file_description = get_file_description( $filename ); |
| 277 | if ( $filename !== basename( $absolute_filename ) || $file_description !== $filename ) { |
| 278 | $file_description .= '<br /><span class="nonessential">(' . $filename . ')</span>'; |
242 | | $previous_file_type = $file_type; |
243 | | ?> |
244 | | <li><a href="theme-editor.php?file=<?php echo urlencode( $filename ) ?>&theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></a></li> |
245 | | <?php |
246 | | endforeach; |
247 | | ?> |
248 | | </ul> |
249 | | <?php endif; ?> |
250 | | </div> |
251 | | <?php if ( $error ) : |
252 | | echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>'; |
253 | | else : ?> |
254 | | <form name="template" id="template" action="theme-editor.php" method="post"> |
255 | | <?php wp_nonce_field( 'edit-theme_' . $file . $stylesheet ); ?> |
256 | | <div><textarea cols="70" rows="30" name="newcontent" id="newcontent" aria-describedby="newcontent-description"><?php echo $content; ?></textarea> |
257 | | <input type="hidden" name="action" value="update" /> |
258 | | <input type="hidden" name="file" value="<?php echo esc_attr( $relative_file ); ?>" /> |
259 | | <input type="hidden" name="theme" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" /> |
260 | | <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" /> |
261 | | </div> |
262 | | <?php if ( ! empty( $functions ) ) : ?> |
263 | | <div id="documentation" class="hide-if-no-js"> |
264 | | <label for="docs-list"><?php _e('Documentation:') ?></label> |
265 | | <?php echo $docs_select; ?> |
266 | | <input type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_user_locale() ) ?>&version=<?php echo urlencode( get_bloginfo( 'version' ) ) ?>&redirect=true'); }" /> |
267 | | </div> |
| 285 | $previous_file_type = $file_type; |
| 286 | ?> |
| 287 | <li><a href="theme-editor.php?file=<?php echo urlencode( $filename ) ?>&theme=<?php echo urlencode( $stylesheet ) ?>"><?php echo $file_description; ?></a></li> |
| 288 | <?php |
| 289 | endforeach; |
| 290 | ?> |
| 291 | </ul> |
269 | | |
270 | | <div> |
271 | | <?php if ( is_child_theme() && $theme->get_stylesheet() == get_template() ) : ?> |
272 | | <p><?php if ( is_writeable( $file ) ) { ?><strong><?php _e( 'Caution:' ); ?></strong><?php } ?> |
273 | | <?php _e( 'This is a file in your current parent theme.' ); ?></p> |
274 | | <?php endif; ?> |
275 | | <?php |
276 | | if ( is_writeable( $file ) ) : |
277 | | submit_button( __( 'Update File' ), 'primary', 'submit', true ); |
| 293 | </div> |
| 294 | <?php if ( $error ) : |
| 295 | echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>'; |
279 | | <p><em><?php _e('You need to make this file writable before you can save your changes. See <a href="https://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.'); ?></em></p> |
280 | | <?php endif; ?> |
281 | | </div> |
282 | | </form> |
283 | | <?php |
284 | | endif; // $error |
285 | | ?> |
286 | | <br class="clear" /> |
| 297 | <form name="template" id="template" action="theme-editor.php" method="post"> |
| 298 | <?php wp_nonce_field( 'edit-theme_' . $file . $stylesheet ); ?> |
| 299 | <div><textarea cols="70" rows="30" name="newcontent" id="newcontent" aria-describedby="newcontent-description"><?php echo $content; ?></textarea> |
| 300 | <input type="hidden" name="action" value="update" /> |
| 301 | <input type="hidden" name="file" value="<?php echo esc_attr( $relative_file ); ?>" /> |
| 302 | <input type="hidden" name="theme" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" /> |
| 303 | <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" /> |
| 304 | </div> |
| 305 | <?php if ( ! empty( $functions ) ) : ?> |
| 306 | <div id="documentation" class="hide-if-no-js"> |
| 307 | <label for="docs-list"><?php _e('Documentation:') ?></label> |
| 308 | <?php echo $docs_select; ?> |
| 309 | <input type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_user_locale() ) ?>&version=<?php echo urlencode( get_bloginfo( 'version' ) ) ?>&redirect=true'); }" /> |
| 310 | </div> |
| 311 | <?php endif; ?> |
| 312 | |
| 313 | <div> |
| 314 | <?php if ( is_child_theme() && $theme->get_stylesheet() == get_template() ) : ?> |
| 315 | <p><?php if ( is_writeable( $file ) ) { ?><strong><?php _e( 'Caution:' ); ?></strong><?php } ?> |
| 316 | <?php _e( 'This is a file in your current parent theme.' ); ?></p> |
| 317 | <?php endif; ?> |
| 318 | <?php |
| 319 | if ( is_writeable( $file ) ) : |
| 320 | submit_button( __( 'Update File' ), 'primary', 'submit', true ); |
| 321 | else : ?> |
| 322 | <p><em><?php _e('You need to make this file writable before you can save your changes. See <a href="https://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.'); ?></em></p> |
| 323 | <?php endif; ?> |
| 324 | </div> |
| 325 | </form> |
| 326 | <?php |
| 327 | endif; // $error |
| 328 | ?> |
| 329 | <?php endif; // End Warning Users check. ?> |
| 330 | <br class="clear" /> |