false, 'error' => 'Usuario no autorizado.')); return; } $args = array( 'post_type' => 'post', 'post_status' => 'any', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => '_autowriter_post', 'value' => '1', ) ) ); $posts = get_posts($args); $all_posts = array(); foreach ($posts as $post){ $each_post = new stdClass(); $each_post->id = $post->ID; $each_post->status = $post->post_status; $each_post->content = $post->post_content; $each_post->title = $post->post_title; $each_post->date = $post->post_date; $each_post->url = $post->guid; $all_posts[]=$each_post; } ai_post_generator_return_json(array('exito' => true, 'array' => $all_posts)); } add_action('wp_ajax_ai_post_generator_get_Posts', 'ai_post_generator_get_Posts'); } if (!function_exists('ai_post_generator_data_Publish')) { function ai_post_generator_data_Publish() { ai_post_generator_verify_nonce(); if (!current_user_can('publish_posts')) { ai_post_generator_return_json(array('exito' => false, 'error' => 'Usuario no autorizado.')); return; } if (!isset($_POST['text']) || !isset($_POST['title'])) { ai_post_generator_return_json(array('exito' => false, 'error' => 'Mensaje vacío')); } if ($_POST['type'] == "publish") { $type = "publish"; } elseif ($_POST['type'] == "draft") { $type = "draft"; } else { $type = "draft"; } $type = sanitize_text_field($type); $title = sanitize_text_field(wp_strip_all_tags($_POST['title'])); $url = trim(preg_replace('/[^a-z0-9-]+/', '-', ai_post_generator_stripAccents(strtolower($title))), '-'); // time config $minutes_to_add = 0; $DateTime = new DateTime(null, new DateTimeZone('Europe/Madrid')); $DateTime->add(new DateInterval('PT' . $minutes_to_add . 'M')); $now = $DateTime->format('Y-m-d H:i:s'); $my_post = array( 'post_title' => $title, 'post_url' => $url, 'post_content' => wp_kses_post('[ai_post_generator_toc]' . $_POST['text']), 'post_status' => $type, 'post_author' => get_current_user_id(), 'post_date' => $now, ); $id = wp_insert_post($my_post); add_post_meta($id, '_autowriter_post', '1', true); if ($_POST['im']) { $image = sanitize_text_field(wp_strip_all_tags($_POST['im'])); $image_id = ai_post_generator_download_img($image, "Image " . $title, $url . "-image"); if ($image_id) { add_post_meta($id, '_thumbnail_id', $image_id, true); add_post_meta($image_id, '_wp_attachment_image_alt', $title, true); } } $post = get_post($id); ai_post_generator_return_json(array('exito' => true, 'content' => $post->post_content, 'url' => $post->guid, 'id' => $id)); } add_action('wp_ajax_ai_post_generator_data_Publish', 'ai_post_generator_data_Publish'); } if (!function_exists('ai_post_generator_data_Preview')) { function ai_post_generator_data_Preview() { ai_post_generator_verify_nonce(); if (!isset($_POST['text']) || !isset($_POST['id'])) { ai_post_generator_return_json(array('exito' => false, 'error' => 'Mensaje vacío')); } // Después (Validar y Sanitizar): $id = ( isset( $_POST['id'] ) && is_numeric( $_POST['id'] ) ) ? intval( $_POST['id'] ) : ''; $data = array('ID' => $id, 'post_content' => wp_kses_post($_POST['text'])); wp_update_post($data); ai_post_generator_return_json(array('exito' => true)); } add_action('wp_ajax_ai_post_generator_data_Preview', 'ai_post_generator_data_Preview'); } if (!function_exists('ai_post_generator_saveas_Publish')) { function ai_post_generator_saveas_Publish() { ai_post_generator_verify_nonce(); if (!isset($_POST['id'])) { ai_post_generator_return_json(array('exito' => false, 'error' => 'Mensaje vacío')); } // time config // time config $minutes_to_add = 0; $DateTime = new DateTime(null, new DateTimeZone('Europe/Madrid')); $DateTime->add(new DateInterval('PT' . $minutes_to_add . 'M')); $now = $DateTime->format('Y-m-d H:i:s'); // Después (Validar y Sanitizar): $id = ( isset( $_POST['id'] ) && is_numeric( $_POST['id'] ) ) ? intval( $_POST['id'] ) : ''; $data = array('ID' => $id, 'post_status' => 'publish', 'post_content' => wp_kses_post($_POST['text']) ,'post_date' => $now); wp_update_post($data); ai_post_generator_return_json(array('exito' => true, 'id' => $id)); } add_action('wp_ajax_ai_post_generator_saveas_Publish', 'ai_post_generator_saveas_Publish'); } if (!function_exists('ai_post_generator_delete_Post')) { function ai_post_generator_delete_Post() { ai_post_generator_verify_nonce(); if (!isset($_POST['id'])) { ai_post_generator_return_json(array('exito' => false, 'error' => 'Mensaje vacío')); } // Después (Validar y Sanitizar): $id = ( isset( $_POST['id'] ) && is_numeric( $_POST['id'] ) ) ? intval( $_POST['id'] ) : ''; wp_delete_post($_POST['id']); ai_post_generator_return_json(array('exito' => true, 'id' => $id)); } add_action('wp_ajax_ai_post_generator_delete_Post', 'ai_post_generator_delete_Post'); } if (!function_exists('ai_post_generator_enqueue_css')) { function ai_post_generator_enqueue_css() { $my_css_ver = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/my-styles-toc.css')); $my_js_ver = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/table-of-content.js')); wp_enqueue_style( 'my-styles-toc', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/my-styles-toc.css", null, $my_css_ver ); // Enqueue the script wp_enqueue_script( 'my-functions1', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/table-of-content.js", null, $my_js_ver, true ); } } if (!function_exists('ai_post_generator_body_enqueue_js')) { function ai_post_generator_body_enqueue_js() { // Create version codes $my_css_ver = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/my-styles.css')); $my_css_bootstrap = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/bootstrap.min.css')); $my_js_ver = date('ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/main.js')); $my_js_header = date('ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/header.js')); $my_js_bootstrap = date('ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/bootstrap.bundle.min.js')); $my_js_circle = date('ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/circle-progress.min.js')); // Enqueue the stylesheet wp_enqueue_style( 'my-styles', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/my-styles.css", null, $my_css_ver ); wp_enqueue_style( 'my-styles2', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/bootstrap.min.css", null, $my_css_bootstrap ); wp_enqueue_style( 'my-styles3', "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css", null, null ); wp_enqueue_script( 'my-functions2', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/bootstrap.bundle.min.js", null, $my_js_bootstrap, true ); wp_enqueue_script( 'my-functions-header', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/header.js", null, $my_js_header, true ); wp_enqueue_script( 'my-functions3', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/circle-progress.min.js", null, $my_js_circle, true ); wp_enqueue_script( 'main-functions', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/main.js", null, $my_js_ver, true ); // Pasar parámetros a JavaScript wp_localize_script('main-functions', 'aiPostGenerator', array( 'ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('ai_post_generator_nonce') )); //TABLE BOOTSTRAP wp_enqueue_style('ai-table-style-1', "https://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css", null, null); wp_enqueue_script('ai-table-script-1', "https://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js", null, null, true); } } if (!function_exists('ai_post_generator_tokens_enqueue_js')) { function ai_post_generator_tokens_enqueue_js() { // Create version codes $my_css_ver = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/my-styles.css')); $my_css_checkout = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/checkout.css')); $my_js_header = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/header.js')); $my_js_checkout = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/checkout.js')); $my_js_checkout2 = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/single-posts-checkout.js')); $my_css_bootstrap = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/bootstrap.min.css')); $my_js_bootstrap = date('ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/bootstrap.bundle.min.js')); // Enqueue the stylesheet wp_enqueue_style( 'my-styles', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/my-styles.css", null, $my_css_ver ); wp_enqueue_style( 'my-styles2', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/bootstrap.min.css", null, $my_css_bootstrap ); wp_enqueue_style( 'my-styles-checkout', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/checkout.css", null, $my_css_checkout ); wp_enqueue_style( 'my-styles3', "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css", null, null ); wp_enqueue_script( 'my-functions2', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/bootstrap.bundle.min.js", null, $my_js_bootstrap, true ); wp_enqueue_script( 'my-functions-header', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/header.js", null, $my_js_header, true ); wp_enqueue_script( 'my-functions-checkout', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/checkout.js", null, $my_js_checkout, true ); // Enqueue the script wp_enqueue_script( 'my-strype', "https://js.stripe.com/v3/", null, null, true ); wp_enqueue_script( 'my-functions-checkout2', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/single-posts-checkout.js", null, $my_js_checkout2, true ); } } if (!function_exists('ai_post_generator_academy_enqueue_js')) { function ai_post_generator_academy_enqueue_js() { // Create version codes $my_css_ver = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/my-styles.css')); $my_css_checkout = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/checkout.css')); $my_js_header = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/header.js')); $my_css_bootstrap = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/bootstrap.min.css')); $my_js_bootstrap = date('ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/bootstrap.bundle.min.js')); // Enqueue the stylesheet wp_enqueue_style( 'my-styles', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/my-styles.css", null, $my_css_ver ); wp_enqueue_style( 'my-styles1', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/checkout.css", null, $my_css_checkout ); wp_enqueue_style( 'my-styles2', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/bootstrap.min.css", null, $my_css_bootstrap ); wp_enqueue_style( 'my-styles3', "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css", null, null ); wp_enqueue_script( 'my-functions2', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/bootstrap.bundle.min.js", null, $my_js_bootstrap, true ); wp_enqueue_script( 'my-functions-header', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/header.js", null, $my_js_header, true ); } } if (!function_exists('ai_post_generator_training_enqueue_js')) { function ai_post_generator_training_enqueue_js() { // Create version codes $my_css_ver = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/my-styles.css')); $my_css_bootstrap = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/bootstrap.min.css')); $my_js_ver = date('ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/training-model.js')); $my_js_header = date('ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/header.js')); $my_js_bootstrap = date('ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/bootstrap.bundle.min.js')); // Enqueue the stylesheet wp_enqueue_style( 'my-styles', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/my-styles.css", null, $my_css_ver ); wp_enqueue_style( 'my-styles2', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/bootstrap.min.css", null, $my_css_bootstrap ); wp_enqueue_style( 'my-styles3', "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css", null, null ); wp_enqueue_script( 'my-functions2', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/bootstrap.bundle.min.js", null, $my_js_bootstrap, true ); wp_enqueue_script( 'my-functions-header', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/header.js", null, $my_js_header, true ); wp_enqueue_script( 'my-functions4', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/training-model.js", null, $my_js_ver, true ); //TABLE BOOTSTRAP wp_enqueue_style('ai-table-style-1', "https://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css", null, null); wp_enqueue_script('ai-table-script-1', "https://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js", null, null, true); } } if (!function_exists('ai_post_generator_settings_enqueue_js')) { function ai_post_generator_settings_enqueue_js() { // Create version codes $my_css_ver = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/my-styles.css')); $my_css_bootstrap = date('Ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'css/bootstrap.min.css')); $my_js_ver = date('ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/settings.js')); $my_js_header = date('ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/header.js')); $my_js_bootstrap = date('ymd-Gis', filemtime(AI_POST_GENERATOR_PLUGIN_DIR . 'js/bootstrap.bundle.min.js')); // Enqueue the stylesheet wp_enqueue_style( 'my-styles', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/my-styles.css", null, $my_css_ver ); wp_enqueue_style( 'my-styles2', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "css/bootstrap.min.css", null, $my_css_bootstrap ); wp_enqueue_style( 'my-styles3', "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css", null, null ); wp_enqueue_script( 'my-functions2', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/bootstrap.bundle.min.js", null, $my_js_bootstrap, true ); wp_enqueue_script( 'my-functions-header', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/header.js", null, $my_js_header, true ); wp_enqueue_script( 'my-functions4', trailingslashit(AI_POST_GENERATOR_PLUGIN_URL) . "js/settings.js", null, $my_js_ver, true ); //TABLE BOOTSTRAP wp_enqueue_style('ai-table-style-1', "https://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css", null, null); wp_enqueue_script('ai-table-script-1', "https://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js", null, null, true); } }