Skip to content

Instantly share code, notes, and snippets.

@boonebgorges
Created May 1, 2012 20:56
Show Gist options
  • Save boonebgorges/2571318 to your computer and use it in GitHub Desktop.
Save boonebgorges/2571318 to your computer and use it in GitHub Desktop.
Update Woo Framework for all WooThemes on an installation
<?php
/**
* Updates Woo Framework in all WooThemes on a WP installation
*
* To use:
*
* - Get the latest copy of the framework
* - Unzip to /wp-content/framework/
* - Visit wp-admin?cac_update_woo=1 as super admin
*
* No guarantees. Test properly and read before using! There is no undo!!
*
* @author Boone B Gorges
* @license GPLv2
*/
function cac_update_woo_framework() {
if ( empty( $_GET['cac_update_woo'] ) ) {
return;
}
if ( !is_super_admin() ) {
return;
}
// Get a list of files to be copied
$tdir = opendir( WP_CONTENT_DIR . '/framework/' );
if ( !$tdir ) {
return;
}
$ffiles = array();
while ( ( $file = readdir( $tdir ) ) !== false ) {
if ( 0 === strpos( $file, '.' ) ) {
continue;
}
$ffiles[] = WP_CONTENT_DIR . '/framework/' . $file;
}
$themes = get_themes();
foreach( $themes as $theme_name => $theme ) {
if ( false === strpos( $theme['Author'], 'WooThemes' ) ) {
continue;
}
foreach( $ffiles as $ff ) {
// can't use basename for dirs?
$ffbase = array_pop( explode( WP_CONTENT_DIR . '/framework/', $ff ) );
rcopy( $ff, $theme['Stylesheet Dir'] . '/functions/' . $ffbase );
}
}
rrmdir( WP_CONTENT_DIR . '/framework/' );
}
add_action( 'admin_init', 'cac_update_woo_framework' );
/**
* http://www.php.net/manual/en/function.copy.php#104020
*/
// copies files and non-empty directories
function rcopy($src, $dst) {
if (file_exists($dst)) rrmdir($dst);
if (is_dir($src)) {
mkdir($dst);
$files = scandir($src);
foreach ($files as $file)
if ($file != "." && $file != "..") rcopy("$src/$file", "$dst/$file");
}
else if (file_exists($src)) copy($src, $dst);
}
function rrmdir($dir) {
if (is_dir($dir)) {
$files = scandir($dir);
foreach ($files as $file)
if ($file != "." && $file != "..") rrmdir("$dir/$file");
rmdir($dir);
}
else if (file_exists($dir)) unlink($dir);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment