-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass-main.php
112 lines (92 loc) · 3.22 KB
/
class-main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package 3rd-party-autoresponder
*/
namespace Thrive\ThirdPartyAutoResponderDemo;
use Thrive\ThirdPartyAutoResponderDemo\AutoResponders\Autoresponder;
defined( 'THRIVE_THIRD_PARTY_PLUGIN_URL' ) || define( 'THRIVE_THIRD_PARTY_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
/**
* Class Main
* @package Thrive\ThirdPartyAutoresponderDemo
*/
class Main {
public static $registered_autoresponders = [];
public static function init() {
static::includes();
static::register_autoresponder( 'clever-reach', 'Thrive\ThirdPartyAutoResponderDemo\AutoResponders\CleverReach\Main' );
static::add_hooks();
}
public static function add_hooks() {
if ( empty( static::$registered_autoresponders ) ) {
return;
}
add_filter( 'tvd_api_available_connections', [ __CLASS__, 'add_api_to_connection_list' ], 10, 3 );
add_filter( 'tvd_third_party_autoresponders', [ __CLASS__, 'add_api_to_thrive_dashboard_list' ], 10, 2 );
}
public static function includes() {
require_once __DIR__ . '/autoresponders/class-autoresponder.php';
}
/**
* @param $key
* @param $class
*/
public static function register_autoresponder( $key, $class ) {
require_once __DIR__ . '/autoresponders/' . $key . '/class-main.php';
static::$registered_autoresponders[ $key ] = new $class();
}
/**
* Hook that adds the autoresponder to the list of available APIs that gets retrieved by Thrive Architect and Thrive Automator.
*
* @param $autoresponders
* @param $only_connected
* @param $include_all - a flag that is set to true when all the connections ( including third party APIs ) must be shown
*
* @return mixed
*/
public static function add_api_to_connection_list( $autoresponders, $only_connected, $api_filter ) {
$include_3rd_party_apis = ! empty( $api_filter['include_3rd_party_apis'] );
if ( ( $include_3rd_party_apis || $only_connected ) && static::should_include_autoresponders( $api_filter ) ) {
foreach ( static::$registered_autoresponders as $autoresponder_key => $autoresponder_instance ) {
/* @var Autoresponder $autoresponder_data */
if ( $include_3rd_party_apis || $autoresponder_instance->is_connected() ) {
$autoresponders[ $autoresponder_key ] = $autoresponder_instance;
}
}
}
return $autoresponders;
}
/**
* Hook that adds the card of this API to the Thrive Dashboard API Connection page.
*
* @param array $autoresponders
* @param bool $localize
*
* @return mixed
*/
public static function add_api_to_thrive_dashboard_list( $autoresponders, $localize ) {
foreach ( static::$registered_autoresponders as $key => $autoresponder_instance ) {
if ( $localize ) {
$autoresponders[] = $autoresponder_instance->localize();
} else {
$autoresponders[ $key ] = $autoresponder_instance;
}
}
return $autoresponders;
}
/**
* @param array $api_filter
*
* @return bool
*/
public static function should_include_autoresponders( $api_filter ) {
$type = 'autoresponder';
if ( empty( $api_filter['include_types'] ) ) {
$should_include_api = ! in_array( $type, $api_filter['exclude_types'], true );
} else {
$should_include_api = in_array( $type, $api_filter['include_types'], true );
}
return $should_include_api;
}
}