Archives: Snippets
Untitled Snippet
MemberPress: Change Username Field’s Placeholder and/or Label of the Field on Login Page
document.addEventListener(‘DOMContentLoaded’, function() { // Select the input element by its id var usernameInput = document.getElementById(‘user_login’); // Check if the element exists to avoid any potential JavaScript errors if (usernameInput) { // Change the placeholder text usernameInput.placeholder = ‘Username or Email’;…Continue reading
MemberPress: Redirect Users After Login Based on Referrer
// Redirect all users to a specific page after login from a specific login page function custom_mepr_login_redirect_url($url, $user) { // Check the referrer to see if the login request came from a specific page if (isset($_SERVER[‘HTTP_REFERER’])) { $referrer = $_SERVER[‘HTTP_REFERER’];…Continue reading
MemberPress: Redirect Users After Login Based on Roles
// Redirect users after login based on their roles function custom_mepr_login_redirect_url($url, $user) { // Check if the user object is valid if (isset($user->roles) && is_array($user->roles)) { // Roles that should be redirected to the WordPress dashboard $admin_roles = array(‘administrator’, ‘editor’,…Continue reading
MemberPress: Redirect Users After Login Based on Roles
// Redirect users after login based on their roles function custom_mepr_login_redirect_url($url, $user) { // Check if the user object is valid if (isset($user->roles) && is_array($user->roles)) { // Roles that should be redirected to the WordPress dashboard $admin_roles = array(‘administrator’, ‘editor’,…Continue reading
MemberPress: Prevent users from auto-login after registration
function mepr_disable_auto_login($auto_login, $membership_id, $mepr_user) { return false; } add_filter(‘mepr-auto-login’, ‘mepr_disable_auto_login’, 10, 3);Continue reading
MemberPress: Exclude MemberPress Custom Post Types from WordPress Search Results
function exclude_ml_file_from_search( $query ) { // Check if it is not an admin page, is a search query, and is the main query if ( !$query->is_admin && $query->is_search && $query->is_main_query() ) { // Exclude the ‘mpdl-file’ post type from the…Continue reading
custom smart tag full page example
Page TitleContinue reading
Lock users if website is idle for certain period ウェブサイトが一定期間アイドル状態の場合にユーザーをロックするAn updated version.
/** * Lock user out after a period of inactivity with customizable timeout and warning notification. */ // Add settings for inactivity timeout add_action(‘admin_init’, ‘register_inactivity_timeout_setting’); function register_inactivity_timeout_setting() { register_setting(‘general’, ‘inactivity_timeout’, [ ‘type’ => ‘integer’, ‘description’ => ‘Inactivity timeout duration in…Continue reading