mirror of
https://github.com/WenPai-org/wp-domain-mapping.git
synced 2025-08-03 22:39:47 +08:00
v2.0 版本重写
新增多项改进
This commit is contained in:
parent
31bf7145ea
commit
fbebd6ea2f
12 changed files with 4241 additions and 2180 deletions
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Domains administration page
|
||||
* Domains administration page template
|
||||
*
|
||||
* @package WP Domain Mapping
|
||||
*/
|
||||
|
@ -9,6 +9,8 @@
|
|||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// This file is included from the render_domains_admin method
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html( get_admin_page_title() ); ?>
|
||||
|
@ -16,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<?php printf( esc_html__( 'Version: %s', 'wp-domain-mapping' ), esc_html( WP_DOMAIN_MAPPING_VERSION ) ); ?>
|
||||
</span>
|
||||
<a href="https://wpmultisite.com/document/wp-domain-mapping" target="_blank" class="button button-secondary" style="margin-left: 10px;">
|
||||
<?php esc_html_e( 'Documentation', 'wp-domain-mapping' ); ?>
|
||||
<?php esc_html_e( 'Document', 'wp-domain-mapping' ); ?>
|
||||
</a>
|
||||
<a href="https://wpmultisite.com/forums/" target="_blank" class="button button-secondary">
|
||||
<?php esc_html_e( 'Support', 'wp-domain-mapping' ); ?>
|
||||
|
@ -26,7 +28,70 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<div class="card domain-mapping-card">
|
||||
<h2><?php echo $edit_row ? esc_html__( 'Edit Domain', 'wp-domain-mapping' ) : esc_html__( 'Add New Domain', 'wp-domain-mapping' ); ?></h2>
|
||||
<div id="edit-domain-status" class="notice" style="display:none;"></div>
|
||||
<?php dm_edit_domain( $edit_row ); ?>
|
||||
|
||||
<form id="edit-domain-form" method="POST">
|
||||
<input type="hidden" name="orig_domain" value="<?php echo esc_attr( $edit_row ? $edit_row->domain : '' ); ?>" />
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th><label for="blog_id"><?php esc_html_e( 'Site ID', 'wp-domain-mapping' ); ?></label></th>
|
||||
<td>
|
||||
<input type="number" id="blog_id" name="blog_id" value="<?php echo esc_attr( $edit_row ? $edit_row->blog_id : '' ); ?>" class="regular-text" required />
|
||||
<?php if ( ! $edit_row ) : ?>
|
||||
<p class="description">
|
||||
<?php
|
||||
$site_list_url = network_admin_url( 'sites.php' );
|
||||
printf(
|
||||
/* translators: %s: URL to sites list */
|
||||
wp_kses(
|
||||
__( 'Not sure about Site ID? <a href="%s" target="_blank">View all sites</a> to find the ID.', 'wp-domain-mapping' ),
|
||||
array( 'a' => array( 'href' => array(), 'target' => array() ) )
|
||||
),
|
||||
esc_url( $site_list_url )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="domain"><?php esc_html_e( 'Domain', 'wp-domain-mapping' ); ?></label></th>
|
||||
<td>
|
||||
<input type="text" id="domain" name="domain" value="<?php echo esc_attr( $edit_row ? $edit_row->domain : '' ); ?>" class="regular-text" required
|
||||
placeholder="example.com" pattern="^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]?\.[a-zA-Z]{2,}$" />
|
||||
<p class="description">
|
||||
<?php esc_html_e( 'Enter the domain without http:// or https:// (e.g., example.com)', 'wp-domain-mapping' ); ?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="active"><?php esc_html_e( 'Primary', 'wp-domain-mapping' ); ?></label></th>
|
||||
<td>
|
||||
<input type="checkbox" id="active" name="active" value="1" <?php checked( $edit_row ? $edit_row->active : 0, 1 ); ?> />
|
||||
<span class="description">
|
||||
<?php esc_html_e( 'Set as the primary domain for this site', 'wp-domain-mapping' ); ?>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<?php if ( get_site_option( 'dm_no_primary_domain' ) == 1 ) : ?>
|
||||
<tr>
|
||||
<td colspan="2" class="notice notice-warning">
|
||||
<p><?php esc_html_e( 'Warning! Primary domains are currently disabled in network settings.', 'wp-domain-mapping' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
<p>
|
||||
<input type="submit" class="button button-primary" value="<?php echo $edit_row
|
||||
? esc_attr__( 'Update Domain', 'wp-domain-mapping' )
|
||||
: esc_attr__( 'Add Domain', 'wp-domain-mapping' ); ?>" />
|
||||
|
||||
<?php if ( $edit_row ) : ?>
|
||||
<a href="<?php echo esc_url( admin_url( 'network/sites.php?page=domains' ) ); ?>" class="button button-secondary">
|
||||
<?php esc_html_e( 'Cancel', 'wp-domain-mapping' ); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card domain-mapping-card">
|
||||
|
@ -112,14 +177,15 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
}
|
||||
|
||||
$where_sql = $where ? ' WHERE ' . implode( ' AND ', $where ) : '';
|
||||
$tables = dm_get_table_names();
|
||||
|
||||
// Count total items for pagination
|
||||
$total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->base_prefix}" . WP_DOMAIN_MAPPING_TABLE_DOMAINS . $where_sql );
|
||||
$total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$tables['domains']}" . $where_sql );
|
||||
$total_pages = ceil( $total_items / $per_page );
|
||||
|
||||
// Get the domains with pagination
|
||||
$rows = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT * FROM {$wpdb->base_prefix}" . WP_DOMAIN_MAPPING_TABLE_DOMAINS . $where_sql . " ORDER BY id DESC LIMIT %d, %d",
|
||||
"SELECT * FROM {$tables['domains']}" . $where_sql . " ORDER BY id DESC LIMIT %d, %d",
|
||||
$offset,
|
||||
$per_page
|
||||
));
|
||||
|
@ -191,7 +257,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
<th><?php esc_html_e( 'Sites with Mapped Domains', 'wp-domain-mapping' ); ?></th>
|
||||
<td>
|
||||
<?php
|
||||
$sites_with_domains = $wpdb->get_var( "SELECT COUNT(DISTINCT blog_id) FROM {$wpdb->base_prefix}" . WP_DOMAIN_MAPPING_TABLE_DOMAINS );
|
||||
$sites_with_domains = $wpdb->get_var( "SELECT COUNT(DISTINCT blog_id) FROM {$tables['domains']}" );
|
||||
echo esc_html( $sites_with_domains );
|
||||
?>
|
||||
</td>
|
||||
|
@ -201,314 +267,162 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
jQuery(document).ready(function($) {
|
||||
// Tab switching functionality
|
||||
$('.domain-mapping-tab').on('click', function() {
|
||||
$('.domain-mapping-tab').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
<?php
|
||||
/**
|
||||
* Render domain listing table
|
||||
*
|
||||
* @param array $rows Domain data rows
|
||||
*/
|
||||
function dm_domain_listing( $rows ) {
|
||||
global $wpdb;
|
||||
|
||||
var tab = $(this).data('tab');
|
||||
$('.domain-mapping-section').hide();
|
||||
$('.domain-mapping-section[data-section="' + tab + '"]').show();
|
||||
});
|
||||
|
||||
// Helper function for showing notices
|
||||
function showNotice(selector, message, type) {
|
||||
$(selector)
|
||||
.removeClass('notice-success notice-error notice-warning notice-info')
|
||||
.addClass('notice-' + type)
|
||||
.html('<p>' + message + '</p>')
|
||||
.show()
|
||||
.delay(3000)
|
||||
.fadeOut();
|
||||
if ( ! $rows ) {
|
||||
echo '<div class="notice notice-info"><p>' . esc_html__( 'No domains found.', 'wp-domain-mapping' ) . '</p></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle domain edit/add form submission
|
||||
$('#edit-domain-form').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
$edit_url = network_admin_url(
|
||||
file_exists( ABSPATH . 'wp-admin/network/site-info.php' )
|
||||
? 'site-info.php'
|
||||
: ( file_exists( ABSPATH . 'wp-admin/ms-sites.php' ) ? 'ms-sites.php' : 'wpmu-blogs.php' )
|
||||
);
|
||||
?>
|
||||
<div class="tablenav top">
|
||||
<div class="alignleft actions bulkactions">
|
||||
<label for="bulk-action-selector-top" class="screen-reader-text"><?php esc_html_e( 'Select bulk action', 'wp-domain-mapping' ); ?></label>
|
||||
<select id="bulk-action-selector-top" name="action">
|
||||
<option value="-1"><?php esc_html_e( 'Bulk Actions', 'wp-domain-mapping' ); ?></option>
|
||||
<option value="delete"><?php esc_html_e( 'Delete', 'wp-domain-mapping' ); ?></option>
|
||||
</select>
|
||||
<input type="submit" class="button action" value="<?php esc_attr_e( 'Apply', 'wp-domain-mapping' ); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
// Validate form
|
||||
var blogId = $('#blog_id').val();
|
||||
var domain = $('#domain').val();
|
||||
<table class="wp-list-table widefat striped domains-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="manage-column column-cb check-column">
|
||||
<input id="select-all" type="checkbox" />
|
||||
</td>
|
||||
<th scope="col" class="column-site-id"><?php esc_html_e( 'Site ID', 'wp-domain-mapping' ); ?></th>
|
||||
<th scope="col" class="column-site-name"><?php esc_html_e( 'Site Name', 'wp-domain-mapping' ); ?></th>
|
||||
<th scope="col" class="column-domain"><?php esc_html_e( 'Domain', 'wp-domain-mapping' ); ?></th>
|
||||
<th scope="col" class="column-primary"><?php esc_html_e( 'Primary', 'wp-domain-mapping' ); ?></th>
|
||||
<th scope="col" class="column-actions"><?php esc_html_e( 'Actions', 'wp-domain-mapping' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ( $rows as $row ) :
|
||||
$site_name = get_blog_option( $row->blog_id, 'blogname', esc_html__( 'Unknown', 'wp-domain-mapping' ) );
|
||||
?>
|
||||
<tr>
|
||||
<th scope="row" class="check-column">
|
||||
<input type="checkbox" class="domain-checkbox" value="<?php echo esc_attr( $row->domain ); ?>" />
|
||||
</th>
|
||||
<td class="column-site-id">
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'editblog', 'id' => $row->blog_id ), $edit_url ) ); ?>">
|
||||
<?php echo esc_html( $row->blog_id ); ?>
|
||||
</a>
|
||||
</td>
|
||||
<td class="column-site-name">
|
||||
<?php echo esc_html( $site_name ); ?>
|
||||
</td>
|
||||
<td class="column-domain">
|
||||
<a href="<?php echo esc_url( dm_ensure_protocol( $row->domain ) ); ?>" target="_blank">
|
||||
<?php echo esc_html( $row->domain ); ?>
|
||||
<span class="dashicons dashicons-external" style="font-size: 14px; line-height: 1.3; opacity: 0.7;"></span>
|
||||
</a>
|
||||
</td>
|
||||
<td class="column-primary">
|
||||
<?php if ( $row->active == 1 ) : ?>
|
||||
<span class="dashicons dashicons-yes-alt" style="color: #46b450;"></span>
|
||||
<span class="screen-reader-text"><?php esc_html_e( 'Yes', 'wp-domain-mapping' ); ?></span>
|
||||
<?php else : ?>
|
||||
<span class="dashicons dashicons-no-alt" style="color: #dc3232;"></span>
|
||||
<span class="screen-reader-text"><?php esc_html_e( 'No', 'wp-domain-mapping' ); ?></span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="column-actions">
|
||||
<div class="row-actions">
|
||||
<span class="edit">
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'edit_domain' => $row->domain ), admin_url( 'network/sites.php?page=domains' ) ) ); ?>" class="button button-small">
|
||||
<?php esc_html_e( 'Edit', 'wp-domain-mapping' ); ?>
|
||||
</a>
|
||||
</span>
|
||||
<?php if ( $row->active != 1 ) : ?>
|
||||
<span class="delete">
|
||||
<a href="#" class="button button-small domain-delete-button" data-domain="<?php echo esc_attr( $row->domain ); ?>">
|
||||
<?php esc_html_e( 'Delete', 'wp-domain-mapping' ); ?>
|
||||
</a>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
if (!blogId || !domain) {
|
||||
showNotice('#edit-domain-status', '<?php esc_html_e( 'Please fill in all required fields.', 'wp-domain-mapping' ); ?>', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
var formData = $(this).serializeArray();
|
||||
formData.push({name: 'action', value: 'dm_handle_actions'});
|
||||
formData.push({name: 'action_type', value: 'save'});
|
||||
formData.push({name: 'nonce', value: '<?php echo wp_create_nonce( 'domain_mapping' ); ?>'});
|
||||
|
||||
$('#edit-domain-status').html('<p><?php esc_html_e( 'Saving...', 'wp-domain-mapping' ); ?></p>').show();
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
showNotice('#edit-domain-status', response.data, 'success');
|
||||
setTimeout(function() {
|
||||
location.href = '<?php echo esc_js( admin_url( 'network/sites.php?page=domains' ) ); ?>';
|
||||
}, 1000);
|
||||
} else {
|
||||
showNotice('#edit-domain-status', response.data || '<?php esc_html_e( 'Failed to save domain.', 'wp-domain-mapping' ); ?>', 'error');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
showNotice('#edit-domain-status', '<?php esc_html_e( 'Server error occurred.', 'wp-domain-mapping' ); ?>', 'error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Handle domain list bulk actions
|
||||
$('#domain-list-form').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var selectedDomains = [];
|
||||
$('.domain-checkbox:checked').each(function() {
|
||||
selectedDomains.push($(this).val());
|
||||
});
|
||||
|
||||
if (selectedDomains.length === 0) {
|
||||
showNotice('#domain-status', '<?php esc_html_e( 'Please select at least one domain.', 'wp-domain-mapping' ); ?>', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
var action = $('#bulk-action-selector-top').val();
|
||||
if (action === '-1') return;
|
||||
|
||||
if (!confirm('<?php esc_html_e( 'Are you sure you want to delete the selected domains?', 'wp-domain-mapping' ); ?>')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$('#domain-status').html('<p><?php esc_html_e( 'Processing...', 'wp-domain-mapping' ); ?></p>').show();
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'dm_handle_actions',
|
||||
action_type: 'delete',
|
||||
domains: selectedDomains,
|
||||
nonce: '<?php echo wp_create_nonce( 'domain_mapping' ); ?>'
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
showNotice('#domain-status', response.data, 'success');
|
||||
setTimeout(function() {
|
||||
location.reload();
|
||||
}, 1000);
|
||||
} else {
|
||||
showNotice('#domain-status', response.data || '<?php esc_html_e( 'Failed to delete domains.', 'wp-domain-mapping' ); ?>', 'error');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
showNotice('#domain-status', '<?php esc_html_e( 'Server error occurred.', 'wp-domain-mapping' ); ?>', 'error');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* Main cards */
|
||||
.domain-mapping-card {
|
||||
background: #fff;
|
||||
border: 1px solid #ccd0d4;
|
||||
border-radius: 4px;
|
||||
max-width: unset;
|
||||
margin-top: 20px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 1px 1px rgba(0,0,0,.04);
|
||||
<?php if ( get_site_option( 'dm_no_primary_domain' ) == 1 ) : ?>
|
||||
<div class="notice notice-warning inline">
|
||||
<p><?php esc_html_e( 'Warning! Primary domains are currently disabled in network settings.', 'wp-domain-mapping' ); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
}
|
||||
|
||||
/* Tabs */
|
||||
.domain-mapping-tabs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
border-bottom: 1px solid #c3c4c7;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
/**
|
||||
* Render domain logs table
|
||||
*/
|
||||
function dm_domain_logs() {
|
||||
global $wpdb;
|
||||
|
||||
.domain-mapping-tab {
|
||||
padding: 8px 16px;
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
border-bottom: 2px solid transparent;
|
||||
}
|
||||
$tables = dm_get_table_names();
|
||||
|
||||
.domain-mapping-tab.active {
|
||||
border-bottom: 2px solid #007cba;
|
||||
font-weight: 600;
|
||||
background: #f0f0f1;
|
||||
}
|
||||
|
||||
.domain-mapping-tab:hover:not(.active) {
|
||||
background: #f0f0f1;
|
||||
border-bottom-color: #dcdcde;
|
||||
}
|
||||
|
||||
.domain-mapping-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* Search form */
|
||||
.search-form {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 15px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.search-form-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 180px;
|
||||
}
|
||||
|
||||
.search-form-field label {
|
||||
margin-bottom: 5px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.search-form-submit {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
/* Tables */
|
||||
.tablenav {
|
||||
margin: 10px 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.tablenav-pages {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.tablenav-pages a,
|
||||
.tablenav-pages span.current {
|
||||
display: inline-block;
|
||||
min-width: 17px;
|
||||
padding: 3px 5px 7px;
|
||||
background: #f0f0f1;
|
||||
font-size: 16px;
|
||||
line-height: 1;
|
||||
font-weight: 400;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.tablenav-pages span.current {
|
||||
background: #007cba;
|
||||
color: #fff;
|
||||
border-color: #007cba;
|
||||
}
|
||||
|
||||
.displaying-num {
|
||||
margin-left: 10px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.domains-table th,
|
||||
.logs-table th {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.column-site-id {
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
.column-site-name {
|
||||
width: 20%;
|
||||
}
|
||||
|
||||
.column-primary {
|
||||
width: 80px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.column-actions {
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
/* Form elements */
|
||||
.form-table th {
|
||||
width: 200px;
|
||||
padding: 15px 10px 15px 0;
|
||||
}
|
||||
|
||||
.form-table td {
|
||||
padding: 15px 0;
|
||||
}
|
||||
|
||||
.description {
|
||||
color: #666;
|
||||
font-size: 13px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
/* Notices */
|
||||
.notice {
|
||||
padding: 8px 12px;
|
||||
border-radius: 3px;
|
||||
margin: 5px 0 15px;
|
||||
}
|
||||
|
||||
.notice p {
|
||||
margin: 0.5em 0;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.notice-success {
|
||||
background-color: #f0f9eb;
|
||||
border-left: 4px solid #46b450;
|
||||
}
|
||||
|
||||
.notice-error {
|
||||
background-color: #fef0f0;
|
||||
border-left: 4px solid #dc3232;
|
||||
}
|
||||
|
||||
.notice-warning {
|
||||
background-color: #fff8e5;
|
||||
border-left: 4px solid #ffb900;
|
||||
}
|
||||
|
||||
.notice-info {
|
||||
background-color: #f0f6fa;
|
||||
border-left: 4px solid #00a0d2;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media screen and (max-width: 782px) {
|
||||
.search-form {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
// Make sure the table exists
|
||||
if ( $wpdb->get_var( "SHOW TABLES LIKE '{$tables['logs']}'" ) != $tables['logs'] ) {
|
||||
echo '<div class="notice notice-error"><p>' .
|
||||
esc_html__('Domain mapping logs table is missing. Please deactivate and reactivate the plugin.', 'wp-domain-mapping') .
|
||||
'</p></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
.search-form-field {
|
||||
min-width: 100%;
|
||||
// Get pagination parameters
|
||||
$per_page = isset( $_GET['logs_per_page'] ) ? absint( $_GET['logs_per_page'] ) : 50;
|
||||
$paged = isset( $_GET['logs_paged'] ) ? absint( $_GET['logs_paged'] ) : 1;
|
||||
$offset = ( $paged - 1 ) * $per_page;
|
||||
|
||||
// Get action filter
|
||||
$action_filter = isset( $_GET['log_action'] ) ? sanitize_text_field( $_GET['log_action'] ) : '';
|
||||
|
||||
// Build WHERE clause for filtering
|
||||
$where = array();
|
||||
if ( ! empty( $action_filter ) ) {
|
||||
$where[] = $wpdb->prepare( "action = %s", $action_filter );
|
||||
}
|
||||
|
||||
.form-table th {
|
||||
width: 100%;
|
||||
display: block;
|
||||
$where_sql = $where ? ' WHERE ' . implode( ' AND ', $where ) : '';
|
||||
|
||||
// Count total logs for pagination
|
||||
$total_logs = $wpdb->get_var( "SELECT COUNT(*) FROM {$tables['logs']}" . $where_sql );
|
||||
$total_pages = ceil( $total_logs / $per_page );
|
||||
|
||||
// Get logs with pagination
|
||||
$logs = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT * FROM {$tables['logs']}" . $where_sql . " ORDER BY timestamp DESC LIMIT %d, %d",
|
||||
$offset,
|
||||
$per_page
|
||||
));
|
||||
|
||||
// Get available actions for filter
|
||||
$actions = $wpdb->get_col( "SELECT DISTINCT action FROM {$tables['logs']}" );
|
||||
|
||||
if ( ! $logs ) {
|
||||
echo '<div class="notice notice-info"><p>' . esc_html__( 'No domain mapping logs available.', 'wp-domain-mapping' ) . '</p></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
.form-table td {
|
||||
display: block;
|
||||
padding: 0 0 15px;
|
||||
}
|
||||
// Include the logs table template
|
||||
include WP_DOMAIN_MAPPING_DIR_PATH . 'admin/logs-table.php';
|
||||
}
|
||||
</style>
|
||||
?>
|
||||
|
|
|
@ -10,46 +10,12 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
exit;
|
||||
}
|
||||
|
||||
// Get pagination parameters
|
||||
$per_page = isset( $_GET['logs_per_page'] ) ? absint( $_GET['logs_per_page'] ) : 50;
|
||||
$paged = isset( $_GET['logs_paged'] ) ? absint( $_GET['logs_paged'] ) : 1;
|
||||
$offset = ( $paged - 1 ) * $per_page;
|
||||
|
||||
// Get action filter
|
||||
$action_filter = isset( $_GET['log_action'] ) ? sanitize_text_field( $_GET['log_action'] ) : '';
|
||||
|
||||
// Build WHERE clause for filtering
|
||||
$where = array();
|
||||
if ( ! empty( $action_filter ) ) {
|
||||
$where[] = $wpdb->prepare( "action = %s", $action_filter );
|
||||
}
|
||||
|
||||
$where_sql = $where ? ' WHERE ' . implode( ' AND ', $where ) : '';
|
||||
|
||||
// Count total logs for pagination
|
||||
$total_logs = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->base_prefix}" . WP_DOMAIN_MAPPING_TABLE_LOGS . $where_sql );
|
||||
$total_pages = ceil( $total_logs / $per_page );
|
||||
|
||||
// Get logs with pagination
|
||||
$logs = $wpdb->get_results( $wpdb->prepare(
|
||||
"SELECT * FROM {$wpdb->base_prefix}" . WP_DOMAIN_MAPPING_TABLE_LOGS . $where_sql . " ORDER BY timestamp DESC LIMIT %d, %d",
|
||||
$offset,
|
||||
$per_page
|
||||
));
|
||||
|
||||
// Get available actions for filter
|
||||
$actions = $wpdb->get_col( "SELECT DISTINCT action FROM {$wpdb->base_prefix}" . WP_DOMAIN_MAPPING_TABLE_LOGS );
|
||||
|
||||
if ( ! $logs ) {
|
||||
echo '<div class="notice notice-info"><p>' . esc_html__( 'No domain mapping logs available.', 'wp-domain-mapping' ) . '</p></div>';
|
||||
return;
|
||||
}
|
||||
// This file is included from dm_domain_logs() function
|
||||
?>
|
||||
|
||||
<div class="tablenav top">
|
||||
<form method="GET" id="logs-filter-form" class="logs-filter">
|
||||
<input type="hidden" name="page" value="domains" />
|
||||
<input type="hidden" name="tab" value="domain-logs" />
|
||||
|
||||
<div class="alignleft actions">
|
||||
<label for="log_action" class="screen-reader-text"><?php esc_html_e( 'Filter by action', 'wp-domain-mapping' ); ?></label>
|
||||
|
@ -57,21 +23,7 @@ if ( ! $logs ) {
|
|||
<option value=""><?php esc_html_e( 'All actions', 'wp-domain-mapping' ); ?></option>
|
||||
<?php foreach ( $actions as $action ) : ?>
|
||||
<option value="<?php echo esc_attr( $action ); ?>" <?php selected( $action_filter, $action ); ?>>
|
||||
<?php
|
||||
switch ( $action ) {
|
||||
case 'add':
|
||||
esc_html_e( 'Added', 'wp-domain-mapping' );
|
||||
break;
|
||||
case 'edit':
|
||||
esc_html_e( 'Updated', 'wp-domain-mapping' );
|
||||
break;
|
||||
case 'delete':
|
||||
esc_html_e( 'Deleted', 'wp-domain-mapping' );
|
||||
break;
|
||||
default:
|
||||
echo esc_html( ucfirst( $action ) );
|
||||
}
|
||||
?>
|
||||
<?php echo esc_html( dm_format_action_name( $action ) ); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
@ -79,7 +31,7 @@ if ( ! $logs ) {
|
|||
<input type="submit" class="button" value="<?php esc_attr_e( 'Filter', 'wp-domain-mapping' ); ?>" />
|
||||
|
||||
<?php if ( ! empty( $action_filter ) ) : ?>
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'page' => 'domains', 'tab' => 'domain-logs' ), admin_url( 'network/sites.php' ) ) ); ?>" class="button">
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'page' => 'domains' ), admin_url( 'network/sites.php' ) ) ); ?>" class="button">
|
||||
<?php esc_html_e( 'Clear', 'wp-domain-mapping' ); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
@ -136,19 +88,8 @@ if ( ! $logs ) {
|
|||
: sprintf( esc_html__( 'User #%d', 'wp-domain-mapping' ), $log->user_id );
|
||||
|
||||
// Format action for display
|
||||
switch ( $log->action ) {
|
||||
case 'add':
|
||||
$action_display = '<span class="log-action log-action-add">' . esc_html__( 'Added', 'wp-domain-mapping' ) . '</span>';
|
||||
break;
|
||||
case 'edit':
|
||||
$action_display = '<span class="log-action log-action-edit">' . esc_html__( 'Updated', 'wp-domain-mapping' ) . '</span>';
|
||||
break;
|
||||
case 'delete':
|
||||
$action_display = '<span class="log-action log-action-delete">' . esc_html__( 'Deleted', 'wp-domain-mapping' ) . '</span>';
|
||||
break;
|
||||
default:
|
||||
$action_display = '<span class="log-action">' . esc_html( ucfirst( $log->action ) ) . '</span>';
|
||||
}
|
||||
$action_display = dm_format_action_name( $log->action );
|
||||
$action_class = 'log-action-' . $log->action;
|
||||
|
||||
// Get site name
|
||||
$site_name = get_blog_option( $log->blog_id, 'blogname', '' );
|
||||
|
@ -166,7 +107,11 @@ if ( ! $logs ) {
|
|||
?>
|
||||
<tr>
|
||||
<td class="column-user"><?php echo $username; ?></td>
|
||||
<td class="column-action"><?php echo $action_display; ?></td>
|
||||
<td class="column-action">
|
||||
<span class="log-action <?php echo esc_attr( $action_class ); ?>">
|
||||
<?php echo esc_html( $action_display ); ?>
|
||||
</span>
|
||||
</td>
|
||||
<td class="column-domain">
|
||||
<a href="<?php echo esc_url( dm_ensure_protocol( $log->domain ) ); ?>" target="_blank">
|
||||
<?php echo esc_html( $log->domain ); ?>
|
||||
|
@ -216,73 +161,3 @@ if ( ! $logs ) {
|
|||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<style>
|
||||
/* Logs table styles */
|
||||
.logs-filter {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.logs-table .column-user,
|
||||
.logs-table .column-site {
|
||||
width: 15%;
|
||||
}
|
||||
|
||||
.logs-table .column-action {
|
||||
width: 10%;
|
||||
}
|
||||
|
||||
.logs-table .column-date {
|
||||
width: 15%;
|
||||
}
|
||||
|
||||
.log-action {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
border-radius: 3px;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.log-action-add {
|
||||
background-color: #dff0d8;
|
||||
color: #3c763d;
|
||||
}
|
||||
|
||||
.log-action-edit {
|
||||
background-color: #d9edf7;
|
||||
color: #31708f;
|
||||
}
|
||||
|
||||
.log-action-delete {
|
||||
background-color: #f2dede;
|
||||
color: #a94442;
|
||||
}
|
||||
|
||||
/* Pagination */
|
||||
.tablenav-pages a,
|
||||
.tablenav-pages span.current {
|
||||
display: inline-block;
|
||||
min-width: 17px;
|
||||
padding: 3px 5px 7px;
|
||||
background: #f0f0f1;
|
||||
font-size: 16px;
|
||||
line-height: 1;
|
||||
font-weight: 400;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.tablenav-pages span.current {
|
||||
background: #007cba;
|
||||
color: #fff;
|
||||
border-color: #007cba;
|
||||
}
|
||||
|
||||
.displaying-num {
|
||||
margin-left: 10px;
|
||||
color: #555;
|
||||
}
|
||||
</style>
|
||||
|
|
1033
admin/pages.php
Normal file
1033
admin/pages.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -39,7 +39,7 @@ settings_errors( 'dm_settings' );
|
|||
<?php printf( esc_html__( 'Version: %s', 'wp-domain-mapping' ), esc_html( WP_DOMAIN_MAPPING_VERSION ) ); ?>
|
||||
</span>
|
||||
<a href="https://wpmultisite.com/document/wp-domain-mapping" target="_blank" class="button button-secondary" style="margin-left: 10px;">
|
||||
<?php esc_html_e( 'Documentation', 'wp-domain-mapping' ); ?>
|
||||
<?php esc_html_e( 'Document', 'wp-domain-mapping' ); ?>
|
||||
</a>
|
||||
<a href="https://wpmultisite.com/forums/" target="_blank" class="button button-secondary">
|
||||
<?php esc_html_e( 'Support', 'wp-domain-mapping' ); ?>
|
||||
|
|
|
@ -9,11 +9,6 @@ defined('ABSPATH') || exit;
|
|||
|
||||
$protocol = isset($protocol) ? $protocol : (is_ssl() ? 'https://' : 'http://');
|
||||
$domains = isset($domains) ? $domains : array();
|
||||
|
||||
// Initialize logs array if not set to prevent PHP warnings
|
||||
if (!isset($logs) || !is_array($logs)) {
|
||||
$logs = array();
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
|
@ -97,18 +92,18 @@ if (!isset($logs) || !is_array($logs)) {
|
|||
<?php foreach ($domains as $domain): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="<?php echo esc_url($protocol . $domain['domain']); ?>" target="_blank">
|
||||
<?php echo esc_html($domain['domain']); ?>
|
||||
<a href="<?php echo esc_url($protocol . $domain->domain); ?>" target="_blank">
|
||||
<?php echo esc_html($domain->domain); ?>
|
||||
<span class="dashicons dashicons-external" style="font-size: 14px; line-height: 1.3; opacity: 0.7;"></span>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($domain['active'] == 1): ?>
|
||||
<?php if ($domain->active == 1): ?>
|
||||
<span class="dashicons dashicons-yes-alt" style="color: #46b450;"></span>
|
||||
<span class="screen-reader-text"><?php _e('Yes', 'wp-domain-mapping'); ?></span>
|
||||
<?php else: ?>
|
||||
<a href="<?php echo wp_nonce_url(add_query_arg(
|
||||
array('page' => 'domainmapping', 'action' => 'primary', 'domain' => $domain['domain']),
|
||||
array('page' => 'domainmapping', 'action' => 'primary', 'domain' => $domain->domain),
|
||||
admin_url('tools.php')
|
||||
), 'domain_mapping'); ?>" class="button button-small">
|
||||
<?php _e('Make Primary', 'wp-domain-mapping'); ?>
|
||||
|
@ -116,11 +111,11 @@ if (!isset($logs) || !is_array($logs)) {
|
|||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($domain['active'] != 1): ?>
|
||||
<?php if ($domain->active != 1): ?>
|
||||
<a href="<?php echo wp_nonce_url(add_query_arg(
|
||||
array('page' => 'domainmapping', 'action' => 'delete', 'domain' => $domain['domain']),
|
||||
array('page' => 'domainmapping', 'action' => 'delete', 'domain' => $domain->domain),
|
||||
admin_url('tools.php')
|
||||
), 'delete' . $domain['domain']); ?>" class="button button-small button-link-delete" onclick="return confirm('<?php _e('Are you sure you want to delete this domain?', 'wp-domain-mapping'); ?>');">
|
||||
), 'delete' . $domain->domain); ?>" class="button button-small button-link-delete" onclick="return confirm('<?php _e('Are you sure you want to delete this domain?', 'wp-domain-mapping'); ?>');">
|
||||
<?php _e('Delete', 'wp-domain-mapping'); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
@ -160,24 +155,3 @@ if (!isset($logs) || !is_array($logs)) {
|
|||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
/* Main cards */
|
||||
.domain-mapping-card {
|
||||
background: #fff;
|
||||
border: 1px solid #ccd0d4;
|
||||
border-radius: 4px;
|
||||
margin-top: 20px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 1px 1px rgba(0,0,0,.04);
|
||||
}
|
||||
|
||||
.domains-table .column-primary {
|
||||
width: 150px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.domains-table .column-actions {
|
||||
width: 120px;
|
||||
}
|
||||
</style>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue