filtres poses une seule fois.
add_action( 'plugins_loaded', array( 'Aiforya_Al_AI_Marking', 'init' ) );
// =============================================================================
// 2bis. Services métier internes.
// =============================================================================
require_once AIFORYA_AL_DIR . 'includes/class-aiforya-al-settings.php';
require_once AIFORYA_AL_DIR . 'includes/class-aiforya-al-repository.php';
require_once AIFORYA_AL_DIR . 'includes/class-aiforya-al-logger.php';
require_once AIFORYA_AL_DIR . 'includes/class-aiforya-al-ajax.php';
// =============================================================================
// 3. Activator.
// =============================================================================
require_once AIFORYA_AL_DIR . 'includes/class-aiforya-al-activator.php';
register_activation_hook( __FILE__, [ 'Aiforya_Al_Activator', 'activate' ] );
register_deactivation_hook( __FILE__, [ 'Aiforya_Al_Activator', 'deactivate' ] );
// =============================================================================
// 3bis. Journalisation des évènements (front + admin).
// =============================================================================
Aiforya_Al_Logger::get_instance()->register_hooks();
// Nettoyage planifié (rétention).
add_action( 'aiforya_al_cleanup', static function (): void {
Aiforya_Al_Repository::get_instance()->purge_old( (int) Aiforya_Al_Settings::get_instance()->value( 'retention_days', 30 ) );
} );
// =============================================================================
// 4bis. Assets du shell + interface commune (admin).
// =============================================================================
add_action( 'admin_enqueue_scripts', static function ( string $hook ): void {
if ( class_exists( 'AIFORYA_AL_Shell' ) && method_exists( 'AIFORYA_AL_Shell', 'maybe_enqueue_assets' ) ) {
AIFORYA_AL_Shell::maybe_enqueue_assets( $hook );
}
}, 5 );
add_action( 'admin_enqueue_scripts', static function ( string $hook ): void {
$vendor_url = AIFORYA_AL_URL . 'vendor-aiforya/assets/';
wp_enqueue_style( 'aiforya-ui-bbf8d166', $vendor_url . 'aiforya-ui.css', [], AIFORYA_AL_VERSION );
wp_enqueue_script( 'aiforya-ui-bbf8d166', $vendor_url . 'aiforya-ui.js', [], AIFORYA_AL_VERSION, true );
wp_localize_script( 'aiforya-ui-bbf8d166', 'aiforyaUiI18n', [
'confirm' => __( 'Confirm', 'aiforya-activity-log' ),
'cancel' => __( 'Cancel', 'aiforya-activity-log' ),
] );
}, 5 );
// =============================================================================
// 4ter. Assets admin spécifiques (JS AJAX + localisation).
// =============================================================================
add_action( 'admin_enqueue_scripts', static function ( string $hook ): void {
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
if ( AIFORYA_AL_SLUG !== $page ) {
return;
}
wp_enqueue_script(
'aiforya-al-admin',
AIFORYA_AL_URL . 'assets/js/aiforya-activity-log-admin.js',
[ 'jquery' ],
AIFORYA_AL_VERSION,
true
);
wp_localize_script( 'aiforya-al-admin', 'aiforyaAl', [
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'aiforya_al_ajax' ),
'i18n' => [
'saved' => __( 'Saved.', 'aiforya-activity-log' ),
'error' => __( 'Something went wrong.', 'aiforya-activity-log' ),
'working' => __( 'Working…', 'aiforya-activity-log' ),
'cleared' => __( 'Log cleared.', 'aiforya-activity-log' ),
'confirm' => __( 'Clear the entire log? This cannot be undone.', 'aiforya-activity-log' ),
],
] );
}, 20 );
// =============================================================================
// 5. Boot du moteur.
// =============================================================================
add_action( 'plugins_loaded', static function (): void {
if ( ! class_exists( 'Aiforya_Al_Engine', false ) ) {
return;
}
Aiforya_Al_Engine::boot( AIFORYA_AL_DIR, [
'slug' => AIFORYA_AL_SLUG,
'requires_activation' => false, // Free .org plugin: no licence activation screen.
'title' => 'AIFORYA Activity Log',
'description' => 'Logs the important admin actions on your site, with adjustable retention — local only, no API key.',
'icon' => 'dashicons-list-view',
'category' => 'Security',
'capability' => 'manage_options',
'position' => 20,
'plugin_basename' => AIFORYA_AL_BASENAME,
'plugin_image' => plugins_url( 'assets/images/cover.png', __FILE__ ),
'faq' => static function () {
return [
[
'q' => __( 'What is an activity log for?', 'aiforya-activity-log' ),
'a' => __( 'It keeps a record of the important actions performed on your site (logins, publishing or editing content, plugin activations, account management). It is what tells you who did what when something looks wrong, after an incident, or when several people work on the same site.', 'aiforya-activity-log' ),
],
[
'q' => __( 'Which actions are recorded?', 'aiforya-activity-log' ),
'a' => __( 'By the categories you enable: logins and logouts, content (publishing, editing, deleting), plugins and theme, user accounts. You choose what you want to track.', 'aiforya-activity-log' ),
],
[
'q' => __( 'How long are events kept?', 'aiforya-activity-log' ),
'a' => __( 'You set a retention period (30 days by default). A daily automatic cleanup removes older events to keep the database small.', 'aiforya-activity-log' ),
],
[
'q' => __( 'Does any of this data leave my site?', 'aiforya-activity-log' ),
'a' => __( 'No. Everything is stored in your own WordPress database. No data is sent to any external service.', 'aiforya-activity-log' ),
],
[
'q' => __( 'Do I need an API key or a subscription?', 'aiforya-activity-log' ),
'a' => __( 'No. The plugin runs entirely locally, with no API key and no third-party service.', 'aiforya-activity-log' ),
],
];
},
] );
// 5b. Services métier admin.
Aiforya_Al_Ajax::get_instance()->register_hooks();
}, 5 );
// =============================================================================
// 6. Liens dans la liste des extensions.
// =============================================================================
add_filter( 'plugin_row_meta', static function ( array $links, string $file ): array {
if ( $file !== AIFORYA_AL_BASENAME ) {
return $links;
}
$links[] = '' . esc_html__( 'User guide', 'aiforya-activity-log' ) . '';
return $links;
}, 10, 2 );
add_filter( 'plugin_action_links_' . AIFORYA_AL_BASENAME, static function ( array $links ): array {
$settings_link = '' . esc_html__( 'Open', 'aiforya-activity-log' ) . '';
array_unshift( $links, $settings_link );
return $links;
} );
// =============================================================================
// 7. Anti-pollution notifications sur les pages AIFORYA.
// =============================================================================
add_action( 'in_admin_header', static function (): void {
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
if ( strpos( $page, 'aiforya-' ) !== 0 ) {
return;
}
remove_all_actions( 'admin_notices' );
remove_all_actions( 'all_admin_notices' );
remove_all_actions( 'user_admin_notices' );
remove_all_actions( 'network_admin_notices' );
}, 1 );