文件操作 - Manager.php
返回文件管理
返回主菜单
删除本文件
文件: /home/www/public/wp-content/plugins/ionos-navigation/inc/Manager.php
编辑文件内容
<?php namespace Ionos\Navigation; // Do not allow direct access! use Ionos\Librarynavigation\Config; use Ionos\Librarynavigation\Options; /** * Manager class */ class Manager { public function __construct() { \add_action( 'admin_init', [ $this, 'init' ] ); } /** * Adds menu and needed resources. */ public function init() { \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_navigation_resources' ] ); \add_action( 'admin_bar_menu', [ $this, 'add_ionos_menu' ], 999 ); } /** * Implements a navigation based on the config.json provided by the WMS. * * @param \WP_Admin_Bar $wp_admin_bar The WordPress Admin bar object. * * @return \WP_Admin_Bar */ public function add_ionos_menu( $wp_admin_bar ) { $menu_object = Config::get( 'features.menu_object' ); if ( ! empty( $menu_object ) ) { $list = $this->rewrite_menu_object( $menu_object ); } if ( empty( $list ) ) { $list = $this->get_elements(); } if ( empty( $list ) ) { return $wp_admin_bar; } // specify background color // the background color changes between two shades of gray. $child_count = 0; foreach ( $wp_admin_bar->get_nodes() as $object ) { if ( 'my-account' === $object->parent ) { ++$child_count; } } // create container basic structure with color specification. $wp_admin_bar->add_group( [ 'id' => 'ionos-global-navigation-group', 'parent' => 'my-account', 'meta' => [ 'class' => ( 0 === ( $child_count % 2 ) ) ? '' : 'ab-sub-secondary', ], ] ); // Add submenu. $wp_admin_bar->add_node( [ 'id' => 'ionos-global-navigation', 'title' => '<span class="ab-sub-menu menupop">' . \__( 'Navigation', 'ionos-navigation' ) . '</span>', 'parent' => 'ionos-global-navigation-group', ] ); // add submenu items. // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText foreach ( $list as $key => $value ) { $args = [ 'id' => 'ionos-global-navigation-' . $key, 'title' => \__( $value['name'], 'ionos-navigation' ), 'parent' => 'ionos-global-navigation', 'href' => $value['href'], 'meta' => [ 'target' => '_blank', ], ]; $wp_admin_bar->add_node( $args ); } return $wp_admin_bar; } /** * Load internal resources */ public function enqueue_navigation_resources() { // Load styles. \wp_enqueue_style( 'ionos-navigation-css', Helper::get_css_url( 'ionos-navigation.css' ), [], filemtime( Helper::get_css_path( 'ionos-navigation.css' ) ) ); } /** * Rewrites the menu object. Uses the market. Defaults to the first market in the list. * * @param array $menu_object The menu object. * * @return array The rewritten menu object. */ private function rewrite_menu_object( $menu_object ) { $tenant = \get_option( 'ionos_group_brand' ) ?: 'ionos'; //phpcs:ignore Universal.Operators.DisallowShortTernary.Found $market = strToLower( \get_option( $tenant . '_market' ) ); $list = []; foreach ( $menu_object as $item ) { if ( isset( $item['href'][ $market ] ) ) { $href = $item['href'][ $market ]; } else { $href = $item['href'][ \array_key_first( $item['href'] ) ]; } $list[] = [ 'name' => $item['name'], 'href' => $href, ]; } return $list; } /** * Gets the WMS feature config and prepares it for navigation. * * @return array|null */ private function get_elements() { $config_array = \json_decode( Config::get( 'features.menu' ), true ); if ( ! \is_array( $config_array ) || ! \is_array( $config_array['menu'] ) ) { return []; } $market_option = \get_option( Options::get_tenant_name() . '_market' ); $market = $config_array['market'][ $market_option ] ?? false; $list = []; foreach ( $config_array['menu'] as $value ) { if ( isset( $value['name'] ) && isset( $value['path'] ) ) { if ( false !== $market && Config::get( 'features.use_market' ) ) { $domain = $market; } elseif ( isset( $value['domain'] ) ) { $domain = $value['domain']; } else { continue; } $list[] = [ 'name' => $value['name'], 'href' => 'https://' . $domain . $value['path'], ]; } } return $list; } }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件