Last active
October 25, 2021 20:27
-
-
Save afragen/9dafb92dc89fac663b9c2cc3a66d8eba to your computer and use it in GitHub Desktop.
Use the 'gu_fix_repo_slug' filter to change the default wp-content folder name.
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 | |
/** | |
* Usage of 'gu_fix_repo_slug' filter. | |
* | |
* @package wordpress-plugin | |
* @link https://github.com/afragen/git-updater/issues/971 | |
*/ | |
/** | |
* Plugin Name: Change Default Content Folder | |
* Plugin URI: https://gist.github.com/afragen/9dafb92dc89fac663b9c2cc3a66d8eba | |
* Description: Use the 'gu_fix_repo_slug' filter to change the default wp-content folder name. | |
* Version: 0.2 | |
* Author: Andy Fragen | |
* License: MIT | |
* Requires at least: 5.2 | |
* Requires PHP: 7.0 | |
* Gist Plugin URI: https://gist.github.com/afragen/9dafb92dc89fac663b9c2cc3a66d8eba | |
*/ | |
add_filter( | |
'gu_fix_repo_slug', | |
function ( $plugin_data ) { | |
foreach ( $plugin_data as $key => $value ) { | |
if ( is_array( $plugin_data[ $key ] ) ) { | |
foreach ( $plugin_data[ $key ] as $key2 => $val2 ) { | |
$plugin_data[ $key ][ $key2 ] = gu_update_string( $val2, 'wp-content', 'content' ); | |
} | |
} else { | |
$plugin_data[ $key ] = gu_update_string( $value, 'wp-content', 'content' ); | |
} | |
} | |
return $plugin_data; | |
}, | |
10, | |
1 | |
); | |
/** | |
* Update string. | |
* | |
* @param string $value Value of string. | |
* @param string $old Value of old string to element. | |
* @param string $new Value of new string element. | |
* | |
* @return string | |
*/ | |
function gu_update_string( $value, $old, $new ) { | |
if ( strpos( $value, $old ) ) { | |
$value = str_replace( $old, $new, $value ); | |
} | |
return $value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment