Skip to content

Overloaded Relationship properties can't be checked with isset #1049

@acrobertson

Description

@acrobertson

Bug Description

The majority of properties on the Cloudinary\Relate\Relationship class are undeclared and accessible through the magic __get() method.

If you check for the existence of one of these properties, e.g., public_id, using isset(), it will return false, even if it is in fact set.

This is because there is no magic __isset() method in the class.

This is impacting me because I am building a Timber theme where I've extended its Attachment class with a cloudinary_relationship method that calls the static \Cloudinary\Relate\Relationship::get_relationship() method to make that relationship data available to all attachment posts.

But in a Twig template, only the declared properties (e.g., post_id, save_on_shutdown, etc.) are accessibile. Using dot notation to access cloudinary_relationship.public_id returns null. This is because under the hood Twig is calling isset() (and by extension __isset()) to verify the existence of the property. Without the magic __isset() method, it returns false, and I'm not able to access any of the overloaded properties within Twig templates.

Expected Behaviour

The Cloudinary\Relate\Relationship class should include an __isset() method.

Steps to reproduce

Assumptions:

  1. Cloudinary plugin is active
  2. An attachment post with id 92 exists
  3. Attachment 92 has been synced to Cloudinary
$post_id = 92;
$cloudinary_relationship = \Cloudinary\Relate\Relationship::get_relationship($post_id);

echo $cloudinary_relationship->public_id;
// Prints `wordpress_assets/title-of-image`
// So we know this property is set.

isset($cloudinary_relationship->public_id);
// Returns `false`.
// It should return `true`

I have confirmed that repeating these steps with an __isset() method returns true as expected.

I don't see any contribution guidelines in this repo, but since it's such a straightforward update, I'll go ahead and follow this issue up with a PR for you to review in case you are open to contributions.

Additional context

  • WordPress version: 6.8.1
  • Plugin version: 3.2.7
  • Gutenberg plugin version (if applicable): N/A
  • PHP version: 8.2
  • Plugin settings: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions