Skip to content

fix: add ABSPATH direct access protection to 15 PHP files#3198

Merged
brianhogg merged 3 commits into
gocodebox:devfrom
faisalahammad:fix/abspath-direct-access-protection
Jul 20, 2026
Merged

fix: add ABSPATH direct access protection to 15 PHP files#3198
brianhogg merged 3 commits into
gocodebox:devfrom
faisalahammad:fix/abspath-direct-access-protection

Conversation

@faisalahammad

Copy link
Copy Markdown
Contributor

Summary

Plugin Check flagged 15 PHP files missing the standard defined( 'ABSPATH' ) || exit; direct access protection. Adds the guard to builder view templates, the access plan dialog, and the order view function file. No business logic changed.

Changes

Builder view templates (13 files)

Inserts the ABSPATH guard after the file docblock, before the closing ?>:

Before:

<?php
/**
 * Builder lesson model view
 *
 * @since 3.16.0
 * @version 7.2.0
 */
?>
<script type="text/html" id="tmpl-llms-lesson-template">

After:

<?php
/**
 * Builder lesson model view
 *
 * @since 3.16.0
 * @version 7.2.0
 */
defined( 'ABSPATH' ) || exit;
?>
<script type="text/html" id="tmpl-llms-lesson-template">

Files: lesson.php, elements.php, question.php, question-type.php, editor.php, section.php, course.php, utilities.php, question-choice.php, assignment.php, sidebar.php, lesson-settings.php, quiz.php.

Access plan dialog template

The file contains no <?php opener, so the guard wraps the existing markup at the top of the file:

Before:

<div
	id="llms-access-plan-dialog"

After:

<?php defined( 'ABSPATH' ) || exit; ?>
<div
	id="llms-access-plan-dialog"

Order view function file

The guard sits between the file docblock and the function definition wrapper:

Before:

 * @since 6.0.0
 * @version 6.0.0
 */

if ( ! function_exists( 'llms_template_view_order' ) ) {

After:

 * @since 6.0.0
 * @version 6.0.0
 */

defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'llms_template_view_order' ) ) {

Why: Plugin Check rejects any PHP file under includes/, libraries/, or the plugin root that can be reached via a direct HTTP request without first going through the WordPress bootstrap. The one-liner is the standard pattern already used across the rest of the codebase (see includes/admin/views/access-plans/access-plan.php, includes/admin/views/dashboard.php, includes/functions/llms-functions-*.php).

Skipped

Two flagged files already have an equivalent guard and were not modified:

  • libraries/lifterlms-cli/src/commands.php (uses defined( 'ABSPATH' ) || exit;)
  • libraries/lifterlms-rest/uninstall.php (uses defined( 'ABSPATH' ) || exit;)

Testing

  1. Run php -l on all 15 modified files: no syntax errors.
  2. Run ./vendor/bin/phpcs --standard=phpcs.xml on all 15 files: exit 0, no warnings or errors.
  3. Spot-check one builder template (includes/admin/views/builder/lesson.php) in the WP admin Course Builder screen: lesson list renders normally.
  4. Spot-check the access plan dialog (includes/admin/views/access-plans/access-plan-dialog.php) in a course's access plan metabox: dialog opens and closes as before.

Build

No new build artifacts. Source-only change.

@faisalahammad
faisalahammad requested a review from brianhogg as a code owner June 19, 2026 05:28
@brianhogg brianhogg moved this to Awaiting Review in Development Jun 19, 2026
Plugin Check flagged 15 files missing the standard WordPress direct
file access guard. Adds the standard 'defined( "ABSPATH" ) || exit;'
check to:

- 13 builder view templates under includes/admin/views/builder/
- 1 access plan dialog template (access-plan-dialog.php)
- 1 order view function file (llms-functions-template-view-order.php)

No business logic changes. Two files (libraries/lifterlms-cli/src/commands.php,
libraries/lifterlms-rest/uninstall.php) already had the guard.

PHP lint and PHPCS pass on all modified files.
@faisalahammad
faisalahammad force-pushed the fix/abspath-direct-access-protection branch from a7b84e8 to 299beaa Compare June 19, 2026 05:31
Comment thread .changelogs/3198.yml Outdated
@github-project-automation github-project-automation Bot moved this from Awaiting Review to To do in Development Jul 16, 2026
@brianhogg brianhogg moved this from To do to Review in Progress in Development Jul 16, 2026
Shorten changelog entry from 28 words to 6 as requested by
reviewer brianhogg.

Refs gocodebox#3198
@brianhogg brianhogg moved this from Review in Progress to Approved in Development Jul 17, 2026
@brianhogg
brianhogg merged commit 453d3e9 into gocodebox:dev Jul 20, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in Development Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants