| @@ -14,17 +14,8 @@ | ||
| 14 | 14 | */ |
| 15 | 15 | class ConvertKit_Output { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * Holds the ConvertKit Subscriber ID. | |
| 19 | - * | |
| 20 | - * @since 2.0.6 | |
| 21 | - * | |
| 22 | - * @var int|string | |
| 23 | - */ | |
| 24 | - private $subscriber_id = 0; | |
| 25 | - | |
| 26 | - /** | |
| 27 | 18 | * Holds the ConvertKit Plugin Settings class |
| 28 | 19 | * |
| 29 | 20 | * @since 1.9.6 |
| 30 | 21 | * |
| @@ -66,14 +57,12 @@ | ||
| 66 | 57 | * @since 1.9.6 |
| 67 | 58 | */ |
| 68 | 59 | public function __construct() { |
| 69 | 60 | |
| 70 | - add_action( 'init', array( $this, 'get_subscriber_id_from_request' ), 1 ); | |
| 71 | 61 | add_action( 'template_redirect', array( $this, 'output_form' ) ); |
| 72 | 62 | add_action( 'template_redirect', array( $this, 'page_takeover' ) ); |
| 73 | 63 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| 74 | 64 | add_filter( 'the_content', array( $this, 'append_form_to_content' ) ); |
| 75 | - add_action( 'wp_footer', array( $this, 'output_scripts_footer' ) ); | |
| 76 | 65 | |
| 77 | 66 | } |
| 78 | 67 | |
| 79 | 68 | /** |
| @@ -370,9 +359,9 @@ | ||
| 370 | 359 | array( |
| 371 | 360 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 372 | 361 | 'debug' => $settings->debug_enabled(), |
| 373 | 362 | 'nonce' => wp_create_nonce( 'convertkit' ), |
| 374 | - 'subscriber_id' => $this->subscriber_id, | |
| 363 | + 'subscriber_id' => $this->get_subscriber_id_from_request(), | |
| 375 | 364 | 'tag' => ( ( is_singular() && $convertkit_post->has_tag() ) ? $convertkit_post->get_tag() : false ), |
| 376 | 365 | 'post_id' => $post->ID, |
| 377 | 366 | ) |
| 378 | 367 | ); |
| @@ -390,8 +379,10 @@ | ||
| 390 | 379 | /** |
| 391 | 380 | * Gets the subscriber ID from the request (either the cookie or the URL). |
| 392 | 381 | * |
| 393 | 382 | * @since 1.9.6 |
| 383 | + * | |
| 384 | + * @return int Subscriber ID | |
| 394 | 385 | */ |
| 395 | 386 | public function get_subscriber_id_from_request() { |
| 396 | 387 | |
| 397 | 388 | // Use ConvertKit_Subscriber class to fetch and validate the subscriber ID. |
| @@ -399,73 +390,12 @@ | ||
| 399 | 390 | $subscriber_id = $subscriber->get_subscriber_id(); |
| 400 | 391 | |
| 401 | 392 | // If an error occured, the subscriber ID in the request/cookie is not a valid subscriber. |
| 402 | 393 | if ( is_wp_error( $subscriber_id ) ) { |
| 403 | - return; | |
| 394 | + return 0; | |
| 404 | 395 | } |
| 405 | 396 | |
| 406 | - $this->subscriber_id = $subscriber_id; | |
| 407 | - | |
| 408 | - } | |
| 409 | - | |
| 410 | - /** | |
| 411 | - * Outputs any JS <script> tags registered with the convertkit_output_scripts_footer | |
| 412 | - * filter | |
| 413 | - * | |
| 414 | - * @since 2.1.4 | |
| 415 | - */ | |
| 416 | - public function output_scripts_footer() { | |
| 417 | - | |
| 418 | - // Define array of scripts. | |
| 419 | - $scripts = array(); | |
| 420 | - | |
| 421 | - /** | |
| 422 | - * Define an array of scripts to output in the footer of the WordPress site. | |
| 423 | - * | |
| 424 | - * @since 2.1.4 | |
| 425 | - * | |
| 426 | - * @param array $scripts Scripts. | |
| 427 | - */ | |
| 428 | - $scripts = apply_filters( 'convertkit_output_scripts_footer', $scripts ); | |
| 429 | - | |
| 430 | - // Bail if no scripts exist. | |
| 431 | - if ( ! count( $scripts ) ) { | |
| 432 | - return; | |
| 433 | - } | |
| 434 | - | |
| 435 | - // Define array to store <script> outputs. | |
| 436 | - $output_scripts = array(); | |
| 437 | - | |
| 438 | - // Iterate through scripts, building the <script> tag for each. | |
| 439 | - foreach ( $scripts as $script ) { | |
| 440 | - $output = '<script'; | |
| 441 | - | |
| 442 | - foreach ( $script as $attribute => $value ) { | |
| 443 | - // If the value is true, just output the attribute. | |
| 444 | - if ( $value === true ) { | |
| 445 | - $output .= ' ' . esc_attr( $attribute ); | |
| 446 | - continue; | |
| 447 | - } | |
| 448 | - | |
| 449 | - // Output the attribute and value. | |
| 450 | - $output .= ' ' . esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; | |
| 451 | - } | |
| 452 | - $output .= '></script>'; | |
| 453 | - | |
| 454 | - // Add to array. | |
| 455 | - $output_scripts[] = $output; | |
| 456 | - } | |
| 457 | - | |
| 458 | - // Remove duplicate scripts. | |
| 459 | - // This prevents the same non-inline form displaying twice. For example, if a modal form is specified both | |
| 460 | - // in the Page's settings and the Form block, the user would see the same modal form displayed twice | |
| 461 | - // because the script would be output twice. | |
| 462 | - $output_scripts = array_unique( $output_scripts ); | |
| 463 | - | |
| 464 | - // Output scripts. | |
| 465 | - foreach ( $output_scripts as $output_script ) { | |
| 466 | - echo $output_script . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 467 | - } | |
| 397 | + return $subscriber_id; | |
| 468 | 398 | |
| 469 | 399 | } |
| 470 | 400 | |
| 471 | 401 | } |