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

Create a new domain mapping
public static create ( string $site, string $domain, boolean $active = false ) : Mapping | WP_Error
$site string Site ID, or site object from {@see \get_blog_details}
$domain string
$active boolean
Результат Mapping | WP_Error
Пример #1
0
/**
 * Handle submission of the add page
 *
 * @return array|null List of errors. Issues a redirect and exits on success.
 */
function handle_edit_page_submit($id, $mapping)
{
    $messages = array();
    if (empty($mapping)) {
        $did_action = 'add';
        check_admin_referer('mercator-add-' . $id);
    } else {
        $did_action = 'edit';
        check_admin_referer('mercator-edit-' . $mapping->get_id());
    }
    // Check that the parameters are correct first
    $params = validate_alias_parameters(wp_unslash($_POST));
    if (is_wp_error($params)) {
        $messages[] = $params->get_error_message();
        if ($params->get_error_code() === 'mercator.params.domain_invalid_chars') {
            $messages[] = __('<strong>Note</strong>: for internationalized domain names, use the ASCII form (e.g, <code>xn--bcher-kva.example</code>)', 'mercator');
        }
        return $messages;
    }
    if (empty($mapping)) {
        // Create the actual mapping
        $result = $mapping = Mapping::create($params['site'], $params['domain'], $params['active']);
    } else {
        // Update our existing
        $result = $mapping->update($params);
    }
    if (is_wp_error($result)) {
        $messages[] = $result->get_error_message();
        return $messages;
    }
    // Success, redirect to alias page
    $location = add_query_arg(array('action' => 'mercator-aliases', 'id' => $id, 'did_action' => $did_action, 'mappings' => $mapping->get_id(), 'processed' => 1, '_wpnonce' => wp_create_nonce('mercator-alias-added-' . $mapping->get_id())), network_admin_url('admin.php'));
    wp_safe_redirect($location);
    exit;
}