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?
- What is the difference between front-page.php and home.php? [duplicate]
- How important is it to enqueue a theme’s stylesheet?
- Can a theme be built in React?
- Strict Standards Error bootstrap navwalker
- Specify image dimensions
- Adding Action Hooks In Parent Theme For Easier Child Theme Customization
- register_sidebar ignores ‘id’ and ‘class’
- Add colors to existing color palette without replacing it
- How to deploy a new theme/theme options from staging to production site
- How do you enqueue script tags for ReactDOM in WordPress’ functions.php?
- How do I get gallery thumbnail URL and change the default thumbnail size?
- add_theme_support( ‘custom-header’ ) does not add option menu in dashboard
- WordPress Errors in generated by theme check plugin [closed]
- Upgrading a custom theme through the Dashboard
- how to make a child theme replace functions in different php files that are loaded throu require_once
- How WordPress converts URL to $query_string
- More than one meta field in a single meta box?
- how can I remove the sidebar from my wp homepage [closed]
- How to develop child theme for thesis
- “add_theme_support” for custom footer color?
- Why is the post type on the search result page random?
- Highlight “Show all” item in wp_list_categories
- What happens to child theme if I change to new version of parent theme?
- Internal error 500 accessing Theme > Customize
- Save Widget State Between Theme Swaps?
- Theme Development: Starter Content after hook
- Display theme layouts [closed]
- How do i place same widgets multiple time by default on theme activation?
- Getting php_network_getaddress error : No such host is known?
- HTML added to editor when deleting shortcodes in Chrome browser
- Combining CSS files into a single cached one
- How to set a page as homepage in stead of the newspages?
- WordPress Theme Validator?
- Get the amount of posts on a given page
- How do I use a color from theme options?
- Second menu has the first menu ID
- How to include a file only on dashboard widgets page?
- WP_Query $gallerypage->the_post() giving Undefined offset: 0
- How do I allow certain users to make a certain type of post?
- Change Image Sizes for Mobile Theme
- Dynamically Populating Image/Excerpt/LInks from Pages in WordPress
- Trouble in creating a custom template on twentyeleven theme
- language support in a custom urdu theme
- If I remove Category base from my URLs, how difficult will rollback be?
- Is there a list of default generated Gutenberg block CSS? Unable to align video blocks
- In wordpress customizer div still showing even if I hid it with javascript
- How do I change the color of individual page titles in WordPress?
- Programatically Created Menu not Editable in Dashboard
- How toprint informations in footer
- How to implement pagination in category.php template
- Embedding CodePen Calorie Script – jquery error
- Is it possible to echo a woocommerce prouct attribute discription?
- WordPress Menu item > Sub menu Class update
- Duplicate child theme incl. design changes
- Why .widget-area is outside of .site-content in Underscores starter theme?
- How can I use a different template file for the blog index’s paginated pages?
- How to customize the colors within a stylesheet using a WordPress setting
- On wordpress, how do i require specific dimensions from user uploads only
- how to create export / import theme options in wordpress without plugin
- WordPress Customization API overwrite LESS variable
- Create image with imagepng() (fails at header)
- Can you create a custom page with content in the center already defined?
- Dynamic meta description
- How to Remove Sidebar when get_sidebar() is not get called in page?
- RSS feed url showing page not found. How to solve it?
- Plugin or script to apply updated media settings to all featured images
- Header links also appearing in the footer
- Extending arrays in parent theme without completely overriding the files
- Retina ready for uploaded images which are cropped
- WordPress Subpages Fancybox Trouble
- Toolbox theme using printif statement – help needed understanding code block
- Search Results not displaying for multiple word search
- Allow users to edit home page from WordPress (home.php problems)
- WordPress does not know the parametrs i sent to admin post
- Display Page featured Image as well as Posts featured Image
- Custom Single Page Portfolio Theme [closed]
- How to make a multilingual wordpress site to be translated one-to-one without much effort and without using translate?
- Is there a way to have WordPress autodetect page templates in the page-templates directory and any sub-folders?
- Theme template file for a specific custom taxonomy
- How do I work with responsive images in WordPress? (img srcset/sizes)
- How can I use pre declared blocks in a php file?
- jQuery Snippet Not Working on WordPress Site [closed]