Materials Plugin
A comprehensive WordPress plugin for managing materials with Google Drive links, advanced search, and mobile-responsive interface.
by Your Name · github.com/saqibullahdev/material_wordpress_plugin · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/saqibullahdev/material_wordpress_plugin/archive/refs/heads/main.zipMaterials Plugin - WordPress Plugin
A comprehensive WordPress plugin that creates a custom post type for materials with Google Drive links, advanced search functionality, and a mobile-responsive frontend interface.
🚀 Features
Core Functionality
- Custom Post Type: "Materials" with Google Drive link integration
- Advanced Search: Real-time AJAX search with filtering and sorting
- Mobile Responsive: Optimized for all devices and screen sizes
- SEO Optimized: Comprehensive SEO features and structured data
- Analytics: Detailed tracking and reporting system
- Security: Enterprise-grade security measures
Search & Discovery
- Real-time search with debounced input (300ms delay)
- Multi-level filtering: categories, subcategories, and tags
- Dynamic subcategory loading
- Multiple sorting options: date, title, downloads, category
- AJAX pagination with configurable results per page
- Grouped results display by category and subcategory
User Experience
- Modern, polished interface with advanced animations
- Skeleton loading animations for better perceived performance
- Dark mode support with automatic detection
- Accessibility compliance with WCAG guidelines
- Enhanced keyboard navigation and focus management
- Cross-browser compatibility and progressive enhancement
SEO & Performance
- Custom meta titles and descriptions
- Open Graph and Twitter Card tags
- Schema.org structured data markup
- XML sitemap integration
- Breadcrumb navigation
- Canonical URLs
- Performance optimizations with modern CSS features
Analytics & Tracking
- Download tracking and analytics
- Search analytics and insights
- User behavior tracking
- Performance metrics
- Data export and reporting
- Dashboard widget for quick overview
Security Features
- Rate limiting for AJAX requests
- Input validation and sanitization
- CSRF protection and nonce verification
- Security headers (CSP, XSS Protection, etc.)
- SQL injection prevention
- XSS protection
- File upload security
- Suspicious user agent blocking
📋 Requirements
- WordPress: 5.0 or higher
- PHP: 7.4 or higher
- MySQL: 5.6 or higher
- Browser Support: Modern browsers (Chrome 60+, Firefox 55+, Safari 12+, Edge 79+)
🛠️ Installation
Method 1: WordPress Admin (Recommended)
- Download the plugin ZIP file
- Go to Plugins > Add New in your WordPress admin
- Click Upload Plugin and select the ZIP file
- Click Install Now and then Activate Plugin
Method 2: Manual Installation
- Extract the plugin ZIP file
- Upload the
materials-pluginfolder to/wp-content/plugins/ - Go to Plugins in your WordPress admin
- Find "Materials Plugin" and click Activate
Method 3: Git Clone
cd wp-content/plugins
git clone https://github.com/yourusername/materials-plugin.git
cd materials-plugin
composer install # If using Composer dependencies
⚙️ Configuration
Initial Setup
- Activate the plugin - This will create necessary database tables
- Create materials - Add your first material with Google Drive links
- Organize content - Set up categories and tags for your materials
- Configure settings - Go to Materials > Settings to customize options
Plugin Settings
Navigate to Materials > Settings to configure:
General Settings
- Materials per page (default: 12)
- Enable download tracking
- Enable search analytics
- Default access level (Public/Private/Premium)
Display Settings
- Show download count
- Show file size
- Group by category
- Enable lazy loading
Search Settings
- Search delay (default: 300ms)
- Cache duration (default: 1 hour)
- Enable SEO optimization
- Validate Google Drive URLs
Database Tables
The plugin creates the following custom tables:
wp_materials_meta- Enhanced material metadatawp_materials_search_log- Search analyticswp_materials_analytics- Comprehensive analyticswp_materials_user_behavior- User behavior trackingwp_materials_rate_limits- Rate limiting datawp_materials_security_log- Security event logging
📖 Usage
Creating Materials
Via WordPress Admin
- Go to Materials > Add New
- Enter the material title and description
- Required: Add Google Drive link in the Material Details meta box
- Optional: Set file size, access level, and other metadata
- Assign categories and tags
- Publish the material
Via Import
- Go to Materials > Import/Export
- Prepare a CSV file with required columns:
title(required)google_drive_link(required)description,file_size,file_type,category,tags(optional)
- Upload and import the CSV file
Frontend Display
Materials Page
The plugin automatically creates a /materials/ page with:
- Search interface with real-time results
- Category and tag filtering
- Sorting options
- Pagination
- Mobile-responsive design
Shortcodes
Use the [materials_search_page] shortcode to display the search interface anywhere:
[materials_search_page]
Template Integration
Include materials in your theme templates:
<?php
$materials = new WP_Query(array(
'post_type' => 'materials',
'posts_per_page' => 10
));
if ($materials->have_posts()) :
while ($materials->have_posts()) : $materials->the_post();
// Display material content
echo '<h2>' . get_the_title() . '</h2>';
echo '<p>' . get_the_excerpt() . '</p>';
$drive_link = get_post_meta(get_the_ID(), '_google_drive_link', true);
if ($drive_link) {
echo '<a href="' . esc_url($drive_link) . '" target="_blank">Download</a>';
}
endwhile;
wp_reset_postdata();
endif;
?>
Search Functionality
Basic Search
Users can search materials by:
- Text content (title, description, content)
- Categories and subcategories
- Tags
- File type
- Access level
Advanced Features
- Real-time results: Updates as users type
- Smart filtering: Combines multiple criteria
- Results grouping: Organized by category and subcategory
- Performance optimized: Cached results and efficient queries
🔧 Developer Guide
Plugin Structure
materials-plugin/
├── materials-plugin.php # Main plugin file
├── includes/ # Core classes
│ ├── class-materials-plugin.php
│ ├── class-materials-post-type.php
│ ├── class-materials-ajax-handler.php
│ ├── class-materials-frontend.php
│ ├── class-materials-seo.php
│ ├── class-materials-analytics.php
│ └── class-materials-security.php
├── admin/ # Admin interface
│ ├── class-materials-admin.php
│ └── class-materials-meta-boxes.php
├── public/ # Frontend assets
│ ├── css/
│ ├── js/
│ └── templates/
├── assets/ # Plugin assets
└── languages/ # Translation files
Hooks and Filters
Actions
// Fired when plugin initializes
do_action('materials_plugin_init');
// Fired when material is created
do_action('materials_material_created', $post_id);
// Fired when material is downloaded
do_action('materials_material_downloaded', $post_id, $user_id);
// Fired when search is performed
do_action('materials_search_performed', $search_term, $results);
Filters
// Modify material query arguments
$args = apply_filters('materials_query_args', $args);
// Customize material display
$content = apply_filters('materials_display_content', $content, $post_id);
// Modify search results
$results = apply_filters('materials_search_results', $results, $search_term);
// Customize SEO meta
$meta = apply_filters('materials_seo_meta', $meta, $post_id);
Custom Post Type
// Register custom post type
$post_type = new Materials_Post_Type();
// Get materials
$materials = get_posts(array(
'post_type' => 'materials',
'post_status' => 'publish',
'posts_per_page' => -1
));
// Get material meta
$drive_link = get_post_meta($post_id, '_google_drive_link', true);
$file_size = get_post_meta($post_id, '_file_size', true);
$access_level = get_post_meta($post_id, '_access_level', true);
AJAX Integration
// Handle custom AJAX requests
add_action('wp_ajax_my_custom_action', 'handle_custom_action');
add_action('wp_ajax_nopriv_my_custom_action', 'handle_custom_action');
function handle_custom_action() {
// Verify nonce
if (!wp_verify_nonce($_POST['nonce'], 'materials_ajax_nonce')) {
wp_send_json_error('Security check failed');
}
// Process request
$result = process_custom_action($_POST);
// Send response
wp_send_json_success($result);
}
Custom Fields
// Add custom meta box
add_action('add_meta_boxes', 'add_custom_meta_box');
function add_custom_meta_box() {
add_meta_box(
'custom_meta_box',
'Custom Fields',
'render_custom_meta_box',
'materials',
'normal',
'high'
);
}
// Save custom meta
add_action('save_post', 'save_custom_meta');
function save_custom_meta($post_id) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (!current_user_can('edit_post', $post_id)) return;
if (isset($_POST['custom_field'])) {
update_post_meta($post_id, '_custom_field', sanitize_text_field($_POST['custom_field']));
}
}
Styling and JavaScript
// Enqueue custom styles
add_action('wp_enqueue_scripts', 'enqueue_custom_styles');
function enqueue_custom_styles() {
wp_enqueue_style(
'custom-materials-style',
get_template_directory_uri() . '/css/custom-materials.css',
array('materials-frontend'),
'1.0.0'
);
}
// Customize JavaScript
add_action('wp_enqueue_scripts', 'enqueue_custom_scripts');
function enqueue_custom_scripts() {
wp_enqueue_script(
'custom-materials-script',
get_template_directory_uri() . '/js/custom-materials.js',
array('materials-search'),
'1.0.0',
true
);
// Localize script with custom data
wp_localize_script('custom-materials-script', 'customMaterials', array(
'ajaxUrl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('materials_ajax_nonce')
));
}
📊 Analytics and Reporting
Dashboard Widget
The plugin adds a dashboard widget showing:
- Today's activity (downloads, views, searches)
- This week's statistics
- Quick access to full analytics
Analytics Page
Navigate to Materials > Analytics for detailed reports:
- Overview statistics
- Popular materials
- Search analytics
- Device and browser statistics
- Export functionality
Data Export
Export analytics data in multiple formats:
- CSV: For spreadsheet analysis
- JSON: For API integration
- Custom periods: 7, 30, 90, 365 days
🔒 Security Features
Rate Limiting
- Search requests: 30 per minute
- Downloads: 10 per minute
- Views: 100 per minute
- General requests: 100 per minute
Input Validation
- Comprehensive input sanitization
- Type-specific validation (URL, email, int, float, filename, HTML)
- Maximum field size limits
- Dangerous content detection
Security Headers
- Content Security Policy (CSP)
- XSS Protection
- Content Type Options
- Frame Options
- Referrer Policy
- HSTS (on HTTPS)
File Upload Security
- Restricted MIME types
- File size limits (50MB max)
- Malicious content scanning
- Path traversal prevention
🚀 Performance Optimization
Caching Strategy
- Object caching: Taxonomy terms and post queries
- Transient caching: Search results for 5 minutes
- Database optimization: Proper indexing on custom tables
- AJAX pagination: Load results in chunks
Code Optimization
- Lazy loading: Load content on scroll
- Minified assets: Compressed CSS and JS files
- CDN integration: Support for CDN delivery
- Database queries: Optimized WP_Query parameters
Modern CSS Features
- CSS custom properties for theming
- Container queries for responsive design
- Backdrop filters for modern effects
- Reduced motion support for accessibility
🌐 Internationalization
Translation Support
The plugin is fully translatable:
- Text domain:
materials-plugin - Translation files in
/languages/directory - Support for RTL languages
- Localized date and number formats
Adding Translations
- Create translation files using Poedit or similar tools
- Place
.poand.mofiles in/languages/directory - Use
__(),_e(), andesc_html__()functions for translatable strings
🧪 Testing
Unit Testing
# Run PHPUnit tests
composer test
# Run specific test suite
vendor/bin/phpunit --testsuite=unit
Integration Testing
# Run integration tests
vendor/bin/phpunit --testsuite=integration
# Run with WordPress test environment
vendor/bin/phpunit --testsuite=wordpress
Browser Testing
- Desktop: Chrome, Firefox, Safari, Edge
- Mobile: iOS Safari, Chrome Mobile, Samsung Internet
- Tablet: iPad, Android tablets
🐛 Troubleshooting
Common Issues
Plugin Not Activating
- Check PHP version (7.4+ required)
- Verify WordPress version (5.0+ required)
- Check for plugin conflicts
- Review error logs
Search Not Working
- Verify AJAX is enabled
- Check nonce verification
- Review browser console for JavaScript errors
- Verify database tables exist
Performance Issues
- Enable caching plugins
- Check database query performance
- Optimize images and assets
- Review server configuration
Security Warnings
- Update WordPress and plugins
- Check file permissions
- Review security logs
- Enable security plugins
Debug Mode
Enable WordPress debug mode for detailed error information:
// In wp-config.php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
Support Resources
- Documentation: Plugin Documentation
- Support Forum: WordPress.org Support
- GitHub Issues: Report Bugs
- Developer Guide: API Reference
📈 Roadmap
Version 1.1 (Q2 2024)
- [ ] Advanced reporting dashboard
- [ ] Email notifications
- [ ] Bulk operations
- [ ] API endpoints
Version 1.2 (Q3 2024)
- [ ] Multi-site support
- [ ] Advanced caching
- [ ] Performance monitoring
- [ ] Mobile app integration
Version 2.0 (Q4 2024)
- [ ] Cloud storage integration
- [ ] Advanced analytics
- [ ] Machine learning features
- [ ] Enterprise features
🤝 Contributing
Development Setup
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
Coding Standards
- Follow WordPress coding standards
- Use PHP 7.4+ features
- Write comprehensive documentation
- Include unit tests for new features
Code Review Process
- Automated checks (PHPCS, PHPUnit)
- Manual code review
- Testing in staging environment
- Merge to development branch
- Release to production
📄 License
This plugin is licensed under the GPL v2 or later.
Copyright (C) 2024 Your Name
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
🙏 Acknowledgments
- WordPress community for the excellent platform
- Contributors and beta testers
- Open source projects that made this possible
- Users who provided feedback and suggestions
📞 Support
For support, questions, or feature requests:
- Email: support@example.com
- Website: https://example.com
- Documentation: https://example.com/docs
- GitHub: https://github.com/yourusername/materials-plugin
Thank you for using Materials Plugin! 🎉
If you find this plugin helpful, please consider:
- ⭐ Rating it on WordPress.org
- 📝 Writing a review
- 💰 Making a donation
- 🔗 Sharing it with others