Skip to content

Commit

Permalink
Update composer.json
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp authored Jan 2, 2021
1 parent 12125fc commit 6c1b514
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
"name": "Josh Cunningham",
"email": "[email protected]"
}
]
}
],
"autoload": {
"files": [
"wp-rest-api-auth0.php"
]
}
}

10 comments on commit 6c1b514

@szepeviktor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshcanhelp Composer's autoloader is/should be required from wp-config.php where MU plugins are unable to start.
Please see https://github.com/joshcanhelp/wp-rest-api-auth0/blob/main/wp-rest-api-auth0-loader.php#L5

@szepeviktor
Copy link
Contributor

@szepeviktor szepeviktor commented on 6c1b514 Jan 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

composer require johnpbloch/wordpress composer/installers joshcanhelp/wp-rest-api-auth0
cp wp-content/mu-plugins/wp-rest-api-auth0/wp-rest-api-auth0-loader.php wp-content/mu-plugins/
# 🎉 

@joshcanhelp
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szepeviktor - Without this, the wp-rest-api-auth0.php is not being loaded when using Composer. How would it know about that file?

@szepeviktor
Copy link
Contributor

@szepeviktor szepeviktor commented on 6c1b514 Jan 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually wp-rest-api-auth0-loader.php should committed to the WordPress installation/project repo.
And there are mu plugin loaders out there.

With Composer/autoload/files it loads too early, e.g. there is no add_action function.

@joshcanhelp
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I follow here. On my local setup using Composer (and I could be doing it wrong but it looks ok to me and works), I have a wp-content/mu-plugins/load.php file that simply requires vendor/autoload.php. Then I add a composer.json right next to that to require joshcanhelp/wp-rest-api-auth0. Without that autoload property, the autoloader would not get built including the right file. How would it know to include it?

Using the loader file, we're running composer install in the package itself and then including the 2 necessary files manually.

Am I missing something here? Not sure of what use case this would break.

Appreciate your input here, BTW 👍

@szepeviktor
Copy link
Contributor

@szepeviktor szepeviktor commented on 6c1b514 Jan 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a wp-content/mu-plugins/load.php file that simply requires vendor/autoload.php

I see. That is late enough.

If you move require vendor/autoload.php to wp-config.php the problem will arise.
https://github.com/szepeviktor/debian-server-tools/blob/master/webserver/wp-install/wp-config.php#L54-L56

@joshcanhelp
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems too early to start loading plugins. Whenever you load this code, you'll need to have add_action available, otherwise it won't work. I'm guessing if this was not throwing an error before then the autoload was not including the right file, which this commit fixes.

@szepeviktor
Copy link
Contributor

@szepeviktor szepeviktor commented on 6c1b514 Jan 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the thing is, Composer autoloader is first thing in all applications, e.g. https://github.com/laravel/laravel/blob/8.x/public/index.php#L34

There are two ways: the WordPressy and the OOP. I choose the later. But it is not a must for you!

@joshcanhelp
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, in most cases. But, whether you include or autoload the main file here, you need to have add_action defined. I don't really see a way around that.

@szepeviktor
Copy link
Contributor

@szepeviktor szepeviktor commented on 6c1b514 Jan 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a way around that

... is the loader file wp-rest-api-auth0-loader.php but it needs manual action and 99.999% of WordPress users are unable to take manual actions.

Please sign in to comment.