wp run php script only once

Solutions on MaxInterview for wp run php script only once by the best coders in the world

showing results for - "wp run php script only once"
Tommaso
14 May 2018
1if ( current_user_can( 'manage_options' ) ) {
2
3    if( ! file_exists( '/path/to/onetime.php' ) )
4      return;
5    add_action( 'wp_footer', 'ravs_my_onetime_function' ); // execute my function on the desired hook.
6
7}
8
9function ravs_my_onetime_function() {
10
11    // all my glorious one-time-magic.
12    include( '/path/to/onetime.php' );
13
14   // after all execution rename your file;
15   rename( '/path/to/onetime.php', '/path/to/onetime-backup.php');
16}