$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>theme development - Where i should not use if (!defined('ABSPATH')) { exit; }?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

theme development - Where i should not use if (!defined('ABSPATH')) { exit; }?

matteradmin7PV0评论

I think this best way to prevent direct access..

<?php if (!defined('ABSPATH')) { exit; }?>

i have used this on all my php files..can it create problems? any files on WordPress theme i should not use it?

I think this best way to prevent direct access..

<?php if (!defined('ABSPATH')) { exit; }?>

i have used this on all my php files..can it create problems? any files on WordPress theme i should not use it?

Share Improve this question asked Nov 16, 2018 at 11:12 user145078user145078 1
  • See wordpress.stackexchange/questions/62999/… – fuxia Commented Nov 16, 2018 at 13:50
Add a comment  | 

1 Answer 1

Reset to default 8

The point of that code is to prevent any PHP inside the file from being executed if the file is accessed directly outside a WordPress context. ABSPATH is defined by WordPress, so if it's missing when the file is accessed you can tell that it's not running in a WordPress context.

So the only place you wouldn't use it is in any file that you did need to access directly. There probably shouldn't be any such files in a WordPress theme or plugin. The most common example might be a file for handling AJAX requests, but in WordPress you should be using admin-ajax.php or the REST API for that sort of thing.

Post a comment

comment list (0)

  1. No comments so far