0

I was able to create a dashboard modal using add_thickbox();, triggered by a link:

<a href="#TB_inline?width=600&height=550&inlineId=my-content-id" class="thickbox">View my inline content!</a>
<div id="my-content-id" style="display:none;">

 <p>
      This is my hidden content! It will appear in ThickBox when the link is clicked.
 </p>

But actually I want it to work like this:

1) When the logged in user is redirected to the dashboard for the first time (and only the first time), the modal should appear automatically, with a button to remove the modal if user don't want to see the movie (please see the following screenshot):

enter image description here

Can someone help me with this implementation?

Thank you very much.

0

I found an old thread, How to stop showing admin notice after close button has been clicked, related to your question.

I think the accepted answer's b) method could be applied to your situation.

b. Keep a history of the dismissal of the notice, with your own dismiss action:

function my_plugin_notice() {
$user_id = get_current_user_id();
if ( !get_user_meta( $user_id, 'my_plugin_notice_dismissed' ) ) 
    echo '<div class="notice"><p>' . _e( 'Imagine something here!', 'sample-text-domain' ) . '</p><a href="?my-plugin-dismissed">Dismiss</a></div>';
}
add_action( 'admin_notices', 'my_plugin_notice' );

function my_plugin_notice_dismissed() {
$user_id = get_current_user_id();
if ( isset( $_GET['my-plugin-dismissed'] ) )
    add_user_meta( $user_id, 'my_plugin_notice_dismissed', 'true', true );
}
add_action( 'admin_init', 'my_plugin_notice_dismissed' );

So you would put

<a href="?my-plugin-dismissed">Dismiss</a>

to your modal to let users close / dismiss the video modal.

The suggested solution uses $_GET to detect if the notice has been dismissed and save it to user meta. Another way to detect and save dismissal is to use (vanilla) js or jquery click event (on close button/link) and Ajax to save the dismissal to the current user's meta.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.