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 WETU_Importer 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 WETU_Importer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class WETU_Importer { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Holds class instance |
||
| 14 | * |
||
| 15 | * @since 1.0.0 |
||
| 16 | * |
||
| 17 | * @var object|Module_Template |
||
| 18 | */ |
||
| 19 | protected static $instance = null; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * The slug for this plugin |
||
| 23 | * |
||
| 24 | * @since 0.0.1 |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | public $plugin_slug = 'wetu-importer'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * The url to list items from WETU |
||
| 32 | * |
||
| 33 | * @since 0.0.1 |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | public $tab_slug = 'default'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The options for the plugin |
||
| 41 | * |
||
| 42 | * @since 0.0.1 |
||
| 43 | * |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | public $options = false; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The url to import images from WETU |
||
| 50 | * |
||
| 51 | * @since 0.0.1 |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | public $import_scaling_url = false; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * scale the images on import or not |
||
| 59 | * |
||
| 60 | * @since 0.0.1 |
||
| 61 | * |
||
| 62 | * @var boolean |
||
| 63 | */ |
||
| 64 | public $scale_images = false; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * The WETU API Key |
||
| 68 | */ |
||
| 69 | public $api_key = false; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * The WETU API Username |
||
| 73 | */ |
||
| 74 | public $api_username = false; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * The WETU API Password |
||
| 78 | */ |
||
| 79 | public $api_password = false; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * The post types this works with. |
||
| 83 | */ |
||
| 84 | public $post_types = array(); |
||
| 85 | |||
| 86 | /** |
||
| 87 | * The previously attached images |
||
| 88 | * |
||
| 89 | * @var array() |
||
| 90 | */ |
||
| 91 | public $found_attachments = array(); |
||
| 92 | |||
| 93 | /** |
||
| 94 | * The gallery ids for the found attachements |
||
| 95 | * |
||
| 96 | * @var array() |
||
| 97 | */ |
||
| 98 | public $gallery_meta = array(); |
||
| 99 | |||
| 100 | /** |
||
| 101 | * The post ids to clean up (make sure the connected items are only singular) |
||
| 102 | * |
||
| 103 | * @var array() |
||
| 104 | */ |
||
| 105 | public $cleanup_posts = array(); |
||
| 106 | |||
| 107 | /** |
||
| 108 | * A post => parent relationship array. |
||
| 109 | * |
||
| 110 | * @var array() |
||
| 111 | */ |
||
| 112 | public $relation_meta = array(); |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Image Limit |
||
| 116 | * |
||
| 117 | * @var int |
||
| 118 | */ |
||
| 119 | public $image_limit = false; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * the featured image id |
||
| 123 | * |
||
| 124 | * @var int |
||
| 125 | */ |
||
| 126 | public $featured_image = false; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * the banner image |
||
| 130 | * |
||
| 131 | * @var int |
||
| 132 | */ |
||
| 133 | public $banner_image = false; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Holds the current import to display |
||
| 137 | * |
||
| 138 | * @var int |
||
| 139 | */ |
||
| 140 | public $current_importer = false; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * if you ran a tour import then you will have accommodation and destination queued to sync as well. |
||
| 144 | * |
||
| 145 | * @var int |
||
| 146 | */ |
||
| 147 | public $queued_imports = array(); |
||
| 148 | |||
| 149 | /** |
||
| 150 | * An Array to hold the items to queue |
||
| 151 | * |
||
| 152 | * @var int |
||
| 153 | */ |
||
| 154 | public $import_queue = array(); |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Holds the current post that is being imported. Use to check the content and excerpt. |
||
| 158 | * |
||
| 159 | * @var int |
||
| 160 | */ |
||
| 161 | public $current_post = false; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Holds the accommodation settings |
||
| 165 | * |
||
| 166 | * @var int |
||
| 167 | */ |
||
| 168 | public $accommodation_settings = false; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Holds the tour settings |
||
| 172 | * |
||
| 173 | * @var int |
||
| 174 | */ |
||
| 175 | public $tour_settings = false; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Holds the destination settings |
||
| 179 | * |
||
| 180 | * @var int |
||
| 181 | */ |
||
| 182 | public $destination_settings = false; |
||
| 183 | |||
| 184 | |||
| 185 | |||
| 186 | /** |
||
| 187 | * Initialize the plugin by setting localization, filters, and administration functions. |
||
| 188 | * |
||
| 189 | * @since 1.0.0 |
||
| 190 | * |
||
| 191 | * @access private |
||
| 192 | */ |
||
| 193 | public function __construct() { |
||
| 221 | |||
| 222 | // ACTIVATION FUNCTIONS |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Load the plugin text domain for translation. |
||
| 226 | * |
||
| 227 | * @since 1.0.0 |
||
| 228 | */ |
||
| 229 | public function load_plugin_textdomain() { |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Sets the variables used throughout the plugin. |
||
| 235 | */ |
||
| 236 | public function set_variables() { |
||
| 237 | $this->post_types = array( 'accommodation','destination','tour' ); |
||
| 238 | $temp_options = get_option( '_lsx-to_settings',false ); |
||
| 239 | |||
| 240 | //Set the options. |
||
| 241 | if ( false !== $temp_options && isset( $temp_options[ $this->plugin_slug ] ) ) { |
||
| 242 | $this->options = $temp_options[ $this->plugin_slug ]; |
||
| 243 | |||
| 244 | $this->accommodation_settings = $temp_options['accommodation']; |
||
| 245 | $this->tour_settings = $temp_options['tour']; |
||
| 246 | $this->destination_settings = $temp_options['destination']; |
||
| 247 | |||
| 248 | $this->api_key = false; |
||
| 249 | $this->api_username = false; |
||
| 250 | $this->api_password = false; |
||
| 251 | |||
| 252 | if ( ! defined( 'WETU_API_KEY' ) ) { |
||
| 253 | if ( isset( $temp_options['api']['wetu_api_key'] ) && '' !== $temp_options['api']['wetu_api_key'] ) { |
||
| 254 | $this->api_key = $temp_options['api']['wetu_api_key']; |
||
| 255 | } |
||
| 256 | if ( isset( $temp_options['api']['wetu_api_username'] ) && '' !== $temp_options['api']['wetu_api_username'] ) { |
||
| 257 | $this->api_username = $temp_options['api']['wetu_api_username']; |
||
| 258 | } |
||
| 259 | if ( isset( $temp_options['api']['wetu_api_password'] ) && '' !== $temp_options['api']['wetu_api_password'] ) { |
||
| 260 | $this->api_password = $temp_options['api']['wetu_api_password']; |
||
| 261 | } |
||
| 262 | } else { |
||
| 263 | $this->api_key = WETU_API_KEY; |
||
| 264 | } |
||
| 265 | |||
| 266 | //Set the tab slug |
||
| 267 | // @codingStandardsIgnoreLine |
||
| 268 | if ( isset( $_GET['tab'] ) || isset( $_POST['type'] ) ) { |
||
| 269 | if ( isset( $_GET['tab'] ) ) { |
||
| 270 | $this->tab_slug = $_GET['tab']; |
||
| 271 | } else { |
||
| 272 | // @codingStandardsIgnoreLine |
||
| 273 | $this->tab_slug = $_POST['type']; |
||
| 274 | } |
||
| 275 | |||
| 276 | //If any tours were queued |
||
| 277 | $this->queued_imports = get_option( 'wetu_importer_que', array() ); |
||
| 278 | } |
||
| 279 | |||
| 280 | //Set the scaling options |
||
| 281 | if ( isset( $this->options ) && isset( $this->options['image_scaling'] ) ) { |
||
| 282 | $this->scale_images = true; |
||
| 283 | $width = '1024'; |
||
| 284 | |||
| 285 | View Code Duplication | if ( isset( $this->options['width'] ) && '' !== $this->options['width'] ) { |
|
|
|
|||
| 286 | $width = $this->options['width']; |
||
| 287 | } |
||
| 288 | |||
| 289 | $height = '768'; |
||
| 290 | |||
| 291 | View Code Duplication | if ( isset( $this->options['height'] ) && '' !== $this->options['height'] ) { |
|
| 292 | $height = $this->options['height']; |
||
| 293 | } |
||
| 294 | |||
| 295 | $cropping = 'w'; |
||
| 296 | |||
| 297 | View Code Duplication | if ( isset( $this->options['cropping'] ) && '' !== $this->options['cropping'] ) { |
|
| 298 | $cropping = $this->options['cropping']; |
||
| 299 | } |
||
| 300 | |||
| 301 | $this->image_scaling_url = 'https://wetu.com/ImageHandler/' . $cropping . $width . 'x' . $height . '/'; |
||
| 302 | } |
||
| 303 | |||
| 304 | if ( isset( $this->options ) && isset( $this->options['image_limit'] ) && '' !== $this->options['image_limit'] ) { |
||
| 305 | $this->image_limit = $this->options['image_limit']; |
||
| 306 | } |
||
| 307 | } |
||
| 308 | } |
||
| 309 | |||
| 310 | // COMPATABILITY FUNCTIONS |
||
| 311 | |||
| 312 | /** |
||
| 313 | * On plugin activation |
||
| 314 | * |
||
| 315 | * @since 1.0.0 |
||
| 316 | */ |
||
| 317 | public static function register_activation_hook() { |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Check if the PHP version is compatible. |
||
| 323 | * |
||
| 324 | * @since 1.0.0 |
||
| 325 | */ |
||
| 326 | public static function compatible_version() { |
||
| 333 | |||
| 334 | /** |
||
| 335 | * The backup sanity check, in case the plugin is activated in a weird way, |
||
| 336 | * or the versions change after activation. |
||
| 337 | * |
||
| 338 | * @since 1.0.0 |
||
| 339 | */ |
||
| 340 | public function compatible_version_check() { |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Display the notice related with the older version from PHP. |
||
| 355 | * |
||
| 356 | * @since 1.0.0 |
||
| 357 | */ |
||
| 358 | public function compatible_version_notice() { |
||
| 363 | |||
| 364 | /** |
||
| 365 | * The primary sanity check, automatically disable the plugin on activation if it doesn't |
||
| 366 | * meet minimum requirements. |
||
| 367 | * |
||
| 368 | * @since 1.0.0 |
||
| 369 | */ |
||
| 370 | public static function compatible_version_check_on_activation() { |
||
| 376 | |||
| 377 | // DISPLAY FUNCTIONS |
||
| 378 | |||
| 379 | /* |
||
| 380 | * Load the importer class you want to use |
||
| 381 | */ |
||
| 382 | public function load_class() { |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Registers the admin page which will house the importer form. |
||
| 404 | */ |
||
| 405 | public function register_importer_page() { |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Enqueue the JS needed to contact wetu and return your result. |
||
| 411 | */ |
||
| 412 | public function admin_scripts() { |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Display the importer administration screen |
||
| 432 | */ |
||
| 433 | public function display_page() { |
||
| 465 | |||
| 466 | /** |
||
| 467 | * search_form |
||
| 468 | */ |
||
| 469 | public function search_form() { |
||
| 511 | |||
| 512 | /** |
||
| 513 | * The header of the item list |
||
| 514 | */ |
||
| 515 | public function table_header() { |
||
| 530 | |||
| 531 | /** |
||
| 532 | * The footer of the item list |
||
| 533 | */ |
||
| 534 | public function table_footer() { |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Displays the importers navigation |
||
| 552 | * |
||
| 553 | * @param $tab string |
||
| 554 | */ |
||
| 555 | public function navigation( $tab = '' ) { |
||
| 572 | |||
| 573 | /** |
||
| 574 | * set_taxonomy with some terms |
||
| 575 | */ |
||
| 576 | public function team_member_checkboxes( $selected = array() ) { |
||
| 601 | |||
| 602 | |||
| 603 | // GENERAL FUNCTIONS |
||
| 604 | |||
| 605 | /** |
||
| 606 | * Checks to see if an item is checked. |
||
| 607 | * |
||
| 608 | * @param $haystack array|string |
||
| 609 | * @param $needle string |
||
| 610 | * @param $echo bool |
||
| 611 | */ |
||
| 612 | View Code Duplication | public function checked( $haystack = false, $needle = '', $echo = true ) { |
|
| 613 | $return = $this->itemd( $haystack,$needle, 'checked' ); |
||
| 614 | |||
| 615 | if ( '' !== $return ) { |
||
| 616 | if ( true === $echo ) { |
||
| 617 | // @codingStandardsIgnoreLine |
||
| 618 | echo $return; |
||
| 619 | } else { |
||
| 620 | return $return; |
||
| 621 | } |
||
| 622 | } |
||
| 623 | } |
||
| 624 | |||
| 625 | /** |
||
| 626 | * Checks to see if an item is checked. |
||
| 627 | * |
||
| 628 | * @param $haystack array|string |
||
| 629 | * @param $needle string |
||
| 630 | * @param $echo bool |
||
| 631 | */ |
||
| 632 | View Code Duplication | public function selected( $haystack = false, $needle = '', $echo = true ) { |
|
| 633 | $return = $this->itemd( $haystack,$needle,'selected' ); |
||
| 634 | |||
| 635 | if ( '' !== $return ) { |
||
| 636 | if ( true === $echo ) { |
||
| 637 | // @codingStandardsIgnoreLine |
||
| 638 | echo $return; |
||
| 639 | } else { |
||
| 640 | return $return; |
||
| 641 | } |
||
| 642 | } |
||
| 643 | } |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Checks to see if an item is selected. If $echo is false, it will return the $type if conditions are true. |
||
| 647 | * |
||
| 648 | * @param $haystack array|string |
||
| 649 | * @param $needle string |
||
| 650 | * @param $type string |
||
| 651 | * @param $wrap bool |
||
| 652 | * @return $html string |
||
| 653 | */ |
||
| 654 | public function itemd( $haystack = false, $needle = '', $type = '', $wrap = true ) { |
||
| 672 | |||
| 673 | /** |
||
| 674 | * grabs any attachments for the current item |
||
| 675 | */ |
||
| 676 | public function find_attachments( $id = false ) { |
||
| 699 | |||
| 700 | // CUSTOM FIELD FUNCTIONS |
||
| 701 | |||
| 702 | /** |
||
| 703 | * Saves the room data |
||
| 704 | */ |
||
| 705 | public function save_custom_field( $value = false, $meta_key, $id, $decrease = false, $unique = true ) { |
||
| 721 | |||
| 722 | /** |
||
| 723 | * Grabs the custom fields, and resaves an array of unique items. |
||
| 724 | */ |
||
| 725 | public function cleanup_posts() { |
||
| 739 | |||
| 740 | // TAXONOMY FUNCTIONS |
||
| 741 | |||
| 742 | /** |
||
| 743 | * set_taxonomy with some terms |
||
| 744 | */ |
||
| 745 | public function set_taxonomy( $taxonomy, $terms, $id ) { |
||
| 746 | $result = array(); |
||
| 747 | |||
| 748 | if ( ! empty( $data ) ) { |
||
| 749 | foreach ( $data as $k ) { |
||
| 750 | if ( $id ) { |
||
| 751 | // @codingStandardsIgnoreLine |
||
| 752 | if ( ! $term = term_exists( trim( $k ), $tax ) ) { |
||
| 753 | $term = wp_insert_term( trim( $k ), $tax ); |
||
| 754 | |||
| 755 | View Code Duplication | if ( is_wp_error( $term ) ) { |
|
| 756 | // @codingStandardsIgnoreLine |
||
| 757 | echo $term->get_error_message(); |
||
| 758 | } else { |
||
| 759 | wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy,true ); |
||
| 760 | } |
||
| 761 | } else { |
||
| 762 | wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy,true ); |
||
| 763 | } |
||
| 764 | } else { |
||
| 765 | $result[] = trim( $k ); |
||
| 766 | } |
||
| 767 | } |
||
| 768 | } |
||
| 769 | return $result; |
||
| 770 | } |
||
| 771 | |||
| 772 | public function set_term( $id = false, $name = false, $taxonomy = false, $parent = false ) { |
||
| 773 | // @codingStandardsIgnoreLine |
||
| 774 | if ( ! $term = term_exists( $name, $taxonomy ) ) { |
||
| 775 | if ( false !== $parent ) { |
||
| 776 | $parent = array( |
||
| 777 | 'parent' => $parent, |
||
| 778 | ); |
||
| 779 | } |
||
| 780 | |||
| 781 | $term = wp_insert_term( trim( $name ), $taxonomy,$parent ); |
||
| 782 | |||
| 783 | View Code Duplication | if ( is_wp_error( $term ) ) { |
|
| 784 | // @codingStandardsIgnoreLine |
||
| 785 | echo $term->get_error_message(); |
||
| 786 | } else { |
||
| 787 | wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy,true ); |
||
| 788 | } |
||
| 789 | } else { |
||
| 790 | wp_set_object_terms( $id, intval( $term['term_id'] ), $taxonomy,true ); |
||
| 791 | } |
||
| 792 | |||
| 793 | return $term['term_id']; |
||
| 794 | } |
||
| 795 | |||
| 796 | /** |
||
| 797 | * set_taxonomy with some terms |
||
| 798 | */ |
||
| 799 | public function taxonomy_checkboxes( $taxonomy = false, $selected = array() ) { |
||
| 822 | |||
| 823 | // MAP FUNCTIONS |
||
| 824 | |||
| 825 | /** |
||
| 826 | * Saves the longitude and lattitude, as well as sets the map marker. |
||
| 827 | */ |
||
| 828 | public function set_map_data( $data, $id, $zoom = '10' ) { |
||
| 829 | $longitude = false; |
||
| 830 | $latitude = false; |
||
| 831 | $address = false; |
||
| 832 | |||
| 833 | if ( isset( $data[0]['position'] ) ) { |
||
| 834 | View Code Duplication | if ( isset( $data[0]['position']['driving_latitude'] ) ) { |
|
| 835 | $latitude = $data[0]['position']['driving_latitude']; |
||
| 836 | } elseif ( isset( $data[0]['position']['latitude'] ) ) { |
||
| 837 | $latitude = $data[0]['position']['latitude']; |
||
| 838 | } |
||
| 839 | |||
| 840 | View Code Duplication | if ( isset( $data[0]['position']['driving_longitude'] ) ) { |
|
| 841 | $longitude = $data[0]['position']['driving_longitude']; |
||
| 842 | } elseif ( isset( $data[0]['position']['longitude'] ) ) { |
||
| 843 | $longitude = $data[0]['position']['longitude']; |
||
| 844 | } |
||
| 845 | } |
||
| 846 | |||
| 847 | if ( isset( $data[0]['content'] ) && isset( $data[0]['content']['contact_information'] ) ) { |
||
| 848 | if ( isset( $data[0]['content']['contact_information']['address'] ) ) { |
||
| 849 | $address = strip_tags( $data[0]['content']['contact_information']['address'] ); |
||
| 850 | $address = explode( "\n", $address ); |
||
| 851 | |||
| 852 | foreach ( $address as $bitkey => $bit ) { |
||
| 853 | $bit = ltrim( rtrim( $bit ) ); |
||
| 854 | |||
| 855 | if ( false === $bit || '' === $bit || null === $bit || empty( $bit ) ) { |
||
| 856 | unset( $address[ $bitkey ] ); |
||
| 857 | } |
||
| 858 | } |
||
| 859 | |||
| 860 | $address = implode( ', ',$address ); |
||
| 861 | $address = str_replace( ', , ', ', ', $address ); |
||
| 862 | } |
||
| 863 | } |
||
| 864 | |||
| 865 | if ( false !== $longitude ) { |
||
| 866 | $location_data = array( |
||
| 867 | 'address' => (string) $address, |
||
| 868 | 'lat' => (string) $latitude, |
||
| 869 | 'long' => (string) $longitude, |
||
| 870 | 'zoom' => (string) $zoom, |
||
| 871 | 'elevation' => '', |
||
| 872 | ); |
||
| 873 | |||
| 874 | View Code Duplication | if ( false !== $id && '0' !== $id ) { |
|
| 875 | $prev = get_post_meta( $id,'location',true ); |
||
| 876 | update_post_meta( $id,'location',$location_data,$prev ); |
||
| 877 | } else { |
||
| 878 | add_post_meta( $id,'location',$location_data,true ); |
||
| 879 | } |
||
| 880 | } |
||
| 881 | } |
||
| 882 | |||
| 883 | // IMAGE FUNCTIONS |
||
| 884 | |||
| 885 | /** |
||
| 886 | * Creates the main gallery data |
||
| 887 | */ |
||
| 888 | public function set_featured_image( $data, $id ) { |
||
| 902 | |||
| 903 | /** |
||
| 904 | * Sets a banner image |
||
| 905 | */ |
||
| 906 | public function set_banner_image( $data, $id, $content = array( 'none' ) ) { |
||
| 907 | if ( is_array( $data[0]['content']['images'] ) && ! empty( $data[0]['content']['images'] ) ) { |
||
| 908 | if ( in_array( 'unique_banner_image', $content ) && isset( $data[0]['destination_image'] ) && is_array( $data[0]['destination_image'] ) ) { |
||
| 937 | |||
| 938 | /** |
||
| 939 | * Creates the main gallery data |
||
| 940 | */ |
||
| 941 | public function create_main_gallery( $data, $id ) { |
||
| 990 | |||
| 991 | /** |
||
| 992 | * search_form |
||
| 993 | */ |
||
| 994 | public function get_scaling_url( $args = array() ) { |
||
| 1023 | |||
| 1024 | /** |
||
| 1025 | * Attaches 1 image |
||
| 1026 | */ |
||
| 1027 | public function attach_image( $v = false, $parent_id, $image_sizes = false, $banner = false ) { |
||
| 1076 | |||
| 1077 | public function attach_external_image2( $url = null, $post_id = null, $thumb = null, $filename = null, $post_data = array() ) { |
||
| 1150 | |||
| 1151 | |||
| 1152 | // AJAX FUNCTIONS |
||
| 1153 | /** |
||
| 1154 | * Run through the accommodation grabbed from the DB. |
||
| 1155 | */ |
||
| 1156 | public function process_ajax_search() { |
||
| 1160 | |||
| 1161 | /** |
||
| 1162 | * Connect to wetu |
||
| 1163 | */ |
||
| 1164 | public function process_ajax_import() { |
||
| 1168 | |||
| 1169 | /** |
||
| 1170 | * Formats the row for the completed list. |
||
| 1171 | */ |
||
| 1172 | public function format_completed_row( $response ) { |
||
| 1176 | |||
| 1177 | /** |
||
| 1178 | * Formats the error. |
||
| 1179 | */ |
||
| 1180 | public function format_error( $response ) { |
||
| 1184 | |||
| 1185 | /** |
||
| 1186 | * Does a multine search |
||
| 1187 | */ |
||
| 1188 | public function multineedle_stripos( $haystack, $needles, $offset = 0 ) { |
||
| 1204 | |||
| 1205 | /** |
||
| 1206 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
||
| 1207 | */ |
||
| 1208 | View Code Duplication | public function find_current_accommodation( $post_type = 'accommodation' ) { |
|
| 1235 | |||
| 1236 | /** |
||
| 1237 | * Set the Video date |
||
| 1238 | */ |
||
| 1239 | public function set_video_data( $data, $id ) { |
||
| 1269 | |||
| 1270 | public function shuffle_assoc( &$array ) { |
||
| 1284 | |||
| 1285 | } |
||
| 1286 | |||
| 1288 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.