Created
January 30, 2018 16:56
-
-
Save gabrieleromanato/e6330a4517d7e04dab185a39125d1411 to your computer and use it in GitHub Desktop.
Unnecessary WordPress overhead: the wp hook incorrect use
This file contains hidden or 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 | |
// Never ever use the wp hook to run unnecessary routines | |
// Global overhead ahead! | |
function my_factorial( $n ) { | |
if( function_exists( 'gmp_fact' ) ) { | |
return gmp_fact( $n ); | |
} else { | |
if ( $n < 2 ) { | |
return 1; | |
} else { | |
return ( $n * my_factorial( $n - 1 ) ); | |
} | |
} | |
} | |
function my_wp_func() { | |
$numbers = range( 1, 1000000 ); | |
$factorials = array_map( 'my_factorial', $numbers ); | |
} | |
add_action( 'wp', 'my_wp_func' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment