Viewing 1 replies (of 1 total)
  • Thread Starter garciasanchezdani

    (@garciasanchezdani)

    Hi all, I solved it by using transient API 🙂
    This is a screenshot of my modal displayed just a user connected to the private zone.
    http://prntscr.com/4lrayw

    The code:

    1. Inside functions.php

    //for activate the flag
    function after_login_display_modal($user_login) {
         set_transient( $user_login, '1', 0 );
    }
    add_action('wp_login', 'after_login_display_modal');

    2. Inside functions.php add our script which display the modal

    add_action( ‘wp_enqueue_scripts’, ‘custom_scripts’ );

    function custom_scripts () {
        global $current_user;
        get_currentuserinfo();
    
         //add the script if the user is connected, and the flag is activated (previously activated with set_transient
       if ( get_transient( $current_user->user_login )==1 && is_user_logged_in() ){
           //the script will dependend on jquery and minified (because of select minify scripts on wplms panel in wpadmin)
          //my custom script names after_login_display_modal.js
            wp_register_script( 'after_login_display_modal_javascript', get_stylesheet_directory_uri().'/js/after_login_display_modal.js', array('jquery','minified-js'));
            wp_enqueue_script( 'after_login_display_modal_javascript' );
        }
    }

    3. The after_login_display_modal.js only have:

    jQuery(document).ready(function($){
        $("#after_login_modal").modal();
    });

    4. In the header.php of my child theme I’ve created the dom type boostrap modal, with id after_login_modal:

    <div id="after_login_modal" class="modal bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-sm">
    
            <div class="modal-content">
    
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="after_login_modalLabel">Bienvenido/a <?php echo ($current_user->display_name); ?></h4>
                </div>
    
                <div class="modal-body" style="padding-bottom: 5em;">
                    <p>¿Qué quiere hacer hoy?</p>
                    <input type="radio" name="group1" value="crear_curso" /> Crear un curso<br>
                    <input type="radio" name="group1" value="ver_cursos_creados" id="<?php echo bp_loggedin_user_domain().BP_COURSE_SLUG.'/instructor-courses' ?>"/> Ver mis cursos creados<br>
                    <input type="radio" name="group1" value="ver_matriculaciones" id="<?php echo bp_loggedin_user_domain().BP_COURSE_SLUG ?>"/> Ver los cursos en los que estoy matriculado/a<br>
                    <input type="radio" name="group1" value="crear_blog"/> Crear un blog<br>
                    <input type="radio" name="group1" value="quedarme_donde_estoy" checked /> Quedarme donde estoy<br>
                    <br><button type="button" data-loading-text="Cargando..." class="btn" id="guia_modal_seleccion">Aceptar</button>
                    <img src="/wp-content/themes/wplms-educa/images/guia_usuario.png"
                         style="position: absolute;right: 0;bottom: 0;padding-bottom: 0em;" />
                </div>
    
            </div>
        </div>
    </div>

    Hope that helps.

Viewing 1 replies (of 1 total)
  • The topic ‘add bootstrap modal after login in wordpress’ is closed to new replies.