Initial commit: AutoBlogger v0.1.0

WordPress plugin that auto-researches topics from Reddit, generates
SEO-optimized articles via OpenRouter LLMs, runs them through a chief
editor agent, and publishes on a daily schedule.

Includes:
- Full generation pipeline (collect → analyze → score → generate → review → publish)
- Cost tracking and budget enforcement
- Admin UI: settings, review queue, metrics, activity log
- CI/CD pipeline (GitHub Actions → WordPress REST deploy)
- Unit test suite (PHPUnit + Brain Monkey)
- Structured logging with configurable verbosity

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Terence Ong
2026-04-10 16:10:27 +07:00
commit 68c6f67bcf
65 changed files with 8833 additions and 0 deletions

94
includes/class-autoloader.php Executable file
View File

@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
/**
* PSR-4-inspired autoloader for AutoBlogger classes.
*
* Maps class names like `Autoblogger_Content_Generator` to file paths like
* `includes/core/class-content-generator.php` by scanning known subdirectories.
*
* Triggered by: PHP's spl_autoload when a class is first referenced.
* Dependencies: None — this is loaded before anything else.
*
* @see autoblogger.php — Registers this autoloader at boot time.
*/
class Autoblogger_Autoloader {
/**
* Directories to scan for class files, relative to the plugin's includes/ dir.
*
* @var string[]
*/
private static array $directories = [
'', // includes/ root
'admin/',
'core/',
'providers/',
'models/',
];
/**
* Register the autoloader with SPL.
*
* @return void
*/
public static function register(): void {
spl_autoload_register( [ __CLASS__, 'autoload' ] );
}
/**
* Attempt to load a class file.
*
* Converts `Autoblogger_Content_Generator` → `class-content-generator.php`
* and searches each registered subdirectory under includes/.
*
* @param string $class_name Fully qualified class name.
*
* @return void
*/
public static function autoload( string $class_name ): void {
// Only handle our own classes.
if ( 0 !== strpos( $class_name, 'Autoblogger' ) ) {
return;
}
$file_name = self::class_to_filename( $class_name );
$base_dir = AUTOBLOGGER_PLUGIN_DIR . 'includes/';
foreach ( self::$directories as $directory ) {
$file_path = $base_dir . $directory . $file_name;
if ( file_exists( $file_path ) ) {
require_once $file_path;
return;
}
}
}
/**
* Convert a class name to its expected filename.
*
* Autoblogger_Content_Generator → class-content-generator.php
* Autoblogger_LLM_Provider_Interface → interface-llm-provider.php
*
* @param string $class_name The class name to convert.
*
* @return string The expected filename.
*/
private static function class_to_filename( string $class_name ): string {
// Remove the Autoblogger_ prefix.
$name = (string) preg_replace( '/^Autoblogger_/', '', $class_name );
// Determine file prefix: interface- or class-.
$prefix = 'class-';
if ( preg_match( '/_Interface$/', $name ) ) {
$prefix = 'interface-';
$name = (string) preg_replace( '/_Interface$/', '', $name );
}
// Convert PascalCase/UPPER_CASE to kebab-case.
$name = strtolower( (string) preg_replace( '/([a-z])([A-Z])/', '$1-$2', $name ) );
$name = str_replace( '_', '-', $name );
return $prefix . $name . '.php';
}
}