-
Notifications
You must be signed in to change notification settings - Fork 0
/
salesfeed.php
137 lines (119 loc) · 3 KB
/
salesfeed.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
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
<?php
/**
* Plugin Name: SalesFeed
* Plugin URI: https://www.pronamic.eu/plugins/salesfeed/
* Description: Add a SalesFeed tracking code to your WordPress site. You need a SalesFeed account.
*
* Version: 1.3.3
* Requires at least: 3.0
*
* Author: Pronamic
* Author URI: https://www.pronamic.eu/
*
* Text Domain: salesfeed
* Domain Path: /languages/
*
* License: GPL-2.0-or-later
*
* GitHub URI: https://github.com/pronamic/wp-salesfeed
*
* @author Pronamic <[email protected]>
* @copyright 2005-2024 Pronamic
* @license GPL-3.0-or-later
* @package Pronamic\SalesFeed
*/
class Pronamic_WP_SalesFeed_Plugin {
/**
* Constructs and initializes an SalesFeed plugin
*/
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
add_action( 'wp_footer', array( $this, 'wp_footer' ) );
if ( is_admin() ) {
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
}
/**
* Plugins loaded
*/
public function plugins_loaded() {
load_plugin_textdomain( 'salesfeed', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Admin init
*/
public function admin_init() {
// Settings - General
add_settings_section(
'salesfeed_general', // id
__( 'General', 'salesfeed' ), // title
'__return_false', // callback
'salesfeed' // page
);
add_settings_field(
'salesfeed_account_id', // id
__( 'SalesFeed Account ID', 'salesfeed' ), // title
array( $this, 'input_text' ), // callback
'salesfeed', // page
'salesfeed_general', // section
array( 'label_for' => 'salesfeed_account_id' ) // args
);
register_setting( 'salesfeed', 'salesfeed_account_id' );
}
/**
* Admin menu
*/
public function admin_menu() {
add_options_page(
__( 'SalesFeed', 'salesfeed' ),
__( 'SalesFeed', 'salesfeed' ),
'manage_options',
'salesfeed',
array( $this, 'page_settings' )
);
}
/**
* Page settings
*/
public function page_settings() {
include plugin_dir_path( __FILE__ ) . '/admin/settings.php';
}
/**
* Input text
*/
public function input_text( $args ) {
printf(
'<input name="%s" id="%s" type="%s" value="%s" class="%s" />',
esc_attr( $args['label_for'] ),
esc_attr( $args['label_for'] ),
esc_attr( 'text' ),
esc_attr( get_option( $args['label_for'] ) ),
'regular-text'
);
}
/**
* Footer
*/
public function wp_footer() {
$id = get_option( 'salesfeed_account_id' );
if ( ! empty( $id ) ) {
?>
<!-- SalesFeed by Pronamic - https://www.pronamic.eu/ -->
<script type='text/javascript'>
(function(d,t) {
_scoopi = {'onload': function() {
this.trkDocumentLoad();
}};
var s=d.getElementsByTagName(t)[0];
var js=d.createElement(t); js.async=1;
js.src='//api.salesfeed.com/v3/bootstrap.js?aid=<?php echo esc_js( $id ); ?>';
s.parentNode.insertBefore(js,s);
})(document,'script');
</script>
<?php
}
}
}
global $pronamic_salesfeed_plugin;
$pronamic_salesfeed_plugin = new Pronamic_WP_SalesFeed_Plugin();