| 1 |
<?php |
| 2 |
/** |
| 3 |
* Insights setup |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace Extendify; |
| 7 |
|
| 8 |
/** |
| 9 |
* Controller for handling various Insights related things. |
| 10 |
*/ |
| 11 |
class Insights |
| 12 |
{ |
| 13 |
|
| 14 |
/** |
| 15 |
* An array of active tests. 'A' should be the control. |
| 16 |
* For weighted tests, try ['A', 'A', 'A', 'A', 'B'] |
| 17 |
* |
| 18 |
* @var array |
| 19 |
*/ |
| 20 |
protected $activeTests = [ |
| 21 |
'remove-dont-see-inputs' => [ |
| 22 |
'A', |
| 23 |
'B', |
| 24 |
], |
| 25 |
]; |
| 26 |
|
| 27 |
/** |
| 28 |
* Process the readme file to get version and name |
| 29 |
* |
| 30 |
* @return void |
| 31 |
*/ |
| 32 |
public function __construct() |
| 33 |
{ |
| 34 |
$this->setUpActiveTests(); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Returns the active tests for the user, and sets up tests as needed. |
| 39 |
* |
| 40 |
* @return void |
| 41 |
*/ |
| 42 |
public function setUpActiveTests() |
| 43 |
{ |
| 44 |
// Make sure that the active tests are set. |
| 45 |
$currentTests = \get_option('extendify_active_tests', []); |
| 46 |
$newTests = array_map(function ($test) { |
| 47 |
// Pick from value randomly. |
| 48 |
return $test[array_rand($test)]; |
| 49 |
}, array_diff_key($this->activeTests, $currentTests)); |
| 50 |
$testsCombined = array_merge($currentTests, $newTests); |
| 51 |
if ($newTests) { |
| 52 |
\update_option('extendify_active_tests', $testsCombined); |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|