pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.07k stars 265 forks source link

CPT disable "Editor" don't send post_id by "upload type custom field" #7316

Open datgausaigon opened 4 months ago

datgausaigon commented 4 months ago

Description

I need to create a Custom Post Type (CPT) with "Editor" having to be "Disabled".

Screenshot 2024-06-21 at 19 57 00

This CTP has other Custom Fields, and has an Upload Image Custom Field (Pods Image Field). And I need to programmatically handle uploading images to CPT with Custom Filed via Hook-Filter "wp_handle_upload_prefilter". If a CPT has Enable Editor then I can get the post_id in Hook-Filter "wp_handle_upload_prefilter" with code like this:

$post_id = intval( $_REQUEST['post_ID'] ?? $_REQUEST['post_id'] ?? $_REQUEST['post'] ?? 0 );

But if Editor is "Disabled", $post_id will be 0 with the above code.

I tried logging debug with the code: error_log( print_r( $_REQUEST, true ) );

Then in the log I get an array of:

[June 21, 2024 12:30:53 UTC] Array
(
 [name] => sample-image.jpg
 [action] => upload-attachment
 [_wpnonce] => 4fe6647c28
)

If I ENABLE "Editor" I can get $post_id as well. The log will be:

[21-Jun-2024 13:05:54 UTC] Array
(
    [name] => sample-image.jpg
    [action] => upload-attachment
    [_wpnonce] => 4fe6647c28
    [post_id] => 6544
)

So is there now a way for me to get the post_id when a CTP disable "Editor"?

Thanks ❤️

Version

3.2.2

sc0ttkclark commented 3 months ago

Can you provide a package of your configuration (Pods Admin > Migrate Packages) using the Migrate Packages component (Pods Admin > Components)? That might help us to see if we can reproduce the issue.

I'm unable to reproduce this issue with only Title + Quick Edit enabled like in your screenshot. I see the argument coming through both $_REQUEST and $_POST as post_id.

Here's my debug output:

  ["$_REQUEST"]=>
  array(4) {
    ["name"]=>
    string(10) "banner.png"
    ["action"]=>
    string(17) "upload-attachment"
    ["_wpnonce"]=>
    string(10) "xxxxxxx"
    ["post_id"]=>
    string(4) "9674"
  }
  ["$_POST"]=>
  array(4) {
    ["name"]=>
    string(10) "banner.png"
    ["action"]=>
    string(17) "upload-attachment"
    ["_wpnonce"]=>
    string(10) "xxxxxxx"
    ["post_id"]=>
    string(4) "9674"
  }
sc0ttkclark commented 3 months ago

I see post_id coming through regardless of whether I use the Plupload or Media Library uploader.

datgausaigon commented 3 months ago

Hi @sc0ttkclark ❤️

Thank you very much for your attention to my problem. I would like to send you export json Pods for this Issue. pods-package-2024-07-16.json