I am using the following filter to run a function that generates a CSS file after a plugin gets updated. Currently the CSS gets generated when any plugin gets updated. Is there a simple way to limit this running to a particular plugin?
add_filter('upgrader_post_install', 'generate_my_css', 100, 0);
function generate_my_css() {
$ss_dir = get_stylesheet_directory();
$pi_dir = plugin_dir_path( __FILE__ );
ob_start();
require($pi_dir . 'includes/css/mycss.php');
$css = ob_get_clean();
file_put_contents($ss_dir . '/css/mycss.css', $css, LOCK_EX);
}
Ideally the above code would live in the plugin that was being updated but could just as easily live in the functions.php
2 Answers
upgrader_post_install
has three parameters $response
, $hook_extra
and $result
which give you extra information. At the moment I can’t take a look myself, but I’m assuming that especially the $result
variable should give you additional information to differentiate.