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?
- Prevent trash/delete action on specific post types
- Templates for Custom Post Types and Custom Taxonomies
- wordpress plugin error handling
- How to get term link that crosses different custom post types?
- register_taxonomy with multiple object type and update_count_callback
- Page is defaulting to archive page and not designated template
- How to quickly switch custom post type singular template?
- Where to put archive-{post-type}.php
- Using Custom Templates for Custom Post Types for the Genesis Theme Framework?
- Determine which template-{slug}.php is being loaded
- Custom page type – template under page attributes?
- Remove POST_TYPE from custom post type permalink
- Use a textarea for a custom post type
- Make custom post type display as a page
- Turn query string to sub page
- Remove header and footer but KEEP all css and js etc for a custom post template?
- WordPress Template Hierarchy
- How to rename image at uploading on specific plugin or post-type in WordPress
- Custom Post Type Navigation on Custom Field
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- Plugin translation not working apart from name and description
- How to show the archive / post type description on Single templates
- Set up Custom-Post-Type Author Archive
- Custom posts don’t work
- How to customize a permalink (URL) structure?
- Update post meta not working in transition_post_status
- Addition of custom option panel crashes Media Library & Admin Area
- Custom post type archive page blank
- WordPress Doesn’t Generate Taxonomy Archive
- 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
- WordPress custom taxonomy template not working
- Wrap meta boxes & data handling for specific post types in classes?
- WordPress custom post type capabilities issue
- HowTo: Custom Post Type (Meta) to Custom Table
- detect your custom post type in WordPress
- Option page’s form doesn’t work
- How to group navigation items in the admin panel
- Creating Sections for Post Types
- How can I trace inconsistency in loading a template?
- How to access the thank you page from the single post?
- Custom Meta Box returns no HTML
- Assigning alternate single-{cpt} template based on blog_id in multisite
- Custom permalink structure for remote content pages
- shopping cart plugin development
- CPT to installable Plugin
- how can i show a google map in custom post type
- How can I add in post’s the text “No content”
- Fill custom fields when saving custom post types
- How to customize `Edit-Post` Screen
- How add column from new table in Custom Post Listing (admin)
- Specifying a template for custom post type pages
- Custom post type set default template using block editor
- allowing custom user role to access custom post type in wordpress admin
- Is it possible to get the specific content on the search page?
- Get next and prev item from custom WP_Query and Custom Post Type
- A certain theme is forcing it’s singular post layout
- Error 404 change permalink term custom term taxonomy
- Post template not applying on theme (potentially rendering as Page template)
- Register custom_post_type from static function
- custom post type and user post count shortcode
- How to select meta key in custom database query
- Restrict Custom Post Type to One Item
- How to seperate posts by categories?
- Question on templates
- Assign for all post of a post type a specific single-post template
- Widget area for individual posts (custom post type)?
- Taxonomy template file not working with a taxonomy that contains a slash
- Which File Populating CPTs in Slug URL
- Front End users account with lots of user Roles (not Woocommerce)
- Custom post type that lets users create a set of posts?
- Foreach in get_post_types to apply a different filter per post type
- How to develop custom URL redirection
- Execute code only after user clicks ‘update’ button for CPT being edited
- Can the wp_posts table have the same slug (post_name) in multiple statuses (post_status)?
- Custom Homepage As Single Page or Custom Post Type?
- WordPress Custom taxonomy template
- Use one template for different custom post types with the same markup
- Not Able to Display Metabox Saved Checkbox and Selected option After Save/ Update
- Custom page template not being called
- Add category slug as class attribute in a link array
- How to display custom post types AND regular posts separately on a shared taxonomy archive?
- Custom post type pagination, single page issue
- Custom post types working in functions.php but not in plugin
- Custom template support for custom post type?
- Custom Post Type Template Based on Page Slug?
- How to separate posts by categories?
- Make term slugs of custom taxonomy available in WP REST API for custom post type?