PluginProbe
Pdf Embed / 0.5.0
Pdf Embed v0.5.0
0.6.2 0.6.1 trunk 0.1.0 0.1.1 0.1.2 0.1.3 0.1.4 0.1.5 0.1.6 0.1.7 0.1.8 0.1.9 0.2.0 0.2.1 0.2.2 0.2.3 0.2.4 0.2.5 0.2.6 0.2.7 0.2.8 0.2.9 0.3.0 0.3.1 All 54 releases
pdf-embed / pdf-embed.php

pdf-embed.php in Pdf Embed 0.5.0, at pdf-embed.php

112 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Pdf Embed
4 * Plugin URI: https://francescopepe.com/
5 * Description: PDF embedded with official Adobe API.
6 * Version: 0.5.0
7 * Author: Tropicalista
8 * Author URI: https://www.francescopepe.com
9 * License: GPL2
10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 * Text Domain: pdf-embed
12 *
13 * @package Formello/PdfEmbed
14 */
15
16 require __DIR__ . '/vendor/autoload.php';
17
18 /**
19 * Registers the block using the metadata loaded from the `block.json` file.
20 * Behind the scenes, it registers also all assets so they can be enqueued
21 * through the block editor in the corresponding context.
22 *
23 * @see https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/writing-your-first-block-type/
24 */
25 function pdf_embed_block_init() {
26 register_block_type_from_metadata(
27 __DIR__ . '/build'
28 );
29 $args = array(
30 'type' => 'string',
31 'sanitize_callback' => 'sanitize_text_field',
32 'default' => '',
33 'show_in_rest' => true,
34 );
35 register_setting( 'embed_pdf', 'pdf_embed_api_key', $args );
36 }
37 add_action( 'init', 'pdf_embed_block_init' );
38
39 /**
40 * Register settings
41 */
42 function pdf_embed_setting() {
43 $key = wp_json_encode(
44 array(
45 'apiKey' => get_option( 'pdf_embed_api_key', '' ),
46 )
47 );
48 wp_add_inline_script(
49 'tropicalista-pdfembed-view-script',
50 'const pdf_embed = ' . $key,
51 'before'
52 );
53 wp_add_inline_script(
54 'tropicalista-pdfembed-editor-script',
55 'const pdf_embed = ' . $key,
56 'before'
57 );
58 }
59 add_action( 'init', 'pdf_embed_setting' );
60
61 /**
62 * Adds pdf embed to button
63 *
64 * @param string $block_content The content.
65 * @param array $block The block.
66 */
67 function pdf_embed_render( $block_content, $block ) {
68 if ( ! empty( $block['attrs']['embedPdf'] ) ) {
69 wp_enqueue_script( 'tropicalista-pdfembed-view-script' );
70 }
71 return $block_content;
72 }
73 add_filter( 'render_block', 'pdf_embed_render', 10, 2 );
74
75 /**
76 * Initialize the plugin tracker
77 *
78 * @return void
79 */
80 function pdf_embed_init_tracker() {
81
82 if ( ! class_exists( 'Appsero\Client' ) ) {
83 require_once __DIR__ . '/appsero/src/Client.php';
84 }
85
86 $client = new Appsero\Client( '48a870fe-75a1-476f-a4d6-bacc22ba54f1', 'Pdf Embed', __FILE__ );
87
88 $client->insights()->init();
89 }
90 pdf_embed_init_tracker();
91
92 /**
93 * Fires after tracking permission allowed (optin)
94 *
95 * @param array $data The Appsero data.
96 *
97 * @return void
98 */
99 function pdf_embed_tracker_optin( $data ) {
100 $data['project'] = 'pdf-embed';
101 $response = wp_remote_post(
102 'https://hook.eu1.make.com/dplrdfggemll51whv3b21yjabuk8po0b',
103 array(
104 'headers' => array( 'Content-Type' => 'application/json; charset=utf-8' ),
105 'body' => wp_json_encode( $data ),
106 'method' => 'POST',
107 'data_format' => 'body',
108 )
109 );
110 }
111 add_action( 'pdf-embed_tracker_optin', 'pdf_embed_tracker_optin', 10 );
112