User Activity Tracking and Log Shortcode

Below, you’ll find a detailed guide on how to add the User Activity Tracking and Log Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the User Activity Tracking and Log Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the User Activity Tracking and Log Plugin and the shortcodes it provides:

Plugin Icon
User Activity Tracking and Log

"User Activity Tracking and Log is a powerful WordPress plugin that allows you to monitor and record user activities on your site. A perfect tool for comprehensive site management."

★★★☆✩ (25) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [show_ip]

User Activity Tracking and Log [show_ip] Shortcode

The Moove Activity Tracking shortcode is designed to retrieve and display the user’s IP address. It checks various server variables to ensure the most accurate IP is returned. This shortcode can be used to track user activity, helping in security and analytics. It considers shared internet, proxy, and direct connections, ensuring a comprehensive tracking solution.

Shortcode: [show_ip]

Examples and Usage

Basic Example – A simple usage of the ‘show_ip’ shortcode to display the user’s IP address.

[show_ip /]

Advanced Examples

Using the ‘show_ip’ shortcode with a filter attribute. This allows you to modify the IP address before it is displayed. For example, you can use a filter to anonymize the IP address.

[show_ip filter="anonymize_ip" /]

Using the ‘show_ip’ shortcode with a ‘format’ attribute. This allows you to specify the format in which the IP address is displayed. For example, you can use the ‘format’ attribute to display the IP address in hexadecimal format.

[show_ip format="hexadecimal" /]
Please note that the ‘filter’ and ‘format’ attributes are hypothetical and would require additional code to function. They are provided as examples of how you might extend the functionality of the ‘show_ip’ shortcode.

PHP Function Code

In case you have difficulties debugging what causing issues with [show_ip] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'show_ip', array( &$this, 'moove_get_the_user_ip' ) );

Shortcode PHP function:

                    function moove_get_the_user_ip( $filter = true ) {
		if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) && ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) :
			// Check ip from share internet.
			$ip = sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) );
		elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && ! empty( sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) :
			// To check ip is pass from proxy.
			if ( is_array( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) :
				$ip          = explode( ',', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) );
				$remote_addr = isset( $_SERVER['REMOTE_ADDR'] ) && ! empty( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
				$ip          = isset( $ip[0] ) ? $ip[0] : $remote_addr;
			else :
				$ip = isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) : '';
			endif;
		else :
			$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
		endif;

		$ip = ( strpos( $ip, ',' ) > 0 ) ? trim( explode( ',', $ip )[0] ) : $ip;

		return $filter ? apply_filters( 'moove_activity_tracking_ip_filter', $ip ) : $ip;
	}
                    

Code file location:

user-activity-tracking-and-log/user-activity-tracking-and-log/class-moove-activity-shortcodes.php

Conclusion

Now that you’ve learned how to embed the User Activity Tracking and Log Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *