'ar-SA', 'Chinese, Mandarin (cmn-CN)' => 'cmn-CN', 'Croatian' => 'hr', 'Czech' => 'cs', 'Danish' => 'da-DK', 'Dutch' => 'nl-NL', 'English' => 'en-us', 'Estonian' => 'et', 'Finnish' => 'fi', 'French' => 'fr', 'German' => 'de', 'Greek' => 'el', 'Hebrew' => 'he-IL', 'Hindi' => 'hi-IN', 'Hungarian' => 'hu', 'Icelandic' => 'is-IS', 'Indonesian' => 'id-ID', 'Italian' => 'it', 'Japanese' => 'ja-JP', 'Korean' => 'ko-KR', 'Malay' => 'ms-MY', 'Norwegian' => 'nb-NO', 'Polish' => 'pl-PL', 'Portuguese' => 'pt', 'Portuguese (Brazil)' => 'pt-BR', 'Romanian' => 'ro-RO', 'Russian' => 'ru-RU', 'Slovenian' => 'sl', 'Spanish' => 'es', 'Swahili' => 'sw', 'Swedish' => 'sv-SE', 'Turkish' => 'tr-TR', 'Vietnamese' => 'vi' ); static $plugin_allowed_html = array( 'a' => array( 'href' => true, 'rel' => true, 'name' => true, 'target' => true, ), 'b' => array(), 'br' => array(), 'button' => array( 'class' => true, 'disabled' => true, 'name' => true, 'type' => true, 'value' => true, ), 'div' => array( 'class' => true, 'data-*' => true, 'style' => true ), 'em' => array(), 'i' => array(), 'input' => array( 'id' => true, 'name' => true, 'placeholder' => true, 'type' => true, 'value' => true, ), 'label' => array( 'for' => true, ), 'option' => array( 'value' => true, 'selected' => true ), 'select' => array( 'name' => true, 'class' => true ), 'textarea' => array( 'id' => true, 'name' => true, 'placeholder' => true ), ); // in init below after translations loaded static $supported_lengths = array(); static $supported_voices = array(); static $debugLogDir = null; static $debugLogUrl = null; static $debugLog = null; static function this_plugin_init() { global $wpdb; register_activation_hook(__FILE__, array(__CLASS__, 'activation_hook')); add_action('admin_init', array(__CLASS__, 'on_post_forms')); add_action('admin_menu', array(__CLASS__, 'admin_menu_action')); add_action('admin_footer', array(__CLASS__, 'admin_footer_action')); add_filter('plugin_action_links_' . plugin_basename(__FILE__), array(__CLASS__, 'plugin_action_links_filter')); add_action('init', array(__CLASS__, 'init_action')); //add_action('admin_enqueue_scripts', array(__CLASS__, 'admin_enqueue_scripts_action'), 10, 1); add_action('wp_ajax_aiwrc_ajax_submission', array(__CLASS__, 'aiwrc_ajax_submission_action')); add_action('enqueue_block_editor_assets', array(__CLASS__, 'example_enqueue_editor_assets_action')); // these will be used only by a developer by setting self::$testing = true some lines above $upload_dir = wp_upload_dir(); self::$debugLogDir = trailingslashit($upload_dir['basedir']); self::$debugLog = self::$debugLogDir . 'ai-writer-contents.txt'; self::$debugLogUrl = trailingslashit($upload_dir['baseurl']) . 'ai-writer-contents.txt'; } static function init_action() { //global $pagenow; //die($pagenow); load_plugin_textdomain( 'aiwrc', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); self::$supported_lengths = array( __('500 words', 'aiwrc') => '500', __('1000 words', 'aiwrc') => '1000', __('2000 words', 'aiwrc') => '2000' ); self::$supported_voices = array( __('Neutral', 'aiwrc') => 'neutral', __('Bold', 'aiwrc') => 'bold', __('Casual', 'aiwrc') => 'casual', __('Dramatic', 'aiwrc') => 'dramatic', __('Excited', 'aiwrc') => 'excited', __('Formal', 'aiwrc') => 'formal', __('Funny', 'aiwrc') => 'funny', __('Informal', 'aiwrc') => 'informal', __('Luxury', 'aiwrc') => 'luxury', __('Motivational', 'aiwrc') => 'motivational', __('Professional', 'aiwrc') => 'professional', __('Sarcastic', 'aiwrc') => 'sarcastic', __('Secretive', 'aiwrc') => 'secretive', __('Witty', 'aiwrc') => 'witty', ); } /** * this functions does nothing when self::$testing = false (always is in production) * a dev would set the var to true to enable the logging * @return void */ static function log() { if (!self::$testing) { return; } $args = func_get_args(); foreach ($args as $i => $arg) { if ('DELETE' === $arg) { wp_delete_file(self::$debugLog); continue; } // "pretty" print if array or object if (is_array($arg) || is_object($arg)) { $arg = print_r($arg, true); $arg = preg_replace("~\r?\n~", PHP_EOL, $arg); } elseif (is_bool($arg)) { $arg = $arg ? 'TRUE' : 'FALSE'; } elseif (is_null($arg)) { $arg = 'NULL'; } elseif (is_string($arg)) { if ('::' == substr($arg, 0, 2)) { self::log('--------------------------------------------------------------------------------'); } } // prepend a line of separation if first argument begins with :: //!devtest file_put_contents(self::$debugLog, $arg . PHP_EOL, FILE_APPEND); } } static function activation_hook() { } static function options() { $opts = get_option(self::$options_name); if (!is_array($opts)) { $opts = array(); } $opts = array_merge(array( 'user_email' => '', 'user_id' => '', 'token' => '', ), $opts); return $opts; } static function admin_menu_action() { $parent_slug = self::$slug . '-page-settings'; add_menu_page(self::$name, self::$name, 'manage_options', $parent_slug, array(__CLASS__, 'menu_settings_callback')); $aiwriter_setup = add_submenu_page($parent_slug, __('Setup', 'aiwrc'), __('Setup', 'aiwrc'), 'manage_options', $parent_slug, array(__CLASS__, 'menu_settings_callback')); $aiwriter_page = add_submenu_page($parent_slug, __('Generate a post', 'aiwrc'), __('Generate a post', 'aiwrc'), 'manage_options', self::$slug . '-page-writer', array(__CLASS__, 'menu_writer_callback')); // selectively load js only for the above page add_action('load-' . $aiwriter_setup, array(__CLASS__, 'load_assets_selectively')); add_action('load-' . $aiwriter_page, array(__CLASS__, 'load_assets_selectively')); add_action('load-post.php', array(__CLASS__, 'load_assets_selectively')); add_action('load-post-new.php', array(__CLASS__, 'load_assets_selectively')); } static function load_assets_selectively() { self::$assets_context = true; add_action('admin_enqueue_scripts', function() { $ver = (string)time(); // self::$version; wp_enqueue_style(self::$slug . '-style', plugins_url('assets/css/style.css', __FILE__), array(), $ver); // https://developer.wordpress.org/reference/functions/wp_add_inline_script/ ?? wp_register_script(self::$slug . '-main', plugins_url('assets/js/main.js', __FILE__), array('jquery', 'jquery-ui-sortable'), $ver, false); // 'jquery' dep removed due to theme deregistering jquery wp_enqueue_script(self::$slug . '-main'); wp_localize_script(self::$slug . '-main', 'aiwrc_globals', array( 'ajaxurl' => admin_url('admin-ajax.php') )); }, 10); } static function example_enqueue_editor_assets_action() { $ver = (string)time(); wp_enqueue_script('aiwrc-editor-scripts', plugins_url('build/index.js', __FILE__), array('jquery'), $ver); } static function admin_footer_action() { if (!self::$assets_context) { return; } $opts = self::options(); $contents_logged_in = !empty($opts['token']); if ($contents_logged_in) { $html_ksesd = wp_kses( self::get_step1_html('gutenberg'), self::$plugin_allowed_html ); } ?>
%2$s', admin_url('admin.php?page=' . self::$slug . '-page-settings'), esc_html__('Setup', 'aiwrc')); return $links; } static function messages_echo() { // notices if (!empty(self::$notices)) { foreach (self::$notices as $notice) { ?>

»

Token:

Hello!

We're excited that you're interested in enhancing your creative process with the Contents.ai plugin, designed to deliver SEO-optimized content. Before using the plugin, you need to create an account on Contents.ai. For full access to all the plugin's capabilities, consider opting for the Starter or Pro plan at https://www.contents.ai/pricing/. After selecting the plan, simply input your access key into the plugin, and it's all set for use.

Understanding how the plugin works: start by selecting a title, deciding on the length of the article, either in the standalone plugin or inside Gutenberg’s editor, and setting your preferred tone. In just minutes, you'll receive content that's not only well-written but also crafted with care. The plugin's ability to generate flexible outlines and its use of unique native-language data sets make it a groundbreaking tool for efficient and effective blogging.

 

»

'language', 'options' => self::$supported_languages, 'selected' => 'en-us')), self::$plugin_allowed_html ); ?>
'length', 'options' => self::$supported_lengths, 'selected' => '1000')), self::$plugin_allowed_html ); ?>
'tov', 'options' => self::$supported_voices, 'selected' => 'neutral')), self::$plugin_allowed_html ); ?>
base !== $hook_suffix) { // return; // } // $ver = self::$version; // // https://developer.wordpress.org/reference/functions/wp_add_inline_script/ ?? // wp_register_script(self::$slug . '-main', plugins_url('assets/js/main.js', __FILE__), array(), $ver, false); // 'jquery' dep removed due to theme deregistering jquery // wp_enqueue_script(self::$slug . '-main'); // wp_localize_script(self::$slug . '-main', 'sscnts_globals', array( // 'ajaxurl' => admin_url('admin-ajax.php'), // )); // } /** * all ajax calls when hitting buttons etc * * @return void */ static function aiwrc_ajax_submission_action() { //!devtest self::log($_POST); $ret = array(); // the object to return to the client at the end as json $opts = self::options(); // the plugin options as saved in the database $_step = isset($_POST['step']) ? intval($_POST['step']) : -1; // the step in the generation wizard (1 or 2) $_title = isset($_POST['title']) ? sanitize_text_field($_POST['title']) : ''; switch($_step) { case 1: $_instructions = ''; if (isset($_POST['instructions'])) { $_instructions = sanitize_textarea_field($_POST['instructions']); } $_language = 'en-us'; if (isset($_POST['language'])) { $tmp = sanitize_text_field($_POST['language']); if (in_array($tmp, self::$supported_languages)) { $_language = $tmp; } } $_length = '500'; if (isset($_POST['length'])) { $tmp = sanitize_text_field($_POST['length']); if (in_array($tmp, self::$supported_lengths)) { $_length = $tmp; } } $_tov = 'neutral'; if (isset($_POST['tov'])) { $tmp = sanitize_text_field($_POST['tov']); if (in_array($tmp, self::$supported_voices)) { $_tov = $tmp; } } $resp = aiwrc_ContentsComAPI::api_article_generator__titles( $opts['token'], $opts['user_id'], $_title, $_instructions, $_language, $_length, $_tov ); $ret = $resp; break; case 2: $_paragraphs = isset($_POST['paragraphs']) ? sanitize_text_field($_POST['paragraphs']) : ''; $_order_detail_id = isset($_POST['order_detail_id']) ? intval($_POST['order_detail_id']) : 0; if (0 === $_order_detail_id) { $ret = array(false, __('Invalid order detail id', 'aiwrc')); break; } $_destination = (isset($_POST['destination']) && in_array($_POST['destination'], array('new_post', 'gutenberg'))) ? sanitize_text_field($_POST['destination']) : ''; if ('' === $_destination) { $ret = array(false, __('Invalid destination', 'aiwrc')); break; } $resp = aiwrc_ContentsComAPI::api_article_generator__paragraphs( $opts['token'], $opts['user_id'], $_paragraphs, $_order_detail_id ); if ($resp[0]) { /* $resp[1]: Array ( [status] => success [message] => Sucess! [order_id] => 286260 [order_detail_id] => 301314 [result] => Italian food is more than just pizza and pasta. ... ) */ self::log('api2 response', $resp); // destination 'new_post' is when we use the plugin embedded in the dedicated admin page if ('new_post' === $_destination) { $postID = wp_insert_post(array( 'post_title' => $_title, 'post_content' => $resp[1]['result'], 'post_status' => 'draft' )); if (is_wp_error($postID)) { $ret = array(false, 'WP err: ' . $postID->get_error_message()); break; } else { $ret = array(true, array( 'post_id' => $postID, 'edit_post_link' => get_edit_post_link($postID, 'display') )); } } // destination 'gutenberg' is when we use the plugin in the gutenberg editor if ('gutenberg' === $_destination) { // transform provided html into an array of p's and h2's $html = $resp[1]['result']; $lines = explode("\n", $html); $lines = array_map('trim', $lines); $lines = array_filter($lines); // at this point we should have an array of ['blabla', '

qweqwe

', 'blabla2', '

qweqwe2

', ...] $data = array(); foreach ($lines as $line) { // heading (h2, h3, ...) if (preg_match('~^~i', $line, $regs)) { $data[] = array( 'type' => 'heading', 'text' => wp_strip_all_tags($line), 'level' => (int)$regs[1] ); } // paragraph p else { $data[] = array( 'type' => 'paragraph', 'text' => $line ); } } $ret = array(true, $data); } } else { $ret = $resp; // [false, "message"] } break; default: $ret = array(false, __('Invalid step', 'aiwrc')); } // switch echo wp_json_encode($ret); wp_die(); } } aiwrc_AiWriterContentsCom::this_plugin_init();