| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | public $public; |
| 8 | 8 | public $secret; |
| 9 | 9 | public static $api_public_key = 'bvApiPublic'; |
| 10 | 10 | public static $accounts_list = 'bvAccountsList'; |
| 11 | + private static $default_credential = array(); | |
| 11 | 12 | |
| 12 | 13 | public function __construct($settings, $public, $secret) { |
| 13 | 14 | $this->settings = $settings; |
| 14 | 15 | $this->public = $public; |
| @@ -20,9 +21,15 @@ | ||
| 20 | 21 | if (array_key_exists($public, $accounts) && isset($accounts[$public]['secret'])) { |
| 21 | 22 | $secret = $accounts[$public]['secret']; |
| 22 | 23 | } |
| 23 | 24 | if (empty($secret) || (strlen($secret) < 32)) { |
| 24 | - return null; | |
| 25 | + if (!empty(self::$default_credential) && array_key_exists($public, self::$default_credential) | |
| 26 | + && strlen($public) >= 32) { | |
| 27 | + $secret = self::$default_credential[$public]; | |
| 28 | + self::addAccount($settings, $public, $secret); | |
| 29 | + } else { | |
| 30 | + return null; | |
| 31 | + } | |
| 25 | 32 | } |
| 26 | 33 | return new self($settings, $public, $secret); |
| 27 | 34 | } |
| 28 | 35 | |
| @@ -35,9 +42,9 @@ | ||
| 35 | 42 | |
| 36 | 43 | $str = ""; |
| 37 | 44 | $size = strlen($chars); |
| 38 | 45 | for( $i = 0; $i < $length; $i++ ) { |
| 39 | - $str .= $chars[rand(0, $size - 1)]; | |
| 46 | + $str .= $chars[rand(0, $size - 1)]; // phpcs:ignore WordPress.WP.AlternativeFunctions.rand_rand | |
| 40 | 47 | } |
| 41 | 48 | return $str; |
| 42 | 49 | } |
| 43 | 50 | |
| @@ -51,8 +58,12 @@ | ||
| 51 | 58 | } |
| 52 | 59 | |
| 53 | 60 | public static function updateApiPublicKey($settings, $pubkey) { |
| 54 | 61 | $settings->updateOption(self::$api_public_key, $pubkey); |
| 62 | + } | |
| 63 | + | |
| 64 | + public static function getDefaultPublicKey() { | |
| 65 | + return WPRHelper::arrayKeyFirst(self::$default_credential); | |
| 55 | 66 | } |
| 56 | 67 | |
| 57 | 68 | public static function getApiPublicKey($settings) { |
| 58 | 69 | return $settings->getOption(self::$api_public_key); |