Skip to content

Instantly share code, notes, and snippets.

@kagg-design
Last active February 4, 2025 16:22
Show Gist options
  • Save kagg-design/11831b74ce03cf574ea36ce642b1d842 to your computer and use it in GitHub Desktop.
Save kagg-design/11831b74ce03cf574ea36ce642b1d842 to your computer and use it in GitHub Desktop.
Prevent updating plugins having a .git folder inside
<?php
/**
* Prevent updating plugins under git.
*
* @param mixed $value Value of site transient.
*
* @return object
*/
function prevent_updating_plugins_under_git( $value ) {
if ( ! is_object( $value ) ) {
return $value;
}
$response = $value->response ?? [];
foreach ( $response as $plugin_file => $plugin_data ) {
$slug = explode( '/', $plugin_file )[0];
if ( is_dir( WP_PLUGIN_DIR . '/' . $slug . '/.git' ) ) {
unset( $response[ $plugin_file ] );
$value->no_update[ $plugin_file ] = (object) [
'id' => $plugin_data->id,
'slug' => $slug,
'plugin' => $plugin_data->plugin,
'new_version' => $plugin_data->version,
'url' => '',
'package' => '',
'icons' => [],
'banners' => [],
'banners_rtl' => [],
'requires' => '',
];
}
}
return $value;
}
add_filter( 'site_transient_update_plugins', 'prevent_updating_plugins_under_git', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment