Skip to content

Commit 7994c49

Browse files
committed
Initial commit.
0 parents  commit 7994c49

4 files changed

Lines changed: 121 additions & 0 deletions

File tree

GlotPress-Logo-20px.png

945 Bytes
Loading

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# GlotPress Additional Links
2+
A plugin for [GlotPress as a WordPress plugin](https://github.com/deliciousbrains/GlotPress) that adds a link to the WordPress dashboard for admins in the GlotPress page as well as a link to the GlotPress page in the WordPress admin menu.
3+

gp-additional-links.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/*
3+
Plugin Name: GlotPress Additional Links
4+
Plugin URI: http://glotpress.org/
5+
Description: Add additional links to the GlotPress side menu and the WordPress admin menu.
6+
Version: 0.5
7+
Author: GlotPress
8+
Author URI: http://glotpress.org
9+
Tags: glotpress, glotpress plugin, translate
10+
License: GPLv2 or later
11+
*/
12+
13+
class GP_Additional_Links {
14+
public $id = 'additional-links';
15+
16+
public function __construct() {
17+
18+
// Check to see if there is a user currently logged in.
19+
if ( is_user_logged_in() ) {
20+
// If someone is logged in, get their user object.
21+
$user_obj = wp_get_current_user();
22+
23+
// Load the user translate key from the WordPress user meta table, using the currently logged in user id.
24+
$user_key = get_user_meta( $user_obj->id, 'gp_google_translate_key', true );
25+
26+
// If there is a user key, override the global key.
27+
if( $user_key ) { $this->key = $user_key; }
28+
}
29+
30+
// Add the dashboard link to the side menu.
31+
add_filter( 'gp_nav_menu_items', array( $this, 'gp_nav_menu_items' ), 10, 2 );
32+
33+
// Add the admin page to the WordPress settings menu.
34+
add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 1 );
35+
}
36+
37+
public function gp_nav_menu_items( $items, $location ) {
38+
$new = array();
39+
40+
if( $location == 'side' ) {
41+
$new[admin_url()] = __('Dashboard');
42+
}
43+
44+
return array_merge( $new, $items );
45+
}
46+
47+
// This function adds the admin settings page to WordPress.
48+
public function admin_menu() {
49+
GLOBAL $menu;
50+
51+
$image = plugins_url( '/GlotPress-Logo-20px.png', __FILE__ );
52+
53+
// Add the menu to the admin menu.
54+
add_menu_page(__('GlotPress'), __('GlotPress'), 'read', __FILE__, array( $this, 'redirect_to_glotpress'), $image, 1 );
55+
56+
// We're going to hack the menu info to use a link to the front end instead of calling the 'redirect_to_glotpress' function so we save a page load.
57+
foreach( $menu as $tag => $mi ) {
58+
if( $mi[0] == __( 'GlotPress' ) ) {
59+
$menu[$tag][2] = gp_url_public_root();
60+
}
61+
}
62+
63+
}
64+
65+
public function redirect_to_glotpress() {
66+
// Just a placeholder, we're going to replace the function call with a real link in the menu_order hook.
67+
}
68+
}
69+
70+
// 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.
71+
add_action( 'gp_init', 'gp_additional_links_init' );
72+
73+
// This function creates the plugin.
74+
function gp_additional_links_init() {
75+
GLOBAL $gp_additional_links;
76+
77+
$gp_additional_links = new GP_Additional_Links;
78+
}

readme.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=== GP Additional Links ===
2+
Contributors: gregross
3+
Donate link: http://toolstack.com/donate
4+
Plugin URI: http://glot-o-matic.com/gp-additional-links
5+
Author URI: http://toolstack.com
6+
Tags: translation, glotpress
7+
Requires at least: 4.4
8+
Tested up to: 4.4
9+
Stable tag: 0.5
10+
License: GPLv2
11+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
12+
13+
A plugin for [GlotPress as a WordPress plugin](https://github.com/deliciousbrains/GlotPress) that adds a link to the WordPress dashboard for admins in the GlotPress page as well as a link to the GlotPress page in the WordPress admin menu.
14+
15+
== Description ==
16+
17+
A plugin for [GlotPress as a WordPress plugin](https://github.com/deliciousbrains/GlotPress) that adds a link to the WordPress dashboard for admins in the GlotPress page as well as a link to the GlotPress page in the WordPress admin menu.
18+
19+
== Installation ==
20+
21+
Install from the WordPress plugin directory.
22+
23+
== Frequently Asked Questions ==
24+
25+
= TBD =
26+
27+
TBD
28+
29+
== Changelog ==
30+
31+
= 1.0 =
32+
* Release Date: TBD
33+
* Initial release.
34+
35+
== Upgrade Notice ==
36+
37+
= 1.0 =
38+
39+
Initial release, no upgrade notes at this time.
40+

0 commit comments

Comments
 (0)