Skip to content

fix: replace deprecated get_terms() form and tag WP 6.4 conditional - #3199

Closed
faisalahammad wants to merge 2 commits into
gocodebox:devfrom
faisalahammad:fix/deprecated-get-terms-and-wp64-compat
Closed

fix: replace deprecated get_terms() form and tag WP 6.4 conditional#3199
faisalahammad wants to merge 2 commits into
gocodebox:devfrom
faisalahammad:fix/deprecated-get-terms-and-wp64-compat

Conversation

@faisalahammad

Copy link
Copy Markdown
Contributor

Summary

Fixes Plugin Check warnings for deprecated WordPress function signatures in two files. The get_terms() calls in the course options meta box were using the legacy two-argument string form removed in WP 4.5.0, and the traverse_and_serialize_blocks() reference in the block templates class needs a phpcs:ignore for the WP 6.4.0 minimum requirement (plugin minimum is 5.9.0). No behavior change.

Changes

includes/admin/post-types/meta-boxes/class.llms.meta.box.course.options.php

Before:

$course_tracks_options = get_terms( 'course_track', 'hide_empty=0' );
// ...
$difficulty_terms   = get_terms( 'course_difficulty', 'hide_empty=0' );

After:

$course_tracks_options = get_terms( array( 'taxonomy' => 'course_track', 'hide_empty' => false ) );
// ...
$difficulty_terms   = get_terms( array( 'taxonomy' => 'course_difficulty', 'hide_empty' => false ) );

Why: get_terms() deprecated the second string argument in WP 4.5.0. Modern form takes a single array of args. Same taxonomy, same empty-term inclusion, just the supported signature.

includes/class-llms-block-templates.php

Before:

$template->content = function_exists( 'traverse_and_serialize_blocks' ) ?
    traverse_and_serialize_blocks( parse_blocks( $template_content ), '_inject_theme_attribute_in_template_part_block' ) :
    _inject_theme_attribute_in_block_template_content( $template_content );

After:

// phpcs:ignore WordPress.WP.RequiresWP -- Fallback to deprecated _inject_theme_attribute_in_block_template_content() handled below for WP < 6.4.0.
$template->content = function_exists( 'traverse_and_serialize_blocks' ) ?
    traverse_and_serialize_blocks( parse_blocks( $template_content ), '_inject_theme_attribute_in_template_part_block' ) :
    _inject_theme_attribute_in_block_template_content( $template_content );

Why: traverse_and_serialize_blocks() requires WP 6.4.0 but the plugin supports WP 5.9.0+. The existing function_exists() guard plus fallback to _inject_theme_attribute_in_block_template_content() already handles older WP. The annotation tells PHPCS the conditional is intentional.

Testing

  1. Open a course in WP admin → Course Options meta box loads with all course tracks and difficulties listed.
  2. Create a new course with no tracks assigned → empty list renders without errors.
  3. On WP 5.9, 6.0, 6.3 (or any sub-6.4): load a LifterLMS block template (e.g. a Single Course page with the LifterLMS theme template). Page renders using the legacy fallback path.
  4. On WP 6.4+: same template renders via traverse_and_serialize_blocks().

Build

No JS or CSS changes. No build artifact needed.

Validation

php -l includes/admin/post-types/meta-boxes/class.llms.meta.box.course.options.php
php -l includes/class-llms-block-templates.php
vendor/bin/phpcs --standard=phpcs.xml <both files>
vendor/bin/phpcs --standard=phpcs.xml --sniffs=WordPress.WP.DeprecatedParameters,WordPress.WP.RequiresWP <both files>

All clean. 0 errors on both files. The 3 Plugin Check findings are gone.

Files

  • includes/admin/post-types/meta-boxes/class.llms.meta.box.course.options.php (2 lines)
  • includes/class-llms-block-templates.php (1 line annotation)
  • .changelogs/3199.yml

…ional

- course.options.php: collapse get_terms( 'tax', 'hide_empty=0' ) to
  single-argument array form (deprecated since WP 4.5.0).
- class-llms-block-templates.php: add phpcs:ignore for the
  WordPress.WP.RequiresWP sniff on the traverse_and_serialize_blocks()
  call. Existing function_exists() fallback to
  _inject_theme_attribute_in_block_template_content() preserved for
  WP 5.9 -> 6.3.

Plugin Check report: lifterlms-lifterlms-php-20260618-170100.md
Fixes WordPress.WP.DeprecatedParameters.Get_termsParam2Found (2 sites)
and wp_function_not_compatible_with_requires_wp (1 site).
@faisalahammad
faisalahammad requested a review from brianhogg as a code owner June 19, 2026 05:49
@brianhogg brianhogg moved this to Awaiting Review in Development Jun 19, 2026
@brianhogg

Copy link
Copy Markdown
Contributor

There's no indication that behaviour will be removed. I'm good to leave as-is for now unless we're forced to change it, and avoid the adding of a phpcs:ignore.

@brianhogg brianhogg closed this Jul 20, 2026
@github-project-automation github-project-automation Bot moved this from Awaiting Review 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