Introduction

WP Landing Kit provides a simple PHP API to enable developers to programmatically work with domains. The API makes it possible to:

  1. Add new domain entries to the database.
  2. Edit existing domain entries.
  3. Delete domain entries.

When creating or editing a domain, the API provides control over:

  1. Domain URL mappings (you can think of these as routes/endpoints)
  2. Domain settings

Important!

It is important to keep in mind that the API affects the database and should not be used as part of a typical WordPress page load. Instead, it is designed to be used at strategic points as a means of automating domain creation/manipulation. e.g; You may choose to run this after a WooCommerce/Easy Digital Downloads transaction or perhaps after user registration, etc.

Quickstart

The PHP API is included in the plugin from version 1.2.0 and you do not need to install or include anything to start using it.

A simple example — mapping a domain to a page

If all you need to do is map a domain to a post/page, you may do so as per the following example:

// Add the domain, map it to a post ID, and make it active.
$domain = wplk_add_domain( 'mydomain.com', 5, true );

if( is_wp_error( $domain ) ){
    // Error message can be accessed here using $domain->get_error_message()
}

Adding a domain and a few simple mappings

Building on the previous example, you may need to also map a number of URLs to either posts or term archive pages. You may do so as per the following example:

$domain = wplk_add_domain( 'mydomain.com', 5, true );

// If domain creation went off without issue, map some URLs.
if ( ! is_wp_error( $domain ) ) {
    wplk_add_url( 'mydomain.com/about', 6 );
    wplk_add_url( 'mydomain.com/contact', 11 );
    wplk_add_url( 'mydomain.com/terms', 987 );
    wplk_add_url( 'mydomain.com/projects/all', get_category_by_slug( 'projects' ) );
} else {
    // Error message can be accessed here using $domain->get_error_message()
}

A complex example — using chained methods for complex mappings