Plugin Directory

Changeset 3277817


Ignore:
Timestamp:
04/21/2025 04:03:29 AM (12 months ago)
Author:
u3kkasha
Message:

feat(rest): add api for uploading images

Location:
blogify-ai/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • blogify-ai/trunk/README.txt

    r3184709 r3277817  
    33Tags: AI Blogging, Automated Post Creation, Video to Blog, Audio to Blog, Blogging Tools
    44Requires at least: 6.0
    5 Tested up to: 6.6
    6 Stable tag: 1.1.2
     5Tested up to: 6.8
     6Stable tag: 1.1.3
    77Requires PHP: 7.4
    88License: GPLv2 or later
  • blogify-ai/trunk/admin/actions/rest.php

    r3170423 r3277817  
    3030require_once ABSPATH . 'wp-admin/includes/image.php';
    3131
    32 add_action('rest_api_init', fn () =>
     32add_action(
     33    'rest_api_init',
     34    fn() =>
    3335    register_rest_route('blogify/v1', '/create-post', [
    3436        'methods' => ['POST'],
     
    3638        'callback' => function (\WP_REST_Request $request) {
    3739
    38             $required = function($field) use ($request) {
     40            $required = function ($field) use ($request) {
    3941                $value = $request->get_param($field);
    4042                if (empty($value)) {
     
    4446            };
    4547
    46             $status_validation = function() use ($request) {
     48            $status_validation = function () use ($request) {
    4749                $status = $request->get_param('status');
    4850                if ($status && !in_array($status, array_keys(get_post_statuses()), true)) {
     
    5153                return $status;
    5254            };
    53            
     55
    5456            $sanitize_text_array = fn(?array $array) => is_array($array) ? array_map('sanitize_text_field', $array) : [];
    5557
     
    8789                    'blogify_meta_description' => sanitize_text_field($request->get_param('meta_description')),
    8890                ],
    89                 true
     91                true,
    9092            ]);
    9193
     
    104106);
    105107
     108add_action(
     109    'rest_api_init',
     110    fn() =>
     111    register_rest_route('blogify/v1', '/upload-image', [
     112        'methods' => ['POST'],
     113        'permission_callback' => fn(\WP_REST_Request $request) => $request->get_param('client_secret') === get_option('blogify_client_secret'),
     114        'callback' => function (\WP_REST_Request $request) {
     115            $image_url = $request->get_param('image');
    106116
     117            if (empty($image_url)) {
     118                return new \WP_Error('error', 'image URL is required', ['status' => 400]);
     119            }
    107120
    108 add_action('wp_head', function () {
    109     global $post;
    110     if (is_page() || is_single()) {
    111         $meta_description = get_post_meta(get_queried_object_id(), 'blogify_meta_description', true);
    112         $meta_tags = get_post_meta(get_queried_object_id(), 'blogify_meta_tags', true);
     121            $image_src = media_sideload_image(sanitize_url($image_url), 0, null, 'src');
    113122
    114         if (!empty($meta_description)) {
    115             printf(
    116                 '<meta name="description" content="%s" />' . "\n",
    117                 esc_attr(trim($meta_description))
    118             );
    119         }
     123            if (is_wp_error($image_src)) {
     124                return new \WP_Error('error', 'Failed to upload image: ' . $image_src->get_error_message(), ['status' => 500]);
     125            }
    120126
    121         if (!empty($meta_tags)) {
    122             printf(
    123                 '<meta name="keywords" content="%s" />' . "\n",
    124                 esc_attr(trim(implode(',', $meta_tags)))
    125             );
     127            return ['src' => $image_src];
     128        },
     129    ])
     130);
     131
     132add_action(
     133    'wp_head',
     134    function () {
     135        global $post;
     136        if (is_page() || is_single()) {
     137            $meta_description = get_post_meta(get_queried_object_id(), 'blogify_meta_description', true);
     138            $meta_tags = get_post_meta(get_queried_object_id(), 'blogify_meta_tags', true);
     139
     140            if (!empty($meta_description)) {
     141                printf(
     142                    '<meta name="description" content="%s" />' . "\n",
     143                    esc_attr(trim($meta_description)),
     144                );
     145            }
     146
     147            if (!empty($meta_tags)) {
     148                printf(
     149                    '<meta name="keywords" content="%s" />' . "\n",
     150                    esc_attr(trim(implode(',', $meta_tags))),
     151                );
     152            }
    126153        }
    127154    }
    128 }
    129155);
  • blogify-ai/trunk/admin/ui/all-blogs.php

    r3170423 r3277817  
    2525        'post_author' => sanitize_text_field($_POST['author']),
    2626        'post_category' => array_map('sanitize_text_field', $_POST['categories'] ?? []),
     27        'meta_input' => [
     28            'blogify_blog_id' => sanitize_text_field($blog_id),
     29            'blogify_meta_tags' => array_map('sanitize_text_field', $blog['blogOutline']['metaTags'] ?? []),
     30            'blogify_meta_description' => sanitize_text_field($blog['blogOutline']['metaDescription']),
     31        ],
    2732    ], true);
     33    if ($blog['image']) {
     34        $image = media_sideload_image(sanitize_url($blog['image']), $post_id, null, 'id');
     35        set_post_thumbnail($post_id, $image);
     36    }
    2837    if (is_wp_error($post_id)) {
    2938        throw new \Exception('Failed to create post: ' . esc_textarea($post_id->get_error_message()));
     
    7887                ceil($blogs['total'] / $page_size),
    7988                $nonce,
    80                 'blogify-ai'
     89                'blogify-ai',
    8190            );
    8291            ?>
  • blogify-ai/trunk/blogify-ai.php

    r3184706 r3277817  
    1313 * Plugin URI:        https://blogify.ai/
    1414 * Description:       Seamlessly publish AI-generated blog posts from Blogify.ai to your WordPress site with ease, enhancing content management and SEO optimization in a few clicks.
    15  * Version:           1.1.2
     15 * Version:           1.1.3
    1616 * Requires at least: 6.0
    1717 * Requires PHP:      7.4
     
    3131
    3232// Constants
    33 DEFINE('BLOGIFY_VERSION', '1.1.2');
     33DEFINE('BLOGIFY_VERSION', '1.1.3');
    3434
    3535DEFINE('BLOGIFY_PLUGIN_DIR', plugin_dir_path(__FILE__));
  • blogify-ai/trunk/changelog.md

    r3184706 r3277817  
    55The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
    66and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
     7
     8## [1.1.3] - 2025-Apr-20
     9
     10### Added
     11
     12- Addded REST endpoint for adding images to Media Library 
     13
     14### Fixed
     15
     16- Set blog image as thumbanil when publishing from within the plugin
     17- Set meta tags and meta description when publishing from within the plugin
     18
    719
    820## [1.1.2] - 2024-Nov-09
Note: See TracChangeset for help on using the changeset viewer.