Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#43699 closed defect (bug) (worksforme)

if i remove image from a post > wp-json return it again as a media

Reported by: adalenv's profile adalenv Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9.4
Component: REST API Keywords:
Focuses: rest-api Cc:

Description

i got this response from

wp-json/wp/v2/media?parent=7 but i have deleted image from post and from media:

[
    {
        "id": 19,
        "date": "2018-04-04T09:16:41",
        "date_gmt": "2018-04-04T09:16:41",
        "guid": {
            "rendered": "http://example.com/wp-content/uploads/2018/04/a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646.png"
        },
        "modified": "2018-04-04T09:16:41",
        "modified_gmt": "2018-04-04T09:16:41",
        "slug": "a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646",
        "status": "inherit",
        "type": "attachment",
        "link": "http://example.com/2018/04/04/lorem-ipsum-dolor-sit-amet-consectetur-adipisicing-elit-minus-dicta-ad-explicabo-ipsa-repellat-atque-dolore-voluptatibus-doloribus-a-molestias/a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646/",
        "title": {
            "rendered": "a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646"
        },
        "author": 1,
        "comment_status": "open",
        "ping_status": "closed",
        "template": "",
        "meta": [],
        "description": {
            "rendered": "<p class=\"attachment\"><a href='http://example.com/wp-content/uploads/2018/04/a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646.png'><img width=\"75\" height=\"17\" src=\"http://example.com/wp-content/uploads/2018/04/a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646.png\" class=\"attachment-medium size-medium\" alt=\"\" /></a></p>\n"
        },
        "caption": {
            "rendered": ""
        },
        "alt_text": "",
        "media_type": "image",
        "mime_type": "image/png",
        "media_details": {
            "width": 75,
            "height": 17,
            "file": "2018/04/a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646.png",
            "sizes": {},
            "image_meta": {
                "aperture": "0",
                "credit": "",
                "camera": "",
                "caption": "",
                "created_timestamp": "0",
                "copyright": "",
                "focal_length": "0",
                "iso": "0",
                "shutter_speed": "0",
                "title": "",
                "orientation": "0",
                "keywords": []
            }
        },
        "post": 17,
        "source_url": "http://example.com/wp-content/uploads/2018/04/a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646.png",
        "_links": {
            "self": [
                {
                    "href": "http://example.com/wp-json/wp/v2/media/19"
                }
            ],
            "collection": [
                {
                    "href": "http://example.com/wp-json/wp/v2/media"
                }
            ],
            "about": [
                {
                    "href": "http://example.com/wp-json/wp/v2/types/attachment"
                }
            ],
            "author": [
                {
                    "embeddable": true,
                    "href": "http://example.com/wp-json/wp/v2/users/1"
                }
            ],
            "replies": [
                {
                    "embeddable": true,
                    "href": "http://example.com/wp-json/wp/v2/comments?post=19"
                }
            ]
        }
    }
]

Change History (8)

#1 @adalenv
6 years ago

  • Severity changed from normal to major

#2 @soulseekah
6 years ago

  • Keywords reporter-feedback added
  • Severity changed from major to normal

Welcome to Trac, @adalenv! :)

I was unable to reproduce this on a fresh installation of WordPress.

Steps I took:

  1. Create a post.
  2. Insert an image (upload).
  3. Request /wp-json/wp/v2/media\?parent=2225. Result: see the uploaded media.
  4. Go to Dashboard / Media and delete the uploaded image.
  5. Request /wp-json/wp/v2/media\?parent=2225. Result: [] empty array

Do you perhaps have page caching plugins? Persistent object caching?

#3 @adalenv
6 years ago

no i got image url instead of empty array
di have no plugin

[
    {
        "id": 19,
        "date": "2018-04-04T09:16:41",
        "date_gmt": "2018-04-04T09:16:41",
        "guid": {
            "rendered": "http://example.com/wp-content/uploads/2018/04/a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646.png"
        },
        "modified": "2018-04-04T09:16:41",
        "modified_gmt": "2018-04-04T09:16:41",
        "slug": "a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646",
        "status": "inherit",
        "type": "attachment",
        "link": "http://example.com/2018/04/04/lorem-ipsum-dolor-sit-amet-consectetur-adipisicing-elit-minus-dicta-ad-explicabo-ipsa-repellat-atque-dolore-voluptatibus-doloribus-a-molestias/a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646/",
        "title": {
            "rendered": "a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646"
        },
        "author": 1,
        "comment_status": "open",
        "ping_status": "closed",
        "template": "",
        "meta": [],
        "description": {
            "rendered": "<p class=\"attachment\"><a href='http://example.com/wp-content/uploads/2018/04/a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646.png'><img width=\"75\" height=\"17\" src=\"http://example.com/wp-content/uploads/2018/04/a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646.png\" class=\"attachment-medium size-medium\" alt=\"\" /></a></p>\n"
        },
        "caption": {
            "rendered": ""
        },
        "alt_text": "",
        "media_type": "image",
        "mime_type": "image/png",
        "media_details": {
            "width": 75,
            "height": 17,
            "file": "2018/04/a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646.png",
            "sizes": {},
            "image_meta": {
                "aperture": "0",
                "credit": "",
                "camera": "",
                "caption": "",
                "created_timestamp": "0",
                "copyright": "",
                "focal_length": "0",
                "iso": "0",
                "shutter_speed": "0",
                "title": "",
                "orientation": "0",
                "keywords": []
            }
        },
        "post": 17,
        "source_url": "http://example.com/wp-content/uploads/2018/04/a5d13887-7884-4b2b-b7fc-efa111e2b024_image5667478565766995646.png",
        "_links": {
            "self": [
                {
                    "href": "http://example.com/wp-json/wp/v2/media/19"
                }
            ],
            "collection": [
                {
                    "href": "http://apolonia.al/wp-json/wp/v2/media"
                }
            ],
            "about": [
                {
                    "href": "http://example.com/wp-json/wp/v2/types/attachment"
                }
            ],
            "author": [
                {
                    "embeddable": true,
                    "href": "http://example.com/wp-json/wp/v2/users/1"
                }
            ],
            "replies": [
                {
                    "embeddable": true,
                    "href": "http://example.com/wp-json/wp/v2/comments?post=19"
                }
            ]
        }
    }
]

#4 @soulseekah
6 years ago

That is weird. I can't reproduce it in any way. Is this on the nightly version of WordPress?

#5 @adalenv
6 years ago

what you mean nightly version
im new to wordpress
im not able to fix this

#6 @soulseekah
6 years ago

The nightly build can be retrieved from here https://wordpress.org/nightly-builds/wordpress-latest.zip

When testing make sure you're using the default theme, and absolutely no active plugins.

Also, please show the HTTP response headers.

And, can you please show a request to /wp-json/wp/v2/media?parent=X, where parent is some non-existing number?

Thanks.

#7 @adalenv
6 years ago

where parent is some non-existing number i got an empty array

#8 @danielbachhuber
6 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Hi @adalenv,

It seems like this issue might be specific to your WordPress installation. Feel free to pop into the #core-restapi channel if you'd like further assistance debugging.

Note: See TracTickets for help on using tickets.