[wp-trac] [WordPress Trac] #38636: Allow passing data parameters to WP Admin Bar
WordPress Trac
noreply at wordpress.org
Wed Nov 2 22:19:45 UTC 2016
#38636: Allow passing data parameters to WP Admin Bar
-------------------------+-----------------------------
Reporter: keraweb | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Toolbar | Version: trunk
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
It is currently not possible to add your own parameters to WP Admin Bar.
For improved flexibility with javascript I think this could be a good
feature.
Example:
{{{#!php
<?php
$wp_admin_bar->add_node(
'id' => '',
'parent' => '',
'title' => '',
'href' => '',
'meta' => array(
'title' => '',
'data' => array(
'test' => 'data-test content'
)
),
) );
}}}
Example code for class-wp-admin-bar.php (L 497 - 533)
{{{#!php
<?php
if ( ! empty( $node->meta['data'] ) && ! is_array( $node->meta['data'] ) )
{
$node->meta['data'] = array( 'data' => (string)
$node->meta['data'] );
}
?>
<li id="<?php echo esc_attr( 'wp-admin-bar-' . $node->id ); ?>"<?php echo
$menuclass; ?>><?php
if ( $has_link ):
?><a class="ab-item"<?php echo $aria_attributes; ?>
href="<?php echo esc_url( $node->href ) ?>"<?php
if ( ! empty( $node->meta['onclick'] ) ) :
?> onclick="<?php echo esc_js(
$node->meta['onclick'] ); ?>"<?php
endif;
if ( ! empty( $node->meta['target'] ) ) :
?> target="<?php echo esc_attr(
$node->meta['target'] ); ?>"<?php
endif;
if ( ! empty( $node->meta['title'] ) ) :
?> title="<?php echo esc_attr(
$node->meta['title'] ); ?>"<?php
endif;
if ( ! empty( $node->meta['rel'] ) ) :
?> rel="<?php echo esc_attr( $node->meta['rel'] );
?>"<?php
endif;
if ( ! empty( $node->meta['lang'] ) ) :
?> lang="<?php echo esc_attr( $node->meta['lang']
); ?>"<?php
endif;
if ( ! empty( $node->meta['dir'] ) ) :
?> dir="<?php echo esc_attr( $node->meta['dir'] );
?>"<?php
endif;
if ( ! empty( $node->meta['data'] ) ) :
foreach ( $node->meta['data'] as $attr => $data )
:
?> data-<?php echo $attr; ?>="<?php echo esc_attr(
$data ); ?>"<?php
endforeach;
endif;
?>><?php
else:
?><div class="ab-item ab-empty-item"<?php echo
$aria_attributes;
if ( ! empty( $node->meta['title'] ) ) :
?> title="<?php echo esc_attr(
$node->meta['title'] ); ?>"<?php
endif;
if ( ! empty( $node->meta['lang'] ) ) :
?> lang="<?php echo esc_attr( $node->meta['lang']
); ?>"<?php
endif;
if ( ! empty( $node->meta['dir'] ) ) :
?> dir="<?php echo esc_attr( $node->meta['dir'] );
?>"<?php
endif;
if ( ! empty( $node->meta['data'] ) ) :
foreach ( $node->meta['data'] as $attr => $data )
:
?> data-<?php echo $attr; ?>="<?php echo
esc_attr( $data ); ?>"<?php
endforeach;
endif;
?>><?php
endif;
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38636>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list