Ejemplo n.º 1
0
function randomtext_edit($randomtext_id = 0)
{
    echo '<div class="wrap">';
    $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 = '<h2>The requested entry was not found.</h2>';
        }
    } else {
        $row = new stdClass();
        $row->text = '';
        $row->visible = 'yes';
    }
    echo randomtext_pagetitle($title);
    if ($randomtext_id && !$row) {
        echo '<h3>The requested entry was not found.</h3>';
    } else {
        // display the add/edit form
        global $randomtext_adminurl;
        echo '<form method="post" action="' . $randomtext_adminurl . '">
		' . wp_nonce_field('randomtext_edit' . $randomtext_id) . '
		<input type="hidden" id="randomtext_id" name="randomtext_id" value="' . $randomtext_id . '">
		<h3>Text To Display</h3>
		<textarea name="randomtext_text" style="width: 80%; height: 100px;">' . apply_filters('format_to_edit', $row->text) . '</textarea>
		<h3>Category</h3>
		<p>Select a category from the list or enter a new one.</p>
		<label for="randomtext_category">Category: </label><select id="randomtext_category" name="randomtext_category">';
        echo randomtext_get_category_options($row->category);
        echo '</select></p>
		<p><label for="randomtext_category_new">New Category: </label><input type="text" id="randomtext_category_new" name="randomtext_category_new"></p>';
        echo '<h3>Is visible.</h3>
			<p><label for="randomtext_visible_yes"><input type="radio" id="randomtext_visible_yes" name="randomtext_visible" value="yes" ' . checked($row->visible, 'yes', false) . ' /> Yes</label>&nbsp;&nbsp;&nbsp;&nbsp;
			<label for="randomtext_visible_no"><input type="radio" id="randomtext_visible_no" name="randomtext_visible" value="no" ' . checked($row->visible, 'no', false) . ' /> No</label></p>';
        if (!$randomtext_id) {
            // don't offer Bulk Insert on edit
            echo '<h3>Use Bulk Insert</h3>
			<p><input type="radio" name="randomtext_bulkinsert" value="yes" /> Yes&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="randomtext_bulkinsert" value="no" checked="checked" /> No</p>
			<small>Bulk insert will create a new record for each line (delimited by carriage return) within the text box above using the same category selected.<br />Empty lines will be ignored.</small>';
        }
        echo '<div class="submit">
			<input class="button-primary" type="submit" name="randomtext_Save" value="Save Changes" />
			</div>
			</form>
			
			<p>Return to <a href="' . $randomtext_adminurl . '">Random Text summary page</a>.</p>';
    }
    echo '</div>';
}
Ejemplo n.º 2
0
    function form($instance)
    {
        $instance = wp_parse_args((array) $instance, array('title' => 'Random Text', 'category' => '', 'pretext' => '', 'posttext' => ''));
        $title = htmlspecialchars($instance['title']);
        $category = htmlspecialchars($instance['category']);
        $pretext = htmlspecialchars($instance['pretext']);
        $posttext = htmlspecialchars($instance['posttext']);
        ${'random_' . intval($instance['random'])} = ' SELECTED';
        echo '<p>
				<label for="' . $this->get_field_name('title') . '">Title: </label> 
				<input type="text" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" value="' . $title . '"/>
			</p><p>
				<label for="' . $this->get_field_name('pretext') . '">Pre-Text: </label> 
				<input type="text" id="' . $this->get_field_id('pretext') . '" name="' . $this->get_field_name('pretext') . '" value="' . $pretext . '"/>
			</p><p>
				<label for="' . $this->get_field_name('category') . '">Category: </label>
				<select id="' . $this->get_field_id('category') . '" name="' . $this->get_field_name('category') . '">
				<option value="">All Categories </option>';
        echo randomtext_get_category_options($instance['category']);
        echo '</select></p>
			<p>
				<label for="' . $this->get_field_name('posttext') . '">Post-Text: </label> 
				<input type="text" id="' . $this->get_field_id('posttext') . '" name="' . $this->get_field_name('posttext') . '" value="' . $posttext . '"/>
			</p>
			<p>
				<label for="' . $this->get_field_name('random') . '">Selection: </label> 
				<select id="' . $this->get_field_id('random') . '" name="' . $this->get_field_name('random') . '">
				<option value="1" ' . $random_1 . '>Random</option>
				<option value="0" ' . $random_0 . '>Rotation</option>
				</select><br/>
				<span class="description">Note: Random can be more intensive with large record sets, and some items may never appear.</span>
			</p>';
    }