Skip to content

Commit 7dd2cc2

Browse files
refactor: use new hooks for Black Friday
1 parent 95dd10a commit 7dd2cc2

File tree

3 files changed

+102
-35
lines changed

3 files changed

+102
-35
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 97 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ class Visualizer_Module_Admin extends Visualizer_Module {
4040
*/
4141
private $_libraryPage;
4242

43+
/**
44+
* Support page suffix.
45+
*
46+
* @access private
47+
* @var string
48+
*/
49+
private $_supportPage;
50+
4351
/**
4452
* Constructor.
4553
*
@@ -56,12 +64,14 @@ public function __construct( Visualizer_Plugin $plugin ) {
5664
$this->_addAction( 'enqueue_block_editor_assets', 'enqueueMediaScripts' );
5765
$this->_addAction( 'admin_footer', 'renderTemplates' );
5866
$this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts', null, 0 );
67+
$this->_addAction( 'admin_enqueue_scripts', 'enqueue_support_page' );
5968
$this->_addAction( 'admin_menu', 'registerAdminMenu' );
6069
$this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' );
6170
$this->_addFilter( 'plugin_action_links', 'getPluginActionLinks', 10, 2 );
6271
$this->_addFilter( 'plugin_row_meta', 'getPluginMetaLinks', 10, 2 );
6372
$this->_addFilter( 'visualizer_logger_data', 'getLoggerData' );
6473
$this->_addFilter( 'visualizer_feedback_review_trigger', 'feedbackReviewTrigger' );
74+
$this->_addFilter( 'themeisle_sdk_blackfriday_data', 'add_black_friday_data' );
6575

6676
// screen pagination
6777
$this->_addFilter( 'set-screen-option', 'setScreenOptions', 10, 3 );
@@ -639,40 +649,56 @@ public function renderTemplates() {
639649
* @param string $suffix The current page suffix.
640650
*/
641651
public function enqueueLibraryScripts( $suffix ) {
642-
if ( $suffix === $this->_libraryPage ) {
643-
wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION );
644-
$this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' );
645-
wp_enqueue_media();
652+
if ( $suffix !== $this->_libraryPage ) {
653+
return;
654+
}
655+
656+
wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION );
657+
$this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' );
658+
wp_enqueue_media();
659+
wp_enqueue_script(
660+
'visualizer-library',
661+
VISUALIZER_ABSURL . 'js/library.js',
662+
array(
663+
'jquery',
664+
'media-views',
665+
'clipboard',
666+
),
667+
Visualizer_Plugin::VERSION,
668+
true
669+
);
670+
671+
wp_enqueue_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true );
672+
673+
$query = $this->getQuery();
674+
while ( $query->have_posts() ) {
675+
$chart = $query->next_post();
676+
$library = $this->load_chart_type( $chart->ID );
677+
if ( is_null( $library ) ) {
678+
continue;
679+
}
646680
wp_enqueue_script(
647-
'visualizer-library',
648-
VISUALIZER_ABSURL . 'js/library.js',
649-
array(
650-
'jquery',
651-
'media-views',
652-
'clipboard',
653-
),
681+
"visualizer-render-$library",
682+
VISUALIZER_ABSURL . 'js/render-facade.js',
683+
apply_filters( 'visualizer_assets_render', array( 'visualizer-library', 'visualizer-customization' ), true ),
654684
Visualizer_Plugin::VERSION,
655685
true
656686
);
687+
}
657688

658-
wp_enqueue_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true );
689+
do_action( 'themeisle_internal_page', VISUALIZER_DIRNAME, 'library' );
690+
}
659691

660-
$query = $this->getQuery();
661-
while ( $query->have_posts() ) {
662-
$chart = $query->next_post();
663-
$library = $this->load_chart_type( $chart->ID );
664-
if ( is_null( $library ) ) {
665-
continue;
666-
}
667-
wp_enqueue_script(
668-
"visualizer-render-$library",
669-
VISUALIZER_ABSURL . 'js/render-facade.js',
670-
apply_filters( 'visualizer_assets_render', array( 'visualizer-library', 'visualizer-customization' ), true ),
671-
Visualizer_Plugin::VERSION,
672-
true
673-
);
674-
}
692+
/**
693+
* Enqueue script for support page.
694+
*
695+
* @param string $hook_suffix Current hook.
696+
*/
697+
public function enqueue_support_page( $hook_suffix ) {
698+
if ( $this->_supportPage !== $hook_suffix ) {
699+
return;
675700
}
701+
do_action( 'themeisle_internal_page', VISUALIZER_DIRNAME, 'support' );
676702
}
677703

678704
/**
@@ -718,7 +744,8 @@ public function registerAdminMenu() {
718744
'edit_posts',
719745
'admin.php?page=' . Visualizer_Plugin::NAME . '&vaction=addnew'
720746
);
721-
add_submenu_page(
747+
748+
$this->_supportPage = add_submenu_page(
722749
Visualizer_Plugin::NAME,
723750
__( 'Support', 'visualizer' ),
724751
__( 'Support', 'visualizer' ) . '<span class="dashicons dashicons-editor-help more-features-icon" style="width: 17px; height: 17px; margin-left: 4px; color: #ffca54; font-size: 17px; vertical-align: -3px;"></span>',
@@ -938,7 +965,6 @@ private function getQuery() {
938965
*/
939966
public function renderSupportPage() {
940967
wp_enqueue_style( 'visualizer-upsell', VISUALIZER_ABSURL . 'css/upsell.css', array(), Visualizer_Plugin::VERSION );
941-
do_action( 'themeisle_internal_page', VISUALIZER_DIRNAME, 'support' );
942968
include_once VISUALIZER_ABSPATH . '/templates/support.php';
943969
}
944970

@@ -1095,12 +1121,6 @@ public function renderLibraryPage() {
10951121
)
10961122
);
10971123

1098-
do_action( 'themeisle_internal_page', VISUALIZER_DIRNAME, 'library' );
1099-
1100-
if ( ! apply_filters( 'visualizer_is_business', false ) ) {
1101-
do_action( 'themeisle_sdk_load_banner', 'visualizer' );
1102-
}
1103-
11041124
$render->render();
11051125
}
11061126

@@ -1304,4 +1324,46 @@ public function count_charts( $limit = -1 ) {
13041324
$query = new WP_Query( $args);
13051325
return $query->post_count;
13061326
}
1327+
1328+
/**
1329+
* Set the black friday data.
1330+
*
1331+
* @param array $configs The configuration array for the loaded products.
1332+
* @return array
1333+
*/
1334+
public function add_black_friday_data( $configs ) {
1335+
$config = $configs['default'];
1336+
1337+
// translators: %1$s - HTML tag, %2$s - discount, %3$s - HTML tag, %4$s - product name.
1338+
$message_template = __( 'Our biggest sale of the year: %1$sup to %2$s OFF%3$s on %4$s. Don\'t miss this limited-time offer.', 'wp-cloudflare-page-cache' );
1339+
$product_label = 'Visualizer';
1340+
$discount = '70%';
1341+
1342+
$plan = apply_filters( 'product_visualizer_license_plan', 0 );
1343+
$license = apply_filters( 'product_visualizer_license_key', false );
1344+
$is_pro = 0 < $plan;
1345+
1346+
if ( $is_pro ) {
1347+
// translators: %1$s - HTML tag, %2$s - discount, %3$s - HTML tag, %4$s - product name.
1348+
$message_template = __( 'Get %1$sup to %2$s off%3$s when you upgrade your %4$s plan or renew early.', 'wp-cloudflare-page-cache' );
1349+
$product_label = 'Visualizer Pro';
1350+
$discount = '30%';
1351+
}
1352+
1353+
$product_label = sprintf( '<strong>%s</strong>', $product_label );
1354+
$url_params = array(
1355+
'utm_term' => $is_pro ? 'plan-' . $plan : 'free',
1356+
'lkey' => ! empty( $license ) ? $license : false,
1357+
);
1358+
1359+
$config['message'] = sprintf( $message_template, '<strong>', $discount, '</strong>', $product_label );
1360+
$config['sale_url'] = add_query_arg(
1361+
$url_params,
1362+
tsdk_translate_link( tsdk_utmify( 'https://themeisle.link/vizualizer-bf', 'bfcm', 'visualizer' ) )
1363+
);
1364+
1365+
$configs[ VISUALIZER_DIRNAME ] = $config;
1366+
1367+
return $configs;
1368+
}
13071369
}

css/upsell.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,8 @@
174174
width: 100%;
175175
background: #fff;
176176
}
177+
178+
div.notice.themeisle-sale {
179+
margin-left: 10px;
180+
margin-right: 10px;
181+
}

images/black-friday.jpg

-88.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)