【问题标题】:How to get properties of Contact Form 7 object in PHP如何在 PHP 中获取 Contact Form 7 对象的属性
【发布时间】:2021-12-14 08:58:18
【问题描述】:

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

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

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

它返回这个对象:

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 和类等内容,但这不是我想要的。我对对象中的对象或数组的理解让我很难理解如何访问此处的值。

【问题讨论】:

  • properties 属性是私有的,所以你不能直接访问它;您需要使用 WPCF7_ContactForm 类提供的 getter 和 setter 方法。
  • 很棒的信息谢谢!所以像: $props = $form->get_properties(); $props['form'] .= $manipulations; $form->set_properties($props);

标签: php arrays wordpress object contact-form-7


【解决方案1】:

表单字符串是我想要操作以向其添加 HTML 的部分。

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

您需要的form 字符串可以使用表单 id 从 post 元字段表中检索,

$form = get_post_meta($form_id, '_form', true);

【讨论】:

  • 啊,我明白了,可以这么说,我一直在开采错误的矿石。我开始走这条路线是因为我认为会有某种钩子支撑,但后来意识到没有。
猜你喜欢
  • 2021-08-23
  • 1970-01-01
  • 1970-01-01
  • 2019-09-10
  • 2019-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多