PluginProbe
Pdf Embed / 0.5.4
Pdf Embed v0.5.4
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.4, at pdf-embed.php

137 lines 3.6 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://www.francescopepe.com/
5 * Description: PDF embedded with official Adobe API.
6 * Version: 0.5.4
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 $args = array(
37 'type' => 'object',
38 'default' => array(
39 'apiKey' => '',
40 'embedMode' => 'FULL_WINDOW',
41 'defaultViewMode' => 'FIT_PAGE',
42 'height' => '500px',
43 'measurementId' => '',
44 'showDownloadPDF' => false,
45 'showPrintPDF' => false,
46 'showFullScreen' => false,
47 'showZoomControl' => false,
48 'showAnnotationTools' => false,
49 'showBookmarks' => false,
50 'showThumbnails' => false,
51 'dockPageControls' => false,
52 'enableTextSelection' => false,
53 'enableFormFilling' => false,
54 'enableLinearization' => false,
55 ),
56 'show_in_rest' => array(
57 'schema' => array(
58 'type' => 'object',
59 'additionalProperties' => true,
60 ),
61 ),
62 );
63 register_setting( 'pdf_embed', 'pdf_embed', $args );
64 }
65 add_action( 'init', 'pdf_embed_block_init' );
66
67 /**
68 * Register settings
69 */
70 function pdf_embed_setting() {
71 $options = get_option( 'pdf_embed', '' );
72
73 wp_add_inline_script(
74 'tropicalista-pdfembed-view-script',
75 'const pdf_embed = ' . wp_json_encode( $options ),
76 'before'
77 );
78 wp_add_inline_script(
79 'tropicalista-pdfembed-editor-script',
80 'const pdf_embed = ' . wp_json_encode( $options ),
81 'before'
82 );
83 }
84 add_action( 'init', 'pdf_embed_setting' );
85
86 /**
87 * Adds pdf embed to button
88 *
89 * @param string $block_content The content.
90 * @param array $block The block.
91 */
92 function pdf_embed_render( $block_content, $block ) {
93 if ( ! empty( $block['attrs']['embedPdf'] ) ) {
94 wp_enqueue_script( 'tropicalista-pdfembed-view-script' );
95 }
96 return $block_content;
97 }
98 add_filter( 'render_block', 'pdf_embed_render', 10, 2 );
99
100 /**
101 * Initialize the plugin tracker
102 *
103 * @return void
104 */
105 function pdf_embed_init_tracker() {
106
107 if ( ! class_exists( 'Appsero\Client' ) ) {
108 require_once __DIR__ . '/appsero/src/Client.php';
109 }
110
111 $client = new Appsero\Client( '48a870fe-75a1-476f-a4d6-bacc22ba54f1', 'Pdf Embed', __FILE__ );
112
113 $client->insights()->init();
114 }
115 pdf_embed_init_tracker();
116
117 /**
118 * Fires after tracking permission allowed (optin)
119 *
120 * @param array $data The Appsero data.
121 *
122 * @return void
123 */
124 function pdf_embed_tracker_optin( $data ) {
125 $data['project'] = 'pdf-embed';
126 $response = wp_remote_post(
127 'https://hook.eu1.make.com/dplrdfggemll51whv3b21yjabuk8po0b',
128 array(
129 'headers' => array( 'Content-Type' => 'application/json; charset=utf-8' ),
130 'body' => wp_json_encode( $data ),
131 'method' => 'POST',
132 'data_format' => 'body',
133 )
134 );
135 }
136 add_action( 'pdf-embed_tracker_optin', 'pdf_embed_tracker_optin', 10 );
137