[英]Run shortcode contact form in a hook - wordpress code snippet
好的,這是我第一次嘗試使用PHP /代碼段,因此,如果我做不到,我會提前道歉!
我有一個帶有房地產插件的Wordpress網站,該插件允許登錄的用戶聯系代理(如果願意,請聯系房東)。 我想擴展插件以使用我自己的聯系表(我正在使用插件聯系表7),以便我們獲得電子郵件而非代理(然后我們將代表用戶聯系代理)
我通過搜索插件代碼找到了下面的聯系代理掛鈎
/**
* single_property_contact_agent
*/
public function single_property_contact_agent()
{
$property_form_sections = ere_get_option('property_form_sections', array('title_des', 'location', 'type', 'price', 'features', 'details', 'media', 'floors', 'agent'));
$hide_contact_information_if_not_login = ere_get_option('hide_contact_information_if_not_login', 0);
if ($hide_contact_information_if_not_login == 0) {
if (in_array('contact', $property_form_sections)) {
ere_get_template('single-property/contact-agent.php');
}
} else {
if (is_user_logged_in()) {
if (in_array('contact', $property_form_sections)) {
ere_get_template('single-property/contact-agent.php');
}
} else {
?>
<p class="ere-account-sign-in"><?php esc_attr_e('Please login or register to view contact information for this agent/owner', 'essential-real-estate'); ?>
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal"
data-target="#ere_signin_modal">
<?php esc_html_e('Login', 'essential-real-estate'); ?>
</button>
</p>
<?php
}
}
}
我的想法是使用下面的代碼片段連接到上面並加載我們的表單(使用聯系表簡碼)
add_action('single_property_contact_agent', 'reg_form_before_content');
function reg_form_before_content() {
echo do_shortcode('[contact-form-7 id="524" title="Register Interest"]');
}
目前什么都沒有發生,所以我可能無法解決這里可能發生的事情,但是如果有人能幫助我,我將永遠感激不已
非常感謝!
從概念上講,您很出色。 我認為這或多或少是WordPress Way™:連接到動作和過濾器以修改輸出/行為。 在那里真是太好了。
麻煩的是,你的目標沒有實現任何調用該函數 apply_filter('filter_name', $data)
,或do_action('hook_name', $var)
許多WordPress代碼中都有一個棘手的規范,其中函數的名稱也是過濾器或操作的名稱。 但這是一個巧合。
說了這么多,您可以看一下ere_get_template
函數的源代碼。 也許它像WooCommerce那樣采用了某種模板繼承 。
也就是說-如果您相對於主題文件夾創建一個名為single-property/contact-agent.php
的模板,則在默認為模板模板之前,它可能會檢查您提供的模板。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.