prefix . "alm";
// **********************************************
// If table exists
// **********************************************
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
// Updated 2.0.5
// Check column 'name' exists in $wpdb - this is an upgrade checker.
$row = $wpdb->get_col("Show columns from $table_name like 'name'");
if(empty($row)){
$wpdb->query("ALTER TABLE $table_name ADD name TEXT NOT NULL");
$wpdb->update($table_name , array('name' => 'default'), array('id' => 1));
}
// ********
// @TO-DO - Upgrade test, will remove in future versions
// REMOVED - 2.1.3
// ********
$test = $wpdb->get_col("Show columns from $table_name like 'test'");
if(!empty($test)){
$wpdb->query("ALTER TABLE $table_name DROP test");
}
//Add column for repeater template alias
$alias = $wpdb->get_col("Show columns from $table_name like 'alias'");
if(empty($alias)){
$wpdb->query("ALTER TABLE $table_name ADD alias TEXT NOT NULL");
}
// Compare versions of repeaters, if template versions do not match, update the repeater with value from DB
$version = $wpdb->get_var("SELECT pluginVersion FROM $table_name WHERE name = 'default'");
if($version != ALM_VERSION){ // First, make sure versions do not match.
//Write to repeater file
$data = $wpdb->get_var("SELECT repeaterDefault FROM $table_name WHERE name = 'default'");
$f = ALM_PATH. 'core/repeater/default.php'; // File
$o = fopen($f, 'w+'); //Open file
$w = fwrite($o, $data); //Save the file
$r = fread($o, 100000); //Read it
fclose($o); //now close it
}
}
// **********************************************
// If table DOES NOT exist, create it.
// **********************************************
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
$createRepeater = '
'. __('Error Opening File', ALM_NAME) .'';
$o_error .= ''. $f .'';
$o_error .= __('Please check your file path and ensure your server is configured to allow Ajax Load More to read and write files within the /ajax-load-more/ plugin directory', ALM_NAME);
$w_error = ''. __('Error Saving File', ALM_NAME) .'';
$w_error .= ''. $f .'';
$w_error .= __('Please check your file path and ensure your server is configured to allow Ajax Load More to read and write files within the /ajax-load-more/ plugin directory', ALM_NAME);
// Open file
$o = fopen($f, 'w+') or die($o_error);
// Save/Write the file
$w = fwrite($o, $c) or die($w_error);
// $r = fread($o, 100000); //Read it
fclose($o); //now close it
//Save to database
global $wpdb;
$table_name = $wpdb->prefix . "alm";
if($t === 'default') {
$data_update = array('repeaterDefault' => "$c", 'pluginVersion' => ALM_VERSION);
$data_where = array('name' => "default");
}
elseif($t === 'unlimited'){ // Unlimited Repeaters
$table_name = $wpdb->prefix . "alm_unlimited";
$data_update = array('repeaterDefault' => "$c", 'alias' => "$a", 'pluginVersion' => ALM_UNLIMITED_VERSION);
$data_where = array('name' => $n);
}
else{ // Custom Repeaters
$data_update = array('repeaterDefault' => "$c", 'alias' => "$a", 'pluginVersion' => ALM_REPEATER_VERSION);
$data_where = array('name' => $n);
}
$wpdb->update($table_name , $data_update, $data_where);
//Our results
if($w){
echo 'Template Saved Successfully';
} else {
echo ''. __('Error Writing File', ALM_NAME) .' Something went wrong and the data could not be saved.';
}
die();
}
/*
* alm_update_repeater
* Update repeater from database function
*
* - User story: User deletes plugin, the installs again and the version has not change - their default repeater will be in the default state and unable to be updated.
*
* COMING SOON
* @since 2.4
*/
function alm_update_repeater(){
$nonce = $_POST["nonce"];
// Check our nonce, if they don't match then bounce!
if (! wp_verify_nonce( $nonce, 'alm_repeater_nonce' ))
die('Get Bounced!');
// Get _POST Vars
$n = Trim(stripslashes($_POST["repeater"])); // Repeater name
$t = Trim(stripslashes($_POST["type"])); // Repeater name
// Get value from database
//Save to database
global $wpdb;
$table_name = $wpdb->prefix . "alm";
if($t === 'default') $n = 'default';
if($t === 'unlimited') $table_name = $wpdb->prefix . "alm_unlimited";
$the_repeater = $wpdb->get_var("SELECT repeaterDefault FROM " . $table_name . " WHERE name = '$n'");
echo $the_repeater;
die();
}
/*
* alm_shortcode_builder_page
* Shortcode Builder
*
* @since 2.0.0
*/
function alm_shortcode_builder_page(){ ?>
shortcode by adjusting the values below', ALM_NAME); ?>