← All changes
|
src/Integrations/class-facebook-instant-articles.php
+23
-16
3.2.0
→
3.8.4
View file →
| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Facebook Instant Articles integration class | |
| 3 | + * Integrations: Facebook Instant Articles integration class | |
| 4 | 4 | * |
| 5 | - * @package Parsely\Integrations | |
| 6 | - * @since 2.6.0 | |
| 5 | + * @package Parsely | |
| 6 | + * @since 2.6.0 | |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | declare(strict_types=1); |
| 10 | 10 | |
| @@ -15,19 +15,27 @@ | ||
| 15 | 15 | /** |
| 16 | 16 | * Integrates Parse.ly tracking with the Facebook Instant Articles plugin. |
| 17 | 17 | * |
| 18 | 18 | * @since 2.6.0 Moved from Parsely class to this file. |
| 19 | + * | |
| 20 | + * @phpstan-type FB_Instant_Articles_Registry array{ | |
| 21 | + * 'parsely-analytics-for-wordpress'?: FB_Parsely_Registry, | |
| 22 | + * } | |
| 23 | + * | |
| 24 | + * @phpstan-type FB_Parsely_Registry array{ | |
| 25 | + * name: string, | |
| 26 | + * payload: string, | |
| 27 | + * } | |
| 19 | 28 | */ |
| 20 | -final class Facebook_Instant_Articles implements Integration { | |
| 29 | +final class Facebook_Instant_Articles extends Integration { | |
| 21 | 30 | private const REGISTRY_IDENTIFIER = 'parsely-analytics-for-wordpress'; |
| 22 | 31 | private const REGISTRY_DISPLAY_NAME = 'Parse.ly Analytics'; |
| 23 | 32 | |
| 24 | 33 | /** |
| 25 | - * Apply the hooks that integrate the plugin or theme with the Parse.ly plugin. | |
| 34 | + * Applies the hooks that integrate the plugin or theme with the Parse.ly | |
| 35 | + * plugin. | |
| 26 | 36 | * |
| 27 | 37 | * @since 2.6.0 |
| 28 | - * | |
| 29 | - * @return void | |
| 30 | 38 | */ |
| 31 | 39 | public function integrate(): void { |
| 32 | 40 | if ( defined( 'IA_PLUGIN_VERSION' ) ) { |
| 33 | 41 | add_action( 'instant_articles_compat_registry_analytics', array( $this, 'insert_parsely_tracking' ) ); |
| @@ -34,36 +42,35 @@ | ||
| 34 | 42 | } |
| 35 | 43 | } |
| 36 | 44 | |
| 37 | 45 | /** |
| 38 | - * Add Parse.ly tracking to Facebook instant articles. | |
| 46 | + * Adds Parse.ly tracking to Facebook instant articles. | |
| 39 | 47 | * |
| 40 | 48 | * @since 2.6.0 |
| 41 | 49 | * |
| 42 | - * @param array $registry The registry info for Facebook Instant Articles. | |
| 43 | - * @return void | |
| 50 | + * @param FB_Instant_Articles_Registry $registry The registry info for Facebook Instant Articles. | |
| 44 | 51 | */ |
| 45 | 52 | public function insert_parsely_tracking( &$registry ): void { |
| 46 | 53 | $parsely = new Parsely(); |
| 47 | - if ( $parsely->api_key_is_missing() ) { | |
| 54 | + if ( $parsely->site_id_is_missing() ) { | |
| 48 | 55 | return; |
| 49 | 56 | } |
| 50 | 57 | |
| 51 | 58 | $registry[ self::REGISTRY_IDENTIFIER ] = array( |
| 52 | 59 | 'name' => self::REGISTRY_DISPLAY_NAME, |
| 53 | - 'payload' => $this->get_embed_code( $parsely->get_api_key() ), | |
| 60 | + 'payload' => $this->get_embed_code( $parsely->get_site_id() ), | |
| 54 | 61 | ); |
| 55 | 62 | } |
| 56 | 63 | |
| 57 | 64 | /** |
| 58 | - * Get the payload / embed code. | |
| 65 | + * Returns the payload / embed code. | |
| 59 | 66 | * |
| 60 | 67 | * @since 2.6.0 |
| 61 | 68 | * |
| 62 | - * @param string $api_key API key. | |
| 69 | + * @param string $site_id Site ID. | |
| 63 | 70 | * @return string Embedded code. |
| 64 | 71 | */ |
| 65 | - private function get_embed_code( string $api_key ): string { | |
| 72 | + private function get_embed_code( string $site_id ): string { | |
| 66 | 73 | return '<script> |
| 67 | 74 | PARSELY = { |
| 68 | 75 | autotrack: false, |
| 69 | 76 | onload: function() { |
| @@ -73,7 +80,7 @@ | ||
| 73 | 80 | return true; |
| 74 | 81 | } |
| 75 | 82 | } |
| 76 | 83 | </script> |
| 77 | - <script data-cfasync="false" id="parsely-cfg" data-parsely-site="' . esc_attr( $api_key ) . '" src="//cdn.parsely.com/keys/' . esc_attr( $api_key ) . '/p.js"></script>'; | |
| 84 | + <script data-cfasync="false" id="parsely-cfg" data-parsely-site="' . esc_attr( $site_id ) . '" src="//cdn.parsely.com/keys/' . esc_attr( $site_id ) . '/p.js"></script>'; | |
| 78 | 85 | } |
| 79 | 86 | } |