Show Last login Time Of User In WordPress

How to display Quickly a WordPress user’s last login with custom code . Actually some time  we need to know our active users of site. so we can differentiate which user hasn’t logged in for a while. This is combination  4-5 hooks. 1: First we can use wp_login hook for saving login time and date. <?php //Record user’s last login to custom meta field add_action( ‘wp_login’, ‘custum_wp_login’, 10, 2 ); function custum_wp_login( $user_login, $user ) { update_user_meta( $user->ID, ‘custum_last_login’, date(‘Y-m-d H:i:s’)); }   2: Second we need to add column in user table to show last login <?php //Register new custom column with last login time add_filter( ‘manage_users_columns’, ‘custum_manage_users_columns’); add_filter(‘manage_users_custom_column’, ‘custum_manage_users_custom_column’, 10, 3); function custum_manage_users_columns( $columns ) { $columns[‘custum_last_login’] = __(‘Last login’, ‘last_login’); return $columns; } function custum_manage_users_custom_column( $value, $column_name, $user_id ) { if ( ‘custum_last_login’ == $column_name){ $last_login = get_user_meta( $user_id, ‘custum_last_login’, true ); $value = date(“g:i a –

How To Get the client IP address using PHP

To get the client’s IP address using PHP, you can use the `$_SERVER` superglobal variable. Here’s an example of how you can retrieve the client’s IP address: // Get the client IP address $client_ip = $_SERVER[‘REMOTE_ADDR’]; // Display the client IP address echo ‘Client IP Address: ‘ . $client_ip;   In this example, `$_SERVER[‘REMOTE_ADDR’]` retrieves the IP address of the client making the request to your PHP script. Please note that the `REMOTE_ADDR` value in the `$_SERVER` superglobal may not always provide the actual client IP address. In some cases, if your server is behind a proxy or load balancer, it may return the IP address of the proxy or load balancer. To handle such cases, you can consider using other headers like `HTTP_X_FORWARDED_FOR` or `HTTP_CLIENT_IP` to get the correct client IP address. Here’s an example that shows how to check for forwarded IP headers:   // Get the client

Add Custom Product Data Tab

Learn how to enhance your WooCommerce product editor by adding a custom product data tab. Follow a step-by-step guide using the woocommerce_product_data_tabs filter and the woocommerce_product_data_panels action. Create a custom tab with your desired label, and include your own fields or content within the panel. Customize your product data to collect and display additional information, providing a tailored experience for your WooCommerce products.

How to know “Who created this coupon?”

What to do when your client ask “Who created this coupon?” . in WooCommerce.  But we don’t have any default things in WooCommerce  which automatically show author of coupon .

How To Add Menu In WordPress Admin Panel

How to add menu in WordPress admin panel – In this post we see how we can add custom menu to admin sidebar. Sometimes when we on WordPress and we need to show some features or any information in admin page then we can use this code snippet to create the same.

How To Limit Search To Post Titles?

I added a text field to the posts filter form and I use s= parameter to make the search work. But how to search only in the title of the post (not in the content)? how to limit search to post titles? How to search only by Post Title?

How To Customize/Replace WordPress Post Excerpts

Example: Sometime we need to show content on frontend with adding some prefix or suffix or may be you have enter spelling mistakes in 2000 posts. so it is very difficult to modify 2000 posts so we can modify using filter . SO mistake will be replaced by correction.   For Modifying post content only:   function link_words( $text ) { $replace = ‘Replace with’; $text = str_replace( ‘Want To replace text’, $replace, $text ); return $text; } add_filter( ‘the_content’, ‘link_words’ );   For Modifying post excerpt only   function link_words( $text ) { $replace = ‘Replace with’; $text = str_replace( ‘Want To replace text’, $replace, $text ); return $text; } add_filter( ‘the_excerpt’, ‘link_words’ );   For Modifying post content and excerpt both   function link_words( $text ) { $replace = ‘Replace with’; $text = str_replace( ‘Want To replace text’, $replace, $text ); return $text; } add_filter( ‘the_content’, ‘link_words’ );

Categories