示例#1
0
/**
 * Wraps field content.
 *
 * @param type $field
 * @param type $content
 * @return type
 */
function wpcf_frontend_wrap_field($field, $content, $params = array())
{
    if (isset($params['output']) && $params['output'] == 'html') {
        $class = array();
        if (!empty($params['class']) && !in_array($field['type'], array('file', 'image', 'email', 'url', 'wysiwyg'))) {
            $class[] = $params['class'];
        }
        $class[] = 'wpcf-field-' . $field['type'] . ' wpcf-field-' . $field['slug'];
        // Add name if needed
        if (isset($params['show_name']) && $params['show_name'] == 'true' && strpos($content, 'class="wpcf-field-' . $field['type'] . '-name ') === false) {
            $content = wpcf_frontend_wrap_field_name($field, $field['name'], $params) . $content;
        }
        $output = '<div id="wpcf-field-' . $field['slug'] . '"' . ' class="' . implode(' ', $class) . '"';
        if (!empty($params['style']) && !in_array($field['type'], array('date', 'file', 'image', 'email', 'url', 'wysiwyg'))) {
            $output .= ' style="' . $params['style'] . '"';
        }
        $output .= '>' . $content . '</div>';
        return $output;
    } else {
        if (isset($params['show_name']) && $params['show_name'] == 'true' && strpos($content, $field['name'] . ':') === false) {
            $content = wpcf_frontend_wrap_field_name($field, $params['field']['name'], $params) . $content;
        }
        return $content;
    }
}
示例#2
0
/**
 * Wraps field content.
 * 
 * @param type $field
 * @param type $content
 * @return type 
 */
function wpcf_frontend_wrap_field($field, $content, $params = array())
{
    if (isset($params['output']) && $params['output'] == 'html') {
        // Add name if needed
        if (isset($params['show_name']) && $params['show_name'] == 'true' && strpos($content, 'class="wpcf-field-' . $field['type'] . '-name ') === false) {
            $content = wpcf_frontend_wrap_field_name($field, $field['name'], $params) . $content;
        }
        return '<div id="wpcf-field-' . $field['slug'] . '"' . ' class="wpcf-field-' . $field['type'] . ' wpcf-field-' . $field['slug'] . '"' . '>' . $content . '</div>';
    } else {
        if (isset($params['show_name']) && $params['show_name'] == 'true' && strpos($content, $field['name']) === false) {
            $content = wpcf_frontend_wrap_field_name($field, $params['field']['name'], $params) . $content;
        }
        return $content;
    }
}