display-conditions
5 months ago
front
2 days ago
helpers
1 month ago
metas
3 months ago
multisite
5 months ago
palettes
3 years ago
provider
1 month ago
providers
2 days ago
templates
3 years ago
update
5 months ago
class-hustle-admin-page-abstract.php
1 month ago
class-hustle-auth-token.php
5 months ago
class-hustle-condition-factory.php
6 years ago
class-hustle-cross-sell.php
10 months ago
class-hustle-dashboard-admin.php
1 month ago
class-hustle-data.php
1 month ago
class-hustle-db.php
2 years ago
class-hustle-installer.php
4 years ago
class-hustle-meta.php
3 years ago
class-hustle-module-admin.php
1 month ago
class-hustle-module-collection.php
5 months ago
class-hustle-module-fields.php
3 months ago
class-hustle-module-page-abstract.php
1 month ago
class-hustle-module-validator.php
3 months ago
class-hustle-notifications.php
2 days ago
class-hustle-settings-admin.php
1 month ago
class-hustle-wp-dashboard-page.php
5 months ago
class-opt-in.php
2 days ago
hustle-background-conversion-log.php
3 months ago
hustle-deletion.php
3 months ago
hustle-embedded-admin.php
3 years ago
hustle-entries-admin.php
5 months ago
hustle-entry-model.php
1 month ago
hustle-general-data-protection.php
5 months ago
hustle-init.php
1 month ago
hustle-mail.php
5 months ago
hustle-migration.php
5 months ago
hustle-model.php
2 days ago
hustle-module-model.php
1 month ago
hustle-module-widget-legacy.php
5 months ago
hustle-module-widget.php
5 months ago
hustle-modules-common-admin-ajax.php
1 month ago
hustle-popup-admin.php
3 years ago
hustle-providers-admin.php
1 month ago
hustle-providers.php
5 months ago
hustle-settings-admin-ajax.php
1 month ago
hustle-settings-page.php
3 years ago
hustle-slidein-admin.php
3 years ago
hustle-sshare-admin.php
2 days ago
hustle-sshare-model.php
2 days ago
hustle-tracking-model.php
3 months ago
interface-hustle-auth-provider.php
5 months ago
opt-in-geo.php
5 months ago
opt-in-utils.php
2 days ago
opt-in-wpmudev-api.php
5 months ago
class-hustle-condition-factory.php
45 lines
| 1 | <?php |
| 2 | /** |
| 3 | * File for Hustle_Condition_Factory class. |
| 4 | * |
| 5 | * @package Hustle |
| 6 | * @since unknwon |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Factory to instantiate display conditions |
| 11 | * |
| 12 | * Class Hustle_Condition_Factory |
| 13 | */ |
| 14 | class Hustle_Condition_Factory { |
| 15 | |
| 16 | /** |
| 17 | * Callback to use with preg_replace_callback in self::build |
| 18 | * |
| 19 | * @param array $matches Matches. |
| 20 | * @return string |
| 21 | */ |
| 22 | private static function preg_replace_callback( $matches ) { |
| 23 | return $matches[1] . ucfirst( $matches[2] ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Instantiates and returns instance of Opt_In_Condition_Abstract |
| 28 | * |
| 29 | * @param string $condition_key Condition slug. |
| 30 | * @param array $args Arguments for the condition. |
| 31 | * @return Opt_In_Condition_Abstract |
| 32 | */ |
| 33 | public static function build( $condition_key, $args ) { |
| 34 | $class = 'Opt_In_Condition_' . preg_replace_callback( |
| 35 | '/(\\_)([A-Za-z]+)/ui', |
| 36 | array( __CLASS__, 'preg_replace_callback' ), |
| 37 | ucfirst( $condition_key ) |
| 38 | ); |
| 39 | |
| 40 | return ( class_exists( $class ) ) |
| 41 | ? new $class( $args ) |
| 42 | : false; |
| 43 | } |
| 44 | } |
| 45 |