filtres poses une seule fois.
add_action( 'plugins_loaded', array( 'Aiforya_Smap_AI_Marking', 'init' ) );
// =============================================================================
// 2bis. Services métier internes.
// =============================================================================
require_once AIFORYA_SMAP_DIR . 'includes/class-aiforya-smap-settings.php';
require_once AIFORYA_SMAP_DIR . 'includes/class-aiforya-smap-sitemap.php';
require_once AIFORYA_SMAP_DIR . 'includes/class-aiforya-smap-ajax.php';
// =============================================================================
// 3. Activator.
// =============================================================================
require_once AIFORYA_SMAP_DIR . 'includes/class-aiforya-smap-activator.php';
register_activation_hook( __FILE__, [ 'Aiforya_Smap_Activator', 'activate' ] );
register_deactivation_hook( __FILE__, [ 'Aiforya_Smap_Activator', 'deactivate' ] );
// =============================================================================
// 3bis. Service de plan de site (front + réécriture d'URL).
// =============================================================================
Aiforya_Smap_Sitemap::get_instance()->register_hooks();
// =============================================================================
// 4bis. Assets du shell + interface commune (admin).
// =============================================================================
add_action( 'admin_enqueue_scripts', static function ( string $hook ): void {
if ( class_exists( 'AIFORYA_SMAP_Shell' ) && method_exists( 'AIFORYA_SMAP_Shell', 'maybe_enqueue_assets' ) ) {
AIFORYA_SMAP_Shell::maybe_enqueue_assets( $hook );
}
}, 5 );
add_action( 'admin_enqueue_scripts', static function ( string $hook ): void {
$vendor_url = AIFORYA_SMAP_URL . 'vendor-aiforya/assets/';
wp_enqueue_style( 'aiforya-ui-bbf8d166', $vendor_url . 'aiforya-ui.css', [], AIFORYA_SMAP_VERSION );
wp_enqueue_script( 'aiforya-ui-bbf8d166', $vendor_url . 'aiforya-ui.js', [], AIFORYA_SMAP_VERSION, true );
wp_localize_script( 'aiforya-ui-bbf8d166', 'aiforyaUiI18n', [
'confirm' => __( 'OK', 'aiforya-sitemap' ),
'cancel' => __( 'Cancel', 'aiforya-sitemap' ),
] );
}, 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_SMAP_SLUG !== $page ) {
return;
}
wp_enqueue_script(
'aiforya-smap-admin',
AIFORYA_SMAP_URL . 'assets/js/aiforya-smap-admin.js',
[ 'jquery' ],
AIFORYA_SMAP_VERSION,
true
);
wp_localize_script( 'aiforya-smap-admin', 'aiforyaSmap', [
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'aiforya_smap_ajax' ),
'i18n' => [
'saved' => __( 'Saved.', 'aiforya-sitemap' ),
'error' => __( 'An error occurred.', 'aiforya-sitemap' ),
'working' => __( 'Processing…', 'aiforya-sitemap' ),
],
] );
}, 20 );
// =============================================================================
// 5. Boot du moteur.
// =============================================================================
add_action( 'plugins_loaded', static function (): void {
if ( ! class_exists( 'Aiforya_Smap_Engine', false ) ) {
return;
}
Aiforya_Smap_Engine::boot( AIFORYA_SMAP_DIR, [
'slug' => AIFORYA_SMAP_SLUG,
'requires_activation' => false, // Extension gratuite .org : aucun écran d'activation licence.
'title' => 'AIFORYA Sitemap',
'description' => 'Generate an XML sitemap so search engines can crawl and index your pages, posts and categories. No API key, no account.',
'icon' => 'dashicons-networking',
'category' => 'SEO',
'capability' => 'manage_options',
'position' => 20,
'plugin_basename' => AIFORYA_SMAP_BASENAME,
'plugin_image' => plugins_url( 'assets/images/cover.png', __FILE__ ),
'faq' => static function () {
return [
[
'q' => __( 'What is an XML sitemap for?', 'aiforya-sitemap' ),
'a' => __( 'An XML sitemap is a structured list of your site addresses. Search engines (Google, Bing and others) use it to discover your pages faster and to see which ones changed recently. An up-to-date sitemap is a cornerstone of organic search.', 'aiforya-sitemap' ),
],
[
'q' => __( 'Where is my sitemap?', 'aiforya-sitemap' ),
'a' => __( 'At your site address followed by "/aiforya-sitemap.xml". The Overview tab shows the exact, clickable link.', 'aiforya-sitemap' ),
],
[
'q' => __( 'Which content is included?', 'aiforya-sitemap' ),
'a' => __( 'The home page, plus published posts and pages of the post types you select. You can also include category and tag archives.', 'aiforya-sitemap' ),
],
[
'q' => __( 'Should I submit the sitemap to Google?', 'aiforya-sitemap' ),
'a' => __( 'For best results, add the sitemap address in Google Search Console and the Bing equivalent. You can also enable the automatic publish notification in the Settings tab.', 'aiforya-sitemap' ),
],
[
'q' => __( 'Do I need an API key?', 'aiforya-sitemap' ),
'a' => __( 'No. This free version is entirely self-contained and generates the sitemap directly on your server. The only optional outside request is the publish notification to Google and Bing, which is off by default.', 'aiforya-sitemap' ),
],
];
},
] );
// 5b. Services métier admin.
Aiforya_Smap_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_SMAP_BASENAME ) {
return $links;
}
$links[] = '' . esc_html__( 'User guide', 'aiforya-sitemap' ) . '';
return $links;
}, 10, 2 );
add_filter( 'plugin_action_links_' . AIFORYA_SMAP_BASENAME, static function ( array $links ): array {
$settings_link = '' . esc_html__( 'Open', 'aiforya-sitemap' ) . '';
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 );