forwp/account-menu', '[forwp_account_menu]', ) ); self::render_context_editor( AccountMenu::CONTEXT_PAGE, __( 'Account page sidebar', '4wp-account' ), __( 'Left navigation on the logged-in account page.', '4wp-account' ), array( 'forwp/account', '[forwp_account]', ) ); } /** * @param string $context header|page. * @param string $title Panel title. * @param string $description Panel description. * @param string[] $shortcodes Shortcode hints. */ private static function render_context_editor( string $context, string $title, string $description, array $shortcodes ): void { $sections = AccountMenu::get_sections( $context ); $prefix = self::field_prefix( $context ); ?>

$section ) : ?>

$link ) { if ( ! is_array( $link ) ) { continue; } self::render_custom_link_row( $field, (string) ( $link['id'] ?? 'row_' . $index ), $link ); } } ?>

$link Saved link row. * @param bool $template JS template fragment. */ private static function render_custom_link_row( string $field_name, string $row_key, array $link, bool $template = false ): void { $id = $template ? '__INDEX__' : $row_key; $label = (string) ( $link['label'] ?? '' ); $url = (string) ( $link['url'] ?? '' ); $order = isset( $link['order'] ) ? (int) $link['order'] : 50; $enabled = ! array_key_exists( 'enabled', $link ) || ! empty( $link['enabled'] ); $target = ( ! empty( $link['target'] ) && '_blank' === $link['target'] ); $name = $field_name . '[' . $id . ']'; ?> $post Raw POST. */ public static function save( array $post ): void { self::save_context( $post, AccountMenu::CONTEXT_HEADER ); self::save_context( $post, AccountMenu::CONTEXT_PAGE ); } /** * @param array $post Raw POST. * @param string $context header|page. */ private static function save_context( array $post, string $context ): void { $sections_key = self::field_prefix( $context ) . '_sections'; $links_key = self::links_field_name( $context ); if ( isset( $post[ $sections_key ] ) && is_array( $post[ $sections_key ] ) ) { AccountMenu::save_sections( $post[ $sections_key ], $context ); } if ( isset( $post[ $links_key ] ) && is_array( $post[ $links_key ] ) ) { AccountMenu::save_custom_links( $post[ $links_key ], $context ); } elseif ( array_key_exists( $links_key, $post ) ) { AccountMenu::save_custom_links( array(), $context ); } } }