PluginProbe
Convertful – Your Ultimate On-Site Conversion Tool / 1.3
Convertful – Your Ultimate On-Site Conversion Tool v1.3
trunk 1.0 1.1 1.3 1.4 1.5 1.6 1.7 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8
convertful / convertful.php

convertful.php in Convertful – Your Ultimate On-Site Conversion Tool 1.3, at convertful.php

188 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
2
3 /**
4 * Plugin Name: Convertful - Your Ultimate On-Site Conversion Tool
5 * Version: 1.3
6 * Plugin URI: https://convertful.com/
7 * Description: All the modern on-site conversion solutions, natively integrates with all modern Email Marketing Platforms.
8 * Author: Convertful
9 * License: GPLv2 or later
10 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
11 * Text Domain: convertful
12 */
13
14 // Global variables for plugin usage (global declaration is needed here for WP CLI compatibility)
15 global $conv_file, $conv_dir, $conv_uri, $conv_version, $conv_domain;
16 //$conv_domain = 'http://convertful.local';
17 $conv_domain = 'https://app.convertful.com';
18 $conv_file = __FILE__;
19 $conv_dir = plugin_dir_path( __FILE__ );
20 $conv_uri = plugins_url( '', __FILE__ );
21 $conv_version = preg_match( '~Version\: ([^\n]+)~', file_get_contents( __FILE__, NULL, NULL, 82, 150 ), $conv_matches ) ? $conv_matches[1] : FALSE;
22 unset( $conv_matches );
23
24 add_action( 'init', 'conv_init' );
25 function conv_init() {
26 if ( get_option( 'optinguru_owner_id' ) ) {
27 update_option( 'convertful_owner_id', get_option( 'optinguru_owner_id' ), TRUE );
28 update_option( 'convertful_site_id', get_option( 'optinguru_site_id', get_option( 'optinguru_website_id' ) ), FALSE );
29 update_option( 'convertful_token', get_option( 'optinguru_token' ), FALSE );
30 }
31 $owner_id = get_option( 'convertful_owner_id' );
32 if ( ! is_admin() AND $owner_id !== FALSE ) {
33 add_action( 'wp_enqueue_scripts', 'conv_enqueue_scripts' );
34 add_filter( 'script_loader_tag', 'conv_script_loader_tag', 10, 2 );
35 add_filter( 'the_content', 'conv_after_post_content' );
36 }
37 }
38
39 if ( is_admin() ) {
40 require $conv_dir . 'functions/admin_pages.php';
41 }
42
43 // Shortcodes
44 require $conv_dir . 'functions/shortcodes.php';
45
46 function conv_enqueue_scripts() {
47 global $conv_domain, $conv_version;
48 wp_enqueue_script( 'convertful-api', $conv_domain . '/Convertful.js', array(), $conv_version, TRUE );
49 }
50
51 function conv_script_loader_tag( $tag, $handle ) {
52 if ( $handle !== 'convertful-api' ) {
53 return $tag;
54 }
55 global $conv_domain;
56
57 return '<script type="text/javascript" id="convertful-api" src="' . $conv_domain . '/Convertful.js" data-owner="' . get_option( 'convertful_owner_id' ) . '" async="async"></script>';
58 }
59
60 add_action( 'admin_enqueue_scripts', 'conv_admin_enqueue_scripts' );
61 function conv_admin_enqueue_scripts( $hook ) {
62 if ( $hook !== 'tools_page_conv-settings' ) {
63 return;
64 }
65
66 global $conv_uri, $conv_version;
67 wp_enqueue_style( 'conv-main', $conv_uri . '/css/main.css', array(), $conv_version );
68 wp_enqueue_script( 'conv-main', $conv_uri . '/js/main.js', array( 'jquery' ), $conv_version );
69 }
70
71 add_action( 'activated_plugin', 'conv_activated_plugin' );
72 function conv_activated_plugin( $plugin ) {
73 global $conv_file;
74 if ( $plugin !== plugin_basename( $conv_file ) ) {
75 return;
76 }
77 // Taking into account promotional links
78 $ref_data = get_transient( 'convertful-ref' );
79 if ( $ref_data AND strpos( $ref_data, '|' ) !== FALSE ) {
80 $ref_data = explode( '|', $ref_data );
81 // Preventing violations with lifetime values
82 if ( time() - intval( $ref_data[1] ) < DAY_IN_SECONDS ) {
83 update_option( 'convertful_ref', $ref_data[0], FALSE );
84 }
85 delete_transient( 'convertful-ref' );
86 }
87 $owner_id = get_option( 'convertful_owner_id' );
88 if ( $owner_id === FALSE ) {
89 $redirect_location = admin_url( 'tools.php?page=conv-settings' );
90 if ( wp_doing_ajax() ) {
91 wp_send_json_success(
92 array(
93 'location' => $redirect_location,
94 )
95 );
96 }
97 wp_redirect( $redirect_location );
98 exit;
99 }
100 }
101
102 function conv_after_post_content( $content ) {
103 if ( is_single() ) {
104 $content .= '<div class="conv-place conv-place_after_post"></div>';
105 }
106
107 return $content;
108 }
109
110 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'conv_plugin_action_links' );
111 function conv_plugin_action_links( $links ) {
112 return array_merge(
113 array(
114 '<a href="' . admin_url( 'tools.php?page=conv-settings' ) . '">' . __( 'Settings' ) . '</a>',
115 ), $links
116 );
117 }
118
119
120 register_uninstall_hook( $conv_file, 'conv_uninstall' );
121 function conv_uninstall() {
122 // Options cleanup
123 foreach ( array( 'owner_id', 'site_id', 'website_id', 'token', 'ref' ) as $option_name ) {
124 delete_option( 'optinguru_' . $option_name );
125 delete_option( 'convertful_' . $option_name );
126 }
127 }
128
129
130 add_action( 'wp_head', 'conv_variables' );
131 function conv_variables() {
132
133 $tags = array();
134 $the_tags = get_the_tags();
135 if ( is_array( $the_tags ) ) {
136 foreach ( $the_tags as $tag ) {
137 $tags[ $tag->slug ] = $tag->name;
138 }
139 }
140
141 $categories = array();
142 $the_categories = get_the_category();
143 if ( is_array($the_categories)) {
144 foreach ( $the_categories as $category ) {
145 $categories[ $category->slug ] = $category->name;
146 }
147 }
148
149 $user_meta = wp_get_current_user();
150 $variables = array(
151 'url' => admin_url( 'admin-ajax.php' ),
152 'tags' => $tags,
153 'categories' => $categories,
154 'user_roles' => ( $user_meta instanceof WP_User ) ? $user_meta->roles : array(),
155 'type' => get_post_type(),
156 );
157
158 echo '<script type="text/javascript">window.conv_page_vars=' . json_encode( $variables ) . ';</script>';
159 }
160
161 if ( defined( 'DOING_AJAX' ) ) {
162
163 add_action( 'wp_ajax_conv_get_info', 'conv_get_info' );
164 add_action( 'wp_ajax_nopriv_conv_get_info', 'conv_get_info' );
165 function conv_get_info() {
166
167 $tags = array();
168 foreach ( get_tags() as $tag ) {
169 $tags[ $tag->slug ] = $tag->name;
170 }
171
172 $categories = array();
173 foreach ( get_categories() as $category ) {
174 $categories[ $category->slug ] = $category->name;
175 }
176
177 wp_send_json_success(
178 array(
179 'tags' => $tags,
180 'categories' => $categories,
181 )
182 );
183 }
184 }
185
186
187
188