Forum Replies Created

Viewing 15 replies - 1 through 15 (of 22 total)
  • Thread Starter czcsabi

    (@czcsabi)

    I understand. As an other customization would there be a possibility to write a filter in functions.php for the dynamically generated javascript to be included only on the login/registration page?

    Thread Starter czcsabi

    (@czcsabi)

    Thank you for your prompt answer. You are right. It would be probably a micro enhancement.

    Thread Starter czcsabi

    (@czcsabi)

    Thank you.

    Interesting that there is also an other error which get`s generated in the site root directory, at every backup attempt:

    PHP Fatal error: Cannot redeclare wp_unregister_globals() in .../wp-includes/load.php on line 18

    I have run a text search to see if there is any duplicate function being called but found nothing. So it could be a looping problem.

    It shouldn`t be an out of memory problem, because my whole sql database is less than 30 MB, and until recently I could successfully make backups with All in One Security plugin. If I use the adminer plugin also from wp-admin the export finishes without problems.I will have to look into this in greater depth.

    I see the same problem on my site also. After trying to generate a backup, I get the following php error in the wp-admin folder:

    PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 256 bytes) in .../wp-includes/wp-db.php on line 2221

    After researching this error it seems it is an indicator of an infinite loop.

    My users have also requested to be shown their past statistics as well. It shouldn`t be that hard to refine the statistics function so that non-admins can see only their own past results in the admin area.
    Unfortunately the complex design of this plug-in prevents me from making the necessary adjustments.

    It would the a much appreciated feature though.

    Best Regards,
    Csaba

    Hi Jeff,
    I can confirm that after the latest update (3.2.6) the error has gone away and W3 cache is acting normally again. Thank you for your efforts.

    Im also using W3 Total Cache and can confirm the error messages. Also plugin order and plugin deactivation arent working.

    Thread Starter czcsabi

    (@czcsabi)

    For the wp_delete_user function to properly work I had to include the user.php file like so:
    require_once( ABSPATH.’wp-admin/includes/user.php’ );
    The modified code is:

    add_action('mydailyclearout', 'deleteinactiveusers');
    
    function my_activation() {
    if( !wp_next_scheduled( 'mydailyclearout' ) ) {
     wp_schedule_event(time(), 'daily', 'mydailyclearout');
     }
    }
    
    add_action('wp', 'my_activation');
    
    function deleteinactiveusers() {
    	  $days = 60; // days without login
    	  $meta_value = time() - ($days * 24 * 60 * 60);
    	  $user_query = new WP_User_Query(
    	    array(
    			'meta_key'       => 'wp-last-login',
    			'meta_value'     => $meta_value,
    			'meta_compare'   => '<',
    			'meta_type'      => 'NUMERIC'
    		    )
    	     );
    
      	  $users = $user_query->results;
         if (!empty($users)){
            require_once( ABSPATH.'wp-admin/includes/user.php' ); // this had to be added for the wp_delete_user function to work properly
    	foreach( $users as $user ) {
    	 if ($user->roles[0] =="subscriber"){	// only delete subscribers
              $user_email = stripslashes($user->user_email);
    	  $user_name = $user->user_login;
    	  $headers = array("Content-Type: text/html; charset=UTF-8");
    	  wp_mail($user_email, $user_name . " unused account deleted",'Your unused account <strong>' . $user_name . '</strong> has been deleted.',$headers); // send an email notification
              wp_delete_user($user->ID); // delete the user
    	 }
    	}
           }
    
      $days=50; // you can even send a notification several days before for their consideration
    	  $meta_value1 = time() - ($days * 24 * 60 * 60);
    	  $meta_value2 = time() - (($days+1) * 24 * 60 * 60);
    	  $user_query = new WP_User_Query(
    	    array(
    			'meta_key'       => 'wp-last-login',
    			'meta_value'     => array($meta_value2,$meta_value1),
    			'meta_compare'   => 'BETWEEN',
    			'meta_type'      => 'NUMERIC'
    		    )
    	     );
    
      	  $users = $user_query->results;
         if (!empty($users)){
           foreach( $users as $user ) {
    	 if ($user->roles[0] =="subscriber"){
    	  $user_email = stripslashes($user->user_email);
    	  $user_name = $user->user_login;
    	  $headers = array("Content-Type: text/html; charset=UTF-8");
    	  wp_mail($user_email, "Important! ". $user_name . " account is scheduled to be deleted",'More then ' . $days . ' have passed since your last login with <strong>' . $user_name . '</strong> username. If you dont login in several days your account will be deleted',$headers); // send notification email
    	 }
           }
       }
    }

    Thread Starter czcsabi

    (@czcsabi)

    You can even schedule a daily automatic delete of unused accounts, specifying the max. days without login, like so (to be put in functions.php):

    add_action('mydailyclearout', 'deleteinactiveusers');
    
    function my_activation() {
    if( !wp_next_scheduled( 'mydailyclearout' ) ) {
     wp_schedule_event(time(), 'daily', 'mydailyclearout');
     }
    }
    
    add_action('wp', 'my_activation');
    
    function deleteinactiveusers() {
    	  $days = 60; // days without login
    	  $meta_value = time() - ($days * 24 * 60 * 60);
    	  $user_query = new WP_User_Query(
    	    array(
    			'meta_key'       => 'wp-last-login',
    			'meta_value'     => $meta_value,
    			'meta_compare'   => '<',
    			'meta_type'      => 'NUMERIC'
    		    )
    	     );
    
      	  $users = $user_query->results;
         if (!empty($users)){
    	foreach( $users as $user ) {
    	 if ($user->roles[0] =="subscriber"){	// only delete subscribers
              $user_email = stripslashes($user->user_email);
    	  $user_name = $user->user_login;
    	  $headers = array("Content-Type: text/html; charset=UTF-8");
    	  wp_mail($user_email, $user_name . " unused account deleted",'Your unused account <strong>' . $user_name . '</strong> has been deleted.',$headers); // send an email notification
              wp_delete_user($user->ID); // delete the user
    	 }
    	}
           }
    
      $days=50; // you can even send a notification several days before for their consideration
    	  $meta_value1 = time() - ($days * 24 * 60 * 60);
    	  $meta_value2 = time() - (($days+1) * 24 * 60 * 60);
    	  $user_query = new WP_User_Query(
    	    array(
    			'meta_key'       => 'wp-last-login',
    			'meta_value'     => array($meta_value2,$meta_value1),
    			'meta_compare'   => 'BETWEEN',
    			'meta_type'      => 'NUMERIC'
    		    )
    	     );
    
      	  $users = $user_query->results;
         if (!empty($users)){
           foreach( $users as $user ) {
    	 if ($user->roles[0] =="subscriber"){
    	  $user_email = stripslashes($user->user_email);
    	  $user_name = $user->user_login;
    	  $headers = array("Content-Type: text/html; charset=UTF-8");
    	  wp_mail($user_email, "Important! ". $user_name . " account is scheduled to be deleted",'More then ' . $days . ' have passed since your last login with <strong>' . $user_name . '</strong> username. If you dont login in several days your account will be deleted',$headers); // send notification email
    	 }
           }
       }
    }

    I`m using this with success on my site, but for security you should test it out first on a nonproduction site first.
    On a side note, this won`t list/delete those users to have never logged in or only before first plugin activation. For them you have to do the job manually.

    Thread Starter czcsabi

    (@czcsabi)

    The code above, when pasted into your functions.php file does the exact same thing … it makes the login date column sortable.

    Thread Starter czcsabi

    (@czcsabi)

    A bit dirtier working alternative I`ve come up with is:

    add_action('pre_user_query','wpse_27518_pre_user_query');
    function wpse_27518_pre_user_query($user_search) {
        global $wpdb,$current_screen;
    
        if ( 'users' != $current_screen->id )
            return;
    
        $vars = $user_search->query_vars;
    
        if('wp-last-login' == $vars['orderby'])
        {
            $user_search->query_from .= " INNER JOIN {$wpdb->usermeta} m1 ON {$wpdb->users}.ID=m1.user_id AND (m1.meta_key='wp-last-login')";
            $user_search->query_orderby = ' ORDER BY UPPER(m1.meta_value) '. $vars['order'];
        }
    }

    Thread Starter czcsabi

    (@czcsabi)

    No. Seemingly it`s not a plugin conflict, because on a smaller site with 4 users (with different login dates) even if I deactivate all plugins (Cimy included), the sort is taking place for the user names.

    Thread Starter czcsabi

    (@czcsabi)

    Yes I have Cimy User Extra Fields.

Viewing 15 replies - 1 through 15 (of 22 total)