HEX
Server: LiteSpeed
System: Linux premium267.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: predezso (1249)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: /home/predezso/samashtimedia.com/wp-content/plugins/ultimate-410/src/AbstractOptionsSection.php
<?php

namespace TinyWeb\Ultimate410;

abstract class AbstractOptionsSection
{
    const ID = '';
    /**
     * @var string
     */
    protected $title = '';
    /**
     * @var OptionsPage
     */
    protected $optionsPage;
    /**
     * @var string
     */
    protected $viewsPath;
    /**
     * @var string
     */
    protected $submit;

    /**
     * AbstractOptionsSection constructor.
     *
     * @param OptionsPage $page
     * @param string $pluginPath
     */
    public function __construct(OptionsPage $page, $pluginPath)
    {
        $this->viewsPath   = trailingslashit($pluginPath).'views/';
        $this->optionsPage = $page;

        add_action('admin_init', [$this, 'addSection']);
    }

    public function getId()
    {
        return static::ID;
    }

    public function getTitle()
    {
        return $this->title;
    }

    /**
     *
     */
    public function addSection()
    {
        add_settings_section($this->getId(), $this->getTitle(), [
            $this,
            'callback',
        ], $this->optionsPage->getId());
    }

    /**
     * Callback for section - include the view.
     */
    public function callback()
    {
        $this->includeView();
    }

    /**
     * @param array $args
     * @param string $name
     */
    protected function includeView($args = [], $name = '')
    {
        if (empty($name)) {
            $name = $this->getId();
        }
        $fileArr = preg_split('/(?=[A-Z-_])/', $name);
        $fileArr = array_map(function ($value) {
            return trim($value, '-_');
        }, $fileArr);
        $fileArr = array_map('strtolower', $fileArr);

        $args = array_merge([
            'id'    => $this->getId(),
            'title' => $this->getTitle(),
            'page'  => $this->optionsPage->getId(),
        ], $args);

        include $this->viewsPath.'section/'.implode('-', $fileArr).'.php';
    }

    /**
     * Get submit button value.
     *
     * @return string
     */
    public function getSubmit()
    {
        return empty($this->submit) ? __('Update Options', 'ultimate-410') : $this->submit;
    }
}