'post-snippets-block', // 'render_callback' => array($this, 'render_block_content'), 'render_callback' => function ($attributes) { return PSallSnippets::render_block_content($attributes); }, )); wp_localize_script('post-snippets-block', 'all_snippets', array( 'all_snippets' => PSallSnippets::get_all_snippets_gutenberg() )); } // ------------------------------------------------------------------------- // Setup // ------------------------------------------------------------------------- /** * Register the administration page. * * @return void */ public function menu() { $capability = $this->get_allowed_capability(); if ($capability == 'edit_posts') { $allowed = true; } if (current_user_can('manage_options') or isset($allowed)) { $optionPage = add_menu_page( __('Post Snippets', 'post-snippets'), __('Post Snippets', 'post-snippets'), $capability, 'post-snippets', array( $this, 'allSnippetsPage', ), PS_URL . 'assets/icon.svg' ); add_action("load-$optionPage", array($this, 'add_screen_options')); $allSnippets = add_submenu_page( 'post-snippets', __('All Snippets', 'post-snippets'), __('All Snippets', 'post-snippets'), $capability, 'post-snippets', array( $this, 'allSnippetsPage', ) ); $editSnippets = add_submenu_page( 'post-snippets', __('Add Custom Code', 'post-snippets'), __('Add Custom Code', 'post-snippets'), $capability, 'post-snippets-edit', array( $this, 'editPage', ) ); add_action('load-' . $editSnippets, array(\PostSnippets::EDIT_CLASS, 'page_actions'), 9); add_action('admin_footer-' . $editSnippets, array(\PostSnippets::EDIT_CLASS, 'footer_scripts')); add_filter('admin_title', array(\PostSnippets::EDIT_CLASS, 'change_edit_snippet_page_title'), 10, 2); /**Add CSS */ $editCSS = add_submenu_page( 'post-snippets', __('Add Custom CSS', 'post-snippets'), __('Add Custom CSS', 'post-snippets'), $capability, 'post-snippets-edit-css', array( $this, 'editPage', ) ); add_action('load-' . $editCSS, array(\PostSnippets::EDIT_CLASS, 'page_actions'), 9); add_action('admin_footer-' . $editCSS, array(\PostSnippets::EDIT_CLASS, 'footer_scripts')); add_filter('admin_title', array(\PostSnippets::EDIT_CLASS, 'change_edit_snippet_page_title'), 10, 2); /**Add JS */ $editJS = add_submenu_page( 'post-snippets', __('Add Custom JS', 'post-snippets'), __('Add Custom JS', 'post-snippets'), $capability, 'post-snippets-edit-js', array( $this, 'editPage', ) ); add_action('load-' . $editJS, array(\PostSnippets::EDIT_CLASS, 'page_actions'), 9); add_action('admin_footer-' . $editJS, array(\PostSnippets::EDIT_CLASS, 'footer_scripts')); add_filter('admin_title', array(\PostSnippets::EDIT_CLASS, 'change_edit_snippet_page_title'), 10, 2); $snippetsOptions = add_submenu_page( 'post-snippets', __('Options', 'post-snippets'), __('Options', 'post-snippets'), $capability, 'post-snippets-options', array( $this, // 'optionsPage', 'tabOptions' ) ); $snippetsImpExp = add_submenu_page( 'post-snippets', __('Import/Export', 'post-snippets'), __('Import/Export', 'post-snippets'), $capability, 'post-snippets-imp-exp', array( $this, 'tabTools', ) ); $newsPage = add_submenu_page( 'post-snippets', __('News', 'post-snippets'), __('News', 'post-snippets'), $capability, 'post-snippets-news', array( $this, 'newsPage', ) ); $chatbot_ai = add_submenu_page( 'post-snippets', __( 'AI Chatbot', 'post-snippets' ), __( 'AI Chatbot', 'post-snippets' ), $capability, 'post-snippets-chatbot', array( $this, 'chatbot_ai', ) ); add_submenu_page($this->_admin_page, __('👉 Get Pro Bundle', 'post-snippets'), sprintf('👉 %1$s %2$s  âž¤', __('Get', 'post-snippets'), __('Pro Bundle', 'post-snippets')), $capability, $this->_admin_upgrade_page, ''); /*$optionPage = add_submenu_page( __( 'Post Snippets', 'post-snippets'), __( 'Post Snippets', 'post-snippets'), $capability, 'post-snippets', array ( &$this, 'optionsPage' ) );*/ new Help($editSnippets); } else { add_menu_page( __('Post Snippets', 'post-snippets'), __('Post Snippets', 'post-snippets'), 'manage_options', 'post-snippets', array( $this, 'overviewPage', ), PS_URL . 'assets/icon.svg' ); } } function add_screen_options() { $option = 'per_page'; $args = array( 'label' => __('Number of items per page', 'post-snippets'), 'default' => 10, 'option' => 'psp_snippets_per_page' ); add_screen_option($option, $args); } function all_snippets_set_option($status, $option, $value) { return $value; } /** * Initialize assets for the administration page. * * @return void */ public function init() { wp_register_script('post-snippets', plugins_url('/assets/post-snippets.js', \PostSnippets::FILE), array('jquery', 'wp-i18n'), PS_VERSION, true); if (postsnippets_fs()->can_use_premium_code__premium_only()) { wp_register_script('post-snippets-pro', plugins_url('/assets-pro/post-snippets-pro.js', \PostSnippets::FILE), array( 'jquery', 'post-snippets' ), PS_VERSION, true); // wp_register_script( 'quill', plugins_url( '/assets-pro/quill.min.js', \PostSnippets::FILE ), array( // 'post-snippets-pro' // ), PS_VERSION, true ); } wp_set_script_translations('post-snippets', 'post-snippets'); /**To use wp i18n in JS */ $this->scripts(); $this->registerSettings(); } /** * Enqueue scripts to be loaded. * * @return void */ public function scripts() { // Localize the strings in the script $translation_array = array( 'invalid_shortcode' => __('Invalid shortcode name', 'post-snippets'), 'save_title_nonce' => wp_create_nonce('ps-save-title-nonce'), 'update_snippet_nonce' => wp_create_nonce('ps-update-snippet-nonce'), ); wp_localize_script('post-snippets', 'post_snippets', $translation_array); // Add CSS for Pro features page $features_style_url = plugins_url('/assets/features.css', \PostSnippets::FILE); wp_register_style('post-snippets-icons', $features_style_url, array(), PS_VERSION); wp_enqueue_style('post-snippets-icons'); // Add CSS for icons $features_style_url = plugins_url('/assets/icons.css', \PostSnippets::FILE); wp_register_style('post-snippets-features', $features_style_url, array(), PS_VERSION); wp_enqueue_style('post-snippets-features'); // Add CSS for newsletter opt-in $features_style_url = plugins_url('/assets/newsletter.css', \PostSnippets::FILE); wp_register_style('post-snippets-newsletter', $features_style_url, array(), PS_VERSION); wp_enqueue_style('post-snippets-newsletter'); // wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script('jquery-ui-dialog'); wp_enqueue_script('underscore'); wp_enqueue_script('post-snippets'); } /** * Add X-XSS-Protection header. * * Newer versions of Chrome does not allow form tags to be submitted in the * forms. This header disables that functionlity on the Post Snippets admin * screen only. */ public function addHeaderXss($current_screen) { if ($current_screen->base == 'settings_page_post-snippets/post-snippets') { header('X-XSS-Protection: 0'); } } /** * Quick link to the Post Snippets Settings page from the Plugins page. * * @param array $links Array of all plugin links * * @return array $links Array with all the plugin's action links */ public function actionLinks($links) { $links[] = '' . __('Settings', 'post-snippets') . ''; return $links; } public static function pspro_object_to_array($obj) { //only process if it's an object or array being passed to the function if (is_object($obj) || is_array($obj)) { $ret = (array) $obj; foreach ($ret as &$item) { //recursively process EACH element regardless of type $item = self::pspro_object_to_array($item); } return $ret; } //otherwise (i.e. for scalar values) return without modification else { return $obj; } } /** * Update User Option. * * Sets the per user option for the read-only overview page. * * @since Post Snippets 1.9.7 */ private function setUserOptions() { if ( isset($_POST['post_snippets_user_nonce']) && wp_verify_nonce($_POST['post_snippets_user_nonce'], 'post_snippets_user_options') ) { $id = get_current_user_id(); $render = isset($_POST['render']) ? true : false; update_user_meta($id, \PostSnippets::USER_META_KEY, $render); } } /** * Get User Option. * * Gets the per user option for the read-only overview page. * * @since Post Snippets 1.9.7 * @return boolean If overview should be rendered on output or not */ private function getUserOptions() { $id = get_current_user_id(); $options = get_user_meta($id, \PostSnippets::USER_META_KEY, true); return $options; } // ------------------------------------------------------------------------- // HTML generation for option pages // ------------------------------------------------------------------------- /** * Display Flashing Message. * * @param string $message Message to display to the user. */ private function message($message) { if ($message) { echo "

{$message}

"; } } public function newsPage() { $plugins = array( array( "name" => "myCred", "description" => "myCred makes it simple to create a loyalty program or gamify your website so that you can increase the average customer value with less marketing effort.", "image" => "myCred.png", "url" => "https://wordpress.org/plugins/mycred", ), array( "name" => "WP Contact Slider", "description" => "WP contact slider is simple contact slider to display contactform7, Gravity forms, Wp Forms, Caldera forms, Constant Contact Forms or display random text or HTML.", "image" => "ContactSlider.png", "url" => "https://wordpress.org/plugins/wp-contact-slider/", ), array( "name" => "Wholesale For WooCommerce", "description" => "Sign up wholesale customers and display wholesale prices based on multiple wholesale user roles on your existing WooCommerce store", "image" => "WholesaleForWoocommerce.png", "url" => "https://woocommerce.com/products/wholesale-for-woocommerce/", ), array( "name" => "WooCommerce Product Disclaimer", "description" => "Woocommerce extension where you can set some products to accept terms and conditions before adding product to cart. ", "image" => "ProductDisclaimer.png", "url" => "https://wordpress.org/plugins/woo-product-disclaimer/", ) ); include PS_PATH . "/views/admin_news.php"; } public function chatbot_ai() { if (isset($_POST['ps_openai_api_key'])) { check_admin_referer('ps_settings_group-options'); $api_key = sanitize_text_field($_POST['ps_openai_api_key']); update_option('ps_openai_api_key', $api_key); echo '

Settings saved successfully.

'; } $api_key = get_option('ps_openai_api_key'); ?>

AI Chatbot Mastery

Connect and configure your advanced AI assistant for intelligent code generation.

Authentication

Your keys are encrypted and stored securely.

Guide

  • 1
    Get Your Key

    Visit OpenAI Dashboard to create a new secret key.

  • 2
    Set Quotas

    Ensure your account has an active balance or credit to use the API.

  • 3
    Go Live

    Paste the key here and start chatting with the assistant on any snippet edit page.

Snippets

" class="page-title-action">
prepare_items(); $allSnippets->display(); ?>
'; // _e( 'Click \'Help\' in the top right for the documentation!', 'post-snippets' ); // echo '

'; ?>

'; // _e( 'Click \'Help\' in the top right for the documentation!', 'post-snippets' ); // echo '

'; $ie = new ImportExport(); // Create header and export html form printf("

%s

", __('Import/Export', 'post-snippets')); printf("

%s

", __('Export', 'post-snippets')); echo '
'; wp_nonce_field('postsnippets_export', 'postsnippets_export_nonce'); echo '

'; _e('Export your snippets for backup or to import them on another site.', 'post-snippets'); echo '

'; printf("", __('Export Snippets', 'post-snippets')); echo '
'; // Export logic, and import html form and logic $ie->exportAllSnippets(); echo $ie->importSnippets(); } /** * Tab for Pro features * * @since Post Snippets 2.5.4 */ private function tabFeatures() { $features = new Features(); echo $features->showFeatures(); } /** * Creates a read-only overview page. * * For users with edit_posts capability but without manage_options * capability. * * @since Post Snippets 1.9.7 */ public function overviewPage() { // Header echo '
'; echo '

Post Snippets

'; echo '

'; _e('This is an overview of all snippets defined for this site. These snippets are inserted into posts from the post editor using the Post Snippets button. You can choose to see the snippets here as-is or as they are actually rendered on the website. Enabling rendered snippets for this overview might look strange if the snippet have dependencies on variables, CSS or other parameters only available on the frontend. If that is the case it is recommended to keep this option disabled.', 'post-snippets'); echo '

'; // Form $this->setUserOptions(); $render = $this->getUserOptions(); echo '
'; wp_nonce_field('post_snippets_user_options', 'post_snippets_user_nonce'); $this->checkbox(__('Display rendered snippets', 'post-snippets'), 'render', $render); $this->submit('update-post-snippets-user', __('Update', 'post-snippets')); echo '
'; // Snippet List $snippets = get_option(\PostSnippets::OPTION_KEY); if (!empty($snippets)) { foreach ($snippets as $key => $snippet) { echo "
"; echo "

{$snippet['title']}"; if ($snippet['description']) { echo " {$snippet['description']}"; } echo "

"; if ($snippet['vars']) { printf("%s: {$snippet['vars']}
", __('Variables', 'post-snippets')); } // echo "Variables: {$snippet['vars']}
"; $options = array(); if ($snippet['shortcode']) { array_push($options, 'Shortcode'); } if ($snippet['php']) { array_push($options, 'PHP'); } if ($snippet['wptexturize']) { array_push($options, 'wptexturize'); } if ($options) { printf("%s: %s
", __('Options', 'post-snippets'), implode(', ', $options)); } printf("
%s:
", __('Snippet', 'post-snippets')); if ($render) { echo do_shortcode($snippet['snippet']); } else { echo ""; echo nl2br(htmlspecialchars($snippet['snippet'], ENT_NOQUOTES)); echo ""; } } } // Close echo '
'; } // ------------------------------------------------------------------------- // Register and callbacks for the options tab // ------------------------------------------------------------------------- /** * Register settings for the options tab. * * @return void */ protected function registerSettings() { $this->settings = get_option(\PostSnippets::SETTINGS); register_setting( \PostSnippets::SETTINGS, \PostSnippets::SETTINGS ); add_settings_section( 'general_section', __('General', 'post-snippets'), null, 'post-snippets' ); add_settings_field( 'exclude_from_custom_editors', __('Exclude from Custom Editors', 'post-snippets'), array($this, 'cbExcludeFromCustomEditors'), 'post-snippets', 'general_section', array( 'id' => 'exclude_from_custom_editors', 'label_for' => 'exclude_from_custom_editors', 'description' => __('Checking this only includes Post Snippets on standard WordPress post editing screens.', 'post-snippets') ) ); add_settings_field( 'complete_uninstall', __('Complete Uninstall', 'post-snippets'), array($this, 'cbCompleteUninstall'), 'post-snippets', 'general_section', array( 'id' => 'complete_uninstall', 'label_for' => 'complete_uninstall', 'description' => __('When the plugin is deleted, also delete all snippets and plugin settings.', 'post-snippets') ) ); add_settings_section( 'duplicate_section', __('Duplicate Snippets', 'post-snippets'), null, 'post-snippets' ); add_settings_field( 'allow_duplicate', __('Allow Duplicate', 'post-snippets'), array($this, 'cbAllowDuplicate'), 'post-snippets', 'duplicate_section', array( 'id' => 'allow_duplicate', 'label_for' => 'allow_duplicate', 'description' => __('Allow duplicate snippets: import all snippets from the file regardless and leave all existing snippets unchanged.', 'post-snippets') ) ); add_settings_field( 'replace_duplicate', __('Replace Duplicate', 'post-snippets'), array($this, 'cbReplaceDuplicate'), 'post-snippets', 'duplicate_section', array( 'id' => 'replace_duplicate', 'label_for' => 'replace_duplicate', 'description' => __('Replace any existing snippets with a newly imported snippet of the same name.', 'post-snippets') ) ); add_settings_field( 'skip_duplicate', __('Do not Import Duplicate', 'post-snippets'), array($this, 'cbSkipDuplicate'), 'post-snippets', 'duplicate_section', array( 'id' => 'skip_duplicate', 'label_for' => 'skip_duplicate', 'description' => __('Do not import any duplicate snippets; leave all existing snippets unchanged.', 'post-snippets') ) ); } /** * Callback for HTML generator for exlusion of custom editors. * * @param array $args * * @return void */ public function cbExcludeFromCustomEditors($args) { $checked = isset($this->settings[$args['id']]) ? $this->settings[$args['id']] : false; echo ""; echo "{$args['description']}"; } /** * Callback for Complete Uninstallation Option. * * @param array $args * * @return void */ public function cbCompleteUninstall($args) { $checked = isset($this->settings[$args['id']]) ? $this->settings[$args['id']] : false; echo ""; echo "{$args['description']}"; } /** * Callback for Allow Duplicate selection. * * @param array $args * * @return void */ public function cbAllowDuplicate($args) { $checked = $this->pspro_isDuplicateOptionChecked($args['id']); echo ""; echo "{$args['description']}"; } /** * Callback for Complete Uninstallation Option. * * @param array $args * * @return void */ public function cbReplaceDuplicate($args) { $checked = $this->pspro_isDuplicateOptionChecked($args['id']); echo ""; echo "{$args['description']}"; } /** * Callback for Complete Uninstallation Option. * * @param array $args * * @return void */ public function cbSkipDuplicate($args) { $checked = $this->pspro_isDuplicateOptionChecked($args['id']); echo ""; echo "{$args['description']}"; } public function pspro_isDuplicateOptionChecked($option = '') { if (empty($option)) { return false; } if (isset($this->settings['duplicate_option']) && $this->settings['duplicate_option'] == $option) { return true; } return false; } // ------------------------------------------------------------------------- // HTML and Form element methods for Snippets form // ------------------------------------------------------------------------- /** * Checkbox. * * Renders the HTML for an input checkbox. * * @param string $label The label rendered to screen * @param string $name The unique name and id to identify the input * @param boolean $checked If the input is checked or not * * @return void */ public static function checkbox($label, $name, $checked) { echo "
"; } /** * Submit. * * Renders the HTML for a submit button. * * @since Post Snippets 1.9.7 * * @param string $name The name that identifies the button on submit * @param string $label The label rendered on the button * @param string $class Optional. Button class. Default: button-primary * @param boolean $wrap Optional. Wrap in a submit div. Default: true * * @return void */ public static function submit($name, $label, $class = 'button-primary', $wrap = true) { $btn = sprintf('   ', $name, $label, $class); if ($wrap) { $btn = "
{$btn}
"; } echo $btn; } /** * * Show newsletter opt-in, only in Post Snippets. * Not on Pro features tab/page. * Not when user selected to Hide opt-in. * * @since 2.5.4 */ public function admin_notice_newsletter() { // Hide newsletter opt-in if option is true if (get_option('ps_hide_admin_notice_newsletter') == true) { return; } // Set option if "hide" button click detected (custom querystring value set to 1). if (!empty($_REQUEST['ps-dismiss-newsletter-nag'])) { update_option('ps_hide_admin_notice_newsletter', true); return; } // Show newsletter notice. if (get_current_screen()->id == 'settings_page_post-snippets/post-snippets') { $active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'snippets'; if ($active_tab != 'features') { include_once(PS_PATH . '/views/admin_notice_newsletter.php'); } } } /** * * Show 'Get started' admin notice', everywhere. * Not when user already clicked or dismissed. * * @since 2.5.4 */ public function admin_notice_get_started() { // Hide newsletter opt-in if option is true if (get_option('ps_hide_admin_notice_get_started') == true) { return; } // Set option if "hide" button click detected (custom query string value set to 1). if (!empty($_REQUEST['ps-dismiss-get-started-nag'])) { update_option('ps_hide_admin_notice_get_started', true); return; } // Show newsletter notice. if (strpos(get_current_screen()->id, '/post-snippets') == false) { $active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'snippets'; if ($active_tab != 'features') { include_once(PS_PATH . '/views/admin_notice_get_started.php'); } } } public function get_allowed_capability() { $capability = 'manage_options'; if (defined('POST_SNIPPETS_ALLOW_EDIT_POSTS') and current_user_can('edit_posts')) { $capability = 'edit_posts'; } return $capability; } }