Skip to content

Commit 1d31625

Browse files
committed
Added Utils::encrypt/decrypt, WP_ENCRYPT_KEY
1 parent be3bd1e commit 1d31625

5 files changed

Lines changed: 32 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ Release changes are noted on the [Releases](https://github.com/dmhendricks/wordp
5959
* Bumped minimum PHP version check to 5.4
6060
* Added initial `plugin.json` for configuration
6161
* Fixed caching expiration bug
62-
* Removed Carbon Fields as dependency in favor of [plugin](https://github.com/dmhendricks/carbon-fields-loader)
62+
* Removed Carbon Fields as dependency in favor of [plugin](https://github.com/dmhendricks/carbon-fields-loader) loader
63+
* Added Utils::encrypt/decrypt helpers, `WP_ENCRYPT_KEY` constant
6364

6465
## Credits
6566

app/Plugin.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ function __construct( $_settings ) {
1515
$plugin_config = new Config\Config( $_settings['path'] . 'plugin.json' );
1616
self::$textdomain = $_settings['data']['TextDomain'];
1717
self::$settings = array_merge( $_settings, $plugin_config->get() );
18-
//var_dump(self::$settings); exit;
1918

2019
// Verify dependecies and load plugin logic
2120
register_activation_hook( self::$settings['plugin_file'], array( $this, 'activate' ) );

app/Utils.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,29 @@ public static function get_post_categories($as_slugs = false, $post_id = null) {
168168
return $return;
169169
}
170170

171+
/**
172+
* Encrypts string using WP_ENCRYPT_KEY as salt if defined, else SECURE_AUTH_KEY.
173+
*
174+
* @param string $str String to encrypt
175+
* @return string Encrypted string
176+
* @since 0.3.0
177+
*/
178+
public static function encrypt( $str ) {
179+
$salt = defined( 'WP_ENCRYPT_KEY' ) && WP_ENCRYPT_KEY ? WP_ENCRYPT_KEY : SECURE_AUTH_KEY;
180+
return openssl_encrypt($str, self::$settings['encrypt_method'], $salt);
181+
}
182+
183+
/**
184+
* Decrypts encrypted string
185+
*
186+
* @param string $str String to decrypt
187+
* @return string Decrypted string
188+
* @since 0.3.0
189+
* @see Utils::encrypt()
190+
*/
191+
public static function decrypt( $str ) {
192+
$salt = defined( 'WP_ENCRYPT_KEY' ) && WP_ENCRYPT_KEY ? WP_ENCRYPT_KEY : SECURE_AUTH_KEY;
193+
return openssl_decrypt($str, self::$settings['encrypt_method'], $salt);
194+
}
195+
171196
}

plugin.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"dependencies": {
88
"php": "5.4.0",
99
"carbon_fields": "2.0"
10-
}
10+
},
11+
"encrypt_method": "AES-128-ECB"
1112
}

wordpress-base-plugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin Name: WordPress Base Plugin
55
* Plugin URI: https://github.com/dmhendricks/wordpress-base-plugin
66
* Description: A boilerplate for WordPress plugins
7-
* Version: 0.2.0
7+
* Version: 0.3.0
88
* Author: Daniel M. Hendricks
99
* Author URI: https://www.danhendricks.com
1010
* License: GPL-2.0
@@ -35,9 +35,9 @@
3535
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
3636

3737
// Initialize plugin - Change to use your own namespace
38-
new \VendorName\MyPlugin\Plugin(array(
38+
new \VendorName\MyPlugin\Plugin( array(
3939
'data' => get_plugin_data( __FILE__ ),
4040
'path' => trailingslashit( realpath( plugin_dir_path( __FILE__ ) ) ),
4141
'url' => plugin_dir_url( __FILE__ ),
4242
'plugin_file' => plugin_basename( __FILE__ )
43-
));
43+
) );

0 commit comments

Comments
 (0)