Ticket #7226: 7226-04.patch
File 7226-04.patch, 7.6 KB (added by , 8 years ago) |
---|
-
src/bp-core/classes/class-bp-button.php
33 33 * Default: ''. 34 34 * @type string $wrapper_class Optional. DOM class of the button wrapper 35 35 * element. Default: ''. 36 * @type string $li_class Optional: Available if $wrapper set to ul & li elements created 37 * Default: ''. 38 * @type string $element Optional. The type of element to use e.g 'anchor', 'button' 39 * Default: 'anchor'. 40 * @type string $button_type Optional. Set the button type i.e like input types 41 * Defaults to 'button' [type="button"] can be 'submit' [type="submit"] 42 * @type string $button_name Optional: Button 'name' value - if type == 'submit'. 43 * @type string $button_value Optional: Button 'value' value - if type == 'submit'. 36 44 * @type string $link_href Optional. Destination link of the button. 37 45 * Default: ''. 46 * @type string $data_attr Optional. Allow a data attributte to be set. e.g 'data-bp-buttons=""' 47 * Default: ''. 38 48 * @type string $link_class Optional. DOM class of the button. Default: ''. 39 49 * @type string $link_id Optional. DOM ID of the button. Default: ''. 40 50 * @type string $link_rel Optional. DOM 'rel' attribute of the button. … … 82 92 /** 83 93 * The type of DOM element to use for a wrapper. 84 94 * 85 * @var string|bool 'div', ' span', 'p', 'li',or false for no wrapper.95 * @var string|bool 'div', 'ul', 'p', 'span' or false for no wrapper. 86 96 */ 87 97 public $wrapper = 'div'; 88 98 … … 100 110 */ 101 111 public $wrapper_id = ''; 102 112 113 /** 114 * The DOM class of li child elements the wrapper as a ul. 115 * 116 * @var string 117 */ 118 119 public $li_class = ''; 120 103 121 /** Button ****************************************************************/ 104 122 105 123 /** 124 * The node element type type i.e. a true '<button>' element or '<a>' anchor: 125 * 'button', 'anchor' 126 * 127 * @var string 128 */ 129 public $element = 'anchor'; 130 131 /** 132 * The button elements type i.e. 'submit', 'button'. 133 * 134 * 135 * @var string 136 */ 137 public $button_type = 'button'; 138 139 /** 140 * The button elements name attr i.e. 'name=""'. 141 * 142 * 143 * @var string 144 */ 145 public $button_name = ''; 146 147 /** 148 * The button elements value attr i.e. 'value=""'. 149 * 150 * 151 * @var string 152 */ 153 public $button_value = ''; 154 155 156 /** 106 157 * The destination link of the button. 107 158 * 108 159 * @var string … … 138 189 public $link_title = ''; 139 190 140 191 /** 192 * A data attribute. 193 * 194 * @var string 195 */ 196 public $data_attr = ''; 197 198 /** 141 199 * The contents of the button link. 142 200 * 143 201 * @var string … … 163 221 164 222 $r = wp_parse_args( $args, get_class_vars( __CLASS__ ) ); 165 223 224 //return var_dump($r); 225 166 226 // Required button properties. 167 227 $this->id = $r['id']; 168 228 $this->component = $r['component']; … … 202 262 // Wrapper properties. 203 263 if ( false !== $this->wrapper ) { 204 264 265 266 // If 'ul' is set for $wrapper we'll automagically create the mandatory 267 // 'li' elements & add class tokens if args !empty 268 if( 'li' == $this->wrapper ) { 269 if( !empty( $r['li_class'] ) ) $this->li_class = ' class="' . $r['li_class'] . '"'; 270 } 271 205 272 // Wrapper ID. 206 273 if ( !empty( $r['wrapper_id'] ) ) { 207 $this->wrapper_id 274 $this->wrapper_id = ' id="' . $r['wrapper_id'] . '"'; 208 275 } 209 276 210 277 // Wrapper class. 211 if ( !empty( $r['wrapper_class'] ) ) { 212 $this->wrapper_class = ' class="generic-button ' . $r['wrapper_class'] . '"'; 278 if ( !empty( $r['wrapper_class'] ) && 'li' !== $this->wrapper ) { 279 $this->wrapper_class = ' class="generic-button ' . $r['wrapper_class'] . '"'; 280 } elseif( 'li' == $this->wrapper ) { 281 if( !empty( $r['li_class'] ) ) $this->wrapper_class = ' class="generic-button ' . $r['li_class'] . '"'; 213 282 } else { 214 283 $this->wrapper_class = ' class="generic-button"'; 215 284 } 216 285 217 286 // Set before and after. 287 // Include 'li' elements if wrapper = 'ul' 218 288 $before = '<' . $r['wrapper'] . $this->wrapper_class . $this->wrapper_id . '>'; 219 289 $after = '</' . $r['wrapper'] . '>'; 220 290 … … 223 293 $before = $after = ''; 224 294 } 225 295 226 // Link properties. 296 297 // Link/Button properties. 298 //if ( !empty( $r['element'] ) ) $this->element = 299 if ( !empty( $r['button_type'] ) && 'button' == $r['element'] ) $this->button_type = ' type="' . $r['button_type'] . '"'; 300 if ( !empty( $r['button_name'] ) && 'button' == $r['element'] && 'submit' == $r['button_type'] ) $this->button_name = ' name="' . $r['button_name'] . '"'; 301 if ( !empty( $r['button_value'] ) && 'button' == $r['element'] && 'submit' == $r['button_type'] ) $this->button_value = ' value="' . $r['button_value'] . '"'; 227 302 if ( !empty( $r['link_id'] ) ) $this->link_id = ' id="' . $r['link_id'] . '"'; 303 // No href if we're a button please! 228 304 if ( !empty( $r['link_href'] ) ) $this->link_href = ' href="' . $r['link_href'] . '"'; 229 305 if ( !empty( $r['link_title'] ) ) $this->link_title = ' title="' . $r['link_title'] . '"'; 230 306 if ( !empty( $r['link_rel'] ) ) $this->link_rel = ' rel="' . $r['link_rel'] . '"'; 231 307 if ( !empty( $r['link_class'] ) ) $this->link_class = ' class="' . $r['link_class'] . '"'; 232 if ( !empty( $r['link_text'] ) ) $this->link_text = $r['link_text']; 308 if ( !empty( $r['data_attr'] ) ) $this->data_attr = ' ' . $r['data_attr'] ; 309 if ( !empty( $r['link_text'] ) ) $this->link_text = $r['link_text']; 233 310 311 // The wrapper element 312 313 // The element tag: e.g '<a', '<button' 314 315 if ( 'button' == $r['element'] ) { 316 317 // If the button type is submit we'll build the button form controls attr here 318 if( 'submit' == $r['button_type'] ) { 319 $button_controls = $this->button_name . $this->button_value ; 320 } 321 322 $before_element = '<button ' . $this->button_type . $button_controls; 323 $after_element = '</button>'; 324 325 } else { 326 $before_element = '<a ' . $this->link_href; 327 $after_element = '</a>'; 328 } 329 234 330 // Build the button. 235 $this->contents = $before . '<a'. $this->link_href . $this->link_title . $this->link_id . $this->link_rel . $this->link_class . '>' . $this->link_text . '</a>' . $after; 331 // attr here can be applicable/common to anchors or button elements 332 $this->contents = $before . $before_element . $this->link_title . $this->link_id . $this->link_rel . $this->data_attr . $this->link_class . '>' . $this->link_text . $after_element . $after; 236 333 237 334 /** 238 335 * Filters the button based on class parameters. … … 246 343 * @param BP_Button $this Current BP_Button instance. 247 344 * @param string $before HTML appended before the actual button. 248 345 * @param string $after HTML appended after the actual button. 346 * @param string $before_element Actual items opening element. 347 * @param string $after_element Actual items closing element t& tag . 249 348 */ 250 $this->contents = apply_filters( 'bp_button_' . $this->component . '_' . $this->id, $this->contents, $this, $before, $after );349 $this->contents = apply_filters( 'bp_button_' . $this->component . '_' . $this->id, $this->contents, $this, $before, $after, $before_element, $after_element ); 251 350 } 252 351 253 352 /**