What are the differences between WPINC and ABSPATH?

It’s common for plugin developers to protect their plugins from direct access. I saw two ways to do that:

if ( ! defined( 'WPINC' ) ) die;

and

if ( ! defined( 'ABSPATH' ) ) exit;

What are the differences between WPINC and ABSPATH? Which one is the ‘right’ way to do it?

3

They are defined as follows:

define( 'ABSPATH', dirname(dirname(__FILE__)) . "https://wordpress.stackexchange.com/" );
define( 'WPINC', 'wp-includes' );

dirname is a PHP function that returns the path of the parent directory, and wp-includes is pretty self explanatory.

I would say ABSPATH is better because it’s one of the first things WP loads and it also looks better:) But there is no real “right way” because they both work.

Leave a Comment