|
| 1 | +<?php |
| 2 | +/* |
| 3 | +Plugin Name: SimplePDF Embed |
| 4 | +Plugin URI: https://simplepdf.com/embed |
| 5 | +Author: SimplePDF |
| 6 | +Author URI: https://simplepdf.com |
| 7 | +Description: Your visitors can fill & sign PDFs without leaving your website. |
| 8 | +Version: 1.1.1 |
| 9 | +License: GPL v2 or later |
| 10 | +License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 11 | +*/ |
| 12 | + |
| 13 | +if ( ! defined( 'ABSPATH' ) ) exit; |
| 14 | + |
| 15 | +function simplepdf_settings_init() { |
| 16 | + add_option('simplepdf_auto_open_pdf', true); |
| 17 | + add_option('simplepdf_company_identifier'); |
| 18 | + |
| 19 | + add_submenu_page( |
| 20 | + 'options-general.php', |
| 21 | + 'SimplePDF Embed Settings', |
| 22 | + 'SimplePDF Embed', |
| 23 | + 'manage_options', |
| 24 | + 'simplepdf_settings', |
| 25 | + 'simplepdf_settings_page' |
| 26 | + ); |
| 27 | + |
| 28 | + |
| 29 | + add_settings_section( |
| 30 | + 'simplepdf_settings_section', |
| 31 | + 'SimplePDF Settings', |
| 32 | + 'simplepdf_settings_section_callback', |
| 33 | + 'simplepdf_settings' |
| 34 | + ); |
| 35 | + |
| 36 | + add_settings_field( |
| 37 | + 'simplepdf_auto_open_pdf', |
| 38 | + 'Automatically open PDFs with SimplePDF', |
| 39 | + 'simplepdf_auto_open_pdf_callback', |
| 40 | + 'simplepdf_settings', |
| 41 | + 'simplepdf_settings_section' |
| 42 | + ); |
| 43 | + |
| 44 | + add_settings_field( |
| 45 | + 'simplepdf_company_identifier', |
| 46 | + 'Company Identifier', |
| 47 | + 'simplepdf_company_identifier_callback', |
| 48 | + 'simplepdf_settings', |
| 49 | + 'simplepdf_settings_section' |
| 50 | + ); |
| 51 | + |
| 52 | + register_setting('simplepdf_settings', 'simplepdf_auto_open_pdf'); |
| 53 | + register_setting('simplepdf_settings', 'simplepdf_company_identifier'); |
| 54 | +} |
| 55 | + |
| 56 | +function simplepdf_settings_section_callback() { |
| 57 | + echo '<p>Configure the SimplePDF Embed settings:</p>'; |
| 58 | +} |
| 59 | + |
| 60 | +function simplepdf_auto_open_pdf_callback() { |
| 61 | + $value = get_option('simplepdf_auto_open_pdf'); |
| 62 | + echo '<div style="display: flex; align-items: center;"><input type="checkbox" name="simplepdf_auto_open_pdf" value="1"' . checked(1, $value, false) . '>'; |
| 63 | + echo '<i style="margin-left: 8px;">Links with the extension .pdf are opened with SimplePDF</i>'; |
| 64 | + echo '</div>'; |
| 65 | +} |
| 66 | + |
| 67 | +function simplepdf_company_identifier_callback() { |
| 68 | + $value = get_option('simplepdf_company_identifier'); |
| 69 | + echo '<input type="text" name="simplepdf_company_identifier" value="' . esc_attr($value) . '">'; |
| 70 | + echo '<p style="margin-top: 8px; margin-bottom: 8px"><b>Signup to get your own company identifier: <a href="https://simplepdf.com/embed#wp" target="_blank">SimplePDF/embed</a>.</b></p>'; |
| 71 | + echo '<ul style="list-style: circle;padding-left: 20px;">'; |
| 72 | + echo '<li><a href="https://simplepdf.com/help/how-to/customize-the-pdf-editor-and-add-branding#wp" target="_blank">Use your own branding and loading</a></li>'; |
| 73 | + echo '<li><a href="https://simplepdf.com/help/how-to/get-email-notifications-for-pdf-form-submissions#wp" target="_blank">Automatically receive the submissions in your inbox</a></li>'; |
| 74 | + echo '<li><a href="https://simplepdf.com/help/how-to/customize-the-pdf-editor-and-add-branding#wp" target="_blank">Customize the editor: show or hide specific fields</a></li>'; |
| 75 | + echo '</ul>'; |
| 76 | +} |
| 77 | + |
| 78 | +function enqueue_simplepdf_script() { |
| 79 | + |
| 80 | + $auto_open_pdf = get_option('simplepdf_auto_open_pdf'); |
| 81 | + |
| 82 | + if ($auto_open_pdf) { |
| 83 | + $plugin_url = plugin_dir_url(__FILE__); |
| 84 | + $script_src = $plugin_url . 'build/web-embed-pdf.js'; |
| 85 | + |
| 86 | + wp_enqueue_script('simplepdf-web-embed-pdf', $script_src, array(), '1.7.2', true); |
| 87 | + |
| 88 | + $company_identifier = get_option('simplepdf_company_identifier'); |
| 89 | + $companyIdentifier = empty($company_identifier) ? 'wordpress' : $company_identifier; |
| 90 | + $inline_script = "window.simplePDF = {companyIdentifier: '" . esc_js($companyIdentifier) . "'};"; |
| 91 | + |
| 92 | + wp_add_inline_script('simplepdf-web-embed-pdf', $inline_script, 'before'); |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +function simplepdf_settings_page() { |
| 97 | + ?> |
| 98 | + <div class="wrap"> |
| 99 | + <h1>SimplePDF Embed Settings</h1> |
| 100 | + <form method="post" action="options.php"> |
| 101 | + <?php |
| 102 | + settings_fields('simplepdf_settings'); |
| 103 | + do_settings_sections('simplepdf_settings'); |
| 104 | + submit_button(); |
| 105 | + ?> |
| 106 | + </form> |
| 107 | + </div> |
| 108 | + <?php |
| 109 | +} |
| 110 | + |
| 111 | +add_action('admin_menu', 'simplepdf_settings_init'); |
| 112 | +add_action('wp_enqueue_scripts', 'enqueue_simplepdf_script'); |
| 113 | +?> |
0 commit comments