The error is self explanatory: PLUGIN_PATH
is not defined anywhere.
It is not one of WordPress’ default constants (which are listed here, and all start with WP_
). In the context of the code you’ve copied, it’s apparent that it was either supposed to be replaced with the path to your plugin (in which case using a constant in the example code was a bad idea), or it used to exist (the answer is 8 years old). This is mentioned in the comments on your own link.
To get the path to a plugin file (these days at least), you need to use plugin_dir_path()
:
if ( file_exists( plugin_dir_path( __FILE__ ) . 'Custom_File.php' ) ) {
return plugin_dir_path( __FILE__ ) . 'Custom_File.php';
}
Just be aware that plugin_dir_path( __FILE__ )
returns the path to the current file, so if the file containing this code is in a subfolder of your plugin you need to account for that.
Related Posts:
- How to add custom content template part for a custom post type on main query using a plugin
- Loading custom page template via plugin
- How to set a fall back template for a custom post type in a plugin?
- Getting template_include to work when allow_url_include is off?
- Main query not querying any posts in custom taxonomy template
- Custom Empty Results page for my Custom Post Type
- get_permalink() of page the enclosing page not posts
- How can I load Template file from wordpress plugin
- Show Templates in Custom Post Type Editor
- How to avoid hardcoded text in a custom page template?
- Custom post type template not loading from plugin
- How can I allow plugin users to define layouts for a custom post type
- Add block templates (html) via plugin for custom post type
- Hook to override title, image and content
- Custom template page with custom archives listing by user
- Insert Multiple Post with Same Publish Button
- Custom post type not using custom template
- Why is conditionally loading a custom plugin’s code only on a specific custom post type causing the site content to disappear?
- Custom Post Type template stored in plugin folder not showing in post attributes dropdown
- get_object_taxonomies() returns empty array for custom post type
- Set up Custom-Post-Type Author Archive
- WordPress theme custom capabilities not works
- custom post type not showing in menu
- Custom posts don’t work
- How to clone the “Projects” Custom Post type in Divi theme
- No posts found – Custom Post Type show_ui
- How to customize a permalink (URL) structure?
- Adding a custom post type taxonomy template in plugin
- Plugin: register custom post types, child ready and performance best practices
- How to add a custom taxonomy to show up in a custom post type menu?
- Query with no terms uses index.php template instead of archive.php
- Give a permalink to Custom Post Types without title
- Create template for taxonomy results limited by Custom Post Type
- Template for custom post with custom taxonomy
- WordPress Custom Post Type Children Template
- Custom post type content using custom fields without template
- WordPress post_where & posts_join not working only for custom post type
- Add custom ID to CPT posts only create not update
- Add custom post type as submenu [closed]
- 2 Templates 1 custom post type according url
- WordPress multiple custom post types capability conflict in a single menu
- Getting meta in editor plugin, and event triggering issue
- Orderby CPT custom fields not working
- Unable to get Custom Plugin Options data
- Update post meta not working in transition_post_status
- Use custom metabox to update automatically a post after a given date
- Custom taxonomy and custom post type – wrong permalinks and template
- Can I override a CPT template on a per post basis with Gutenberg block editor?
- Addition of custom option panel crashes Media Library & Admin Area
- Custom Permalink to remove category word , keeping posts permalink with date?
- Form action/link to render a plugin in WordPress front-end
- What is the best practice for displaying my plugin content in themes?
- Content vs Template on custom post
- Custom post type archive page blank
- Add Custom Post type menu to another menu in specific location
- Set a CPT slug as a base name for all the taxonomies
- How to use custom template files in deeper directory?
- How to use TinyMCE Editor for one of my custom post meta field?
- WordPress Doesn’t Generate Taxonomy Archive
- A case for Hierarchical Custom Posts
- How to Create a WordPress Plugin With Custom Post Type/Custom Field Features?
- Custom taxonomy returns 404
- Custom post listing page layout of custom post type
- How to Get WordPress custom post data in WooCommerce product meta panel? [closed]
- Filter widget outputs
- Adding Page Templates to post but it ignored it
- A custom post type in another post type
- Adding a metabox on a CPT’s submenu page
- Template for all categories of a custom post type?
- Deleting taxonomy terms and relationships on a custom post_type when a user is deleted
- Migrating a taxonomy’s tags to the native category
- Flush Rewrite Rules when new site is created on network
- Plugin fatal error
- custom comments form for custom post type
- WordPress custom taxonomy template not working
- Wrap meta boxes & data handling for specific post types in classes?
- How can I get this request to use the Custom Post Type page template instead?
- Problems wp_insert_post and save_posts filter
- How to specify a template for a path like http://example.com/something?
- Custom templates for a specific category
- Custom fields for custom post type
- Archive for a Taxonomy of a Custom Post type
- Suggestion on custom post type/ taxonomy relationship
- Custom post type pages return 404 page?
- WordPress 3.9 not using custom template
- Template files for Custom Post Type and Taxonomy
- Set templates for custom post types
- wordpress remove views from action links in a custom post
- How to Create Template File for Parent Page of Custom Post Type
- When should I create custom post types?
- Custom post type’s extra fields – how to handle?
- Custom post_type search pages
- Save Multiple Metabox values
- Send a conditional email notification when a custom field value changes in Post Type
- WordPress custom post type capabilities issue
- how to remove pages loading with the archive templates
- HowTo: Custom Post Type (Meta) to Custom Table
- how to set a WP Plugin’s url
- Getting 400 Bad Request on AJAX Call
- detect your custom post type in WordPress