Skip to content

Commit

Permalink
Merge pull request #30 from JarrydLong/nginx-prompt
Browse files Browse the repository at this point in the history
Nginx Config Prompt
  • Loading branch information
andrewlimaza authored May 6, 2021
2 parents cabea18 + 8f1700b commit 45410e1
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
31 changes: 29 additions & 2 deletions includes/general-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ function pmpro_pdf_invoice_settings_page() {
<?php } ?>
</td>
</tr>
<?php } ?>
<?php } ?>

</tbody>
</table>
<?php submit_button(); ?>
Expand Down Expand Up @@ -318,6 +319,33 @@ function pmpro_pdf_invoice_settings_page() {
<small><em>Please leave this window open while processing</em></small>
<br><br>
<button class='button generate_missing_logs'>Generate</button>
<?php

$user_id = get_current_user_id();
if( ( !empty( $_SERVER['SERVER_SOFTWARE'] ) && strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false ) ){

$upload_dir = wp_upload_dir();

$baseurl = str_replace( site_url(), '', $upload_dir['baseurl'] );

$invoice_dir = $baseurl . '/pmpro-invoices/';

$access_key = pmpropdf_get_rewrite_token();

?>
<br/><br/>
<div class="pmpro-pdf-invoices-nginx-notice">
<strong><?php _e('Nginx Detected', 'pmpro-pdf-invoices'); ?></strong>
<p><?php _e('We detected that your installation is running on Nginx. To protect generated invoices that are stored on your web server, the following Nginx rule should be added to your Nginx WordPress installation config file.', 'pmpro-pdf-invoices' ); ?></p>
<p><code>
location <?php echo $invoice_dir; ?> {
if ($query_string !~ "access=<?php echo $access_key; ?>"){
return 403;
}
}
</code></p>
</div>
<?php } ?>

<br><br>
<strong>Archives</strong>
Expand All @@ -327,7 +355,6 @@ function pmpro_pdf_invoice_settings_page() {

<br><br>
<small><em>Click the button above to download all stored invoices as a ZIP file. Alternatively individual files can be downloaded from the orders page</em></small>

</div>

<div class='wp-editor-container pmpropdf_option_section' data-tab='2'>
Expand Down
51 changes: 50 additions & 1 deletion pmpro-pdf-invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,54 @@ function pmpropdf_footer_note ($footnote){

add_filter('admin_footer_text', 'pmpropdf_footer_note', 10, 1);


function pmpropdf_nginx_notice () {

$user_id = get_current_user_id();

if( current_user_can( 'manage_options' ) &&
intval( get_user_meta( $user_id, 'pmpropdf_nginx_dismissed', true ) ) == false &&
( !empty( $_SERVER['SERVER_SOFTWARE'] ) && strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false )
){

$upload_dir = wp_upload_dir();

$baseurl = str_replace( site_url(), '', $upload_dir['baseurl'] );

$invoice_dir = $baseurl . '/pmpro-invoices/';

$access_key = pmpropdf_get_rewrite_token();

?>
<div class="updated">
<h2><?php _e('Paid Memberships Pro - PDF Invoices - Nginx Detected', 'pmpro-pdf-invoices'); ?></h2>
<p><?php _e('We detected that your installation is running on Nginx. To protect generated invoices that are stored on your web server, the following Nginx rule should be added to your Nginx WordPress installation config file.', 'pmpro-pdf-invoices' ); ?></p>
<p><code>
location <?php echo $invoice_dir; ?> {
if ($query_string !~ "access=<?php echo $access_key; ?>"){
return 403;
}
}
</code></p>
<p><a class='button button-primary' id="pmpropdf_nginx_prompt" href="<?php echo admin_url( '?pmpropdf_nginx=dismiss' ); ?>"><?php _e("I've Added The Nginx Rule", "pmpro-pdf-invoices"); ?></a></p>
</div>
<?php
}
}
add_action( 'admin_notices', 'pmpropdf_nginx_notice' );

function pmpropdf_dismiss_nginx_notice(){

if( !empty( $_REQUEST['pmpropdf_nginx'] ) && $_REQUEST['pmpropdf_nginx'] == 'dismiss' ){
if( current_user_can( 'manage_options' ) ){
$user_id = get_current_user_id();
update_user_meta( $user_id, 'pmpropdf_nginx_dismissed', 1 );
}
}

}
add_action( 'admin_init', 'pmpropdf_dismiss_nginx_notice' );

/**
* Get the template content
*
Expand Down Expand Up @@ -766,4 +814,5 @@ function pmpropdf_updated_order( $order ) {
$path = pmpropdf_generate_pdf($order);
}
}
add_action( 'pmpro_updated_order', 'pmpropdf_updated_order', 99, 1);
add_action( 'pmpro_updated_order', 'pmpropdf_updated_order', 99, 1);

0 comments on commit 45410e1

Please sign in to comment.