| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
|
| 5 |
use Forge12\Shared\Logger; |
| 6 |
use Forge12\Shared\LoggerInterface; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* |
| 14 |
*/ |
| 15 |
class UIMenu { |
| 16 |
private LoggerInterface $logger; |
| 17 |
|
| 18 |
/** |
| 19 |
* UI constructor. |
| 20 |
* |
| 21 |
* @param $slug |
| 22 |
*/ |
| 23 |
public function __construct( LoggerInterface $logger ) { |
| 24 |
$this->logger = $logger; |
| 25 |
$this->get_logger()->info( 'UIMenu class instance created. Registering menu renderer.', [ |
| 26 |
'plugin' => 'double-opt-in', |
| 27 |
] ); |
| 28 |
|
| 29 |
add_action( 'f12_cf7_doubleoptin_admin_menu', array( $this, 'render' ), 10, 3 ); |
| 30 |
$this->get_logger()->debug( 'Added "render" method to "f12_cf7_doubleoptin_admin_menu" action.', [ |
| 31 |
'plugin' => 'double-opt-in', |
| 32 |
] ); |
| 33 |
} |
| 34 |
|
| 35 |
public function get_logger() { |
| 36 |
return $this->logger; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* |
| 41 |
* @param array<UIPage> $Pages |
| 42 |
* @param string $active_slug |
| 43 |
* |
| 44 |
* @return void |
| 45 |
*/ |
| 46 |
public function render( $Pages, $active_slug, $plugin_slug ) { |
| 47 |
$this->get_logger()->info( 'Rendering the admin menu navigation.', [ |
| 48 |
'plugin' => $plugin_slug, |
| 49 |
'active_slug' => $active_slug, |
| 50 |
] ); |
| 51 |
|
| 52 |
if ( ! is_array( $Pages ) ) { |
| 53 |
$this->get_logger()->warning( 'Provided pages variable is not an array. Converting to an array.', [ |
| 54 |
'plugin' => $plugin_slug, |
| 55 |
] ); |
| 56 |
$Pages = array( $Pages ); |
| 57 |
} |
| 58 |
|
| 59 |
// Begin HTML output |
| 60 |
?> |
| 61 |
<nav class="navbar"> |
| 62 |
<ul class="navbar-nav"> |
| 63 |
<?php |
| 64 |
$this->get_logger()->info( 'Triggering "before-forge12-plugin-menu-' . $plugin_slug . '" action.', [ |
| 65 |
'plugin' => $plugin_slug, |
| 66 |
] ); |
| 67 |
do_action( 'before-forge12-plugin-menu-' . $plugin_slug ); |
| 68 |
?> |
| 69 |
<?php foreach ( $Pages as /** @var UIPage $Page */ $Page ): ?> |
| 70 |
<li class="forge12-plugin-menu-item"> |
| 71 |
<?php |
| 72 |
$this->get_logger()->debug( 'Processing menu item for page: ' . $Page->getSlug(), [ |
| 73 |
'plugin' => $plugin_slug, |
| 74 |
] ); |
| 75 |
|
| 76 |
$class = ''; |
| 77 |
$slug = $plugin_slug . '_' . $Page->getSlug(); |
| 78 |
|
| 79 |
if ( $Page->isDashboard() ) { |
| 80 |
$slug = $plugin_slug; |
| 81 |
} |
| 82 |
|
| 83 |
if ( $Page->getSlug() == $active_slug || ( $Page->isDashboard() && empty( $active_slug ) ) ) { |
| 84 |
$class = 'active'; |
| 85 |
$this->get_logger()->notice( 'Setting menu item "' . $Page->getSlug() . '" as active.', [ |
| 86 |
'plugin' => $plugin_slug, |
| 87 |
] ); |
| 88 |
} |
| 89 |
?> |
| 90 |
<a href="<?php echo esc_url( admin_url( 'admin.php' ) ); ?>?page=<?php echo esc_attr( $slug ); ?>" |
| 91 |
title="<?php echo esc_attr( $Page->getTitle() ); ?>" |
| 92 |
class="<?php echo esc_attr( $class ) . ' ' . esc_attr( $Page->getClass() ); ?>"> |
| 93 |
<?php echo esc_html( $Page->getTitle() ); ?> |
| 94 |
</a> |
| 95 |
</li> |
| 96 |
<?php endforeach; ?> |
| 97 |
<?php |
| 98 |
$this->get_logger()->info( 'Triggering "after-forge12-plugin-menu-' . $plugin_slug . '" action.', [ |
| 99 |
'plugin' => $plugin_slug, |
| 100 |
] ); |
| 101 |
do_action( 'after-forge12-plugin-menu-' . $plugin_slug ); |
| 102 |
?> |
| 103 |
</ul> |
| 104 |
</nav> |
| 105 |
<?php |
| 106 |
$this->get_logger()->notice( 'Menu navigation rendering complete.', [ |
| 107 |
'plugin' => $plugin_slug, |
| 108 |
] ); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
new UIMenu( Logger::getInstance() ); |
| 113 |
} |