Skip to content

Commit 2dcc6c3

Browse files
authored
Merge pull request #125 from cameronterry/release/2.5.0
Release: 2.5.0
2 parents aa694bc + 329d037 commit 2dcc6c3

20 files changed

+5612
-8860
lines changed

.babelrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.idea/
22
node_modules
33

4-
domain-mapping/build/*
4+
/dist/
55
/vendor/
66

77
# PHPUnit

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cameronterry/dark-matter",
3-
"version": "2.4.0",
3+
"version": "2.5.0",
44
"description": "A highly opinionated domain mapping plugin for WordPress.",
55
"type": "wordpress-plugin",
66
"license": "GPL-2.0+",

composer.lock

Lines changed: 143 additions & 84 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dark-matter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Dark Matter Plugin
44
* Plugin URI: https://github.com/cameronterry/dark-matter
55
* Description: A highly opinionated domain mapping plugin for WordPress.
6-
* Version: 2.4.0
6+
* Version: 2.5.0
77
* Author: Cameron Terry
88
* Author URI: https://github.com/cameronterry/
99
* Text Domain: dark-matter
@@ -34,7 +34,7 @@
3434

3535
/** Setup the Plugin Constants */
3636
define( 'DM_PATH', plugin_dir_path( __FILE__ ) );
37-
define( 'DM_VERSION', '2.4.0' );
37+
define( 'DM_VERSION', '2.5.0' );
3838
define( 'DM_DB_VERSION', '20210517' );
3939

4040
define( 'DM_PLUGIN_URL', plugin_dir_url( __FILE__ ) );

domain-mapping/classes/class-dm-ui.php

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,23 @@ public function admin_menu() {
6161
* @return void
6262
*/
6363
public function enqueue() {
64-
$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' );
64+
$script_data = include DM_PATH . 'dist/app-script.asset.php';
6565

66-
wp_register_script(
67-
'dark-matter-domains',
68-
DM_PLUGIN_URL . 'domain-mapping/build/domain-mapping' . $min . '.js',
69-
[ 'wp-i18n' ],
70-
DM_VERSION,
71-
true
66+
wp_enqueue_script(
67+
'darkmatterplugin-admin-script',
68+
DM_PLUGIN_URL . 'dist/app-script.js',
69+
$script_data['dependencies'],
70+
$script_data['version'],
71+
[
72+
'in_footer' => true,
73+
]
7274
);
73-
74-
wp_localize_script(
75-
'dark-matter-domains',
76-
'dmSettings',
77-
array(
78-
'rest_root' => get_rest_url(),
79-
'nonce' => wp_create_nonce( 'wp_rest' ),
80-
)
75+
wp_enqueue_style(
76+
'darkmatterplugin-admin-style',
77+
DM_PLUGIN_URL . 'dist/app-style.css',
78+
[],
79+
$script_data['version'],
8180
);
82-
83-
wp_enqueue_script( 'dark-matter-domains' );
84-
85-
wp_enqueue_style( 'dark-matter-domains', DM_PLUGIN_URL . 'domain-mapping/build/domain-mapping-style' . $min . '.css', [], DM_VERSION );
8681
}
8782

8883
/**
@@ -116,7 +111,7 @@ public function page() {
116111
wp_die( esc_html__( 'You do not have permission to manage domains.', 'dark-matter' ) );
117112
}
118113
?>
119-
<div id="root"></div>
114+
<div id="root" data-admin-domain="<?php echo esc_url( get_home_url( null, '/', 'unmapped' ) ); ?>"></div>
120115
<?php
121116
}
122117
}

domain-mapping/ui/API/Domains.js

Lines changed: 20 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* We use jQuery's AJAX mechanism as this is already in WordPress and
3-
* doesn't require a separate dependency / library liks Axios ... for now.
2+
* WordPress dependencies
43
*/
4+
import apiFetch from '@wordpress/api-fetch';
55

66
class Domains {
77
/**
@@ -11,25 +11,15 @@ class Domains {
1111
* @param {Object} data Data record for the new domain.
1212
*/
1313
async add( data ) {
14-
let result = null;
15-
1614
try {
17-
result = await window.jQuery.ajax( {
18-
url: window.dmSettings.rest_root + 'dm/v1/domain',
15+
return await apiFetch( {
1916
data,
20-
dataType: 'json',
21-
method: 'post',
22-
beforeSend( xhr ) {
23-
xhr.setRequestHeader( 'X-WP-Nonce', window.dmSettings.nonce );
24-
},
17+
method: 'POST',
18+
path: '/dm/v1/domain',
2519
} );
2620
} catch ( error ) {
27-
if ( error.responseJSON ) {
28-
result = error.responseJSON;
29-
}
21+
return error;
3022
}
31-
32-
return result;
3323
}
3424

3525
/**
@@ -40,43 +30,22 @@ class Domains {
4030
* @param {string} domain FQDN to be deleted.
4131
*/
4232
async delete( domain ) {
43-
let result = null;
44-
45-
try {
46-
result = await window.jQuery.ajax( {
47-
url: window.dmSettings.rest_root + 'dm/v1/domain/' + domain,
48-
data: {
49-
force: true,
50-
},
51-
dataType: 'json',
52-
method: 'DELETE',
53-
beforeSend( xhr ) {
54-
xhr.setRequestHeader( 'X-WP-Nonce', window.dmSettings.nonce );
55-
},
56-
} );
57-
} catch ( error ) {
58-
if ( error.responseJSON ) {
59-
result = error.responseJSON;
60-
}
61-
}
62-
63-
return result;
33+
return await apiFetch( {
34+
data: {
35+
force: true,
36+
},
37+
method: 'DELETE',
38+
path: `/dm/v1/domain/${domain}`,
39+
} );
6440
}
6541

6642
/**
6743
* Retrieve all the domains for a specific website.
6844
*/
6945
async getAll() {
70-
const result = await window.jQuery.ajax( {
71-
url: window.dmSettings.rest_root + 'dm/v1/domains',
72-
dataType: 'json',
73-
method: 'GET',
74-
beforeSend( xhr ) {
75-
xhr.setRequestHeader( 'X-WP-Nonce', window.dmSettings.nonce );
76-
},
46+
return await apiFetch( {
47+
path: '/dm/v1/domains',
7748
} );
78-
79-
return result;
8049
}
8150

8251
/**
@@ -97,26 +66,11 @@ class Domains {
9766
*/
9867
delete data.site;
9968

100-
let result = null;
101-
102-
try {
103-
result = await window.jQuery.ajax( {
104-
url:
105-
window.dmSettings.rest_root + 'dm/v1/domain/' + data.domain,
106-
data,
107-
dataType: 'json',
108-
method: 'PUT',
109-
beforeSend( xhr ) {
110-
xhr.setRequestHeader( 'X-WP-Nonce', window.dmSettings.nonce );
111-
},
112-
} );
113-
} catch ( error ) {
114-
if ( error.responseJSON ) {
115-
result = error.responseJSON;
116-
}
117-
}
118-
119-
return result;
69+
return await apiFetch( {
70+
data,
71+
method: 'PUT',
72+
path: `/dm/v1/domain/${data.domain}`,
73+
} );
12074
}
12175
}
12276

domain-mapping/ui/Components/DomainAdd.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
/**
2+
* WordPress dependencies.
3+
*/
4+
import { Component } from '@wordpress/element';
15
import { __, sprintf } from '@wordpress/i18n';
2-
import React from 'react';
36

7+
/**
8+
* Internal dependencies.
9+
*/
410
import Domains from '../API/Domains';
511

6-
class DomainAdd extends React.Component {
12+
class DomainAdd extends Component {
713
/**
814
* Constructor.
915
*
@@ -33,11 +39,18 @@ class DomainAdd extends React.Component {
3339
let message = '';
3440

3541
if ( result.code ) {
36-
message = sprintf(
37-
/* translators: error message */
38-
__( 'Cannot add domain. %s', 'dark-matter' ),
39-
result.message
40-
);
42+
if ( 'primary' === result.code ) {
43+
message = sprintf(
44+
__( 'Cannot add domain. Primary domain cannot be overridden by a new domain.', 'dark-matter' ),
45+
result.message
46+
);
47+
} else {
48+
message = sprintf(
49+
/* translators: error message */
50+
__( 'Cannot add domain. %s', 'dark-matter' ),
51+
result.message
52+
);
53+
}
4154
} else {
4255
message = sprintf(
4356
/* translators: added domain */

domain-mapping/ui/Components/DomainDisplayMedia.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
/**
2+
* WordPress dependencies.
3+
*/
4+
import { Component } from '@wordpress/element';
15
import { __ } from '@wordpress/i18n';
2-
import React from 'react';
36

4-
class DomainDisplayMedia extends React.Component {
7+
class DomainDisplayMedia extends Component {
58
/**
69
* Render component
710
*/

domain-mapping/ui/Components/DomainDisplayPrimary.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import React from 'react';
1+
/**
2+
* WordPress dependencies.
3+
*/
4+
import { Component } from '@wordpress/element';
25
import { __, sprintf } from '@wordpress/i18n';
36

4-
class DomainDisplayPrimary extends React.Component {
7+
class DomainDisplayPrimary extends Component {
58
/**
69
* Render component.
710
*/

0 commit comments

Comments
 (0)