Skip to content

Commit 91c7c9f

Browse files
committed
Added API key sharing with other PDF Forms Filler plugins
1 parent 8fa9cd3 commit 91c7c9f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

modules/pdf-ninja.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,20 @@ public function link()
8383
*/
8484
public function get_key()
8585
{
86+
if( $this->key )
87+
return $this->key;
88+
8689
if( ! $this->key )
8790
$this->key = WPCF7::get_option( 'wpcf7_pdf_forms_pdfninja_key' );
8891

92+
if( ! $this->key )
93+
{
94+
// attempt to get the key from another plugin
95+
$key = $this->get_external_key();
96+
if( $key )
97+
$this->set_key( $key );
98+
}
99+
89100
if( ! $this->key )
90101
{
91102
// don't try to get the key from the API on every page load!
@@ -121,6 +132,24 @@ public function set_key( $value )
121132
return true;
122133
}
123134

135+
/**
136+
* Searches for key in other plugins
137+
*/
138+
public function get_external_key()
139+
{
140+
// from PDF Forms Filler for WPForms
141+
$option = get_option( 'wpforms_settings' );
142+
if( $option !== false && is_array( $option ) && isset( $option['pdf-ninja-api_key'] ) )
143+
return $option['pdf-ninja-api_key'];
144+
145+
// from PDF Forms Filler for WooCommerce
146+
$option = get_option( 'pdf-forms-for-woocommerce-settings-pdf-ninja-api-key' );
147+
if( $option !== false )
148+
return $option;
149+
150+
return null;
151+
}
152+
124153
/*
125154
* Determines administrator's email address (for use with requesting a new key from the API)
126155
*/

0 commit comments

Comments
 (0)