| 325 | function _filter_atts( $out, $pairs, $atts ) { |
| 326 | $this->filter_atts_out = $out; |
| 327 | $this->filter_atts_pairs = $pairs; |
| 328 | $this->filter_atts_atts = $atts; |
| 329 | return $out; |
| 330 | } |
| 331 | |
| 332 | function _filter_atts2( $out, $pairs, $atts ) { |
| 333 | // If foo attribute equals "foo1", change it to be default value |
| 334 | if ( isset( $out['foo'] ) && 'foo1' == $out['foo'] ) |
| 335 | $out['foo'] = $pairs['foo']; |
| 336 | // If baz attribute is set, remove it |
| 337 | if ( isset( $out['baz'] ) ) |
| 338 | unset( $out['baz'] ); |
| 339 | $this->filter_atts_out = $out; |
| 340 | return $out; |
| 341 | } |
| 342 | |
| 343 | // Test to ensure the filter passes proper arguments |
| 344 | function test_shortcode_atts_filter_basics() { |
| 345 | add_filter( 'shortcode_atts_bartag', array( &$this, '_filter_atts' ), 10, 3 ); |
| 346 | do_shortcode('[bartag foo="foo1" /]'); |
| 347 | $this->assertEquals( array( 'foo' => 'foo1', 'baz' => 'default baz' ), $this->filter_atts_out ); |
| 348 | $this->assertEquals( array( 'foo' => 'no foo', 'baz' => 'default baz' ), $this->filter_atts_pairs ); |
| 349 | $this->assertEquals( array( 'foo' => 'foo1' ), $this->filter_atts_atts ); |
| 350 | remove_filter( 'shortcode_atts_bartag', array( &$this, '_filter_atts' ), 10, 3 ); |
| 351 | } |
| 352 | |
| 353 | function test_shortcode_atts_filtering() { |
| 354 | add_filter( 'shortcode_atts_bartag', array( &$this, '_filter_atts2' ), 10, 3 ); |
| 355 | $out = do_shortcode('[bartag foo="foo1" baz="baz1" /]'); |
| 356 | $this->assertEquals( array( 'foo' => 'no foo' ), $this->filter_atts_out ); |
| 357 | $this->assertEquals( 'foo = no foo', $out ); |
| 358 | $out = do_shortcode('[bartag foo="foo2" /]'); |
| 359 | $this->assertEquals( 'foo = foo2', $out ); |
| 360 | remove_filter( 'shortcode_atts_bartag', array( &$this, '_filter_atts2' ), 10, 3 ); |
| 361 | } |