[Résolu] Debug error in wp-admin relating to images (Types 3.3)
Ce fil est résolu. Voici une description du problème et la solution proposée.
Problem:
A "Trying to get property of non-object..." error appears on post edit screens with related posts containing image fields.
Solution:
The client was using custom code to delete the attachment post entries from wp_posts. While not required it was unexpected, and producing the error. This has now been fixed.
This support ticket is created Il y a 5 années et 6 mois. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
Since upgrading to WordPress 5.2 and Types 3.3, I'm seeing this error in my debug log and displaying in wp-admin on "child" posts for the related posts that contain images. The error is generated for each image in the post but the content doesn't vary, it's always:-
Notice: Trying to get property of non-object in /home/XXX/public_html/wp-content/plugins/types/vendor/toolset/types/embedded/includes/fields/image.php on line 1273
The images are displayed correctly in wp-admin and on frontend. Not sure if this is relevant but developer tools shows the URL for the image in wp-admin as the main one not the thumbnail even though the thumbnail exists.
I've also noticed that whilst post relationships don't seem to have been removed or changed, when I view the parent post in wp-admin, I'm only seeing the post title and no other field content from the child post whereas when I visit the child post, the field content from the parent post IS displayed.
Can you check if this issue can be replicated your end please?
Also, when I visited Toolset settings to get debug info, this is showing at the top of the page:-
Notice: Undefined property: stdClass::$rules in /home/XXX/public_html/wp-content/plugins/types-access/application/controllers/filters/backend_filters.php on line 330
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+00:00)
Hi Julie
Starting with the second one first, where the child fields are missing when on a parent post edit screen. You can customise which fields appear there with the button that is a cog icon. I found on my site that no fields were selected by default, but that I could choose to display them with that cog.
Now, the other two problems I cannot reproduce.
Have I understood the first correctly?
You have a parent-child relationship. The parent post has image fields (a repeating image field?). When editing a child post, where you can see the parent posts in the relationship metabox, this generates a warning in the debug.log.
I don't see that.
You say that the img URL points to the full sized image not the thumbnail. In my screenshot you can see the src points to the thumbnail, although there is a data-full-src attribute that points to the original full-sized image. You see the src itself pointing to the full-sized image?
I'm probably going to need a copy of your site to try and see the warnings, but let's clarify that I've understood the set-up correctly, first.
Thanks for mentioning the cog/settings option - I've not really noticed it to be honest and all my fields from related posts show by default but I don't now believe there's a problem with this bit.
Yes, you have understood correctly and the image field is not a repeating one.
Since you've not been able to reproduce the problem, I've done some comprehensive testing this morning. Here's what I found:-
I've re-installed my 'pure' single (as opposed to multi site) test site, upgraded everything to the latest and implemented only the absolute basics required to replicate a parent post with image field & child post with just post title. My uploads are not organised by year/month. I'm using two hooks on my main dev site which rename the image and delete the 'attachment' pages created by WordPress. The renaming hook isn't causing a problem but when the attachment pages are deleted (whether the images have been renamed or not), the errors appear.
You may not agree with my approach here but attachment pages won't add anything for this site and I don't want them!! Any suggestions (checking and deleting the content from my debug log all the time would be a real pain in the ****)? Thanks
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+00:00)
OK, that explains a lot.
Adding image fields, whether in the backend or via a frontend form, is essentially the same as adding a featured image or inserting inline images within the content of the post, and involves WordPress creating an attachment post (i.e. a row in wp_posts) corresponding to that image.
It's clear looking at some of the code generating the warnings that Types expects to find these attachment posts, and meaning that removing them will result in unexpected behaviour, namely generating PHP warnings in this case.
I don't have any advice to offer, I simply don't think you can remove those attachment posts, and if you do, well, it means dealing with the consequences.
There haven't been consequences in deleting attachment pages with previous versions of Types. What purpose is served by checking that an attachment page exists as of the current version?
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+00:00)
I can't answer that, but I can say that the error-handling in our code should fail silently in such a scenario.
I've been able to reproduce the warning with Types 3.3 after manually deleting the attachment posts and its post meta, and so I'm passing the details on to the developer to review.
It's well documented that website owners either aren't aware of attachment pages or don't really know what to do with them and that they are low value where SEO is concerned. At best the trend seems to be to redirect attachment pages to the parent so they're not indexed. What we can't get away from (if we don't delete them) is a waste of database resource and time in managing them when images are removed or changed. The latter is particularly true for sites where visitors upload images.
Deleting attachment pages hasn't been an issue to date & the current code makes an unfair assumption. I'll leave it in your capable hands to put forward my case!