get() публичный статический Метод

Get mapping by mapping ID
public static get ( integer | Mapping $mapping ) : Mapping | WP_Erro\WP_Error | null
$mapping integer | Mapping Mapping ID or instance
Результат Mapping | WP_Erro\WP_Error | null Mapping on success, WP_Error if error occurred, or null if no mapping found
Пример #1
0
 /**
  * Delete a single mapping
  *
  * ## OPTIONS
  *
  * <id>
  * : Mapping ID
  */
 public function delete($args)
 {
     $mapping = Mapping::get($args[0]);
     if (empty($mapping)) {
         $mapping = new WP_Error('mercator.cli.mapping_not_found', __('Invalid mapping ID', 'mercator'));
     }
     if (is_wp_error($mapping)) {
         return WP_CLI::error($mapping->get_error_message());
     }
     $result = $mapping->delete();
     if (empty($result) || is_wp_error($result)) {
         return WP_CLI::error(__('Could not delete mapping', 'mercator'));
     }
 }
Пример #2
0
/**
 * Output alias editing page
 */
function output_edit_page()
{
    $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
    if (!$id) {
        wp_die(__('Invalid site ID.'));
    }
    $id = absint($id);
    $details = get_blog_details($id);
    if (!can_edit_network($details->site_id) || (int) $details->blog_id !== $id) {
        wp_die(__('You do not have permission to access this page.'));
    }
    // Are we editing?
    $mapping = null;
    $form_action = network_admin_url('admin.php?action=mercator-add');
    if (!empty($_REQUEST['mapping'])) {
        $mapping_id = absint($_REQUEST['mapping']);
        $mapping = Mapping::get($mapping_id);
        if (is_wp_error($mapping) || empty($mapping)) {
            wp_die(__('Invalid alias ID.', 'mercator'));
        }
        $form_action = network_admin_url('admin.php?action=mercator-edit');
    }
    // Handle form submission
    $messages = array();
    if (!empty($_POST['submit'])) {
        $messages = handle_edit_page_submit($id, $mapping);
    }
    output_page_header($id, $messages);
    if (empty($mapping) || !empty($_POST['_wpnonce'])) {
        $domain = empty($_POST['domain']) ? '' : wp_unslash($_POST['domain']);
        $active = !empty($_POST['active']);
    } else {
        $domain = $mapping->get_domain();
        $active = $mapping->is_active();
    }
    ?>
	<form method="post" action="<?php 
    echo esc_url($form_action);
    ?>
">
		<table class="form-table">
			<tr>
				<th scope="row">
					<label for="mercator-domain"><?php 
    echo esc_html_x('Domain Name', 'field name', 'mercator');
    ?>
</label>
				</th>
				<td>
					<input type="text" class="regular-text code"
						name="domain" id="mercator-domain"
						value="<?php 
    echo esc_attr($domain);
    ?>
" />
				</td>
			</tr>
			<tr>
				<th scope="row">
					<?php 
    echo esc_html_x('Active', 'field name', 'mercator');
    ?>
				</th>
				<td>
					<label>
						<input type="checkbox"
							name="active" <?php 
    checked($active);
    ?>
 />

						<?php 
    esc_html_e('Mark alias as active', 'mercator');
    ?>
					</label>
				</td>
			</tr>
		</table>

		<input type="hidden" name="id" value="<?php 
    echo esc_attr($id);
    ?>
" />
		<?php 
    if (empty($mapping)) {
        wp_nonce_field('mercator-add-' . $id);
        submit_button(__('Add Alias', 'mercator'));
    } else {
        echo '<input type="hidden" name="mapping" value="' . esc_attr($mapping->get_id()) . '" />';
        wp_nonce_field('mercator-edit-' . $mapping->get_id());
        submit_button(__('Save Alias', 'mercator'));
    }
    ?>
	</form>
<?php 
    output_page_footer();
}