Plugin Directory

Changeset 3075791


Ignore:
Timestamp:
04/23/2024 01:00:21 PM (23 months ago)
Author:
knowhalim
Message:

Added Category Creation

Location:
easily-post-gpt
Files:
33 added
2 edited

Legend:

Unmodified
Added
Removed
  • easily-post-gpt/trunk/admin/class-gpt2wp-admin.php

    r3069299 r3075791  
    197197
    198198
     199
     200
    199201function gpt2wp_add_blogpost($request) {
    200202   
     
    215217        'post_title' => $post_title,
    216218        'post_content' => $post_content,
    217         'post_category' => array(get_cat_ID($post_category)),
     219        'post_category' => array(gpt2wp_category_make($post_category)),
    218220        'tags_input' => $post_tags,
    219221        'post_status' => 'publish',
     
    487489    return esc_attr(get_option('gpt2wp_custom_field_1'));
    488490}
     491
     492function gpt2wp_category_make($categoryName) {
     493   
     494    $categoryExists = term_exists($categoryName, 'category');
     495
     496    if ($categoryExists) {
     497       
     498        return $categoryExists['term_id'];
     499    } else {
     500       
     501        $newCategory = wp_insert_term(
     502            $categoryName,
     503            'category'     
     504        );
     505
     506       
     507        if (!is_wp_error($newCategory)) {
     508            return $newCategory['term_id'];
     509        } else {
     510           
     511            $uncategorized = get_category_by_slug('uncategorized');
     512            return $uncategorized->term_id;
     513        }
     514    }
     515}
  • easily-post-gpt/trunk/gpt2wp.php

    r3069299 r3075791  
    1717 * Plugin URI:        https://gpttowp.com
    1818 * Description:       Easily post from ChatGPT to your WP without writing any codes.
    19  * Version:           1.0.0
     19 * Version:           1.0.1
    2020 * Author:            Knowhalim
    2121 * Author URI:        https://knowhalim.com/
     
    3131}
    3232
    33 /**
    34  * Currently plugin version.
    35  * Start at version 1.0.0 and use SemVer - https://semver.org
    36  * Rename this for your plugin and update it as you release new versions.
    37  */
    38 define( 'GPT2WP_VERSION', '1.0.0' );
    3933
    40 /**
    41  * The code that runs during plugin activation.
    42  * This action is documented in includes/class-gpt2wp-activator.php
    43  */
     34define( 'GPT2WP_VERSION', '1.0.1' );
     35
     36
    4437function gpt2wp_activate_plugin() {
    4538    require_once plugin_dir_path( __FILE__ ) . 'includes/class-gpt2wp-activator.php';
     
    4740}
    4841
    49 /**
    50  * The code that runs during plugin deactivation.
    51  * This action is documented in includes/class-gpt2wp-deactivator.php
    52  */
    5342function gpt2wp_deactivate_plugin() {
    5443    require_once plugin_dir_path( __FILE__ ) . 'includes/class-gpt2wp-deactivator.php';
     
    5948register_deactivation_hook( __FILE__, 'gpt2wp_deactivate_plugin' );
    6049
    61 /**
    62  * The core plugin class that is used to define internationalization,
    63  * admin-specific hooks, and public-facing site hooks.
    64  */
     50
    6551require plugin_dir_path( __FILE__ ) . 'includes/class-gpt2wp.php';
    6652
    67 /**
    68  * Begins execution of the plugin.
    69  *
    70  * Since everything within the plugin is registered via hooks,
    71  * then kicking off the plugin from this point in the file does
    72  * not affect the page life cycle.
    73  *
    74  * @since    1.0.0
    75  */
     53
    7654function gpt2wp_start_run() {
    7755
Note: See TracChangeset for help on using the changeset viewer.