Plugin Directory

Changeset 3255397


Ignore:
Timestamp:
03/13/2025 01:32:51 PM (19 months ago)
Author:
hipaai
Message:

added version 1.7

Location:
hipa-ai
Files:
12 added
2 edited

Legend:

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

    r3255301 r3255397  
    66Tested up to: 6.7
    77Requires PHP: 7.0
    8 Stable tag: 1.6
     8Stable tag: 1.7
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    9191* Added functionality of fetching single post
    9292
     93= 1.7 =
     94* Single post now can be fetched by id and after date period
     95
    9396== Upgrade Notice ==
    9497
  • hipa-ai/trunk/hipa-ai.php

    r3255301 r3255397  
    44Plugin URI:   https://hipa.ai
    55Description:  Refresh your blog posts on autopilot with intelligent, in-depth updates.
    6 Version:      1.6
     6Version:      1.7
    77Author:       Hipa.ai
    88Author URI:   https://hipa.ai/suggestions/new
    … …  
    333333    // Validate URL parameter
    334334    $url = $request->get_param('url');
    335     if (empty($url)) {
    336         return new WP_REST_Response(array('message' => 'URL parameter is required'), 400);
    337     }
    338 
    339     // Sanitize and validate URL
     335    $id = $request->get_param('id');
     336    $after = $request->get_param('after');
     337    $context = $request->get_param('context');
     338
     339    if ($context && !in_array($context, ['raw', 'rendered'])) {
     340        return new WP_REST_Response(array('message' => 'Invalid context value'), 400);
     341    }
     342
     343        // Ensure that at least one identifier (URL or ID) is provided
     344    if (!$url && !$id) {
     345        return new WP_REST_Response(array('message' => 'Either URL or post ID parameter is required'), 400);
     346    }
     347
     348    if ($id) {
     349        $post_id = (int) $id;
     350    } else {
    340351    $clean_url = esc_url_raw($url);
    341352    $site_url = get_site_url();
    342353   
    343     // Verify URL belongs to this site
    344354    if (strpos($clean_url, $site_url) !== 0) {
    345355        return new WP_REST_Response(array('message' => 'Invalid URL for this site'), 400);
    346356    }
    347357
    348     // Get post ID from URL
    349358    $post_id = url_to_postid($clean_url);
     359    }
     360
    350361    if (!$post_id) {
    351362        return new WP_REST_Response(array('message' => 'Post not found for the given URL'), 404);
    352363    }
    353364
    354     // Get post data
    355365    $post = get_post($post_id);
    356366    if (!$post || $post->post_status !== 'publish') {
    … …  
    358368    }
    359369
    360     // Handle context parameter
    361     $context = $request->get_param('context');
    362     if ($context && !in_array($context, ['raw', 'rendered'])) {
    363         return new WP_REST_Response(array('message' => 'Invalid context value'), 400);
    364     }
    365 
    366     // Format content based on context
     370     if ($after) {
     371        if (strtotime($post->post_modified) < strtotime($after)) {
     372            return new WP_REST_Response(array('message' => 'Post not found for the given date filter'), 404);
     373        }
     374    }
     375
    367376    if ($context === 'raw') {
    368377        $raw_content = get_post_field('post_content', $post_id);
    … …  
    371380        $content = apply_filters('the_content', $post->post_content);
    372381    }
     382   
    373383
    374384    // Build response
Note: See TracChangeset for help on using the changeset viewer.