Plugin Directory

Changeset 3086265


Ignore:
Timestamp:
05/14/2024 06:26:13 AM (22 months ago)
Author:
afello
Message:

add short description generator for product

Location:
ai-title-generator/trunk
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • ai-title-generator/trunk/ai-title-generator.php

    r3057551 r3086265  
    33 * Plugin Name: AI Title Generator
    44 * Description: Generate / Regenerate your Title using AI on WordPress website.
    5  * Version: 1.0.0
     5 * Version: 1.0.1
    66 * Author: Spark Coder
    77 * Author URI: https://sparkcoder.com
     
    4949            require( AITGEN_DIR_PATH.'classes/AITGEN-ajax-handling.php' ); 
    5050            require( AITGEN_DIR_PATH.'classes/AITGEN-title-handling.php' ); 
     51            require( AITGEN_DIR_PATH.'classes/AITGEN-short-desc-handling.php' ); 
    5152            require( AITGEN_DIR_PATH.'classes/AITGEN_dbManagement.php' ); 
    5253
     
    5556            // Assets load
    5657            add_action( 'admin_enqueue_scripts', 'aitgen_admin_assets');
     58            // add_action( 'enqueue_block_editor_assets', 'aitgen_editor_assets' );
    5759            // Load Content
    5860            add_action('admin_footer', 'aitgen_title_generator_box_admin');
     61
    5962            add_filter('post_row_actions', 'aitgen_admin_postProduct_custom_button', 10, 2);
    6063            // Hook into the page_row_actions filter to add the custom button for pages
     
    7275            add_action('wp_ajax_update_regenerate_title_action', array( new AITGEN_Title_Handle(), 'aitgen_update_product_title_callback') );
    7376
    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') );
    7581        }
    7682    }
     
    131137
    132138}
     139
     140
     141function 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
    133170// 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}
     189add_action( 'media_buttons', 'aitgen_short_description_button' );
     190
     191
     192
     193
     194
  • ai-title-generator/trunk/assets/css/aitgen-admin-style.css

    r3057551 r3086265  
    158158}
    159159
     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  
    234234        },
    235235      success: function (response) {
    236          
    237 console.log(response);
    238236
    239237            let status = response.data.status;
     
    259257
    260258
    261   /*====== Image Generator ======
     259  /*====== Short Description ======
    262260  =============================*/
     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
    263391
    264392
     
    269397
    270398
    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  
    1515
    1616        // 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')) {
    1818            // Enqueue Bootstrap CSS
    1919            wp_enqueue_style('aitgen-admin-bootsrap-css', AITGEN_DIR_URI .'assets/css/bootstrap.min.css');
     
    3131            wp_localize_script('aitgen-admin-script', 'UpdateObj', array('ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('update_reGenTitle_nonce')));
    3232            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
    3340            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        // }
    3542    }
    3643}
    3744
    38 
  • ai-title-generator/trunk/readme.txt

    r3057943 r3086265  
    55Requires at least: 5.4+
    66Tested up to: 6.4.2
    7 Stable tag: 1.0.0
     7Stable tag: 1.0.1
    88Requires PHP: 8.1
    99License: GPLv3 or later
     
    1414== Description ==
    1515
    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.
     16AI 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.
    1717Just install and go ahead and enjoy OpenAi power.
    1818
     
    2323* Auto Tittle Generator / Regenerator
    2424* Title suggestion tool for posts and products.
     25* Short Description Generate / Re-generator based on description
    2526* Unlimited titles are suggested for topic -- 5+ Every time.
    2627* One click update Generated Title
     
    36371. Go to `Plugins` in the Admin menu
    37382. Click on the button `Add new`
    38 3. Search for `AI Title Generator` and click `Install Now`
     393. Search for `Product discount manager` and click `Install Now`
    39404. Click on the `Activate plugin`
    40 5. Enter Valid OpenAI API Key to run "AI Title Generator"
     415. Enter Valid API Key to run "AI Title Generator"
    4142
    4243You can also do it Manually.
     
    8485
    8586== Changelog ==
     87= 1.0.1- 14 May, 2024 =
     88* Feature: Short Description Generator added for product
     89
    8690= 1.0.0 =
    8791* Initial Release
     
    9296
    9397
     98
     99
  • ai-title-generator/trunk/views/admin/aitgen-conent.php

    r3057551 r3086265  
    4141        if ($current_screen && $current_screen->post_type === 'product' || $current_screen && $current_screen->post_type === 'post' || $current_screen ) {
    4242            aitgen_titleRegenerate_modal();
     43            aitgen_shortDescriptionRegenerate_modal();
    4344        }
    4445    }
     
    6869                            </div>
    6970
    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
     87if( !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>
    7597                        </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>
    76115                    </div>
    77116                </div>
Note: See TracChangeset for help on using the changeset viewer.