-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgp-remove-projects-from-breadcrumbs.php
More file actions
113 lines (86 loc) · 3.77 KB
/
gp-remove-projects-from-breadcrumbs.php
File metadata and controls
113 lines (86 loc) · 3.77 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/*
Plugin Name: GP Remove Projects from Breadcrumbs
Plugin URI: http://glot-o-matic.com/gp-remove-projects-from-breadcrumbs
Description: Remove the "Projects" link from the breadcrumbs in GlotPress
Version: 1.0
Author: Greg Ross
Author URI: http://toolstack.com
Tags: glotpress, glotpress plugin
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
class GP_Remove_Projects_From_Breadcrumbs {
public $id = 'gp-remove-projects-from-breadcrumbs';
public $errors = array();
public $notices = array();
public function __construct() {
add_action( 'gp_breadcrumb_items', array( $this, 'gp_breadcrumb_items'), 10, 1 );
add_action( 'gp_nav_menu_items', array( $this, 'gp_nav_menu_items' ), 10, 2 );
add_filter( 'gp_home_title', array( $this, 'gp_home_title' ), 10, 1 );
// Add the admin page to the WordPress settings menu.
add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 1 );
}
public function gp_breadcrumb_items( $breadcrums ) {
if( is_array( $breadcrums ) ) {
if( is_array( $breadcrums[0] ) ) {
unset( $breadcrums[0][0] );
}
else {
unset( $breadcrums[0] );
}
}
return $breadcrums;
}
public function gp_nav_menu_items( $items, $locaiton ) {
$as = array_search( __('Projects'), $items );
if( $as !== FALSE ) { unset( $items[$as] ); }
return $items;
}
public function gp_home_title( $title ) {
return $title . '<script type="text/javascript">jQuery(\'a[rel="home"\').attr("href", "' . gp_url_project( get_option( 'gp_rpfbc_logo_project' ) ) . '")</script>';
}
// This function adds the admin settings page to WordPress.
public function admin_menu() {
add_options_page( __('GlotPress Remove Projects from Breadcrumbs'), __('GlotPress Remove Projects from Breadcrumbs'), 'manage_options', basename( __FILE__ ), array( $this, 'admin_page' ) );
}
// This function displays the admin settings page in WordPress.
public function admin_page() {
// If the current user can't manage options, display a message and return immediately.
if( ! current_user_can( 'manage_options' ) ) { _e('You do not have permissions to this page!'); return; }
// If the user has saved the settings, commit them to the database.
if( array_key_exists( 'save_gp_rpfbc', $_POST ) ) {
// If the API key value is being saved, store it in the global key setting.
if( array_key_exists( 'gp_rpfbc_logo_project', $_POST ) ) {
// Make sure to sanitize the data before saving it.
$this->key = sanitize_text_field( $_POST['gp_rpfbc_logo_project'] );
}
// Update the option in the database.
update_option( 'gp_rpfbc_logo_project', $this->key );
}
?>
<div class="wrap">
<h2><?php _e('GlotPress Remove Projects from Breadcrumbs');?></h2>
<form method="post" action="options-general.php?page=gp-remove-projects-from-breadcrumbs.php" >
<table class="form-table">
<tr>
<th><label for="gp_rpfbc_logo_project"><?php _e('Project Slug');?></label></th>
<td>
<input type="text" id="gp_rpfbc_logo_project" name="gp_rpfbc_logo_project" size="40" value="<?php echo htmlentities( get_option( 'gp_rpfbc_logo_project' ) );?>">
<p class="description"><?php _e('Enter project slug to use for the logo url (leave blank to use the default).');?></p>
</td>
</tr>
</table>
<?php submit_button( __('Save'), 'primary', 'save_gp_rpfbc' ); ?>
</form>
</div>
<?php
}
}
// Add an action to WordPress's init hook to setup the plugin. Don't just setup the plugin here as the GlotPress plugin may not have loaded yet.
add_action( 'gp_init', 'gp_remove_projects_from_breadcrumbs_init' );
// This function creates the plugin.
function gp_remove_projects_from_breadcrumbs_init() {
GLOBAL $gp_remove_projects_from_breadcrumbs;
$gp_remove_projects_from_breadcrumbs = new GP_Remove_Projects_From_Breadcrumbs;
}