get_results( 'SELECT * FROM wp_options WHERE option_name LIKE "_transient_aprq_%" ORDER BY option_id ASC', OBJECT );
$e = memory_get_usage();
$expirations = $wpdb->get_results( 'SELECT * FROM wp_options WHERE option_name LIKE "_transient_timeout_aprq_%" ORDER BY option_value ASC', OBJECT );
$exp = array();
foreach($expirations as $row){
$hash = str_replace("_transient_timeout_aprq_","",$row->option_name);
$exp[$hash] = $row->option_value;
}
?>
";
$now = time();
foreach($results as $row){
$hash = str_replace("_transient_aprq_","",$row->option_name);
$data = unserialize($row->option_value);
$data_age = round( ($now - $data["created_at"])/60/60, 2 );
$data_expire = round( ($exp[$hash]-$now)/60/60, 2 );
echo "$data_age hours old. Transient expires in $data_expire hours.
";
}
?>
">Delete Expired Transients?
">Delete All Transients (completely clear cache)?
You may find that multiple API Keys or APP IDs are required for your website. Create as many as you need!
$config):
$class = ($active_tab == $key)? 'nav-tab-active' : '';
?>
+
"New Configuration");
$configs[] = $config;
$active_tab = count($configs)-1;
set_airpress_config("airpress_".$airpress_config_initials,$active_tab,$config);
} else {
$active_tab = $requested_tab;
}
$_GET['tab'] = $active_tab;
foreach($configs as $key => $config){
$function = "airpress_admin_".$airpress_config_initials."_tab";
call_user_func($function,$key,$config);
}
}
add_action( 'admin_init', 'airpress_admin_cx_tab_controller');
/***********************************************/
# TAB: DEFAULT
/***********************************************/
function airpress_admin_cx_tab($key,$config) {
$option_name = "airpress_cx".$key;
//$options = get_option( $option_name );
$defaults = array(
"api_key" => "",
"app_id" => "",
"refresh" => MINUTE_IN_SECONDS * 5,
"expire" => DAY_IN_SECONDS,
"api_url" => "https://api.airtable.com/v0/",
"fresh" => "fresh",
"debug" => 0,
"log" => dirname(dirname(dirname(__FILE__)))."/airpress.log",
"log_max_size" => 3072
);
$options = array_merge($defaults,$config);
################################
################################
$section_title = "Airtable API Connections";
$section_name = "airpress_cx".$key;
add_settings_section(
$section_name,
__( $section_title, 'airpress' ),
"airpress_admin_cx_render_section",
$option_name
);
################################
$field_name = "name";
$field_title = "Configuration Name";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "api_key";
$field_title = "Airtable API Key";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "app_id";
$field_title = "Airtable APP ID";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "api_url";
$field_title = "Airtable API URL";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
################################
$section_title = "Request Caching";
$section_name = "airpress_cx".$key;
add_settings_section(
$section_name,
__( $section_title, 'airpress' ),
"airpress_admin_cx_render_section",
$option_name
);
################################
$field_name = "refresh";
$field_title = "Refresh";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "expire";
$field_title = "Expire";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "fresh";
$field_title = "Query var to force refresh cache for this request";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "debug";
$field_title = "Enable Debugging";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_select__debug', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "log";
$field_title = "Debug Logfile";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
################################
$field_name = "log_max_size";
$field_title = "Logfile Max Size in Kilobytes (0 for unlimited)";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_text', $option_name, $section_name, array($options,$option_name,$field_name) );
###############################
$field_name = "delete";
$field_title = "Delete Configuration?";
add_settings_field( $field_name, __( $field_title, 'airpress' ), 'airpress_admin_cx_render_element_delete', $option_name, $section_name, array($options,$option_name,$field_name) );
register_setting($option_name,$option_name,"airpress_cx_validation");
}
function airpress_cx_validation($input){
global $wp_rewrite;
if ($input["debug"] == 1 || $input["debug"] == 2){
if ( $h = @fopen($input["log"], "a") ){
$message = "log file created at ".$input["log"];
fwrite($h, $message."\n");
fclose($h);
} else {
$input["debug"] = 0;
add_settings_error('airpress_cx_log', esc_attr( 'settings_updated' ), esc_attr($input["log"])." is not writable.","error");
}
} else {
$manual_intervention = false;
if ( file_exists($input["log"]) ){
$manual_intervention = true;
if ( is_writable($input["log"]) ){
$parts = pathinfo($input["log"]);
// Let's only delete log files named airpress.log to avoid allowing
// this field to control the deletion of any file on the server
if ( $parts["filename"] == "airpress.log" ){
unlink($input["log"]);
$manual_intervention = false;
}
} else {
add_settings_error('airpress_cx_log', esc_attr( 'settings_updated' ), "Failed to delete log file. Please manually delete.","error");
}
}
// if ( $manual_intervention ){
// add_settings_error('airpress_cx_log', esc_attr( 'settings_updated' ), "Please delete the log file at " . esc_attr($input["log"]),"error");
// }
}
$wp_rewrite->flush_rules();
return $input;
}
function airpress_admin_cx_render_section__general() {
echo '' . __( 'Provides examples of the five basic element types.', 'sandbox' ) . '
';
}
function airpress_admin_cx_render_section() {
echo '' . __( '', 'airpress' ) . '
';
}
function airpress_admin_cx_render_element_text($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
echo ' ';
}
function airpress_admin_cx_render_element_toggle($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
$checked = checked( 1, isset( $options[$field_name] ) ? $options[$field_name] : 0, false );
echo ' ';
echo ' ' . $field_name . ' ';
}
function airpress_admin_cx_render_element_select__posttypes($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
$post_types = airpress_get_posttypes_available();
echo '';
foreach ( $post_types as $post_type ) {
$selected = (in_array($post_type, $options[$field_name]))? "selected" : "";
echo ''.$post_type.' ';
}
echo ' ';
}
function airpress_admin_cx_render_element_select_connections($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
$connections = get_airpress_configs("airpress_cx");
echo '';
foreach ( $connections as $connection ) {
$selected = (in_array($connection["name"], $options[$field_name]))? "selected" : "";
echo ''.$connection["name"].' ';
}
echo ' ';
}
function airpress_admin_cx_render_element_select__page($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
$pages = get_pages();
echo '';
foreach ( $pages as $page ) {
$selected = ($options[$field_name] == $page->ID)? " selected" : "";
$option = '';
$option .= $page->post_title." (".$page->post_name.")";
$option .= ' ';
echo $option;
}
echo ' ';
}
function airpress_admin_cx_render_element_select__debug($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
echo '';
$select_options = array(0 => "Disabled", 1 => "Admin Bar & Logfile", 2 => "Logfile only", 3 => "Admin Bar only");
foreach ( $select_options as $value => $label ) {
$selected = ($options[$field_name] == $value)? " selected" : "";
$option = '';
$option .= $label;
$option .= ' ';
echo $option;
}
echo ' ';
}
function airpress_admin_cx_render_element_delete($args) {
$options = $args[0];
$option_name = $args[1];
$field_name = $args[2];
$tab = (int)$_GET["tab"];
echo "Yes, delete this configuration ";
}
?>