Brak opisu

class-constant-contact.php 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. <?php
  2. /**
  3. * Constant Contact integration.
  4. *
  5. * @since 1.3.6
  6. */
  7. class WPForms_Constant_Contact extends WPForms_Provider {
  8. /**
  9. * Provider access token.
  10. *
  11. * @since 1.3.6
  12. *
  13. * @var string
  14. */
  15. public $access_token;
  16. /**
  17. * Provider API key.
  18. *
  19. * @since 1.3.6
  20. *
  21. * @var string
  22. */
  23. public $api_key = 'c58xq3r27udz59h9rrq7qnvf';
  24. /**
  25. * Sign up link.
  26. *
  27. * @since 1.3.6
  28. *
  29. * @var string
  30. */
  31. public $sign_up = 'https://constant-contact.evyy.net/c/11535/341874/3411?sharedid=wpforms';
  32. /**
  33. * Initialize.
  34. *
  35. * @since 1.3.6
  36. */
  37. public function init() {
  38. $this->version = '1.3.6';
  39. $this->name = 'Constant Contact';
  40. $this->slug = 'constant-contact';
  41. $this->priority = 14;
  42. $this->icon = WPFORMS_PLUGIN_URL . 'assets/images/icon-provider-constant-contact.png';
  43. if ( is_admin() ) {
  44. // Admin notice requesting connecting.
  45. $this->connect_request();
  46. add_action( 'wpforms_admin_notice_dismiss_ajax', [ $this, 'connect_dismiss' ] );
  47. add_action( 'wpforms_admin_page', [ $this, 'learn_more_page' ] );
  48. add_filter( "wpforms_providers_provider_settings_formbuilder_display_content_default_screen_{$this->slug}", [ $this, 'builder_settings_default_content' ] );
  49. // Provide option to override sign up link.
  50. $sign_up = get_option( 'wpforms_constant_contact_signup', false );
  51. if ( $sign_up ) {
  52. $this->sign_up = esc_html( $sign_up );
  53. }
  54. }
  55. }
  56. /**
  57. * Process and submit entry to provider.
  58. *
  59. * @since 1.3.6
  60. *
  61. * @param array $fields List of fields with their data and settings.
  62. * @param array $entry Submitted entry values.
  63. * @param array $form_data Form data and settings.
  64. * @param int $entry_id Saved entry ID.
  65. *
  66. * @return void
  67. */
  68. public function process_entry( $fields, $entry, $form_data, $entry_id = 0 ) {
  69. // Only run if this form has a connections for this provider.
  70. if ( empty( $form_data['providers'][ $this->slug ] ) ) {
  71. return;
  72. }
  73. /*
  74. * Fire for each connection.
  75. */
  76. foreach ( $form_data['providers'][ $this->slug ] as $connection ) :
  77. // Before proceeding make sure required fields are configured.
  78. if ( empty( $connection['fields']['email'] ) ) {
  79. continue;
  80. }
  81. // Setup basic data.
  82. $list_id = $connection['list_id'];
  83. $account_id = $connection['account_id'];
  84. $email_data = explode( '.', $connection['fields']['email'] );
  85. $email_id = $email_data[0];
  86. $email = $fields[ $email_id ]['value'];
  87. $this->api_connect( $account_id );
  88. // Email is required and Access token are required.
  89. if ( empty( $email ) || empty( $this->access_token ) ) {
  90. continue;
  91. }
  92. // Check for conditionals.
  93. $pass = $this->process_conditionals( $fields, $entry, $form_data, $connection );
  94. if ( ! $pass ) {
  95. wpforms_log(
  96. esc_html__( 'Constant Contact Subscription stopped by conditional logic', 'wpforms-lite' ),
  97. $fields,
  98. array(
  99. 'type' => array( 'provider', 'conditional_logic' ),
  100. 'parent' => $entry_id,
  101. 'form_id' => $form_data['id'],
  102. )
  103. );
  104. continue;
  105. }
  106. // Check to see if the lead already exists in Constant Contact.
  107. $response = wp_remote_get( 'https://api.constantcontact.com/v2/contacts?api_key=' . $this->api_key . '&access_token=' . $this->access_token . '&email=' . $email );
  108. $contact = json_decode( wp_remote_retrieve_body( $response ), true );
  109. // Return early if there was a problem.
  110. if ( isset( $contact['error_key'] ) ) {
  111. wpforms_log(
  112. esc_html__( 'Constant Contact API Error', 'wpforms-lite' ),
  113. $contact->get_error_message(),
  114. array(
  115. 'type' => array( 'provider', 'error' ),
  116. 'parent' => $entry_id,
  117. 'form_id' => $form_data['id'],
  118. )
  119. );
  120. continue;
  121. }
  122. /*
  123. * Setup Merge Vars
  124. */
  125. $merge_vars = array();
  126. foreach ( $connection['fields'] as $name => $merge_var ) {
  127. // Don't include Email or Full name fields.
  128. if ( 'email' === $name ) {
  129. continue;
  130. }
  131. // Check if merge var is mapped.
  132. if ( empty( $merge_var ) ) {
  133. continue;
  134. }
  135. $merge_var = explode( '.', $merge_var );
  136. $id = $merge_var[0];
  137. $key = ! empty( $merge_var[1] ) ? $merge_var[1] : 'value';
  138. // Check if mapped form field has a value.
  139. if ( empty( $fields[ $id ][ $key ] ) ) {
  140. continue;
  141. }
  142. $value = $fields[ $id ][ $key ];
  143. // Constant Contact doesn't native URL field so it has to be
  144. // stored in a custom field.
  145. if ( 'url' === $name ) {
  146. $merge_vars['custom_fields'] = array(
  147. array(
  148. 'name' => 'custom_field_1',
  149. 'value' => $value,
  150. ),
  151. );
  152. continue;
  153. }
  154. // Constant Contact stores name in two fields, so we have to
  155. // separate it.
  156. if ( 'full_name' === $name ) {
  157. $names = explode( ' ', $value );
  158. if ( ! empty( $names[0] ) ) {
  159. $merge_vars['first_name'] = $names[0];
  160. }
  161. if ( ! empty( $names[1] ) ) {
  162. $merge_vars['last_name'] = $names[1];
  163. }
  164. continue;
  165. }
  166. // Constant Contact stores address in multiple fields, so we
  167. // have to separate it.
  168. if ( $name === 'address' ) {
  169. // Only support Address fields.
  170. if ( $fields[ $id ]['type'] !== 'address' ) {
  171. continue;
  172. }
  173. // Postal code may be in extended US format.
  174. $postal = [
  175. 'code' => '',
  176. 'subcode' => '',
  177. ];
  178. if ( ! empty( $fields[ $id ]['postal'] ) ) {
  179. $p = explode( '-', $fields[ $id ]['postal'] );
  180. $postal['code'] = ! empty( $p[0] ) ? $p[0] : '';
  181. $postal['subcode'] = ! empty( $p[1] ) ? $p[1] : '';
  182. }
  183. $merge_vars['addresses'] = [
  184. [
  185. 'address_type' => 'BUSINESS',
  186. 'city' => ! empty( $fields[ $id ]['city'] ) ? $fields[ $id ]['city'] : '',
  187. 'country_code' => ! empty( $fields[ $id ]['country'] ) ? $fields[ $id ]['country'] : '',
  188. 'line1' => ! empty( $fields[ $id ]['address1'] ) ? $fields[ $id ]['address1'] : '',
  189. 'line2' => ! empty( $fields[ $id ]['address2'] ) ? $fields[ $id ]['address2'] : '',
  190. 'postal_code' => $postal['code'],
  191. 'state' => ! empty( $fields[ $id ]['state'] ) ? $fields[ $id ]['state'] : '',
  192. 'sub_postal_code' => $postal['subcode'],
  193. ],
  194. ];
  195. continue;
  196. }
  197. $merge_vars[ $name ] = $value;
  198. }
  199. /*
  200. * Process in API
  201. */
  202. // If we have a previous contact, only update the list association.
  203. if ( ! empty( $contact['results'] ) ) {
  204. $data = $contact['results'][0];
  205. // Check if they are already assigned to lists.
  206. if ( ! empty( $data['lists'] ) ) {
  207. foreach ( $data['lists'] as $list ) {
  208. // If they are already assigned to this list, return early.
  209. if ( isset( $list['id'] ) && (string) $list_id === (string) $list['id'] ) {
  210. return;
  211. }
  212. }
  213. // Otherwise, add them to the list.
  214. $data['lists'][ count( $data['lists'] ) ] = [
  215. 'id' => $list_id,
  216. 'status' => 'ACTIVE',
  217. ];
  218. } else {
  219. // Add the contact to the list.
  220. $data['lists'][0] = [
  221. 'id' => $list_id,
  222. 'status' => 'ACTIVE',
  223. ];
  224. }
  225. // Combine merge vars into data before sending.
  226. $data = array_merge( $data, $merge_vars );
  227. // Args to use.
  228. $args = [
  229. 'body' => wp_json_encode( $data ),
  230. 'method' => 'PUT',
  231. 'headers' => [
  232. 'Content-Type' => 'application/json',
  233. ],
  234. ];
  235. $update = wp_remote_request( 'https://api.constantcontact.com/v2/contacts/' . $data['id'] . '?api_key=' . $this->api_key . '&access_token=' . $this->access_token . '&action_by=ACTION_BY_VISITOR', $args );
  236. $res = json_decode( wp_remote_retrieve_body( $update ), true );
  237. } else {
  238. // Add a new contact.
  239. $data = [
  240. 'email_addresses' => [ [ 'email_address' => $email ] ],
  241. 'lists' => [ [ 'id' => $list_id ] ],
  242. ];
  243. // Combine merge vars into data before sending.
  244. $data = array_merge( $data, $merge_vars );
  245. // Args to use.
  246. $args = [
  247. 'body' => wp_json_encode( $data ),
  248. 'headers' => [
  249. 'Content-Type' => 'application/json',
  250. ],
  251. ];
  252. $add = wp_remote_post( 'https://api.constantcontact.com/v2/contacts?api_key=' . $this->api_key . '&access_token=' . $this->access_token . '&action_by=ACTION_BY_VISITOR', $args );
  253. $res = json_decode( wp_remote_retrieve_body( $add ), true );
  254. }
  255. // Check for errors.
  256. if ( isset( $res['error_key'] ) ) {
  257. wpforms_log(
  258. esc_html__( 'Constant Contact API Error', 'wpforms-lite' ),
  259. $res->get_error_message(),
  260. [
  261. 'type' => [ 'provider', 'error' ],
  262. 'parent' => $entry_id,
  263. 'form_id' => $form_data['id'],
  264. ]
  265. );
  266. }
  267. endforeach;
  268. }
  269. /************************************************************************
  270. * API methods - these methods interact directly with the provider API. *
  271. ************************************************************************/
  272. /**
  273. * Authenticate with the API.
  274. *
  275. * @since 1.3.6
  276. *
  277. * @param array $data
  278. * @param string $form_id
  279. *
  280. * @return mixed id or error object
  281. */
  282. public function api_auth( $data = array(), $form_id = '' ) {
  283. $id = uniqid();
  284. $providers = wpforms_get_providers_options();
  285. $providers[ $this->slug ][ $id ] = array(
  286. 'access_token' => sanitize_text_field( $data['authcode'] ),
  287. 'label' => sanitize_text_field( $data['label'] ),
  288. 'date' => time(),
  289. );
  290. update_option( 'wpforms_providers', $providers );
  291. return $id;
  292. }
  293. /**
  294. * Establish connection object to API.
  295. *
  296. * @since 1.3.6
  297. *
  298. * @param string $account_id
  299. *
  300. * @return mixed array or error object.
  301. */
  302. public function api_connect( $account_id ) {
  303. if ( ! empty( $this->api[ $account_id ] ) ) {
  304. return $this->api[ $account_id ];
  305. } else {
  306. $providers = wpforms_get_providers_options();
  307. if ( ! empty( $providers[ $this->slug ][ $account_id ] ) ) {
  308. $this->api[ $account_id ] = true;
  309. $this->access_token = $providers[ $this->slug ][ $account_id ]['access_token'];
  310. } else {
  311. return $this->error( 'API error' );
  312. }
  313. }
  314. }
  315. /**
  316. * Retrieve provider account lists.
  317. *
  318. * @since 1.3.6
  319. *
  320. * @param string $connection_id
  321. * @param string $account_id
  322. *
  323. * @return mixed array or error object
  324. */
  325. public function api_lists( $connection_id = '', $account_id = '' ) {
  326. $this->api_connect( $account_id );
  327. $request = wp_remote_get( 'https://api.constantcontact.com/v2/lists?api_key=' . $this->api_key . '&access_token=' . $this->access_token );
  328. $lists = json_decode( wp_remote_retrieve_body( $request ), true );
  329. if ( empty( $lists ) ) {
  330. wpforms_log(
  331. esc_html__( 'Constant Contact API Error', 'wpforms-lite' ),
  332. '',
  333. array(
  334. 'type' => array( 'provider', 'error' ),
  335. )
  336. );
  337. return $this->error( esc_html__( 'API list error: Constant API error', 'wpforms-lite' ) );
  338. }
  339. return $lists;
  340. }
  341. /**
  342. * Retrieve provider account list fields.
  343. *
  344. * @since 1.3.6
  345. *
  346. * @param string $connection_id
  347. * @param string $account_id
  348. * @param string $list_id
  349. *
  350. * @return mixed array or error object
  351. */
  352. public function api_fields( $connection_id = '', $account_id = '', $list_id = '' ) {
  353. $provider_fields = array(
  354. array(
  355. 'name' => 'Email',
  356. 'field_type' => 'email',
  357. 'req' => '1',
  358. 'tag' => 'email',
  359. ),
  360. array(
  361. 'name' => 'Full Name',
  362. 'field_type' => 'name',
  363. 'tag' => 'full_name',
  364. ),
  365. array(
  366. 'name' => 'First Name',
  367. 'field_type' => 'first',
  368. 'tag' => 'first_name',
  369. ),
  370. array(
  371. 'name' => 'Last Name',
  372. 'field_type' => 'last',
  373. 'tag' => 'last_name',
  374. ),
  375. array(
  376. 'name' => 'Phone',
  377. 'field_type' => 'text',
  378. 'tag' => 'work_phone',
  379. ),
  380. array(
  381. 'name' => 'Website',
  382. 'field_type' => 'text',
  383. 'tag' => 'url',
  384. ),
  385. array(
  386. 'name' => 'Address',
  387. 'field_type' => 'address',
  388. 'tag' => 'address',
  389. ),
  390. array(
  391. 'name' => 'Job Title',
  392. 'field_type' => 'text',
  393. 'tag' => 'job_title',
  394. ),
  395. array(
  396. 'name' => 'Company',
  397. 'field_type' => 'text',
  398. 'tag' => 'company_name',
  399. ),
  400. );
  401. return $provider_fields;
  402. }
  403. /*************************************************************************
  404. * Output methods - these methods generally return HTML for the builder. *
  405. *************************************************************************/
  406. /**
  407. * Provider account authorize fields HTML.
  408. *
  409. * @since 1.3.6
  410. * @return string
  411. */
  412. public function output_auth() {
  413. $providers = wpforms_get_providers_options();
  414. $class = ! empty( $providers[ $this->slug ] ) ? 'hidden' : '';
  415. $output = '<div class="wpforms-provider-account-add ' . $class . ' wpforms-connection-block">';
  416. $output .= sprintf( '<h4>%s</h4>', esc_html__( 'Add New Account', 'wpforms-lite' ) );
  417. $output .= '<p>';
  418. $output .= esc_html__( 'Please fill out all of the fields below to register your new Constant Contact account.', 'wpforms-lite' );
  419. $output .= '<br><a href="https://wpforms.com/docs/how-to-connect-constant-contact-with-wpforms/" target="_blank" rel="noopener noreferrer">';
  420. $output .= esc_html__( 'Click here for documentation on connecting WPForms with Constant Contact.', 'wpforms-lite' );
  421. $output .= '</a>';
  422. $output .= '</p>';
  423. $output .= '<p class="wpforms-alert wpforms-alert-warning">';
  424. $output .= esc_html__( 'Because Constant Contact requires external authentication, you will need to register WPForms with Constant Contact before you can proceed.', 'wpforms-lite' );
  425. $output .= '</p>';
  426. $output .= '<p class=""><strong><a onclick="window.open(this.href,\'\',\'resizable=yes,location=no,width=750,height=500,status\'); return false" href="https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize?response_type=code&client_id=c58xq3r27udz59h9rrq7qnvf&redirect_uri=https://wpforms.com/oauth/constant-contact/" class="btn">';
  427. $output .= esc_html__( 'Click here to register with Constant Contact', 'wpforms-lite' );
  428. $output .= '</a></strong></p>';
  429. $output .= sprintf( '<input type="text" data-name="authcode" placeholder="%s %s" class="wpforms-required">', $this->name, esc_html__( 'Authorization Code', 'wpforms-lite' ) );
  430. $output .= sprintf( '<input type="text" data-name="label" placeholder="%s %s" class="wpforms-required">', $this->name, esc_html__( 'Account Nickname', 'wpforms-lite' ) );
  431. $output .= sprintf( '<button data-provider="%s">%s</button>', $this->slug, esc_html__( 'Connect', 'wpforms-lite' ) );
  432. $output .= '</div>';
  433. return $output;
  434. }
  435. /**
  436. * Provider account list groups HTML.
  437. *
  438. * @since 1.3.6
  439. *
  440. * @param string $connection_id Connection Id.
  441. * @param array $connection Connection data.
  442. *
  443. * @return string
  444. */
  445. public function output_groups( $connection_id = '', $connection = [] ) {
  446. // No groups or segments for this provider.
  447. return '';
  448. }
  449. /**
  450. * Default content for the provider settings panel in the form builder.
  451. *
  452. * @since 1.6.8
  453. *
  454. * @param string $content Default content.
  455. *
  456. * @return string
  457. */
  458. public function builder_settings_default_content( $content ) {
  459. ob_start();
  460. ?>
  461. <p>
  462. <a href="<?php echo esc_url( $this->sign_up ); ?>" class="wpforms-btn wpforms-btn-md wpforms-btn-orange" target="_blank" rel="noopener noreferrer">
  463. <?php esc_html_e( 'Try Constant Contact for Free', 'wpforms-lite' ); ?>
  464. </a>
  465. </p>
  466. <p>
  467. <?php
  468. printf(
  469. '<a href="%s" target="_blank" rel="noopener noreferrer" class="secondary-text">' .
  470. esc_html__( 'Learn more about the power of email marketing.', 'wpforms-lite' ) .
  471. '</a>',
  472. esc_url( admin_url( 'admin.php?page=wpforms-page&wpforms-page=constant-contact' ) )
  473. );
  474. ?>
  475. </p>
  476. <?php
  477. return $content . ob_get_clean();
  478. }
  479. /*************************************************************************
  480. * Integrations tab methods - these methods relate to the settings page. *
  481. *************************************************************************/
  482. /**
  483. * Form fields to add a new provider account.
  484. *
  485. * @since 1.3.6
  486. */
  487. public function integrations_tab_new_form() {
  488. $output = '<p>';
  489. $output .= '<a href="https://wpforms.com/docs/how-to-connect-constant-contact-with-wpforms/" target="_blank" rel="noopener noreferrer">';
  490. $output .= esc_html__( 'Click here for documentation on connecting WPForms with Constant Contact.', 'wpforms-lite' );
  491. $output .= '</a>';
  492. $output .= '</p>';
  493. $output .= '<p class="wpforms-alert wpforms-alert-warning">';
  494. $output .= esc_html__( 'Because Constant Contact requires external authentication, you will need to register WPForms with Constant Contact before you can proceed.', 'wpforms-lite' );
  495. $output .= '</p>';
  496. $output .= '<p class=""><strong><a onclick="window.open(this.href,\'\',\'resizable=yes,location=no,width=800,height=600,status\'); return false" href="https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize?response_type=code&client_id=c58xq3r27udz59h9rrq7qnvf&redirect_uri=https://wpforms.com/oauth/constant-contact/" class="btn">';
  497. $output .= esc_html__( 'Click here to register with Constant Contact', 'wpforms-lite' );
  498. $output .= '</a></strong></p>';
  499. $output .= sprintf( '<input type="text" name="authcode" placeholder="%s %s" class="wpforms-required">', $this->name, esc_html__( 'Authorization Code', 'wpforms-lite' ) );
  500. $output .= sprintf( '<input type="text" name="label" placeholder="%s %s" class="wpforms-required">', $this->name, esc_html__( 'Account Nickname', 'wpforms-lite' ) );
  501. echo $output;
  502. }
  503. /************************
  504. * Other functionality. *
  505. ************************/
  506. /**
  507. * Add admin notices to connect to Constant Contact.
  508. *
  509. * @since 1.3.6
  510. */
  511. public function connect_request() {
  512. // Only consider showing the review request to admin users.
  513. if ( ! is_super_admin() ) {
  514. return;
  515. }
  516. // Don't display on WPForms admin content pages.
  517. if ( ! empty( $_GET['wpforms-page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
  518. return;
  519. }
  520. // Don't display if user is about to connect via Settings page.
  521. if ( ! empty( $_GET['wpforms-integration'] ) && $this->slug === $_GET['wpforms-integration'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
  522. return;
  523. }
  524. // Only display the notice if the Constant Contact option is set and
  525. // there are previous Constant Contact connections created.
  526. // Please do not delete 'wpforms_constant_contact' option check from the code.
  527. $cc_notice = get_option( 'wpforms_constant_contact', false );
  528. $providers = wpforms_get_providers_options();
  529. if ( ! $cc_notice || ! empty( $providers[ $this->slug ] ) ) {
  530. return;
  531. }
  532. // Output the notice message.
  533. $connect = admin_url( 'admin.php?page=wpforms-settings&wpforms-integration=constant-contact#!wpforms-tab-providers' );
  534. $learn_more = admin_url( 'admin.php?page=wpforms-page&wpforms-page=constant-contact' );
  535. ob_start();
  536. ?>
  537. <p>
  538. <?php
  539. echo wp_kses(
  540. __( 'Get the most out of the <strong>WPForms</strong> plugin &mdash; use it with an active Constant Contact account.', 'wpforms-lite' ),
  541. [
  542. 'strong' => [],
  543. ]
  544. );
  545. ?>
  546. </p>
  547. <p>
  548. <a href="<?php echo esc_url( $this->sign_up ); ?>" class="button-primary" target="_blank" rel="noopener noreferrer">
  549. <?php esc_html_e( 'Try Constant Contact for Free', 'wpforms-lite' ); ?>
  550. </a>
  551. <a href="<?php echo esc_url( $connect ); ?>" class="button-secondary">
  552. <?php esc_html_e( 'Connect your existing account', 'wpforms-lite' ); ?>
  553. </a>
  554. <?php
  555. printf(
  556. wp_kses( /* translators: %s - WPForms Constant Contact internal URL. */
  557. __( 'Learn More about the <a href="%s">power of email marketing</a>', 'wpforms-lite' ),
  558. [
  559. 'a' => [
  560. 'href' => [],
  561. ],
  562. ]
  563. ),
  564. esc_url( $learn_more )
  565. );
  566. ?>
  567. </p>
  568. <style>
  569. .wpforms-constant-contact-notice {
  570. border-left-color: #1a5285;
  571. }
  572. .wpforms-constant-contact-notice p:first-of-type {
  573. margin: 16px 0 8px;
  574. }
  575. .wpforms-constant-contact-notice p:last-of-type {
  576. margin: 8px 0 16px;
  577. }
  578. .wpforms-constant-contact-notice .button-primary,
  579. .wpforms-constant-contact-notice .button-secondary {
  580. display: inline-block;
  581. margin: 0 10px 0 0;
  582. }
  583. </style>
  584. <?php
  585. $notice = ob_get_clean();
  586. \WPForms\Admin\Notice::info(
  587. $notice,
  588. [
  589. 'dismiss' => \WPForms\Admin\Notice::DISMISS_GLOBAL,
  590. 'slug' => 'constant_contact_connect',
  591. 'autop' => false,
  592. 'class' => 'wpforms-constant-contact-notice',
  593. ]
  594. );
  595. }
  596. /**
  597. * Dismiss the Constant Contact admin notice.
  598. *
  599. * @since 1.3.6
  600. * @since 1.6.7.1 Added parameter $notice_id.
  601. *
  602. * @param string $notice_id Notice ID (slug).
  603. */
  604. public function connect_dismiss( $notice_id = '' ) {
  605. if ( $notice_id !== 'global-constant_contact_connect' ) {
  606. return;
  607. }
  608. delete_option( 'wpforms_constant_contact' );
  609. wp_send_json_success();
  610. }
  611. /**
  612. * Constant Contact "Learn More" admin page.
  613. *
  614. * @since 1.3.6
  615. */
  616. public function learn_more_page() {
  617. if (
  618. empty( $_GET['page'] ) ||
  619. empty( $_GET['wpforms-page'] ) ||
  620. 'wpforms-page' !== $_GET['page'] ||
  621. 'constant-contact' !== $_GET['wpforms-page']
  622. ) {
  623. return;
  624. }
  625. $more = 'http://www.wpbeginner.com/beginners-guide/why-you-should-start-building-your-email-list-right-away';
  626. ?>
  627. <div class="wrap about-wrap">
  628. <h1><?php esc_html_e( 'Grow Your Website with WPForms + Email Marketing', 'wpforms-lite' ); ?></h1>
  629. <p><?php esc_html_e( 'Wondering if email marketing is really worth your time?', 'wpforms-lite' ); ?></p>
  630. <p><?php echo wp_kses( __( 'Email is hands-down the most effective way to nurture leads and turn them into customers, with a return on investment (ROI) of <strong>$44 back for every $1 spent</strong> according to DMA.', 'wpforms-lite' ), array( 'strong' => array() ) ); ?></p>
  631. <p><?php esc_html_e( 'Here are 3 big reasons why every smart business in the world has an email list:', 'wpforms-lite' ); ?></p>
  632. <a href="<?php echo esc_url( $this->sign_up ); ?>" target="_blank" rel="noopener noreferrer">
  633. <img src="<?php echo WPFORMS_PLUGIN_URL; ?>assets/images/cc-about-logo.png" class="logo">
  634. </a>
  635. <ol class="reasons">
  636. <li><?php echo wp_kses( __( '<strong>Email is still #1</strong> - At least 91% of consumers check their email on a daily basis. You get direct access to your subscribers, without having to play by social media&#39;s rules and algorithms.', 'wpforms-lite' ), array( 'strong' => array() ) ); ?></li>
  637. <li><?php echo wp_kses( __( '<strong>You own your email list</strong> - Unlike with social media, your list is your property and no one can revoke your access to it.', 'wpforms-lite' ), array( 'strong' => array() ) ); ?></li>
  638. <li><?php echo wp_kses( __( '<strong>Email converts</strong> - People who buy products marketed through email spend 138% more than those who don&#39;t receive email offers.', 'wpforms-lite' ), array( 'strong' => array() ) ); ?></li>
  639. </ol>
  640. <p><?php esc_html_e( 'That&#39;s why it&#39;s crucial to start collecting email addresses and building your list as soon as possible.', 'wpforms-lite' ); ?></p>
  641. <p>
  642. <?php
  643. printf(
  644. wp_kses(
  645. /* translators: %s - WPBeginners.com Guide to Email Lists URL. */
  646. __( 'For more details, see this guide on <a href="%s" target="_blank" rel="noopener noreferrer">why building your email list is so important</a>.', 'wpforms-lite' ),
  647. array(
  648. 'a' => array(
  649. 'href' => array(),
  650. 'target' => array(),
  651. 'rel' => array(),
  652. ),
  653. )
  654. ),
  655. $more
  656. );
  657. ?>
  658. </p>
  659. <hr/>
  660. <h2><?php esc_html_e( 'You&#39;ve Already Started - Here&#39;s the Next Step (It&#39;s Easy)', 'wpforms-lite' ); ?></h2>
  661. <p><?php esc_html_e( 'Here are the 3 things you need to build an email list:', 'wpforms-lite' ); ?></p>
  662. <ol>
  663. <li><?php esc_html_e( 'A Website or Blog', 'wpforms-lite' ); ?> <span class="dashicons dashicons-yes"></span></li>
  664. <li><?php esc_html_e( 'High-Converting Form Builder', 'wpforms-lite' ); ?> <span class="dashicons dashicons-yes"></span></li>
  665. <li><strong><?php esc_html_e( 'The Best Email Marketing Service', 'wpforms-lite' ); ?></strong></li>
  666. </ol>
  667. <p><?php esc_html_e( 'With a powerful email marketing service like Constant Contact, you can instantly send out mass notifications and beautifully designed newsletters to engage your subscribers.', 'wpforms-lite' ); ?></p>
  668. <p>
  669. <a href="<?php echo esc_url( $this->sign_up ); ?>" class="button" target="_blank" rel="noopener noreferrer">
  670. <?php esc_html_e( 'Get Started with Constant Contact for Free', 'wpforms-lite' ); ?>
  671. </a>
  672. </p>
  673. <p><?php esc_html_e( 'WPForms plugin makes it fast and easy to capture all kinds of visitor information right from your WordPress site - even if you don&#39;t have a Constant Contact account.', 'wpforms-lite' ); ?></p>
  674. <p><?php esc_html_e( 'But when you combine WPForms with Constant Contact, you can nurture your contacts and engage with them even after they leave your website. When you use Constant Contact + WPForms together, you can:', 'wpforms-lite' ); ?></p>
  675. <ul>
  676. <li><?php esc_html_e( 'Seamlessly add new contacts to your email list', 'wpforms-lite' ); ?></li>
  677. <li><?php esc_html_e( 'Create and send professional email newsletters', 'wpforms-lite' ); ?></li>
  678. <li><?php esc_html_e( 'Get expert marketing and support', 'wpforms-lite' ); ?></li>
  679. </ul>
  680. <p>
  681. <a href="<?php echo esc_url( $this->sign_up ); ?>" target="_blank" rel="noopener noreferrer">
  682. <strong><?php esc_html_e( 'Try Constant Contact Today', 'wpforms-lite' ); ?></strong>
  683. </a>
  684. </p>
  685. <hr/>
  686. <h2><?php esc_html_e( 'WPForms Makes List Building Easy', 'wpforms-lite' ); ?></h2>
  687. <p><?php esc_html_e( 'When creating WPForms, our goal was to make a WordPress forms plugin that&#39;s both EASY and POWERFUL.', 'wpforms-lite' ); ?></p>
  688. <p><?php esc_html_e( 'We made the form creation process extremely intuitive, so you can create a form to start capturing emails within 5 minutes or less.', 'wpforms-lite' ); ?></p>
  689. <p><?php esc_html_e( 'Here&#39;s how it works.', 'wpforms-lite' ); ?></p>
  690. <div class="steps">
  691. <div class="step1 step">
  692. <img src="<?php echo WPFORMS_PLUGIN_URL; ?>assets/images/cc-about-step1.png">
  693. <p><?php esc_html_e( '1. Select from our pre-built templates, or create a form from scratch.', 'wpforms-lite' ); ?></p>
  694. </div>
  695. <div class="step2 step">
  696. <img src="<?php echo WPFORMS_PLUGIN_URL; ?>assets/images/cc-about-step2.png">
  697. <p><?php esc_html_e( '2. Drag and drop any field you want onto your signup form.', 'wpforms-lite' ); ?></p>
  698. </div>
  699. <div class="step3 step">
  700. <img src="<?php echo WPFORMS_PLUGIN_URL; ?>assets/images/cc-about-step3.png">
  701. <p><?php esc_html_e( '3. Connect your Constant Contact email list.', 'wpforms-lite' ); ?></p>
  702. </div>
  703. <div class="step4 step">
  704. <img src="<?php echo WPFORMS_PLUGIN_URL; ?>assets/images/cc-about-step4.png">
  705. <p><?php esc_html_e( '4. Add your new form to any post, page, or sidebar.', 'wpforms-lite' ); ?></p>
  706. </div>
  707. </div>
  708. <p><?php esc_html_e( 'It doesn&#39;t matter what kind of business you run, what kind of website you have, or what industry you are in - you need to start building your email list today.', 'wpforms-lite' ); ?></p>
  709. <p><?php esc_html_e( 'With Constant Contact + WPForms, growing your list is easy.', 'wpforms-lite' ); ?></p>
  710. </div>
  711. <style>
  712. .notice {
  713. display: none;
  714. }
  715. .about-wrap {
  716. padding: 15px;
  717. max-width: 970px;
  718. }
  719. .about-wrap h1 {
  720. color: #1a5285;
  721. font-size: 30px;
  722. margin: 0 0 15px 0;
  723. }
  724. .about-wrap h2 {
  725. color: #1a5285;
  726. font-size: 26px;
  727. margin: 0 0 15px 0;
  728. text-align: left;
  729. }
  730. .about-wrap p {
  731. font-size: 16px;
  732. font-weight: 300;
  733. color: #333;
  734. margin: 1.2em 0;
  735. }
  736. .about-wrap ul,
  737. .about-wrap ol {
  738. margin: 1.6em 2.5em 2em;
  739. line-height: 1.5;
  740. font-size: 16px;
  741. font-weight: 300;
  742. }
  743. .about-wrap ul {
  744. list-style: disc;
  745. }
  746. .about-wrap li {
  747. margin-bottom: 0.8em;
  748. }
  749. .about-wrap hr {
  750. margin: 2.2em 0;
  751. }
  752. .about-wrap .logo {
  753. float: right;
  754. margin-top: 0.8em;
  755. width: auto;
  756. }
  757. .about-wrap .reasons {
  758. margin: 2.2em 400px 2.2em 2em;
  759. }
  760. .about-wrap .reasons li {
  761. margin-bottom: 1.4em;
  762. }
  763. .about-wrap .steps {
  764. clear: both;
  765. overflow: hidden;
  766. }
  767. .about-wrap .step {
  768. width: 46%;
  769. float: left;
  770. }
  771. .about-wrap .step {
  772. margin-bottom: 1.4em;
  773. }
  774. .about-wrap .step2,
  775. .about-wrap .step4 {
  776. float: right;
  777. }
  778. .about-wrap .step3 {
  779. clear: both;
  780. }
  781. .about-wrap .dashicons-yes {
  782. color: #19BE19;
  783. font-size: 26px;
  784. }
  785. .about-wrap .button {
  786. background-color: #0078C3;
  787. border: 1px solid #005990;
  788. border-radius: 4px;
  789. color: #fff;
  790. font-size: 16px;
  791. font-weight: 600;
  792. height: auto;
  793. line-height: 1;
  794. margin-bottom: 10px;
  795. padding: 14px 30px;
  796. text-align: center;
  797. }
  798. .about-wrap .button:hover,
  799. .about-wrap .button:focus {
  800. background-color: #005990;
  801. color: #fff
  802. }
  803. @media only screen and (max-width: 767px) {
  804. .about-wrap {
  805. padding: 0;
  806. }
  807. .about-wrap h1 {
  808. font-size: 26px;
  809. }
  810. .about-wrap h2 {
  811. font-size: 22px;
  812. }
  813. .about-wrap p {
  814. font-size: 14px;
  815. }
  816. .about-wrap ul,
  817. .about-wrap ol {
  818. font-size: 14px;
  819. }
  820. .about-wrap .logo {
  821. width: 120px;
  822. }
  823. .about-wrap .reasons {
  824. margin-right: 150px;
  825. }
  826. }
  827. </style>
  828. <?php
  829. }
  830. }
  831. new WPForms_Constant_Contact();