-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrustmary.php
More file actions
166 lines (148 loc) · 5.98 KB
/
trustmary.php
File metadata and controls
166 lines (148 loc) · 5.98 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/**
* Plugin Name: Trustmary
* Plugin URI: https://trustmary.com/
* Description: Display Trustmary Widgets and Experiments on your site.
* Version: 1.0.10
* Tested up to: 6.6.2
* Author: Trustmary
* Text Domain: trustmary-widgets
* Domain Path: /languages
* License: GPLv3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
/**
* Prevent direct access to this file
*/
defined('ABSPATH') or die('No');
/**
* Main class for the plugin
*/
class Trustmary_Widgets
{
/**
* Identifier for config array to be stored in WP options
*
* @var string
*/
private $_config_idenfifier = 'trustmary_widgets_config';
/**
* An array of plugin configuration
*
* @var array
*/
private $_config;
/**
* An object for admin pages
*
* @var Trustmary_Pages
*/
private $_pages;
/**
* Constructor
*
* Includes plugin files and adds main hooks.
*/
public function __construct()
{
register_activation_hook(__FILE__, array($this, 'activate'));
register_deactivation_hook(__FILE__, array($this, 'deactivate'));
require_once plugin_dir_path(__FILE__) . 'includes/helper.php';
require_once plugin_dir_path(__FILE__) . 'includes/connect.php';
require_once plugin_dir_path(__FILE__) . 'includes/settings.php';
require_once plugin_dir_path(__FILE__) . 'includes/pages.php';
require_once plugin_dir_path(__FILE__) . 'includes/shortcodes.php';
$this->_config = get_option($this->_config_idenfifier);
if (!$this->_config)
$this->_config = array();
add_action('wp_head', array($this, 'add_scripts'));
add_action('admin_menu', array($this, 'admin_pages'));
add_action('admin_enqueue_scripts', array($this, 'admin_styles'));
add_action('plugins_loaded', array($this, 'init_textdomain'));
new Trustmary_Settings($this->_config_idenfifier, $this->_config);
new Trustmary_Shortcodes();
$this->_pages = new Trustmary_Pages($this->_config);
}
/**
* Checks if necessary functions are available in current PHP build. If not,
* prevents the activation.
*
* Also checks if SECURE_AUTH_KEY and SECURE_AUTH_SALT have been set
* (should be on all up-to-date WP installations).
*
* @return void
*/
public function activate()
{
if (!function_exists('openssl_encrypt')) {
deactivate_plugins(plugin_basename(__FILE__));
wp_die('Please upgrade PHP. This plugin requires openssl, which is available from PHP 5.3+.', 'Plugin dependency', array('back_link' => true));
}
if (!defined('SECURE_AUTH_KEY') || SECURE_AUTH_KEY === '' || !defined('SECURE_AUTH_SALT') || SECURE_AUTH_SALT === '') {
deactivate_plugins(plugin_basename(__FILE__));
wp_die('SECURE_AUTH_KEY and SECURE_AUTH_SALT cannot be empty. See wp-config.php for more information.', 'Plugin dependency', array('back_link' => true));
}
}
/**
* Removes plugin configuration on plugin deactivation.
*
* @return void
*/
public function deactivate()
{
delete_option($this->_config_idenfifier);
}
/**
* Loads plugin textdomain for translations
*
* @return void
*/
public function init_textdomain()
{
load_plugin_textdomain('trustmary-widgets', false, basename(dirname(__FILE__)) . '/languages/');
}
/**
* Creates admin menu links and pages
*
* @return void
*/
public function admin_pages()
{
add_menu_page('Trustmary', 'Trustmary', 'manage_options', 'trustmary-dashboard', array($this->_pages, 'dashboard'), plugins_url('/assets/images/logo-icon.svg', __FILE__), 30);
add_submenu_page('trustmary-dashboard', esc_attr__('Dashboard', 'trustmary-widgets'), esc_attr__('Dashboard', 'trustmary-widgets'), 'manage_options', 'trustmary-dashboard', array($this->_pages, 'dashboard'));
add_submenu_page('trustmary-dashboard', esc_attr__('Popups', 'trustmary-widgets'), esc_attr__('Popups', 'trustmary-widgets'), 'manage_options', 'trustmary-popups', array($this->_pages, 'popups'));
add_submenu_page('trustmary-dashboard', esc_attr__('Inline widgets', 'trustmary-widgets'), esc_attr__('Inline widgets', 'trustmary-widgets'), 'manage_options', 'trustmary-inline', array($this->_pages, 'inline'));
add_submenu_page('trustmary-dashboard', esc_attr__('Experiments', 'trustmary-widgets'), esc_attr__('Experiments', 'trustmary-widgets'), 'manage_options', 'trustmary-experiments', array($this->_pages, 'experiments'));
add_submenu_page('trustmary-dashboard', esc_attr__('Gather reviews', 'trustmary-widgets'), esc_attr__('Gather reviews', 'trustmary-widgets'), 'manage_options', 'trustmary-reviews', array($this->_pages, 'reviews'));
}
/**
* Adds admin css
*
* @return void
*/
public function admin_styles()
{
wp_enqueue_style('trustmary-admin-styles', plugins_url('/assets/css/admin.css', __FILE__));
wp_enqueue_script('trustmary-admin-scripts', plugins_url('/assets/js/admin.js', __FILE__), array(), false, true);
}
/**
* Inserts javascript to WP head if organization ID has been set and add_scripts setting is on.
*
* @return void
*/
public function add_scripts()
{
if (!isset($this->_config['organization_id']) || (isset($this->_config['add_scripts']) && !$this->_config['add_scripts']))
return;
?><script>(function (w,d,s,o,r,js,fjs) {
w[r]=w[r]||function() {(w[r].q = w[r].q || []).push(arguments)}
w[r]('app', '<?php echo esc_attr($this->_config['organization_id']); ?>');
if(d.getElementById(o)) return;
js = d.createElement(s), fjs = d.getElementsByTagName(s)[0];
js.id = o; js.src = 'https://embed.trustmary.com/embed.js';
js.async = 1; fjs.parentNode.insertBefore(js, fjs);
}(window, document, 'script', 'trustmary-embed', 'tmary'));
</script><?php
}
}
new Trustmary_Widgets();