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
|
<?php // phpcs:ignoreFile
namespace AutomateWoo\Admin\Controllers;
if ( ! defined( 'ABSPATH' ) ) exit;
/** * @class Settings */ class Settings extends Base {
/** @var array */ public $settings = [];
function handle() { wp_localize_script( 'automatewoo-settings', 'automatewooSettingsLocalizeScript', [ 'messages' => [ 'switchToOptinWarning' => __( "WARNING: After switching to 'Opt-in mode' current customers will not be automatically opted in. Non-transactional workflows will stop sending emails and SMS until customers choose to opt-in. You can import opt-ins via AutomateWoo > Tools.", 'automatewoo' ), ], ] );
wp_enqueue_script( 'automatewoo-settings' );
$this->output_view( 'page-settings', [ 'current_tab' => $this->get_current_tab(), 'tabs' => $this->get_settings_tabs() ]); }
function save() {
// Save settings if data has been posted if ( empty( $_POST ) ) return;
if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'automatewoo-settings' ) ) { die( __( 'Action failed. Please refresh the page and retry.', 'automatewoo' ) ); }
$current_tab = $this->get_current_tab(); $current_tab->save(); }
/** * @return \AutomateWoo\Admin_Settings_Tab_Abstract|false */ function get_current_tab() {
$current_tab_id = empty( $_GET['tab'] ) ? 'general' : sanitize_title( $_GET['tab'] );
$tabs = $this->get_settings_tabs();
return isset( $tabs[$current_tab_id] ) ? $tabs[$current_tab_id] : false; }
/** * @return array */ function get_settings_tabs() { if ( empty( $this->settings ) ) { $path = AW()->path( '/admin/settings-tabs/' );
$settings_includes = apply_filters( 'automatewoo/settings/tabs', [ $path . 'general.php', $path . 'carts.php', $path . 'mailchimp.php', $path . 'campaign-monitor.php', $path . 'active-campaign.php', $path . 'twilio.php', $path . 'bitly.php', ]);
$settings_includes[] = $path . 'status.php';
foreach ( $settings_includes as $settings_include ) { if ( $class = require_once $settings_include ) { $this->settings[$class->id] = $class; } } }
return $this->settings; }
}
return new Settings();
|