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.
127 lines
3.4 KiB
PHP
127 lines
3.4 KiB
PHP
<?php
|
|
// Copyright 2026 Umbra Tools (umbratools.com)
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
/**
|
|
* GDPR Compliance class
|
|
*
|
|
* @package Umbra_Bookshelf
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class Umbra_GDPR {
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct() {
|
|
add_action('wp_footer', [$this, 'render_consent_banner']);
|
|
add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']);
|
|
|
|
// AJAX handlers
|
|
add_action('wp_ajax_bd_bookshelf_accept_consent', [$this, 'ajax_accept_consent']);
|
|
add_action('wp_ajax_nopriv_bd_bookshelf_accept_consent', [$this, 'ajax_accept_consent']);
|
|
}
|
|
|
|
/**
|
|
* Enqueue GDPR scripts
|
|
*/
|
|
public function enqueue_scripts() {
|
|
if (is_admin()) {
|
|
return;
|
|
}
|
|
|
|
wp_enqueue_script(
|
|
'umbra-bookshelf-gdpr',
|
|
UMBRA_BOOKSHELF_URL . 'public/js/umbra-bookshelf-gdpr.js',
|
|
[],
|
|
UMBRA_BOOKSHELF_VERSION,
|
|
true
|
|
);
|
|
|
|
wp_localize_script('umbra-bookshelf-gdpr', 'umbraBookshelfGdpr', [
|
|
'ajaxurl' => admin_url('admin-ajax.php'),
|
|
'nonce' => wp_create_nonce('bd_bookshelf_gdpr_nonce'),
|
|
'cookieDays' => 30,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Render consent banner
|
|
*/
|
|
public function render_consent_banner() {
|
|
if (is_admin()) {
|
|
return;
|
|
}
|
|
|
|
if ($this->has_consent()) {
|
|
return;
|
|
}
|
|
|
|
$privacy_page_url = $this->get_privacy_page_url();
|
|
$privacy_text = get_option('bd_bookshelf_gdpr_text',
|
|
'We use cookies for affiliate tracking only. By clicking "Accept", you agree to our use of cookies as described in our <a href="' . esc_url($privacy_page_url) . '" target="_blank">Privacy Policy</a>.'
|
|
);
|
|
|
|
echo '<div id="bd-bookshelf-gdpr-banner" class="bd-bookshelf-gdpr-banner">';
|
|
echo '<div class="bd-bookshelf-gdpr-content">';
|
|
echo '<p>' . wp_kses_post($privacy_text) . '</p>';
|
|
echo '<button id="bd-bookshelf-gdpr-accept" class="bd-bookshelf-gdpr-accept">' . esc_html__('Accept', 'umbra-bookshelf') . '</button>';
|
|
echo '</div>';
|
|
echo '</div>';
|
|
}
|
|
|
|
/**
|
|
* Check if user has given consent
|
|
*/
|
|
public static function has_consent() {
|
|
if (isset($_COOKIE['bd_bookshelf_consent'])) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* AJAX handler for accepting consent
|
|
*/
|
|
public function ajax_accept_consent() {
|
|
check_ajax_referer('bd_bookshelf_gdpr_nonce', 'nonce');
|
|
|
|
// Set consent cookie (30 days)
|
|
setcookie('bd_bookshelf_consent', '1', time() + (30 * DAY_IN_SECONDS), '/');
|
|
|
|
wp_send_json_success(['message' => 'Consent accepted']);
|
|
}
|
|
|
|
/**
|
|
* Get privacy page URL
|
|
*/
|
|
private function get_privacy_page_url() {
|
|
$privacy_page_id = get_option('wp_page_for_privacy_policy');
|
|
|
|
if ($privacy_page_id) {
|
|
return get_permalink($privacy_page_id);
|
|
}
|
|
|
|
return '#';
|
|
}
|
|
|
|
/**
|
|
* Get GDPR consent banner text
|
|
*/
|
|
public static function get_consent_text() {
|
|
return get_option('bd_bookshelf_gdpr_text', '');
|
|
}
|
|
|
|
/**
|
|
* Update GDPR consent banner text
|
|
*/
|
|
public static function update_consent_text($text) {
|
|
update_option('bd_bookshelf_gdpr_text', sanitize_text_field($text));
|
|
}
|
|
}
|