Site Builder
Editing:
promptinator-shortcode.php
writable 0666
<?php /** * Plugin Name: Promptinator – Dynamic Prompt Short‑Code Builder * Plugin URI: https://bestdealon.com/plugins/promptinator * Description: Craft, store and reuse AI‑powered prompt templates directly inside WordPress posts and pages using an intuitive token‑based editor and modal UI. Built by Quanta X Technology. * Version: 1.0.0 * Author: John Coates * Author URI: https://bestdealon.com * Contributors: quantaxtech, johncoates * License: GPLv2 or later * License URI: https://www.gnu.org/licenses/gpl-2.0.html * Text Domain: promptinator * Domain Path: /languages * Requires at least: 6.0 * Tested up to: 6.8 * Requires PHP: 7.4 */ /* -------------------------------------------------------------------------- * Detect Promptinator blocks and inject the JS engine * ----------------------------------------------------------------------- */ if ( ! defined( 'ABSPATH' ) ) { exit; } /* -------------------------------------------------------------------------- * I18N – load .mo/.po files * ----------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- * Detect Promptinator blocks and enqueue assets on the front‑end * ----------------------------------------------------------------------- */ add_filter( 'the_posts', function ( $posts ) { if ( empty( $posts ) || is_admin() ) { return $posts; } foreach ( $posts as $post ) { if ( stripos( $post->post_content, 'class="Promptinator"' ) !== false ) { add_action( 'wp_enqueue_scripts', 'qtx_promptinator_enqueue' ); break; } } return $posts; } ); function qtx_promptinator_enqueue() { $assets_url = plugins_url( 'assets', __FILE__ ); $assets_dir = plugin_dir_path( __FILE__ ); // CSS wp_enqueue_style( 'promptinator-css', "$assets_url/promptinator.css", [], '1.0.0' ); // JS – ES module wp_register_script( 'promptinator', "$assets_url/promptinator.js", [ 'wp-i18n' ], '1.0.0', true ); wp_script_add_data( 'promptinator', 'type', 'module' ); wp_set_script_translations( 'promptinator', 'promptinator', $assets_dir . 'languages' ); wp_enqueue_script( 'promptinator' ); // Auto‑init blocks wp_add_inline_script( 'promptinator', "import('$assets_url/promptinator.js').then(m => { document.querySelectorAll('.Promptinator') .forEach(el => m.default.init({ mount: el })); });", 'after' ); } /* -------------------------------------------------------------------------- * Classic‑Editor / TinyMCE integration * ----------------------------------------------------------------------- */ add_action( 'admin_enqueue_scripts', function ( $hook ) { // Only on post editor screens if ( ! in_array( $hook, [ 'post.php', 'post-new.php' ], true ) ) { return; } wp_register_script( 'promptinator-tinymce', plugins_url( 'assets/promptinator-tinymce.js', __FILE__ ), [], '1.0.0', true ); /* ---------- CLEAN, UNIQUE LOCALISATION ARRAY ---------- */ wp_localize_script( 'promptinator-tinymce', 'promptinatorL10n', [ 'insertPrompt' => __( 'Wrap Selection as Promptinator', 'promptinator' ), 'promptHtml' => __( 'Prompt HTML', 'promptinator' ), 'selectAction' => __( 'Select action', 'promptinator' ), 'editPrompt' => __( 'Edit Prompt', 'promptinator' ), 'removePromptinator' => __( 'Remove Promptinator', 'promptinator' ), 'selectTextAlert' => __( 'Please select some text first.', 'promptinator' ), 'promptOptions' => __( 'Promptinator Options', 'promptinator' ), 'showEditor' => __( 'Allow Inline Editing', 'promptinator' ), 'connectAI' => __( 'Connect to AI', 'promptinator' ), 'yes' => __( 'Yes', 'promptinator' ), 'no' => __( 'No', 'promptinator' ), 'action' => __( 'Action', 'promptinator' ) ] ); wp_enqueue_script( 'promptinator-tinymce' ); } ); add_filter( 'mce_external_plugins', function ( $plugins ) { $plugins['promptinator'] = plugins_url( 'assets/promptinator-tinymce.js', __FILE__ ); return $plugins; } ); add_filter( 'mce_buttons', function ( $buttons ) { $buttons[] = 'promptinator'; return $buttons; } ); /* -------------------------------------------------------------------------- * TinyMCE content‑style helper – visual border * ----------------------------------------------------------------------- */ function promptinator_inline_editor_styles( $init ) { $css = '.Promptinator{border:1px solid #4CAF50!important;padding:4px 8px!important;border-radius:3px!important;}'; $init['content_style'] = empty( $init['content_style'] ) ? $css : $init['content_style'] . ' ' . $css; return $init; } add_filter( 'tiny_mce_before_init', 'promptinator_inline_editor_styles', 20 );
Save changes
Create folder
writable 0777
Create
Cancel