/home/vianto5/ceibaresidencial.mx/wp-content/plugins/olympus-google-fonts/lib/src
Edit: /home/vianto5/ceibaresidencial.mx/wp-content/plugins/olympus-google-fonts/lib/src/Shell.php (13847B)
'settings'
* (Plinth renders from your definitions).
*
* CSS class names follow BEM: block, block__element, block--modifier.
* All classes use the "pln-" prefix.
*
* @package Plinth
*/
namespace Plinth;
/**
* Admin page shell with sidebar navigation, tab panels, and toast.
*/
class Shell {
/**
* Merged configuration array.
*
* @var array
*/
private $config = array();
/**
* Settings instance for auto-rendered settings tabs.
*
* @var Settings
*/
private $settings;
/**
* Built-in SVG icon paths keyed by name.
*
* @var array
*/
private $icons = array(
'check' => '
',
'package' => '
',
'zap' => '
',
'clock' => '
',
'edit' => '
',
'upload' => '
',
'book' => '
',
'chevron-right' => '
',
'arrow-right' => '
',
'globe' => '
',
'trash' => '
',
'close' => '
',
'activity' => '
',
'type' => '
',
'adobe' => '
',
'settings' => '
',
'pulse' => '
',
'copy' => '
',
'life-buoy' => '
',
);
/**
* Build the admin shell.
*
* @param array $config Shell configuration: slug, title, version, icon, tabs,
* default_tab, capability, help, nav_groups, after_tabs,
* and an optional pre-built Settings instance.
*/
public function __construct( array $config ) {
$defaults = array(
'slug' => '',
'title' => '',
'version' => '1.0.0',
'icon' => '',
'tabs' => array(),
'default_tab' => '',
'capability' => 'manage_options',
'help' => null,
'nav_groups' => null,
'after_tabs' => null,
);
$this->config = array_merge( $defaults, $config );
// Accept a pre-built Settings instance from the consumer. The consumer
// must create Settings early (in its constructor) so the AJAX handler
// registers on every admin request. Shell only instantiates on the
// plugin page, which is too late for AJAX.
if ( isset( $config['settings'] ) && $config['settings'] instanceof Settings ) {
$this->settings = $config['settings'];
} else {
$this->settings = new Settings( $this->config['slug'], $this->config['capability'] );
}
}
/**
* Get the Settings instance.
*
* @return Settings
*/
public function settings() {
return $this->settings;
}
/**
* Register setting definitions with the Settings instance.
*
* @param array $definitions Setting definitions keyed by setting name.
* @return void
*/
public function register_settings( array $definitions ) {
$this->settings->register( $definitions );
}
/**
* Add the admin page to the WordPress menu and enqueue assets.
*
* @param string|null $parent Parent menu slug, or null for a top-level page.
* @return void
*/
public function register_menu( $parent = null ) {
add_action(
'admin_menu',
function () use ( $parent ) {
if ( $parent ) {
add_submenu_page(
$parent,
$this->config['title'],
$this->config['title'],
$this->config['capability'],
$this->config['slug'],
array( $this, 'render' )
);
} else {
add_menu_page(
$this->config['title'],
$this->config['title'],
$this->config['capability'],
$this->config['slug'],
array( $this, 'render' ),
$this->config['icon'] ? $this->config['icon'] : 'dashicons-admin-generic'
);
}
}
);
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
$this->settings->register_ajax();
}
/**
* Enqueue Plinth assets. Plinth JS uses its own nonce (slug_plinth_nonce)
* for settings auto-save. The consumer enqueues its own assets and nonce
* separately for domain-specific AJAX actions.
*
* @param string $hook The current admin page hook suffix.
* @return void
*/
public function enqueue( $hook ) {
$slug = $this->config['slug'];
$suffix = $slug;
if ( false === strpos( $hook, $slug ) ) {
return;
}
$lib_url = $this->get_lib_url();
wp_enqueue_style(
'plinth-shell',
$lib_url . 'assets/css/plinth.css',
array(),
$this->config['version']
);
wp_enqueue_script(
'plinth-shell',
$lib_url . 'assets/js/plinth.js',
array(),
$this->config['version'],
true
);
wp_localize_script(
'plinth-shell',
'plinthAdmin',
array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( $slug . '_plinth_nonce' ),
'slug' => $slug,
'i18n' => array(
'saved' => __( 'Saved', 'plinth' ),
'error' => __( 'Something went wrong', 'plinth' ),
),
)
);
}
/**
* Get the URL to the Plinth lib/ directory.
*
* @return string
*/
private function get_lib_url() {
$lib_dir = dirname( __DIR__ );
$abs_path = wp_normalize_path( ABSPATH );
$lib_path = wp_normalize_path( $lib_dir );
$relative = str_replace( $abs_path, '', $lib_path );
return site_url( '/' . $relative . '/' );
}
/**
* Render the full admin page: sidebar, tab panels, and toast.
*
* @return void
*/
public function render() {
$tabs = $this->config['tabs'];
$default_tab = $this->config['default_tab'];
$nav_groups = $this->config['nav_groups'];
if ( ! $default_tab && ! empty( $tabs ) ) {
$default_tab = array_key_first( $tabs );
}
?>
$tab ) {
$is_active = $default_tab === $slug;
$type = isset( $tab['type'] ) ? $tab['type'] : 'custom';
printf(
'
',
$is_active ? ' active' : '',
esc_attr( $slug )
);
if ( 'settings' === $type ) {
$this->settings->render_tab( $tab );
} elseif ( isset( $tab['callback'] ) && is_callable( $tab['callback'] ) ) {
call_user_func( $tab['callback'], $this );
}
echo '
';
}
?>
config['after_tabs'] ) && is_callable( $this->config['after_tabs'] ) ) {
call_user_func( $this->config['after_tabs'], $this );
}
?>
icon( 'check', 16, 2.5 ); ?>
$group ) {
$label = isset( $group['group'] ) ? $group['group'] : null;
$items = isset( $group['items'] ) ? $group['items'] : array();
if ( $label ) {
echo '
' . esc_html( $label ) . '
';
} elseif ( $index > 0 ) {
echo '
';
}
foreach ( $items as $item ) {
$this->render_nav_item( $item, $default_tab );
}
}
}
/**
* Render a flat list of navigation items from the tabs config.
*
* @param array $tabs Tabs configuration keyed by slug.
* @param string $default_tab Slug of the default active tab.
* @return void
*/
private function render_nav_flat( array $tabs, $default_tab ) {
foreach ( $tabs as $slug => $tab ) {
$this->render_nav_item(
array(
$slug,
isset( $tab['label'] ) ? $tab['label'] : $slug,
isset( $tab['icon'] ) ? $tab['icon'] : null,
isset( $tab['count'] ) ? $tab['count'] : null,
),
$default_tab
);
}
}
/**
* Render a single navigation button.
*
* @param array $item Item array: [ slug, label, icon, count ].
* @param string $default_tab Slug of the default active tab.
* @return void
*/
private function render_nav_item( array $item, $default_tab ) {
list( $slug, $label, $icon, $count ) = array_pad( $item, 4, null );
?>
icons[ $name ] ) ) {
return;
}
$svg = sprintf(
'
',
$classname ? 'class="' . esc_attr( $classname ) . '" ' : '',
(int) $size,
esc_attr( (string) $stroke ),
$this->icons[ $name ]
);
echo wp_kses( $svg, $this->allowed_svg_tags() );
}
/**
* Add a custom icon to the icon set.
*
* @param string $name Icon name.
* @param string $path SVG path markup (inner elements only, no wrapping svg tag).
* @return void
*/
public function add_icon( $name, $path ) {
$this->icons[ $name ] = $path;
}
/**
* Get the allowed HTML tags and attributes for wp_kses SVG output.
*
* @return array
*/
private function allowed_svg_tags() {
return array(
'svg' => array(
'class' => true,
'width' => true,
'height' => true,
'viewbox' => true,
'fill' => true,
'stroke' => true,
'stroke-width' => true,
'aria-hidden' => true,
'focusable' => true,
),
'path' => array( 'd' => true ),
'polyline' => array( 'points' => true ),
'circle' => array(
'cx' => true,
'cy' => true,
'r' => true,
),
'rect' => array(
'x' => true,
'y' => true,
'width' => true,
'height' => true,
'rx' => true,
),
'line' => array(
'x1' => true,
'y1' => true,
'x2' => true,
'y2' => true,
),
);
}
}