woo-audio-preview-pro/
├── admin/ # Admin functionality
├── public/ # Frontend functionality
├── includes/ # Core classes
├── assets/ # Shared CSS/JS
├── dokan/ # Dokan integration
├── wcfm/ # WCFM integration
├── wc-vendors/ # WC Vendors integration
└── docs/ # Documentation
Woo_Audio_Preview_Pro– Main plugin classWoo_Audio_Preview_Pro_Admin– Admin functionalityWoo_Audio_Preview_Pro_Public– Frontend functionalityWCAP_Multivendor_Template– Multi-vendor integration
// Before audio player is rendered
do_action('wcap_pro_before_audio_player', $product_id, $audio_data);
// After audio player is rendered
do_action('wcap_pro_after_audio_player', $product_id, $audio_data);
// Before saving audio data
do_action('wcap_pro_before_save_audio', $product_id, $audio_data);
// After saving audio data
do_action('wcap_pro_after_save_audio', $product_id, $audio_data);
// When audio starts playing
do_action('wcap_pro_audio_play_start', $product_id, $audio_index);
// When audio stops playing
do_action('wcap_pro_audio_play_stop', $product_id, $audio_index);
// Before admin meta box content
do_action('wcap_pro_admin_before_meta_box', $post);
// After admin meta box content
do_action('wcap_pro_admin_after_meta_box', $post);
// Before settings page content
do_action('wcap_pro_admin_before_settings', $tab);
// After settings page content
do_action('wcap_pro_admin_after_settings', $tab);
// Before vendor audio fields
do_action('wcap_pro_vendor_before_audio_fields', $product_id);
// After vendor audio fields
do_action('wcap_pro_vendor_after_audio_fields', $product_id);
// When vendor saves audio data
do_action('wcap_pro_vendor_save_audio', $product_id, $audio_data);
// Filter audio player HTML output
$html = apply_filters('wcap_pro_audio_player_html', $html, $product_id, $audio_data);
// Filter audio file URL before processing
$url = apply_filters('wcap_pro_audio_file_url', $url, $product_id, $index);
// Filter player configuration
$config = apply_filters('wcap_pro_player_config', $config, $product_id);
// Filter audio preview duration
$duration = apply_filters('wcap_pro_preview_duration', $duration, $product_id, $index);
// Filter watermark settings
$watermark = apply_filters('wcap_pro_watermark_settings', $watermark, $product_id);
// Filter whether to show audio player for product
$show = apply_filters('wcap_pro_show_audio_player', $show, $product_id);
// Filter player position on product page
$position = apply_filters('wcap_pro_player_position', $position, $product_id);
// Filter player theme
$theme = apply_filters('wcap_pro_player_theme', $theme, $product_id);
// Filter archive display mode
$mode = apply_filters('wcap_pro_archive_display_mode', $mode, $product_id);
// Filter allowed audio file types
$types = apply_filters('wcap_pro_allowed_file_types', $types);
// Filter maximum file size
$max_size = apply_filters('wcap_pro_max_file_size', $max_size, $product_id);
// Filter CDN domains
$domains = apply_filters('wcap_pro_cdn_domains', $domains);
// Filter upload validation
$valid = apply_filters('wcap_pro_validate_upload', $valid, $file, $product_id);
// Filter vendor upload limit
$limit = apply_filters('wcap_pro_vendor_upload_limit', $limit, $vendor_id);
// Filter vendor capabilities
$can_manage = apply_filters('wcap_pro_vendor_can_manage', $can_manage, $vendor_id);
// Filter vendor audio data before save
$data = apply_filters('wcap_pro_vendor_audio_data', $data, $product_id, $vendor_id);
Templates can be overridden in your theme:
your-theme/
└── woo-audio-preview-pro/
├── audio-player.php
├── audio-button.php
└── archive-player.php
// your-theme/woo-audio-preview-pro/audio-player.php
<?php
if (!defined('ABSPATH')) exit;
$audio_data = $args['audio_data'];
$product_id = $args['product_id'];
?>
<div class="custom-audio-player" data-product="<?php echo esc_attr($product_id); ?>">
<?php foreach ($audio_data['wcap_audio_urls'] as $index => $url): ?>
<div class="audio-item">
<span class="audio-name"><?php echo esc_html($audio_data['wcap_audio_names'][$index]); ?></span>
<audio controls>
<source src="<?php echo esc_url($url); ?>" type="audio/mpeg">
</audio>
</div>
<?php endforeach; ?>
</div>
Admin templates can also be customized:
// Filter admin template path
add_filter('wcap_pro_admin_template_path', function($path, $template) {
if ($template === 'meta-box') {
return get_template_directory() . '/admin/audio-meta-box.php';
}
return $path;
}, 10, 2);
// Player events
$(document).on('wcap:player:ready', function(e, playerId, config) {
// Player is ready, playerId and config are available
});
$(document).on('wcap:audio:play', function(e, playerId, audioIndex) {
// Audio started playing
// playerId: the player instance ID
// audioIndex: index of the audio file being played
});
$(document).on('wcap:audio:pause', function(e, playerId, audioIndex) {
// Audio paused
});
$(document).on('wcap:audio:ended', function(e, playerId, audioIndex) {
// Audio playback ended
});
// Get player instance
var player = window.WCAPPlayer.getInstance(playerId);
// Control playback
player.play();
player.pause();
player.stop();
player.setVolume(0.5);
player.seek(30); // Seek to 30 seconds
// Get player state
var isPlaying = player.isPlaying();
var currentTime = player.getCurrentTime();
var duration = player.getDuration();
// Register custom player
window.WCAPPlayer.registerPlayer('custom', {
init: function(element, config) {
// Initialize custom player
},
play: function() {
// Play audio
},
pause: function() {
// Pause audio
}
});
Audio data is stored in the wp_postmeta table with meta_key wcap_audio:
$audio_data = array(
'wcap_audio_urls' => array(
'https://example.com/audio1.mp3',
'https://example.com/audio2.mp3'
),
'wcap_audio_names' => array(
'Track 1 - Introduction',
'Track 2 - Demo'
),
'wcap_audio_durations' => array(30, 45),
'wcap_audio_theme' => 'classic'
);
Plugin settings are stored in the wp_options table:
wcap_pro_admin_general_option– General settingswcap_pro_player_settings– Player configurationwcap_pro_watermark_settings– Watermark optionswcap_pro_advanced_settings– Advanced options
// Add custom audio source handler
add_filter('wcap_pro_audio_file_url', function($url, $product_id, $index) {
if (strpos($url, 'custom://') === 0) {
// Handle custom protocol
$file_id = str_replace('custom://', '', $url);
return your_custom_url_resolver($file_id);
}
return $url;
}, 10, 3);
// Register custom theme
add_filter('wcap_pro_player_themes', function($themes) {
$themes['mytheme'] = 'My Custom Theme';
return $themes;
});
// Enqueue theme styles
add_filter('wcap_pro_player_theme', function($theme, $product_id) {
if ($theme === 'mytheme') {
wp_enqueue_style('my-audio-theme', get_template_directory_uri() . '/css/audio-theme.css');
}
return $theme;
}, 10, 2);
// Add custom file validation
add_filter('wcap_pro_validate_upload', function($valid, $file, $product_id) {
// Custom validation logic
if (!your_custom_validation($file)) {
return new WP_Error('invalid_file', 'Custom validation failed');
}
return $valid;
}, 10, 3);
// Custom watermark processor
add_filter('wcap_pro_watermark_settings', function($watermark, $product_id) {
if ($watermark['watermark_type'] === 'custom') {
$watermark['processor'] = 'your_custom_processor';
}
return $watermark;
}, 10, 2);
function your_custom_processor($audio_url, $watermark_settings) {
// Process audio with custom watermark
return $processed_url;
}
// Custom vendor platform support
add_filter('wcap_pro_vendor_platforms', function($platforms) {
$platforms['myvendor'] = array(
'name' => 'My Vendor Platform',
'class' => 'MyVendor_Audio_Integration'
);
return $platforms;
});
class MyVendor_Audio_Integration {
public function render_fields($product_id) {
// Render vendor-specific fields
}
public function save_data($product_id, $data) {
// Save vendor data
}
}
// Add custom play button to product thumbnails
add_action('woocommerce_product_thumbnails', function() {
global $product;
$audio_data = get_post_meta($product->get_id(), 'wcap_audio', true);
if (!empty($audio_data['wcap_audio_urls'])) {
echo '<button class="custom-play-btn" data-product="' . $product->get_id() . '">▶ Preview</button>';
}
});
// Track audio plays
add_action('wcap_pro_audio_play_start', function($product_id, $audio_index) {
// Log to analytics
your_analytics_track('audio_play', array(
'product_id' => $product_id,
'audio_index' => $audio_index
));
});
// Set dynamic preview duration based on product category
add_filter('wcap_pro_preview_duration', function($duration, $product_id, $index) {
$product = wc_get_product($product_id);
if ($product->is_type('variable')) {
return 60; // Longer preview for variable products
}
return $duration;
}, 10, 3);
// Add custom CSS based on product type
add_action('wp_head', function() {
if (is_product()) {
global $product;
$audio_data = get_post_meta($product->get_id(), 'wcap_audio', true);
if (!empty($audio_data)) {
echo '<style>.wcap-player { /* custom styles */ }</style>';
}
}
});
- Use lazy loading for audio files
- Implement proper caching strategies
- Optimize audio file sizes
- Use CDN for better delivery
- Always validate and sanitize input
- Use nonces for form submissions
- Implement proper capability checks
- Sanitize file uploads
- Test with popular themes
- Check WordPress version compatibility
- Verify WooCommerce version support
- Test multi-vendor integrations
// Enable debug mode
define('WCAP_PRO_DEBUG', true);
// Debug logging
do_action('wcap_pro_log', 'Debug message', $data);
