Created
May 25, 2013 17:15
-
-
Save jasonrhodes/5649902 to your computer and use it in GitHub Desktop.
WordPress + Composer integration prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: WP Composer | |
| * Require: something @ >=4.0, another @ latest | |
| */ | |
| add_action('extra_plugin_headers', function ($headers) { | |
| $headers['Require'] = 'Require'; | |
| return $headers; | |
| }); | |
| function parse_require($string) { | |
| $libs = array_filter(preg_split('/\s*,\s*/', $string)); | |
| $libs = array_map(function ($lib) { | |
| return preg_split('/\s*@\s*/', $lib); | |
| }, $libs); | |
| return $libs; | |
| } | |
| add_action('load-plugins.php', function () { | |
| $plugins = get_plugins(); | |
| foreach ($plugins as $p => $data) { | |
| if (empty($data['Require'])) continue; | |
| echo "<p><strong>Composer requirements for: " . $data['Name'] . "</strong></p>"; | |
| echo "<pre>" . print_r(parse_require($data["Require"]), true) . "</pre>"; | |
| echo "<br><br><hr><br><br>"; | |
| } | |
| }); | |
| /** | |
| * TODO: | |
| * - On plugin activate/deactivate, modify composer.json file, autorun 'composer install' | |
| * - WP-CLI command? $ wp composer install (pull plugin data first) | |
| * - auto include vendor/autoload file? Not possible? | |
| */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment