342 lines
17 KiB
PHP
342 lines
17 KiB
PHP
<?php
|
|
/**
|
|
* Settings Page (Renamed from Controls)
|
|
* Simplified post type and taxonomy management
|
|
*
|
|
* @package Igny8Bridge
|
|
*/
|
|
|
|
// Prevent direct access
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
// Include layout header
|
|
include IGNY8_BRIDGE_PLUGIN_DIR . 'admin/layout-header.php';
|
|
|
|
// Get all registered public post types
|
|
$all_post_types = get_post_types(array('public' => true), 'objects');
|
|
$excluded_post_types = array('attachment', 'revision', 'nav_menu_item', 'wp_block', 'wp_template', 'wp_template_part', 'wp_navigation');
|
|
$enabled_post_types = igny8_get_enabled_post_types();
|
|
$default_post_status = get_option('igny8_default_post_status', 'draft');
|
|
$sync_enabled = get_option('igny8_sync_enabled', 1);
|
|
|
|
// Get enabled taxonomies
|
|
$enabled_taxonomies = igny8_get_enabled_taxonomies();
|
|
|
|
// Filter out system post types
|
|
$public_post_types = array();
|
|
foreach ($all_post_types as $pt) {
|
|
if (!in_array($pt->name, $excluded_post_types, true)) {
|
|
$public_post_types[$pt->name] = $pt;
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="igny8-page-header">
|
|
<h1><?php _e('Settings', 'igny8-bridge'); ?></h1>
|
|
<p><?php _e('Configure post types, taxonomies, and sync settings', 'igny8-bridge'); ?></p>
|
|
</div>
|
|
|
|
<form method="post" action="options.php" id="igny8-settings-form">
|
|
<?php settings_fields('igny8_bridge_controls'); ?>
|
|
|
|
<!-- Post Types Section -->
|
|
<div class="igny8-card" style="margin-bottom: 24px;">
|
|
<div class="igny8-card-header">
|
|
<h2>
|
|
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width: 20px; height: 20px;">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
|
</svg>
|
|
<?php _e('Post Types', 'igny8-bridge'); ?>
|
|
</h2>
|
|
</div>
|
|
<p style="margin-bottom: 16px; color: var(--igny8-text-dim);">
|
|
<?php _e('Enable post types to sync with IGNY8. Only enabled post types will show their taxonomy configuration below.', 'igny8-bridge'); ?>
|
|
</p>
|
|
|
|
<div style="display: grid; gap: 12px;">
|
|
<?php foreach ($public_post_types as $slug => $pt) :
|
|
$is_posts = ($slug === 'post');
|
|
$is_enabled = in_array($slug, $enabled_post_types, true);
|
|
?>
|
|
<label class="igny8-post-type-toggle" style="display: flex; align-items: center; cursor: pointer; padding: 12px 16px; border: 1px solid var(--igny8-stroke); border-radius: var(--igny8-radius-base); background: var(--igny8-surface);">
|
|
<input
|
|
type="checkbox"
|
|
name="igny8_enabled_post_types[]"
|
|
value="<?php echo esc_attr($slug); ?>"
|
|
class="igny8-post-type-checkbox"
|
|
data-post-type="<?php echo esc_attr($slug); ?>"
|
|
<?php checked($is_enabled); ?>
|
|
style="margin-right: 12px;"
|
|
/>
|
|
<div style="flex: 1;">
|
|
<span style="font-weight: 600;">
|
|
<?php echo esc_html($pt->label); ?>
|
|
</span>
|
|
<?php if (!$is_posts) : ?>
|
|
<span class="igny8-badge igny8-badge-warning" style="margin-left: 8px;">
|
|
<?php _e('Coming Soon', 'igny8-bridge'); ?>
|
|
</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
<span style="color: var(--igny8-text-dim); font-size: 13px;">
|
|
<?php echo esc_html($slug); ?>
|
|
</span>
|
|
</label>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Post Type Taxonomy Cards (dynamic, shown only for enabled post types) -->
|
|
<?php foreach ($public_post_types as $slug => $pt) :
|
|
$is_posts = ($slug === 'post');
|
|
$is_enabled = in_array($slug, $enabled_post_types, true);
|
|
$taxonomies = get_object_taxonomies($slug, 'objects');
|
|
|
|
// Filter out system taxonomies
|
|
$public_taxonomies = array();
|
|
foreach ($taxonomies as $tax) {
|
|
if ($tax->public && !in_array($tax->name, array('post_format', 'wp_theme'), true)) {
|
|
$public_taxonomies[$tax->name] = $tax;
|
|
}
|
|
}
|
|
|
|
// Skip if no public taxonomies
|
|
if (empty($public_taxonomies)) continue;
|
|
|
|
// Add IGNY8 taxonomies if they exist
|
|
if (taxonomy_exists('igny8_sectors')) {
|
|
$public_taxonomies['igny8_sectors'] = get_taxonomy('igny8_sectors');
|
|
}
|
|
if (taxonomy_exists('igny8_clusters')) {
|
|
$public_taxonomies['igny8_clusters'] = get_taxonomy('igny8_clusters');
|
|
}
|
|
?>
|
|
<div class="igny8-card igny8-taxonomy-card" data-post-type="<?php echo esc_attr($slug); ?>" style="margin-bottom: 24px; <?php echo $is_enabled ? '' : 'display: none;'; ?>">
|
|
<div class="igny8-card-header" style="display: flex; align-items: center; justify-content: space-between;">
|
|
<h2 style="display: flex; align-items: center; gap: 8px;">
|
|
<?php if ($slug === 'post') : ?>
|
|
<span style="font-size: 20px;">📝</span>
|
|
<?php elseif ($slug === 'product') : ?>
|
|
<span style="font-size: 20px;">📦</span>
|
|
<?php elseif ($slug === 'page') : ?>
|
|
<span style="font-size: 20px;">📄</span>
|
|
<?php else : ?>
|
|
<span style="font-size: 20px;">📁</span>
|
|
<?php endif; ?>
|
|
<?php echo esc_html(strtoupper($pt->label)); ?>
|
|
</h2>
|
|
<?php if (!$is_posts) : ?>
|
|
<span class="igny8-badge igny8-badge-warning">
|
|
<?php _e('Coming Soon', 'igny8-bridge'); ?>
|
|
</span>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<p style="margin-bottom: 16px; color: var(--igny8-text-dim); font-size: 14px;">
|
|
<?php printf(__('Taxonomies for %s:', 'igny8-bridge'), esc_html($pt->label)); ?>
|
|
</p>
|
|
|
|
<div style="display: grid; gap: 8px;">
|
|
<?php foreach ($public_taxonomies as $tax_slug => $tax) :
|
|
// Default enabled: category, post_tag, product_cat, product_tag, igny8_sectors, igny8_clusters
|
|
$default_enabled = in_array($tax_slug, array('category', 'post_tag', 'product_cat', 'product_tag', 'igny8_sectors', 'igny8_clusters'), true);
|
|
$is_tax_enabled = in_array($tax_slug, $enabled_taxonomies, true);
|
|
?>
|
|
<label style="display: flex; align-items: center; cursor: pointer; padding: 10px 14px; border: 1px solid var(--igny8-stroke); border-radius: var(--igny8-radius-sm); background: var(--igny8-bg);">
|
|
<input
|
|
type="checkbox"
|
|
name="igny8_enabled_taxonomies[]"
|
|
value="<?php echo esc_attr($tax_slug); ?>"
|
|
<?php checked($is_tax_enabled); ?>
|
|
style="margin-right: 10px;"
|
|
/>
|
|
<span style="flex: 1;"><?php echo esc_html($tax->label); ?></span>
|
|
<span style="color: var(--igny8-text-dim); font-size: 12px;"><?php echo esc_html($tax_slug); ?></span>
|
|
</label>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
|
|
<!-- Default Settings -->
|
|
<div class="igny8-card" style="margin-bottom: 24px;">
|
|
<div class="igny8-card-header">
|
|
<h2>
|
|
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width: 20px; height: 20px;">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/>
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
|
|
</svg>
|
|
<?php _e('Default Settings', 'igny8-bridge'); ?>
|
|
</h2>
|
|
</div>
|
|
|
|
<div class="igny8-grid igny8-grid-2" style="gap: 24px;">
|
|
<!-- Default Post Status -->
|
|
<div>
|
|
<label style="display: block; font-weight: 600; margin-bottom: 12px;">
|
|
<?php _e('Default Post Status', 'igny8-bridge'); ?>
|
|
</label>
|
|
<div style="display: grid; gap: 8px;">
|
|
<label style="display: flex; align-items: center; cursor: pointer; padding: 12px; border: 1px solid var(--igny8-stroke); border-radius: var(--igny8-radius-sm); <?php echo $default_post_status === 'draft' ? 'background: var(--igny8-primary-subtle); border-color: var(--igny8-primary);' : ''; ?>">
|
|
<input
|
|
type="radio"
|
|
name="igny8_default_post_status"
|
|
value="draft"
|
|
<?php checked($default_post_status, 'draft'); ?>
|
|
style="margin-right: 10px;"
|
|
/>
|
|
<div>
|
|
<strong><?php _e('Draft', 'igny8-bridge'); ?></strong>
|
|
<span style="display: block; font-size: 12px; color: var(--igny8-text-dim);">
|
|
<?php _e('Review before publishing', 'igny8-bridge'); ?>
|
|
</span>
|
|
</div>
|
|
</label>
|
|
<label style="display: flex; align-items: center; cursor: pointer; padding: 12px; border: 1px solid var(--igny8-stroke); border-radius: var(--igny8-radius-sm); <?php echo $default_post_status === 'publish' ? 'background: var(--igny8-primary-subtle); border-color: var(--igny8-primary);' : ''; ?>">
|
|
<input
|
|
type="radio"
|
|
name="igny8_default_post_status"
|
|
value="publish"
|
|
<?php checked($default_post_status, 'publish'); ?>
|
|
style="margin-right: 10px;"
|
|
/>
|
|
<div>
|
|
<strong><?php _e('Publish', 'igny8-bridge'); ?></strong>
|
|
<span style="display: block; font-size: 12px; color: var(--igny8-text-dim);">
|
|
<?php _e('Publish immediately', 'igny8-bridge'); ?>
|
|
</span>
|
|
</div>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Enable Sync -->
|
|
<div>
|
|
<label style="display: block; font-weight: 600; margin-bottom: 12px;">
|
|
<?php _e('IGNY8 Sync', 'igny8-bridge'); ?>
|
|
</label>
|
|
<label style="display: flex; align-items: center; cursor: pointer; padding: 16px; border: 1px solid var(--igny8-stroke); border-radius: var(--igny8-radius-sm); background: var(--igny8-surface);">
|
|
<input
|
|
type="checkbox"
|
|
name="igny8_sync_enabled"
|
|
value="1"
|
|
<?php checked($sync_enabled, 1); ?>
|
|
style="margin-right: 12px; width: 20px; height: 20px;"
|
|
/>
|
|
<div>
|
|
<strong><?php _e('Enable IGNY8 Sync', 'igny8-bridge'); ?></strong>
|
|
<span style="display: block; font-size: 12px; color: var(--igny8-text-dim);">
|
|
<?php _e('Allow IGNY8 to publish content to this site', 'igny8-bridge'); ?>
|
|
</span>
|
|
</div>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div style="display: flex; gap: 12px; align-items: center;">
|
|
<button type="submit" class="igny8-btn igny8-btn-primary">
|
|
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width: 16px; height: 16px;">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
|
|
</svg>
|
|
<?php _e('Save Settings', 'igny8-bridge'); ?>
|
|
</button>
|
|
|
|
<button type="button" id="igny8-clear-update-cache" class="igny8-btn" style="background: var(--igny8-surface); border: 1px solid var(--igny8-stroke);">
|
|
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width: 16px; height: 16px;">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
|
|
</svg>
|
|
<?php _e('Clear Update Cache', 'igny8-bridge'); ?>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
<style>
|
|
.igny8-badge {
|
|
display: inline-block;
|
|
padding: 2px 8px;
|
|
font-size: 11px;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
border-radius: 4px;
|
|
}
|
|
.igny8-badge-warning {
|
|
background: #fef3c7;
|
|
color: #92400e;
|
|
}
|
|
.igny8-badge-success {
|
|
background: #d1fae5;
|
|
color: #065f46;
|
|
}
|
|
.igny8-post-type-toggle:hover {
|
|
border-color: var(--igny8-primary);
|
|
}
|
|
.igny8-taxonomy-card {
|
|
transition: opacity 0.2s ease, transform 0.2s ease;
|
|
}
|
|
</style>
|
|
|
|
<script>
|
|
jQuery(document).ready(function($) {
|
|
// Toggle taxonomy cards based on post type checkboxes
|
|
$('.igny8-post-type-checkbox').on('change', function() {
|
|
var postType = $(this).data('post-type');
|
|
var card = $('.igny8-taxonomy-card[data-post-type="' + postType + '"]');
|
|
|
|
if ($(this).is(':checked')) {
|
|
card.slideDown(200);
|
|
} else {
|
|
card.slideUp(200);
|
|
}
|
|
});
|
|
|
|
// Handle clear update cache button
|
|
$('#igny8-clear-update-cache').on('click', function(e) {
|
|
e.preventDefault();
|
|
var $btn = $(this);
|
|
var originalText = $btn.html();
|
|
|
|
$btn.prop('disabled', true).html('<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width: 16px; height: 16px; animation: spin 1s linear infinite;"><circle cx="12" cy="12" r="10" stroke-width="4" stroke="currentColor" stroke-opacity="0.25"></circle><path fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg> Clearing...');
|
|
|
|
$.ajax({
|
|
url: ajaxurl,
|
|
type: 'POST',
|
|
data: {
|
|
action: 'igny8_clear_update_cache',
|
|
nonce: '<?php echo wp_create_nonce('igny8_clear_cache'); ?>'
|
|
},
|
|
success: function(response) {
|
|
if (response.success) {
|
|
$btn.html('<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width: 16px; height: 16px;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg> Cache Cleared!').css('background', '#10b981').css('color', 'white').css('border-color', '#10b981');
|
|
|
|
setTimeout(function() {
|
|
$btn.prop('disabled', false).html(originalText).css('background', '').css('color', '').css('border-color', '');
|
|
}, 2000);
|
|
} else {
|
|
$btn.html('<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width: 16px; height: 16px;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg> Failed').css('background', '#ef4444').css('color', 'white');
|
|
|
|
setTimeout(function() {
|
|
$btn.prop('disabled', false).html(originalText).css('background', '').css('color', '');
|
|
}, 2000);
|
|
}
|
|
},
|
|
error: function() {
|
|
$btn.html('<svg fill="none" stroke="currentColor" viewBox="0 0 24 24" style="width: 16px; height: 16px;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg> Error').css('background', '#ef4444').css('color', 'white');
|
|
|
|
setTimeout(function() {
|
|
$btn.prop('disabled', false).html(originalText).css('background', '').css('color', '');
|
|
}, 2000);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<?php
|
|
// Include layout footer
|
|
include IGNY8_BRIDGE_PLUGIN_DIR . 'admin/layout-footer.php';
|
|
?>
|