Plugin Directory

Changeset 3448175


Ignore:
Timestamp:
01/27/2026 08:33:31 PM (2 months ago)
Author:
ipodguy79
Message:

1.2.2 i always have to do it twice

Location:
ghost-update/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ghost-update/trunk/ghost-update.php

    r3448117 r3448175  
    33 * Plugin Name: Ghost Update
    44 * Description: Keeps your WordPress site fresh by rotating post/page publish dates & pinging Google Search Console.
    5  * Version: 1.2.1
     5 * Version: 1.2.2
    66 * License: GPLv2 or later
    77 * Author: IpodGuy79
  • ghost-update/trunk/includes/class-ghost-update-feedback-banner.php

    r3287022 r3448175  
    11<?php
     2
     3if ( ! defined( 'ABSPATH' ) ) {
     4    exit;
     5}
     6
    27
    38class GhostUpdateFeedbackBanner {
  • ghost-update/trunk/includes/updater.php

    r3448117 r3448175  
    1010 * Debug logs are available when ghostupdate_log_level = 2.
    1111 */
     12
     13/**
     14 * Append text to a file using WP_Filesystem (PluginCheck compliant).
     15 *
     16 * @param string $path Absolute path.
     17 * @param string $text Text to append.
     18 * @return bool
     19 */
     20function ghostupdate_fs_append($path, $text) {
     21    if (!function_exists('WP_Filesystem')) {
     22        require_once ABSPATH . 'wp-admin/includes/file.php';
     23    }
     24
     25    // Initialize filesystem (direct if possible).
     26    global $wp_filesystem;
     27    if (!$wp_filesystem) {
     28        WP_Filesystem();
     29    }
     30    if (!$wp_filesystem) {
     31        return false;
     32    }
     33
     34    $existing = '';
     35    if ($wp_filesystem->exists($path)) {
     36        $existing = (string) $wp_filesystem->get_contents($path);
     37    } else {
     38        // Ensure parent dir exists.
     39        $dir = wp_normalize_path(dirname($path));
     40        if (!$wp_filesystem->is_dir($dir)) {
     41            $wp_filesystem->mkdir($dir);
     42        }
     43    }
     44
     45    // Preserve behavior: "append" exactly.
     46    return (bool) $wp_filesystem->put_contents($path, $existing . $text, FS_CHMOD_FILE);
     47}
     48
     49
    1250
    1351function ghostupdate_log_level() {
     
    91129
    92130/**
    93  * Tail reader for admin UI (reads from end; does NOT load entire file).
     131 * Tail reader for admin UI (PluginCheck compliant: uses WP_Filesystem).
     132 * Note: This reads the whole file; OK because your logs are small/rotated daily.
    94133 */
    95134function ghostupdate_tail_lines($file, $max_lines = 100, $chunk_size = 8192) {
    96     if (!file_exists($file)) return [];
    97     $max_lines = max(1, (int)$max_lines);
    98 
    99     $fp = @fopen($file, 'rb');
    100     if (!$fp) return [];
    101 
    102     $buffer = '';
    103     $pos = -1;
    104     $lines = [];
    105 
    106     fseek($fp, 0, SEEK_END);
    107     $filesize = ftell($fp);
    108 
    109     while (count($lines) <= $max_lines && abs($pos) < $filesize) {
    110         $read = min($chunk_size, $filesize - abs($pos));
    111         $pos -= $read;
    112         fseek($fp, $pos, SEEK_END);
    113         $buffer = fread($fp, $read) . $buffer;
    114         $lines = preg_split("/\r\n|\n|\r/", $buffer);
    115     }
    116 
    117     fclose($fp);
     135    unset($chunk_size); // kept for back-compat signature
     136    $max_lines = max(1, (int) $max_lines);
     137
     138    if (!function_exists('WP_Filesystem')) {
     139        require_once ABSPATH . 'wp-admin/includes/file.php';
     140    }
     141
     142    global $wp_filesystem;
     143    if (!$wp_filesystem) {
     144        WP_Filesystem();
     145    }
     146    if (!$wp_filesystem) {
     147        return [];
     148    }
     149
     150    if (!$wp_filesystem->exists($file)) return [];
     151
     152    $content = (string) $wp_filesystem->get_contents($file);
     153    if ($content === '') return [];
     154
     155    $lines = preg_split("/\r\n|\n|\r/", $content);
    118156
    119157    // Remove potential trailing empty line
     
    124162    return array_slice($lines, -$max_lines);
    125163}
     164
    126165
    127166function ghostupdate_get_excluded_ids() {
     
    146185    $limit = max(1, (int) $limit);
    147186
    148     $sql = "SELECT ID FROM {$wpdb->posts}
     187        $sql = "SELECT ID FROM {$wpdb->posts}
    149188            WHERE post_status = 'publish'
    150189              AND post_type IN ('post','page')
     
    161200    $args[] = $limit;
    162201
    163     $prepared = $wpdb->prepare($sql, $args);
    164     return $wpdb->get_col($prepared);
     202    // Cache to satisfy PHPCS NoCaching + reduce repeated selects during runs.
     203    $cache_group = 'ghost-update';
     204    $cache_key   = 'cand_ids_' . md5($cursor . '|' . $limit . '|' . implode(',', array_map('intval', (array) $excluded)));
     205    $cached      = wp_cache_get($cache_key, $cache_group);
     206    if ($cached !== false) {
     207        return $cached;
     208    }
     209
     210    // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
     211    // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
     212    $ids = $wpdb->get_col(
     213        $wpdb->prepare($sql, ...$args)
     214    );
     215    // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
     216    // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery
     217    wp_cache_set($cache_key, $ids, $cache_group, 30);
     218
     219    return $ids;
    165220}
    166221
  • ghost-update/trunk/readme.txt

    r3448117 r3448175  
    55Tested up to: 6.9
    66Requires PHP: 7.2
    7 Stable tag: 1.2.1
     7Stable tag: 1.2.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.