Wordpress - What are the differences between WPINC and ABSPATH?
They are defined as follows:
define( 'ABSPATH', dirname(dirname(__FILE__)) . '/' );
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.
if ( ! defined( 'WPINC' ) ) die;
and if ( ! defined( 'ABSPATH' ) ) exit;
add an extra layer of security by preventing any direct access to your plugin file. ABSPATH
is a PHP constant defined by WordPress in its core.
If your plugin file is accessed from outside of WordPress, the constant ABSPATH
or WPINC
will not be defined, so it exits the plugin code, preventing any unauthorized access to your code.
ABSPATH
and WPINC
are defined in WordPress core as:
define( 'ABSPATH', dirname(dirname(__FILE__)) . '/' );
define( 'WPINC', 'wp-includes' );
Both are used for same purpose.