Without more context from you, I can only assume and show you what I have done that works for me using PSR4 Autoloading.
Example:
Assuming that all my custom class directories and files is in ./inc folder
In your composer.json, add this
"autoload": {
"psr-4": {
"Inc\\": "./inc"
}
}
Inc is the vendor name of your application, use this for namspacing files inside your inc directory like namespace Inc/Api;
./inc is the directory(with all the class files or nested directory) you want to autoload.
Next, do this in your terminal to generate the vendor directory & autoload the files.
composer dump-autoload
Lastly, require the the autoloading by adding this to your plugin file eg. my-awesome-plugin.php
if (file_exists(dirname(__FILE__) . '/vendor/autoload.php')) {
require_once dirname(__FILE__) . '/vendor/autoload.php';
}
Related Posts:
- Plugin development and composer
- How can I search all plugins for composer’s vendor/autoload.php?
- When to use Exceptions vs Error Objects vs just plain false/null
- WordPress URL Rewrite not working
- Detect a focus on wp_editor
- Namespacing WordPress project according to FIG standards
- simple wordpress ajax plugin not working when not logged in
- Utilize WP-CLI from inside WordPress, not SSH
- Saving metabox repeatable fields
- Why is PHP Cookie via plugin only set when logged in as Admin and not regular users? and other questions
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- Loading page template into shortcode
- WordPress template_include filter not working properly
- Using wp_get_image_editor in a standalone script
- Continue execution after WP REST API response
- WordPress Ajax Custom Query – High CPU LOAD
- “The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working
- How to display a value from a radio button in the options menu in wordpress
- allow users to publish without admin approval
- action hook wp_head higher priority as all other plugins/hooks
- Do my defines need to be unique?
- What does $wpdb->get_row return?
- woocommerce subscriptions – get expiration date [closed]
- Delete a WordPress transient from a shortcode on Page/Post update
- Plugin CSS not enqueing
- Swapping wp_dropdown_categories function with wp_category_checklist
- Using WordPress gettext functions in a library outside plugin or theme scope
- How can I remove a function that has been added to wordpress with add_filter?
- PHP Fatal error: Uncaught mysqli_sql_exception: Table doesn’t exist in wordpress/wp-includes/wp-db.php
- How to use $_GET function WordPress backend
- How to call plugin function per site in a multisite?
- How wp-cron can run in background if PHP is single threaded?
- Options API get_option() and update_option() Not Correctly Updating or Returning
- wp_head function not outputting
- Extend PHP regex to cover “srcset” and “style” attributes
- How to make own crop image function for WordPress plugin
- How can I hide that I Use WordPress (with W3 Total Cache)
- Custom array from a query only write the last row of the query
- wp_insert_post: array only. wp_update_post: array|object (?)
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Building a REST API for your web app exposes primary keys of DB records?
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- Custom meta box values are not getting saved for my custom post type
- Can’t upload CSV file to plugin directory using custom upload form in admin panel
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Custom Registration username_exists / email_exists
- Action Hook Inside WordPress Plugin Shortcode
- Can I remove or edit an include() from a function with a filter?
- Call to undefined function error in plugin
- Submit form to db
- Get category id when SEO URL is turned on
- Add a custom WooCommerce settings tab with sections
- PHP using external anonymous function inside class
- Using ACF Relationship field to set post type to draft or published status
- Add Pre-Defined Value to Click Counter in WordPress
- How can i avoid duplicate same post in wp?
- Drop down question
- How do I disable cache for a certain page?
- code that I can run, or a plug in to show what sql tables something pulls information from
- Automatic email message after manual user approval
- How to check if plugin update process completed in wordpress?
- custom mailchimp form using HTTP API
- How to override theme’s public static function inside of a trait?
- pass datetime using wp_localize_script to frontend from settings page
- add custom metabox to media library custom widget
- using filter and hook inside class
- Display attached images of a page or post that are insetred using gallery
- overwrite wordpress gallery with custom gallery shortcode
- Enqueue sripts and styles only if function is called
- Add widget area from visual editor
- Register/enqueue scripts only on certain admin pages
- Looping through custom data in a custom table to display all items in a post
- Priority call methods – PHPMailer->addAddress(NULL)
- How to properly escape in ternary operators – Wp Coding Standards?
- not able to access $_POST on backend profile update
- Custom Plugin Develoment, Form Action
- WordPress Query Crashes Browser
- How to send logs to plugin owner for a plugin?
- How to Request a User to Register on Landing at a Site, Then Automatically Delete the Users Password on Logout?
- Plugin Modification Change Functionality For Logged User Only
- Force CSV download with template_redirect
- How to use foreach and if statement within array of arrays?
- INCOMING: Wall of code for form and $_POST, not updating custom field’s value
- add shortcode heading showing multiple time
- WP multisite network plugin fails to see classes loaded with spl autoload
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- What is this mark for “? function()” [closed]
- How to edit the default database of WordPress [closed]
- using a shortcode in a hyperlink
- How to automatically convert images to WebP on WordPress?
- Check user last login date
- Import js variables loaded via wp_localize_script() into js module without global scope connection
- Custom taxonomy with page post type – WordPress
- Query posts by custom taxonomy slug in WP REST API?
- oneOf JSON Schema validation not properly working for custom post meta value?
- Too few arguments at registering new templates in my plugin
- I want to lists posts in wordpress to nearest location entered by the user
- Displaying custom meta box value in a custom post page
- how to check elementor is widget is active or loaded
- Create a custom plugin with dynamic child pages listing database records