Skip to content

Do not allow the usage of magic properties on WP_Post objects #229

Open
@fklein-lu

Description

@fklein-lu

The WP_Post class offers access to various properties through magic getters:

  • $page_template
  • $ancestors
  • $post_category
  • $tag_input

In addition, post meta can be retrieved by using $post->meta_key.

We should not allow the usage of these coding approaches:

  1. Magic properties are discouraged in the PHP community, because IDEs and other code quality tools cannot understand them.
  2. Since there are reserved keywords, using $post->meta_key does not always return the meta data.
  3. Depending on how the post is instantiated, the meta value will be passed through sanitize_post_field() before being returned.
  4. Meta will always be pulled with $single set to true.

All in all there are no benefits here, and only downsides.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions