WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#18879 closed defect (bug) (invalid)

Impossible to use wp_admin_bar_class filter

Reported by: geminorum Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: General Keywords:
Focuses: Cc:

Description

wanting to extend WP_Admin_Bar class, cannot include the class-wp-admin-bar.php for a fatal (cannot redeclare class). because of require() instead of require_once() on _wp_admin_bar_init()

Attachments (1)

18879.patch (531 bytes) - added by kurtpayne 6 years ago.

Download all attachments as: .zip

Change History (8)

#1 @volcanicpixels
6 years ago

  • Keywords needs-patch added

Seems like a valid bug. I'll get a patch for it.

@kurtpayne
6 years ago

#2 @kurtpayne
6 years ago

  • Keywords has-patch added; needs-patch removed

#3 @kurtpayne
6 years ago

  • Cc kpayne@… added

#4 @kawauso
6 years ago

  • Keywords reporter-feedback added

There is no need to require class-wp-admin-bar.php a second time. If you're extending it, then it's already loaded by the time the 'wp_admin_bar_class' filter is fired.

Test code:

<?php
function check_wp_admin_bar_class( $class ) {
	class My_Admin_Bar extends WP_Admin_Bar {
	
	}

	echo '<p>&nbsp;</p><p><pre>'; var_dump( class_exists( 'My_Admin_Bar' ) ); echo '</pre></p>';
	return 'My_Admin_Bar';
}

add_action( 'wp_admin_bar_class', 'check_wp_admin_bar_class' );

#5 @geminorum
6 years ago

  • Resolution set to invalid
  • Status changed from new to closed

kawauso's way works, sorry to bother.

#6 @kawauso
6 years ago

  • Milestone Awaiting Review deleted

#7 @kawauso
6 years ago

  • Keywords has-patch reporter-feedback removed
Note: See TracTickets for help on using tickets.