Settings';
array_unshift($links, $settings_link);
return $links;
}
add_filter("plugin_action_links_$plugin_basename", 'randomtext_settings_link' );
function randomtext_options() {
if($_POST) {
// process the posted data and display summary page - not pretty :(
randomtext_save($_POST);
}
$action = isset($_GET['action']) ? $_GET['action'] : false;
switch($action){
case 'new' :
randomtext_edit();
break;
case 'edit' :
$id = intval($_GET['id']);
randomtext_edit($id);
break;
case 'delete' :
$id = intval($_GET['id']);
check_admin_referer('randomtext_delete'.$id);
randomtext_delete($id);
// now display summary page
randomtext_list();
break;
default:
randomtext_list();
}
}
function randomtext_pagetitle($suffix='') {
return '
';
$title = '- Add New';
if($randomtext_id) {
$title = '- Edit';
global $wpdb;
$table_name = $wpdb->prefix . 'randomtext';
$sql = "SELECT * from $table_name where randomtext_id=$randomtext_id";
$row = $wpdb->get_row($sql);
if(!$row)
$error_text = '
The requested entry was not found.
';
} else {
$row = new stdClass();
$row->text = '';
$row->visible = 'yes';
}
echo randomtext_pagetitle($title);
if($randomtext_id && !$row) {
echo '
The requested entry was not found.
';
} else {
// display the add/edit form
global $randomtext_adminurl;
echo '
Return to Random Text summary page.
';
}
echo '
';
}
function randomtext_save($data) {
global $wpdb, $user_ID;
$table_name = $wpdb->prefix . 'randomtext';
$randomtext_id = intval($data['randomtext_id']);
check_admin_referer('randomtext_edit'.$randomtext_id);
$sqldata = array();
$category_new = trim($data['randomtext_category_new']);
$sqldata['category'] = ($category_new) ? $category_new : $data['randomtext_category'];
$sqldata['user_id'] = $user_ID;
$sqldata['visible'] = $data['randomtext_visible'];
// check for "Bulk Insert"
$do_bulkinsert = isset($data['randomtext_bulkinsert']) ? $data['randomtext_bulkinsert'] : 'no';
if ($do_bulkinsert == 'yes') {
// Split the data by carriage returns
$lines = preg_split("/[\n|\r]/", trim(stripslashes($data['randomtext_text'])));
foreach ($lines as $key=>$value) {
// Ignore empty lines
if (!empty($value)) {
// Set the datavalue and insert
$sqldata['text'] = $value;
$wpdb->insert($table_name, $sqldata);
}
}
} else {
// single record insert/update
$sqldata['text'] = trim(stripslashes($data['randomtext_text']));
if($randomtext_id)
$wpdb->update($table_name, $sqldata, array('randomtext_id'=>$randomtext_id));
else
$wpdb->insert($table_name, $sqldata);
}
}
function randomtext_delete($id) {
global $wpdb;
$table_name = $wpdb->prefix . 'randomtext';
$id = intval($id);
$sql = "DELETE FROM $table_name WHERE randomtext_id = $id";
$wpdb->query($sql);
}
?>