Changeset 3086265
- Timestamp:
- 05/14/2024 06:26:13 AM (22 months ago)
- Location:
- ai-title-generator/trunk
- Files:
-
- 3 added
- 6 edited
-
ai-title-generator.php (modified) (5 diffs)
-
assets/css/aitgen-admin-style.css (modified) (1 diff)
-
assets/js/aitgen-admin-script.js (modified) (3 diffs)
-
assets/js/aitgen-editor-script.js (added)
-
classes/AITGEN-short-desc-handling.php (added)
-
includes/assets.php (modified) (2 diffs)
-
languages (added)
-
readme.txt (modified) (6 diffs)
-
views/admin/aitgen-conent.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ai-title-generator/trunk/ai-title-generator.php
r3057551 r3086265 3 3 * Plugin Name: AI Title Generator 4 4 * Description: Generate / Regenerate your Title using AI on WordPress website. 5 * Version: 1.0. 05 * Version: 1.0.1 6 6 * Author: Spark Coder 7 7 * Author URI: https://sparkcoder.com … … 49 49 require( AITGEN_DIR_PATH.'classes/AITGEN-ajax-handling.php' ); 50 50 require( AITGEN_DIR_PATH.'classes/AITGEN-title-handling.php' ); 51 require( AITGEN_DIR_PATH.'classes/AITGEN-short-desc-handling.php' ); 51 52 require( AITGEN_DIR_PATH.'classes/AITGEN_dbManagement.php' ); 52 53 … … 55 56 // Assets load 56 57 add_action( 'admin_enqueue_scripts', 'aitgen_admin_assets'); 58 // add_action( 'enqueue_block_editor_assets', 'aitgen_editor_assets' ); 57 59 // Load Content 58 60 add_action('admin_footer', 'aitgen_title_generator_box_admin'); 61 59 62 add_filter('post_row_actions', 'aitgen_admin_postProduct_custom_button', 10, 2); 60 63 // Hook into the page_row_actions filter to add the custom button for pages … … 72 75 add_action('wp_ajax_update_regenerate_title_action', array( new AITGEN_Title_Handle(), 'aitgen_update_product_title_callback') ); 73 76 74 add_action('wp_ajax_regenerate_postTitle_action', array( new AITGEN_Title_Handle(), 'aitgen_postReGenTitle_callback') ); 77 // Short Description 78 add_action('wp_ajax_aitgen_shortDsc_action', array( new AITGEN_ShortDesc_Handle(), 'aitgen_shortDesc_action_callback') ); 79 add_action('wp_ajax_reGenShortDsc_action', array( new AITGEN_ShortDesc_Handle(), 'aitgen_reGenShortDesc_callback') ); 80 add_action('wp_ajax_updateShortDsc_action', array( new AITGEN_ShortDesc_Handle(), 'aitgen_update_shortDesc_callback') ); 75 81 } 76 82 } … … 131 137 132 138 } 139 140 141 function aitgen_generateShortDescription( $description = null, $keywords = null ) { 142 global $client; 143 // Construct the prompt based on the provided parameters 144 $prompt = 'Generate professional and SEO friendly short description'; 145 146 if (!$description ) { 147 return null; 148 } 149 150 if ($description) { 151 $prompt .= " based on {$description}"; 152 } 153 154 // Make the API call 155 $result = $client->chat()->create([ 156 'model' => 'gpt-3.5-turbo', 157 'messages' => [ 158 ['role' => 'user', 'content' => $prompt], 159 ], 160 'max_tokens' => 4000, 161 'temperature' => 0.7 162 ]); 163 164 // Extract and return the generated product title from the API response 165 return $result['choices'][0]['message']['content']; 166 } 167 168 169 133 170 // It's initial release version. 171 172 173 174 /** 175 * Example of how you can add your own custom media 176 * button in WordPress editor 177 */ 178 179 function aitgen_short_description_button() { 180 global $post; 181 printf( 182 '<a href="#" class="button aitgen_shortDescription" data-id="%s">' . 183 '<span class="wp-media-buttons-icon dashicons dashicons-image-rotate"></span> %s' . 184 '</a>', 185 esc_attr( $post->ID ), 186 __( 'Generate Short Description by AI', 'textdomain' ) 187 ); 188 } 189 add_action( 'media_buttons', 'aitgen_short_description_button' ); 190 191 192 193 194 -
ai-title-generator/trunk/assets/css/aitgen-admin-style.css
r3057551 r3086265 158 158 } 159 159 160 /* Generated Short Description */ 161 .aitgen_short_description_wrapper{ 162 display: flex; 163 justify-content: center; 164 align-items: center; 165 position: relative; 166 167 } 168 .aitgen_short_description_wrapper .lds-spinner { 169 position: absolute !important; 170 left: 45% !important; 171 top: 45% !important; 172 } -
ai-title-generator/trunk/assets/js/aitgen-admin-script.js
r3057551 r3086265 234 234 }, 235 235 success: function (response) { 236 237 console.log(response);238 236 239 237 let status = response.data.status; … … 259 257 260 258 261 /*====== Image Generator======259 /*====== Short Description ====== 262 260 =============================*/ 261 //Generate Short Description 262 $(".aitgen_shortDescription").on('click', function (event) { 263 event.preventDefault(); 264 265 console.log("clicked"); 266 267 let id = $(this).data("id"); 268 // let dataTitle = $(this).data("title"); 269 270 // Perform the AJAX request 271 $.ajax({ 272 type: 'POST', 273 url: shortDsc.ajaxurl, 274 data: { 275 action: 'aitgen_shortDsc_action', 276 nonce: shortDsc.nonce, 277 id 278 }, 279 success: function (response) { 280 console.log(response); 281 let description = response.data.desc; 282 let id = response.data.id; 283 284 if (description) { 285 286 // Remove starting and ending double quotes 287 description = description.replace(/^"|"$/g, ''); 288 289 $(".aitgen_short_description").attr('dataType', 'short-desc'); 290 $(".aitgen_short_description").attr('pid', id); 291 $(".aitgen_short_description").val(description); 292 $("#aitgen_shortDesc").modal("show"); 293 } 294 }, 295 error: function (error) { 296 console.error('AJAX error:', error); 297 }, 298 }); 299 }); 300 301 // Re-generate Short Description 302 $(".aitgen_regenerate_shortDesc").on('click', function (event) { 303 event.preventDefault(); 304 305 let id = $(".aitgen_short_description").attr("pid"); 306 let generated_shortDesc_container = $("#aitgen_short_description"); 307 let generatedShortDesc = $(".aitgen_short_description").val(); 308 309 let ldsLoader = $(".lds-spinner"); 310 ldsLoader.css({ "display": "inline-block" }); 311 312 // Store reference to $(this) 313 let $buttonUpdate = $(".aitgen_update_shortDsc"); 314 $buttonUpdate.prop("disabled", true); 315 316 let $button = $(this); 317 $button.text("Generating..").prop("disabled", true); 318 319 // Perform the AJAX request 320 $.ajax({ 321 type: 'POST', 322 url: reGenShortDsc.ajaxurl, 323 data: { 324 action: 'reGenShortDsc_action', 325 nonce: reGenShortDsc.nonce, 326 id, 327 generatedShortDesc 328 }, 329 success: function (response) { 330 console.log(response); 331 let shortDescription = response.data.shortDesc; 332 // Remove starting and ending double quotes 333 shortDescription = shortDescription.replace(/^"|"$/g, ''); 334 335 if (shortDescription) { 336 ldsLoader.css({ "display": "none" }); 337 $button.text("Regenerate").removeAttr("disabled"); 338 $buttonUpdate.removeAttr("disabled"); 339 // Slide up the suggestions list 340 generated_shortDesc_container.slideUp(500, function () { 341 // Clear previous suggestions 342 generated_shortDesc_container.empty(); 343 generated_shortDesc_container.val(shortDescription); 344 generated_shortDesc_container.slideDown(500); 345 }) 346 } 347 }, 348 error: function (error) { 349 console.error('AJAX error:', error); 350 }, 351 }); 352 }); 353 354 355 $(".aitgen_update_shortDsc").on('click', function (event) { 356 event.preventDefault(); 357 358 let product_id = $(".aitgen_short_description").attr("pid"); 359 let dataType = $(".aitgen_short_description").attr("dataType"); 360 let updated_desc = $(".aitgen_short_description").val(); 361 362 // Perform the AJAX request 363 $.ajax({ 364 type: 'POST', 365 url: updateShortDsc.ajaxurl, 366 data: { 367 action: 'updateShortDsc_action', 368 'nonce': updateShortDsc.nonce, 369 'dataType':dataType, 370 'id': product_id, 371 'updated_desc': updated_desc, 372 }, 373 success: function (response) { 374 375 console.log(response); 376 let pageUrl = response?.data?.pageUrl; 377 if (response.success) { 378 window.location.href = pageUrl; 379 } 380 381 }, 382 error: function (error) { 383 console.error('AJAX error:', error); 384 }, 385 }); 386 }); 387 388 389 390 263 391 264 392 … … 269 397 270 398 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 399 400 401 402 403 404 405 406 407 408 409 410 411 412 -
ai-title-generator/trunk/includes/assets.php
r3057551 r3086265 15 15 16 16 // Check if current screen matches any of the specified locations 17 if ( is_admin() && $screen && ($screen->id === 'toplevel_page_ai-title-generator' || $screen->id === 'edit-product' || $screen->id === 'edit-post')) {17 // if ( is_admin() && $screen && ($screen->id === 'toplevel_page_ai-title-generator' || $screen->id === 'edit-product' || $screen->id === 'edit-post')) { 18 18 // Enqueue Bootstrap CSS 19 19 wp_enqueue_style('aitgen-admin-bootsrap-css', AITGEN_DIR_URI .'assets/css/bootstrap.min.css'); … … 31 31 wp_localize_script('aitgen-admin-script', 'UpdateObj', array('ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('update_reGenTitle_nonce'))); 32 32 wp_localize_script('aitgen-admin-script', 'postAjaxObj', array('ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('postReGenTitle_nonce'), 'action' => 'regenerate_postTitle_action')); 33 34 // Short Description 35 wp_localize_script('aitgen-admin-script', 'shortDsc', array('ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('generate_shortDesc_nonce'), 'action' => 'generate_shortDsc_action')); 36 37 wp_localize_script('aitgen-admin-script', 'reGenShortDsc', array('ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('reGenShortDesc_nonce') )); 38 wp_localize_script('aitgen-admin-script', 'updateShortDsc', array('ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('updateShortDesc_nonce') )); 39 33 40 wp_localize_script('aitgen-admin-script', 'openApiObj', array('ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('openApi_nonce'), 'action' => 'aitgen_openApiCheck_action')); 34 }41 // } 35 42 } 36 43 } 37 44 38 -
ai-title-generator/trunk/readme.txt
r3057943 r3086265 5 5 Requires at least: 5.4+ 6 6 Tested up to: 6.4.2 7 Stable tag: 1.0. 07 Stable tag: 1.0.1 8 8 Requires PHP: 8.1 9 9 License: GPLv3 or later … … 14 14 == Description == 15 15 16 AI Title Generator - AI Tittle Writer – ChatGPT is a content generator package for WordPress. It will help you to generate your Post, Product Title in your wordpress website. This will consume your time & smartly generate SEO friendly title with OpenAi power. It utilizes gpt-3.5 (https://openai.com) turbo(model) and other models to generate Title / content. Provides features for very quick use of prompt and built-in forms.16 AI Title Generator - AI Tittle Writer – ChatGPT is a content generator package for WordPress. It will help you to generate your Post, Product Title in your wordpress website. This will consume your time & smartly generate SEO friendly title/ short description with OpenAi power. It utilizes gpt-3.5 (https://openai.com) turbo(model) and other models to generate Title / content. Provides features for very quick use of prompt and built-in forms. 17 17 Just install and go ahead and enjoy OpenAi power. 18 18 … … 23 23 * Auto Tittle Generator / Regenerator 24 24 * Title suggestion tool for posts and products. 25 * Short Description Generate / Re-generator based on description 25 26 * Unlimited titles are suggested for topic -- 5+ Every time. 26 27 * One click update Generated Title … … 36 37 1. Go to `Plugins` in the Admin menu 37 38 2. Click on the button `Add new` 38 3. Search for ` AI Title Generator` and click `Install Now`39 3. Search for `Product discount manager` and click `Install Now` 39 40 4. Click on the `Activate plugin` 40 5. Enter Valid OpenAIAPI Key to run "AI Title Generator"41 5. Enter Valid API Key to run "AI Title Generator" 41 42 42 43 You can also do it Manually. … … 84 85 85 86 == Changelog == 87 = 1.0.1- 14 May, 2024 = 88 * Feature: Short Description Generator added for product 89 86 90 = 1.0.0 = 87 91 * Initial Release … … 92 96 93 97 98 99 -
ai-title-generator/trunk/views/admin/aitgen-conent.php
r3057551 r3086265 41 41 if ($current_screen && $current_screen->post_type === 'product' || $current_screen && $current_screen->post_type === 'post' || $current_screen ) { 42 42 aitgen_titleRegenerate_modal(); 43 aitgen_shortDescriptionRegenerate_modal(); 43 44 } 44 45 } … … 68 69 </div> 69 70 70 <div class="modal-footer"> 71 <span class="aitgen_update_msg text-secondary d-none"><?php esc_html_e( 'Updated', 'ai-title-generator' ) ?></span> 72 <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php esc_html_e( 'Cancel', 'ai-title-generator' ) ?></button> 73 <button type="button" class="btn btn-secondary aitgen_regenerate_title"><?php esc_html_e( 'Regenerate', 'ai-title-generator' ) ?></button> 74 <button type="button" class="btn btn-success aitgen_update_title" data-bs-dismiss="modal"><?php esc_html_e( 'Confirm', 'ai-title-generator' ) ?></button> 71 <div class="modal-footer"> 72 <span class="aitgen_update_msg text-secondary d-none"><?php esc_html_e( 'Updated', 'ai-title-generator' ) ?></span> 73 <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php esc_html_e( 'Cancel', 'ai-title-generator' ) ?></button> 74 <button type="button" class="btn btn-secondary aitgen_regenerate_title"><?php esc_html_e( 'Regenerate', 'ai-title-generator' ) ?></button> 75 <button type="button" class="btn btn-success aitgen_update_title" data-bs-dismiss="modal"><?php esc_html_e( 'Confirm', 'ai-title-generator' ) ?></button> 76 </div> 77 </div> 78 </div> 79 </div> 80 <?php 81 } 82 } 83 84 85 86 // Short Description Regenerator Modal 87 if( !function_exists('aitgen_shortDescriptionRegenerate_modal')){ 88 function aitgen_shortDescriptionRegenerate_modal(){ 89 ?> 90 <div class="modal fade" id="aitgen_shortDesc" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true"> 91 <div class="modal-dialog aitgen-modal-dialog modal-lg"> 92 <div class="modal-content"> 93 94 <div class="modal-header"> 95 <h5 class="modal-title"><?php esc_html_e( 'Generated Short Description', 'ai-title-generator' ) ?></h5> 96 <button type="button" class="btn-close py-1" data-bs-dismiss="modal" aria-label="Close"></button> 75 97 </div> 98 <div class="modal-body"> 99 100 <p class="fs-6"><?php esc_html_e( 'Short Description:', 'ai-title-generator' ) ?></p> 101 <div class="aitgen_short_description_wrapper"> 102 <textarea cols="30" rows="7" class="form-control aitgen_short_description" id="aitgen_short_description"> 103 </textarea> 104 <!-- Loader --> 105 <div class="lds-spinner"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div> 106 </div> 107 <!-- ./Loader --> 108 </div> 109 <div class="modal-footer"> 110 <span class="aitgen_update_msg text-secondary d-none"><?php esc_html_e( 'Updated', 'ai-title-generator' ) ?></span> 111 <button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php esc_html_e( 'Cancel', 'ai-title-generator' ) ?></button> 112 <button type="button" class="btn btn-secondary aitgen_regenerate_shortDesc"><?php esc_html_e( 'Regenerate', 'ai-title-generator' ) ?></button> 113 <button type="button" class="btn btn-success aitgen_update_shortDsc" data-bs-dismiss="modal"><?php esc_html_e( 'Update', 'ai-title-generator' ) ?></button> 114 </div> 76 115 </div> 77 116 </div>
Note: See TracChangeset
for help on using the changeset viewer.