Conditions | 4 |
Paths | 3 |
Total Lines | 99 |
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 |
||
57 | function AtD_display_unignore_form() { |
||
58 | |||
59 | if ( ! AtD_is_allowed() ) { |
||
60 | return; |
||
61 | } |
||
62 | |||
63 | $user = wp_get_current_user(); |
||
64 | |||
65 | if ( ! $user || $user->ID == 0 ) { |
||
66 | return; |
||
67 | } |
||
68 | |||
69 | $ignores = AtD_get_setting( $user->ID, 'AtD_ignored_phrases' ); |
||
70 | ?> |
||
71 | <script> |
||
72 | function atd_show_phrases( ignored ) |
||
73 | { |
||
74 | var element = jQuery( '#atd_ignores' ), |
||
75 | items = [], |
||
76 | delLink; |
||
77 | |||
78 | ignored.sort(); |
||
79 | |||
80 | element.empty(); |
||
81 | for ( var i = 0; i < ignored.length; i++ ) { |
||
82 | if ( ignored[i].length > 0 ) { |
||
83 | delLink = jQuery( '<span id="atd_' + i + '"> </span>' ); |
||
84 | delLink |
||
85 | .text( delLink.text() + ignored[i] ) |
||
86 | .prepend( jQuery( '<a class="ntdelbutton">X</a>' ).data( 'ignored', ignored[i] ) ); |
||
87 | element.append( delLink ).append( '<br />' ); |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | |||
92 | function atd_unignore( phrase ) { |
||
93 | /* get the ignored values and remove the unwanted phrase */ |
||
94 | var ignored = jQuery( '#AtD_ignored_phrases' ).val().split( /,/g ); |
||
95 | ignored = jQuery.map(ignored, function(value, index) { return value == phrase ? null : value; }); |
||
96 | jQuery( '#AtD_ignored_phrases' ).val( ignored.join(',') ); |
||
97 | |||
98 | /* update the UI */ |
||
99 | atd_show_phrases( ignored ); |
||
100 | |||
101 | /* show a nifty message to the user */ |
||
102 | jQuery( '#AtD_message' ).show(); |
||
103 | } |
||
104 | |||
105 | function atd_ignore () { |
||
106 | /* get the ignored values and update the hidden field */ |
||
107 | var ignored = jQuery( '#AtD_ignored_phrases' ).val().split( /,/g ); |
||
108 | |||
109 | jQuery.map(jQuery( '#AtD_add_ignore' ).val().split(/,\s*/g), function(value, index) { ignored.push(value); }); |
||
110 | |||
111 | jQuery( '#AtD_ignored_phrases' ).val( ignored.join(',') ); |
||
112 | |||
113 | /* update the UI */ |
||
114 | atd_show_phrases( ignored ); |
||
115 | jQuery( '#AtD_add_ignore' ).val(''); |
||
116 | |||
117 | /* show that nifteroo messaroo to the useroo */ |
||
118 | jQuery( '#AtD_message' ).show(); |
||
119 | } |
||
120 | |||
121 | function atd_ignore_init() { |
||
122 | jQuery( '#AtD_message' ).hide(); |
||
123 | jQuery( '#atd_ignores' ).on( 'click', 'a', function() { |
||
124 | atd_unignore( jQuery(this).data( 'ignored' ) ); |
||
125 | return false; |
||
126 | } ); |
||
127 | atd_show_phrases( jQuery( '#AtD_ignored_phrases' ).val().split( /,/g ) ); |
||
128 | } |
||
129 | |||
130 | /* document.ready() does not execute in IE6 unless it's at the bottom of the page. oi! */ |
||
131 | if (navigator.appName == 'Microsoft Internet Explorer') |
||
132 | setTimeout( atd_ignore_init, 2500 ); |
||
133 | else |
||
134 | jQuery( document ).ready( atd_ignore_init ); |
||
135 | </script> |
||
136 | <input type="hidden" name="AtD_ignored_phrases" id="AtD_ignored_phrases" value="<?php echo esc_attr( $ignores ); ?>"> |
||
137 | |||
138 | <p style="font-weight: bold"><?php _e( 'Ignored Phrases', 'jetpack' ); ?></p> |
||
139 | |||
140 | <p><?php _e( 'Identify words and phrases to ignore while proofreading your posts and pages:', 'jetpack' ); ?></p> |
||
141 | |||
142 | <p><input type="text" id="AtD_add_ignore" name="AtD_add_ignore"> <input type="button" value="<?php esc_attr_e( 'Add', 'jetpack' ); ?>" onclick="javascript:atd_ignore()"></p> |
||
143 | |||
144 | <div class="tagchecklist" id="atd_ignores"></div> |
||
145 | |||
146 | <div class="plugin-update-tr" id="AtD_message" style="display: none"> |
||
147 | <div class="update-message"><strong><?php _e( 'Be sure to click "Update Profile" at the bottom of the screen to save your changes.', 'jetpack' ); ?></strong></div> |
||
148 | </div> |
||
149 | |||
150 | </td> |
||
151 | </tr> |
||
152 | </table> |
||
153 | |||
154 | <?php |
||
155 | } |
||
156 |