Created
August 13, 2014 00:42
-
-
Save aendra-rininsland/17476da9249c92d25584 to your computer and use it in GitHub Desktop.
Install Bower dependencies on WordPress plugin activation
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 | |
register_activation_hook(__FILE__, 'activate_my_plugin'); | |
function activate_my_plugin() { | |
// Some basic securifying | |
if ( ! current_user_can( 'activate_plugins' ) ) | |
return; | |
$plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : ''; | |
check_admin_referer( "activate-plugin_{$plugin}" ); | |
// Is Node Bower installed on server? Use that if so. | |
if (`which bower`) { | |
exec('cd ' . dirname(__FILE__) . ' && bower install'); | |
} else { // Otherwise download and use BowerPHP | |
if (!file_exists(dirname(__FILE__) . '/bowerphp')) { | |
// include WP_Http to download bowerphp. | |
if( !class_exists( 'WP_Http' ) ) | |
include_once( ABSPATH . WPINC. '/class-http.php' ); | |
$request = new WP_Http; | |
$result = $request->request('http://bowerphp.org/bowerphp.phar'); | |
file_put_contents(dirname(__FILE__) . '/bowerphp', $result['body']); | |
exec('chmod ugo+x ' . dirname(__FILE__) . '/bowerphp'); | |
} | |
//BowerPHP install | |
exec('cd ' . dirname(__FILE__) . ' && ' . dirname(__FILE__) . '/bowerphp install'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment