render_preview_metabox($post) { $btn_url = admin_url('admin-ajax.php'); $attr = ['data-action' => 'dce_preview_pdf_html_template', 'data-url' => $btn_url, 'id' => 'dce-preview-pdf', 'type' => 'button', 'class' => 'dce-pdf-preview-button']; echo ''; echo '
'; } // This function will only present the font options to the user. public function render_fonts_metabox($post) { echo '' . __('The following fonts can be used with the font-family
CSS property. ', 'dynamic-content-for-elementor') . '
';
echo __('The available core fonts are: ', 'dynamic-content-for-elementor');
echo 'ctimes
, chelvetica
, ccourier
';
echo '
' . __('RTL languages: please notice that you cannot use the core fonts in a page that contains also an RTL language, like Arabic or Hebrew. Upload them as Custom Fonts if you need them.', 'dynamic-content-for-elementor') . '
'; echo '' . $text . '
'; $font_data = $this->get_fonts()['fonts']; echo '' . $font_name . '
, ' . __('weight-style variants:', 'dynamic-content-for-elementor') . ' (';
echo '' . __('To insert an image, first go to the ', 'dynamic-content-for-elementor'); echo "" . __('WordPress Media Library', 'dynamic-content-for-elementor') . ''; echo __(', select an image and find its ID. Then you can use the image like this:', 'dynamic-content-for-elementor') . '
'; echo '<img src="{{ Image( <ID> ).file_loc }}">
';
echo '' . __('Notice how we used .file_loc
, which is a file system path, instead of a URL. Avoid image URLs as they will be slow to fetch.', 'dynamic-content-for-elementor') . '
' . __('To insert a signature you can use:', 'dynamic-content-for-elementor') . '
'; echo '<img src="{{ form_raw.signature_field_id }}">
';
}
// Render a select2 input where $id is its id, and $post_id is the
// preselected post id.
public function render_select2($id, $post_id, $label)
{
// do not forget about WP Nonces for security purposes
$attr = ['name' => $id, 'id' => $id, 'style' => 'width:99%;max-width:25em;'];
if ($post_id) {
$title = wp_kses_post(get_the_title($post_id));
$title = \mb_strlen($title) > 50 ? \mb_substr($title, 0, 49) . '...' : $title;
}
echo '
';
echo '
'; echo '
'; } public function render_dimensions_metabox($post) { $data = get_post_meta($post->ID, self::TEMPLATE_META_KEY, \true); $format_attr = ['name' => self::FIELD_FORMAT, 'id' => self::FIELD_FORMAT]; $orientation_attr = ['name' => self::FIELD_ORIENTATION, 'type' => 'radio']; $selected_format = $data[self::FIELD_FORMAT] ?? 'A4'; $selected_orientation = $data[self::FIELD_ORIENTATION] ?? 'P'; $formats = ['A4', 'A5', 'A6', 'Letter', 'Legal', 'Executive', 'Folio']; echo ''; echo ''; echo ''; $checked = $selected_orientation === 'P' ? ' checked ' : ''; echo 'get_attribute_string($orientation_attr) . $checked . '>'; echo ''; $checked = $selected_orientation === 'L' ? ' checked ' : ''; echo 'get_attribute_string($orientation_attr) . $checked . '>'; echo '
'; } private function get_code_editor_settings() { // TODO: Handle `enqueue_code_editor_scripts` to work with `lint => 'true'`. return ['type' => 'text/html', 'codemirror' => ['indentUnit' => 2, 'tabSize' => 2, 'mode' => ['name' => 'twig', 'base' => 'text/html']]]; } private function enqueue_code_editor_scripts($field_code_id) { wp_enqueue_script('htmlhint'); wp_enqueue_script('csslint'); wp_add_inline_script( // fix as described here: https://make.wordpress.org/core/2017/10/22/code-editing-improvements-in-wordpress-4-9/ 'wp-codemirror', 'window.CodeMirror = wp.CodeMirror;' ); wp_enqueue_script('codemirror-twig', 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.29.0/mode/twig/twig.min.js', ['wp-codemirror'], DCE_VERSION, \false); /** * Some of the plugins may load 'code-editor' for their needs and change the default behavior, so it should * re-initialize the code editor with 'custom code' settings. */ if (wp_script_is('code-editor')) { wp_add_inline_script('code-editor', \sprintf('wp.codeEditor.initialize( jQuery( "#%s"), %s );', $field_code_id, wp_json_encode(wp_get_code_editor_settings($this->get_code_editor_settings())))); } else { wp_enqueue_code_editor($this->get_code_editor_settings()); wp_add_inline_script('code-editor', \sprintf('wp.codeEditor.initialize( jQuery( "#%s") );', $field_code_id)); } } public function add_meta_boxes() { add_meta_box('elementor-pdf-html-code-metabox', __('HTML', 'dynamic-content-for-elementor'), [$this, 'render_code_metabox'], self::CPT, 'normal', 'default'); add_meta_box('elementor-pdf-html-preview-metabox', __('Preview', 'dynamic-content-for-elementor'), [$this, 'render_preview_metabox'], self::CPT, 'side', 'default'); add_meta_box('elementor-pdf-html-dimensions-metabox', __('Dimensions', 'dynamic-content-for-elementor'), [$this, 'render_dimensions_metabox'], self::CPT, 'normal', 'default'); add_meta_box('elementor-pdf-html-fonts-metabox', __('Fonts', 'dynamic-content-for-elementor'), [$this, 'render_fonts_metabox'], self::CPT, 'normal', 'default'); add_meta_box('elementor-pdf-html-preview-data-metabox', __('Preview Data', 'dynamic-content-for-elementor'), [$this, 'render_preview_data_metabox'], self::CPT, 'normal', 'default'); add_meta_box('elementor-pdf-html-image-metabox', __('Inserting Images', 'dynamic-content-for-elementor'), [$this, 'render_images_metabox'], self::CPT, 'side', 'default'); } }