Skip to content

Commit 23ddba8

Browse files
committed
Added Google and ipstack management tabs.
1 parent 99f84ab commit 23ddba8

5 files changed

Lines changed: 437 additions & 3 deletions

File tree

disciple-tools-multisite.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*Plugin Name: Disciple.Tools - Multisite
44
* Plugin URI: https://github.com/DiscipleTools/disciple-tools-multisite
55
* Description: Disciple Tools Multisite plugin adds network administration utilities to the multisite network admin area, helpful for managing Disciple Tools multisite installs.
6-
* Version: 1.8
6+
* Version: 1.9
77
* Author URI: https://github.com/DiscipleTools
88
* GitHub Plugin URI: https://github.com/DiscipleTools/disciple-tools-multisite
99
* Requires at least: 4.7.0
@@ -103,6 +103,8 @@ private function __construct() {
103103
require_once( 'includes/tab-mapbox-keys.php' );
104104
require_once( 'includes/tab-multisite-migration.php' );
105105
require_once( 'includes/tab-movement-maps-stats-plugin.php' );
106+
require_once( 'includes/tab-ipstack.php' );
107+
require_once( 'includes/tab-google.php' );
106108
require_once( 'includes/admin-page.php' );
107109
require_once( 'includes/add-colum-to-sites-list.php' );
108110
}

includes/admin-page.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ function dt_multisite_network_admin_content(){
4545
<?php echo ( $tab == 'mapbox_keys' ) ? esc_attr( 'nav-tab-active' ) : ''; ?>">
4646
<?php echo esc_attr( 'Mapbox Keys' ) ?>
4747
</a>
48+
<a href="<?php echo esc_attr( $link ) . 'google_keys' ?>" class="nav-tab
49+
<?php echo ( $tab == 'google_keys' ) ? esc_attr( 'nav-tab-active' ) : ''; ?>">
50+
<?php echo esc_attr( 'Google Keys' ) ?>
51+
</a>
52+
<a href="<?php echo esc_attr( $link ) . 'ipstack_keys' ?>" class="nav-tab
53+
<?php echo ( $tab == 'ipstack_keys' ) ? esc_attr( 'nav-tab-active' ) : ''; ?>">
54+
<?php echo esc_attr( 'IpStack Keys' ) ?>
55+
</a>
4856
<?php
4957
if ( isset( $plugins_installed['disciple-tools-network-dashboard/disciple-tools-network-dashboard.php'] ) || isset( $mu_plugins['disciple-tools-network-dashboard/disciple-tools-network-dashboard.php'] ) ) {
5058
?>
@@ -85,6 +93,14 @@ function dt_multisite_network_admin_content(){
8593
$object = new DT_Multisite_Tab_Mapbox_Keys();
8694
$object->content();
8795
break;
96+
case "google_keys":
97+
$object = new DT_Multisite_Tab_Google_Keys();
98+
$object->content();
99+
break;
100+
case "ipstack_keys":
101+
$object = new DT_Multisite_Tab_Ipstack_Keys();
102+
$object->content();
103+
break;
88104
case "movement_maps":
89105
$object = new DT_Movement_Maps_Tab_Network_Dashboard();
90106
$object->content();

includes/tab-google.php

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
<?php
2+
if ( ! defined( 'ABSPATH' ) ) {
3+
exit; // Exit if accessed directly
4+
}
5+
6+
/**
7+
* Class DT_Multisite_Tab_Google Map_Keys
8+
*/
9+
class DT_Multisite_Tab_Google_Keys
10+
{
11+
public function content(){
12+
$this->process_post();
13+
?>
14+
<div class="wrap">
15+
<div id="poststuff">
16+
<div id="post-body" class="metabox-holder columns-2">
17+
<div id="post-body-content">
18+
<!-- Main Column -->
19+
20+
<?php $this->list_keys() ?>
21+
22+
<!-- End Main Column -->
23+
</div><!-- end post-body-content -->
24+
<div id="postbox-container-1" class="postbox-container">
25+
<!-- Right Column -->
26+
27+
<?php $this->bulk_key_add() ?>
28+
29+
<?php $this->default_key() ?>
30+
31+
32+
<!-- End Right Column -->
33+
</div><!-- postbox-container 1 -->
34+
<div id="postbox-container-2" class="postbox-container">
35+
</div><!-- postbox-container 2 -->
36+
</div><!-- post-body meta box container -->
37+
</div><!--poststuff end -->
38+
</div><!-- wrap end -->
39+
<?php
40+
}
41+
42+
public function process_post() {
43+
// update
44+
if ( isset( $_POST['google_nonce'] )
45+
&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['google_nonce'] ) ), 'google' ) ) {
46+
47+
if ( isset( $_POST['site_id'] ) && ! empty( $_POST['site_id'] ) ) {
48+
$site_id = sanitize_text_field( wp_unslash( $_POST['site_id'] ) );
49+
50+
if ( isset( $_POST['google_key'] ) && empty( $_POST['google_key'] ) ) {
51+
update_blog_option( $site_id, 'dt_google_map_key', '' );
52+
} else {
53+
update_blog_option( $site_id, 'dt_google_map_key', sanitize_text_field( wp_unslash( $_POST['google_key'] ) ) );
54+
}
55+
}
56+
}
57+
// bulk
58+
if ( isset( $_POST['bulk_google_nonce'] )
59+
&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['bulk_google_nonce'] ) ), 'bulk_google' )
60+
&& isset( $_POST['add_key'] ) && ! empty( $_POST['add_key'] )
61+
) {
62+
$key = sanitize_text_field( wp_unslash( $_POST['add_key'] ) );
63+
64+
global $wpdb;
65+
$sites = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->base_prefix}blogs;" );
66+
if ( ! empty( $sites ) ) {
67+
foreach ( $sites as $site ) {
68+
if ( get_blog_option( $site, 'stylesheet' ) === 'disciple-tools-theme' ) {
69+
$current_key = get_blog_option( $site, 'dt_google_map_key' );
70+
if ( empty( $current_key ) ) {
71+
update_blog_option( $site, 'dt_google_map_key', $key );
72+
}
73+
}
74+
}
75+
}
76+
}
77+
// default
78+
if ( isset( $_POST['default_google_nonce'] )
79+
&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['default_google_nonce'] ) ), 'default_google' )
80+
&& isset( $_POST['default_key'] )
81+
) {
82+
$key = sanitize_text_field( wp_unslash( $_POST['default_key'] ) );
83+
if ( empty( $_POST['default_key'] ) ) {
84+
update_network_option( 1, 'dt_google_map_key', '' );
85+
} else {
86+
update_network_option( 1, 'dt_google_map_key', $key );
87+
}
88+
}
89+
}
90+
91+
public function list_keys(){
92+
global $wpdb;
93+
94+
$sites = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->base_prefix}blogs;" );
95+
$list = [];
96+
$list['count'] = 0;
97+
if ( ! empty( $sites ) ) {
98+
foreach ( $sites as $site ) {
99+
if ( get_blog_option( $site, 'stylesheet' ) === 'disciple-tools-theme' ) {
100+
$dt_setup_options = get_blog_option( $site, "dt_setup_options", [] );
101+
$list[$site] = [];
102+
$list[$site]['url'] = get_blog_option( $site, 'siteurl' );
103+
$list[$site]['google_key'] = get_blog_option( $site, 'dt_google_map_key' );
104+
$list[$site]['locations_upgraded'] = isset( $dt_setup_options["google_upgrade"] );
105+
$list['count']++;
106+
}
107+
}
108+
}
109+
110+
?>
111+
<!-- Box -->
112+
<table class="widefat striped">
113+
<thead>
114+
<tr>
115+
<th>Site Name (<?php echo esc_attr( $list['count'] ) ?>)</th>
116+
<th>Keys</th>
117+
<th></th>
118+
</tr>
119+
</thead>
120+
<tbody>
121+
122+
<?php if ( ! empty( $list ) ) : unset( $list['count'] ); foreach ( $list as $id => $site ) : ?>
123+
<form method="post">
124+
<tr>
125+
<td style="width:30%;">
126+
<?php echo esc_url( $site['url'] ) ?>
127+
</td>
128+
<td>
129+
<?php wp_nonce_field( 'google', 'google_nonce' ) ?>
130+
<input type="hidden" name="site_id" value="<?php echo esc_attr( $id ) ?>" />
131+
<input type="text" class="regular-text" style="width:100%;" value="<?php echo esc_attr( $site['google_key'] ) ?>" name="google_key" placeholder="add google key" />
132+
</td>
133+
<td style="width:10%;">
134+
<button class="button btn" type="submit">Update</button>
135+
</td>
136+
</tr>
137+
</form>
138+
<?php endforeach;
139+
endif; ?>
140+
</tbody>
141+
</table>
142+
<br>
143+
<!-- End Box -->
144+
<?php
145+
}
146+
147+
public function bulk_key_add(){
148+
?>
149+
<!-- Box -->
150+
<form method="post">
151+
<?php wp_nonce_field( 'bulk_google', 'bulk_google_nonce' ) ?>
152+
<table class="widefat striped">
153+
<thead>
154+
<tr>
155+
<th>Add Google Map Key to All Empty Sites</th>
156+
</tr>
157+
</thead>
158+
<tbody>
159+
<tr>
160+
<td>
161+
<input type="text" name="add_key" />
162+
</td>
163+
</tr>
164+
<tr>
165+
<td>
166+
<button class="button btn" type="submit">Add Key to All Empty Fields</button>
167+
</td>
168+
</tr>
169+
</tbody>
170+
</table>
171+
</form>
172+
<br>
173+
<!-- End Box -->
174+
<?php
175+
}
176+
177+
public function default_key(){
178+
$key = get_network_option( 1, 'dt_google_map_key' );
179+
?>
180+
<!-- Box -->
181+
<form method="post">
182+
<?php wp_nonce_field( 'default_google', 'default_google_nonce' ) ?>
183+
<table class="widefat striped">
184+
<thead>
185+
<tr>
186+
<th>Set Default Google Map Key</th>
187+
</tr>
188+
</thead>
189+
<tbody>
190+
<tr>
191+
<td>
192+
<input type="text" name="default_key" value="<?php echo esc_attr( $key ) ?>" />
193+
</td>
194+
</tr>
195+
<tr>
196+
<td>
197+
<button class="button btn" type="submit">Set Default Key</button>
198+
</td>
199+
</tr>
200+
</tbody>
201+
</table>
202+
</form>
203+
<br>
204+
<!-- End Box -->
205+
<?php
206+
}
207+
208+
}

0 commit comments

Comments
 (0)