| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 3.1.8 Free | |
| 4 | + * @version 3.1.14 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <[email protected]> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | 8 | * @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| @@ -15,18 +15,89 @@ | ||
| 15 | 15 | { |
| 16 | 16 | exit; // Exit if accessed directly. |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -use \FireBox\Core\Helpers\Form\Form; | |
| 20 | - | |
| 21 | 19 | class Campaigns extends BaseController |
| 22 | 20 | { |
| 23 | 21 | /** |
| 24 | - * Render Submissions page. | |
| 25 | - * | |
| 22 | + * The minimum WordPress version required to render the DataViews Campaigns page. | |
| 23 | + * Below this, the classic WP_List_Table fallback (CampaignsList) is used instead. | |
| 24 | + * See docs/plans/campaigns-dataviews-migration.md §3.1. | |
| 25 | + * | |
| 26 | + * Pinned to 7.0: @wordpress/dataviews depends on @wordpress/ui, whose ThemeProvider | |
| 27 | + * opts into WordPress's private/unstable APIs identifying itself as "@wordpress/theme". | |
| 28 | + * That module name is only on WordPress core's allow-list for private-API consumers | |
| 29 | + * starting WP 7.0 (it's also only WP 7.0+ that registers a `wp-theme` script handle | |
| 30 | + * at all) - on earlier WP the call throws at runtime and the whole bundle fails to | |
| 31 | + * mount, leaving the page stuck on the server-rendered loading skeleton. | |
| 32 | + */ | |
| 33 | + const DATAVIEWS_MIN_WP_VERSION = '7.0'; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Render Campaigns page. | |
| 37 | + * | |
| 26 | 38 | * @return void |
| 27 | 39 | */ |
| 28 | 40 | public function render() |
| 29 | 41 | { |
| 30 | 42 | firebox()->renderer->admin->render('pages/campaigns'); |
| 43 | + } | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * Enqueues the DataViews React app on WP >= self::DATAVIEWS_MIN_WP_VERSION. | |
| 47 | + * On older WP, the classic list table (CampaignsList) is used and needs no extra assets. | |
| 48 | + * | |
| 49 | + * @return void | |
| 50 | + */ | |
| 51 | + public function addMedia() | |
| 52 | + { | |
| 53 | + if (!self::useDataViews()) | |
| 54 | + { | |
| 55 | + return; | |
| 56 | + } | |
| 57 | + | |
| 58 | + // Build artifact, committed and shipped in every tier - always present. | |
| 59 | + $asset = include FBOX_PLUGIN_DIR . 'media/admin/js/blocks/campaigns-dataviews.asset.php'; | |
| 60 | + | |
| 61 | + wp_register_script( | |
| 62 | + 'firebox-campaigns-dataviews', | |
| 63 | + FBOX_MEDIA_ADMIN_URL . 'js/blocks/campaigns-dataviews.js', | |
| 64 | + $asset['dependencies'], | |
| 65 | + $asset['version'], | |
| 66 | + true | |
| 67 | + ); | |
| 68 | + | |
| 69 | + wp_localize_script('firebox-campaigns-dataviews', 'fboxCampaignsData', [ | |
| 70 | + 'capabilities' => [ | |
| 71 | + 'edit' => current_user_can('edit_fireboxes'), | |
| 72 | + 'delete' => current_user_can('delete_fireboxes'), | |
| 73 | + ], | |
| 74 | + 'urls' => [ | |
| 75 | + 'newCampaign' => admin_url('post-new.php?post_type=firebox'), | |
| 76 | + 'import' => admin_url('admin.php?page=firebox-import'), | |
| 77 | + ], | |
| 78 | + ]); | |
| 79 | + | |
| 80 | + wp_set_script_translations('firebox-campaigns-dataviews', 'firebox', FBOX_PLUGIN_DIR . 'languages'); | |
| 81 | + | |
| 82 | + wp_enqueue_script('firebox-campaigns-dataviews'); | |
| 83 | + | |
| 84 | + // The bundle emits one stylesheet: the @wordpress/dataviews styles followed | |
| 85 | + // by our own overrides (see the import order in campaigns/index.js). | |
| 86 | + wp_enqueue_style( | |
| 87 | + 'firebox-campaigns-dataviews', | |
| 88 | + FBOX_MEDIA_ADMIN_URL . 'js/blocks/style-campaigns-dataviews.css', | |
| 89 | + ['wp-components'], | |
| 90 | + $asset['version'] | |
| 91 | + ); | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Whether the current WordPress version can render the DataViews Campaigns page. | |
| 96 | + * | |
| 97 | + * @return bool | |
| 98 | + */ | |
| 99 | + public static function useDataViews() | |
| 100 | + { | |
| 101 | + return version_compare(get_bloginfo('version'), self::DATAVIEWS_MIN_WP_VERSION, '>='); | |
| 31 | 102 | } |
| 32 | 103 | } |