Example #1
0
/**
 * Editor callback form submit.
 */
function wpcf_fields_url_editor_submit($data, $field, $context)
{
    $add = '';
    if (!empty($data['title'])) {
        $add .= ' title="' . strval($data['title']) . '"';
    }
    if (!empty($data['no_protocol'])) {
        $add .= ' no_protocol="true"';
    }
    if (!empty($data['target'])) {
        if ($data['target'] == 'framename') {
            $add .= ' target="' . strval($data['framename']) . '"';
        } else {
            if ($data['target'] != '_self') {
                $add .= ' target="' . strval($data['target']) . '"';
            }
        }
    }
    if ($context == 'usermeta') {
        $add .= wpcf_get_usermeta_form_addon_submit();
        $shortcode = wpcf_usermeta_get_shortcode($field, $add);
    } elseif ($context == 'termmeta') {
        $add .= wpcf_get_termmeta_form_addon_submit();
        $shortcode = wpcf_termmeta_get_shortcode($field, $add);
    } else {
        $shortcode = wpcf_fields_get_shortcode($field, $add);
    }
    return $shortcode;
}
Example #2
0
/**
 * Editor callback form submit.
 */
function wpcf_fields_radio_editor_submit($data, $field, $context)
{
    $add = '';
    switch ($context) {
        case 'usermeta':
            $types_attr = 'usermeta';
            $add .= wpcf_get_usermeta_form_addon_submit();
            break;
        case 'termmeta':
            $types_attr = 'termmeta';
            $add .= wpcf_get_termmeta_form_addon_submit();
            break;
        default:
            $types_attr = 'field';
            break;
    }
    if (isset($data['display']) && $data['display'] == 'value' && !empty($data['options'])) {
        $shortcode = '';
        foreach ($data['options'] as $option_id => $value) {
            $shortcode .= '[types ' . $types_attr . '="' . $field['slug'] . '" ' . $add . ' option="' . $option_id . '"]' . $value . '[/types] ';
        }
    } else {
        if ($context == 'usermeta') {
            $shortcode = wpcf_usermeta_get_shortcode($field, $add);
        } elseif ($context == 'termmeta') {
            $shortcode = wpcf_termmeta_get_shortcode($field, $add);
        } else {
            $shortcode = wpcf_fields_get_shortcode($field, $add);
        }
    }
    return $shortcode;
}
/**
 * Editor callback form submit.
 */
function wpcf_fields_numeric_editor_submit($data, $field, $context)
{
    $add = '';
    if (!empty($data['format'])) {
        $add .= ' format="' . strval($data['format']) . '"';
    }
    if ($context == 'usermeta') {
        $add .= wpcf_get_usermeta_form_addon_submit();
        $shortcode = wpcf_usermeta_get_shortcode($field, $add);
    } elseif ($context == 'termmeta') {
        $add .= wpcf_get_termmeta_form_addon_submit();
        $shortcode = wpcf_termmeta_get_shortcode($field, $add);
    } else {
        $shortcode = wpcf_fields_get_shortcode($field, $add);
    }
    return $shortcode;
}
Example #4
0
/**
 * Editor callback form submit.
 */
function wpcf_fields_checkbox_editor_submit($data, $field, $context)
{
    $add = '';
    if ($context == 'usermeta') {
        $add .= wpcf_get_usermeta_form_addon_submit();
    } elseif ($context == 'termmeta') {
        $add .= wpcf_get_termmeta_form_addon_submit();
    }
    if (isset($data['display']) && $data['display'] == 'value') {
        $checked_add = $add . ' state="checked"';
        $unchecked_add = $add . ' state="unchecked"';
        if ($context == 'usermeta') {
            $shortcode_checked = wpcf_usermeta_get_shortcode($field, $checked_add, $data['selected']);
            $shortcode_unchecked = wpcf_usermeta_get_shortcode($field, $unchecked_add, $data['not_selected']);
        } else {
            if ($context == 'termmeta') {
                $shortcode_checked = wpcf_termmeta_get_shortcode($field, $checked_add, $data['selected']);
                $shortcode_unchecked = wpcf_termmeta_get_shortcode($field, $unchecked_add, $data['not_selected']);
            } else {
                $shortcode_checked = wpcf_fields_get_shortcode($field, $checked_add, $data['selected']);
                $shortcode_unchecked = wpcf_fields_get_shortcode($field, $unchecked_add, $data['not_selected']);
            }
        }
        $shortcode = $shortcode_checked . $shortcode_unchecked;
    } else {
        if ($context == 'usermeta') {
            $shortcode = wpcf_usermeta_get_shortcode($field, $add);
        } else {
            if ($context == 'termmeta') {
                $shortcode = wpcf_termmeta_get_shortcode($field, $add);
            } else {
                $shortcode = wpcf_fields_get_shortcode($field, $add);
            }
        }
    }
    return $shortcode;
}
/**
 * Editor callback form submit.
 */
function wpcf_fields_image_editor_submit($data, $field, $context)
{
    // Saved settings
    $settings = array();
    $add = '';
    if (!empty($data['alt'])) {
        $add .= ' alt="' . strval($data['alt']) . '"';
    }
    if (!empty($data['title'])) {
        $add .= ' title="' . strval($data['title']) . '"';
    }
    $size = !empty($data['image_size']) ? $data['image_size'] : false;
    if ($size == 'wpcf-custom') {
        if (!empty($data['width'])) {
            $add .= ' width="' . intval($data['width']) . '"';
        }
        if (!empty($data['height'])) {
            $add .= ' height="' . intval($data['height']) . '"';
        }
    } else {
        if (!empty($size)) {
            $add .= ' size="' . $size . '"';
            $settings['image_size'] = $size;
        }
    }
    if (!empty($data['alignment'])) {
        $add .= ' align="' . $data['alignment'] . '"';
        $settings['alignment'] = $data['alignment'];
    }
    if (!empty($data['url'])) {
        $add .= ' url="true"';
    }
    if (!empty($data['onload'])) {
        $add .= ' onload="' . $data['onload'] . '"';
    }
    if (array_key_exists('image_size', $data) && $data['image_size'] != 'full') {
        if (!empty($data['proportional'])) {
            $settings['resize'] = isset($data['resize']) ? $data['resize'] : 'proportional';
            $add .= " resize=\"{$settings['resize']}\"";
            if ($settings['resize'] == 'pad') {
                if (isset($data['padding_transparent'])) {
                    $data['padding_color'] = 'transparent';
                }
                if (empty($data['padding_color'])) {
                    $data['padding_color'] = '#FFF';
                }
                if ((strpos($data['padding_color'], '#') !== 0 || !(strlen($data['padding_color']) == 4 || strlen($data['padding_color']) == 7)) && $data['padding_color'] != 'transparent') {
                    $data['padding_color'] = '#FFF';
                }
                $settings['padding_color'] = $data['padding_color'];
                $add .= " padding_color=\"{$data['padding_color']}\"";
            }
        } else {
            if (!isset($data['raw_mode'])) {
                $settings['resize'] = 'stretch';
                $add .= ' resize="stretch"';
            }
        }
    }
    $field = apply_filters('wpcf_fields_image_editor_submit_field', $field);
    // Save settings
    wpcf_admin_fields_save_field_last_settings($field['id'], $settings);
    if ($context == 'usermeta') {
        $add .= wpcf_get_usermeta_form_addon_submit();
        $shortcode = wpcf_usermeta_get_shortcode($field, $add);
    } elseif ($context == 'termmeta') {
        $add .= wpcf_get_termmeta_form_addon_submit();
        $shortcode = wpcf_termmeta_get_shortcode($field, $add);
    } else {
        $shortcode = wpcf_fields_get_shortcode($field, $add);
    }
    return $shortcode;
}
Example #6
0
/**
 * Editor callback form submit.
 */
function wpcf_fields_video_editor_submit($data, $field, $context)
{
    $add = '';
    if (!empty($data['width'])) {
        $add .= " width=\"{$data['width']}\"";
    }
    if (!empty($data['height'])) {
        $add .= " height=\"{$data['height']}\"";
    }
    if (!empty($data['poster'])) {
        $add .= " poster=\"{$data['poster']}\"";
    }
    if (!empty($data['loop'])) {
        $add .= " loop=\"{$data['loop']}\"";
    }
    if (!empty($data['autoplay'])) {
        $add .= " autoplay=\"{$data['autoplay']}\"";
    }
    if (!empty($data['preload'])) {
        $add .= " preload=\"{$data['preload']}\"";
    }
    if ($context == 'usermeta') {
        $add .= wpcf_get_usermeta_form_addon_submit();
        $shortcode = wpcf_usermeta_get_shortcode($field, $add);
    } elseif ($context == 'termmeta') {
        $add .= wpcf_get_termmeta_form_addon_submit();
        $shortcode = wpcf_termmeta_get_shortcode($field, $add);
    } else {
        $shortcode = wpcf_fields_get_shortcode($field, $add);
    }
    return $shortcode;
}
Example #7
0
/**
 * Editor callback form submit.
 */
function wpcf_fields_embed_editor_submit($data, $field, $context)
{
    $add = '';
    if (!empty($data['width'])) {
        $add .= " width=\"{$data['width']}\"";
    }
    if (!empty($data['height'])) {
        $add .= " height=\"{$data['height']}\"";
    }
    if ($context == 'usermeta') {
        $add .= wpcf_get_usermeta_form_addon_submit();
        $shortcode = wpcf_usermeta_get_shortcode($field, $add);
    } elseif ($context == 'termmeta') {
        $add .= wpcf_get_termmeta_form_addon_submit();
        $shortcode = wpcf_termmeta_get_shortcode($field, $add);
    } else {
        $shortcode = wpcf_fields_get_shortcode($field, $add);
    }
    return $shortcode;
}
Example #8
0
 /**
  * Process if submitted.
  *
  * Field should provide callback function
  * that will be called automatically.
  *
  * Function should be named like:
  * 'wpcf_fields_' . $field_type . '_editor_submit'
  * e.g. 'wpcf_fields_checkbox_editor_submit'
  *
  * Function should return shortcode string.
  */
 function _thickbox_check_submit()
 {
     if (!empty($_POST['__types_editor_nonce']) && wp_verify_nonce($_POST['__types_editor_nonce'], 'types_editor_frame')) {
         $function = 'wpcf_fields_' . strtolower($this->field['type']) . '_editor_submit';
         $shortcode = '';
         if (function_exists($function)) {
             /*
              * Callback
              */
             $shortcode = call_user_func($function, $_POST, $this->field, $this->_meta_type);
         } else {
             /*
              * Generic
              */
             if ($this->_meta_type == 'usermeta') {
                 $add = wpcf_get_usermeta_form_addon_submit();
                 $shortcode = wpcf_usermeta_get_shortcode($this->field, $add);
             } elseif ($this->_meta_type == 'termmeta') {
                 $add = wpcf_get_termmeta_form_addon_submit();
                 $shortcode = wpcf_termmeta_get_shortcode($this->field, $add);
             } else {
                 $shortcode = wpcf_fields_get_shortcode($this->field);
             }
         }
         if (!empty($shortcode)) {
             /**
              * remove <script> tag from all data
              * remove not allowed tags from shortcode using wp_kses_post
              */
             $shortcode = preg_replace('@</?script[^>]*>@im', '', wp_kses_post($shortcode));
             // Add additional parameters if required
             $shortcode = $this->_add_parameters_to_shortcode($shortcode, $_POST);
             // Insert shortcode
             echo '<script type="text/javascript">jQuery(function(){tedFrame.close(\'' . $shortcode . '\', \'' . esc_js($shortcode) . '\');});</script>';
         } else {
             echo '<div class="message error"><p>' . __('Shortcode generation failed', 'wpcf') . '</p></div>';
         }
         wpcf_admin_ajax_footer();
         die;
     }
 }
Example #9
0
/**
 * Inserts shortcode in editor.
 * 
 * @return type 
 */
function wpcf_fields_date_editor_submit($data, $field, $context)
{
    $add = ' ';
    $raw = !empty($data['raw_mode']);
    $format = get_option('date_format');
    $style = isset($data['style']) ? $data['style'] : 'text';
    if (!$raw) {
        $add .= 'style="' . $style . '"';
        if ($style == 'text') {
            if (isset($data['format'])) {
                if ($data['format'] == 'custom' && isset($data['custom'])) {
                    $format = $data['custom'];
                } else {
                    $format = $data['format'];
                }
            }
            $add .= ' format="' . $format . '"';
        }
    }
    if ($context == 'usermeta') {
        $add .= wpcf_get_usermeta_form_addon_submit();
        $shortcode = wpcf_usermeta_get_shortcode($field, $add);
    } elseif ($context == 'termmeta') {
        $add .= wpcf_get_termmeta_form_addon_submit();
        $shortcode = wpcf_termmeta_get_shortcode($field, $add);
    } else {
        $shortcode = wpcf_fields_get_shortcode($field, $add);
    }
    return $shortcode;
}
Example #10
0
/**
 * Editor callback form submit.
 */
function wpcf_fields_checkboxes_editor_submit($data, $field, $context)
{
    $add = '';
    $shortcode = '';
    if ($context == 'usermeta') {
        $add .= wpcf_get_usermeta_form_addon_submit();
    } elseif ($context == 'termmeta') {
        $add .= wpcf_get_termmeta_form_addon_submit();
    }
    if (!empty($data['options'])) {
        if ($data['display'] == 'display_all') {
            $separator = !empty($data['cbs_separator']) ? $data['cbs_separator'] : '';
            $_add = $add . ' separator="' . $separator . '"';
            if ($context == 'usermeta') {
                $shortcode .= wpcf_usermeta_get_shortcode($field, $_add);
            } elseif ($context == 'termmeta') {
                $shortcode = wpcf_termmeta_get_shortcode($field, $add);
            } else {
                $shortcode .= wpcf_fields_get_shortcode($field, $_add);
            }
        } else {
            $i = 0;
            foreach ($data['options'] as $option) {
                if ($data['display'] == 'value') {
                    $checked_add = $add . ' option="' . $i . '" state="checked"';
                    $unchecked_add = $add . ' option="' . $i . '" state="unchecked"';
                    if ($context == 'usermeta') {
                        $shortcode_checked = wpcf_usermeta_get_shortcode($field, $checked_add, $option['selected']);
                        $shortcode_unchecked = wpcf_usermeta_get_shortcode($field, $unchecked_add, $option['not_selected']);
                    } elseif ($context == 'termmeta') {
                        $shortcode_checked = wpcf_termmeta_get_shortcode($field, $checked_add, $option['selected']);
                        $shortcode_unchecked = wpcf_termmeta_get_shortcode($field, $unchecked_add, $option['not_selected']);
                    } else {
                        $shortcode_checked = wpcf_fields_get_shortcode($field, $checked_add, $option['selected']);
                        $shortcode_unchecked = wpcf_fields_get_shortcode($field, $unchecked_add, $option['not_selected']);
                    }
                    $shortcode .= $shortcode_checked . $shortcode_unchecked;
                } else {
                    $add = ' option="' . $i . '"';
                    if ($context == 'usermeta') {
                        $add .= wpcf_get_usermeta_form_addon_submit();
                        $shortcode .= wpcf_usermeta_get_shortcode($field, $add);
                    } elseif ($context == 'termmeta') {
                        $add .= wpcf_get_termmeta_form_addon_submit();
                        $shortcode = wpcf_termmeta_get_shortcode($field, $add);
                    } else {
                        $shortcode .= wpcf_fields_get_shortcode($field, $add);
                    }
                }
                $i++;
            }
        }
    } else {
        if ($context == 'usermeta') {
            $shortcode .= wpcf_usermeta_get_shortcode($field, $add);
        } elseif ($context == 'termmeta') {
            $shortcode = wpcf_termmeta_get_shortcode($field, $add);
        } else {
            $shortcode .= wpcf_fields_get_shortcode($field, $add);
        }
    }
    return $shortcode;
}