<?php
$cfg=getenv('WPCFG');$pfx=getenv('PFX');
$s=file_get_contents($cfg);
function gc($s,$k){return preg_match('/define\(\s*[\x27\x22]'.$k.'[\x27\x22]\s*,\s*[\x27\x22]([^\x27\x22]*)/',$s,$m)?$m[1]:'';}
$m=@new mysqli(gc($s,'DB_HOST'),gc($s,'DB_USER'),gc($s,'DB_PASSWORD'),gc($s,'DB_NAME'));
if($m->connect_errno){fwrite(STDERR,'  DB ERR '.$m->connect_error."\n");exit(1);}
$r=$m->query("SELECT option_value FROM {$pfx}options WHERE option_name='active_plugins'");
if(!$r||!$r->num_rows){echo "  active_plugins: introuvable\n";exit(0);}
$arr=@unserialize($r->fetch_row()[0]);
if(!is_array($arr)){fwrite(STDERR,"  active_plugins illisible\n");exit(1);}
$b=count($arr);
$arr=array_values(array_filter($arr,function($x){return strpos($x,'wp-helper-')===false && strpos($x,'hseo/')===false;}));
$st=$m->prepare("UPDATE {$pfx}options SET option_value=? WHERE option_name='active_plugins'");
$n=serialize($arr);$st->bind_param('s',$n);$st->execute();
echo "  active_plugins: $b -> ".count($arr)." (retire ".($b-count($arr)).")\n";
