can_use_premium_code() ) { add_filter( 'the_content', [__CLASS__, 'append_credit'] ); } else { remove_filter( 'the_content', [__CLASS__, 'append_credit'] ); } } /* -------------------------------------------------------------------- * Dependency map * ------------------------------------------------------------------*/ private static function load_dependencies() : void { require_once AIPUB_DIR . 'includes/class-context.php'; require_once AIPUB_DIR . 'includes/utils.php'; require_once AIPUB_DIR . 'includes/class-limits.php'; require_once AIPUB_DIR . 'includes/class-cron.php'; require_once AIPUB_DIR . 'includes/class-brand-strategy.php'; require_once AIPUB_DIR . 'includes/class-keywords.php'; require_once AIPUB_DIR . 'includes/class-markdown.php'; require_once AIPUB_DIR . 'includes/class-generator.php'; require_once AIPUB_DIR . 'includes/class-faq.php'; // admin UI lives in /admin/ require_once AIPUB_DIR . 'admin/class-admin.php'; require_once AIPUB_DIR . 'includes/class-settings.php'; require_once AIPUB_DIR . 'includes/class-openai.php'; require_once AIPUB_DIR . 'includes/class-image.php'; require_once AIPUB_DIR . 'includes/class-rest.php'; } /* -------------------------------------------------------------------- * Compatibility guard – returns bool success * ------------------------------------------------------------------*/ private static function compat_check() : bool { global $wp_version; $php_ok = version_compare( PHP_VERSION, self::MIN_PHP, '>=' ); $wp_ok = version_compare( $wp_version, self::MIN_WP, '>=' ); if ( $php_ok && $wp_ok ) { return true; } add_action( 'admin_notices', function () use($php_ok, $wp_ok) { printf( '

%s

', esc_html( sprintf( /* translators: 1: WP version 2: PHP version */ __( 'TransformX Post Publisher requires at least WordPress %1$s and PHP %2$s.', 'ai-publisher' ), self::MIN_WP, self::MIN_PHP ) ) ); } ); /* De-activate plugin to avoid fatal errors */ add_action( 'admin_init', function () { deactivate_plugins( plugin_basename( AIPUB_FILE ) ); } ); return false; } /* -------------------------------------------------------------------- * Hooks * ------------------------------------------------------------------*/ private static function register_hooks() : void { /* Lifecycle */ register_activation_hook( AIPUB_FILE, [__CLASS__, 'on_activate'] ); register_deactivation_hook( AIPUB_FILE, [__CLASS__, 'on_deactivate'] ); register_uninstall_hook( AIPUB_FILE, [__CLASS__, 'on_uninstall'] ); /* Admin UI actions */ add_action( 'admin_menu', [Admin::class, 'register_menu'] ); add_filter( 'upload_mimes', [Image::class, 'enable_webp_uploads'] ); add_action( 'delete_attachment', [Image::class, 'cleanup_generated_files'] ); /* Front-end output */ add_action( 'wp_head', [__CLASS__, 'maybe_print_faq_schema'] ); } /** * Append attribution to post content for free users. * * @param string $content Original post content. * @return string Modified content with credit appended. */ public static function append_credit( string $content ) : string { global $post; if ( !$post instanceof \WP_Post ) { return $content; } if ( 'post' !== $post->post_type ) { return $content; } if ( !get_post_meta( $post->ID, '_aipub_generated', true ) ) { return $content; } $credit = '

Generated with brandifyit.ai

'; return $content . $credit; } /** * Output FAQPage schema in the document head when available. */ public static function maybe_print_faq_schema() : void { if ( !is_singular( 'post' ) ) { return; } global $post; if ( !$post instanceof \WP_Post ) { return; } if ( !get_post_meta( $post->ID, '_aipub_generated', true ) ) { return; } $json = get_post_meta( $post->ID, '_aipub_faq_schema', true ); if ( empty( $json ) ) { $path = Context::dir() . 'faq-schema.json'; if ( file_exists( $path ) ) { $json = file_get_contents( $path ); } } if ( empty( $json ) ) { return; } $schema = json_decode( $json, true ); if ( !is_array( $schema ) ) { return; } printf( '', esc_html( wp_json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) ) ); } /* -------------------------------------------------------------------- * Lifecycle callbacks * ------------------------------------------------------------------*/ public static function on_activate() : void { Cron::maybe_reschedule(); // Schedule event if auto-mode is enabled. flush_rewrite_rules(); } public static function on_deactivate() : void { Cron::clear(); flush_rewrite_rules(); } public static function on_uninstall() : void { /* Remove plugin options */ foreach ( [ 'aipub_openai_api_key', 'aipub_ai_model', 'aipub_keywords', 'aipub_schedule', 'aipub_post_status', 'aipub_brand_strategy' ] as $opt ) { delete_option( $opt ); } /* Purge context directory */ $dir = Context::dir(); if ( is_dir( $dir ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; WP_Filesystem(); global $wp_filesystem; foreach ( glob( $dir . '*' ) as $file ) { $wp_filesystem->delete( $file ); } $wp_filesystem->rmdir( $dir ); } } }