PHP code example of varunsridharan / wp-transient-api

1. Go to this page and download the library: Download varunsridharan/wp-transient-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

varunsridharan / wp-transient-api example snippets


$api = new Varunsridharan\WordPress\Transient_API::instance('instance_key',array(
    // Transients
    'transient_version'     => 1.0,
    'transient_auto_delete' => false,
    'transient_surfix'      => '',
    'transient_prefix'      => '',
    // WP DB Options
    'option_auto_delete'    => false,
    'option_version'        => 1.0,
    'option_surfix'         => '',
    'option_prefix'         => '',
    // Global Config.
    'is_option'             => false,
));
YourPlugin_Transient_Api::instance();


YourPlugin_Transient_Api::instance('instance_key')->set('your-key','your-value');
YourPlugin_Transient_Api::instance('instance_key')->get('your-key'); # Returns the values only if option version matched with $option_version
YourPlugin_Transient_Api::instance('instance_key')->update('your-key','your-value'); # Updates the options value
YourPlugin_Transient_Api::instance('instance_key')->delete('your-key'); # Deletes the options and its releated options 

YourPlugin_Transient_Api::instance('instance_key')->add_option('your-key','your-value');
YourPlugin_Transient_Api::instance('instance_key')->get_option('your-key'); # Returns the values only if option version matched with $option_version
YourPlugin_Transient_Api::instance('instance_key')->update_option('your-key','your-value'); # Updates the options value
YourPlugin_Transient_Api::instance('instance_key')->delete_option('your-key'); # Deletes the options and its releated options 

YourPlugin_Transient_Api::instance('instance_key')->add_transient('your-key','your-value',2000);
YourPlugin_Transient_Api::instance('instance_key')->get_transient('your-key'); # Returns the values only if option version matched with $transient_version
YourPlugin_Transient_Api::instance('instance_key')->delete_transient('your-key'); # Deletes the options and its releated options