当前位置: 首页>>代码示例>>PHP>>正文


PHP WPCF7_Shortcode::get_first_match_option方法代码示例

本文整理汇总了PHP中WPCF7_Shortcode::get_first_match_option方法的典型用法代码示例。如果您正苦于以下问题:PHP WPCF7_Shortcode::get_first_match_option方法的具体用法?PHP WPCF7_Shortcode::get_first_match_option怎么用?PHP WPCF7_Shortcode::get_first_match_option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WPCF7_Shortcode的用法示例。


在下文中一共展示了WPCF7_Shortcode::get_first_match_option方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: cf7bs_select_shortcode_handler

function cf7bs_select_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $mode = $status = 'default';
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
        $status = 'error';
    }
    if ($tag->is_required()) {
        $mode = 'required';
    }
    $defaults = array();
    $default_choice = $tag->get_default_option(null, 'multiple=1');
    foreach ($default_choice as $value) {
        $key = array_search($value, $values, true);
        if (false !== $key) {
            $defaults[] = (int) $key + 1;
        }
    }
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = explode('_', $matches[1]);
    }
    $defaults = array_unique($defaults);
    $multiple = $tag->has_option('multiple');
    $include_blank = $tag->has_option('include_blank');
    $first_as_label = $tag->has_option('first_as_label');
    $values = $tag->values;
    $labels = $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        $values = array_merge($values, array_values($data));
        $labels = array_merge($labels, array_values($data));
    }
    $empty_select = empty($values);
    $shifted = false;
    if ($empty_select || $include_blank) {
        array_unshift($labels, '---');
        array_unshift($values, '');
        $shifted = true;
    } elseif ($first_as_label) {
        $values[0] = '';
    }
    $options = array();
    $selected = '';
    if ($multiple) {
        $selected = array();
    }
    if (isset($_POST[$tag->name])) {
        $post = $_POST[$tag->name];
    } else {
        if (isset($_GET[$tag->name])) {
            if ($multiple) {
                $get = cf7bs_array_decode(rawurldecode($_GET[$tag->name]));
            } else {
                $get = rawurldecode($_GET[$tag->name]);
            }
        }
        $post = $multiple ? array() : '';
    }
    $posted = wpcf7_is_posted();
    foreach ($values as $key => $value) {
        $options[$value] = isset($labels[$key]) ? $labels[$key] : $value;
        if ($posted && !empty($post)) {
            if ($multiple && in_array(esc_sql($value), (array) $post)) {
                $selected[] = $value;
            }
            if (!$multiple && $post == esc_sql($value)) {
                $selected = $value;
            }
        } elseif (isset($get) && !empty($get)) {
            if ($multiple && in_array(esc_sql($value), (array) $get)) {
                $selected[] = $value;
            }
            if (!$multiple && $get == esc_sql($value)) {
                $selected = $value;
            }
        } elseif (!$shifted && in_array((int) $key + 1, (array) $defaults) || $shifted && in_array((int) $key, (array) $defaults)) {
            if ($multiple) {
                $selected[] = $value;
            } else {
                $selected = $value;
            }
        }
    }
    $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => $tag->get_class_option($class), 'type' => $multiple ? 'multiselect' : 'select', 'value' => $selected, 'label' => $tag->content, 'options' => $options, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'mode' => $mode, 'status' => $status, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->name), $tag->basetype, $tag->name));
    $html = $field->display(false);
    return $html;
}
开发者ID:aaronfrey,项目名称:PepperLillie-CVM,代码行数:92,代码来源:select.php

示例2: wpcf7_select_shortcode_handler

function wpcf7_select_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $defaults = array();
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = explode('_', $matches[1]);
    }
    $multiple = $tag->has_option('multiple');
    $include_blank = $tag->has_option('include_blank');
    $first_as_label = $tag->has_option('first_as_label');
    $values = $tag->values;
    $labels = $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        $values = array_merge($values, array_values($data));
        $labels = array_merge($labels, array_values($data));
    }
    $empty_select = empty($values);
    if ($empty_select || $include_blank) {
        array_unshift($labels, '---');
        array_unshift($values, '');
    } elseif ($first_as_label) {
        $values[0] = '';
    }
    $html = '';
    $hangover = wpcf7_get_hangover($tag->name);
    foreach ($values as $key => $value) {
        $selected = false;
        if ($hangover) {
            if ($multiple) {
                $selected = in_array(esc_sql($value), (array) $hangover);
            } else {
                $selected = $hangover == esc_sql($value);
            }
        } else {
            if (!$empty_select && in_array($key + 1, (array) $defaults)) {
                $selected = true;
            }
        }
        $item_atts = array('value' => $value, 'selected' => $selected ? 'selected' : '');
        $item_atts = wpcf7_format_atts($item_atts);
        $label = isset($labels[$key]) ? $labels[$key] : $value;
        $html .= sprintf('<option %1$s>%2$s</option>', $item_atts, esc_html($label));
    }
    if ($multiple) {
        $atts['multiple'] = 'multiple';
    }
    $atts['name'] = $tag->name . ($multiple ? '[]' : '');
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><select %2$s>%3$s</select>%4$s</span>', sanitize_html_class($tag->name), $atts, $html, $validation_error);
    return $html;
}
开发者ID:crazyyy,项目名称:octagram,代码行数:67,代码来源:select.php

示例3: cf7bs_text_shortcode_handler

function cf7bs_text_shortcode_handler($tag)
{
    $tag_obj = new WPCF7_Shortcode($tag);
    if (empty($tag_obj->name)) {
        return '';
    }
    $mode = $status = 'default';
    $validation_error = wpcf7_get_validation_error($tag_obj->name);
    $class = wpcf7_form_controls_class($tag_obj->type, 'wpcf7-text');
    if (in_array($tag_obj->basetype, array('email', 'url', 'tel'))) {
        $class .= ' wpcf7-validates-as-' . $tag_obj->basetype;
    }
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
        $status = 'error';
    }
    // size is not used since Bootstrap input fields always scale 100%
    //$atts['size'] = $tag_obj->get_size_option( '40' );
    if ($tag_obj->is_required()) {
        $mode = 'required';
    }
    $value = (string) reset($tag_obj->values);
    $placeholder = '';
    if ($tag_obj->has_option('placeholder') || $tag_obj->has_option('watermark')) {
        $placeholder = $value;
        $value = '';
    }
    $value = $tag_obj->get_default_option($value);
    if (wpcf7_is_posted() && isset($_POST[$tag_obj->name])) {
        $value = stripslashes_deep($_POST[$tag_obj->name]);
    } elseif (isset($_GET) && array_key_exists($tag_obj->name, $_GET)) {
        $value = stripslashes_deep(rawurldecode($_GET[$tag_obj->name]));
    }
    $input_before = $tag_obj->get_first_match_option('/input_before:([^\\s]+)/');
    $input_after = $tag_obj->get_first_match_option('/input_after:([^\\s]+)/');
    if (is_array($input_before) && isset($input_before[1])) {
        $input_before = str_replace('---', ' ', $input_before[1]);
    } else {
        $input_before = '';
    }
    if (is_array($input_after) && isset($input_after[1])) {
        $input_after = str_replace('---', ' ', $input_after[1]);
    } else {
        $input_after = '';
    }
    if ($tag_obj->has_option('include_count')) {
        $count_mode = 'input_after';
        $count_down = false;
        $count_options = $tag_obj->get_option('include_count', '[A-Za-z]+(:[A-Za-z]+)?', true);
        if ($count_options) {
            $count_options = explode(':', $count_options);
            foreach ($count_options as $count_option) {
                switch ($count_option) {
                    case 'down':
                    case 'DOWN':
                        $count_down = true;
                        break;
                    case 'before':
                    case 'BEFORE':
                        $count_mode = 'input_before';
                        break;
                    default:
                }
            }
        }
        $tag = cf7bs_text_to_count($tag, $count_down);
        if (!empty(${$count_mode})) {
            ${$count_mode} = wpcf7_count_shortcode_handler($tag) . ' ' . ${$count_mode};
        } else {
            ${$count_mode} = wpcf7_count_shortcode_handler($tag);
        }
    }
    $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag_obj->name, 'id' => $tag_obj->get_option('id', 'id', true), 'class' => $tag_obj->get_class_option($class), 'type' => wpcf7_support_html5() ? $tag_obj->basetype : 'text', 'value' => $value, 'placeholder' => $placeholder, 'label' => $tag_obj->content, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'mode' => $mode, 'status' => $status, 'readonly' => $tag_obj->has_option('readonly') ? true : false, 'minlength' => $tag_obj->get_minlength_option(), 'maxlength' => $tag_obj->get_maxlength_option(), 'tabindex' => $tag_obj->get_option('tabindex', 'int', true), 'wrapper_class' => $tag_obj->name, 'input_before' => $input_before, 'input_after' => $input_after), $tag_obj->basetype, $tag_obj->name));
    $html = $field->display(false);
    return $html;
}
开发者ID:joostthehost,项目名称:bootstrap-for-contact-form-7,代码行数:76,代码来源:text.php

示例4: wpcf7_checkbox_shortcode_handler

function wpcf7_checkbox_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $label_first = $tag->has_option('label_first');
    $use_label_element = $tag->has_option('use_label_element');
    $exclusive = $tag->has_option('exclusive');
    $free_text = $tag->has_option('free_text');
    $multiple = false;
    if ('checkbox' == $tag->basetype) {
        $multiple = !$exclusive;
    } else {
        // radio
        $exclusive = false;
    }
    if ($exclusive) {
        $class .= ' wpcf7-exclusive-checkbox';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $tabindex = $tag->get_option('tabindex', 'int', true);
    if (false !== $tabindex) {
        $tabindex = absint($tabindex);
    }
    $html = '';
    $count = 0;
    $values = (array) $tag->values;
    $labels = (array) $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        if ($free_text) {
            $values = array_merge(array_slice($values, 0, -1), array_values($data), array_slice($values, -1));
            $labels = array_merge(array_slice($labels, 0, -1), array_values($data), array_slice($labels, -1));
        } else {
            $values = array_merge($values, array_values($data));
            $labels = array_merge($labels, array_values($data));
        }
    }
    $defaults = array();
    $default_choice = $tag->get_default_option(null, 'multiple=1');
    foreach ($default_choice as $value) {
        $key = array_search($value, $values, true);
        if (false !== $key) {
            $defaults[] = (int) $key + 1;
        }
    }
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = array_merge($defaults, explode('_', $matches[1]));
    }
    $defaults = array_unique($defaults);
    $hangover = wpcf7_get_hangover($tag->name, $multiple ? array() : '');
    foreach ($values as $key => $value) {
        $class = 'wpcf7-list-item';
        $checked = false;
        if ($hangover) {
            if ($multiple) {
                $checked = in_array(esc_sql($value), (array) $hangover);
            } else {
                $checked = $hangover == esc_sql($value);
            }
        } else {
            $checked = in_array($key + 1, (array) $defaults);
        }
        if (isset($labels[$key])) {
            $label = $labels[$key];
        } else {
            $label = $value;
        }
        $item_atts = array('type' => $tag->basetype, 'name' => $tag->name . ($multiple ? '[]' : ''), 'value' => $value, 'checked' => $checked ? 'checked' : '', 'tabindex' => $tabindex ? $tabindex : '');
        $item_atts = wpcf7_format_atts($item_atts);
        if ($label_first) {
            // put label first, input last
            $item = sprintf('<span class="wpcf7-list-item-label">%1$s</span>&nbsp;<input %2$s />', esc_html($label), $item_atts);
        } else {
            $item = sprintf('<input %2$s />&nbsp;<span class="wpcf7-list-item-label">%1$s</span>', esc_html($label), $item_atts);
        }
        if ($use_label_element) {
            $item = '<label>' . $item . '</label>';
        }
        if (false !== $tabindex) {
            $tabindex += 1;
        }
        $count += 1;
        if (1 == $count) {
            $class .= ' first';
        }
        if (count($values) == $count) {
            // last round
            $class .= ' last';
            if ($free_text) {
                $free_text_name = sprintf('_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name);
                $free_text_atts = array('name' => $free_text_name, 'class' => 'wpcf7-free-text', 'tabindex' => $tabindex ? $tabindex : '');
                if (wpcf7_is_posted() && isset($_POST[$free_text_name])) {
//.........这里部分代码省略.........
开发者ID:Lumbe,项目名称:dev_servus,代码行数:101,代码来源:checkbox.php

示例5: wpcf7_checkbox_shortcode_handler

function wpcf7_checkbox_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $label_first = $tag->has_option('label_first');
    $use_label_element = $tag->has_option('use_label_element');
    $exclusive = $tag->has_option('exclusive');
    $multiple = false;
    if ('checkbox' == $tag->basetype) {
        $multiple = !$exclusive;
    } else {
        // radio
        $exclusive = false;
    }
    if ($exclusive) {
        $class .= ' wpcf7-exclusive-checkbox';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_option('id', 'id', true);
    $tabindex = $tag->get_option('tabindex', 'int', true);
    if (false !== $tabindex) {
        $tabindex = absint($tabindex);
    }
    $defaults = array();
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = explode('_', $matches[1]);
    }
    if (isset($_POST[$tag->name])) {
        $post = $_POST[$tag->name];
    } else {
        $post = $multiple ? array() : '';
    }
    $is_posted = wpcf7_is_posted();
    $html = '';
    foreach ((array) $tag->values as $key => $value) {
        $checked = false;
        if ($is_posted && !empty($post)) {
            if ($multiple && in_array(esc_sql($value), (array) $post)) {
                $checked = true;
            }
            if (!$multiple && $post == esc_sql($value)) {
                $checked = true;
            }
        } else {
            if (in_array($key + 1, (array) $defaults)) {
                $checked = true;
            }
        }
        if (isset($tag->labels[$key])) {
            $label = $tag->labels[$key];
        } else {
            $label = $value;
        }
        $item_atts = array('type' => $tag->basetype, 'name' => $tag->name . ($multiple ? '[]' : ''), 'value' => $value, 'checked' => $checked ? 'checked' : '', 'tabindex' => $tabindex ? $tabindex : '');
        $item_atts = wpcf7_format_atts($item_atts);
        if ($label_first) {
            // put label first, input last
            $item = sprintf('<span class="wpcf7-list-item-label">%1$s</span>&nbsp;<input %2$s />', esc_html($label), $item_atts);
        } else {
            $item = sprintf('<input %2$s />&nbsp;<span class="wpcf7-list-item-label">%1$s</span>', esc_html($label), $item_atts);
        }
        if ($use_label_element) {
            $item = '<label>' . $item . '</label>';
        }
        $item = '<span class="wpcf7-list-item">' . $item . '</span>';
        $html .= $item;
        if (false !== $tabindex) {
            $tabindex += 1;
        }
    }
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><span %2$s>%3$s</span>%4$s</span>', $tag->name, $atts, $html, $validation_error);
    return $html;
}
开发者ID:KurtMakesWeb,项目名称:CandG,代码行数:82,代码来源:checkbox.php

示例6: cf7bs_checkbox_shortcode_handler

function cf7bs_checkbox_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $mode = $status = 'default';
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
        $status = 'error';
    }
    $exclusive = $tag->has_option('exclusive');
    $free_text = $tag->has_option('free_text');
    $multiple = false;
    if ('checkbox' == $tag->basetype) {
        $multiple = !$exclusive;
    } else {
        $exclusive = false;
    }
    if ($exclusive) {
        $class .= ' wpcf7-exclusive-checkbox';
    }
    if ($tag->is_required()) {
        $mode = 'required';
    }
    $values = (array) $tag->values;
    $labels = (array) $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        if ($free_text) {
            $values = array_merge(array_slice($values, 0, -1), array_values($data), array_slice($values, -1));
            $labels = array_merge(array_slice($labels, 0, -1), array_values($data), array_slice($labels, -1));
        } else {
            $values = array_merge($values, array_values($data));
            $labels = array_merge($labels, array_values($data));
        }
    }
    $defaults = array();
    $default_choice = $tag->get_default_option(null, 'multiple=1');
    foreach ($default_choice as $value) {
        $key = array_search($value, $values, true);
        if (false !== $key) {
            $defaults[] = (int) $key + 1;
        }
    }
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = array_merge($defaults, explode('_', $matches[1]));
    }
    $defaults = array_unique($defaults);
    $options = array();
    $checked = '';
    if ($multiple) {
        $checked = array();
    }
    if (isset($_POST[$tag->name])) {
        $post = $_POST[$tag->name];
    } else {
        if (isset($_GET[$tag->name])) {
            if ($multiple) {
                $get = cf7bs_array_decode(rawurldecode($_GET[$tag->name]));
            } else {
                $get = rawurldecode($_GET[$tag->name]);
            }
        }
        $post = $multiple ? array() : '';
    }
    $posted = wpcf7_is_posted();
    $count = 0;
    foreach ((array) $tag->values as $key => $value) {
        if ($free_text && $count == count($tag->values) - 1) {
            $options[$value] = '<input type="text" name="' . sprintf('_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name) . '" class="wpcf7-free-text">';
        } else {
            $options[$value] = isset($labels[$key]) ? $labels[$key] : $value;
        }
        if ($posted && !empty($post)) {
            if ($multiple && in_array(esc_sql($value), (array) $post)) {
                $checked[] = $value;
            }
            if (!$multiple && $post == esc_sql($value)) {
                $checked = $value;
            }
        } elseif (isset($get) && !empty($get)) {
            if ($multiple && in_array(esc_sql($value), (array) $get)) {
                $checked[] = $value;
            }
            if (!$multiple && $get == esc_sql($value)) {
                $checked = $value;
            }
        } elseif (in_array($key + 1, (array) $defaults)) {
            if ($multiple) {
                $checked[] = $value;
            } else {
                $checked = $value;
            }
        }
        $count++;
    }
    $label = $tag->content;
    if (count($options) < 1) {
//.........这里部分代码省略.........
开发者ID:joostthehost,项目名称:bootstrap-for-contact-form-7,代码行数:101,代码来源:checkbox.php


注:本文中的WPCF7_Shortcode::get_first_match_option方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。