在hook-wordpress代码片段中运行短代码联系表单

时间:2018-02-02 17:04:27

标签: php wordpress forms contact code-snippets

好的,这是我有史以来第一次尝试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"]');

   }

目前没有任何事情发生,所以我可能会忘记这里有什么可能但是如果有人可以帮助我会永远感激

非常感谢!

1 个答案:

答案 0 :(得分:1)

从概念上讲,你是在标记上。我认为这或多或少是WordPress Way™:挂钩动作和过滤器以修改输出/行为。所以在那里向你致敬。

问题是,您定位的功能没有实现对ACTION_IMAGE_CAPTUREapply_filter('filter_name', $data)的任何调用。

在许多WordPress代码中有一个棘手的规范,其中函数的名称也是过滤器或操作的名称。但这是巧合。

所有这些,你可以看一下do_action('hook_name', $var)函数的来源。也许它正在使用某种template inheritance like WooCommerce does

也就是说 - 如果您创建一个相对于名为ere_get_template的主题文件夹的模板,它可能会检查您提供的模板,然后默认为自己的模板。