استوری

نمایش استوری‌های ویدیویی آپارات به‌صورت دایره‌ای با قابلیت پخش، جابجایی بین استوری‌ها و لینک‌دهی به محصولات یا نوشته‌ها با شورت‌کد [aparat_stories].

استوری آپارات با شورت‌کد [aparat_stories]

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

<?php
add_action('admin_menu', 'asp_add_admin_menu');
function asp_add_admin_menu() {
    add_menu_page(
        'تنظیمات استوری آپارات',
        'استوری آپارات',
        'manage_options',
        'aparat-stories',
        'asp_settings_page',
        'dashicons-format-video',
        25
    );
}

function asp_settings_page() {
    if (!current_user_can('manage_options')) return;
    if (isset($_POST['asp_save_settings'])) {
        check_admin_referer('asp_save_settings_action', 'asp_nonce');
        $raw_data = isset($_POST['asp_data']) && is_array($_POST['asp_data']) ? $_POST['asp_data'] : [];
        $clean_data = [];
        foreach ($raw_data as $row) {
            $title = isset($row['title']) ? sanitize_text_field($row['title']) : '';
            $link  = isset($row['link']) ? esc_url_raw(trim($row['link'])) : '';
            $item_title = isset($row['item_title']) ? sanitize_text_field($row['item_title']) : '';
            $item_link  = isset($row['item_link']) ? esc_url_raw(trim($row['item_link'])) : '';
            if ($title === '' && $link === '' && $item_title === '' && $item_link === '') {
                continue;
            }
            $clean_data[] = [
                'title'      => $title,
                'link'       => $link,
                'item_title' => $item_title,
                'item_link'  => $item_link,
            ];
        }
        update_option('asp_aparat_data', array_values($clean_data));
        echo '<div class="updated"><p>تنظیمات استوری با موفقیت ذخیره شد.</p></div>';
    }
    $data = get_option('asp_aparat_data', []);
    if (!is_array($data)) $data = [];
    if (empty($data)) {
        $data[] = [
            'title'      => '',
            'link'       => '',
            'item_title' => '',
            'item_link'  => '',
        ];
    }
    ?>
    <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cstyle%3E%0A%20%20%20%20%20%20%20%20.asp-rows%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3A%20flex%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20flex-direction%3A%20column%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20gap%3A%205px%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-row%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20background%3A%20%23fff%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border%3A%201px%20solid%20%23e5e7eb%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border-radius%3A%2010px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding%3A%2010px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3A%20grid%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20grid-template-columns%3A%2050px%201fr%201fr%201fr%201fr%20100px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20gap%3A%2010px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20align-items%3A%20start%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-row.dragging%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20opacity%3A%20.55%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border-color%3A%20%232271b1%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20background%3A%20%23f8fbff%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-col%20label%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3A%20block%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-input%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20width%3A%20100%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding%3A%2010px%2012px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border%3A%201px%20solid%20%23cfd4d9%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border-radius%3A%208px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-size%3A%2014px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20background%3A%20%23fff%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20box-sizing%3A%20border-box%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-input%3Afocus%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20outline%3A%20none%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border-color%3A%20%232271b1%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20box-shadow%3A%200%200%200%201px%20%232271b1%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-url%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20direction%3A%20ltr%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20text-align%3A%20left%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-row-no%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3A%20flex%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20align-items%3A%20center%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20justify-content%3A%20center%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-weight%3A%20700%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-actions%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3A%20flex%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20gap%3A%205px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20align-items%3A%20center%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-drag%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-size%3A%2020px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20justify-content%3A%20center%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-drag%3Aactive%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20cursor%3A%20grabbing%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-remove%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-size%3A%2012px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20justify-content%3A%20center%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-admin-actions%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding-top%3A%2010px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3A%20flex%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20gap%3A%2010px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20flex-wrap%3A%20wrap%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%40media%20(max-width%3A%201100px)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-row%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20grid-template-columns%3A%2050px%201fr%201fr%20100px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%40media%20(max-width%3A%20782px)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-row%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20grid-template-columns%3A%201fr%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-row-no%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-actions%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20margin-top%3A%200%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-actions%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20justify-content%3A%20flex-start%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%3C%2Fstyle%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object mce-object-style" width="20" height="20" alt="&lt;style&gt;" />
    <div class="wrap">
            <form method="post" id="asp-admin-form">
                <?php wp_nonce_field('asp_save_settings_action', 'asp_nonce'); ?>
                    <div class="asp-rows" id="asp-rows">
                        <?php foreach ($data as $i => $row): ?>
                            <div class="asp-row" draggable="true">
                                <div class="asp-row-no"><?php echo esc_html($i + 1); ?></div>
                                <div class="asp-col">
                                    <input type="text" name="asp_data[<?php echo esc_attr($i); ?>][title]" value="<?php echo esc_attr($row['title'] ?? ''); ?>" class="asp-input">
                                </div>
                                <div class="asp-col">
                                    <input type="text" name="asp_data[<?php echo esc_attr($i); ?>][link]" value="<?php echo esc_attr($row['link'] ?? ''); ?>" class="asp-input asp-url">
                                </div>
                                <div class="asp-col">
                                    <input type="text" name="asp_data[<?php echo esc_attr($i); ?>][item_title]" value="<?php echo esc_attr($row['item_title'] ?? ''); ?>" class="asp-input">
                                </div>
                                <div class="asp-col">
                                    <input type="url" name="asp_data[<?php echo esc_attr($i); ?>][item_link]" value="<?php echo esc_attr($row['item_link'] ?? ''); ?>" class="asp-input asp-url">
                                </div>
                                <div class="asp-actions">
                                    <div class="asp-drag" title="جابجایی">☰</div>
                                    <button type="button" class="asp-remove" title="حذف ردیف">حذف</button>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                <div class="asp-admin-actions">
                    <button type="button" class="button" id="asp-add-row">افزودن ردیف جدید</button>
                    <?php submit_button('ذخیره تنظیمات', 'primary', 'asp_save_settings', false); ?>
                </div>
            </form>
    </div>
    <template id="asp-row-template">
        <div class="asp-row" draggable="true">
            <div class="asp-row-no">1</div>
            <div class="asp-col">
                <input type="text" name="" class="asp-input asp-field-title" placeholder="عنوان استوری" >
            </div>
            <div class="asp-col">
                <input type="text" name="" class="asp-input asp-url asp-field-link" placeholder="لینک ویدیو یا هش آپارات" >
            </div>
            <div class="asp-col">
                <input type="text" name="" class="asp-input asp-field-item-title" placeholder="عنوان نوشته یا محصول" >
            </div>
            <div class="asp-col">
                <input type="url" name="" class="asp-input asp-url asp-field-item-link" placeholder="لینک نوشته یا محصول" >
            </div>
            <div class="asp-actions">
                <div class="asp-drag" title="جابجایی">☰</div>
                <button type="button" class="asp-remove" title="حذف ردیف">×</button>
            </div>
        </div>
    </template>
    <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%3E%0A%20%20%20%20(function()%7B%0A%20%20%20%20%20%20%20%20const%20rowsWrap%20%3D%20document.getElementById('asp-rows')%3B%0A%20%20%20%20%20%20%20%20const%20addBtn%20%3D%20document.getElementById('asp-add-row')%3B%0A%20%20%20%20%20%20%20%20const%20tpl%20%3D%20document.getElementById('asp-row-template')%3B%0A%20%20%20%20%20%20%20%20function%20refreshIndexes()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20rows%20%3D%20rowsWrap.querySelectorAll('.asp-row')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20rows.forEach((row%2C%20index)%20%3D%3E%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20no%20%3D%20row.querySelector('.asp-row-no')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(no)%20no.textContent%20%3D%20index%20%2B%201%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20title%20%3D%20row.querySelector('.asp-field-title')%20%7C%7C%20row.querySelector('input%5Bname*%3D%22%5Btitle%5D%22%5D')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20link%20%3D%20row.querySelector('.asp-field-link')%20%7C%7C%20row.querySelector('input%5Bname*%3D%22%5Blink%5D%22%5D%3Anot(%5Bname*%3D%22%5Bitem_link%5D%22%5D)')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20itemTitle%20%3D%20row.querySelector('.asp-field-item-title')%20%7C%7C%20row.querySelector('input%5Bname*%3D%22%5Bitem_title%5D%22%5D')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20itemLink%20%3D%20row.querySelector('.asp-field-item-link')%20%7C%7C%20row.querySelector('input%5Bname*%3D%22%5Bitem_link%5D%22%5D')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(title)%20title.name%20%3D%20'asp_data%5B'%20%2B%20index%20%2B%20'%5D%5Btitle%5D'%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(link)%20link.name%20%3D%20'asp_data%5B'%20%2B%20index%20%2B%20'%5D%5Blink%5D'%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(itemTitle)%20itemTitle.name%20%3D%20'asp_data%5B'%20%2B%20index%20%2B%20'%5D%5Bitem_title%5D'%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(itemLink)%20itemLink.name%20%3D%20'asp_data%5B'%20%2B%20index%20%2B%20'%5D%5Bitem_link%5D'%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20function%20bindRow(row)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20removeBtn%20%3D%20row.querySelector('.asp-remove')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(removeBtn)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20removeBtn.addEventListener('click'%2C%20function()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20rows%20%3D%20rowsWrap.querySelectorAll('.asp-row')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(rows.length%20%3C%3D%201)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20row.querySelectorAll('input').forEach(inp%20%3D%3E%20inp.value%20%3D%20'')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20row.remove()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20refreshIndexes()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20row.addEventListener('dragstart'%2C%20function()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20row.classList.add('dragging')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20row.addEventListener('dragend'%2C%20function()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20row.classList.remove('dragging')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20refreshIndexes()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20function%20getDragAfterElement(container%2C%20y)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20draggableElements%20%3D%20%5B...container.querySelectorAll('.asp-row%3Anot(.dragging)')%5D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20draggableElements.reduce((closest%2C%20child)%20%3D%3E%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20box%20%3D%20child.getBoundingClientRect()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20offset%20%3D%20y%20-%20box.top%20-%20box.height%20%2F%202%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(offset%20%3C%200%20%26%26%20offset%20%3E%20closest.offset)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20%7B%20offset%3A%20offset%2C%20element%3A%20child%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20closest%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%20%7B%20offset%3A%20Number.NEGATIVE_INFINITY%20%7D).element%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20rowsWrap.addEventListener('dragover'%2C%20function(e)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20e.preventDefault()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20dragging%20%3D%20rowsWrap.querySelector('.dragging')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(!dragging)%20return%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20afterElement%20%3D%20getDragAfterElement(rowsWrap%2C%20e.clientY)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(afterElement%20%3D%3D%20null)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20rowsWrap.appendChild(dragging)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20rowsWrap.insertBefore(dragging%2C%20afterElement)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20addBtn.addEventListener('click'%2C%20function()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20node%20%3D%20tpl.content.firstElementChild.cloneNode(true)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20rowsWrap.appendChild(node)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20bindRow(node)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20refreshIndexes()%3B%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20rowsWrap.querySelectorAll('.asp-row').forEach(bindRow)%3B%0A%20%20%20%20%20%20%20%20refreshIndexes()%3B%0A%20%20%20%20%7D)()%3B%0A%20%20%20%20%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object mce-object-script" width="20" height="20" alt="&lt;script&gt;" />
    <?php
}
function asp_extract_hash($link) {
    $link = trim((string)$link);
    if ($link === '') return false;
    if (preg_match('/aparat\.com\/v\/([a-zA-Z0-9]+)/', $link, $m)) {
        return $m[1];
    }
    if (preg_match('/^[a-zA-Z0-9]+$/', $link)) {
        return $link;
    }
    return false;
}
function asp_get_info($link) {
    $hash = asp_extract_hash($link);
    if (!$hash) return false;
    $cache_key = 'asp_v130_' . md5($hash);
    $cached = get_transient($cache_key);
    if ($cached) return $cached;
    $response = wp_remote_get(
        'https://www.aparat.com/api/fa/v1/video/video/show/videohash/' . rawurlencode($hash),
        ['timeout' => 12]
    );
    if (is_wp_error($response)) return false;
    $body = json_decode(wp_remote_retrieve_body($response), true);
    if (empty($body['data']['attributes'])) return false;
    $attr = $body['data']['attributes'];
    $info = [
        'mp4'   => !empty($attr['file_link']) ? esc_url_raw($attr['file_link']) : '',
        'thumb' => !empty($attr['big_poster']) ? esc_url_raw($attr['big_poster']) : '',
        'title' => !empty($attr['title']) ? sanitize_text_field($attr['title']) : '',
    ];
    if (empty($info['mp4'])) return false;
    set_transient($cache_key, $info, 2 * HOUR_IN_SECONDS);
    return $info;
}
add_shortcode('aparat_stories', 'asp_render_stories');
function asp_render_stories() {
    $data = get_option('asp_aparat_data', []);
    $stories = [];
    if (!is_array($data)) $data = [];
    foreach ($data as $item) {
        if (empty($item['link'])) continue;
        $info = asp_get_info($item['link']);
        if ($info) {
            $stories[] = [
                'mp4'        => $info['mp4'],
                'thumb'      => $info['thumb'],
                'title'      => !empty($item['title']) ? $item['title'] : $info['title'],
                'item_title' => !empty($item['item_title']) ? $item['item_title'] : '',
                'item_link'  => !empty($item['item_link']) ? $item['item_link'] : '',
            ];
        }
    }
    if (empty($stories)) return '';
    $uid = 'asp_' . wp_rand(1000, 999999);
    ob_start();
    ?>
    <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cstyle%3E%0A%20%20%20%20%20%20%20%20%3Aroot%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20--asp-main%3A%23FFD600%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20--asp-font%3A'iranyekan'%2C'IRANYekan'%2C'Tahoma'%2Csans-serif%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-container%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20width%3A100%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20direction%3Artl%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20margin%3A0%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding%3A0%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-family%3Avar(--asp-font)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20position%3Arelative%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-strip%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20position%3Arelative%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3Aflex%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20align-items%3Acenter%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-wrapper%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3Aflex%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20gap%3A15px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20overflow-x%3Aauto%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding%3A10px%205px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20scrollbar-width%3Anone%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20-ms-overflow-style%3Anone%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20scroll-behavior%3Asmooth%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20width%3A100%25%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-wrapper%3A%3A-webkit-scrollbar%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3Anone%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-node%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20flex%3A0%200%20auto%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20width%3A92px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20min-width%3A92px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20cursor%3Apointer%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20text-align%3Acenter%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-circle%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20width%3A85px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20height%3A85px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border-radius%3A50%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20background%3Alinear-gradient(135deg%2C%23DDA63A%200%25%2C%23FFD600%2045%25%2C%23FFB300%20100%25)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding%3A2px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20margin%3A0%20auto%208px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20box-sizing%3Aborder-box%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20transition%3Atransform%20.2s%20ease%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-node%3Ahover%20.asp-circle%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20transform%3Ascale(1.05)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-circle%20img%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20width%3A100%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20height%3A100%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border-radius%3A50%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20object-fit%3Acover%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border%3A3px%20solid%20%23fff%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3Ablock%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-txt%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-size%3A11px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3A%23333%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20line-height%3A1.45%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20height%3A32px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3A-webkit-box%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20-webkit-line-clamp%3A2%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20-webkit-box-orient%3Avertical%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20overflow%3Ahidden%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20text-overflow%3Aellipsis%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20word-wrap%3Abreak-word%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-family%3Avar(--asp-font)%3B%0A%20%20%20%20%20%20%20%20%7D%0A.asp-nav%20%7B%0A%20%20%20%20position%3A%20absolute%3B%0A%20%20%20%20top%3A%2050%25%20%20!important%3B%0A%20%20%20%20width%3A%2025px%3B%0A%20%20%20%20height%3A%2025px%3B%0A%20%20%20%20border-radius%3A%2050%25%20!important%3B%0A%20%20%20%20background%3A%20%23fff%3B%0A%20%20%20%20border%3A2px%20solid%20%23ccc%3B%0A%20%20%20%20display%3A%20flex%3B%0A%20%20%20%20align-items%3A%20center%3B%0A%20%20%20%20justify-content%3A%20center%3B%0A%20%20%20%20cursor%3A%20pointer%3B%0A%20%20%20%20z-index%3A%205%3B%0A%20%20%20%20transition%3A%20.2s%3B%0A%20%20%20%20color%3A%20%23ccc%3B%0A%20%20%20%20padding%3A%200%20!important%3B%0A%7D%0A.asp-nav-prev%20%7B%0A%20%20%20%20right%3A%200%3B%20%0A%7D%0A.asp-nav-next%20%7B%0A%20%20%20%20left%3A%200%3B%0A%7D%0A%20%20%20%20%20%20%20%20.asp-overlay%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20position%3Afixed%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20inset%3A0%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20background%3Argba(0%2C0%2C0%2C.92)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20z-index%3A999999%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3Anone%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20align-items%3Acenter%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20justify-content%3Acenter%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding%3A20px%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-close-btn%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20position%3A%20absolute%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20top%3A%2020px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20left%3A%2020px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20width%3A%2025px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20height%3A%2025px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20background%3A%20%23ef4444%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border%3A%202px%20%23fff%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border-radius%3A%205px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3A%20%23fff%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-size%3A%2020px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20line-height%3A%200px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20text-align%3A%20center%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20cursor%3A%20pointer%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20z-index%3A%201000001%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3A%20flex%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20align-items%3A%20center%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20justify-content%3A%20center%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20transition%3A%20background%200.2s%2C%20transform%200.2s%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-close-btn%3Ahover%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20background%3A%20rgba(255%2C%20255%2C%20255%2C%200.3)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20transform%3A%20scale(1.1)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-content%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20width%3A%20100%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20max-width%3A%20400px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20height%3A%20auto%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20max-height%3A%2095vh%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20position%3A%20relative%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3A%20flex%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20flex-direction%3A%20column%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20gap%3A%2010px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20justify-content%3A%20center%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-header%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20position%3A%20static%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20text-align%3A%20center%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3A%20%23fff%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20z-index%3A%20auto%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3A%20flex%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20flex-direction%3A%20column%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20gap%3A%2010px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20margin-top%3A%200%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding-top%3A%200%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-main-title%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3A%20%23ffffff%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-weight%3A%20700%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-size%3A%2018px%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20line-height%3A%201.4%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20margin%3A%200%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding%3A%200%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20text-align%3A%20center%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20background%3A%20none%20!important%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-item-link%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3A%20block%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3A%20%23FFD600%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-size%3A%2015px%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-weight%3A%20700%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20margin%3A%200%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding%3A%200%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20text-align%3A%20center%20!important%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20text-decoration%3A%20none%20!important%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-video%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20width%3A%20100%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20height%3A%20auto%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20max-height%3A%2070vh%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20background%3A%20%23000%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border-radius%3A%2012px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20display%3A%20block%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20object-fit%3A%20contain%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-mbtn%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20position%3Aabsolute%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20top%3A50%25%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20transform%3AtranslateY(-50%25)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20background%3Avar(--asp-main)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border%3A%202px%20%23fff%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20width%3A30px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20height%3A30px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20border-radius%3A%205px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20cursor%3Apointer%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-weight%3A700%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20font-size%3A20px%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20z-index%3A10%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20box-shadow%3A0%204px%2010px%20rgba(0%2C0%2C0%2C.25)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20transition%3Atransform%20.2s%20ease%2C%20opacity%20.2s%20ease%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20line-height%3A%201%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20padding%3A%200%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20margin%3A%200%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-mbtn%3Ahover%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20transform%3AtranslateY(-50%25)%20scale(1.07)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20.asp-mbtn-next%7B%20left%3A-50px%3B%20%7D%0A%20%20%20%20%20%20%20%20.asp-mbtn-prev%7B%20right%3A-50px%3B%20%7D%0A%20%20%20%20%20%20%20%20%40media%20(max-width%3A768px)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-header%20%7B%20text-align%3A%20center%3B%20padding%3A%200%2010px%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-content%20%7B%20gap%3A%2010px%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-mbtn-next%20%7B%20left%3A%205px%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-mbtn-prev%20%7B%20right%3A%205px%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-close-btn%20%7B%20top%3A%2015px%3B%20left%3A%2015px%3B%20width%3A%2025px%3B%20height%3A%2025px%3B%20font-size%3A%2020px%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-main-title%7B%20font-size%3A14px%20!important%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-item-link%7B%20font-size%3A12px%20!important%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-nav-prev%7B%20right%3A0%3B%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20.asp-nav-next%7B%20left%3A0%3B%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%3C%2Fstyle%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object mce-object-style" width="20" height="20" alt="&lt;style&gt;" />
    <div class="asp-container" id="<?php echo esc_attr($uid); ?>">
        <div class="asp-strip">
<button class="asp-nav asp-nav-next" type="button" aria-label="اسکرول به راست">
    <svg width="15" height="15" viewBox="0 0 24 24" fill="none">
        <path d="M15 6L9 12L15 18"
              stroke="currentColor"
              stroke-width="2.5"
              stroke-linecap="round"
              stroke-linejoin="round"/>
    </svg>
</button>
            <div class="asp-wrapper">
                <?php foreach ($stories as $i => $s): ?>
                    <div class="asp-node" data-index="<?php echo esc_attr($i); ?>">
                        <div class="asp-circle">
                            <img src="<?php echo esc_url($s['thumb']); ?>" alt="<?php echo esc_attr($s['title']); ?>">
                        </div>
                        <div class="asp-txt"><?php echo esc_html($s['title']); ?></div>
                    </div>
                <?php endforeach; ?>
            </div>
<button class="asp-nav asp-nav-prev" type="button" aria-label="اسکرول به چپ">
    <svg width="15" height="15" viewBox="0 0 24 24" fill="none">
        <path d="M9 6L15 12L9 18"
              stroke="currentColor"
              stroke-width="2.5"
              stroke-linecap="round"
              stroke-linejoin="round"/>
    </svg>
</button>
        </div>
        <div class="asp-overlay">
            <button class="asp-close-btn" type="button" aria-label="بستن">&times;</button>
            <div class="asp-content">
                <div class="asp-header">
                    <div class="asp-main-title"></div>
                    <a href="#" class="asp-item-link" target="_blank" rel="noopener noreferrer" style="display:none;"></a>
                </div>
                <button class="asp-mbtn asp-mbtn-prev" type="button" aria-label="استوری قبلی">&#10094;</button>
                <video class="asp-video" autoplay playsinline controls></video>
                <button class="asp-mbtn asp-mbtn-next" type="button" aria-label="استوری بعدی">&#10095;</button>
            </div>
        </div>
    </div>
    <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%3E%0A%20%20%20%20(function()%7B%0A%20%20%20%20%20%20%20%20const%20root%20%3D%20document.getElementById(%3C%3Fphp%20echo%20wp_json_encode(%24uid)%3B%20%3F%3E)%3B%0A%20%20%20%20%20%20%20%20if%20(!root)%20return%3B%0A%20%20%20%20%20%20%20%20const%20stories%20%3D%20%3C%3Fphp%20echo%20wp_json_encode(%24stories%2C%20JSON_UNESCAPED_UNICODE%20%7C%20JSON_UNESCAPED_SLASHES)%3B%20%3F%3E%3B%0A%20%20%20%20%20%20%20%20const%20strip%20%3D%20root.querySelector('.asp-wrapper')%3B%0A%20%20%20%20%20%20%20%20const%20stripPrev%20%3D%20root.querySelector('.asp-nav-prev')%3B%0A%20%20%20%20%20%20%20%20const%20stripNext%20%3D%20root.querySelector('.asp-nav-next')%3B%0A%20%20%20%20%20%20%20%20const%20nodes%20%3D%20root.querySelectorAll('.asp-node')%3B%0A%20%20%20%20%20%20%20%20const%20overlay%20%3D%20root.querySelector('.asp-overlay')%3B%0A%20%20%20%20%20%20%20%20const%20closeBtn%20%3D%20root.querySelector('.asp-close-btn')%3B%20%2F%2F%20%D8%AF%DA%A9%D9%85%D9%87%20%D8%AE%D8%B1%D9%88%D8%AC%0A%20%20%20%20%20%20%20%20const%20video%20%3D%20root.querySelector('.asp-video')%3B%0A%20%20%20%20%20%20%20%20const%20mainTitle%20%3D%20root.querySelector('.asp-main-title')%3B%0A%20%20%20%20%20%20%20%20const%20itemLink%20%3D%20root.querySelector('.asp-item-link')%3B%0A%20%20%20%20%20%20%20%20const%20prevBtn%20%3D%20root.querySelector('.asp-mbtn-prev')%3B%0A%20%20%20%20%20%20%20%20const%20nextBtn%20%3D%20root.querySelector('.asp-mbtn-next')%3B%0A%20%20%20%20%20%20%20%20let%20currentIndex%20%3D%200%3B%0A%20%20%20%20%20%20%20%20function%20updateModalButtons()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20prevBtn.disabled%20%3D%20currentIndex%20%3C%3D%200%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20nextBtn.disabled%20%3D%20currentIndex%20%3E%3D%20stories.length%20-%201%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20prevBtn.style.opacity%20%3D%20currentIndex%20%3C%3D%200%20%3F%20'.35'%20%3A%20'1'%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20nextBtn.style.opacity%20%3D%20currentIndex%20%3E%3D%20stories.length%20-%201%20%3F%20'.35'%20%3A%20'1'%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20function%20openStory(index)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(!stories%5Bindex%5D)%20return%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20currentIndex%20%3D%20index%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20mainTitle.textContent%20%3D%20stories%5Bindex%5D.title%20%7C%7C%20''%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(stories%5Bindex%5D.item_title%20%26%26%20stories%5Bindex%5D.item_link)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20itemLink.textContent%20%3D%20stories%5Bindex%5D.item_title%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20itemLink.href%20%3D%20stories%5Bindex%5D.item_link%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20itemLink.style.setProperty('display'%2C%20'inline'%2C%20'important')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20itemLink.textContent%20%3D%20''%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20itemLink.href%20%3D%20'%23'%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20itemLink.style.setProperty('display'%2C%20'none'%2C%20'important')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20video.src%20%3D%20stories%5Bindex%5D.mp4%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20overlay.style.display%20%3D%20'flex'%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20document.body.style.overflow%20%3D%20'hidden'%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20updateModalButtons()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20video.load()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20video.play().catch(function()%7B%7D)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20function%20closeStory()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20overlay.style.display%20%3D%20'none'%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20video.pause()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20video.removeAttribute('src')%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20video.load()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20document.body.style.overflow%20%3D%20''%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20function%20nextStory()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(currentIndex%20%3C%20stories.length%20-%201)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20openStory(currentIndex%20%2B%201)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20closeStory()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20function%20prevStory()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(currentIndex%20%3E%200)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20openStory(currentIndex%20-%201)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20function%20getScrollAmount()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20Math.max(strip.clientWidth%20*%200.75%2C%20220)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20function%20scrollStrip(direction)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20amount%20%3D%20getScrollAmount()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20delta%20%3D%20direction%20%3D%3D%3D%20'next'%20%3F%20-amount%20%3A%20amount%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20strip.scrollBy(%7B%20left%3A%20delta%2C%20behavior%3A%20'smooth'%20%7D)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20function%20updateStripButtons()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20maxScroll%20%3D%20strip.scrollWidth%20-%20strip.clientWidth%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(maxScroll%20%3C%3D%205)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20stripPrev.disabled%20%3D%20true%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20stripNext.disabled%20%3D%20true%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20stripPrev.disabled%20%3D%20false%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20stripNext.disabled%20%3D%20false%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20nodes.forEach(function(node)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20node.addEventListener('click'%2C%20function()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20const%20index%20%3D%20parseInt(node.getAttribute('data-index')%2C%2010)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20openStory(index)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20stripPrev.addEventListener('click'%2C%20function(e)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20e.preventDefault()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20scrollStrip('prev')%3B%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20stripNext.addEventListener('click'%2C%20function(e)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20e.preventDefault()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20scrollStrip('next')%3B%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20prevBtn.addEventListener('click'%2C%20function(e)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20e.stopPropagation()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20prevStory()%3B%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20nextBtn.addEventListener('click'%2C%20function(e)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20e.stopPropagation()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20nextStory()%3B%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20closeBtn.addEventListener('click'%2C%20function(e)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20e.stopPropagation()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20closeStory()%3B%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20overlay.addEventListener('click'%2C%20function(e)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(e.target%20%3D%3D%3D%20overlay)%20closeStory()%3B%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20video.addEventListener('ended'%2C%20function()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20nextStory()%3B%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20document.addEventListener('keydown'%2C%20function(e)%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(overlay.style.display%20!%3D%3D%20'flex')%20return%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(e.key%20%3D%3D%3D%20'Escape')%20closeStory()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(e.key%20%3D%3D%3D%20'ArrowRight')%20nextStory()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(e.key%20%3D%3D%3D%20'ArrowLeft')%20prevStory()%3B%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20updateStripButtons()%3B%0A%20%20%20%20%7D)()%3B%0A%20%20%20%20%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object mce-object-script" width="20" height="20" alt="&lt;script&gt;" />
    <?php
    return ob_get_clean();
}

روش اول: فایل functions.php

اگر از قالب فرزند (Child Theme) استفاده می‌کنید، می‌توانید کد را در فایل: functions.php قالب فرزند قرار دهید.

توصیه می‌شود کد را مستقیماً در فایل functions.php قالب اصلی قرار ندهید؛ زیرا با به‌روزرسانی قالب ممکن است تغییرات شما از بین برود.

روش دوم: استفاده از افزونه Code Snippets

روش ساده‌تر این است که از افزونه‌های مدیریت Snippet استفاده کنید.

در این روش، کد را به‌عنوان یک Snippet جدید اضافه کرده و آن را فعال می‌کنید.

مزیت این روش این است که برای اضافه کردن کدهای PHP نیازی به ویرایش مستقیم فایل‌های قالب ندارید.

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *