如何在 PHP 中获取 Contact Form 7 对象的属性

How to get properties of Contact Form 7 object in PHP

我正在尝试操纵我网站上联系表单的一些标记,并设法获得了我想要使用的特定对象

        $forms = WPCF7_ContactForm::find(array('p' => $redirect['form']));

我不知道 'p' 键是什么或它为什么起作用,但似乎没有别的。

它returns这个对象:

object(WPCF7_ContactForm)#6114 (9) { ["id":"WPCF7_ContactForm":private]=> int(383) 
["name":"WPCF7_ContactForm":private]=> string(8) "untitled" 
["title":"WPCF7_ContactForm":private]=> string(15) "Customer Survey" 
["locale":"WPCF7_ContactForm":private]=> string(5) "en_GB" 
["properties":"WPCF7_ContactForm":private]=> array(5) { ["form"]=> string(2119) " (really long 
form string) "

表单字符串是我要操作以向其添加 HTML 的部分。我知道您可以在编辑器中添加 ID 和 类 之类的东西,但这不是我想要的。我对对象或对象中的数组的理解让我对如何访问此处的值感到困惑。

The form string is the part i want to manipulate to add HTML to it.

在数据库级别更容易做到这一点。 CF7 表单将其元数据和 HTML 表单存储为自定义 post 类型 wpcf7_contact_form 以及许多元字段。

可以使用表单 ID

从 post 元字段 table 中检索到您想要的 form 字符串
$form = get_post_meta($form_id, '_form', true);