Adding more functionality
This commit is contained in:
@@ -16,7 +16,7 @@ class WPDD_Settings {
|
||||
'edit.php?post_type=wpdd_product',
|
||||
__('Settings', 'wp-digital-download'),
|
||||
__('Settings', 'wp-digital-download'),
|
||||
'wpdd_manage_settings',
|
||||
'manage_options',
|
||||
'wpdd-settings',
|
||||
array(__CLASS__, 'render_settings_page')
|
||||
);
|
||||
@@ -26,9 +26,16 @@ class WPDD_Settings {
|
||||
register_setting('wpdd_settings', 'wpdd_paypal_mode');
|
||||
register_setting('wpdd_settings', 'wpdd_paypal_client_id');
|
||||
register_setting('wpdd_settings', 'wpdd_paypal_secret');
|
||||
register_setting('wpdd_settings', 'wpdd_paypal_payout_email');
|
||||
register_setting('wpdd_settings', 'wpdd_admin_email');
|
||||
register_setting('wpdd_settings', 'wpdd_from_name');
|
||||
register_setting('wpdd_settings', 'wpdd_from_email');
|
||||
register_setting('wpdd_settings', 'wpdd_smtp_enabled');
|
||||
register_setting('wpdd_settings', 'wpdd_smtp_host');
|
||||
register_setting('wpdd_settings', 'wpdd_smtp_port');
|
||||
register_setting('wpdd_settings', 'wpdd_smtp_username');
|
||||
register_setting('wpdd_settings', 'wpdd_smtp_password');
|
||||
register_setting('wpdd_settings', 'wpdd_smtp_encryption');
|
||||
register_setting('wpdd_settings', 'wpdd_currency');
|
||||
register_setting('wpdd_settings', 'wpdd_enable_guest_checkout');
|
||||
register_setting('wpdd_settings', 'wpdd_default_download_limit');
|
||||
@@ -193,6 +200,18 @@ class WPDD_Settings {
|
||||
'wpdd_paypal_settings',
|
||||
array('name' => 'wpdd_paypal_secret')
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpdd_paypal_payout_email',
|
||||
__('PayPal Payout Account Email', 'wp-digital-download'),
|
||||
array(__CLASS__, 'email_field'),
|
||||
'wpdd_settings',
|
||||
'wpdd_paypal_settings',
|
||||
array(
|
||||
'name' => 'wpdd_paypal_payout_email',
|
||||
'description' => __('PayPal account email that will send payouts to creators', 'wp-digital-download')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static function add_email_fields() {
|
||||
@@ -231,6 +250,94 @@ class WPDD_Settings {
|
||||
'description' => __('Email address shown in email headers', 'wp-digital-download')
|
||||
)
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpdd_smtp_enabled',
|
||||
__('Enable SMTP', 'wp-digital-download'),
|
||||
array(__CLASS__, 'checkbox_field'),
|
||||
'wpdd_settings',
|
||||
'wpdd_email_settings',
|
||||
array(
|
||||
'name' => 'wpdd_smtp_enabled',
|
||||
'label' => __('Use SMTP for sending emails instead of PHP mail()', 'wp-digital-download')
|
||||
)
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpdd_smtp_host',
|
||||
__('SMTP Host', 'wp-digital-download'),
|
||||
array(__CLASS__, 'text_field'),
|
||||
'wpdd_settings',
|
||||
'wpdd_email_settings',
|
||||
array(
|
||||
'name' => 'wpdd_smtp_host',
|
||||
'description' => __('SMTP server hostname (e.g., smtp.gmail.com)', 'wp-digital-download')
|
||||
)
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpdd_smtp_port',
|
||||
__('SMTP Port', 'wp-digital-download'),
|
||||
array(__CLASS__, 'number_field'),
|
||||
'wpdd_settings',
|
||||
'wpdd_email_settings',
|
||||
array(
|
||||
'name' => 'wpdd_smtp_port',
|
||||
'description' => __('SMTP server port number (common ports: 25, 465, 587)', 'wp-digital-download'),
|
||||
'min' => 1,
|
||||
'max' => 65535
|
||||
)
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpdd_smtp_encryption',
|
||||
__('SMTP Encryption', 'wp-digital-download'),
|
||||
array(__CLASS__, 'select_field'),
|
||||
'wpdd_settings',
|
||||
'wpdd_email_settings',
|
||||
array(
|
||||
'name' => 'wpdd_smtp_encryption',
|
||||
'options' => array(
|
||||
'' => __('None', 'wp-digital-download'),
|
||||
'tls' => __('TLS', 'wp-digital-download'),
|
||||
'ssl' => __('SSL', 'wp-digital-download')
|
||||
),
|
||||
'description' => __('Select encryption method - TLS is recommended for most providers', 'wp-digital-download')
|
||||
)
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpdd_smtp_autodetect',
|
||||
__('Auto-Detect Settings', 'wp-digital-download'),
|
||||
array(__CLASS__, 'smtp_autodetect_field'),
|
||||
'wpdd_settings',
|
||||
'wpdd_email_settings',
|
||||
array()
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpdd_smtp_username',
|
||||
__('SMTP Username', 'wp-digital-download'),
|
||||
array(__CLASS__, 'text_field'),
|
||||
'wpdd_settings',
|
||||
'wpdd_email_settings',
|
||||
array(
|
||||
'name' => 'wpdd_smtp_username',
|
||||
'description' => __('SMTP authentication username', 'wp-digital-download')
|
||||
)
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'wpdd_smtp_password',
|
||||
__('SMTP Password', 'wp-digital-download'),
|
||||
array(__CLASS__, 'password_field'),
|
||||
'wpdd_settings',
|
||||
'wpdd_email_settings',
|
||||
array(
|
||||
'name' => 'wpdd_smtp_password',
|
||||
'description' => __('SMTP authentication password', 'wp-digital-download')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static function add_download_fields() {
|
||||
@@ -305,59 +412,101 @@ class WPDD_Settings {
|
||||
}
|
||||
|
||||
public static function render_settings_page() {
|
||||
$active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'general';
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php _e('WP Digital Download Settings', 'wp-digital-download'); ?></h1>
|
||||
|
||||
<div class="wpdd-settings-sidebar">
|
||||
<div class="wpdd-settings-box">
|
||||
<h3><?php _e('Quick Setup', 'wp-digital-download'); ?></h3>
|
||||
<p><?php _e('To get started quickly:', 'wp-digital-download'); ?></p>
|
||||
<ol>
|
||||
<li><?php _e('Configure PayPal settings above', 'wp-digital-download'); ?></li>
|
||||
<li><?php _e('Create your first product', 'wp-digital-download'); ?></li>
|
||||
<li><?php _e('Add the shop shortcode [wpdd_shop] to a page', 'wp-digital-download'); ?></li>
|
||||
<li><?php _e('Test with a free product first', 'wp-digital-download'); ?></li>
|
||||
</ol>
|
||||
<h2 class="nav-tab-wrapper">
|
||||
<a href="<?php echo admin_url('edit.php?post_type=wpdd_product&page=wpdd-settings&tab=general'); ?>"
|
||||
class="nav-tab <?php echo $active_tab == 'general' ? 'nav-tab-active' : ''; ?>"><?php _e('General', 'wp-digital-download'); ?></a>
|
||||
<a href="<?php echo admin_url('edit.php?post_type=wpdd_product&page=wpdd-settings&tab=paypal'); ?>"
|
||||
class="nav-tab <?php echo $active_tab == 'paypal' ? 'nav-tab-active' : ''; ?>"><?php _e('PayPal', 'wp-digital-download'); ?></a>
|
||||
<a href="<?php echo admin_url('edit.php?post_type=wpdd_product&page=wpdd-settings&tab=email'); ?>"
|
||||
class="nav-tab <?php echo $active_tab == 'email' ? 'nav-tab-active' : ''; ?>"><?php _e('Email', 'wp-digital-download'); ?></a>
|
||||
<a href="<?php echo admin_url('edit.php?post_type=wpdd_product&page=wpdd-settings&tab=downloads'); ?>"
|
||||
class="nav-tab <?php echo $active_tab == 'downloads' ? 'nav-tab-active' : ''; ?>"><?php _e('Downloads', 'wp-digital-download'); ?></a>
|
||||
<a href="<?php echo admin_url('edit.php?post_type=wpdd_product&page=wpdd-settings&tab=watermark'); ?>"
|
||||
class="nav-tab <?php echo $active_tab == 'watermark' ? 'nav-tab-active' : ''; ?>"><?php _e('Watermark', 'wp-digital-download'); ?></a>
|
||||
</h2>
|
||||
|
||||
<div class="wpdd-settings-container">
|
||||
<div class="wpdd-settings-content">
|
||||
<form method="post" action="options.php" class="wpdd-settings-form">
|
||||
<?php
|
||||
settings_fields('wpdd_settings');
|
||||
|
||||
switch ($active_tab) {
|
||||
case 'general':
|
||||
self::render_general_tab();
|
||||
break;
|
||||
case 'paypal':
|
||||
self::render_paypal_tab();
|
||||
break;
|
||||
case 'email':
|
||||
self::render_email_tab();
|
||||
break;
|
||||
case 'downloads':
|
||||
self::render_downloads_tab();
|
||||
break;
|
||||
case 'watermark':
|
||||
self::render_watermark_tab();
|
||||
break;
|
||||
default:
|
||||
self::render_general_tab();
|
||||
}
|
||||
|
||||
submit_button();
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="wpdd-settings-box">
|
||||
<h3><?php _e('Available Shortcodes', 'wp-digital-download'); ?></h3>
|
||||
<ul>
|
||||
<li><code>[wpdd_shop]</code> - <?php _e('Display product storefront', 'wp-digital-download'); ?></li>
|
||||
<li><code>[wpdd_customer_purchases]</code> - <?php _e('Customer purchase history', 'wp-digital-download'); ?></li>
|
||||
<li><code>[wpdd_checkout]</code> - <?php _e('Checkout page', 'wp-digital-download'); ?></li>
|
||||
<li><code>[wpdd_thank_you]</code> - <?php _e('Thank you page', 'wp-digital-download'); ?></li>
|
||||
<li><code>[wpdd_product id="123"]</code> - <?php _e('Single product display', 'wp-digital-download'); ?></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="wpdd-settings-box">
|
||||
<h3><?php _e('System Status', 'wp-digital-download'); ?></h3>
|
||||
<?php self::system_status(); ?>
|
||||
<div class="wpdd-settings-sidebar">
|
||||
<?php if ($active_tab == 'general') : ?>
|
||||
<div class="wpdd-settings-box">
|
||||
<h3><?php _e('Quick Setup', 'wp-digital-download'); ?></h3>
|
||||
<p><?php _e('To get started quickly:', 'wp-digital-download'); ?></p>
|
||||
<ol>
|
||||
<li><?php _e('Configure PayPal settings', 'wp-digital-download'); ?></li>
|
||||
<li><?php _e('Create your first product', 'wp-digital-download'); ?></li>
|
||||
<li><?php _e('Add the shop shortcode [wpdd_shop] to a page', 'wp-digital-download'); ?></li>
|
||||
<li><?php _e('Test with a free product first', 'wp-digital-download'); ?></li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<div class="wpdd-settings-box">
|
||||
<h3><?php _e('Available Shortcodes', 'wp-digital-download'); ?></h3>
|
||||
<ul>
|
||||
<li><code>[wpdd_shop]</code> - <?php _e('Display product storefront', 'wp-digital-download'); ?></li>
|
||||
<li><code>[wpdd_customer_purchases]</code> - <?php _e('Customer purchase history', 'wp-digital-download'); ?></li>
|
||||
<li><code>[wpdd_checkout]</code> - <?php _e('Checkout page', 'wp-digital-download'); ?></li>
|
||||
<li><code>[wpdd_thank_you]</code> - <?php _e('Thank you page', 'wp-digital-download'); ?></li>
|
||||
<li><code>[wpdd_product id="123"]</code> - <?php _e('Single product display', 'wp-digital-download'); ?></li>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="wpdd-settings-box">
|
||||
<h3><?php _e('System Status', 'wp-digital-download'); ?></h3>
|
||||
<?php self::system_status(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form method="post" action="options.php" class="wpdd-settings-form">
|
||||
<?php
|
||||
settings_fields('wpdd_settings');
|
||||
do_settings_sections('wpdd_settings');
|
||||
submit_button();
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.wpdd-settings-sidebar {
|
||||
float: right;
|
||||
width: 300px;
|
||||
margin-left: 20px;
|
||||
position: relative;
|
||||
z-index: 10;
|
||||
.wpdd-settings-container {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.wpdd-settings-form {
|
||||
overflow: hidden;
|
||||
margin-right: 340px;
|
||||
.wpdd-settings-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.wpdd-settings-sidebar {
|
||||
width: 300px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.wpdd-settings-box {
|
||||
background: white;
|
||||
@@ -377,15 +526,21 @@ class WPDD_Settings {
|
||||
.wpdd-status-good { color: #46b450; }
|
||||
.wpdd-status-warning { color: #ffb900; }
|
||||
.wpdd-status-error { color: #dc3232; }
|
||||
|
||||
.wpdd-tab-content {
|
||||
background: white;
|
||||
border: 1px solid #ccd0d4;
|
||||
padding: 20px;
|
||||
margin-top: -1px;
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
.wpdd-settings-sidebar {
|
||||
float: none;
|
||||
width: 100%;
|
||||
margin-left: 0;
|
||||
margin-top: 30px;
|
||||
.wpdd-settings-container {
|
||||
flex-direction: column;
|
||||
}
|
||||
.wpdd-settings-form {
|
||||
margin-right: 0;
|
||||
.wpdd-settings-sidebar {
|
||||
width: 100%;
|
||||
order: 2;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -584,9 +739,98 @@ class WPDD_Settings {
|
||||
));
|
||||
}
|
||||
|
||||
public static function smtp_autodetect_field($args) {
|
||||
?>
|
||||
<button type="button" id="wpdd-smtp-autodetect" class="button button-secondary">
|
||||
<?php _e('Auto-Detect SMTP Settings', 'wp-digital-download'); ?>
|
||||
</button>
|
||||
<span id="wpdd-smtp-autodetect-status" style="margin-left: 10px;"></span>
|
||||
<p class="description">
|
||||
<?php _e('Automatically detect port and encryption settings based on the SMTP host.', 'wp-digital-download'); ?>
|
||||
</p>
|
||||
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function($) {
|
||||
$('#wpdd-smtp-autodetect').on('click', function() {
|
||||
var $button = $(this);
|
||||
var $status = $('#wpdd-smtp-autodetect-status');
|
||||
var host = $('#wpdd_smtp_host').val();
|
||||
|
||||
if (!host) {
|
||||
$status.html('<span style="color: #dc3232;"><?php _e('Please enter SMTP host first.', 'wp-digital-download'); ?></span>');
|
||||
return;
|
||||
}
|
||||
|
||||
$button.prop('disabled', true).text('<?php _e('Detecting...', 'wp-digital-download'); ?>');
|
||||
$status.html('<span style="color: #0073aa;"><?php _e('Testing connection...', 'wp-digital-download'); ?></span>');
|
||||
|
||||
// Test common SMTP configurations
|
||||
var configs = [
|
||||
{ port: 587, encryption: 'tls' },
|
||||
{ port: 465, encryption: 'ssl' },
|
||||
{ port: 25, encryption: 'tls' },
|
||||
{ port: 25, encryption: '' }
|
||||
];
|
||||
|
||||
// Detect common providers
|
||||
var detectedConfig = null;
|
||||
var hostname = host.toLowerCase();
|
||||
|
||||
if (hostname.includes('gmail.com') || hostname.includes('google.com')) {
|
||||
detectedConfig = { port: 587, encryption: 'tls' };
|
||||
} else if (hostname.includes('outlook.com') || hostname.includes('hotmail.com') || hostname.includes('live.com')) {
|
||||
detectedConfig = { port: 587, encryption: 'tls' };
|
||||
} else if (hostname.includes('yahoo.com')) {
|
||||
detectedConfig = { port: 587, encryption: 'tls' };
|
||||
} else if (hostname.includes('smtp.') && hostname.includes('.com')) {
|
||||
detectedConfig = { port: 587, encryption: 'tls' };
|
||||
} else {
|
||||
// Default to most common configuration
|
||||
detectedConfig = { port: 587, encryption: 'tls' };
|
||||
}
|
||||
|
||||
// Apply detected settings
|
||||
setTimeout(function() {
|
||||
$('#wpdd_smtp_port').val(detectedConfig.port);
|
||||
$('#wpdd_smtp_encryption').val(detectedConfig.encryption);
|
||||
|
||||
$button.prop('disabled', false).text('<?php _e('Auto-Detect SMTP Settings', 'wp-digital-download'); ?>');
|
||||
$status.html('<span style="color: #46b450;"><?php _e('Settings detected and applied!', 'wp-digital-download'); ?></span>');
|
||||
|
||||
// Clear status after 5 seconds
|
||||
setTimeout(function() {
|
||||
$status.html('');
|
||||
}, 5000);
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function system_status() {
|
||||
$status = array();
|
||||
|
||||
// Check if WPDD_UPLOADS_DIR is defined to prevent fatal errors
|
||||
if (!defined('WPDD_UPLOADS_DIR')) {
|
||||
$status[] = array(
|
||||
'label' => __('Plugin Constants', 'wp-digital-download'),
|
||||
'value' => __('Not Loaded', 'wp-digital-download'),
|
||||
'class' => 'wpdd-status-error'
|
||||
);
|
||||
echo '<ul>';
|
||||
foreach ($status as $item) {
|
||||
printf(
|
||||
'<li>%s: <span class="%s">%s</span></li>',
|
||||
esc_html($item['label']),
|
||||
esc_attr($item['class']),
|
||||
esc_html($item['value'])
|
||||
);
|
||||
}
|
||||
echo '</ul>';
|
||||
return;
|
||||
}
|
||||
|
||||
$upload_dir = wp_upload_dir();
|
||||
$protected_dir = trailingslashit($upload_dir['basedir']) . WPDD_UPLOADS_DIR;
|
||||
|
||||
@@ -659,6 +903,73 @@ class WPDD_Settings {
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
public static function render_general_tab() {
|
||||
?>
|
||||
<div class="wpdd-tab-content">
|
||||
<h2><?php _e('General Settings', 'wp-digital-download'); ?></h2>
|
||||
<?php self::do_settings_sections_for_tab('wpdd_general_settings'); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function render_paypal_tab() {
|
||||
?>
|
||||
<div class="wpdd-tab-content">
|
||||
<h2><?php _e('PayPal Settings', 'wp-digital-download'); ?></h2>
|
||||
<?php self::do_settings_sections_for_tab('wpdd_paypal_settings'); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function render_email_tab() {
|
||||
?>
|
||||
<div class="wpdd-tab-content">
|
||||
<h2><?php _e('Email Settings', 'wp-digital-download'); ?></h2>
|
||||
<?php self::do_settings_sections_for_tab('wpdd_email_settings'); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function render_downloads_tab() {
|
||||
?>
|
||||
<div class="wpdd-tab-content">
|
||||
<h2><?php _e('Download Settings', 'wp-digital-download'); ?></h2>
|
||||
<?php self::do_settings_sections_for_tab('wpdd_download_settings'); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function render_watermark_tab() {
|
||||
?>
|
||||
<div class="wpdd-tab-content">
|
||||
<h2><?php _e('Watermark Settings', 'wp-digital-download'); ?></h2>
|
||||
<?php self::do_settings_sections_for_tab('wpdd_watermark_settings'); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
private static function do_settings_sections_for_tab($section_id) {
|
||||
global $wp_settings_sections, $wp_settings_fields;
|
||||
|
||||
if (!isset($wp_settings_sections['wpdd_settings'][$section_id])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$section = $wp_settings_sections['wpdd_settings'][$section_id];
|
||||
|
||||
if (isset($section['callback']) && $section['callback']) {
|
||||
call_user_func($section['callback'], $section);
|
||||
}
|
||||
|
||||
if (!isset($wp_settings_fields['wpdd_settings'][$section_id])) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<table class="form-table" role="presentation">';
|
||||
do_settings_fields('wpdd_settings', $section_id);
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
public static function sanitize_commission_rate($input) {
|
||||
$value = floatval($input);
|
||||
if ($value < 0) {
|
||||
|
Reference in New Issue
Block a user