PluginProbe
Pdf Embed / 0.5.7
Pdf Embed v0.5.7
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.7, at pdf-embed.php

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