Last active
December 11, 2016 20:01
-
-
Save westonruter/35105d1e3d29a9964d9063894add3b40 to your computer and use it in GitHub Desktop.
See https://frankiejarrett.com/2016/12/experimenting-with-magic-return-methods-on-wordpress-filters/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function __return_value( $value ) { | |
return create_function( '', sprintf( 'return %s;', var_export( $value, true ) ) ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function __return_value( $value ) { | |
return function () use ( $value ) { | |
return $value; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'section_count', __return_value( 5 ) ); | |
add_filter( 'allowed_properties', __return_value( array( 'foo', 'bar', 'baz' ) ) ); | |
add_filter( 'cup_overfloweth_amount', __return_value( 1.5 ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This.