Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/elemento.../modules/editor-o.../classes
File: active-menu-resolver.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Elementor\Modules\EditorOne\Classes;
[2] Fix | Delete
[3] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[4] Fix | Delete
exit;
[5] Fix | Delete
}
[6] Fix | Delete
[7] Fix | Delete
class Active_Menu_Resolver {
[8] Fix | Delete
[9] Fix | Delete
private const HOME_SLUG = 'elementor';
[10] Fix | Delete
[11] Fix | Delete
private Url_Matcher $url_matcher;
[12] Fix | Delete
[13] Fix | Delete
public function __construct( Url_Matcher $url_matcher ) {
[14] Fix | Delete
$this->url_matcher = $url_matcher;
[15] Fix | Delete
}
[16] Fix | Delete
[17] Fix | Delete
public function resolve( array $menu_items, array $level4_groups, string $current_page, string $current_uri ): array {
[18] Fix | Delete
if ( 'elementor-editor' === $current_page || Menu_Config::EDITOR_MENU_SLUG === $current_page || Menu_Config::ELEMENTOR_MENU_SLUG === $current_page ) {
[19] Fix | Delete
return $this->create_active_state( self::HOME_SLUG );
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
$pro_post_type_match = $this->get_pro_post_type_active_state();
[23] Fix | Delete
[24] Fix | Delete
if ( $pro_post_type_match ) {
[25] Fix | Delete
return $pro_post_type_match;
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
return $this->find_best_matching_menu_item( $menu_items, $level4_groups, $current_uri );
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
public function create_active_state( string $menu_slug, string $child_slug = '', int $score = 0 ): array {
[32] Fix | Delete
return [
[33] Fix | Delete
'menu_slug' => $menu_slug,
[34] Fix | Delete
'child_slug' => $child_slug,
[35] Fix | Delete
'score' => $score,
[36] Fix | Delete
];
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
private function find_best_matching_menu_item( array $menu_items, array $level4_groups, string $current_uri ): array {
[40] Fix | Delete
$best_match = $this->create_active_state( '', '', -1 );
[41] Fix | Delete
[42] Fix | Delete
foreach ( $menu_items as $item ) {
[43] Fix | Delete
$best_match = $this->update_best_match_from_level4(
[44] Fix | Delete
$item,
[45] Fix | Delete
$level4_groups,
[46] Fix | Delete
$current_uri,
[47] Fix | Delete
$best_match
[48] Fix | Delete
);
[49] Fix | Delete
[50] Fix | Delete
$score = $this->url_matcher->get_match_score( $item['url'], $current_uri );
[51] Fix | Delete
[52] Fix | Delete
if ( $score > $best_match['score'] ) {
[53] Fix | Delete
$best_match = $this->create_active_state( $item['slug'], '', $score );
[54] Fix | Delete
}
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
return $this->create_active_state( $best_match['menu_slug'], $best_match['child_slug'] );
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
private function update_best_match_from_level4(
[61] Fix | Delete
array $item,
[62] Fix | Delete
array $level4_groups,
[63] Fix | Delete
string $current_uri,
[64] Fix | Delete
array $best_match
[65] Fix | Delete
): array {
[66] Fix | Delete
if ( empty( $item['group_id'] ) || ! isset( $level4_groups[ $item['group_id'] ] ) ) {
[67] Fix | Delete
return $best_match;
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
$group = $level4_groups[ $item['group_id'] ];
[71] Fix | Delete
[72] Fix | Delete
if ( empty( $group['items'] ) ) {
[73] Fix | Delete
return $best_match;
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
foreach ( $group['items'] as $child_item ) {
[77] Fix | Delete
$score = $this->url_matcher->get_match_score( $child_item['url'], $current_uri );
[78] Fix | Delete
[79] Fix | Delete
if ( $score > $best_match['score'] ) {
[80] Fix | Delete
$best_match = $this->create_active_state( $item['slug'], $child_item['slug'], $score );
[81] Fix | Delete
}
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
return $best_match;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
private function get_pro_post_type_active_state(): ?array {
[88] Fix | Delete
$current_post_type = filter_input( INPUT_GET, 'post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ?? '';
[89] Fix | Delete
[90] Fix | Delete
if ( empty( $current_post_type ) ) {
[91] Fix | Delete
return null;
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
return Menu_Data_Provider::get_elementor_post_types()[ $current_post_type ] ?? null;
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function