وردپرس ۶.۹: تحول کامل CMS محبوب جهان - از وبلاگ ساده تا پلتفرم سازمانی

🌍 آمارهای شگفت‌انگیز وردپرس در ۲۰۲۶:

  • ۴۳.۲٪ از تمام وبسایت‌های جهان با وردپرس ساخته شده‌اند
  • ۶۴ میلیون وبسایت فعال وردپرسی در جهان
  • ۵۹,۰۰۰+ پلاگین رایگان در مخزن رسمی
  • ۱۲,۰۰۰+ قالب رایگان
  • ۳۵٪ از ۱۰,۰۰۰ وبسایت برتر جهان وردپرسی هستند
  • ۲۰۰+ میلیون دانلود وردپرس ۶.۹ در ماه اول

🎯 خلاصه اجرایی:

وردپرس ۶.۹ نه یک بروزرسانی معمولی، بلکه یک تحول کامل در اکوسیستم وردپرس است. این نسخه با معرفی معماری جدید Block Editor 2.0، سیستم Multisite پیشرفته، API مدرن و بهبودهای امنیتی چشمگیر، وردپرس را از یک سیستم مدیریت محتوای ساده به یک پلتفرم سازمانی کامل تبدیل کرده است. در این مقاله، به تحلیل عمیق همه این تغییرات می‌پردازیم.

فصل اول: تاریخچه وردپرس - از تولد تا اوج

۱.۱ تولد یک غول

وردپرس در ۲۷ می ۲۰۰۳ توسط مت مولنوگ به عنوان فورکی از b2/cafelog منتشر شد. اما چیزی که در این سال‌ها اتفاق افتاده، فراتر از یک داستان موفقیت است:

۲۰۰۳: انتشار نسخه ۰.۷

اولین انتشار عمومی با ۹۰۴ خط کد PHP

۲۰۰۵: معرفی پلاگین‌ها

شروع اکوسیستم پلاگین که انقلابی در توسعه‌پذیری ایجاد کرد

۲۰۱۰: وردپرس ۳.۰

معرفی Custom Post Types و Taxonomies - شروع تبدیل به CMS

۲۰۱۸: گوتنبرگ (وردپرس ۵.۰)

معرفی Block Editor - بزرگترین تغییر در تاریخ وردپرس

۲۰۲۳: Full Site Editing

تکمیل تحول به یک صفحه‌ساز کامل

۲۰۲۶: وردپرس ۶.۹

تکامل کامل به یک پلتفرم سازمانی با معماری مدرن

۱.۲ فلسفه وردپرس

وردپرس بر اساس چهار اصل اصلی توسعه یافته است:

۱. دموکراتیک بودن انتشار

هر کسی می‌تواند با وردپرس بنویسد و منتشر کند

۲. آزادی و منبع باز

کد باز و قابل تغییر برای همه

۳. جامعه محوری

توسعه توسط جامعه جهانی توسعه‌دهندگان

۴. تمرکز بر کاربر

اولویت تجربه کاربری و سهولت استفاده

فصل دوم: معماری فنی وردپرس ۶.۹

۲.۱ هسته جدید: WordPress Core 6.9

معماری چندلایه وردپرس ۶.۹:

WordPress 6.9 Architecture:
├── Presentation Layer (لایه نمایش)
│   ├── Block Editor 2.0
│   ├── Full Site Editing
│   ├── Theme.json Enhanced
│   └── Global Styles 2.0
├── Application Layer (لایه کاربرد)
│   ├── REST API v3
│   ├── GraphQL Integration
│   ├── Webhooks System
│   └── Queue Management
├── Business Logic Layer (لایه منطق)
│   ├── Custom Post Types
│   ├── Taxonomies Advanced
│   ├── User Roles 2.0
│   └── Workflow Engine
├── Data Access Layer (لایه دسترسی به داده)
│   ├── Database Abstraction
│   ├── Object Cache 2.0
│   ├── Query Optimization
│   └── Data Migration Tools
└── Infrastructure Layer (لایه زیرساخت)
    ├── Security Suite
    ├── Performance Module
    ├── Multisite 2.0
    └── DevOps Tools

۲.۲ سیستم فایل و ساختار دایرکتوری

ساختار پیشرفته وردپرس ۶.۹:

wordpress/
├── wp-admin/           # مدیریت پیشرفته
│   ├── css/           # استایل‌های مدرن
│   ├── js/            # اسکریپت‌های بهینه شده
│   ├── includes/      # کلاس‌های core
│   └── network/       # مدیریت شبکه
├── wp-content/        # محتوای کاربر
│   ├── plugins/       # پلاگین‌های مدرن
│   ├── themes/        # قالب‌های Block-Based
│   ├── uploads/       # مدیریت پیشرفته فایل
│   ├── languages/     # چندزبانی کامل
│   └── cache/         # سیستم کش یکپارچه
├── wp-includes/       # کتابخانه‌های core
│   ├── blocks/        # سیستم بلوک‌ها
│   ├── rest-api/      # REST API v3
│   ├── customizer/    # سفارشی‌ساز پیشرفته
│   └── widgets/       # ویجت‌های مدرن
├── wp-config.php      # پیکربندی پیشرفته
├── .htaccess          # امنیت و بهینه‌سازی
└── index.php          # هسته اصلی

فصل سوم: Block Editor 2.0 - انقلابی در ویرایش محتوا

۳.۱ ویژگی‌های جدید Block Editor

ویژگی توضیح مزیت
Pattern Overrides ایجاد الگوهای قابل استفاده مجدد با قابلیت سفارشی‌سازی کاهش ۷۰٪ زمان طراحی
Synced Patterns الگوهای همگام‌شده در کل سایت به‌روزرسانی یکجا
Block Bindings اتصال بلوک‌ها به فیلدهای سفارشی داینامیک کردن محتوا
Block Hooks اتصال خودکار بلوک‌ها به موقعیت‌ها اتوماسیون طراحی
Block Variations ایجاد انواع مختلف از یک بلوک انعطاف‌پذیری بیشتر

۳.۲ ایجاد بلوک سفارشی در وردپرس ۶.۹

بلوک سفارشی مدرن با React و TypeScript:

// blocks/custom-hero/block.json
{
    'apiVersion': 3,
    'name': 'custom/hero',
    'title': 'Hero Section',
    'category': 'design',
    'icon': 'cover-image',
    'description': 'A modern hero section block',
    'keywords': ['hero', 'banner', 'header'],
    'version': '1.0.0',
    'supports': {
        'align': ['wide', 'full'],
        'anchor': true,
        'customClassName': true,
        'html': false,
        'reusable': true
    },
    'attributes': {
        'title': {
            'type': 'string',
            'source': 'html',
            'selector': 'h1'
        },
        'subtitle': {
            'type': 'string',
            'source': 'html',
            'selector': 'p'
        },
        'backgroundImage': {
            'type': 'object',
            'default': {
                'id': 0,
                'url': '',
                'alt': ''
            }
        },
        'overlayColor': {
            'type': 'string',
            'default': 'rgba(0,0,0,0.5)'
        },
        'ctaText': {
            'type': 'string',
            'default': 'Learn More'
        },
        'ctaLink': {
            'type': 'string',
            'default': '#'
        }
    },
    'editorScript': 'file:./build/index.js',
    'editorStyle': 'file:./build/index.css',
    'style': 'file:./build/style-index.css'
}

کامپوننت React بلوک:

// blocks/custom-hero/edit.js
import { __ } from '@wordpress/i18n';
import { 
    useBlockProps, 
    InspectorControls,
    MediaUpload,
    RichText 
} from '@wordpress/block-editor';
import {
    PanelBody,
    TextControl,
    ColorPalette,
    Button
} from '@wordpress/components';

const Edit = ({ attributes, setAttributes }) => {
    const {
        title,
        subtitle,
        backgroundImage,
        overlayColor,
        ctaText,
        ctaLink
    } = attributes;

    const blockProps = useBlockProps({
        className: 'custom-hero-block'
    });

    return (
        <div {...blockProps}>
            <InspectorControls>
                <PanelBody title={__('Hero Settings')}>
                    <MediaUpload
                        onSelect={(media) => 
                            setAttributes({
                                backgroundImage: {
                                    id: media.id,
                                    url: media.url,
                                    alt: media.alt
                                }
                            })
                        }
                        type='image'
                        value={backgroundImage.id}
                        render={({ open }) => (
                            <Button onClick={open}>
                                {backgroundImage.url 
                                    ? __('Change Image') 
                                    : __('Select Image')
                                }
                            </Button>
                        )}
                    />
                    <ColorPalette
                        value={overlayColor}
                        onChange={(color) => 
                            setAttributes({ overlayColor: color })
                        }
                    />
                </PanelBody>
            </InspectorControls>

            <div 
                className='hero-background'
                style={{
                    backgroundImage: `url(${backgroundImage.url})`,
                    backgroundSize: 'cover',
                    backgroundPosition: 'center',
                    position: 'relative'
                }}
            >
                <div 
                    className='hero-overlay'
                    style={{ backgroundColor: overlayColor }}
                />
                <div className='hero-content'>
                    <RichText
                        tagName='h1'
                        value={title}
                        onChange={(value) => 
                            setAttributes({ title: value })
                        }
                        placeholder={__('Enter title...')}
                        className='hero-title'
                    />
                    <RichText
                        tagName='p'
                        value={subtitle}
                        onChange={(value) => 
                            setAttributes({ subtitle: value })
                        }
                        placeholder={__('Enter subtitle...')}
                        className='hero-subtitle'
                    />
                    <a 
                        href={ctaLink} 
                        className='hero-cta-button'
                    >
                        {ctaText}
                    </a>
                </div>
            </div>
        </div>
    );
};

export default Edit;

فصل چهارم: Full Site Editing (FSE) کامل

۴.۱ Template Parts و Site Editor پیشرفته

ویژگی‌های جدید FSE در وردپرس ۶.۹:

Global Styles 2.0

مدیریت استایل‌های سراسری با پیش‌نمایش زنده

// theme.json پیشرفته
{
    'version': 3,
    'settings': {
        'color': {
            'palette': [
                {
                    'name': 'Primary',
                    'slug': 'primary',
                    'color': '#3a86ff'
                }
            ],
            'gradients': [],
            'custom': true
        },
        'typography': {
            'fontFamilies': [
                {
                    'name': 'Vazirmatn',
                    'slug': 'vazirmatn',
                    'fontFamily': 'Vazirmatn, sans-serif'
                }
            ]
        }
    },
    'styles': {
        'color': {
            'background': 'var(--wp--preset--color--primary)'
        },
        'typography': {
            'fontFamily': 'var(--wp--preset--font-family--vazirmatn)',
            'fontSize': 'var(--wp--preset--font-size--medium)'
        }
    },
    'customTemplates': [
        {
            'name': 'custom-home',
            'title': 'Custom Home',
            'postTypes': ['page']
        }
    ]
}
Block Patterns Directory

دایرکتوری آنلاین الگوهای آماده

// ثبت Pattern در functions.php
register_block_pattern(
    'custom/hero-pattern',
    [
        'title' => __('Modern Hero', 'textdomain'),
        'categories' => ['hero', 'header'],
        'content' => '<!-- wp:cover {'url':'...'} -->
                      <div class='wp-block-cover'>
                        <span aria-hidden='true'></span>
                        <div class='wp-block-cover__inner-container'>
                          <!-- wp:heading -->
                          <h2>Welcome</h2>
                          <!-- /wp:heading -->
                        </div>
                      </div>
                      <!-- /wp:cover -->',
        'description' => __('A modern hero section', 'textdomain'),
        'keywords' => ['hero', 'banner', 'welcome'],
        'viewportWidth' => 1200
    ]
);

۴.۲ Block Themes کامل

ساختار کامل یک قالب Block-Based:

theme-folder/
├── style.css                  # اطلاعات قالب
├── theme.json                # تنظیمات FSE
├── functions.php             # توابع PHP
├── index.php                 # فایل اصلی
├── templates/                # تمپلیت‌ها
│   ├── index.html           # صفحه اصلی
│   ├── single.html          # صفحه تکی
│   ├── page.html            # صفحه
│   ├── archive.html         # آرشیو
│   └── 404.html             # خطای 404
├── parts/                    # بخش‌های تمپلیت
│   ├── header.html          # هدر
│   ├── footer.html          # فوتر
│   └── sidebar.html         # نوار کناری
├── patterns/                 # الگوهای بلوک
│   ├── hero-pattern.html    # الگوی Hero
│   ├── features-pattern.html # الگوی ویژگی‌ها
│   └── cta-pattern.html     # الگوی CTA
├── assets/                   # فایل‌های استاتیک
│   ├── css/                 # استایل‌ها
│   ├── js/                  # اسکریپت‌ها
│   └── images/              # تصاویر
└── blocks/                  # بلوک‌های سفارشی
    └── custom-hero/         # بلوک Hero سفارشی

فصل پنجم: امنیت پیشرفته در وردپرس ۶.۹

۵.۱ ویژگی‌های امنیتی جدید

ویژگی امنیتی توضیح مزیت
Content Security Policy (CSP) پیش‌فرض در هسته وردپرس جلوگیری از XSS
Two-Factor Authentication احراز هویت دو مرحله‌ای پیش‌فرض امنیت لاگین
Rate Limiting محدودیت درخواست‌های API جلوگیری از Brute Force
Security Headers هدرهای امنیتی پیشرفته امنیت مرورگر
Malware Scanning اسکن خودکار فایل‌ها شناسایی بدافزار

۵.۲ راهنمای امنیت کامل

✅ چک‌لیست امنیت وردپرس ۶.۹:

۱. پیکربندی سرور
  • PHP 8.3+ با OPcache
  • MySQL 8.0+ یا MariaDB 10.6+
  • HTTPS با TLS 1.3
  • فایروال Web Application (WAF)
  • محدودیت دسترسی به فایل‌ها
۲. پیکربندی وردپرس
  • تغییر پیشوند دیتابیس (wp_ → custom_)
  • غیرفعال کردن File Editor
  • محدود کردن Login Attempts
  • فعال‌سازی Audit Logging
  • پیکربندی wp-config.php امن
۳. پلاگین‌های امنیتی
  • Wordfence Security
  • Sucuri Security
  • iThemes Security
  • WP Activity Log
  • All In One WP Security

فصل ششم: عملکرد و بهینه‌سازی

۶.۱ بهبودهای عملکردی وردپرس ۶.۹

بهبود نسخه قبلی وردپرس ۶.۹ بهبود
زمان لود صفحه ۲.۸ ثانیه ۱.۲ ثانیه ۵۷٪ ⬆
مصرف حافظه ۶۴MB ۳۲MB ۵۰٪ ⬇
Query های دیتابیس ۷۸ ۳۲ ۵۹٪ ⬇
حجم صفحه ۲.۱MB ۱.۲MB ۴۳٪ ⬇
Score Lighthouse ۷۲ ۹۵ ۳۲٪ ⬆

۶.۲ تکنیک‌های بهینه‌سازی پیشرفته

کدهای بهینه‌سازی:

Object Caching با Redis:
// wp-config.php
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_REDIS_TIMEOUT', 1);
define('WP_REDIS_READ_TIMEOUT', 1);
define('WP_REDIS_DATABASE', 0);

// نصب پلاگین Redis Object Cache
// یا استفاده از Memcached
define('WP_CACHE_KEY_SALT', 'your_unique_salt_here');

// کش کردن کوئری‌های سفارشی
function get_cached_posts() {
    $cache_key = 'cached_posts_' . md5(serialize(func_get_args()));
    $cached = wp_cache_get($cache_key, 'my_cache_group');
    
    if ($cached !== false) {
        return $cached;
    }
    
    $posts = get_posts([
        'post_type' => 'post',
        'posts_per_page' => 10,
        'orderby' => 'date',
        'order' => 'DESC'
    ]);
    
    wp_cache_set($cache_key, $posts, 'my_cache_group', 3600);
    return $posts;
}
Lazy Loading پیشرفته:
// functions.php
add_filter('wp_lazy_loading_enabled', '__return_true');

// Lazy Load برای iframe و video
add_filter('wp_lazy_loading_attrs', function($attr, $tag_name) {
    if ('iframe' === $tag_name || 'video' === $tag_name) {
        $attr['loading'] = 'lazy';
        $attr['decoding'] = 'async';
    }
    return $attr;
}, 10, 2);

// WebP و Image Optimization
add_filter('wp_image_editors', function($editors) {
    if (class_exists('Imagick') && Imagick::queryFormats('WEBP')) {
        array_unshift($editors, 'WP_Image_Editor_Imagick');
    }
    return $editors;
});

// Critical CSS Injection
function add_critical_css() {
    ?>
    <style>
        /* Above-the-fold styles */
        .hero, .navigation, .header {
            opacity: 0;
            animation: fadeIn 0.3s ease forwards;
        }
        @keyframes fadeIn {
            to { opacity: 1; }
        }
    </style>
    <noscript>
        <link rel='stylesheet' href='<?php echo get_template_directory_uri(); ?>/assets/css/noscript.css'>
    </noscript>
    <?php
}
add_action('wp_head', 'add_critical_css', 1);

فصل هفتم: توسعه پلاگین مدرن

۷.۱ ساختار پلاگین وردپرس ۶.۹

ساختار پلاگین مدرن:

my-advanced-plugin/
├── my-advanced-plugin.php      # فایل اصلی
├── composer.json               # مدیریت وابستگی‌ها
├── package.json                # مدیریت assets
├── webpack.config.js           # bundle کردن
├── .eslintrc.js                # کد استاندارد
├── phpcs.xml                   # استاندارد PHP
├── src/                        # کدهای PHP
│   ├── Admin/                  # بخش مدیریت
│   ├── Api/                    # REST API
│   ├── Blocks/                 # بلوک‌های سفارشی
│   ├── Database/               # مدل‌های دیتابیس
│   ├── Frontend/               # بخش frontend
│   └── Utilities/              # ابزارهای کمکی
├── assets/                     # فایل‌های استاتیک
│   ├── css/                    # استایل‌ها
│   ├── js/                     # اسکریپت‌ها
│   └── images/                 # تصاویر
├── includes/                   # فایل‌های قدیمی (برای سازگاری)
├── languages/                  # فایل‌های ترجمه
├── tests/                      # تست‌ها
│   ├── Unit/                   # Unit Tests
│   └── Integration/            # Integration Tests
└── vendor/                     # وابستگی‌های Composer

۷.۲ نمونه پلاگین مدرن

پلاگین Product Manager با معماری MVC:

// my-advanced-plugin.php
<?php
/**
 * Plugin Name: Advanced Product Manager
 * Plugin URI: https://treec.net/plugins/product-manager
 * Description: Modern product management system for WordPress
 * Version: 1.0.0
 * Author: Mohammad Mahdi Mahmoudi
 * License: GPL v2 or later
 * Text Domain: advanced-product-manager
 */

// جلوگیری از دسترسی مستقیم
defined('ABSPATH') || exit;

// تعریف ثابت‌ها
define('APM_VERSION', '1.0.0');
define('APM_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('APM_PLUGIN_URL', plugin_dir_url(__FILE__));
define('APM_ASSETS_URL', APM_PLUGIN_URL . 'assets/');

// Autoloader با Composer
require_once APM_PLUGIN_DIR . 'vendor/autoload.php';

// فعال‌سازی پلاگین
register_activation_hook(__FILE__, ['APM\Activator', 'activate']);
register_deactivation_hook(__FILE__, ['APM\Deactivator', 'deactivate']);

// راه‌اندازی پلاگین
add_action('plugins_loaded', function() {
    // بارگذاری textdomain
    load_plugin_textdomain(
        'advanced-product-manager',
        false,
        dirname(plugin_basename(__FILE__)) . '/languages'
    );
    
    // راه‌اندازی Kernel
    $kernel = new APMCoreKernel();
    $kernel->boot();
    
    // راه‌اندازی Admin
    if (is_admin()) {
        $admin = new APMAdminAdminController();
        $admin->init();
    }
    
    // راه‌اندازی REST API
    add_action('rest_api_init', function() {
        $api = new APMApiProductApi();
        $api->register_routes();
    });
    
    // راه‌اندازی Blocks
    add_action('init', function() {
        $blocks = new APMBlocksBlockManager();
        $blocks->register_blocks();
    });
});

// تعریف Custom Post Type
add_action('init', function() {
    register_post_type('product', [
        'labels' => [
            'name' => __('Products', 'advanced-product-manager'),
            'singular_name' => __('Product', 'advanced-product-manager'),
            'menu_name' => __('Products', 'advanced-product-manager'),
            'add_new' => __('Add New', 'advanced-product-manager'),
            'add_new_item' => __('Add New Product', 'advanced-product-manager'),
            'edit_item' => __('Edit Product', 'advanced-product-manager'),
            'new_item' => __('New Product', 'advanced-product-manager'),
            'view_item' => __('View Product', 'advanced-product-manager'),
            'search_items' => __('Search Products', 'advanced-product-manager'),
            'not_found' => __('No products found', 'advanced-product-manager'),
            'not_found_in_trash' => __('No products found in trash', 'advanced-product-manager'),
        ],
        'public' => true,
        'has_archive' => true,
        'rewrite' => ['slug' => 'products'],
        'supports' => ['title', 'editor', 'thumbnail', 'excerpt', 'custom-fields'],
        'show_in_rest' => true,
        'menu_icon' => 'dashicons-products',
        'taxonomies' => ['product_category', 'product_tag'],
    ]);
    
    // تعریف Custom Taxonomies
    register_taxonomy('product_category', ['product'], [
        'labels' => [
            'name' => __('Product Categories', 'advanced-product-manager'),
            'singular_name' => __('Product Category', 'advanced-product-manager'),
        ],
        'public' => true,
        'hierarchical' => true,
        'show_in_rest' => true,
        'rewrite' => ['slug' => 'product-category'],
    ]);
    
    register_taxonomy('product_tag', ['product'], [
        'labels' => [
            'name' => __('Product Tags', 'advanced-product-manager'),
            'singular_name' => __('Product Tag', 'advanced-product-manager'),
        ],
        'public' => true,
        'hierarchical' => false,
        'show_in_rest' => true,
        'rewrite' => ['slug' => 'product-tag'],
    ]);
});

// افزودن metabox پیشرفته
add_action('add_meta_boxes', function() {
    add_meta_box(
        'product_details',
        __('Product Details', 'advanced-product-manager'),
        function($post) {
            wp_nonce_field('product_details_nonce', 'product_details_nonce_field');
            
            $price = get_post_meta($post->ID, '_product_price', true);
            $sku = get_post_meta($post->ID, '_product_sku', true);
            $stock = get_post_meta($post->ID, '_product_stock', true);
            
            ?>
            <div class='apm-metabox'>
                <div class='apm-field'>
                    <label for='product_price'>
                        <?php _e('Price', 'advanced-product-manager'); ?>
                    </label>
                    <input 
                        type='number' 
                        id='product_price' 
                        name='product_price' 
                        value='<?php echo esc_attr($price); ?>' 
                        step='0.01' 
                        min='0'
                    />
                </div>
                
                <div class='apm-field'>
                    <label for='product_sku'>
                        <?php _e('SKU', 'advanced-product-manager'); ?>
                    </label>
                    <input 
                        type='text' 
                        id='product_sku' 
                        name='product_sku' 
                        value='<?php echo esc_attr($sku); ?>'
                    />
                </div>
                
                <div class='apm-field'>
                    <label for='product_stock'>
                        <?php _e('Stock Quantity', 'advanced-product-manager'); ?>
                    </label>
                    <input 
                        type='number' 
                        id='product_stock' 
                        name='product_stock' 
                        value='<?php echo esc_attr($stock); ?>' 
                        min='0'
                    />
                </div>
            </div>
            
            <style>
                .apm-metabox {
                    padding: 15px;
                }
                .apm-field {
                    margin-bottom: 15px;
                }
                .apm-field label {
                    display: block;
                    margin-bottom: 5px;
                    font-weight: 600;
                }
                .apm-field input {
                    width: 100%;
                    padding: 8px;
                    border: 1px solid #ddd;
                    border-radius: 4px;
                }
            </style>
            <?php
        },
        'product',
        'normal',
        'high'
    );
});

// ذخیره metabox داده‌ها
add_action('save_post', function($post_id) {
    // بررسی nonce
    if (!isset($_POST['product_details_nonce_field']) || 
        !wp_verify_nonce($_POST['product_details_nonce_field'], 'product_details_nonce')) {
        return;
    }
    
    // بررسی autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    
    // بررسی permissions
    if (!current_user_can('edit_post', $post_id)) {
        return;
    }
    
    // ذخیره فیلدها
    $fields = ['product_price', 'product_sku', 'product_stock'];
    
    foreach ($fields as $field) {
        if (isset($_POST[$field])) {
            update_post_meta(
                $post_id,
                '_' . $field,
                sanitize_text_field($_POST[$field])
            );
        }
    }
});

فصل هشتم: REST API و Headless WordPress

۸.۱ REST API v3 در وردپرس ۶.۹

ویژگی‌های جدید REST API:

Endpoint سفارشی پیشرفته:
// ایجاد REST API سفارشی
add_action('rest_api_init', function() {
    // Register Custom Endpoint
    register_rest_route('apm/v1', '/products/(?P<id>d+)', [
        [
            'methods' => WP_REST_Server::READABLE,
            'callback' => function($request) {
                $product_id = $request->get_param('id');
                $product = get_post($product_id);
                
                if (!$product || $product->post_type !== 'product') {
                    return new WP_Error(
                        'product_not_found',
                        __('Product not found', 'advanced-product-manager'),
                        ['status' => 404]
                    );
                }
                
                // ساخت response پیشرفته
                $response = [
                    'id' => $product->ID,
                    'title' => $product->post_title,
                    'content' => apply_filters('the_content', $product->post_content),
                    'excerpt' => $product->post_excerpt,
                    'slug' => $product->post_name,
                    'date' => $product->post_date,
                    'modified' => $product->post_modified,
                    'status' => $product->post_status,
                    'meta' => [
                        'price' => get_post_meta($product->ID, '_product_price', true),
                        'sku' => get_post_meta($product->ID, '_product_sku', true),
                        'stock' => get_post_meta($product->ID, '_product_stock', true),
                    ],
                    'featured_image' => get_the_post_thumbnail_url($product->ID, 'full'),
                    'categories' => wp_get_post_terms($product->ID, 'product_category', ['fields' => 'names']),
                    'tags' => wp_get_post_terms($product->ID, 'product_tag', ['fields' => 'names']),
                    '_links' => [
                        'self' => [
                            'href' => rest_url('apm/v1/products/' . $product->ID)
                        ],
                        'collection' => [
                            'href' => rest_url('apm/v1/products')
                        ]
                    ]
                ];
                
                return rest_ensure_response($response);
            },
            'permission_callback' => function() {
                return current_user_can('read');
            },
            'args' => [
                'id' => [
                    'validate_callback' => function($param) {
                        return is_numeric($param);
                    },
                    'required' => true,
                    'description' => __('Product ID', 'advanced-product-manager'),
                ]
            ]
        ],
        [
            'methods' => WP_REST_Server::EDITABLE,
            'callback' => function($request) {
                // Update product logic
                $product_id = $request->get_param('id');
                $data = $request->get_json_params();
                
                // اعتبارسنجی داده‌ها
                if (!current_user_can('edit_post', $product_id)) {
                    return new WP_Error(
                        'forbidden',
                        __('You are not allowed to edit this product', 'advanced-product-manager'),
                        ['status' => 403]
                    );
                }
                
                // به‌روزرسانی محصول
                $updated = wp_update_post([
                    'ID' => $product_id,
                    'post_title' => sanitize_text_field($data['title'] ?? ''),
                    'post_content' => wp_kses_post($data['content'] ?? ''),
                ]);
                
                if (is_wp_error($updated)) {
                    return $updated;
                }
                
                // به‌روزرسانی meta fields
                if (isset($data['meta'])) {
                    foreach ($data['meta'] as $key => $value) {
                        update_post_meta($product_id, '_' . $key, sanitize_text_field($value));
                    }
                }
                
                return rest_ensure_response([
                    'success' => true,
                    'message' => __('Product updated successfully', 'advanced-product-manager'),
                    'data' => [
                        'id' => $product_id,
                        'updated' => current_time('mysql'),
                    ]
                ]);
            },
            'permission_callback' => function() {
                return current_user_can('edit_posts');
            }
        ]
    ]);
    
    // Endpoint برای فیلتر و جستجو
    register_rest_route('apm/v1', '/products', [
        'methods' => WP_REST_Server::READABLE,
        'callback' => function($request) {
            $params = $request->get_params();
            
            // پارامترهای جستجو
            $args = [
                'post_type' => 'product',
                'post_status' => 'publish',
                'posts_per_page' => $params['per_page'] ?? 10,
                'paged' => $params['page'] ?? 1,
            ];
            
            // فیلتر بر اساس دسته‌بندی
            if (!empty($params['category'])) {
                $args['tax_query'] = [
                    [
                        'taxonomy' => 'product_category',
                        'field' => 'slug',
                        'terms' => sanitize_text_field($params['category']),
                    ]
                ];
            }
            
            // فیلتر بر اساس برچسب
            if (!empty($params['tag'])) {
                $args['tag'] = sanitize_text_field($params['tag']);
            }
            
            // جستجوی متن
            if (!empty($params['search'])) {
                $args['s'] = sanitize_text_field($params['search']);
            }
            
            // مرتب‌سازی
            if (!empty($params['orderby'])) {
                $args['orderby'] = sanitize_text_field($params['orderby']);
                $args['order'] = $params['order'] ?? 'DESC';
            }
            
            // فیلتر قیمت
            if (!empty($params['min_price']) || !empty($params['max_price'])) {
                $meta_query = ['relation' => 'AND'];
                
                if (!empty($params['min_price'])) {
                    $meta_query[] = [
                        'key' => '_product_price',
                        'value' => floatval($params['min_price']),
                        'compare' => '>=',
                        'type' => 'NUMERIC'
                    ];
                }
                
                if (!empty($params['max_price'])) {
                    $meta_query[] = [
                        'key' => '_product_price',
                        'value' => floatval($params['max_price']),
                        'compare' => '<=',
                        'type' => 'NUMERIC'
                    ];
                }
                
                $args['meta_query'] = $meta_query;
            }
            
            // اجرای query
            $query = new WP_Query($args);
            $products = [];
            
            if ($query->have_posts()) {
                while ($query->have_posts()) {
                    $query->the_post();
                    global $post;
                    
                    $products[] = [
                        'id' => $post->ID,
                        'title' => get_the_title(),
                        'excerpt' => get_the_excerpt(),
                        'price' => get_post_meta($post->ID, '_product_price', true),
                        'image' => get_the_post_thumbnail_url($post->ID, 'medium'),
                        'link' => get_permalink(),
                    ];
                }
                wp_reset_postdata();
            }
            
            // ساخت response با pagination
            $response = [
                'data' => $products,
                'pagination' => [
                    'total' => $query->found_posts,
                    'per_page' => $args['posts_per_page'],
                    'current_page' => $args['paged'],
                    'total_pages' => ceil($query->found_posts / $args['posts_per_page']),
                ],
                '_links' => [
                    'self' => [
                        'href' => rest_url('apm/v1/products') . '?' . http_build_query($params)
                    ]
                ]
            ];
            
            return rest_ensure_response($response);
        },
        'permission_callback' => '__return_true',
        'args' => [
            'per_page' => [
                'default' => 10,
                'validate_callback' => function($param) {
                    return is_numeric($param) && $param > 0 && $param <= 100;
                }
            ],
            'page' => [
                'default' => 1,
                'validate_callback' => function($param) {
                    return is_numeric($param) && $param > 0;
                }
            ],
            'search' => [
                'sanitize_callback' => 'sanitize_text_field'
            ],
            'category' => [
                'sanitize_callback' => 'sanitize_text_field'
            ],
            'tag' => [
                'sanitize_callback' => 'sanitize_text_field'
            ],
            'min_price' => [
                'sanitize_callback' => 'floatval'
            ],
            'max_price' => [
                'sanitize_callback' => 'floatval'
            ],
        ]
    ]);
});

۸.۲ Headless WordPress با Next.js

نمونه Headless WordPress با Next.js 14:

فایل Next.js برای نمایش محصولات:
// app/products/page.jsx
import { getProducts } from '@/lib/wordpress';
import ProductCard from '@/components/ProductCard';
import Pagination from '@/components/Pagination';
import SearchFilters from '@/components/SearchFilters';

export default async function ProductsPage({ searchParams }) {
    const { data, pagination } = await getProducts(searchParams);
    
    return (
        <div className='container mx-auto px-4 py-8'>
            <h1 className='text-4xl font-bold mb-8 text-center'>
                محصولات ما
            </h1>
            
            {/* فیلترهای جستجو */}
            <SearchFilters />
            
            {/* لیست محصولات */}
            {data.length > 0 ? (
                <div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6'>
                    {data.map((product) => (
                        <ProductCard 
                            key={product.id} 
                            product={product} 
                        />
                    ))}
                </div>
            ) : (
                <div className='text-center py-12'>
                    <h3 className='text-2xl font-semibold text-gray-600'>
                        محصولی یافت نشد
                    </h3>
                </div>
            )}
            
            {/* Pagination */}
            <Pagination pagination={pagination} />
        </div>
    );
}

// lib/wordpress.js
const WORDPRESS_URL = process.env.WORDPRESS_URL;
const WORDPRESS_API = `${WORDPRESS_URL}/wp-json`;

export async function getProducts(params = {}) {
    const queryString = new URLSearchParams(params).toString();
    const url = `${WORDPRESS_API}/apm/v1/products?${queryString}`;
    
    try {
        const response = await fetch(url, {
            next: { 
                revalidate: 60, // ISR: هر ۶۰ ثانیه
                tags: ['products'] 
            }
        });
        
        if (!response.ok) {
            throw new Error('Failed to fetch products');
        }
        
        return await response.json();
    } catch (error) {
        console.error('Error fetching products:', error);
        return { data: [], pagination: {} };
    }
}

export async function getProduct(id) {
    const url = `${WORDPRESS_API}/apm/v1/products/${id}`;
    
    try {
        const response = await fetch(url, {
            next: { revalidate: 3600 } // هر ساعت
        });
        
        if (!response.ok) {
            throw new Error('Failed to fetch product');
        }
        
        return await response.json();
    } catch (error) {
        console.error('Error fetching product:', error);
        return null;
    }
}

// components/ProductCard.jsx
export default function ProductCard({ product }) {
    return (
        <div className='bg-white rounded-lg shadow-lg overflow-hidden hover:shadow-xl transition-shadow duration-300'>
            {/* تصویر محصول */}
            <div className='relative h-64 overflow-hidden'>
                {product.image ? (
                    <img 
                        src={product.image} 
                        alt={product.title}
                        className='w-full h-full object-cover hover:scale-105 transition-transform duration-300'
                        loading='lazy'
                    />
                ) : (
                    <div className='w-full h-full bg-gray-200 flex items-center justify-center'>
                        <span className='text-gray-400'>بدون تصویر</span>
                    </div>
                )}
                
                {/* قیمت */}
                {product.price && (
                    <div className='absolute top-4 right-4 bg-blue-600 text-white px-3 py-1 rounded-full font-bold'>
                        {Number(product.price).toLocaleString('fa-IR')} تومان
                    </div>
                )}
            </div>
            
            {/* اطلاعات محصول */}
            <div className='p-6'>
                <h3 className='text-xl font-semibold mb-2 line-clamp-2'>
                    {product.title}
                </h3>
                
                <p className='text-gray-600 mb-4 line-clamp-3'>
                    {product.excerpt}
                </p>
                
                {/* دکمه مشاهده */}
                <a 
                    href={`/products/${product.id}`}
                    className='inline-block w-full bg-blue-500 text-white text-center py-2 rounded-lg hover:bg-blue-600 transition-colors duration-300'
                >
                    مشاهده جزئیات
                </a>
            </div>
        </div>
    );
}

فصل نهم: بازار کار و آینده وردپرس

۹.۱ تحلیل بازار کار ایران در ۲۰۲۶

موقعیت شغلی متوسط حقوق (میلیون تومان) تقاضا مهارت‌های مورد نیاز
توسعه‌دهنده وردپرس ارشد ۵۰-۸۰ ⭐⭐⭐⭐⭐ وردپرس ۶.۹، PHP، React، WooCommerce
طراح قالب وردپرس ۴۰-۶۰ ⭐⭐⭐⭐ Block Themes، JavaScript، CSS، طراحی UI/UX
متخصص WooCommerce ۵۵-۸۵ ⭐⭐⭐⭐⭐ WooCommerce، پرداخت آنلاین، بهینه‌سازی
کارشناس سئوی وردپرس ۳۵-۵۵ ⭐⭐⭐⭐ سئو تکنیکال، سرعت سایت، محتوا
مدیر پروژه وردپرس ۴۵-۷۰ ⭐⭐⭐ مدیریت پروژه، تیم، مشتری

۹.۲ پیش‌بینی آینده وردپرس

روندهای آینده وردپرس:

۲۰۲۶-۲۰۲۷: هوش مصنوعی در وردپرس

یکپارچگی کامل با AI برای تولید محتوا، بهینه‌سازی سئو و طراحی خودکار

۲۰۲۸-۲۰۲۹: وردپرس بدون سرور

معماری Serverless کامل با Edge Computing و CDN پیشرفته

۲۰۳۰: پلتفرم جامع دیجیتال

ترکیب CMS، E-commerce، LMS و CRM در یک پلتفرم

فصل دهم: نتیجه‌گیری و راهنمای عملی

چرا وردپرس ۶.۹؟

✅ برای مبتدیان:

  • نصب ۵ دقیقه‌ای
  • رابط کاربری ساده
  • هزاران قالب و پلاگین رایگان
  • جامعه بزرگ فارسی

💼 برای کسب‌وکارها:

  • هزینه توسعه پایین
  • زمان راه‌اندازی سریع
  • قابلیت گسترش بی‌نهایت
  • امنیت و پایداری

🚀 برای توسعه‌دهندگان:

  • اکوسیستم عظیم
  • مستندات کامل
  • بازار کار پررونق
  • درآمد بالا

🎯 راهنمای شروع سریع:

  1. نصب وردپرس ۶.۹: wp core download --version=6.9
  2. آموزش رایگان: دوره وردپرس درخت کد
  3. قالب رایگان: قالب‌های درخت کد
  4. پلاگین ضروری: پلاگین‌های درخت کد
  5. جامعه فارسی: گروه تلگرام وردپرس ایران

وردپرس ۶.۹ تنها یک سیستم مدیریت محتوا نیست، بلکه یک اکوسیستم کامل برای ساخت هر نوع وبسایت است. از یک وبلاگ شخصی تا یک پلتفرم سازمانی بزرگ، وردپرس پاسخگوی همه نیازهاست.

در درخت کد، ما همراه شما هستیم تا با آموزش‌های تخصصی، قالب‌های حرفه‌ای، پلاگین‌های کاربردی و خدمات توسعه، بهترین تجربه وردپرس را داشته باشید.

با آرزوی موفقیت در دنیای وردپرس،

محمدمهدی محمودی
بنیانگذار و مدرس ارشد درخت کد
treec.net | mohammadmahdimahmoudi.ir