| 1 |
<?php defined( 'ABSPATH' ) or die( 'This script cannot be accessed directly.' ); |
| 2 |
|
| 3 |
add_action( 'admin_enqueue_scripts', 'conv_admin_enqueue_scripts' ); |
| 4 |
function conv_admin_enqueue_scripts( $hook ) { |
| 5 |
if ( $hook !== 'tools_page_conv-settings' ) { |
| 6 |
return; |
| 7 |
} |
| 8 |
|
| 9 |
global $conv_uri, $conv_version; |
| 10 |
wp_enqueue_style( 'conv-main', $conv_uri . '/css/main.css', array(), $conv_version ); |
| 11 |
wp_enqueue_script( 'conv-main', $conv_uri . '/js/main.js', array('jquery'), $conv_version ); |
| 12 |
} |
| 13 |
|
| 14 |
add_action( 'activated_plugin', 'conv_activated_plugin' ); |
| 15 |
function conv_activated_plugin( $plugin ) { |
| 16 |
global $conv_file; |
| 17 |
if ( $plugin !== plugin_basename( $conv_file ) ) { |
| 18 |
return; |
| 19 |
} |
| 20 |
// Taking into account promotional links |
| 21 |
$ref_data = get_transient( 'conv-ref' ); |
| 22 |
if ( $ref_data and strpos( $ref_data, '|' ) !== FALSE ) { |
| 23 |
$ref_data = explode( '|', $ref_data ); |
| 24 |
// Preventing violations with lifetime values |
| 25 |
if ( time() - intval( $ref_data[1] ) < DAY_IN_SECONDS ) { |
| 26 |
update_option( 'conv_ref', $ref_data[0], FALSE ); |
| 27 |
} |
| 28 |
delete_transient( 'conv-ref' ); |
| 29 |
} |
| 30 |
$owner_id = get_option( 'conv_owner_id' ); |
| 31 |
if ( $owner_id === FALSE ) { |
| 32 |
$redirect_location = admin_url( 'tools.php?page=conv-settings' ); |
| 33 |
if ( wp_doing_ajax() ) { |
| 34 |
wp_send_json_success( array( 'location' => $redirect_location ) ); |
| 35 |
} |
| 36 |
wp_redirect( $redirect_location ); |
| 37 |
exit; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
add_action( 'admin_menu', 'conv_add_admin_pages', 30 ); |
| 43 |
function conv_add_admin_pages() { |
| 44 |
global $conv_config; |
| 45 |
add_submenu_page( 'tools.php', $conv_config['title'], $conv_config['title'], 'manage_options', 'conv-settings', 'conv_settings_page' ); |
| 46 |
} |
| 47 |
|
| 48 |
function conv_handle_disconnect_click() { |
| 49 |
if ( isset( $_GET['disconnect'] ) and wp_verify_nonce( $_GET['disconnect'], 'conv_disconnect' ) ) { |
| 50 |
conv_uninstall(); |
| 51 |
// Redirect |
| 52 |
echo '<script type="text/javascript">location.assign(\'' . admin_url( 'tools.php?page=conv-settings' ) . '\')</script>'; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
function conv_settings_page() { |
| 57 |
global $conv_config; |
| 58 |
conv_handle_disconnect_click(); |
| 59 |
$site_id = get_option( 'conv_site_id' ); |
| 60 |
if ( $site_id === FALSE ) { |
| 61 |
nocache_headers(); |
| 62 |
$connect_url = $conv_config['host'] . '/sites/authorize/WordPressPlugin/'; |
| 63 |
if ( $ref_username = get_option( 'conv_ref' ) ) { |
| 64 |
$connect_url .= '?ref=' . $ref_username; |
| 65 |
} |
| 66 |
// Generating access token to use it to authenticate requests |
| 67 |
$access_token = wp_generate_password( 32, FALSE ); |
| 68 |
update_option( 'conv_token', $access_token ); |
| 69 |
?> |
| 70 |
<div class="conv-connect"> |
| 71 |
<div class="conv-connect-logo"> |
| 72 |
<img class="conv-connect-logo-img" src="<?php echo esc_attr( $conv_config['logo'] ) ?>" srcset="<?php echo esc_attr( $conv_config['logo@2x'] ) ?>" alt="<?php echo esc_attr( $conv_config['title'] ) ?>"> |
| 73 |
</div> |
| 74 |
<div class="conv-connect-box"> |
| 75 |
<h1 class="conv-connect-header">Connect Site to <?php echo esc_attr( $conv_config['title'] ) ?></h1> |
| 76 |
<form class="conv-connect-card" method="post" action="<?php echo esc_attr( $connect_url ) ?>"> |
| 77 |
<div class="conv-connect-card-body"> |
| 78 |
<p>Please create a <?php echo esc_attr( $conv_config['title'] ) ?> Account or connect to an existing Account.<br> |
| 79 |
This will allow you to <strong>grow email lists easily</strong> using our top-notch builder |
| 80 |
with unique features and amazing pre-built form templates!</p> |
| 81 |
</div> |
| 82 |
<div class="conv-connect-card-footer"> |
| 83 |
<input type="hidden" name="domain" value="<?php echo esc_attr( preg_replace( '~^https?://~', '', get_site_url() ) ) ?>"> |
| 84 |
|
| 85 |
<input type="hidden" name="credentials[index_page_url]" value="<?php echo esc_attr( get_home_url() ) ?>"> |
| 86 |
<input type="hidden" name="credentials[ajax_url]" value="<?php echo esc_attr( get_home_url() . '/index.php?rest_route=/convertful/v2/' ) ?>"> |
| 87 |
<input type="hidden" name="credentials[access_token]" value="<?php echo esc_attr( $access_token ) ?>"> |
| 88 |
|
| 89 |
<button class="conv-btn action_connect"> |
| 90 |
Connect to <?php echo esc_attr( $conv_config['title'] ) ?> |
| 91 |
</button> |
| 92 |
</div> |
| 93 |
</form> |
| 94 |
</div> |
| 95 |
<?php if ( isset( $conv_config['connect_help_url'] ) and ! empty( $conv_config['connect_help_url'] ) ): ?> |
| 96 |
<a href="<?php echo esc_attr( $conv_config['connect_help_url'] ) ?>" class="conv-connect-help" target="_blank">Get help connecting your site</a> |
| 97 |
<?php endif; ?> |
| 98 |
</div> |
| 99 |
<?php |
| 100 |
} else { |
| 101 |
?> |
| 102 |
<div class="conv-connect type_success"> |
| 103 |
<div class="conv-connect-logo"> |
| 104 |
<img class="conv-connect-logo-img" src="<?php echo esc_attr( $conv_config['logo'] ) ?>" srcset="<?php echo esc_attr( $conv_config['logo@2x'] ) ?> 2x" alt="<?php echo esc_attr( $conv_config['title'] ) ?>"> |
| 105 |
</div> |
| 106 |
<div class="conv-connect-box"> |
| 107 |
<h1 class="conv-connect-header">Site is Connected to <?php echo esc_attr( $conv_config['title'] ) ?></h1> |
| 108 |
<div class="conv-connect-card"> |
| 109 |
<div class="conv-connect-card-body"> |
| 110 |
<p>Congratulations! Your site is connected to <?php echo esc_attr( $conv_config['title'] ) ?>.</p> |
| 111 |
<p>Now you can <strong>grow email lists easily</strong> using our top-notch builder |
| 112 |
with unique features and amazing pre-built form templates!</p> |
| 113 |
</div> |
| 114 |
<div class="conv-connect-card-footer"> |
| 115 |
<a class="conv-btn action_create" href="<?php echo esc_attr( $conv_config['host'] . '/sites/' . $site_id . '/widgets/create/' ) ?>" target="_blank"> |
| 116 |
Create New Optin |
| 117 |
</a> |
| 118 |
</div> |
| 119 |
</div> |
| 120 |
</div> |
| 121 |
<a href="<?php echo admin_url( 'tools.php?page=conv-settings&disconnect=' . wp_create_nonce( 'conv_disconnect' ) ) ?>" class="conv-connect-disconnect">Disconnect site</a> |
| 122 |
</div> |
| 123 |
<?php |
| 124 |
} |
| 125 |
} |
| 126 |
|