Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like FrmFieldsHelper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FrmFieldsHelper, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class FrmFieldsHelper { |
||
| 7 | |||
| 8 | public static function setup_new_vars( $type = '', $form_id = '' ) { |
||
| 9 | |||
| 10 | if ( strpos($type, '|') ) { |
||
| 11 | list($type, $setting) = explode('|', $type); |
||
| 12 | } |
||
| 13 | |||
| 14 | $values = self::get_default_field( $type ); |
||
| 15 | |||
| 16 | global $wpdb; |
||
| 17 | $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) ); |
||
| 18 | |||
| 19 | $values['field_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' ); |
||
| 20 | $values['form_id'] = $form_id; |
||
| 21 | $values['field_order'] = $field_count + 1; |
||
| 22 | $values['field_options']['custom_html'] = self::get_default_html( $type ); |
||
| 23 | |||
| 24 | if ( isset( $setting ) && ! empty( $setting ) ) { |
||
| 25 | if ( in_array( $type, array( 'data', 'lookup' ) ) ) { |
||
| 26 | $values['field_options']['data_type'] = $setting; |
||
| 27 | } else { |
||
| 28 | $values['field_options'][ $setting ] = 1; |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | return $values; |
||
| 33 | } |
||
| 34 | |||
| 35 | public static function get_html_id( $field, $plus = '' ) { |
||
| 36 | return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field ); |
||
| 37 | } |
||
| 38 | |||
| 39 | public static function setup_edit_vars( $field, $doing_ajax = false ) { |
||
| 40 | $values = self::field_object_to_array( $field ); |
||
| 41 | return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) ); |
||
| 42 | } |
||
| 43 | |||
| 44 | public static function field_object_to_array( $field ) { |
||
| 45 | $values = (array) $field; |
||
| 46 | |||
| 47 | self::fill_field_array( $field, $values ); |
||
| 48 | |||
| 49 | $values['custom_html'] = ( isset( $field->field_options['custom_html'] ) ) ? $field->field_options['custom_html'] : self::get_default_html( $field->type ); |
||
| 50 | |||
| 51 | return $values; |
||
| 52 | } |
||
| 53 | |||
| 54 | private static function fill_field_array( $field, array &$field_array ) { |
||
| 55 | $field_array['options'] = $field->options; |
||
| 56 | $field_array['value'] = $field->default_value; |
||
| 57 | |||
| 58 | self::prepare_edit_front_field( $field_array, $field ); |
||
| 59 | |||
| 60 | $field_array = array_merge( $field->field_options, $field_array ); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Prepare field while creating a new entry |
||
| 65 | * @since 3.0 |
||
| 66 | */ |
||
| 67 | public static function prepare_new_front_field( &$field_array, $field, $args = array() ) { |
||
| 68 | $args['action'] = 'new'; |
||
| 69 | self::prepare_front_field( $field_array, $field, $args ); |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Prepare field while editing an entry |
||
| 74 | * @since 3.0 |
||
| 75 | */ |
||
| 76 | public static function prepare_edit_front_field( &$field_array, $field, $entry_id = 0, $args = array() ) { |
||
| 77 | $args['entry_id'] = $entry_id; |
||
| 78 | $args['action'] = 'edit'; |
||
| 79 | self::prepare_front_field( $field_array, $field, $args ); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Prepare field while creating a new entry |
||
| 84 | * @since 3.0 |
||
| 85 | */ |
||
| 86 | private static function prepare_front_field( &$field_array, $field, $args ) { |
||
| 87 | self::fill_default_field_opts( $field, $field_array ); |
||
| 88 | self::fill_cleared_strings( $field, $field_array ); |
||
| 89 | |||
| 90 | // Track the original field's type |
||
| 91 | $field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type; |
||
| 92 | |||
| 93 | self::prepare_field_options_for_display( $field_array, $field, $args ); |
||
| 94 | |||
| 95 | if ( $args['action'] == 'edit' ) { |
||
| 96 | $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $args['entry_id'], $args ); |
||
| 97 | } else { |
||
| 98 | $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args ); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @since 3.0 |
||
| 104 | * |
||
| 105 | * @param string $type |
||
| 106 | * |
||
| 107 | * @return array |
||
| 108 | */ |
||
| 109 | public static function get_default_field_options( $type ) { |
||
| 110 | $field_type = FrmFieldFactory::get_field_type( $type ); |
||
| 111 | return $field_type->get_default_field_options(); |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @since 3.0 |
||
| 116 | * |
||
| 117 | * @param object $field |
||
| 118 | * @param array $values |
||
| 119 | */ |
||
| 120 | private static function fill_default_field_opts( $field, array &$values ) { |
||
| 121 | $check_post = FrmAppHelper::is_admin() && $_POST && isset( $_POST['field_options'] ); |
||
| 122 | |||
| 123 | $defaults = self::get_default_field_options_from_field( $field, $values ); |
||
| 124 | if ( ! $check_post ) { |
||
| 125 | $defaults['required_indicator'] = ''; |
||
| 126 | $defaults['original_type'] = $field->type; |
||
| 127 | } |
||
| 128 | |||
| 129 | foreach ( $defaults as $opt => $default ) { |
||
| 130 | $values[ $opt ] = isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default; |
||
| 131 | |||
| 132 | if ( $check_post ) { |
||
| 133 | self::get_posted_field_setting( $opt . '_' . $field->id, $values[ $opt ] ); |
||
| 134 | } |
||
| 135 | |||
| 136 | unset( $opt, $default ); |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Fill the required message, invalid message, |
||
| 142 | * and refill the HTML when cleared |
||
| 143 | * |
||
| 144 | * @since 3.0 |
||
| 145 | * |
||
| 146 | * @param object $field |
||
| 147 | * @param array $field_array |
||
| 148 | */ |
||
| 149 | private static function fill_cleared_strings( $field, array &$field_array ) { |
||
| 150 | $frm_settings = FrmAppHelper::get_settings(); |
||
| 151 | |||
| 152 | if ( '' == $field_array['blank'] && '1' === $field_array['required'] ) { |
||
| 153 | $field_array['blank'] = $frm_settings->blank_msg; |
||
| 154 | } |
||
| 155 | |||
| 156 | if ( '' == $field_array['invalid'] ) { |
||
| 157 | if ( 'captcha' === $field->type ) { |
||
| 158 | $field_array['invalid'] = $frm_settings->re_msg; |
||
| 159 | } else { |
||
| 160 | $field_array['invalid'] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] ); |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | if ( '' == $field_array['custom_html'] ) { |
||
| 165 | $field_array['custom_html'] = FrmFieldsHelper::get_default_html( $field->type ); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @since 3.0 |
||
| 171 | * |
||
| 172 | * @param string $setting |
||
| 173 | * @param mixed $current |
||
|
|
|||
| 174 | */ |
||
| 175 | private static function get_posted_field_setting( $setting, &$value ) { |
||
| 176 | if ( isset( $_POST['field_options'][ $setting ] ) ) { |
||
| 177 | $value = maybe_unserialize( $_POST['field_options'][ $setting ] ); |
||
| 178 | if ( strpos( $setting, 'html' ) !== false ) { |
||
| 179 | // strip slashes from HTML but not regex |
||
| 180 | $value = stripslashes_deep( $value ); |
||
| 181 | } |
||
| 182 | } |
||
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @since 3.0 |
||
| 187 | * |
||
| 188 | * @param object $field |
||
| 189 | * @param array $values The field array is needed for hooks |
||
| 190 | * |
||
| 191 | * @return array |
||
| 192 | */ |
||
| 193 | public static function get_default_field_options_from_field( $field, $values = array() ) { |
||
| 194 | $field_type = self::get_original_field( $field ); |
||
| 195 | $opts = $field_type->get_default_field_options(); |
||
| 196 | |||
| 197 | $opts = apply_filters( 'frm_default_field_opts', $opts, $values, $field ); |
||
| 198 | $opts = apply_filters( 'frm_default_' . $field->type . '_field_opts', $opts, $values, $field ); |
||
| 199 | |||
| 200 | return $opts; |
||
| 201 | } |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @since 3.0 |
||
| 205 | * |
||
| 206 | * @param object $field |
||
| 207 | * |
||
| 208 | * @return array |
||
| 209 | */ |
||
| 210 | private static function get_original_field( $field ) { |
||
| 211 | $original_type = FrmField::get_option( $field, 'original_type' ); |
||
| 212 | if ( ! empty( $original_type ) && $field->type != $original_type ) { |
||
| 213 | $field->type = $original_type; |
||
| 214 | } |
||
| 215 | return FrmFieldFactory::get_field_object( $field ); |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @since 3.0 |
||
| 220 | * |
||
| 221 | * @param array $field_array |
||
| 222 | * @param object $field |
||
| 223 | * @param array $atts |
||
| 224 | */ |
||
| 225 | private static function prepare_field_options_for_display( &$field_array, $field, $atts ) { |
||
| 226 | $field_obj = FrmFieldFactory::get_field_object( $field ); |
||
| 227 | $field_array = $field_obj->prepare_front_field( $field_array, $atts ); |
||
| 228 | } |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @since 3.0 |
||
| 232 | * |
||
| 233 | * @param string $type |
||
| 234 | * |
||
| 235 | * @return array |
||
| 236 | */ |
||
| 237 | public static function get_default_field( $type ) { |
||
| 238 | $field_type = FrmFieldFactory::get_field_type( $type ); |
||
| 239 | return $field_type->get_new_field_defaults(); |
||
| 240 | } |
||
| 241 | |||
| 242 | public static function fill_field( &$values, $field, $form_id, $new_key = '' ) { |
||
| 243 | global $wpdb; |
||
| 244 | |||
| 245 | $values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' ); |
||
| 246 | $values['form_id'] = $form_id; |
||
| 247 | $values['options'] = maybe_serialize($field->options); |
||
| 248 | $values['default_value'] = maybe_serialize($field->default_value); |
||
| 249 | |||
| 250 | foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) { |
||
| 251 | $values[ $col ] = $field->{$col}; |
||
| 252 | } |
||
| 253 | } |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @since 2.0 |
||
| 257 | * |
||
| 258 | * @param $field |
||
| 259 | * @param $error |
||
| 260 | * |
||
| 261 | * @return string |
||
| 262 | */ |
||
| 263 | public static function get_error_msg( $field, $error ) { |
||
| 264 | $frm_settings = FrmAppHelper::get_settings(); |
||
| 265 | $default_settings = $frm_settings->default_options(); |
||
| 266 | $field_name = is_array( $field ) ? $field['name'] : $field->name; |
||
| 267 | |||
| 268 | $conf_msg = __( 'The entered values do not match', 'formidable' ); |
||
| 269 | $defaults = array( |
||
| 270 | 'unique_msg' => array( |
||
| 271 | 'full' => $default_settings['unique_msg'], |
||
| 272 | 'part' => sprintf( __('%s must be unique', 'formidable' ), $field_name ), |
||
| 273 | ), |
||
| 274 | 'invalid' => array( |
||
| 275 | 'full' => __( 'This field is invalid', 'formidable' ), |
||
| 276 | 'part' => sprintf( __('%s is invalid', 'formidable' ), $field_name ), |
||
| 277 | ), |
||
| 278 | 'blank' => array( |
||
| 279 | 'full' => $frm_settings->blank_msg, |
||
| 280 | 'part' => $frm_settings->blank_msg, |
||
| 281 | ), |
||
| 282 | 'conf_msg' => array( |
||
| 283 | 'full' => $conf_msg, |
||
| 284 | 'part' => $conf_msg, |
||
| 285 | ), |
||
| 286 | ); |
||
| 287 | |||
| 288 | $msg = FrmField::get_option( $field, $error ); |
||
| 289 | $msg = empty( $msg ) ? $defaults[ $error ]['part'] : $msg; |
||
| 290 | $msg = do_shortcode( $msg ); |
||
| 291 | return $msg; |
||
| 292 | } |
||
| 293 | |||
| 294 | public static function get_form_fields( $form_id, $error = array() ) { |
||
| 295 | $fields = FrmField::get_all_for_form( $form_id ); |
||
| 296 | return apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error ); |
||
| 297 | } |
||
| 298 | |||
| 299 | public static function get_default_html( $type = 'text' ) { |
||
| 300 | $field = FrmFieldFactory::get_field_type( $type ); |
||
| 301 | $default_html = $field->default_html(); |
||
| 302 | |||
| 303 | // these hooks are here for reverse compatibility since 3.0 |
||
| 304 | if ( ! apply_filters( 'frm_normal_field_type_html', true, $type ) ) { |
||
| 305 | $default_html = apply_filters( 'frm_other_custom_html', '', $type ); |
||
| 306 | } |
||
| 307 | |||
| 308 | return apply_filters('frm_custom_html', $default_html, $type); |
||
| 309 | } |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @param array $fields |
||
| 313 | * @param array $errors |
||
| 314 | * @param object $form |
||
| 315 | * @param $form_action |
||
| 316 | */ |
||
| 317 | public static function show_fields( $fields, $errors, $form, $form_action ) { |
||
| 318 | foreach ( $fields as $field ) { |
||
| 319 | $field_obj = FrmFieldFactory::get_field_type( $field['type'], $field ); |
||
| 320 | $field_obj->show_field( compact( 'errors', 'form', 'form_action' ) ); |
||
| 321 | } |
||
| 322 | } |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @param string $html |
||
| 326 | * @param array $field |
||
| 327 | * @param array $errors |
||
| 328 | * @param object $form |
||
| 329 | * @param array $args |
||
| 330 | * |
||
| 331 | * @return string |
||
| 332 | */ |
||
| 333 | public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) { |
||
| 334 | _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldType::prepare_field_html' ); |
||
| 335 | $field_obj = FrmFieldFactory::get_field_type( $field['type'], $field ); |
||
| 336 | return $field_obj->prepare_field_html( compact( 'errors', 'form' ) ); |
||
| 337 | } |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @since 3.0 |
||
| 341 | * |
||
| 342 | * @param array $atts |
||
| 343 | * @param string|array $value |
||
| 344 | */ |
||
| 345 | public static function run_wpautop( $atts, &$value ) { |
||
| 346 | $autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true; |
||
| 347 | if ( apply_filters( 'frm_use_wpautop', $autop ) ) { |
||
| 348 | if ( is_array( $value ) ) { |
||
| 349 | $value = implode( "\n", $value ); |
||
| 350 | } |
||
| 351 | $value = wpautop( $value ); |
||
| 352 | } |
||
| 353 | } |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Get the class to use for the label position |
||
| 357 | * @since 2.05 |
||
| 358 | */ |
||
| 359 | public static function &label_position( $position, $field, $form ) { |
||
| 360 | if ( $position && $position != '' ) { |
||
| 361 | return $position; |
||
| 362 | } |
||
| 363 | |||
| 364 | $position = FrmStylesController::get_style_val( 'position', $form ); |
||
| 365 | if ( $position == 'none' ) { |
||
| 366 | $position = 'top'; |
||
| 367 | } elseif ( $position == 'no_label' ) { |
||
| 368 | $position = 'none'; |
||
| 369 | } elseif ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) { |
||
| 370 | $position = 'top'; |
||
| 371 | } |
||
| 372 | |||
| 373 | $position = apply_filters( 'frm_html_label_position', $position, $field, $form ); |
||
| 374 | $position = ( ! empty( $position ) ) ? $position : 'top'; |
||
| 375 | |||
| 376 | return $position; |
||
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Check if this field type allows placeholders |
||
| 381 | * @since 2.05 |
||
| 382 | */ |
||
| 383 | public static function is_placeholder_field_type( $type ) { |
||
| 384 | return ! in_array( $type, array( 'select', 'radio', 'checkbox', 'hidden', 'file' ) ); |
||
| 385 | } |
||
| 386 | |||
| 387 | public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) { |
||
| 388 | _deprecated_function( __FUNCTION__, '3.0', 'FrmShortcodeHelper::remove_inline_conditions' ); |
||
| 389 | FrmShortcodeHelper::remove_inline_conditions( $no_vars, $code, $replace_with, $html ); |
||
| 390 | } |
||
| 391 | |||
| 392 | public static function get_shortcode_tag( $shortcodes, $short_key, $args ) { |
||
| 393 | _deprecated_function( __FUNCTION__, '3.0', 'FrmShortcodeHelper::get_shortcode_tag' ); |
||
| 394 | return FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key, $args ); |
||
| 395 | } |
||
| 396 | |||
| 397 | public static function get_checkbox_id( $field, $opt_key ) { |
||
| 398 | $id = $field['id']; |
||
| 399 | if ( isset( $field['in_section'] ) && $field['in_section'] ) { |
||
| 400 | $id .= '-' . $field['in_section']; |
||
| 401 | } |
||
| 402 | return 'frm_checkbox_' . $id . '-' . $opt_key; |
||
| 403 | } |
||
| 404 | |||
| 405 | public static function display_recaptcha( $field ) { |
||
| 406 | _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' ); |
||
| 407 | } |
||
| 408 | |||
| 409 | public static function show_single_option( $field ) { |
||
| 410 | if ( ! is_array( $field['options'] ) ) { |
||
| 411 | return; |
||
| 412 | } |
||
| 413 | |||
| 414 | $field_name = isset( $field['html_name'] ) ? $field['html_name'] : $field['name']; |
||
| 415 | $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field ); |
||
| 416 | |||
| 417 | foreach ( $field['options'] as $opt_key => $opt ) { |
||
| 418 | $field_val = self::get_value_from_array( $opt, $opt_key, $field ); |
||
| 419 | $opt = self::get_label_from_array( $opt, $opt_key, $field ); |
||
| 420 | |||
| 421 | // Get string for Other text field, if needed |
||
| 422 | $other_val = self::get_other_val( compact( 'opt_key', 'field' ) ); |
||
| 423 | |||
| 424 | $checked = ( $other_val || isset( $field['value'] ) && ( ( ! is_array( $field['value'] ) && $field['value'] == $field_val ) || ( is_array($field['value'] ) && in_array( $field_val, $field['value'] ) ) ) ) ? ' checked="checked"' : ''; |
||
| 425 | |||
| 426 | // If this is an "Other" option, get the HTML for it |
||
| 427 | if ( self::is_other_opt( $opt_key ) ) { |
||
| 428 | if ( FrmAppHelper::pro_is_installed() ) { |
||
| 429 | require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' ); |
||
| 430 | } |
||
| 431 | } else { |
||
| 432 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); |
||
| 433 | } |
||
| 434 | |||
| 435 | unset( $checked, $other_val ); |
||
| 436 | } |
||
| 437 | } |
||
| 438 | |||
| 439 | public static function get_value_from_array( $opt, $opt_key, $field ) { |
||
| 440 | $opt = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field ); |
||
| 441 | return FrmFieldsController::check_value( $opt, $opt_key, $field ); |
||
| 442 | } |
||
| 443 | |||
| 444 | public static function get_label_from_array( $opt, $opt_key, $field ) { |
||
| 445 | $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field ); |
||
| 446 | return FrmFieldsController::check_label( $opt ); |
||
| 447 | } |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @param int $tax_id |
||
| 451 | * |
||
| 452 | * @return string |
||
| 453 | */ |
||
| 454 | public static function get_term_link( $tax_id ) { |
||
| 455 | $tax = get_taxonomy($tax_id); |
||
| 456 | if ( ! $tax ) { |
||
| 457 | return ''; |
||
| 458 | } |
||
| 459 | |||
| 460 | $link = sprintf( |
||
| 461 | __( 'Please add options from the WordPress "%1$s" page', 'formidable' ), |
||
| 462 | '<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">' . ( empty( $tax->labels->name ) ? __( 'Categories' ) : $tax->labels->name ) . '</a>' |
||
| 463 | ); |
||
| 464 | unset($tax); |
||
| 465 | |||
| 466 | return $link; |
||
| 467 | } |
||
| 468 | |||
| 469 | public static function value_meets_condition( $observed_value, $cond, $hide_opt ) { |
||
| 470 | $hide_opt = self::get_value_for_comparision( $hide_opt ); |
||
| 471 | $observed_value = self::get_value_for_comparision( $observed_value ); |
||
| 472 | |||
| 473 | if ( is_array($observed_value) ) { |
||
| 474 | return self::array_value_condition($observed_value, $cond, $hide_opt); |
||
| 475 | } |
||
| 476 | |||
| 477 | $m = false; |
||
| 478 | if ( $cond == '==' ) { |
||
| 479 | $m = $observed_value == $hide_opt; |
||
| 480 | } else if ( $cond == '!=' ) { |
||
| 481 | $m = $observed_value != $hide_opt; |
||
| 482 | } else if ( $cond == '>' ) { |
||
| 483 | $m = $observed_value > $hide_opt; |
||
| 484 | } else if ( $cond == '<' ) { |
||
| 485 | $m = $observed_value < $hide_opt; |
||
| 486 | } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
||
| 487 | $m = stripos($observed_value, $hide_opt); |
||
| 488 | if ( $cond == 'not LIKE' ) { |
||
| 489 | $m = ( $m === false ) ? true : false; |
||
| 490 | } else { |
||
| 491 | $m = ( $m === false ) ? false : true; |
||
| 492 | } |
||
| 493 | } |
||
| 494 | return $m; |
||
| 495 | } |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Trim and sanitize the values |
||
| 499 | * @since 2.05 |
||
| 500 | */ |
||
| 501 | private static function get_value_for_comparision( $value ) { |
||
| 502 | // Remove white space from hide_opt |
||
| 503 | if ( ! is_array( $value ) ) { |
||
| 504 | $value = trim( $value ); |
||
| 505 | } |
||
| 506 | |||
| 507 | return wp_kses_post( $value ); |
||
| 508 | } |
||
| 509 | |||
| 510 | public static function array_value_condition( $observed_value, $cond, $hide_opt ) { |
||
| 511 | $m = false; |
||
| 512 | if ( $cond == '==' ) { |
||
| 513 | if ( is_array($hide_opt) ) { |
||
| 514 | $m = array_intersect($hide_opt, $observed_value); |
||
| 515 | $m = empty($m) ? false : true; |
||
| 516 | } else { |
||
| 517 | $m = in_array($hide_opt, $observed_value); |
||
| 518 | } |
||
| 519 | } else if ( $cond == '!=' ) { |
||
| 520 | $m = ! in_array($hide_opt, $observed_value); |
||
| 521 | } else if ( $cond == '>' ) { |
||
| 522 | $min = min($observed_value); |
||
| 523 | $m = $min > $hide_opt; |
||
| 524 | } else if ( $cond == '<' ) { |
||
| 525 | $max = max($observed_value); |
||
| 526 | $m = $max < $hide_opt; |
||
| 527 | } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
||
| 528 | foreach ( $observed_value as $ob ) { |
||
| 529 | $m = strpos($ob, $hide_opt); |
||
| 530 | if ( $m !== false ) { |
||
| 531 | $m = true; |
||
| 532 | break; |
||
| 533 | } |
||
| 534 | } |
||
| 535 | |||
| 536 | if ( $cond == 'not LIKE' ) { |
||
| 537 | $m = ( $m === false ) ? true : false; |
||
| 538 | } |
||
| 539 | } |
||
| 540 | |||
| 541 | return $m; |
||
| 542 | } |
||
| 543 | |||
| 544 | /** |
||
| 545 | * Replace a few basic shortcodes and field ids |
||
| 546 | * @since 2.0 |
||
| 547 | * @return string |
||
| 548 | */ |
||
| 549 | public static function basic_replace_shortcodes( $value, $form, $entry ) { |
||
| 550 | if ( strpos($value, '[sitename]') !== false ) { |
||
| 551 | $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
||
| 552 | $value = str_replace('[sitename]', $new_value, $value); |
||
| 553 | } |
||
| 554 | |||
| 555 | $value = apply_filters('frm_content', $value, $form, $entry); |
||
| 556 | $value = do_shortcode($value); |
||
| 557 | |||
| 558 | return $value; |
||
| 559 | } |
||
| 560 | |||
| 561 | public static function get_shortcodes( $content, $form_id ) { |
||
| 562 | if ( FrmAppHelper::pro_is_installed() ) { |
||
| 563 | return FrmProDisplaysHelper::get_shortcodes($content, $form_id); |
||
| 564 | } |
||
| 565 | |||
| 566 | $fields = FrmField::getAll( array( |
||
| 567 | 'fi.form_id' => (int) $form_id, |
||
| 568 | 'fi.type not' => FrmField::no_save_fields(), |
||
| 569 | ) ); |
||
| 570 | |||
| 571 | $tagregexp = self::allowed_shortcodes($fields); |
||
| 572 | |||
| 573 | preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER); |
||
| 574 | |||
| 575 | return $matches; |
||
| 576 | } |
||
| 577 | |||
| 578 | public static function allowed_shortcodes( $fields = array() ) { |
||
| 579 | $tagregexp = array( 'editlink', 'id', 'key', 'ip', 'siteurl', 'sitename', 'admin_email', 'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by', 'parent[-|_]id' ); |
||
| 580 | |||
| 581 | foreach ( $fields as $field ) { |
||
| 582 | $tagregexp[] = $field->id; |
||
| 583 | $tagregexp[] = $field->field_key; |
||
| 584 | } |
||
| 585 | |||
| 586 | $tagregexp = implode('|', $tagregexp); |
||
| 587 | return $tagregexp; |
||
| 588 | } |
||
| 589 | |||
| 590 | public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
||
| 591 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
||
| 592 | if ( empty( $tag ) ) { |
||
| 593 | continue; |
||
| 594 | } |
||
| 595 | |||
| 596 | $atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] ); |
||
| 597 | $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key ); |
||
| 598 | |||
| 599 | $atts['entry'] = $entry; |
||
| 600 | $atts['tag'] = $tag; |
||
| 601 | $replace_with = self::get_value_for_shortcode( $atts ); |
||
| 602 | |||
| 603 | if ( $replace_with !== null ) { |
||
| 604 | $content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content ); |
||
| 605 | } |
||
| 606 | |||
| 607 | unset( $atts, $replace_with ); |
||
| 608 | } |
||
| 609 | |||
| 610 | return $content; |
||
| 611 | } |
||
| 612 | |||
| 613 | /** |
||
| 614 | * @since 3.0 |
||
| 615 | * |
||
| 616 | * @param $atts |
||
| 617 | * |
||
| 618 | * @return string |
||
| 619 | */ |
||
| 620 | private static function get_value_for_shortcode( $atts ) { |
||
| 621 | $clean_tag = str_replace( '-', '_', $atts['tag'] ); |
||
| 622 | |||
| 623 | $shortcode_values = array( |
||
| 624 | 'id' => $atts['entry']->id, |
||
| 625 | 'key' => $atts['entry']->item_key, |
||
| 626 | 'ip' => $atts['entry']->ip, |
||
| 627 | ); |
||
| 628 | |||
| 629 | $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' ); |
||
| 630 | |||
| 631 | if ( isset( $shortcode_values[ $atts['tag'] ] ) ) { |
||
| 632 | $replace_with = $shortcode_values[ $atts['tag'] ]; |
||
| 633 | } elseif ( in_array( $atts['tag'], $dynamic_default ) ) { |
||
| 634 | $replace_with = self::dynamic_default_values( $atts['tag'], $atts ); |
||
| 635 | } elseif ( $clean_tag == 'user_agent' ) { |
||
| 636 | $description = maybe_unserialize( $atts['entry']->description ); |
||
| 637 | $replace_with = FrmEntriesHelper::get_browser( $description['browser'] ); |
||
| 638 | } elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) { |
||
| 639 | $atts['tag'] = $clean_tag; |
||
| 640 | $replace_with = self::get_entry_timestamp( $atts ); |
||
| 641 | } elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) { |
||
| 642 | $replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts ); |
||
| 643 | } else { |
||
| 644 | $replace_with = self::get_field_shortcode_value( $atts ); |
||
| 645 | } |
||
| 646 | |||
| 647 | return $replace_with; |
||
| 648 | } |
||
| 649 | |||
| 650 | /** |
||
| 651 | * @since 3.0 |
||
| 652 | * |
||
| 653 | * @param $atts |
||
| 654 | * |
||
| 655 | * @return string |
||
| 656 | */ |
||
| 657 | private static function get_entry_timestamp( $atts ) { |
||
| 658 | if ( isset( $atts['format'] ) ) { |
||
| 659 | $time_format = ' '; |
||
| 660 | } else { |
||
| 661 | $atts['format'] = get_option('date_format'); |
||
| 662 | $time_format = ''; |
||
| 663 | } |
||
| 664 | |||
| 665 | return FrmAppHelper::get_formatted_time( $atts['entry']->{$atts['tag']}, $atts['format'], $time_format ); |
||
| 666 | } |
||
| 667 | |||
| 668 | /** |
||
| 669 | * @since 3.0 |
||
| 670 | * |
||
| 671 | * @param $atts |
||
| 672 | * |
||
| 673 | * @return null|string |
||
| 674 | */ |
||
| 675 | private static function get_field_shortcode_value( $atts ) { |
||
| 676 | $field = FrmField::getOne( $atts['tag'] ); |
||
| 677 | if ( empty( $field ) ) { |
||
| 678 | return null; |
||
| 679 | } |
||
| 680 | |||
| 681 | if ( isset( $atts['show'] ) && $atts['show'] == 'field_label' ) { |
||
| 682 | $replace_with = $field->name; |
||
| 683 | } elseif ( isset( $atts['show'] ) && $atts['show'] == 'description' ) { |
||
| 684 | $replace_with = $field->description; |
||
| 685 | } else { |
||
| 686 | $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id ); |
||
| 687 | $string_value = $replace_with; |
||
| 688 | if ( is_array( $replace_with ) ) { |
||
| 689 | $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', '; |
||
| 690 | $string_value = implode( $sep, $replace_with ); |
||
| 691 | } |
||
| 692 | |||
| 693 | if ( empty( $string_value ) && $string_value != '0' ) { |
||
| 694 | $replace_with = ''; |
||
| 695 | } else { |
||
| 696 | $atts['entry_id'] = $atts['entry']->id; |
||
| 697 | $atts['entry_key'] = $atts['entry']->item_key; |
||
| 698 | $replace_with = self::get_display_value( $replace_with, $field, $atts ); |
||
| 699 | } |
||
| 700 | } |
||
| 701 | |||
| 702 | return $replace_with; |
||
| 703 | } |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Get the value to replace a few standard shortcodes |
||
| 707 | * |
||
| 708 | * @since 2.0 |
||
| 709 | * @return string |
||
| 710 | */ |
||
| 711 | public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) { |
||
| 712 | $new_value = ''; |
||
| 713 | switch ( $tag ) { |
||
| 714 | case 'admin_email': |
||
| 715 | $new_value = get_option('admin_email'); |
||
| 716 | break; |
||
| 717 | case 'siteurl': |
||
| 718 | $new_value = FrmAppHelper::site_url(); |
||
| 719 | break; |
||
| 720 | case 'frmurl': |
||
| 721 | $new_value = FrmAppHelper::plugin_url(); |
||
| 722 | break; |
||
| 723 | case 'sitename': |
||
| 724 | $new_value = FrmAppHelper::site_name(); |
||
| 725 | break; |
||
| 726 | case 'get': |
||
| 727 | $new_value = self::process_get_shortcode( $atts, $return_array ); |
||
| 728 | } |
||
| 729 | |||
| 730 | return $new_value; |
||
| 731 | } |
||
| 732 | |||
| 733 | /** |
||
| 734 | * Process the [get] shortcode |
||
| 735 | * |
||
| 736 | * @since 2.0 |
||
| 737 | * @return string|array |
||
| 738 | */ |
||
| 739 | public static function process_get_shortcode( $atts, $return_array = false ) { |
||
| 740 | if ( ! isset($atts['param']) ) { |
||
| 741 | return ''; |
||
| 742 | } |
||
| 743 | |||
| 744 | if ( strpos($atts['param'], '[') ) { |
||
| 745 | $atts['param'] = str_replace('[', '[', $atts['param']); |
||
| 746 | $atts['param'] = str_replace(']', ']', $atts['param']); |
||
| 747 | } |
||
| 748 | |||
| 749 | $new_value = FrmAppHelper::get_param( $atts['param'], '', 'get', 'sanitize_text_field' ); |
||
| 750 | $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] ); |
||
| 751 | |||
| 752 | if ( $new_value == '' ) { |
||
| 753 | if ( ! isset($atts['prev_val']) ) { |
||
| 754 | $atts['prev_val'] = ''; |
||
| 755 | } |
||
| 756 | |||
| 757 | $new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val']; |
||
| 758 | } |
||
| 759 | |||
| 760 | if ( is_array($new_value) && ! $return_array ) { |
||
| 761 | $new_value = implode(', ', $new_value); |
||
| 762 | } |
||
| 763 | |||
| 764 | return $new_value; |
||
| 765 | } |
||
| 766 | |||
| 767 | public static function get_display_value( $value, $field, $atts = array() ) { |
||
| 768 | |||
| 769 | $value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts ); |
||
| 770 | $value = apply_filters( 'frm_get_display_value', $value, $field, $atts ); |
||
| 771 | |||
| 772 | return self::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) ); |
||
| 773 | } |
||
| 774 | |||
| 775 | /** |
||
| 776 | * @param $atts array Includes value, field, and atts |
||
| 777 | */ |
||
| 778 | public static function get_unfiltered_display_value( $atts ) { |
||
| 779 | $value = $atts['value']; |
||
| 780 | $field = $atts['field']; |
||
| 781 | $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts; |
||
| 782 | |||
| 783 | if ( is_array( $field ) ) { |
||
| 784 | $field = $field['id']; |
||
| 785 | } |
||
| 786 | |||
| 787 | $field_obj = FrmFieldFactory::get_field_object( $field ); |
||
| 788 | return $field_obj->get_display_value( $value, $atts ); |
||
| 789 | } |
||
| 790 | |||
| 791 | /** |
||
| 792 | * Get a value from the user profile from the user ID |
||
| 793 | * @since 3.0 |
||
| 794 | */ |
||
| 795 | public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) { |
||
| 796 | $defaults = array( |
||
| 797 | 'blank' => false, |
||
| 798 | 'link' => false, |
||
| 799 | 'size' => 96, |
||
| 800 | ); |
||
| 801 | |||
| 802 | $args = wp_parse_args($args, $defaults); |
||
| 803 | |||
| 804 | $user = get_userdata($user_id); |
||
| 805 | $info = ''; |
||
| 806 | |||
| 807 | if ( $user ) { |
||
| 808 | if ( $user_info == 'avatar' ) { |
||
| 809 | $info = get_avatar( $user_id, $args['size'] ); |
||
| 810 | } elseif ( $user_info == 'author_link' ) { |
||
| 811 | $info = get_author_posts_url( $user_id ); |
||
| 812 | } else { |
||
| 813 | $info = isset($user->$user_info) ? $user->$user_info : ''; |
||
| 814 | } |
||
| 815 | |||
| 816 | if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) { |
||
| 817 | $info = $user->user_login; |
||
| 818 | } |
||
| 819 | } |
||
| 820 | |||
| 821 | if ( $args['link'] ) { |
||
| 822 | $info = '<a href="' . esc_url( admin_url('user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>'; |
||
| 823 | } |
||
| 824 | |||
| 825 | return $info; |
||
| 826 | } |
||
| 827 | |||
| 828 | public static function get_field_types( $type ) { |
||
| 829 | $single_input = array( 'text', 'textarea', 'rte', 'number', 'email', 'url', 'file', 'date', 'phone', 'hidden', 'time', 'user_id', 'tag', 'password' ); |
||
| 830 | $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' ); |
||
| 831 | $other_type = array( 'html', 'break' ); |
||
| 832 | |||
| 833 | $field_selection = array_merge( FrmField::pro_field_selection(), FrmField::field_selection() ); |
||
| 834 | |||
| 835 | $field_types = array(); |
||
| 836 | if ( in_array($type, $single_input) ) { |
||
| 837 | self::field_types_for_input( $single_input, $field_selection, $field_types ); |
||
| 838 | } else if ( in_array($type, $multiple_input) ) { |
||
| 839 | self::field_types_for_input( $multiple_input, $field_selection, $field_types ); |
||
| 840 | } else if ( in_array($type, $other_type) ) { |
||
| 841 | self::field_types_for_input( $other_type, $field_selection, $field_types ); |
||
| 842 | } else if ( isset( $field_selection[ $type ] ) ) { |
||
| 843 | $field_types[ $type ] = $field_selection[ $type ]; |
||
| 844 | } |
||
| 845 | |||
| 846 | $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type' ) ); |
||
| 847 | return $field_types; |
||
| 848 | } |
||
| 849 | |||
| 850 | private static function field_types_for_input( $inputs, $fields, &$field_types ) { |
||
| 856 | |||
| 857 | /** |
||
| 858 | * Check if current field option is an "other" option |
||
| 859 | * |
||
| 860 | * @since 2.0.6 |
||
| 861 | * |
||
| 862 | * @param string $opt_key |
||
| 863 | * @return boolean Returns true if current field option is an "Other" option |
||
| 864 | */ |
||
| 865 | public static function is_other_opt( $opt_key ) { |
||
| 868 | |||
| 869 | /** |
||
| 870 | * Get value that belongs in "Other" text box |
||
| 871 | * |
||
| 872 | * @since 2.0.6 |
||
| 873 | * |
||
| 874 | * @param array $args |
||
| 875 | */ |
||
| 876 | public static function get_other_val( $args ) { |
||
| 877 | $defaults = array( |
||
| 878 | 'opt_key' => 0, |
||
| 879 | 'field' => array(), |
||
| 880 | 'parent' => false, |
||
| 881 | 'pointer' => false, |
||
| 882 | ); |
||
| 883 | $args = wp_parse_args( $args, $defaults ); |
||
| 884 | |||
| 885 | $opt_key = $args['opt_key']; |
||
| 886 | $field = $args['field']; |
||
| 887 | $parent = $args['parent']; |
||
| 888 | $pointer = $args['pointer']; |
||
| 889 | $other_val = ''; |
||
| 890 | |||
| 891 | // If option is an "other" option and there is a value set for this field, |
||
| 892 | // check if the value belongs in the current "Other" option text field |
||
| 893 | if ( ! FrmFieldsHelper::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) { |
||
| 894 | return $other_val; |
||
| 895 | } |
||
| 896 | |||
| 897 | // Check posted vals before checking saved values |
||
| 898 | |||
| 899 | // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero |
||
| 900 | if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) { |
||
| 901 | if ( FrmField::is_field_with_multiple_values( $field ) ) { |
||
| 902 | $other_val = isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) : ''; |
||
| 903 | } else { |
||
| 904 | $other_val = sanitize_text_field( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ); |
||
| 905 | } |
||
| 906 | return $other_val; |
||
| 907 | |||
| 908 | } else if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { |
||
| 909 | // For normal fields |
||
| 910 | |||
| 911 | if ( FrmField::is_field_with_multiple_values( $field ) ) { |
||
| 912 | $other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) : ''; |
||
| 913 | } else { |
||
| 914 | $other_val = sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ] ); |
||
| 915 | } |
||
| 916 | return $other_val; |
||
| 917 | } |
||
| 955 | |||
| 956 | /** |
||
| 957 | * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val. |
||
| 958 | * Intended for front-end use |
||
| 959 | * |
||
| 960 | * @since 2.0.6 |
||
| 961 | * |
||
| 962 | * @param array $args should include field, opt_key and field name |
||
| 963 | * @param boolean $other_opt |
||
| 964 | * @param string $checked |
||
| 965 | * @return array $other_args |
||
| 966 | */ |
||
| 967 | public static function prepare_other_input( $args, &$other_opt, &$checked ) { |
||
| 985 | |||
| 986 | /** |
||
| 987 | * @param array $args |
||
| 988 | * @param array $other_args |
||
| 989 | * @since 2.0.6 |
||
| 990 | */ |
||
| 991 | private static function set_other_name( $args, &$other_args ) { |
||
| 1003 | |||
| 1004 | /** |
||
| 1005 | * Find the parent and pointer, and get text for "other" text field |
||
| 1006 | * @param array $args |
||
| 1007 | * @param array $other_args |
||
| 1008 | * |
||
| 1009 | * @since 2.0.6 |
||
| 1010 | */ |
||
| 1011 | private static function set_other_value( $args, &$other_args ) { |
||
| 1032 | |||
| 1033 | /** |
||
| 1034 | * If this field includes an other option, show it |
||
| 1035 | * @param $args array |
||
| 1036 | * @since 2.0.6 |
||
| 1037 | */ |
||
| 1038 | public static function include_other_input( $args ) { |
||
| 1063 | |||
| 1064 | /** |
||
| 1065 | * Get the HTML id for an "Other" text field |
||
| 1066 | * Note: This does not affect fields in repeating sections |
||
| 1067 | * |
||
| 1068 | * @since 2.0.08 |
||
| 1069 | * @param string $type - field type |
||
| 1070 | * @param string $html_id |
||
| 1071 | * @param string|boolean $opt_key |
||
| 1072 | * @return string $other_id |
||
| 1073 | */ |
||
| 1074 | public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) { |
||
| 1090 | |||
| 1091 | public static function clear_on_focus_html( $field, $display, $id = '' ) { |
||
| 1107 | |||
| 1108 | View Code Duplication | public static function show_onfocus_js( $is_selected, $has_default_value = true ) { |
|
| 1117 | |||
| 1118 | View Code Duplication | public static function show_default_blank_js( $is_selected, $has_default_value = true ) { |
|
| 1127 | |||
| 1128 | public static function show_icon_link_js( $atts ) { |
||
| 1135 | |||
| 1136 | public static function switch_field_ids( $val ) { |
||
| 1168 | |||
| 1169 | public static function get_us_states() { |
||
| 1224 | |||
| 1225 | public static function get_countries() { |
||
| 1228 | |||
| 1229 | public static function get_bulk_prefilled_opts( array &$prepop ) { |
||
| 1282 | |||
| 1283 | /** |
||
| 1284 | * Display a field value selector |
||
| 1285 | * |
||
| 1286 | * @since 2.03.05 |
||
| 1287 | * |
||
| 1288 | * @param int $selector_field_id |
||
| 1289 | * @param array $selector_args |
||
| 1290 | */ |
||
| 1291 | public static function display_field_value_selector( $selector_field_id, $selector_args ) { |
||
| 1295 | |||
| 1296 | /** |
||
| 1297 | * Convert a field object to a flat array |
||
| 1298 | * |
||
| 1299 | * @since 2.03.05 |
||
| 1300 | * |
||
| 1301 | * @param object $field |
||
| 1302 | * |
||
| 1303 | * @return array |
||
| 1304 | */ |
||
| 1305 | public static function convert_field_object_to_flat_array( $field ) { |
||
| 1311 | |||
| 1312 | public static function get_default_field_opts( $type, $field = null, $limit = false ) { |
||
| 1323 | |||
| 1324 | public static function dropdown_categories( $args ) { |
||
| 1336 | } |
||
| 1337 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.