Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid fatals in nav menu filter #917

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions php/class-coauthors-guest-authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function __construct() {
add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'filter_personal_data_exporter' ), 1 );

// Filters the guest author menu URL in nav menus.
add_filter( 'nav_menu_link_attributes', array( $this, 'filter_nav_menu_attributes' ), 10, 4 );
add_filter( 'nav_menu_link_attributes', array( $this, 'filter_nav_menu_attributes' ), 10, 2 );

// Allow users to change where this is placed in the WordPress admin
$this->parent_page = apply_filters( 'coauthors_guest_author_parent_page', $this->parent_page );
Expand Down Expand Up @@ -1642,21 +1642,19 @@ public function personal_data_exporter( $email_address ) {
/**
* Filters the guest author menu item attributes
*
* @param array $atts {
* The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
* @param array $atts {
* The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
*
* @type string $title Title attribute.
* @type string $target Target attribute.
* @type string $rel The rel attribute.
* @type string $href The href attribute.
* @type string $aria-current The aria-current attribute.
* }
* @param WP_Post $menu_item The current menu item object.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
* @return void
* @param WP_Post $menu_item The current menu item object.
* @return array
*/
public function filter_nav_menu_attributes( $atts, $menu_item, $args, $depth ) {
public function filter_nav_menu_attributes( $atts, $menu_item ) {
if ( ! empty( $menu_item->object ) && 'guest-author' === $menu_item->object ) {
$author = $this->get_guest_author_by( 'ID', $menu_item->object_id );
if ( ! empty( $author->type ) && $author->type === 'guest-author' ) {
Expand Down