Skip to content

Instantly share code, notes, and snippets.

@lightningspirit
Last active July 7, 2022 11:17
Show Gist options
  • Save lightningspirit/73df703f0db1fef14bd30d64ea1e8631 to your computer and use it in GitHub Desktop.
Save lightningspirit/73df703f0db1fef14bd30d64ea1e8631 to your computer and use it in GitHub Desktop.
WordPress Autoload Composer Vendor MU-Plugin

WordPress composer autoload

Do you use WordPress along with composer? This is the right plugin for you. Just add it to mu-plugins and the root autoloader is activated.

Usage

  1. Download or copy the autoload.php file
  2. Place it under wp-content/mu-plugins
  3. Done

If a composer autoloader exists, it loads in every WordPress request.

<?php
/**
* Plugin Name: Composer Autoload
* Description: Includes the autogenerated composer autoload.php file
* Plugin URI: https://gist.github.com/lightningspirit/73df703f0db1fef14bd30d64ea1e8631
* Author: Move Your Digital, Inc.
* Author URI: https://moveyourdigital.com
* Version: 0.2.2
*
* @package Autoload
*/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**#@+
* Include compose autoload, if exists
*/
if( file_exists(ABSPATH . '/vendor/autoload.php') ) :
include_once ABSPATH . '/vendor/autoload.php';
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment