Usually, you don’t need it. But … there is at least one edge case:
- If a theme file is a template part,
- and it is using global variables from the calling context (parent file),
- and register_globals is
on
, - and it is just using these variables without any security check …
… an attacker can call this file, set the missing variables with GET
or POST
and make the theme file print those out. And then there is a security problem.
So … the best option is not a context check like the one from your example, but good code: avoid global variables, check their content before you print it out.
Related Posts:
- Should `get_template_directory_uri()` be escaped?
- Is it good to rename theme folder downloaded from WordPress.org?
- How to sanitize select box values in post meta?
- When to use esc_url, esc_html, esc_attr, and friends?
- Worthwhile to restrict direct access of theme files?
- Where i should not use if (!defined(‘ABSPATH’)) { exit; }?
- Whats the safest way to output custom JavaScript and Css code entered by the admin in the Theme Settings?
- Is it safe to enqueue a font style without putting http or https?
- Using esc_url with a hard coded url
- What is the safe way to print tracking code / pixel code before tag or tag
- Underscore Based Theme File Permissions in Git
- correct tags for validating input types
- How to escape multiple attribute at once in WordPress?
- Contact Form Security
- Do I need to escape get_the_post_thumbnail function?
- Strict Folder and File Permissions for WordPress Themes Folder
- hide theme files for admin beneath root
- Should we escape the values of constants?
- WordPress Theme Preview Image
- What is a Theme textdomain?
- What are the advantages and disadvantages of Option Tree over the Customization API?
- Splitting WordPress theme CSS into multiple files, good or bad?
- Edit srcset and sizes attributes in Gutenberg image, cover and gallery – blocks
- do_shortcode() doesn’t do shortcodes ;)
- How do I check if a menu exists?
- How to concatenate inside the _e() function the right way?
- Why to check if function doesn’t exists in functions.php?
- Pages: frontpage.php, home.php, posts page etc
- How to add a WYSIWYG text editor to the Category Edit Screen
- Different wordpress 404 template for different post type [duplicate]
- How to choose which template to be used for multiple taxonomy query?
- How to programmatically bring back “excerpts” field in post editor in WP 3.1+
- How to set dimensions of the post thumbnails (featured images)
- Fatal error: Call to undefined function get_header()
- Add a theme via symlink
- Alterntives to BEM syntax that comply with WordPress coding standards? [closed]
- How to determine which registered sidebar area a custom widget is loaded into
- Integrating Html5Boilerplate’s Builder into a WP Theme
- Including wp-blog-header.php from functions.php remote call?
- Administration Pages Styling
- Theme settings keep getting reset/erased
- Custom button block doesn’t work
- How can i convert the figma design into wordpress [closed]
- A custom theme with support for multiple layouts
- WordPress Local Install Theme Folder Permission To Edit
- Display div only on the HOMEPAGE
- WordPress is adding margins and padding to my custom menu?
- What is the best way to organize template parts?
- Keep sticky posts out of query unless they have featured image
- wp_enqueue_script outside functions.php file?
- How can I make my options in an array and store theme in WP options one DB row?
- Differences between developing custom themes for wordpress.com and wordpress.org?
- Easy to develop on a URL that is changed for production?
- Following Web Performance Optimization techniques to output static and dynamic css
- How to control on which pages the Aldehyde theme’s main slider is shown?
- How to support letting users add their OWN logo to a custom theme?
- WordPress stylesheet isn’t being added
- How to detect and display a page only for IE?
- Does code in function.php differ from theme to theme
- How can I optimize this code? [closed]
- Issue on Getting Custom post type Thumbnail’s URL
- Forms won’t submit
- Change image size depending on page
- How do I provide for multiple crops of the same image in a theme?
- Why WordPress AJAX returns undefined however it works fine when I add static url instead of dynamic function?
- Twenty Seventeen Pages Loop
- What and where are the WordPress core-bundled scripts?
- How to add pages in wordpress using codes?
- How does the loop know which post to view?
- How to use multiple check-box values to work in a function and insert values in database
- How to make a function occurs for one time?
- How to know if I am on 1st page
- security concerns if using html data-* attribute for l10n?
- How to create a robust and logic class naming system in WordPress theme developing?
- How to enable admin to upload multiple images to support header carousel slider theme in WordPress?
- function ‘theme_settings_page’ not found
- I don’t know why categories are showing below post
- Is there a way to create sections under “Colors” panel in the Theme Customizer?
- Need help with adding custom wordpress menu and sub-menu
- get currently showed author ID in theme functions.php
- WordPress Custom font not found
- How do I control the header space in non-front pages in Twenty Seventeen?
- How to load mediaelement.js in theme template?
- Customizer API way function is_customize_preview() works only in main page?
- Advantages/Disadvantages Using Theme Editor Instead of Pages
- using theme check plugin to remove waring and errors from my theme
- paragraph format in WYSIWYG on a custom theme?
- unable to display the image meta value as background
- editor style css and page template with and without sidebar
- 3 x 3 grid of posts on the home page
- Suppress the_content filter in a nested loop
- The normal loop with different styles doesn’t work in search.php
- Pass custom css class to add_menu_page
- URL conflict with a ‘Single Page Layout’
- loading custom.js file after jquery is loaded
- How to determine if it is legal to remove credit link from theme?
- Display recent posts on front page
- How to create sub-menu in “Allure Real Estate Theme for Placester”?
- Configuring static page with add_rewrite_rule gives 404 after navigating to Permalinks admin panel
- How to Enable Hot Module Replacement with Webpack