<?php
/**
* Main class of the Neve Dashboard
*
* @package neve
*/
namespace Hi\Controllers;
/**
* Class Main
*
* @package Neve\Admin\Dashboard
*/
class Main
{
private $theme_args = [];
public function __construct()
{
$this->setup_config();
add_action('init', [$this, 'setup_config']);
add_action('admin_menu', [$this, 'register']);
add_action('init', array($this, 'register_about_page'), 1);
}
public function register()
{
$theme = $this->theme_args;
if (empty($theme['name']) || empty($theme['slug'])) {
return;
}
$theme_page = !empty($theme['template']) ? $theme['template'] . '-welcome' : $theme['slug'] . '-welcome';
$icon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI3LjQuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHZpZXdCb3g9IjAgMCAzMiAzMiIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMzIgMzI7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4KPHN0eWxlIHR5cGU9InRleHQvY3NzIj4KCS5zdDB7ZmlsbC1ydWxlOmV2ZW5vZGQ7Y2xpcC1ydWxlOmV2ZW5vZGQ7ZmlsbDojRkZGRkZGO30KPC9zdHlsZT4KPHBhdGggY2xhc3M9InN0MCIgZD0iTTAsMS42QzAsMC43LDAuNywwLDEuNiwwaDI4LjhDMzEuMywwLDMyLDAuNywzMiwxLjZWMzBjMCwwLjktMC43LDEuNi0xLjYsMS42SDEuNkMwLjcsMzEuNSwwLDMwLjgsMCwzMFYxLjZ6CgkgTTEzLDE1Ljh2Ny41SDkuMVY4YzAtMC4xLDAtMC4xLDAuMS0wLjJjMCwwLDAuMSwwLDAuMiwwLjFsOS42LDcuOFY4LjJoMy44djE1LjJjMCwwLjEsMCwwLjEtMC4xLDAuMmMwLDAtMC4xLDAtMC4yLTAuMUwxMywxNS44egoJIE0yMi44LDI1LjdIOS4xVjI3aDEzLjdWMjUuN3oiLz4KPC9zdmc+Cg==';
if ($theme['name'] !== 'Neve') {
$icon = 'dashicons-admin-appearance';
}
$neve_icon = apply_filters('neve_menu_icon', $icon);
$priority = apply_filters('neve_menu_priority', 59); // The position of the menu item, 60 is the position of the Appearance menu.
$capability = 'manage_options';
// Place a theme page in the Appearance menu, for older versions of Neve Pro or TPC. to maintain backwards compatibility.
if (
(defined('NEVE_PRO_VERSION') && version_compare(NEVE_PRO_VERSION, '2.6.1', '<=')) ||
(defined('TIOB_VERSION') && version_compare(TIOB_VERSION, '1.1.38', '<='))
) {
add_theme_page(
/* translators: %s - Theme name */
sprintf(__('%s Options', 'neve'), wp_kses_post($theme['name'])),
/* translators: %s - Theme name */
sprintf(__('%s Options', 'neve'), wp_kses_post($theme['name'])),
$capability,
'admin.php?page=neve-welcome'
);
}
add_menu_page( // phpcs:ignore WPThemeReview.PluginTerritory.NoAddAdminPages.add_menu_pages_add_menu_page
wp_kses_post($theme['name']),
wp_kses_post($theme['name']),
$capability,
$theme_page,
[$this, 'render'],
$neve_icon, // The URL to the icon to be used for this menu
$priority
);
// Add Dashboard submenu. Same slug as parent to allow renaming the automatic submenu that is added.
add_submenu_page( // phpcs:ignore WPThemeReview.PluginTerritory.NoAddAdminPages.add_menu_pages_add_submenu_page
$theme_page,
/* translators: %s - Theme name */
sprintf(__('%s Options', 'neve'), wp_kses_post($theme['name'])),
/* translators: %s - Theme name */
sprintf(__('%s Options', 'neve'), wp_kses_post($theme['name'])),
$capability,
$theme_page,
[$this, 'render']
);
}
/**
* Setup the class props based on current theme.
*/
public function setup_config()
{
$theme = wp_get_theme();
$this->theme_args['name'] = apply_filters('ti_wl_theme_name', $theme->__get('Name'));
$this->theme_args['template'] = $theme->get('Template');
$this->theme_args['version'] = $theme->__get('Version');
$this->theme_args['description'] = apply_filters('ti_wl_theme_description', $theme->__get('Description'));
$this->theme_args['slug'] = $theme->__get('stylesheet');
}
/**
* Add the about page with respect to the white label settings.
*
* @return void
*/
public function register_about_page()
{
$theme = wp_get_theme();
$filtered_name = apply_filters('ti_wl_theme_name', $theme->__get('Name'));
$slug = $theme->__get('stylesheet');
if (empty($slug) || empty($filtered_name)) {
return;
}
// We check if the name is different from the filtered name,
// if it is, the whitelabel is in use and we should not add the about page.
// this check allows for child themes to use the about page.
if ($filtered_name !== $theme->__get('Name')) {
return;
}
add_filter(
'neve_about_us_metadata',
function () use ($filtered_name) {
return [
// Top-level page in the dashboard sidebar
'location' => 'neve-welcome',
// Logo to display on the page
'logo' => get_template_directory_uri() . '/assets/images/dashboard/logo.svg',
// Condition to show or hide the upgrade menu in the sidebar
'has_upgrade_menu' => !defined('NEVE_PRO_VERSION'),
// Add predefined product pages to the about page.
'product_pages' => ['otter-page'],
// Upgrade menu item link & text
'upgrade_link' => tsdk_utmify(esc_url('https://themeisle.com/themes/neve/upgrade/'), 'aboutfilter', 'nevedashboard'),
'upgrade_text' => __('Upgrade', 'neve') . ' ' . $filtered_name,
];
}
);
}
/**
* Render the application stub.
*
* @return void
*/
public function render()
{
echo '<div id="neve-dashboard"></div>';
}
}