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 GVCommon 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 GVCommon, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class GVCommon { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Returns the form object for a given Form ID. |
||
| 23 | * |
||
| 24 | * @access public |
||
| 25 | * @param mixed $form_id |
||
| 26 | * @return mixed False: no form ID specified or Gravity Forms isn't active. Array: Form returned from Gravity Forms |
||
| 27 | */ |
||
| 28 | public static function get_form( $form_id ) { |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Alias of GravityView_Roles_Capabilities::has_cap() |
||
| 47 | * |
||
| 48 | * @since 1.15 |
||
| 49 | * |
||
| 50 | * @see GravityView_Roles_Capabilities::has_cap() |
||
| 51 | * |
||
| 52 | * @param string|array $caps Single capability or array of capabilities |
||
| 53 | * @param int $object_id (optional) Parameter can be used to check for capabilities against a specific object, such as a post or user |
||
| 54 | * @param int|null $user_id (optional) Check the capabilities for a user who is not necessarily the currently logged-in user |
||
| 55 | * |
||
| 56 | * @return bool True: user has at least one passed capability; False: user does not have any defined capabilities |
||
| 57 | */ |
||
| 58 | public static function has_cap( $caps = '', $object_id = null, $user_id = null ) { |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Return a Gravity Forms field array, whether using GF 1.9 or not |
||
| 64 | * |
||
| 65 | * @since 1.7 |
||
| 66 | * |
||
| 67 | * @param array|GF_Fields $field Gravity Forms field or array |
||
| 68 | * @return array Array version of $field |
||
| 69 | */ |
||
| 70 | public static function get_field_array( $field ) { |
||
| 71 | |||
| 72 | if ( class_exists( 'GF_Fields' ) ) { |
||
| 73 | |||
| 74 | $field_object = GF_Fields::create( $field ); |
||
| 75 | |||
| 76 | // Convert the field object in 1.9 to an array for backward compatibility |
||
| 77 | $field_array = get_object_vars( $field_object ); |
||
| 78 | |||
| 79 | } else { |
||
| 80 | $field_array = $field; |
||
| 81 | } |
||
| 82 | |||
| 83 | return $field_array; |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Get all existing Views |
||
| 88 | * |
||
| 89 | * @since 1.5.4 |
||
| 90 | * @since TODO Added $args array |
||
| 91 | * |
||
| 92 | * @param array $args Pass custom array of args, formatted as if for `get_posts()` |
||
| 93 | * |
||
| 94 | * @return array Array of Views as `WP_Post`. Empty array if none found. |
||
| 95 | */ |
||
| 96 | View Code Duplication | public static function get_all_views( $args = array() ) { |
|
| 97 | |||
| 98 | $default_params = array( |
||
| 99 | 'post_type' => 'gravityview', |
||
| 100 | 'posts_per_page' => -1, |
||
| 101 | 'post_status' => 'publish', |
||
| 102 | ); |
||
| 103 | |||
| 104 | $params = wp_parse_args( $args, $default_params ); |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @filter `gravityview/get_all_views/params` Modify the parameters sent to get all views. |
||
| 108 | * @param[in,out] array $params Array of parameters to pass to `get_posts()` |
||
| 109 | */ |
||
| 110 | $views_params = apply_filters( 'gravityview/get_all_views/params', $params ); |
||
| 111 | |||
| 112 | $views = get_posts( $views_params ); |
||
| 113 | |||
| 114 | return $views; |
||
| 115 | } |
||
| 116 | |||
| 117 | |||
| 118 | /** |
||
| 119 | * Get the form array for an entry based only on the entry ID |
||
| 120 | * @param int|string $entry_slug Entry slug |
||
| 121 | * @return array Gravity Forms form array |
||
| 122 | */ |
||
| 123 | public static function get_form_from_entry_id( $entry_slug ) { |
||
| 124 | |||
| 125 | $entry = self::get_entry( $entry_slug, true ); |
||
| 126 | |||
| 127 | $form = self::get_form( $entry['form_id'] ); |
||
| 128 | |||
| 129 | return $form; |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Check whether a form has product fields |
||
| 134 | * |
||
| 135 | * @since 1.16 |
||
| 136 | * |
||
| 137 | * @param array $form Gravity Forms form array |
||
| 138 | * |
||
| 139 | * @return bool|GF_Field[] |
||
| 140 | */ |
||
| 141 | public static function has_product_field( $form = array() ) { |
||
| 142 | |||
| 143 | $product_fields = apply_filters( 'gform_product_field_types', array( 'option', 'quantity', 'product', 'total', 'shipping', 'calculation', 'price' ) ); |
||
| 144 | |||
| 145 | $fields = GFAPI::get_fields_by_type( $form, $product_fields ); |
||
| 146 | |||
| 147 | return empty( $fields ) ? false : $fields; |
||
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Get the entry ID from the entry slug, which may or may not be the entry ID |
||
| 152 | * |
||
| 153 | * @since 1.5.2 |
||
| 154 | * @param string $slug The entry slug, as returned by GravityView_API::get_entry_slug() |
||
| 155 | * @return int|null The entry ID, if exists; `NULL` if not |
||
| 156 | */ |
||
| 157 | public static function get_entry_id_from_slug( $slug ) { |
||
| 158 | global $wpdb; |
||
| 159 | |||
| 160 | $search_criteria = array( |
||
| 161 | 'field_filters' => array( |
||
| 162 | array( |
||
| 163 | 'key' => 'gravityview_unique_id', // Search the meta values |
||
| 164 | 'value' => $slug, |
||
| 165 | 'operator' => 'is', |
||
| 166 | 'type' => 'meta', |
||
| 167 | ), |
||
| 168 | ) |
||
| 169 | ); |
||
| 170 | |||
| 171 | // Limit to one for speed |
||
| 172 | $paging = array( |
||
| 173 | 'page_size' => 1, |
||
| 174 | ); |
||
| 175 | |||
| 176 | $results = GFAPI::get_entries( 0, $search_criteria, null, $paging ); |
||
| 177 | |||
| 178 | $result = ( ! empty( $results ) && ! empty( $results[0]['id'] ) ) ? $results[0]['id'] : null; |
||
| 179 | |||
| 180 | return $result; |
||
| 181 | } |
||
| 182 | |||
| 183 | |||
| 184 | /** |
||
| 185 | * Returns the list of available forms |
||
| 186 | * |
||
| 187 | * @access public |
||
| 188 | * @param mixed $form_id |
||
|
|
|||
| 189 | * @return array Empty array if GFAPI isn't available or no forms. Otherwise, associative array with id, title keys |
||
| 190 | */ |
||
| 191 | public static function get_forms() { |
||
| 192 | $forms = array(); |
||
| 193 | if ( class_exists( 'GFAPI' ) ) { |
||
| 194 | $gf_forms = GFAPI::get_forms(); |
||
| 195 | foreach ( $gf_forms as $form ) { |
||
| 196 | $forms[] = array( |
||
| 197 | 'id' => $form['id'], |
||
| 198 | 'title' => $form['title'], |
||
| 199 | ); |
||
| 200 | } |
||
| 201 | } |
||
| 202 | return $forms; |
||
| 203 | } |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Return array of fields' id and label, for a given Form ID |
||
| 207 | * |
||
| 208 | * @access public |
||
| 209 | * @param string|array $form_id (default: '') or $form object |
||
| 210 | * @return array |
||
| 211 | */ |
||
| 212 | public static function get_form_fields( $form = '', $add_default_properties = false, $include_parent_field = true ) { |
||
| 213 | |||
| 214 | if ( ! is_array( $form ) ) { |
||
| 215 | $form = self::get_form( $form ); |
||
| 216 | } |
||
| 217 | |||
| 218 | $fields = array(); |
||
| 219 | $has_product_fields = false; |
||
| 220 | $has_post_fields = false; |
||
| 221 | $has_quiz_fields = false; |
||
| 222 | $has_poll_fields = false; |
||
| 223 | |||
| 224 | // If GF_Field exists, we're using GF 1.9+, where add_default_properties has been deprecated. |
||
| 225 | if ( false === class_exists( 'GF_Field' ) && $add_default_properties ) { |
||
| 226 | $form = RGFormsModel::add_default_properties( $form ); |
||
| 227 | } |
||
| 228 | |||
| 229 | if ( $form ) { |
||
| 230 | foreach ( $form['fields'] as $field ) { |
||
| 231 | if ( $include_parent_field || empty( $field['inputs'] ) ) { |
||
| 232 | $fields[ $field['id'] ] = array( |
||
| 233 | 'label' => rgar( $field, 'label' ), |
||
| 234 | 'parent' => null, |
||
| 235 | 'type' => rgar( $field, 'type' ), |
||
| 236 | 'adminLabel' => rgar( $field, 'adminLabel' ), |
||
| 237 | 'adminOnly' => rgar( $field, 'adminOnly' ), |
||
| 238 | ); |
||
| 239 | } |
||
| 240 | |||
| 241 | if ( $add_default_properties && ! empty( $field['inputs'] ) ) { |
||
| 242 | foreach ( $field['inputs'] as $input ) { |
||
| 243 | /** |
||
| 244 | * @hack |
||
| 245 | * In case of email/email confirmation, the input for email has the same id as the parent field |
||
| 246 | */ |
||
| 247 | if( 'email' == rgar( $field, 'type' ) && false === strpos( $input['id'], '.' ) ) { |
||
| 248 | continue; |
||
| 249 | } |
||
| 250 | $fields[ (string)$input['id'] ] = array( |
||
| 251 | 'label' => rgar( $input, 'label' ), |
||
| 252 | 'customLabel' => rgar( $input, 'customLabel' ), |
||
| 253 | 'parent' => $field, |
||
| 254 | 'type' => rgar( $field, 'type' ), |
||
| 255 | 'adminLabel' => rgar( $field, 'adminLabel' ), |
||
| 256 | 'adminOnly' => rgar( $field, 'adminOnly' ), |
||
| 257 | ); |
||
| 258 | } |
||
| 259 | } |
||
| 260 | |||
| 261 | /** @since 1.14 */ |
||
| 262 | if( 'list' === $field['type'] && !empty( $field['enableColumns'] ) ) { |
||
| 263 | |||
| 264 | foreach ( (array)$field['choices'] as $key => $input ) { |
||
| 265 | |||
| 266 | $input_id = sprintf( '%d.%d', $field['id'], $key ); // {field_id}.{column_key} |
||
| 267 | |||
| 268 | $fields[ $input_id ] = array( |
||
| 269 | 'label' => rgar( $input, 'text' ), |
||
| 270 | 'customLabel' => '', |
||
| 271 | 'parent' => $field, |
||
| 272 | 'type' => rgar( $field, 'type' ), |
||
| 273 | 'adminLabel' => rgar( $field, 'adminLabel' ), |
||
| 274 | 'adminOnly' => rgar( $field, 'adminOnly' ), |
||
| 275 | ); |
||
| 276 | } |
||
| 277 | } |
||
| 278 | |||
| 279 | /** |
||
| 280 | * @since 1.8 |
||
| 281 | */ |
||
| 282 | if( 'quiz' === $field['type'] ) { |
||
| 283 | $has_quiz_fields = true; |
||
| 284 | } |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @since 1.8 |
||
| 288 | */ |
||
| 289 | if( 'poll' === $field['type'] ) { |
||
| 290 | $has_poll_fields = true; |
||
| 291 | } |
||
| 292 | |||
| 293 | if( GFCommon::is_product_field( $field['type'] ) ){ |
||
| 294 | $has_product_fields = true; |
||
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @hack Version 1.9 |
||
| 299 | */ |
||
| 300 | $field_for_is_post_field = class_exists( 'GF_Fields' ) ? (object) $field : (array) $field; |
||
| 301 | |||
| 302 | if ( GFCommon::is_post_field( $field_for_is_post_field ) ) { |
||
| 303 | $has_post_fields = true; |
||
| 304 | } |
||
| 305 | } |
||
| 306 | } |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @since 1.7 |
||
| 310 | */ |
||
| 311 | if ( $has_post_fields ) { |
||
| 312 | $fields['post_id'] = array( |
||
| 313 | 'label' => __( 'Post ID', 'gravityview' ), |
||
| 314 | 'type' => 'post_id', |
||
| 315 | ); |
||
| 316 | } |
||
| 317 | |||
| 318 | if ( $has_product_fields ) { |
||
| 319 | |||
| 320 | $payment_fields = GravityView_Fields::get_all( 'pricing' ); |
||
| 321 | |||
| 322 | foreach ( $payment_fields as $payment_field ) { |
||
| 323 | if( isset( $fields["{$payment_field->name}"] ) ) { |
||
| 324 | continue; |
||
| 325 | } |
||
| 326 | $fields["{$payment_field->name}"] = array( |
||
| 327 | 'label' => $payment_field->label, |
||
| 328 | 'desc' => $payment_field->description, |
||
| 329 | 'type' => $payment_field->name, |
||
| 330 | ); |
||
| 331 | } |
||
| 332 | } |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @since 1.8 |
||
| 336 | */ |
||
| 337 | if( $has_quiz_fields ) { |
||
| 338 | |||
| 339 | $fields['gquiz_score'] = array( |
||
| 340 | 'label' => __( 'Quiz Score Total', 'gravityview' ), |
||
| 341 | 'type' => 'quiz_score', |
||
| 342 | 'desc' => __( 'Displays the number of correct Quiz answers the user submitted.', 'gravityview' ), |
||
| 343 | ); |
||
| 344 | $fields['gquiz_percent'] = array( |
||
| 345 | 'label' => __( 'Quiz Percentage Grade', 'gravityview' ), |
||
| 346 | 'type' => 'quiz_percent', |
||
| 347 | 'desc' => __( 'Displays the percentage of correct Quiz answers the user submitted.', 'gravityview' ), |
||
| 348 | ); |
||
| 349 | $fields['gquiz_grade'] = array( |
||
| 350 | 'label' => __( 'Quiz Letter Grade', 'gravityview' ), |
||
| 351 | 'type' => 'quiz_grade', |
||
| 352 | 'desc' => __( 'Displays the Grade the user achieved based on Letter Grading configured in the Quiz Settings.', 'gravityview' ), |
||
| 353 | ); |
||
| 354 | $fields['gquiz_is_pass'] = array( |
||
| 355 | 'label' => __( 'Quiz Pass/Fail', 'gravityview' ), |
||
| 356 | 'type' => 'quiz_is_pass', |
||
| 357 | 'desc' => __( 'Displays either Passed or Failed based on the Pass/Fail settings configured in the Quiz Settings.', 'gravityview' ), |
||
| 358 | ); |
||
| 359 | } |
||
| 360 | |||
| 361 | return $fields; |
||
| 362 | |||
| 363 | } |
||
| 364 | |||
| 365 | /** |
||
| 366 | * get extra fields from entry meta |
||
| 367 | * @param string $form_id (default: '') |
||
| 368 | * @return array |
||
| 369 | */ |
||
| 370 | public static function get_entry_meta( $form_id, $only_default_column = true ) { |
||
| 384 | |||
| 385 | |||
| 386 | /** |
||
| 387 | * Wrapper for the Gravity Forms GFFormsModel::search_lead_ids() method |
||
| 388 | * |
||
| 389 | * @see GFEntryList::leads_page() |
||
| 390 | * @param int $form_id ID of the Gravity Forms form |
||
| 391 | * @since 1.1.6 |
||
| 392 | * @return array|void Array of entry IDs. Void if Gravity Forms isn't active. |
||
| 393 | */ |
||
| 394 | public static function get_entry_ids( $form_id, $search_criteria = array() ) { |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Calculates the Search Criteria used on the self::get_entries / self::get_entry methods |
||
| 405 | * |
||
| 406 | * @since 1.7.4 |
||
| 407 | * |
||
| 408 | * @param array $passed_criteria array Input Criteria (search_criteria, sorting, paging) |
||
| 409 | * @param array $form_ids array Gravity Forms form IDs |
||
| 410 | * @return array |
||
| 411 | */ |
||
| 412 | public static function calculate_get_entries_criteria( $passed_criteria = array(), $form_ids = array() ) { |
||
| 487 | |||
| 488 | |||
| 489 | /** |
||
| 490 | * Retrieve entries given search, sort, paging criteria |
||
| 491 | * |
||
| 492 | * @see GFAPI::get_entries() |
||
| 493 | * @see GFFormsModel::get_field_filters_where() |
||
| 494 | * @access public |
||
| 495 | * @param int|array $form_ids The ID of the form or an array IDs of the Forms. Zero for all forms. |
||
| 496 | * @param mixed $passed_criteria (default: null) |
||
| 497 | * @param mixed &$total Optional. An output parameter containing the total number of entries. Pass a non-null value to generate the total count. (default: null) |
||
| 498 | * @return mixed False: Error fetching entries. Array: Multi-dimensional array of Gravity Forms entry arrays |
||
| 499 | */ |
||
| 500 | public static function get_entries( $form_ids = null, $passed_criteria = null, &$total = null ) { |
||
| 576 | |||
| 577 | |||
| 578 | /** |
||
| 579 | * Return a single entry object |
||
| 580 | * |
||
| 581 | * Since 1.4, supports custom entry slugs. The way that GravityView fetches an entry based on the custom slug is by searching `gravityview_unique_id` meta. The `$entry_slug` is fetched by getting the current query var set by `is_single_entry()` |
||
| 582 | * |
||
| 583 | * @access public |
||
| 584 | * @param string|int $entry_slug Either entry ID or entry slug string |
||
| 585 | * @param boolean $force_allow_ids Force the get_entry() method to allow passed entry IDs, even if the `gravityview_custom_entry_slug_allow_id` filter returns false. |
||
| 586 | * @param boolean $check_entry_display Check whether the entry is visible for the current View configuration. Default: true. {@since 1.14} |
||
| 587 | * @return array|boolean |
||
| 588 | */ |
||
| 589 | public static function get_entry( $entry_slug, $force_allow_ids = false, $check_entry_display = true ) { |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Wrapper for the GFFormsModel::matches_operation() method that adds additional comparisons, including: |
||
| 645 | * 'equals', 'greater_than_or_is', 'greater_than_or_equals', 'less_than_or_is', 'less_than_or_equals', |
||
| 646 | * and 'not_contains' |
||
| 647 | * |
||
| 648 | * @since 1.13 You can define context, which displays/hides based on what's being displayed (single, multiple, edit) |
||
| 649 | * |
||
| 650 | * @see http://docs.gravityview.co/article/252-gvlogic-shortcode |
||
| 651 | * @uses GFFormsModel::matches_operation |
||
| 652 | * @since 1.7.5 |
||
| 653 | * |
||
| 654 | * @param string $val1 Left side of comparison |
||
| 655 | * @param string $val2 Right side of comparison |
||
| 656 | * @param string $operation Type of comparison |
||
| 657 | * |
||
| 658 | * @return bool True: matches, false: not matches |
||
| 659 | */ |
||
| 660 | public static function matches_operation( $val1, $val2, $operation ) { |
||
| 709 | |||
| 710 | /** |
||
| 711 | * |
||
| 712 | * Checks if a certain entry is valid according to the View search filters (specially the Adv Filters) |
||
| 713 | * |
||
| 714 | * @see GFFormsModel::is_value_match() |
||
| 715 | * |
||
| 716 | * @since 1.7.4 |
||
| 717 | * @todo Return WP_Error instead of boolean |
||
| 718 | * |
||
| 719 | * @param array $entry Gravity Forms Entry object |
||
| 720 | * @return bool|array Returns 'false' if entry is not valid according to the view search filters (Adv Filter) |
||
| 721 | */ |
||
| 722 | public static function check_entry_display( $entry ) { |
||
| 815 | |||
| 816 | |||
| 817 | /** |
||
| 818 | * Allow formatting date and time based on GravityView standards |
||
| 819 | * |
||
| 820 | * @since 1.16 |
||
| 821 | * |
||
| 822 | * @see GVCommon_Test::test_format_date for examples |
||
| 823 | * |
||
| 824 | * @param string $date_string The date as stored by Gravity Forms (`Y-m-d h:i:s` GMT) |
||
| 825 | * @param string|array $args Array or string of settings for output parsed by `wp_parse_args()`; Can use `raw=1` or `array('raw' => true)` \n |
||
| 826 | * - `raw` Un-formatted date string in original `Y-m-d h:i:s` format |
||
| 827 | * - `timestamp` Integer timestamp returned by GFCommon::get_local_timestamp() |
||
| 828 | * - `diff` "%s ago" format, unless other `format` is defined |
||
| 829 | * - `human` Set $is_human parameter to true for `GFCommon::format_date()`. Shows `diff` within 24 hours or date after. Format based on blog setting, unless `format` is defined. |
||
| 830 | * - `time` Include time in the `GFCommon::format_date()` output |
||
| 831 | * - `format` Define your own date format, or `diff` format |
||
| 832 | * |
||
| 833 | * @return int|null|string Formatted date based on the original date |
||
| 834 | */ |
||
| 835 | public static function format_date( $date_string = '', $args = array() ) { |
||
| 882 | |||
| 883 | /** |
||
| 884 | * Retrieve the label of a given field id (for a specific form) |
||
| 885 | * |
||
| 886 | * @access public |
||
| 887 | * @param array $form |
||
| 888 | * @param string $field_id |
||
| 889 | * @return string |
||
| 890 | */ |
||
| 891 | public static function get_field_label( $form = array(), $field_id = '' ) { |
||
| 901 | |||
| 902 | |||
| 903 | /** |
||
| 904 | * Returns the field details array of a specific form given the field id |
||
| 905 | * |
||
| 906 | * Alias of GFFormsModel::get_field |
||
| 907 | * |
||
| 908 | * @uses GFFormsModel::get_field |
||
| 909 | * @see GFFormsModel::get_field |
||
| 910 | * @access public |
||
| 911 | * @param array $form |
||
| 912 | * @param string|int $field_id |
||
| 913 | * @return array|null Array: Gravity Forms field array; NULL: Gravity Forms GFFormsModel does not exist |
||
| 914 | */ |
||
| 915 | public static function get_field( $form, $field_id ) { |
||
| 922 | |||
| 923 | |||
| 924 | /** |
||
| 925 | * Check whether the post is GravityView |
||
| 926 | * |
||
| 927 | * - Check post type. Is it `gravityview`? |
||
| 928 | * - Check shortcode |
||
| 929 | * |
||
| 930 | * @param WP_Post $post WordPress post object |
||
| 931 | * @return boolean True: yep, GravityView; No: not! |
||
| 932 | */ |
||
| 933 | public static function has_gravityview_shortcode( $post = null ) { |
||
| 945 | |||
| 946 | |||
| 947 | /** |
||
| 948 | * Placeholder until the recursive has_shortcode() patch is merged |
||
| 949 | * @see https://core.trac.wordpress.org/ticket/26343#comment:10 |
||
| 950 | * @param string $content Content to check whether there's a shortcode |
||
| 951 | * @param string $tag Current shortcode tag |
||
| 952 | */ |
||
| 953 | public static function has_shortcode_r( $content, $tag = 'gravityview' ) { |
||
| 982 | |||
| 983 | |||
| 984 | |||
| 985 | /** |
||
| 986 | * Get the views for a particular form |
||
| 987 | * |
||
| 988 | * @since 1.15.2 Add $args array and limit posts_per_page to 500 |
||
| 989 | * |
||
| 990 | * @uses get_posts() |
||
| 991 | * |
||
| 992 | * @param int $form_id Gravity Forms form ID |
||
| 993 | * @param array $args Pass args sent to get_posts() |
||
| 994 | * |
||
| 995 | * @return array Array with view details, as returned by get_posts() |
||
| 996 | */ |
||
| 997 | View Code Duplication | public static function get_connected_views( $form_id, $args = array() ) { |
|
| 1012 | |||
| 1013 | /** |
||
| 1014 | * Get the Gravity Forms form ID connected to a View |
||
| 1015 | * |
||
| 1016 | * @param int $view_id The ID of the View to get the connected form of |
||
| 1017 | * |
||
| 1018 | * @return string ID of the connected Form, if exists. Empty string if not. |
||
| 1019 | */ |
||
| 1020 | public static function get_meta_form_id( $view_id ) { |
||
| 1023 | |||
| 1024 | /** |
||
| 1025 | * Get the template ID (`list`, `table`, `datatables`, `map`) for a View |
||
| 1026 | * |
||
| 1027 | * @see GravityView_Template::template_id |
||
| 1028 | * |
||
| 1029 | * @param int $view_id The ID of the View to get the layout of |
||
| 1030 | * |
||
| 1031 | * @return string GravityView_Template::template_id value. Empty string if not. |
||
| 1032 | */ |
||
| 1033 | public static function get_meta_template_id( $view_id ) { |
||
| 1036 | |||
| 1037 | |||
| 1038 | /** |
||
| 1039 | * Get all the settings for a View |
||
| 1040 | * |
||
| 1041 | * @uses GravityView_View_Data::get_default_args() Parses the settings with the plugin defaults as backups. |
||
| 1042 | * @param int $post_id View ID |
||
| 1043 | * @return array Associative array of settings with plugin defaults used if not set by the View |
||
| 1044 | */ |
||
| 1045 | public static function get_template_settings( $post_id ) { |
||
| 1060 | |||
| 1061 | /** |
||
| 1062 | * Get the setting for a View |
||
| 1063 | * |
||
| 1064 | * If the setting isn't set by the View, it returns the plugin default. |
||
| 1065 | * |
||
| 1066 | * @param int $post_id View ID |
||
| 1067 | * @param string $key Key for the setting |
||
| 1068 | * @return mixed|null Setting value, or NULL if not set. |
||
| 1069 | */ |
||
| 1070 | public static function get_template_setting( $post_id, $key ) { |
||
| 1080 | |||
| 1081 | /** |
||
| 1082 | * Get the field configuration for the View |
||
| 1083 | * |
||
| 1084 | * array( |
||
| 1085 | * |
||
| 1086 | * [other zones] |
||
| 1087 | * |
||
| 1088 | * 'directory_list-title' => array( |
||
| 1089 | * |
||
| 1090 | * [other fields] |
||
| 1091 | * |
||
| 1092 | * '5372653f25d44' => array( |
||
| 1093 | * 'id' => string '9' (length=1) |
||
| 1094 | * 'label' => string 'Screenshots' (length=11) |
||
| 1095 | * 'show_label' => string '1' (length=1) |
||
| 1096 | * 'custom_label' => string '' (length=0) |
||
| 1097 | * 'custom_class' => string 'gv-gallery' (length=10) |
||
| 1098 | * 'only_loggedin' => string '0' (length=1) |
||
| 1099 | * 'only_loggedin_cap' => string 'read' (length=4) |
||
| 1100 | * ) |
||
| 1101 | * |
||
| 1102 | * [other fields] |
||
| 1103 | * ) |
||
| 1104 | * |
||
| 1105 | * [other zones] |
||
| 1106 | * ) |
||
| 1107 | * |
||
| 1108 | * @param int $post_id View ID |
||
| 1109 | * @return array Multi-array of fields with first level being the field zones. See code comment. |
||
| 1110 | */ |
||
| 1111 | public static function get_directory_fields( $post_id ) { |
||
| 1114 | |||
| 1115 | |||
| 1116 | /** |
||
| 1117 | * Render dropdown (select) with the list of sortable fields from a form ID |
||
| 1118 | * |
||
| 1119 | * @access public |
||
| 1120 | * @param int $formid Form ID |
||
| 1121 | * @return string html |
||
| 1122 | */ |
||
| 1123 | public static function get_sortable_fields( $formid, $current = '' ) { |
||
| 1147 | |||
| 1148 | /** |
||
| 1149 | * |
||
| 1150 | * @param int $formid Gravity Forms form ID |
||
| 1151 | * @param array $blacklist Field types to exclude |
||
| 1152 | * |
||
| 1153 | * @since TODO |
||
| 1154 | * |
||
| 1155 | * @todo Get all fields, check if sortable dynamically |
||
| 1156 | * |
||
| 1157 | * @return array |
||
| 1158 | */ |
||
| 1159 | public static function get_sortable_fields_array( $formid, $blacklist = array( 'list', 'textarea' ) ) { |
||
| 1193 | |||
| 1194 | /** |
||
| 1195 | * Returns the GF Form field type for a certain field(id) of a form |
||
| 1196 | * @param object $form Gravity Forms form |
||
| 1197 | * @param mixed $field_id Field ID or Field array |
||
| 1198 | * @return string field type |
||
| 1199 | */ |
||
| 1200 | public static function get_field_type( $form = null, $field_id = '' ) { |
||
| 1211 | |||
| 1212 | |||
| 1213 | /** |
||
| 1214 | * Checks if the field type is a 'numeric' field type (e.g. to be used when sorting) |
||
| 1215 | * @param int|array $form form ID or form array |
||
| 1216 | * @param int|array $field field key or field array |
||
| 1217 | * @return boolean |
||
| 1218 | */ |
||
| 1219 | public static function is_field_numeric( $form = null, $field = '' ) { |
||
| 1250 | |||
| 1251 | /** |
||
| 1252 | * Encrypt content using Javascript so that it's hidden when JS is disabled. |
||
| 1253 | * |
||
| 1254 | * This is mostly used to hide email addresses from scraper bots. |
||
| 1255 | * |
||
| 1256 | * @param string $content Content to encrypt |
||
| 1257 | * @param string $message Message shown if Javascript is disabled |
||
| 1258 | * |
||
| 1259 | * @see https://github.com/jnicol/standalone-phpenkoder StandalonePHPEnkoder on Github |
||
| 1260 | * |
||
| 1261 | * @since 1.7 |
||
| 1262 | * |
||
| 1263 | * @return string Content, encrypted |
||
| 1264 | */ |
||
| 1265 | public static function js_encrypt( $content, $message = '' ) { |
||
| 1292 | |||
| 1293 | /** |
||
| 1294 | * |
||
| 1295 | * Do the same than parse_str without max_input_vars limitation: |
||
| 1296 | * Parses $string as if it were the query string passed via a URL and sets variables in the current scope. |
||
| 1297 | * @param $string array string to parse (not altered like in the original parse_str(), use the second parameter!) |
||
| 1298 | * @param $result array If the second parameter is present, variables are stored in this variable as array elements |
||
| 1299 | * @return bool true or false if $string is an empty string |
||
| 1300 | * @since 1.5.3 |
||
| 1301 | * |
||
| 1302 | * @author rubo77 at https://gist.github.com/rubo77/6821632 |
||
| 1303 | **/ |
||
| 1304 | public static function gv_parse_str( $string, &$result ) { |
||
| 1327 | |||
| 1328 | |||
| 1329 | /** |
||
| 1330 | * Generate an HTML anchor tag with a list of supported attributes |
||
| 1331 | * |
||
| 1332 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a Supported attributes defined here |
||
| 1333 | * @uses esc_url_raw() to sanitize $href |
||
| 1334 | * @uses esc_attr() to sanitize $atts |
||
| 1335 | * |
||
| 1336 | * @since 1.6 |
||
| 1337 | * |
||
| 1338 | * @param string $href URL of the link. Sanitized using `esc_url_raw()` |
||
| 1339 | * @param string $anchor_text The text or HTML inside the anchor. This is not sanitized in the function. |
||
| 1340 | * @param array|string $atts Attributes to be added to the anchor tag. Parsed by `wp_parse_args()`, sanitized using `esc_attr()` |
||
| 1341 | * |
||
| 1342 | * @return string HTML output of anchor link. If empty $href, returns NULL |
||
| 1343 | */ |
||
| 1344 | public static function get_link_html( $href = '', $anchor_text = '', $atts = array() ) { |
||
| 1408 | |||
| 1409 | /** |
||
| 1410 | * array_merge_recursive does indeed merge arrays, but it converts values with duplicate |
||
| 1411 | * keys to arrays rather than overwriting the value in the first array with the duplicate |
||
| 1412 | * value in the second array, as array_merge does. |
||
| 1413 | * |
||
| 1414 | * @see http://php.net/manual/en/function.array-merge-recursive.php |
||
| 1415 | * |
||
| 1416 | * @since 1.5.3 |
||
| 1417 | * @param array $array1 |
||
| 1418 | * @param array $array2 |
||
| 1419 | * @return array |
||
| 1420 | * @author Daniel <daniel (at) danielsmedegaardbuus (dot) dk> |
||
| 1421 | * @author Gabriel Sobrinho <gabriel (dot) sobrinho (at) gmail (dot) com> |
||
| 1422 | */ |
||
| 1423 | public static function array_merge_recursive_distinct( array &$array1, array &$array2 ) { |
||
| 1436 | |||
| 1437 | /** |
||
| 1438 | * Get WordPress users with reasonable limits set |
||
| 1439 | * |
||
| 1440 | * @param string $context Where are we using this information (e.g. change_entry_creator, search_widget ..) |
||
| 1441 | * @param array $args Arguments to modify the user query. See get_users() {@since 1.14} |
||
| 1442 | * @return array Array of WP_User objects. |
||
| 1443 | */ |
||
| 1444 | public static function get_users( $context = 'change_entry_creator', $args = array() ) { |
||
| 1465 | |||
| 1466 | |||
| 1467 | /** |
||
| 1468 | * Display updated/error notice |
||
| 1469 | * |
||
| 1470 | * @param string $notice text/HTML of notice |
||
| 1471 | * @param string $class CSS class for notice (`updated` or `error`) |
||
| 1472 | * |
||
| 1473 | * @return string |
||
| 1474 | */ |
||
| 1475 | public static function generate_notice( $notice, $class = '' ) { |
||
| 1478 | |||
| 1479 | |||
| 1480 | |||
| 1481 | |||
| 1482 | } //end class |
||
| 1483 | |||
| 1501 |
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.