Beispiel #1
0
 /**
  * Creates form fields
  *
  * Creates various form fields and returns them as a string.
  *
  * @since 1.8
  *
  * @param  string $name the name of the field
  * @param  string $type the field type
  * @param  string $value the default value for the field
  * @param  string $valtochk optional for comparing the default value of the field
  * @param  string $class optional for setting a specific CSS class for the field 
  * @return string $str the field returned as a string
  */
 function wpmem_create_formfield($name, $type, $value, $valtochk = null, $class = 'textbox')
 {
     switch ($type) {
         case "checkbox":
             if ($class == 'textbox') {
                 $class = "checkbox";
             }
             $str = "<input name=\"{$name}\" type=\"{$type}\" id=\"{$name}\" value=\"{$value}\"" . wpmem_selected($value, $valtochk, $type) . " />";
             break;
         case "text":
             $value = stripslashes(esc_attr($value));
             $str = "<input name=\"{$name}\" type=\"{$type}\" id=\"{$name}\" value=\"{$value}\" class=\"{$class}\" />";
             break;
         case "textarea":
             $value = stripslashes(esc_textarea($value));
             if ($class == 'textbox') {
                 $class = "textarea";
             }
             $str = "<textarea cols=\"20\" rows=\"5\" name=\"{$name}\" id=\"{$name}\" class=\"{$class}\">{$value}</textarea>";
             break;
         case "password":
             $str = "<input name=\"{$name}\" type=\"{$type}\" id=\"{$name}\" class=\"{$class}\" />";
             break;
         case "hidden":
             $str = "<input name=\"{$name}\" type=\"{$type}\" value=\"{$value}\" />";
             break;
         case "option":
             $str = "<option value=\"{$value}\" " . wpmem_selected($value, $valtochk, 'select') . " >{$name}</option>";
             break;
         case "select":
             if ($class == 'textbox') {
                 $class = "dropdown";
             }
             $str = "<select name=\"{$name}\" id=\"{$name}\" class=\"{$class}\">\n";
             foreach ($value as $option) {
                 $pieces = explode('|', $option);
                 $str = $str . "<option value=\"{$pieces['1']}\"" . wpmem_selected($pieces[1], $valtochk, 'select') . ">" . __($pieces[0], 'wp-members') . "</option>\n";
             }
             $str = $str . "</select>";
             break;
     }
     return $str;
 }
Beispiel #2
0
/**
 * Create a dropdown selection of pages.
 *
 * @since 2.8.1
 *
 * @param string $val
 */
function wpmem_admin_page_list($val, $show_custom_url = true)
{
    $selected = $val == 'http://' ? 'select a page' : false;
    $pages = get_pages();
    echo '<option value=""';
    echo $selected == 'select a page' ? ' selected' : '';
    echo '>';
    echo esc_attr(__('Select a page'));
    echo '</option>';
    foreach ($pages as $page) {
        $selected = get_page_link($page->ID) == $val ? true : $selected;
        $option = '<option value="' . get_page_link($page->ID) . '"' . wpmem_selected(get_page_link($page->ID), $val, 'select') . '>';
        $option .= $page->post_title;
        $option .= '</option>';
        echo $option;
    }
    if ($show_custom_url) {
        $selected = !$selected ? ' selected' : '';
        echo '<option value="use_custom"' . $selected . '>' . __('USE CUSTOM URL BELOW', 'wp-members') . '</option>';
    }
}
Beispiel #3
0
/**
 * Function to dispay the add/edit field form.
 *
 * @since 2.8
 *
 * @param string      $mode The mode for the function (edit|add)
 * @param array|null  $wpmem_fields the array of fields
 * @param string|null $field the field being edited
 */
function wpmem_a_field_edit($mode, $wpmem_fields = null, $field = null)
{
    if ($mode == 'edit') {
        for ($row = 0; $row < count($wpmem_fields); $row++) {
            if ($wpmem_fields[$row][2] == $field) {
                $field_arr = $wpmem_fields[$row];
            }
        }
    }
    $form_action = $mode == 'edit' ? 'editfieldform' : 'addfieldform';
    ?>
	<div class="postbox">
		<h3 class="title"><?php 
    $mode == 'edit' ? _e('Edit Field', 'wp-members') : _e('Add a Field', 'wp-members');
    ?>
</h3>
		<div class="inside">
			<form name="<?php 
    echo $form_action;
    ?>
" id="<?php 
    echo $form_action;
    ?>
" method="post" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
">
				<?php 
    wp_nonce_field('wpmem-add-fields');
    ?>
				<ul>
					<li>
						<label><?php 
    _e('Field Label', 'wp-members');
    ?>
</label>
						<input type="text" name="add_name" value="<?php 
    echo $mode == 'edit' ? $field_arr[1] : false;
    ?>
" />
						<?php 
    _e('The name of the field as it will be displayed to the user.', 'wp-members');
    ?>
					</li>
					<li>
						<label><?php 
    _e('Option Name', 'wp-members');
    ?>
</label>
						<?php 
    if ($mode == 'edit') {
        echo $field_arr[2];
        ?>
							<input type="hidden" name="add_option" value="<?php 
        echo $field_arr[2];
        ?>
" /> 
						<?php 
    } else {
        ?>
							<input type="text" name="add_option" value="" />
							<?php 
        _e('The database meta value for the field. It must be unique and contain no spaces (underscores are ok).', 'wp-members');
        ?>
						<?php 
    }
    ?>
					</li>
					<li>
						<label><?php 
    _e('Field Type', 'wp-members');
    ?>
</label>
						<?php 
    if ($mode == 'edit') {
        echo $field_arr[3];
        ?>
							<input type="hidden" name="add_type" value="<?php 
        echo $field_arr[3];
        ?>
" /> 							
						<?php 
    } else {
        ?>
						
							<select name="add_type" id="wpmem_field_type_select">
								<option value="text"><?php 
        _e('text', 'wp-members');
        ?>
</option>
								<option value="textarea"><?php 
        _e('textarea', 'wp-members');
        ?>
</option>
								<option value="checkbox"><?php 
        _e('checkbox', 'wp-members');
        ?>
</option>
								<option value="select"><?php 
        _e('dropdown', 'wp-members');
        ?>
</option>
								<option value="password"><?php 
        _e('password', 'wp-members');
        ?>
</option>
								<option value="file"><?php 
        _e('file', 'wp-members');
        ?>
</option>
							</select>
						<?php 
    }
    ?>
					</li>
					<li>
						<label><?php 
    _e('Display?', 'wp-members');
    ?>
</label>
						<input type="checkbox" name="add_display" value="y" <?php 
    echo $mode == 'edit' ? wpmem_selected('y', $field_arr[4]) : false;
    ?>
 />
					</li>
					<li>
						<label><?php 
    _e('Required?', 'wp-members');
    ?>
</label>
						<input type="checkbox" name="add_required" value="y" <?php 
    echo $mode == 'edit' ? wpmem_selected('y', $field_arr[5]) : false;
    ?>
 />
					</li>
				<?php 
    if ($mode == 'add' || $mode == 'edit' && $field_arr[3] == 'file') {
        ?>
				<?php 
        echo $mode == 'add' ? '<div id="wpmem_file_info">' : '';
        ?>
					<li>
						<strong><?php 
        _e('Additional information for field upload fields', 'wp-members');
        ?>
</strong>
					</li>
					<li>
						<label><?php 
        _e('Accepted file types:', 'wp-members');
        ?>
</label>
						<input type="text" name="add_file_value" value="<?php 
        echo $mode == 'edit' && $field_arr[3] == 'file' ? $field_arr[7] : false;
        ?>
" />
					</li>
					<li>
						<label>&nbsp;</label>
						<span class="description"><?php 
        _e('Accepted file types should be set like this: jpg|jpeg|png|gif', 'wp-members');
        ?>
					</li>
				<?php 
        echo $mode == 'add' ? '</div>' : '';
        ?>
				<?php 
    }
    ?>
				<?php 
    if ($mode == 'add' || $mode == 'edit' && $field_arr[3] == 'checkbox') {
        ?>
				<?php 
        echo $mode == 'add' ? '<div id="wpmem_checkbox_info">' : '';
        ?>
					<li>
						<strong><?php 
        _e('Additional information for checkbox fields', 'wp-members');
        ?>
</strong>
					</li>
					<li>
						<label><?php 
        _e('Checked by default?', 'wp-members');
        ?>
</label>
						<input type="checkbox" name="add_checked_default" value="y" <?php 
        echo $mode == 'edit' && $field_arr[3] == 'checkbox' ? wpmem_selected('y', $field_arr[8]) : false;
        ?>
 />
					</li>
					<li>
						<label><?php 
        _e('Stored value if checked:', 'wp-members');
        ?>
</label>
						<input type="text" name="add_checked_value" value="<?php 
        echo $mode == 'edit' && $field_arr[3] == 'checkbox' ? $field_arr[7] : false;
        ?>
" class="small-text" />
					</li>
				<?php 
        echo $mode == 'add' ? '</div>' : '';
        ?>
				<?php 
    }
    ?>
				<?php 
    if ($mode == 'add' || $mode == 'edit' && $field_arr[3] == 'select') {
        ?>
				<?php 
        echo $mode == 'add' ? '<div id="wpmem_dropdown_info">' : '';
        ?>
					<li>
						<strong><?php 
        _e('Additional information for dropdown fields', 'wp-members');
        ?>
</strong>
					</li>
					<li>
						<label><?php 
        _e('For dropdown, array of values:', 'wp-members');
        ?>
</label>
						<textarea name="add_dropdown_value" rows="5" cols="40"><?php 
        // Accomodate editing the current dropdown values or create dropdown value example.
        if ($mode == 'edit') {
            for ($row = 0; $row < count($field_arr[7]); $row++) {
                // If the row contains commas (i.e. 1,000-10,000), wrap in double quotes.
                if (strstr($field_arr[7][$row], ',')) {
                    echo '"' . $field_arr[7][$row];
                    echo $row == count($field_arr[7]) - 1 ? '"' : "\",\n";
                } else {
                    echo $field_arr[7][$row];
                    echo $row == count($field_arr[7]) - 1 ? "" : ",\n";
                }
            }
        } else {
            if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
                ?>
<---- Select One ---->|,
Choice One|choice_one,
"1,000|one_thousand",
"1,000-10,000|1,000-10,000",
Last Row|last_row<?php 
            } else {
                ?>
<---- Select One ---->|,
Choice One|choice_one,
Choice 2|choice_two,
Last Row|last_row<?php 
            }
        }
        ?>
</textarea>
					</li>
					<li>
						<label>&nbsp;</label>
						<span class="description"><?php 
        _e('Options should be Option Name|option_value,', 'wp-members');
        ?>
					</li>
					<li>
						<label>&nbsp;</label>
						<a href="http://rocketgeek.com/plugins/wp-members/users-guide/registration/choosing-fields/" target="_blank"><?php 
        _e('Visit plugin site for more information', 'wp-members');
        ?>
</a></span>
					</li>
				<?php 
        echo $mode == 'add' ? '</div>' : '';
        ?>
				<?php 
    }
    ?>

				</ul><br />
				<?php 
    if ($mode == 'edit') {
        ?>
<input type="hidden" name="field_arr" value="<?php 
        echo $field_arr[2];
        ?>
" /><?php 
    }
    ?>
				<input type="hidden" name="wpmem_admin_a" value="<?php 
    echo $mode == 'edit' ? 'edit_field' : 'add_field';
    ?>
" />
				<input type="submit" name="save"  class="button-primary" value="<?php 
    echo $mode == 'edit' ? __('Edit Field', 'wp-members') : __('Add Field', 'wp-members');
    ?>
 &raquo;" /> 
			</form>
		</div>
	</div>
<?php 
}
/**
 * Create a dropdown selection of pages
 *
 * @since 2.8.1
 *
 * @param string $val
 */
function wpmem_admin_page_list($val)
{
    echo '<option value="">';
    echo esc_attr(__('Select a page'));
    echo '</option>';
    $pages = get_pages();
    foreach ($pages as $page) {
        $option = '<option value="' . get_page_link($page->ID) . '" ' . wpmem_selected(get_page_link($page->ID), $val, 'select') . '>';
        $option .= $page->post_title;
        $option .= '</option>';
        echo $option;
    }
    echo '<option value="">';
    _e('USE CUSTOM URL ---->', 'wp-members');
    echo '</option>';
}