function custom_options_plus_adm()
{
    global $wpdb, $my_plugin_hook;
    wp_enqueue_script('stringToSlug', COP_PLUGIN_URL . '/js/jquery.stringToSlug.min.js', array('jquery'), '2.5.9');
    wp_enqueue_script('copFunctions', COP_PLUGIN_URL . '/js/functions.js', array('stringToSlug'));
    $id = '';
    $label = '';
    $name = '';
    $value = '';
    $message = '';
    if (isset($_GET['del']) && $_GET['del'] > 0) {
        if (cop_delete($_GET['del'])) {
            $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';
        }
    } elseif (isset($_POST['id'])) {
        if ($_POST['id'] == '') {
            cop_insert();
            $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';
        } elseif ($_POST['id'] > 0) {
            cop_update();
            $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';
        }
    } elseif (isset($_GET['id']) && $_GET['id'] > 0) {
        $option = cop_get_option($_GET['id']);
        $id = $option->id;
        $label = $option->label;
        $name = $option->name;
        $value = $option->value;
    }
    $options = cop_get_options();
    ?>


	<div class="wrap">
		<div id="icon-tools" class="icon32"></div><h2>Custom Options Plus <a href="<?php 
    echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']);
    ?>
#new-custom-option" class="add-new-h2">Add New</a></h2>

		<?php 
    echo $message;
    ?>

		<br />
		<?php 
    if (count($options) > 0) {
        ?>

			<div class="wpbody-content">
				<table class="wp-list-table widefat" cellspacing="0">
					<thead>
						<tr>
							<th scope="col" class="manage-column " style="min-width: 100px">Label</th>
							<th scope="col" class="manage-column column-title">Name</th>
							<th scope="col" class="manage-column column-title">Value</th>
						</tr>
					</thead>
                    <tfoot>
						<tr>
							<th scope="col" class="manage-column column-title">Label</th>
							<th scope="col" class="manage-column column-title">Name</th>
							<th scope="col" class="manage-column column-title">Value</th>
						</tr>
					</tfoot>
					<tbody id="the-list">
						<?php 
        $trclass = 'class="alternate"';
        foreach ($options as $option) {
            ?>

						<tr <?php 
            echo $trclass;
            ?>
 rowspan="2">
							<td>
                            	<?php 
            echo $option->label;
            ?>

                                <div class="row-actions">
                                	<span class="edit"><a href="<?php 
            echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']);
            ?>
&amp;id=<?php 
            echo $option->id;
            ?>
#new-custom-option">Edit</a> | </span>
                                    <span class="delete"><a onclick="return confirm('Are you sure want to delete item?')" class="submitdelete" title="Delete <?php 
            echo $option->label;
            ?>
" href="<?php 
            echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']);
            ?>
&del=<?php 
            echo $option->id;
            ?>
">Delete</a></span>
                                </div>
                            </td>
                            <td>
                            	<textarea style="font-size:12px;" type="text" onclick="this.select();" onfocus="this.select();" readonly="readonly" class="shortcode-in-list-table wp-ui-text-highlight code"><?php 
            echo $option->name;
            ?>
</textarea>
                            </td>
							<td><div style="overflow:auto; min-height:99%; width:99%; margin:2px; padding:2px; background-color:#eee; clear:both;"><?php 
            echo $option->value;
            ?>
</div></td>
						</tr>
						<?php 
            $trclass = $trclass == 'class="alternate"' ? '' : 'class="alternate"';
        }
        ?>

					</tbody>
				</table>
			</div>
		<br />
		<?php 
    }
    ?>


		<form method="post" action="<?php 
    echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']);
    ?>
">
			<input type="hidden" name="id" value="<?php 
    echo $id;
    ?>
" />
			<h3 id="new-custom-option">Add new Custom Option</h3>
			<table class="form-table">
				<tbody>
					<tr valign="top">
						<th scope="row">
							<label for="label">Label:</label>
						</td>
						<td>
							<input name="label" type="text" id="label" value="<?php 
    echo $label;
    ?>
" class="regular-text">
						</td>
					</tr>
					<tr>
						<th scope="row">
							<label for="name">*Name:</label>
						</td>
						<td>
							<input name="name" type="text" id="name" value="<?php 
    echo $name;
    ?>
" class="regular-text">
						</td>
					</tr>
					<tr>
						<th scope="row">
							<label for="value">Value:</label>
						</td>
						<td>
							<textarea name="value" rows="7" cols="40" type="text" id="value" class="regular-text code"><?php 
    echo $value;
    ?>
</textarea>
						</td>
					</tr>
				</tbody>
			</table>
			<p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="<?php 
    _e('Save Changes');
    ?>
"></p>
		</form>

	</div>
<?php 
}
Ejemplo n.º 2
0
function custom_options_plus_adm()
{
    global $wpdb, $my_plugin_hook;
    $id = '';
    $label = '';
    $name = '';
    $value = '';
    $message = '';
    if (isset($_GET['del']) && $_GET['del'] > 0) {
        if (cop_delete($_GET['del'])) {
            $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';
        }
    } elseif (isset($_POST['id'])) {
        if ($_POST['id'] == '') {
            cop_insert();
            $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';
        } elseif ($_POST['id'] > 0) {
            cop_update();
            $message = '<div class="updated"><p><strong>' . __('Settings saved.') . '</strong></p></div>';
        }
    } elseif (isset($_GET['id']) && $_GET['id'] > 0) {
        $option = cop_get_option($_GET['id']);
        $id = $option->id;
        $label = $option->label;
        $name = $option->name;
        $value = $option->value;
    }
    $options = cop_get_options();
    ?>
	
	<div class="wrap">
		<div id="icon-tools" class="icon32"></div><h2>Custom Options Plus</h2>
		
		<?php 
    echo $message;
    ?>
		<br />
		<?php 
    if (count($options) > 0) {
        ?>
			<div class="wpbody-content">
				<table class="widefat" cellspacing="0">
					<thead>
						<tr>
							<th>Label</th>
							<th>Name</th>
							<th>Value</th>
							<th> </th>
						</tr>
					</thead>
					<tbody>
						<?php 
        foreach ($options as $option) {
            ?>
						<tr>
							<td><a title="Edit <?php 
            echo $option->label;
            ?>
" href="<?php 
            echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']);
            ?>
&id=<?php 
            echo $option->id;
            ?>
"><?php 
            echo $option->label;
            ?>
</a></td>
							<td><a title="Edit <?php 
            echo $option->label;
            ?>
" href="<?php 
            echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']);
            ?>
&id=<?php 
            echo $option->id;
            ?>
"><?php 
            echo $option->name;
            ?>
</a></td>
							<td><a title="Edit <?php 
            echo $option->label;
            ?>
" href="<?php 
            echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']);
            ?>
&id=<?php 
            echo $option->id;
            ?>
"><?php 
            echo $option->value;
            ?>
</a></td>
							<td><span class="trash"><a onclick="return confirm('Are you sure want to delete item?')" class="submitdelete" title="Delete <?php 
            echo $option->label;
            ?>
" href="<?php 
            echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']);
            ?>
&del=<?php 
            echo $option->id;
            ?>
">Delete</a></span></td>
						</tr>
						<?php 
        }
        ?>
					</tbody>
				</table>
			</div>
		<br />
		<?php 
    }
    ?>
		
		<form method="post" action="<?php 
    echo preg_replace('/\\&.*/', '', $_SERVER['REQUEST_URI']);
    ?>
">
			<input type="hidden" name="id" value="<?php 
    echo $id;
    ?>
" />
			<h3>Add new Custom Option</h3>
			<table class="form-table">				
				<tbody>
					<tr valign="top">
						<th scope="row">
							<label for="label">Label:</label>
						</td>
						<td>
							<input name="label" type="text" id="label" value="<?php 
    echo $label;
    ?>
" class="regular-text">
						</td>
					</tr>
					<tr>
						<th scope="row">
							<label for="name">*Name:</label>
						</td>
						<td>
							<input name="name" type="text" id="name" value="<?php 
    echo $name;
    ?>
" class="regular-text">
						</td>						
					</tr>
					<tr>
						<th scope="row">
							<label for="value">Value:</label>
						</td>
						<td>
							<textarea name="value" rows="7" cols="40" type="text" id="value" class="regular-text code"><?php 
    echo $value;
    ?>
</textarea>
						</td>						
					</tr>
				</tbody>
			</table>
			<p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="<?php 
    _e('Save Changes');
    ?>
"></p>
		</form>
		
	</div>
<?php 
}