Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress tmp API example for https://core.trac.wordpress.org/ticket/31138
----
TEMPORARY DIRECTORY: This is where plugin / theme authors can store temporary files and directories. When a temporary directory expires, the garbage collector will delete it.
* '''tmp_dir_create'''( $expiration, $primary_file )
* ==> string $absolute_path | WP_Error $error
* Create a temporary directory specifically for the plugin/theme defined by $primary_file.
* '''tmp_dir_info'''( $absolute_path, $with_listing = false )
* ==> array $tmp_info | WP_Error $error
* Get info about the temporary directory at $absolute_path.
* $tmp_info contains $primary_file, $absolute_path, $expiration time and a (recursively obtained) file listing, if requested.
* '''tmp_dir_expire'''( $absolute_path )
* ==> WP_Error $error
* Allow the garbage collector to delete the temporary directory ASAP, together with its transient.
----
TEMPORARY BACKUP: This is how plugin / theme authors can take advantage of the same temporary backup API internally used by WordPress 4.2. (This is a lie at the moment... my patch is not exactly like this :-)
* '''tmp_backup_create'''( $expiration, $primary_file, $relative_path = './' )
* ==> string $backup_name | WP_Error $error
* Recursively backup anything inside $relative_path, relative to the directory of the $primary_file.
* The location of this backup could be different from that of a temporary directory.
* '''tmp_backup_info'''( $backup_name, $with_listing = false )
* ==> array $backup_info | WP_Error $error
* Get info about the backup whose name is $backup_name.
* $backup_info contains primary file, relative_path, backup path, expiration time and a recursive file listing, if requested.
* '''tmp_backup_expire'''( $backup_name )
* ==> WP_Error $error
* Allow the garbage collector to delete the backup ASAP, together with its transient.
* '''tmp_backup_find_like'''( $backup_name )
* ==> array $backups | WP_Error $error
* Get the names of all the currently non-expired backups whose names share the same prefix of $backup_name.
* Items sorted from older to newer.
* '''tmp_backup_expire_like'''( $backup_name )
* ==> WP_Error $error
* Allow the garbage collector to delete all the currently non-expired backups whose names share the same prefix of $backup_name ASAP, together with their transients.
* '''tmp_backup_find_all'''( $primary_file )
* ==> array $all_names | WP_Error $error
* Get the names of all the currently non-expired backups for $primary_file.
* Items sorted from older to newer.
* '''tmp_backup_expire_all'''( $primary_file )
* ==> WP_Error $error
* Allow the garbage collector to delete all the backups ASAP, together with their transients.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment