| Conditions | 6 |
| Paths | 5 |
| Total Lines | 115 |
| Code Lines | 75 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 47 | public function load() { |
||
| 48 | |||
| 49 | $css_path = SIMPLE_CALENDAR_ASSETS . 'css/'; |
||
| 50 | $css_path_vendor = $css_path . 'vendor/'; |
||
| 51 | $js_path = SIMPLE_CALENDAR_ASSETS . 'js/'; |
||
| 52 | $js_path_vendor = $js_path . 'vendor/'; |
||
| 53 | |||
| 54 | /* ====================== * |
||
| 55 | * Register Admin Scripts * |
||
| 56 | * ====================== */ |
||
| 57 | |||
| 58 | // TipTip uses ".minified.js" filename ending. |
||
| 59 | wp_register_script( |
||
| 60 | 'simcal-tiptip', |
||
| 61 | $js_path_vendor . 'jquery.tipTip' . ( ( $this->min !== '' ) ? '.minified' : '' ) . '.js', |
||
| 62 | array( 'jquery' ), |
||
| 63 | SIMPLE_CALENDAR_VERSION, |
||
| 64 | true |
||
| 65 | ); |
||
| 66 | wp_register_script( |
||
| 67 | 'simcal-select2', |
||
| 68 | $js_path_vendor . 'select2' . $this->min . '.js', |
||
| 69 | array(), |
||
| 70 | SIMPLE_CALENDAR_VERSION, |
||
| 71 | true |
||
| 72 | ); |
||
| 73 | wp_register_script( |
||
| 74 | 'simcal-admin', |
||
| 75 | $js_path . 'admin' . $this->min . '.js', |
||
| 76 | array( |
||
| 77 | 'jquery', |
||
| 78 | 'jquery-ui-sortable', |
||
| 79 | 'jquery-ui-datepicker', |
||
| 80 | 'wp-color-picker', |
||
| 81 | 'simcal-tiptip', |
||
| 82 | 'simcal-select2', |
||
| 83 | ), |
||
| 84 | SIMPLE_CALENDAR_VERSION, |
||
| 85 | true |
||
| 86 | ); |
||
| 87 | wp_register_script( |
||
| 88 | 'simcal-admin-add-calendar', |
||
| 89 | $js_path . 'admin-add-calendar' . $this->min . '.js', |
||
| 90 | array( 'simcal-select2' ), |
||
| 91 | SIMPLE_CALENDAR_VERSION, |
||
| 92 | true |
||
| 93 | ); |
||
| 94 | |||
| 95 | /* ===================== * |
||
| 96 | * Register Admin Styles * |
||
| 97 | * ===================== */ |
||
| 98 | |||
| 99 | wp_register_style( |
||
| 100 | 'simcal-select2', |
||
| 101 | $css_path_vendor . 'select2' . $this->min . '.css', |
||
| 102 | array(), |
||
| 103 | SIMPLE_CALENDAR_VERSION |
||
| 104 | ); |
||
| 105 | wp_register_style( |
||
| 106 | 'simcal-admin', |
||
| 107 | $css_path . 'admin' . $this->min . '.css', |
||
| 108 | array( |
||
| 109 | 'wp-color-picker', |
||
| 110 | 'simcal-select2', |
||
| 111 | ), |
||
| 112 | SIMPLE_CALENDAR_VERSION |
||
| 113 | ); |
||
| 114 | wp_register_style( |
||
| 115 | 'simcal-admin-add-calendar', |
||
| 116 | $css_path . 'admin-add-calendar' . $this->min . '.css', |
||
| 117 | array( 'simcal-select2' ), |
||
| 118 | SIMPLE_CALENDAR_VERSION |
||
| 119 | ); |
||
| 120 | |||
| 121 | if ( simcal_is_admin_screen() !== false ) { |
||
| 122 | |||
| 123 | wp_enqueue_script( 'simcal-admin' ); |
||
| 124 | wp_localize_script( |
||
| 125 | 'simcal-admin', |
||
| 126 | 'simcal_admin', |
||
| 127 | simcal_common_scripts_variables() |
||
| 128 | ); |
||
| 129 | |||
| 130 | wp_enqueue_style( 'simcal-admin' ); |
||
| 131 | |||
| 132 | } else { |
||
| 133 | |||
| 134 | global $post_type; |
||
|
|
|||
| 135 | $screen = get_current_screen(); |
||
| 136 | |||
| 137 | $post_types = array(); |
||
| 138 | $settings = get_option( 'simple-calendar_settings_calendars' ); |
||
| 139 | if ( isset( $settings['general']['attach_calendars_posts'] ) ) { |
||
| 140 | $post_types = $settings['general']['attach_calendars_posts']; |
||
| 141 | } |
||
| 142 | |||
| 143 | $conditions = array( |
||
| 144 | in_array( $post_type, (array) $post_types ), |
||
| 145 | $screen->id == 'widgets', |
||
| 146 | ); |
||
| 147 | |||
| 148 | if ( in_array( true, $conditions ) ) { |
||
| 149 | |||
| 150 | wp_enqueue_script( 'simcal-admin-add-calendar' ); |
||
| 151 | wp_localize_script( 'simcal-admin-add-calendar', 'simcal_admin', array( |
||
| 152 | 'locale' => get_locale(), |
||
| 153 | 'text_dir' => is_rtl() ? 'rtl' : 'ltr', |
||
| 154 | ) ); |
||
| 155 | |||
| 156 | wp_enqueue_style( 'simcal-admin-add-calendar' ); |
||
| 157 | } |
||
| 158 | |||
| 159 | } |
||
| 160 | |||
| 161 | } |
||
| 162 | |||
| 164 |
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state