Skip to content

Commit b49fe8e

Browse files
authored
Merge pull request #114 from woocommerce/update/admin-notice
Update the admin notice after doing something in the UI
2 parents 51a12de + 2d8e8f4 commit b49fe8e

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

includes/Admin/Settings.php

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public static function register_admin_menu() {
3737
public static function render_admin_page() {
3838
?>
3939
<h1>WooCommerce Smooth Generator</h1>
40+
<?php echo self::while_you_wait(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
4041
<form method="post">
4142
<?php wp_nonce_field( 'generate', 'smoothgenerator_nonce' ); ?>
4243
<h2>Generate Products</h2>
@@ -78,6 +79,7 @@ public static function process_page_submit() {
7879
} else if ( ! empty( $_POST['cancel_all_generations'] ) ) {
7980
check_admin_referer( 'generate', 'smoothgenerator_nonce' );
8081
wc_smooth_generate_cancel_all();
82+
add_action( 'admin_notices', array( __CLASS__, 'cancel_generations_notice' ) );
8183
}
8284
}
8385

@@ -88,9 +90,6 @@ public static function product_generating_notice() {
8890
?>
8991
<div class="notice notice-success is-dismissible">
9092
<p>Generating products in the background . . . </p>
91-
<p>
92-
<iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0"width="427.2" height="240" type="text/html" src="https://www.youtube.com/embed/4TYv2PhG89A?autoplay=1&fs=0&iv_load_policy=3&showinfo=0&rel=0&cc_load_policy=0&start=0&end=0"></iframe>
93-
</p>
9493
</div>
9594
<?php
9695
}
@@ -102,10 +101,53 @@ public static function order_generating_notice() {
102101
?>
103102
<div class="notice notice-success is-dismissible">
104103
<p>Generating orders in the background . . . </p>
105-
<p>
106-
<iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0"width="427.2" height="240" type="text/html" src="https://www.youtube.com/embed/4TYv2PhG89A?autoplay=1&fs=0&iv_load_policy=3&showinfo=0&rel=0&cc_load_policy=0&start=0&end=0"></iframe>
107-
</p>
108104
</div>
109105
<?php
110106
}
107+
108+
/**
109+
* Render notice about canceling generations.
110+
*/
111+
public static function cancel_generations_notice() {
112+
?>
113+
<div class="notice notice-warning is-dismissible">
114+
<p>Canceling all generations . . . </p>
115+
</div>
116+
<?php
117+
}
118+
119+
/**
120+
* Render some entertainment while waiting for the generator to finish.
121+
*
122+
* @return string
123+
*/
124+
protected static function while_you_wait() {
125+
$content = '';
126+
127+
if ( filter_input( INPUT_POST, 'smoothgenerator_nonce' ) ) {
128+
if ( filter_input( INPUT_POST, 'cancel_all_generations' ) ) {
129+
$embed = 'NF9Y3GVuPfY';
130+
} else {
131+
$videos = array(
132+
'4TYv2PhG89A',
133+
'6Whgn_iE5uc',
134+
'h_D3VFfhvs4',
135+
'QcjAXI4jANw',
136+
);
137+
$next_wait = filter_input( INPUT_COOKIE, 'smoothgenerator_next_wait' );
138+
if ( ! isset( $videos[ $next_wait ] ) ) {
139+
$next_wait = 0;
140+
}
141+
$embed = $videos[ $next_wait ];
142+
$next_wait ++;
143+
setcookie( 'smoothgenerator_next_wait', $next_wait, time() + WEEK_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, is_ssl() );
144+
}
145+
146+
$content = <<<"EMBED"
147+
<div class="wp-block-embed__wrapper"><iframe width="560" height="315" src="https://www.youtube.com/embed/$embed?autoplay=1&fs=0&iv_load_policy=3&showinfo=0&rel=0&cc_load_policy=0&start=0&end=0" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen>></iframe></div>
148+
EMBED;
149+
}
150+
151+
return $content;
152+
}
111153
}

0 commit comments

Comments
 (0)