示例#1
0
 /**
  * Test adding a new prefix.
  */
 function test_prefixes_add_and_delete()
 {
     // Create a random prefix and an example namespace.
     $prefix = uniqid('prefix');
     $namespace = 'http://example.org/ns/';
     // Check that the prefix doesn't exist yet.
     $this->assertFalse(wl_prefixes_get($prefix));
     // Add the prefix.
     wl_prefixes_add($prefix, $namespace);
     $path = uniqid('this/is/a/test/');
     // Compact a URL.
     $url_to_compact = $namespace . $path;
     $url_compacted = wl_prefixes_compact($url_to_compact);
     $this->assertEquals($prefix . ':' . $path, $url_compacted);
     // Expand a URL.
     $url_to_expand = $url_compacted;
     $url_expanded = wl_prefixes_expand($url_to_expand);
     $this->assertEquals($namespace . $path, $url_expanded);
     // Check the namespace.
     $this->assertEquals($namespace, wl_prefixes_get($prefix));
     // Now delete the prefix.
     wl_prefixes_delete($prefix);
     // Check that the prefix doesn't exist.
     $this->assertFalse(wl_prefixes_get($prefix));
 }
/**
 * Displays the page content.
 *
 * @since 3.0.0
 *
 * @param boolean $display_page_title If true, prints out the page title.
 */
function wl_prefixes_admin_menu_callback($display_page_title = true)
{
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    $page_title = __('Prefixes', 'wordlift');
    echo '<div class="wrap">';
    if ($display_page_title) {
        echo "<h2>{$page_title}</h2>";
    }
    echo <<<EOF
    <br class="clear">

    <div id="col-container">

        <div id="col-right">
            <div class="col-wrap">
EOF;
    // Create the List Table.
    $wl_prefixes_table = new WL_Prefixes_List_Table();
    // See if we have an action.
    switch ($wl_prefixes_table->current_action()) {
        // Add the prefix using the provided data.
        case 'add-prefix':
            check_admin_referer('add-prefix', '_wpnonce_add-prefix');
            if (!current_user_can('manage_options')) {
                wp_die(__('Cheatin&#8217; uh?'));
            }
            wl_prefixes_add($_POST['prefix'], $_POST['namespace']);
            break;
            // Delete a prefix.
        // Delete a prefix.
        case 'delete':
            if (!current_user_can('manage_options')) {
                wp_die(__('Cheatin&#8217; uh?'));
            }
            wl_prefixes_delete($_GET['prefix']);
            break;
        case 'bulk-delete':
            $prefixes = (array) $_REQUEST['prefix'];
            foreach ($prefixes as $prefix) {
                wl_prefixes_delete($prefix);
            }
            break;
    }
    $wl_prefixes_table->prepare_items();
    $wl_prefixes_table->display();
    ?>
	</div>
	</div><!-- /col-right -->

	<div id="col-left">
		<div class="col-wrap">

			<div class="form-wrap">
				<h3>Add New Prefix</h3>

				<form id="addprefix" method="post" class="validate">
					<input type="hidden" name="action" value="add-prefix">
					<?php 
    wp_nonce_field('add-prefix', '_wpnonce_add-prefix');
    ?>

					<div class="form-field form-required">
						<label for="prefix"><?php 
    _e('Prefix', 'wordlift');
    ?>
</label>
						<input name="prefix" id="prefix" type="text" value="" size="40" aria-required="true">

						<p><?php 
    __('The namespace prefix.', 'wordlift');
    ?>
</p>
					</div>
					<div class="form-field">
						<label for="namespace"><?php 
    _e('Namespace', 'wordlift');
    ?>
</label>
						<input name="namespace" id="namespace" type="text" value="" size="128">

						<p><?php 
    __('The namespace URL.', 'wordlift');
    ?>
</p>
					</div>

					<?php 
    submit_button(__('Add New Prefix', 'wordlift'));
    ?>

				</form>
			</div>
		</div>
	</div><!-- /col-left -->

	</div><!-- /col-container -->
	</div>

<?php 
}