| @@ -49,40 +49,14 @@ | ||
| 49 | 49 | $context |
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - // Get last query time and existing resources. | |
| 54 | - $this->last_queried = get_option( $this->settings_name . '_last_queried' ); | |
| 55 | - $this->resources = get_option( $this->settings_name ); | |
| 53 | + // Call parent initialization function. | |
| 54 | + parent::init(); | |
| 56 | 55 | |
| 57 | 56 | } |
| 58 | 57 | |
| 59 | 58 | /** |
| 60 | - * Fetches resources (forms, landing pages or tags) from the API, storing them in the options table | |
| 61 | - * with a last queried timestamp. | |
| 62 | - * | |
| 63 | - * If the refresh results in a 401, removes the access and refresh tokens from the settings. | |
| 64 | - * | |
| 65 | - * @since 3.1.2 | |
| 66 | - * | |
| 67 | - * @return WP_Error|array | |
| 68 | - */ | |
| 69 | - public function refresh() { | |
| 70 | - | |
| 71 | - // Call parent refresh method. | |
| 72 | - $result = parent::refresh(); | |
| 73 | - | |
| 74 | - // If an error occured, maybe delete credentials from the Plugin's settings | |
| 75 | - // if the error is a 401 unauthorized. | |
| 76 | - if ( is_wp_error( $result ) ) { | |
| 77 | - convertkit_maybe_delete_credentials( $result, CONVERTKIT_OAUTH_CLIENT_ID ); | |
| 78 | - } | |
| 79 | - | |
| 80 | - return $result; | |
| 81 | - | |
| 82 | - } | |
| 83 | - | |
| 84 | - /** | |
| 85 | 59 | * Returns all inline forms based on the sort order. |
| 86 | 60 | * |
| 87 | 61 | * @since 2.7.3 |
| 88 | 62 | * |
| @@ -499,13 +473,12 @@ | ||
| 499 | 473 | * Current Forms will return a <script> embed string. |
| 500 | 474 | * |
| 501 | 475 | * @since 1.9.6 |
| 502 | 476 | * |
| 503 | - * @param int $id Form ID. | |
| 504 | - * @param int $post_id Post ID that requested the Form. | |
| 477 | + * @param int $id Form ID. | |
| 505 | 478 | * @return WP_Error|string |
| 506 | 479 | */ |
| 507 | - public function get_html( $id, $post_id = 0 ) { | |
| 480 | + public function get_html( $id ) { | |
| 508 | 481 | |
| 509 | 482 | // Cast ID to integer. |
| 510 | 483 | $id = absint( $id ); |
| 511 | 484 | |
| @@ -521,19 +494,18 @@ | ||
| 521 | 494 | sprintf( |
| 522 | 495 | /* translators: ConvertKit Form ID */ |
| 523 | 496 | __( 'Kit Form ID %s does not exist on Kit.', 'convertkit' ), |
| 524 | 497 | $id |
| 525 | - ), | |
| 526 | - 404 | |
| 498 | + ) | |
| 527 | 499 | ); |
| 528 | 500 | } |
| 529 | 501 | |
| 530 | - // Initialize Settings. | |
| 531 | - $settings = new ConvertKit_Settings(); | |
| 532 | - | |
| 533 | 502 | // If no uid is present in the Form API data, this is a legacy form that's served by directly fetching the HTML |
| 534 | 503 | // from forms.kit.com. |
| 535 | 504 | if ( ! isset( $this->resources[ $id ]['uid'] ) ) { |
| 505 | + // Initialize Settings. | |
| 506 | + $settings = new ConvertKit_Settings(); | |
| 507 | + | |
| 536 | 508 | // Bail if no Access Token is specified in the Plugin Settings. |
| 537 | 509 | if ( ! $settings->has_access_token() ) { |
| 538 | 510 | return new WP_Error( |
| 539 | 511 | 'convertkit_resource_forms_get_html', |
| @@ -563,26 +535,16 @@ | ||
| 563 | 535 | // displaying twice. |
| 564 | 536 | if ( $this->resources[ $id ]['format'] !== 'inline' ) { |
| 565 | 537 | add_filter( |
| 566 | 538 | 'convertkit_output_scripts_footer', |
| 567 | - function ( $scripts ) use ( $id, $post_id, $settings ) { | |
| 539 | + function ( $scripts ) use ( $id ) { | |
| 568 | 540 | |
| 569 | - // Build script. | |
| 570 | - $script = array( | |
| 571 | - 'async' => true, | |
| 572 | - 'data-uid' => $this->resources[ $id ]['uid'], | |
| 573 | - 'src' => $this->resources[ $id ]['embed_js'], | |
| 574 | - 'data-kit-limit-per-session' => $settings->non_inline_form_limit_per_session() ? '1' : '0', | |
| 541 | + $scripts[] = array( | |
| 542 | + 'async' => true, | |
| 543 | + 'data-uid' => $this->resources[ $id ]['uid'], | |
| 544 | + 'src' => $this->resources[ $id ]['embed_js'], | |
| 575 | 545 | ); |
| 576 | 546 | |
| 577 | - // If debugging is enabled, add the post ID to the script. | |
| 578 | - if ( $settings->debug_enabled() ) { | |
| 579 | - $script['data-kit-source-post-id'] = $post_id; | |
| 580 | - } | |
| 581 | - | |
| 582 | - // Add the script to the scripts array. | |
| 583 | - $scripts[] = $script; | |
| 584 | - | |
| 585 | 547 | return $scripts; |
| 586 | 548 | |
| 587 | 549 | } |
| 588 | 550 | ); |
| @@ -611,13 +573,8 @@ | ||
| 611 | 573 | 'async' => true, |
| 612 | 574 | 'data-uid' => $this->resources[ $id ]['uid'], |
| 613 | 575 | 'src' => $this->resources[ $id ]['embed_js'], |
| 614 | 576 | ); |
| 615 | - | |
| 616 | - // If debugging is enabled, add the post ID to the script. | |
| 617 | - if ( $settings->debug_enabled() ) { | |
| 618 | - $script['data-kit-source-post-id'] = $post_id; | |
| 619 | - } | |
| 620 | 577 | |
| 621 | 578 | /** |
| 622 | 579 | * Filter the form <script> key/value pairs immediately before the script is output. |
| 623 | 580 | * |