Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 3 |
CRAP | n/a |
0 / 0 |
|
| Automattic\Jetpack\Launchpad\get_goals_default_checklist_slug | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| Automattic\Jetpack\Launchpad\get_checklist_slug_by_goals | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
110 | |||
| Automattic\Jetpack\Launchpad\contains_any | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Functions pertaining to Launchpad task lists, where the tasks depend |
| 4 | * on a site's goals; as choosen by the user during onboarding. |
| 5 | * |
| 6 | * @package automattic/jetpack-mu-wpcom |
| 7 | */ |
| 8 | |
| 9 | namespace Automattic\Jetpack\Launchpad; |
| 10 | |
| 11 | /** |
| 12 | * Checklist slug to use when the user chose no goals, or the chosen goals |
| 13 | * don't have a corresponding checklist. |
| 14 | * |
| 15 | * @return string |
| 16 | */ |
| 17 | function get_goals_default_checklist_slug() { |
| 18 | return 'build'; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Given a set of goals, which checklist is best for the user. The checklist |
| 23 | * slugs are those returned by the wpcom_launchpad_get_task_list_definitions() |
| 24 | * function in launchpad.php. |
| 25 | * |
| 26 | * The algorithm in this function shouldn't be considered final: expect it to |
| 27 | * change over time as we receive feedback and analytics on which checklists |
| 28 | * are successful for which goals. |
| 29 | * |
| 30 | * @param array $goals Array of goal slugs. |
| 31 | * @param array $enable_checklist_for_goals Used by the client to signal to Jetpack which launchpad goals have been enabled (e.g. via feature flags)'. |
| 32 | * |
| 33 | * @return string |
| 34 | */ |
| 35 | function get_checklist_slug_by_goals( $goals, $enable_checklist_for_goals ) { |
| 36 | if ( empty( $goals ) ) { |
| 37 | return get_goals_default_checklist_slug(); |
| 38 | } |
| 39 | |
| 40 | if ( count( $goals ) >= 3 ) { |
| 41 | // If the user chooses too many goals we're not as confident we know |
| 42 | // exactly what they think is most important. A general checklist |
| 43 | // could be best. |
| 44 | return get_goals_default_checklist_slug(); |
| 45 | } |
| 46 | |
| 47 | if ( in_array( 'courses', $enable_checklist_for_goals, true ) ) { |
| 48 | if ( in_array( 'courses', $goals, true ) ) { |
| 49 | return 'create-course-goal'; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if ( in_array( 'newsletter', $enable_checklist_for_goals, true ) ) { |
| 54 | if ( in_array( 'newsletter', $goals, true ) ) { |
| 55 | return 'intent-newsletter-goal'; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if ( contains_any( $goals, 'sell', 'sell-digital', 'sell-physical' ) ) { |
| 60 | return 'sell'; |
| 61 | } |
| 62 | |
| 63 | if ( in_array( 'promote', $goals, true ) ) { |
| 64 | return 'build'; |
| 65 | } |
| 66 | |
| 67 | if ( in_array( 'write', $goals, true ) ) { |
| 68 | return 'write'; |
| 69 | } |
| 70 | |
| 71 | return get_goals_default_checklist_slug(); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * The string_list must contain any of the provided strings. |
| 76 | * |
| 77 | * @param array $string_list The list of strings to check. |
| 78 | * @param string ...$strings_to_check The strings to check for. |
| 79 | * @return bool |
| 80 | */ |
| 81 | function contains_any( $string_list, ...$strings_to_check ) { |
| 82 | foreach ( $strings_to_check as $s ) { |
| 83 | if ( in_array( $s, $string_list, true ) ) { |
| 84 | return true; |
| 85 | } |
| 86 | } |
| 87 | return false; |
| 88 | } |