You might see this code in a WordPress plugin. What does it do?

Advertisement

  • This is how WordPress detects a plugin’s presence. This ensures that the plugin is running from the /wp-content/plugins/ directory. If it is not, the plugin should not run.
  • This is a way to prevent naming collisions. ABSPATH is the absolute path to the plugin’s directory. If ABSPATH is defined by another WordPress plugin with the same directory slug, the plugin should not run.
  • This is a security measure. ABSPATH is the absolute path to the WordPress directory. If the file is called directly, ABSPATH will not be defined and therefore the plugin should not run.
  • This is a compatibility checker. ABSPATH is defined in WordPress core. The plugin checks that the minimum version of WordPress needed to support the plugin is installed. If it is not, the plugin should not run.
Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

Leave a Comment


Share via
Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

Send this to a friend