我维护了一个插件,当创建、更新和删除匹配的对象时,它会将选定的WordPress数据发送到外部REST API(本例中为Salesforce)。
例如post
工作原理如下:
add_action( \'save_post\', array( $this, \'post_actions\' ), 11, 2 );
对于自定义帖子类型,其工作原理如下:
add_action( \'save_post_\' . $object_type, array( $this, \'post_actions\' ), 11, 2 );
post_actions
是一种尝试检索所有WordPress字段数据(可以包括自定义字段)然后将其发送到API的方法。
例如,标准的post类型结果如下所示:
首先,它是一个草稿,没有元字段:
[ID] => 600
[post_author] => 1
[post_date] => 2018-04-14 03:02:29
[post_date_gmt] => 0000-00-00 00:00:00
[post_content] =>
[post_title] => test post
[post_excerpt] =>
[post_status] => draft
[comment_status] => open
[ping_status] => open
[post_password] =>
[post_name] =>
[to_ping] =>
[pinged] =>
[post_modified] => 2018-04-14 03:02:29
[post_modified_gmt] => 2018-04-14 03:02:29
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://vanilla-wordpress.test/?p=600
[menu_order] => 0
[post_type] => post
[post_mime_type] =>
[comment_count] => 0
[_close_date] =>
[_stage] =>
[_type] =>
[_subtype] =>
[_amount] =>
[_first_name] =>
[_last_name] =>
[_email_address] =>
[_payment_type] =>
[RecordTypeId] =>
[_edit_lock] => 1523674949:1
[_edit_last] => 1
然后它与元字段一起发布:
[ID] => 600
[post_author] => 1
[post_date] => 2018-04-14 03:02:51
[post_date_gmt] => 2018-04-14 03:02:51
[post_content] => test
[post_title] => test post
[post_excerpt] =>
[post_status] => publish
[comment_status] => open
[ping_status] => open
[post_password] =>
[post_name] => test-post-6
[to_ping] =>
[pinged] =>
[post_modified] => 2018-04-14 03:02:51
[post_modified_gmt] => 2018-04-14 03:02:51
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://vanilla-wordpress.test/?p=600
[menu_order] => 0
[post_type] => post
[post_mime_type] =>
[comment_count] => 0
[_close_date] => 04/13/2018
[_stage] => Closed Won
[_type] => Donation
[_subtype] => Donation: Individual
[_amount] => 199
[_first_name] => test
[_last_name] => name
[_email_address] => [email protected]
[_payment_type] =>
[RecordTypeId] =>
[_edit_lock] => 1523674964:1
之后我的日志似乎会被截断,但一旦文章从草稿更改为发布,自定义字段值就会出现。我的插件忽略草稿,这样它就不会在草稿上失败。但在任何情况下,都会将数据发送给Salesforce,并创建一个没有错误的项目;必填字段都按其应有的方式存在。
当我对自定义post对象(称为opportunity)执行同样的操作时,它是这样产生的:
第一次,它是一个草稿:
[ID] => 597
[post_author] => 1
[post_date] => 2018-04-14 03:00:33
[post_date_gmt] => 0000-00-00 00:00:00
[post_content] =>
[post_title] => test
[post_excerpt] =>
[post_status] => draft
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] =>
[to_ping] =>
[pinged] =>
[post_modified] => 2018-04-14 03:00:33
[post_modified_gmt] => 2018-04-14 03:00:33
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://vanilla-wordpress.test/?post_type=donation&p=597
[menu_order] => 0
[post_type] => donation
[post_mime_type] =>
[comment_count] => 0
[_edit_lock] => 1523674833:1
[_edit_last] => 1
[_close_date] =>
[_stage] =>
[_type] =>
[_subtype] =>
[_amount] =>
[_payment_type] =>
[_first_name] =>
[_last_name] =>
[_email_address] =>
第二,出版:
[ID] => 597
[post_author] => 1
[post_date] => 2018-04-14 03:00:54
[post_date_gmt] => 2018-04-14 03:00:54
[post_content] => test
[post_title] => test
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => test-4
[to_ping] =>
[pinged] =>
[post_modified] => 2018-04-14 03:00:54
[post_modified_gmt] => 2018-04-14 03:00:54
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://vanilla-wordpress.test/?post_type=donation&p=597
[menu_order] => 0
[post_type] => donation
[post_mime_type] =>
[comment_count] => 0
[_edit_lock] => 1523674848:1
[_edit_last] => 1
[_close_date] =>
[_stage] =>
[_type] =>
[_subtype] =>
[_amount] =>
[_payment_type] =>
[_first_name] =>
[_last_name] =>
[_email_address] =>
WordPress中的此自定义帖子类型具有与标准相同的自定义字段
post
类型,但Salesforce无法创建/更新记录,因为必填字段没有值。
我一直无法找到这两个钩子应该如何工作的差异来解释这一点。是否有任何方法可以确保我能够加载所有的元数据来发送它们?