php 将此脚本插入到WordPress主题中的functions.php中(了解开启和关闭的php标记)以允许Gr中的字段组

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 将此脚本插入到WordPress主题中的functions.php中(了解开启和关闭的php标记)以允许Gr中的字段组相关的知识,希望对你有一定的参考价值。

<?php
/*
Insert this script into functions.php in your WordPress theme (be cognizant of the opening and closing php tags) to allow field groups in Gravity Forms. The script will create two new field types - Open Group and Close Group. Add classes to your Open Group fields to style your groups.

Note that there is a stray (but empty) <li> element created. It is given the class "fieldgroup_extra_li" so that you can hide it in your CSS if needed.
*/
add_filter("gform_add_field_buttons", "add_fieldgroup_fields");
function add_fieldgroup_fields($field_groups){

    foreach($field_groups as &$group){
        if($group["name"] == "standard_fields"){
            $group["fields"][] = array("class"=>"button", "value" => __("Open Group", "gravityforms"), "onclick" => "StartAddField('fieldgroupopen');");
            $group["fields"][] = array("class"=>"button", "value" => __("Close Group", "gravityforms"), "onclick" => "StartAddField('fieldgroupclose');");
            break;
        }
    }
    return $field_groups;
}

// Add title to the Field Group fields
add_filter( 'gform_field_type_title' , 'field_group_titles' );
function field_group_titles( $type ) {
    if ( $type == 'fieldgroupopen' ) {
        return __( 'Open Field Group' , 'gravityforms' );
    } else if ( $type == 'fieldgroupclose' ) {
        return __( 'Close Field Group' , 'gravityforms' );
    }
}

add_filter("gform_field_content", "create_gf_field_group", 10, 5);
function create_gf_field_group($content, $field, $value, $lead_id, $form_id){
    if ( ! is_admin() ) {
        if(rgar($field,"type") == "fieldgroupopen"){
            $content = "<ul><li style='display: none;'>";
        }
        else if(rgar($field,"type") == "fieldgroupclose"){
            $content = "</li></ul><!-- close field group --><li style='display: none;'>";
        }
    }
    return $content;
}

// Add a CSS class to the Field Group Close field so we can hide the extra <li> that is created.
add_action("gform_field_css_class", "close_field_group_class", 10, 3);
function close_field_group_class($classes, $field, $form){
    if($field["type"] == "fieldgroupclose"){
        $classes .= " fieldgroup_extra_li";
    }
    return $classes;
}

add_action("gform_editor_js_set_default_values", "field_group_default_labels");
function field_group_default_labels(){
    ?>
    case "fieldgroupopen" :
        field.label = "Field Group Open";
    break;
    case "fieldgroupclose" :
        field.label = "Field Group Close";
    break;
    <?php
}

add_action("gform_editor_js", "allow_fieldgroup_settings");
function allow_fieldgroup_settings(){
    ?>
    <script type='text/javascript'>
        fieldSettings["fieldgroupopen"] = fieldSettings["text"] + ", .cssClass";
        fieldSettings["fieldgroupclose"] = fieldSettings["text"] + ", .cssClass";
    </script>
    <?php
}
?>

以上是关于php 将此脚本插入到WordPress主题中的functions.php中(了解开启和关闭的php标记)以允许Gr中的字段组的主要内容,如果未能解决你的问题,请参考以下文章

访问下划线主题中的非wordpress php文件

PHP 在wordpress页面主题中插入img

php 将wordpress主题的脚本和样式排入队列

如何设置wordpress主题的日期格式

如何将此 jQuery 脚本添加到我的 Wordpress

重写 WordPress 主题文件,将所有内容重定向到 httpd.conf 中的 index.php