HeavenCore
Forum Replies Created
-
hi Chris – for those more comfortable with SQL workbench or PHPMyadmin etc – please can you provide the sql here to create the index as that’s often the easiest way to do so.
e.g. CREATE INDEX index_name ON table_name (column_name(length));
That would be really handy ta.
PS: thank you for maintaining this plugin – it really makes session management behind a load balancer sooooo much easier – in fact – with the popularity of load balancers and the dominance of WordPress I’m kinda amazed they’ve never added this functionality to the core WordPress product.
Proposed fix:
class-session-handler.php
<?php /** * Implementation of 'SessionHandlerInterface' that writes to the database. * * @package WPNPS */ namespace Pantheon_Sessions; use Pantheon_Sessions\Session; /** * Implementation of 'SessionHandlerInterface' that writes to the database. * * @package WPNPS */ class Session_Handler implements \SessionHandlerInterface { /** * Closes the session. * * @param string $save_path Path to where the session is to be stored. * @param string $session_name Name of the session. * @return boolean */ public function open( $save_path, $session_name ):bool { return true; } /** * Writes a session to the database. * * @param string $session_id Session id. * @param string $session_data Session data. * @return boolean */ public function write( $session_id, $session_data ): bool { $session = Session::get_by_sid( $session_id ); if ( ! $session ) { $session = Session::create_for_sid( $session_id ); } if ( ! $session ) { trigger_error( 'Could not write session to the database. Please check MySQL configuration.', E_USER_WARNING ); return false; } $session->set_data( $session_data ); return true; } /** * Reads session data from the database. * * @param string $session_id Session id. * @return string */ public function read( $session_id ): string|false { // Handle the case of first time visitors and clients that don't store // cookies (eg. web crawlers). $insecure_session_name = substr( session_name(), 1 ); if ( empty( $session_id ) || ( ! isset( $_COOKIE[ session_name() ] ) && ! isset( $_COOKIE[ $insecure_session_name ] ) ) ) { return ""; } $session = Session::get_by_sid( $session_id ); if ( $session ) { return $session->get_data(); } else { return false; } } /** * Destroys the session. * * @param string $session_id Session id. */ public function destroy( $session_id ): bool { $session = Session::get_by_sid( $session_id ); if ( ! $session ) { return true; } $session->destroy(); return true; } /** * Runs the garbage collection process. * * @param integer $maxlifetime Maximum lifetime in seconds. */ public function gc( $maxlifetime ): int|false { global $wpdb; $wpdb = Session::restore_wpdb_if_null( $wpdb ); // Be sure to adjust 'php_value session.gc_maxlifetime' to a large enough // value. For example, if you want user sessions to stay in your database // for three weeks before deleting them, you need to set gc_maxlifetime // to '1814400'. At that value, only after a user doesn't log in after // three weeks (1814400 seconds) will his/her session be removed. $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->pantheon_sessions WHERE <code>datetime</code> <= %s ", gmdate( 'Y-m-d H:i:s', time() - $maxlifetime ) ) ); return true; } /** * Closes the session. * * @return boolean */ public function close(): bool { return true; } }
Forum: Plugins
In reply to: validate_password_reset action to firingWell, ended up fixing this after hours of banging my head on keyboard. Fixed by making the first parameter of my hooked function a value instead of a reference – curious when nearly all hooks in wordpress pass the error object by reference!
function validatePasswordReset( &$errors, $userData ) { return validateComplexPassword( $errors ); }
changed to
function validatePasswordReset( $errors, $userData ) { return validateComplexPassword( $errors ); }
PS: Most actions have a reference on the codex, for example:
https://codex.www.ads-software.com/Plugin_API/Action_Reference/user_profile_update_errors
why is there no entry for validate_password_reset?
Forum: Hacks
In reply to: "Show Toolbar when viewing site" & wp_insert_user()cheers bcworkz, tried that but it would not work for love nor money!
Turns out I needed to pass false as a string instead of a boolean, i.e:
update_user_meta( $user_id, 'show_admin_bar_front', 'false' );
instead of:
update_user_meta( $user_id, 'show_admin_bar_front', false );
Just thought id share this in case anyone else runs into the same problem.
Regards
J.