add_node( [
'id' => HELPDOCS_TEXTDOMAIN,
'title' => '',
'href' => helpdocs_plugin_options_path( 'documentation' ),
'meta' => [
'target' => '_blank'
],
] );
// Start the args to get the docs
$args = [
'posts_per_page' => -1,
'post_status' => 'publish',
'post_type' => 'help-docs',
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
[
'key' => HELPDOCS_GO_PF.'site_location',
'value' => base64_encode( 'admin_bar' ),
'compare' => '='
]
]
];
// Get the posts
$docs = get_posts( $args );
// Also get the imports
$imports = helpdocs_get_imports( $args );
// Merge them together
if ( !empty( $imports ) ) {
$docs = array_merge( $docs, $imports );
}
// Check if we found docs
if ( !empty( $docs ) ) {
// First we sort by the doc order
usort( $docs, function( $a, $b ) { return strcmp( $a->helpdocs_order, $b->helpdocs_order ) ; } );
// Iter the docs
foreach ( $docs as $key => $doc ) {
// Add content
if ( filter_var( trim( $doc->post_content ), FILTER_VALIDATE_URL) ) {
$href = trim( $doc->post_content );
$incl_content = '';
} elseif ( trim( $doc->post_content ) != '' ) {
$href = false;
$incl_content = ' — '.esc_html( wp_strip_all_tags( $doc->post_content ) );
} else {
$href = false;
$incl_content = '';
}
// The node array
$node = [
'id' => HELPDOCS_GO_PF.$key,
'parent' => HELPDOCS_TEXTDOMAIN,
'title' => esc_html( $doc->post_title ).$incl_content,
'meta' => [
'target' => '_blank'
],
];
// Are we making it a link?
if ( $href ) {
$node[ 'href' ] = $href;
}
// Add the node
$wp_admin_bar->add_node( $node );
}
}
// CSS
echo '';
} // End admin_bar()
}