| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.1.13 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FireBox\Core\Controllers; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class Campaigns extends BaseController |
| 20 |
{ |
| 21 |
/** |
| 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 |
* |
| 38 |
* @return void |
| 39 |
*/ |
| 40 |
public function render() |
| 41 |
{ |
| 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, '>='); |
| 102 |
} |
| 103 |
} |