-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdl-edit-post-breadcrumbs.php
56 lines (46 loc) · 1.87 KB
/
fdl-edit-post-breadcrumbs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Plugin Name: WordPress Admin Edit Post Breadcrumbs.
* Version: 1.0
* Plugin URI: https://github.com/marconmartins/fdl-edit-post-breadcrumbs
* Description: Add breadcrumbs with edit links to the WordPress admin edit post screen.
* Author: marcomartins
* Author URI: http://fimdalinha.com
* Text Domain: fdl-wpadmin-edit-post-breadcrumbs
* Domain Path: /languages/
* License: GPL v2 or later
*/
/**
* Add breadcrumbs with edit links to the admin post edit screen.
*
* @param WP_Post $post The post currently being edited.
* @return void
*/
function fdl_wpadmin_edit_post_breadcrumbs( $post ) {
$breadcrumbs = array();
$output = '';
$ancestors = get_post_ancestors( $post );
foreach ( array_reverse( $ancestors ) as $ancestor ) {
$breadcrumbs[] = '<a href="' . get_edit_post_link( $post ) . '">' . get_the_title( $ancestor ) . '</a>';
}
// Join the ancestor edit links and the current page title into breadcrumb links.
if ( count( $breadcrumbs ) > 0 ) {
$breadcrumbs[] = $post->post_title;
$output .= '<div class="fdl-wpadmin-edit-post-breadcrumbs">';
$output .= __( 'Path:', 'fdl-wpadmin-edit-post-breadcrumbs' ) . ' ' . implode( ' » ', $breadcrumbs ) . '<br><br>';
$output .= '</div>';
}
/**
* Filter the breadcrumbs html output.
*
* @param string $output The breadcrumb links in HTML.
* @param array $ancestors Array of IDs or empty if no ancestors are found. The
* direct parent is returned as the first value in
* the array. The highest level ancestor is returned
* as the last value in the array.
* @param WP_Post $post The Post being edited.
*/
$output = apply_filters( 'fdl_wpadmin_edit_post_breadcrumbs_output', $output, $ancestors, $post );
echo $output;
}
add_action( 'edit_form_top', 'fdl_wpadmin_edit_post_breadcrumbs' );