Skip to content

Commit

Permalink
Add: Cloudflare Keys Tab (#15)
Browse files Browse the repository at this point in the history
* tab to update cloudflare turnstile keys

* Remove unneeded global

* docs column
  • Loading branch information
corsacca authored Nov 15, 2024
1 parent 4ef6d1a commit dcac57b
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 1 deletion.
3 changes: 2 additions & 1 deletion disciple-tools-multisite.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ private function __construct() {
require_once( 'includes/tab-google.php' );
require_once( 'includes/admin-page.php' );
require_once( 'includes/add-colum-to-sites-list.php' );
require_once( 'includes/sso-login.php' );
require_once( 'includes/tab-sso-login.php' );
require_once( 'includes/tab-cloudflare.php' );
}

if ( is_admin() || is_network_admin() ) {
Expand Down
8 changes: 8 additions & 0 deletions includes/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ function dt_multisite_network_admin_content(){
<?php echo ( $tab == 'sso-login' ) ? 'nav-tab-active' : ''; ?>">
SSO Login
</a>
<a href="<?php echo esc_attr( $link ) . 'cloudflare' ?>" class="nav-tab
<?php echo ( $tab == 'cloudflare' ) ? 'nav-tab-active' : ''; ?>">
Cloudflare
</a>

</h2>

Expand Down Expand Up @@ -113,6 +117,10 @@ function dt_multisite_network_admin_content(){
$object = new DT_Movement_Maps_Tab_Network_Dashboard();
$object->content();
break;
case 'cloudflare':
$object = new DT_Multisite_Tab_Cloudflare();
$object->content();
break;

default:
break;
Expand Down
115 changes: 115 additions & 0 deletions includes/tab-cloudflare.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

/**
* Class DT_Multisite_Tab_Google Map_Keys
*/
class DT_Multisite_Tab_Cloudflare
{
public function content(){
$this->process_post();
?>
<div class="wrap">
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content">
<!-- Main Column -->

<?php $this->list_keys() ?>

<!-- End Main Column -->
</div><!-- end post-body-content -->
<div id="postbox-container-1" class="postbox-container">
<!-- Right Column -->

<?php $this->documentation() ?>

<!-- --><?php //$this->default_key() ?>


<!-- End Right Column -->
</div><!-- postbox-container 1 -->
<div id="postbox-container-2" class="postbox-container">
</div><!-- postbox-container 2 -->
</div><!-- post-body meta box container -->
</div><!--poststuff end -->
</div><!-- wrap end -->
<?php
}

public function process_post() {
// update
if ( isset( $_POST['cloudflare_nonce'] )
&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cloudflare_nonce'] ) ), 'cloudflare' ) ) {

update_site_option( 'dt_cloudflare_site_key', sanitize_text_field( wp_unslash( $_POST['dt_cloudflare_site_key'] ?? '' ) ) );
update_site_option( 'dt_cloudflare_secret_key', sanitize_text_field( wp_unslash( $_POST['dt_cloudflare_secret_key'] ?? '' ) ) );
}
}

public function list_keys(){
$network_cloudflare_site_key = get_site_option( 'dt_cloudflare_site_key', '' );
$network_cloudflare_secret_key = get_site_option( 'dt_cloudflare_secret_key', '' );

?>
<!-- Box -->
<form method="post">
<?php wp_nonce_field( 'cloudflare', 'cloudflare_nonce' ) ?>
<table class="widefat striped">
<thead>
<tr>
<th>Option</th>
<th>Keys</th>
</tr>
</thead>
<tbody>
<tr>
<td style="width:30%;">
Cloudflare Turnstile Site Key
</td>
<td>
<input type="text" class="regular-text" style="width:100%;" value="<?php echo esc_attr( $network_cloudflare_site_key ) ?>" name="dt_cloudflare_site_key" placeholder="add site key" />
</td>
</tr>
<tr>
<td style="width:30%;">
Cloudflare Turnstile Secret Key
</td>
<td>
<input type="password" class="regular-text" style="width:100%;" value="<?php echo esc_attr( $network_cloudflare_secret_key ) ?>" name="dt_cloudflare_secret_key" placeholder="add secret key" />
</td>
</tr>
<tr>
<td style="width:10%;">
<button class="button btn" type="submit">Update</button>
</td>
<td></td>
</tr>
</tbody>
</table>
</form>
<br>
<!-- End Box -->
<?php
}

public function documentation(){
?>
<!-- Box -->
<div class="postbox">
<h3 class="hndle">Documentation</h3>
<div class="inside">
<p>
<?php esc_html_e( 'Cloudflare Turnstile is a security feature that helps protect your website from spam and abuse. It is a free service that requires a site key and a secret key.', 'disciple-tools' ) ?>
</p>
<p>
See <a href="https://developers.cloudflare.com/turnstile/get-started/client-side-rendering/">Turnstile Documentation</a>
</p>
</div>
</div>
<!-- End Box -->
<?php
}
}
File renamed without changes.

0 comments on commit dcac57b

Please sign in to comment.