Merge BD Bookshelf (0.1.0), BD BookShelfHelper (2.0.0) and BD SimpleEmail
(2.0.0) into a single plugin released as Umbra Bookshelf 1.0.0, with the
BD Bookshelf theme left as a separate, unrenamed artifact.
Modules
includes/books/ catalogue, ISBN/ASIN, series, retail, ratings, shortcodes,
SEO, GDPR, scrapers, admin, CSV/post import
includes/library/ book post type + series taxonomy, pen names, data entry,
shortlinks, reviews, migrate
includes/email/ subscribers, newsletters, composition, sending
Renamed: plugin headers, text domains (all three -> umbra-bookshelf), classes
(BD_*/BDM_* -> Umbra_*), constants (-> UMBRA_BOOKSHELF_*), asset handles, JS
globals and admin slugs.
Deliberately not renamed -- persisted contract with live installs and with
published post content: table names, option keys, post meta keys, transients,
nonce actions, cron hooks, AJAX actions, shortcodes ([bd-book], [bd-books],
[bdm_signup]), post type `book`, taxonomy `series`, cookies and CSS classes.
BD_BookShelfHelper survives only as a class_alias for the unmodified theme.
Collisions resolved
* class-umbra-theme-compatibility.php declared BD_BookShelfHelper, the same
name as the library module's helper. Latent while the plugins were
separate (only fired when both were active), but an unconditional fatal
once merged. Renamed to Umbra_Theme_Compatibility with a class_alias.
* All three modules called add_menu_page. One top-level menu is now
registered by the bootstrap at admin_menu priority 9.
* BD Bookshelf and BookShelfHelper both claimed bd-bookshelf-settings, leaving
one Settings screen unreachable -> umbra-bookshelf-settings and
umbra-bookshelf-library-settings.
* Catalogue and library both enqueued bd-bookshelf-admin; the second enqueue
was silently discarded -> unique handles per module.
* Umbra_Admin and Umbra_Migration both registered bd_bookshelf_import_csv, so
one handler silently replaced the other. The import page now lives only in
Umbra_Admin (the variant wired to the admin JS); Umbra_Migration keeps only
the preview/run endpoints it uniquely provides.
* Modules were constructed from an init callback, so their own init
registrations raced the hook being dispatched. Now constructed on
plugins_loaded behind a re-entrancy guard.
Also
* Missing assets created: assets/images/default-cover.png (referenced but
never committed, so every cover-less book 404'd) and email/assets/js/
admin.js (enqueued on every email admin page but never committed).
* Library module's strpos($hook, 'bd-bookshelf') asset check matched every
catalogue and email screen once slugs shared the umbra-bookshelf- prefix;
now matched against its own slug list.
* Consolidated uninstall deduplicates the double drop of bd_books/bd_series.
* Specs aligned to the new name; pre-merge specs retained under
spec/archive/ with provenance notes.
* Tests added: tests/verify_structure.py (static) and tests/smoke_runtime.php
(WordPress-stub runtime boot, front-end and admin contexts).
Deferred and recorded in docs/KNOWN-ISSUES.md: the catalogue and library
modules still create bd_books and bd_series with two incompatible schemas
(pre-existing, now unconditional), and Goodreads/Amazon scraping is still
implemented twice on shared cron hooks.
176 lines
5.7 KiB
PHP
176 lines
5.7 KiB
PHP
<?php
|
|
// Copyright 2026 Umbra Tools (umbratools.com)
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
/**
|
|
* Installation and Database Setup
|
|
*
|
|
* @package Umbra_Bookshelf_Helper
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class Umbra_Bookshelf_Helper_Install {
|
|
/**
|
|
* Activate plugin
|
|
*/
|
|
public static function activate() {
|
|
self::create_tables();
|
|
self::create_roles();
|
|
flush_rewrite_rules();
|
|
}
|
|
|
|
/**
|
|
* Deactivate plugin
|
|
*/
|
|
public static function deactivate() {
|
|
self::remove_roles();
|
|
wp_clear_scheduled_hook('bd_bookshelf_goodreads_refresh');
|
|
wp_clear_scheduled_hook('bd_bookshelf_amazon_scrape');
|
|
flush_rewrite_rules();
|
|
}
|
|
|
|
/**
|
|
* Create database tables
|
|
*/
|
|
public static function create_tables() {
|
|
global $wpdb;
|
|
$charset_collate = $wpdb->get_charset_collate();
|
|
|
|
$tables = array(
|
|
"CREATE TABLE IF NOT EXISTS {$wpdb->prefix}bd_books (
|
|
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
post_id BIGINT(20) NOT NULL,
|
|
pen_name_id BIGINT(20),
|
|
series_id BIGINT(20),
|
|
volume_number INT(11),
|
|
asin VARCHAR(20),
|
|
isbn VARCHAR(20),
|
|
publish_date DATE,
|
|
sort_order INT(11) DEFAULT 0,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
UNIQUE KEY post_id (post_id)
|
|
) $charset_collate;",
|
|
|
|
"CREATE TABLE IF NOT EXISTS {$wpdb->prefix}bd_book_meta (
|
|
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
book_id BIGINT(20) NOT NULL,
|
|
language_code VARCHAR(5) NOT NULL,
|
|
title VARCHAR(255),
|
|
blurb TEXT,
|
|
preview_excerpt TEXT,
|
|
pull_quotes JSON,
|
|
UNIQUE KEY book_language (book_id, language_code)
|
|
) $charset_collate;",
|
|
|
|
"CREATE TABLE IF NOT EXISTS {$wpdb->prefix}bd_series (
|
|
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
slug VARCHAR(100) NOT NULL UNIQUE,
|
|
cover_attachment_id BIGINT(20),
|
|
header_attachment_id BIGINT(20),
|
|
blurb TEXT,
|
|
display_order INT(11) DEFAULT 0,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
) $charset_collate;",
|
|
|
|
"CREATE TABLE IF NOT EXISTS {$wpdb->prefix}bd_pen_names (
|
|
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
pen_name VARCHAR(255) NOT NULL,
|
|
notes TEXT,
|
|
active TINYINT(1) DEFAULT 1,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
) $charset_collate;",
|
|
|
|
"CREATE TABLE IF NOT EXISTS {$wpdb->prefix}bd_reviews (
|
|
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
book_id BIGINT(20) NOT NULL,
|
|
comment_text TEXT,
|
|
synopsis TEXT,
|
|
source_name VARCHAR(255) NOT NULL,
|
|
source_url VARCHAR(500),
|
|
display_order INT(11) DEFAULT 0,
|
|
KEY book_id (book_id)
|
|
) $charset_collate;",
|
|
|
|
"CREATE TABLE IF NOT EXISTS {$wpdb->prefix}bd_ratings (
|
|
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
book_id BIGINT(20) NOT NULL,
|
|
source VARCHAR(20) NOT NULL,
|
|
rating DECIMAL(3,2),
|
|
review_count INT(11),
|
|
last_updated DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
UNIQUE KEY book_source (book_id, source)
|
|
) $charset_collate;",
|
|
|
|
"CREATE TABLE IF NOT EXISTS {$wpdb->prefix}bd_review_shortlinks (
|
|
id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
book_id BIGINT(20) NOT NULL,
|
|
site_code VARCHAR(5) NOT NULL,
|
|
slug VARCHAR(20) NOT NULL UNIQUE,
|
|
destination_url VARCHAR(500),
|
|
status VARCHAR(20) DEFAULT 'pending',
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
activated_at DATETIME
|
|
) $charset_collate;",
|
|
);
|
|
|
|
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
|
|
|
foreach ($tables as $table) {
|
|
dbDelta($table);
|
|
}
|
|
|
|
self::install_sample_data();
|
|
}
|
|
|
|
/**
|
|
* Install sample data
|
|
*/
|
|
private static function install_sample_data() {
|
|
global $wpdb;
|
|
|
|
// Add default pen name
|
|
$pen_names_table = $wpdb->prefix . 'bd_pen_names';
|
|
$exists = $wpdb->get_var("SELECT COUNT(*) FROM {$pen_names_table}");
|
|
|
|
if ($exists == 0) {
|
|
$wpdb->insert($pen_names_table, array(
|
|
'pen_name' => 'B.D. Murphy',
|
|
'notes' => 'Primary author name',
|
|
'active' => 1,
|
|
'created_at' => current_time('mysql'),
|
|
));
|
|
}
|
|
|
|
// Set default Goodreads ID
|
|
update_option('bdm_goodreads_author_id', '30469651');
|
|
}
|
|
|
|
/**
|
|
* Create roles
|
|
*/
|
|
private static function create_roles() {
|
|
add_role('book_manager', esc_html__('Book Manager', 'umbra-bookshelf'), array(
|
|
'read' => true,
|
|
'edit_books' => true,
|
|
'edit_others_books' => true,
|
|
'publish_books' => true,
|
|
'read_private_posts' => true,
|
|
'edit_posts' => true,
|
|
'edit_others_posts' => true,
|
|
'publish_posts' => true,
|
|
'upload_files' => true,
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Remove roles
|
|
*/
|
|
private static function remove_roles() {
|
|
remove_role('book_manager');
|
|
}
|
|
}
|