Skip to content

Commit 7ec47ca

Browse files
committed
Moved several functions to wordpress-toolkit
1 parent e37de45 commit 7ec47ca

2 files changed

Lines changed: 3 additions & 78 deletions

File tree

app/Helpers.php

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,7 @@ public static function show_notice( $msg, $type = 'error', $is_dismissible = fal
2727
}
2828

2929
/**
30-
* Combine function attributes with known attributes and fill in defaults when needed.
31-
*
32-
* @param array $pairs Entire list of supported attributes and their defaults.
33-
* @param array $atts User defined attributes in shortcode tag.
34-
* @return array Combined and filtered attribute list.
35-
* @link https://core.trac.wordpress.org/browser/tags/4.8/src/wp-includes/shortcodes.php#L540 Original source
36-
* @since 0.2.0
37-
*/
38-
public static function set_default_atts( $pairs, $atts ) {
39-
40-
$atts = (array)$atts;
41-
$result = array();
42-
43-
foreach ($pairs as $name => $default) {
44-
if ( array_key_exists($name, $atts) ) {
45-
$result[$name] = $atts[$name];
46-
} else {
47-
$result[$name] = $default;
48-
}
49-
}
50-
51-
return $result;
52-
53-
}
54-
55-
/**
56-
* Merges two array, eliminating duplicates
30+
* Merges two arrays, eliminating duplicates
5731
*
5832
* array_merge_recursive_distinct does not change the datatypes of the values in the arrays.
5933
* Matching keys' values in the second array overwrite those in the first array, as is the
@@ -168,29 +142,4 @@ public static function get_post_categories($as_slugs = false, $post_id = null) {
168142
return $return;
169143
}
170144

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.2.1
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::$config->get( '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.2.1
189-
* @see Helpers::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::$config->get( 'encrypt_method' ), $salt);
194-
}
195-
196145
}

app/Plugin.php

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace VendorName\PluginName;
33
use WordPress_ToolKit\ObjectCache;
44
use WordPress_ToolKit\ConfigRegistry;
5+
use WordPress_ToolKit\Helpers\ArrayHelper;
56
use Carbon_Fields\Container;
67
use Carbon_Fields\Field;
78
use Config;
@@ -122,7 +123,7 @@ private function verify_dependencies( $deps = true, $args = array() ) {
122123
if( is_bool( $deps ) && $deps ) $deps = self::$config->get( 'dependencies' );
123124
if( !is_array( $deps ) ) $deps = array( $deps => self::$config->get( 'dependencies/' . $deps ) );
124125

125-
$args = Helpers::set_default_atts( array(
126+
$args = ArrayHelper::set_default_atts( array(
126127
'echo' => true,
127128
'activate' => true
128129
), $args);
@@ -199,31 +200,6 @@ public function get_plugin_option( $key, $cache = true ) {
199200

200201
}
201202

202-
/**
203-
* Return constant, if defined (with filter validation, if specified)
204-
*
205-
* Example usage:
206-
* echo $this->get_const( 'DB_HOST' ); // MySQL host name
207-
* echo $this->get_const( 'MY_BOOLEAN_CONST', FILTER_VALIDATE_BOOLEAN );
208-
* // null if undefined, true if valid boolean, else false
209-
*
210-
* @param string $const The name of constant to retrieve.
211-
* @param const $filter_validate filter_var() filter to apply (optional).
212-
* Valid values: http://php.net/manual/en/filter.filters.validate.php
213-
* @return mixed Value of constant if specified, else null.
214-
* @since 0.2.0
215-
*/
216-
public static function get_const( $const, $filter_validate = null ) {
217-
218-
if( !defined( $const ) ) {
219-
return null;
220-
} else if( $filter_validate ) {
221-
return filter_var( constant( $const ), $filter_validate);
222-
}
223-
return constant( $const );
224-
225-
}
226-
227203
/**
228204
* A wrapper for the plugin's data fiala prefix as defined in $config
229205
*

0 commit comments

Comments
 (0)