What is ABSPATH in WordPress and How to Use it for Security

ABSPATH is a PHP constant, which holds the Absolute path to the WordPress directory.

It is defined in wp-config.php

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
	define( 'ABSPATH', __DIR__ . '/' );
}

ABSPATH for Security

You can place it on top of a plugin or theme to prevent direct access to these files (from the URL):

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}