Guest User

Funciones / functions

a guest
Jan 16th, 2021
92
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Close session when clicking, avoid confirmation.
  2. function add_logout_url_nonce($items){
  3.   foreach($items as $item){
  4.     if( $item->url == '/wp_login.php/?action=logout'){
  5.          $item->url = $item->url . '?redirect_url=/&_wpnonce=' . wp_create_nonce( 'log-out' );
  6.     }
  7.   }
  8.   return $items;
  9.  
  10. } add_filter('wp_nav_menu_objects', 'add_logout_url_nonce');
  11.  
  12.  
  13.  
  14.  
  15. //Logout in a link
  16.  function custom_logout_link_func() {
  17.             $return = wp_logout_url();?>
  18.             <a href="<?php echo $return; ?>" class="btn btn-primary btn-xs btn-block" role="button" style="margin-bottom: 10px;">Logout</a>
  19.             <?php
  20.         }
  21.          
  22.     add_shortcode('logout_link', 'custom_logout_link_func');
  23.  
  24.  
  25.  
  26.  
  27. //Redirect after Logout
  28. function logout_page() {
  29.     $login_page  = home_url();
  30.     wp_redirect( $login_page . "" );
  31.     exit;
  32. }
  33. add_action('wp_logout','logout_page');
RAW Paste Data