The point of that code is to prevent any PHP inside the file from being executed if the file is accessed directly outside a WordPress context. ABSPATH is defined by WordPress, so if it’s missing when the file is accessed you can tell that it’s not running in a WordPress context.
So the only place you wouldn’t use it is in any file that you did need to access directly. There probably shouldn’t be any such files in a WordPress theme or plugin. The most common example might be a file for handling AJAX requests, but in WordPress you should be using admin-ajax.php or the REST API for that sort of thing.
Related Posts:
- Worthwhile to restrict direct access of theme files?
- 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?
- 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?
- If necessary, how should wp_get_attachment_image() and its parameters be escaped?
- How to define and link full path to css located at a random folder on header.php
- Get the blog page URL set in Options
- Do I actually need to link my theme’s style.css in the theme files
- Adding a div to wrap widget content after the widget title
- CSS classes for theme
- How to make native video player full width?
- get_template_directory_uri() in child theme pointing at child theme
- What are the ADVANTAGES of ORIGINAL wordpress template structure?
- How to remove “prev, next, shortlink” from wp_head()?
- How to add a 2nd “featured image” to a post?
- What is the difference between WP: template_directory vs TEMPLATEPATH
- How to edit bbPress template files – WordPress + BuddyPress + bbPress? [closed]
- Comment form not display properly?
- How to add menu support to a theme?
- Adding widgets programatically: how to avoid collisions?
- Why max-width:97.5% on content images?
- Use of undefined constant FS_CHMOD_DIR – assumed ‘FS_CHMOD_DIR’
- Setting up partial Right-to-Left admin interface
- Moving functionality from functions.php to classes?
- Registering Sidebars and Sidebar Widgets. Sidebar Widgets Not Displaying
- How do I get a parent theme modification from a child theme?
- Removing the default sidebar from admin panel
- Extend walker – navigation, adding data attribute to a tag
- How to display category specific post content on a page
- Is there any need to use both wp_reset_postdata and wp_reset_query together?
- how to pull wordpress post comments to a external page
- How to remove header images from all pages except the home page? skeleton theme
- Move my theme style.css into a folder
- Enqueued Stylesheets Effecting Admin Styles
- Why use while over if in single wordpress posts?
- wp_enqueue_script being ignored in custom theme
- First completely customized theme, where should I start?
- How to change the customizer´s sidebar width?
- Single Theme folder for Multiple WordPress
- Theme Options page not showing up in admin menu
- Gutenberg Reusable Block as part of WordPress Theme page
- Why is $GLOBALS[‘content_width’] needed if site is responsive?
- How i can get widgets areas working in customizer?
- Cutomize Colors utility: How to add more configurable colors to a theme
- Does WordPress count as a means to learn web development? [closed]
- current-menu-item class not working
- Prevent theme from activating [duplicate]
- Messing up with transient API – getting flushed on refresh
- Correctly using wp_head()
- Theme development question regarding layouts
- Cannot figure out how to overwrite files in child theme
- WordPress post arrangement using post_class
- Removing non native customizer settings from a child theme
- How to prepare the HTML for WordPress [closed]
- Using wp_tag_cloud(‘format=array’) to print tag names without links?
- Link to a .po file in a child theme
- Alias to theme folder for local development
- Create wordpress header with custom logo in between the menu splitting the menu into two equal parts [closed]
- Inheritance of parent theme plugin files in a child theme
- My Admin bar covers my sticky navbar [closed]
- Responsive embed for the video shortcode
- Access theme options in templates
- Display a list of certain categories by ID
- How to show post from category select
- Can’t work out why widget contents disappear from admin
- Implementing FancyBox
- Single Page Design, Storing in Theme Options
- How to append to menu items selectively
- How to create a multiple choice radio group for a single theme option
- Not able to select width of blocks inside of cover block
- Working with a WP Starter theme
- Edit footer via customizer
- gutenberg add classes to list items
- wordpress post category shows double`
- Should I change text-domain of TGM library inside theme?
- tag is being auto inserted
- “Bad element for masonry: undefined” why this error us occuring? [closed]
- Scroll to position on page for category pages only — woocommerce
- How remove render blocking css from wordpress when you build a theme?
- How to: JQuery multiple wordpress media uploader buttons in the same options page?
- Move default page templates to sub directory
- $this->get_field_id() not working in customizer
- Displaying details of a post in a sidebar
- How to upload/update theme from local – bitbucket – shared hosting?
- Migrated WordPress site renders Chinese
- How to modify default controls in WordPress theme customizer