Plugin Directory

Changeset 3482478


Ignore:
Timestamp:
03/14/2026 10:32:08 AM (2 weeks ago)
Author:
rocketcomunicazione
Message:

2.4.4

Location:
rc-site-manager-optimization/trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • rc-site-manager-optimization/trunk/crons/pagespeed.php

    r3482178 r3482478  
    66add_action('wp', 'rc_sm_pagespeed_schedule_cron');
    77function rc_sm_pagespeed_schedule_cron() {
    8     if (!wp_next_scheduled('rc_sm_pagespeed_daily_cron')) {
    9         // Calcola prossime 06:00 nel timezone del sito
    10         $timezone = new DateTimeZone(wp_timezone_string());
    11         $now      = new DateTime('now', $timezone);
    12         $next_run = new DateTime('today 06:00', $timezone);
    13 
    14         // Se le 06:00 sono già passate oggi, schedula per domani
    15         if ($now >= $next_run) {
    16             $next_run->modify('+1 day');
    17         }
    18 
    19         wp_schedule_event($next_run->getTimestamp(), 'daily', 'rc_sm_pagespeed_daily_cron');
     8    if (!wp_next_scheduled('rc_sm_pagespeed_cron')) {
     9        wp_schedule_event(time(), 'hourly', 'rc_sm_pagespeed_cron');
    2010    }
    2111}
     
    2313register_deactivation_hook(RC_SM_PLUGIN_DIR . 'rc-site-manager-optimization.php', 'rc_sm_pagespeed_unschedule_cron');
    2414function rc_sm_pagespeed_unschedule_cron() {
    25     $timestamp = wp_next_scheduled('rc_sm_pagespeed_daily_cron');
     15    $timestamp = wp_next_scheduled('rc_sm_pagespeed_cron');
    2616    if ($timestamp) {
    27         wp_unschedule_event($timestamp, 'rc_sm_pagespeed_daily_cron');
    28     }
    29 }
    30 
    31 add_action('rc_sm_pagespeed_daily_cron', 'rc_sm_pagespeed_run_job');
     17        wp_unschedule_event($timestamp, 'rc_sm_pagespeed_cron');
     18    }
     19}
     20
     21add_action('rc_sm_pagespeed_cron', 'rc_sm_pagespeed_run_job');
    3222
    3323// ─── Job principale ───────────────────────────────────────────────────────────
     
    3929    $log_file = WP_CONTENT_DIR . '/debug.log';
    4030
     31    // Calcola soglia giornaliera: oggi alle 06:00 nel timezone del sito
     32    $timezone       = new DateTimeZone(wp_timezone_string());
     33    $now            = new DateTime('now', $timezone);
     34    $daily_threshold = new DateTime('today 06:00', $timezone);
     35
    4136    rc_sm_pagespeed_log('=== INIZIO JOB PAGESPEED ===', $log_file);
    42 
    43     $records = rc_sm_pagespeed_get_all();
    44     $total   = count($records);
    45 
    46     rc_sm_pagespeed_log("Record da processare: {$total}", $log_file);
     37    rc_sm_pagespeed_log('Ora attuale: ' . $now->format('Y-m-d H:i:s'), $log_file);
     38    rc_sm_pagespeed_log('Soglia giornaliera: ' . $daily_threshold->format('Y-m-d H:i:s'), $log_file);
     39
     40    $all_records = rc_sm_pagespeed_get_all();
     41    $total       = count($all_records);
    4742
    4843    if ($total === 0) {
    49         rc_sm_pagespeed_log("Nessun record da processare. Uscita.", $log_file);
     44        rc_sm_pagespeed_log('Nessun record. Uscita.', $log_file);
     45        return;
     46    }
     47
     48    // Filtra i record da processare
     49    $records = [];
     50    foreach ($all_records as $record) {
     51
     52        if (empty($record->last_check) || $record->last_check === '0000-00-00 00:00:00') {
     53            // Mai verificato → processa subito
     54            $records[] = $record;
     55
     56        } else {
     57            // Già verificato → processa solo se:
     58            // 1. Sono passate le 06:00 di oggi
     59            // 2. L'ultimo check è precedente alle 06:00 di oggi
     60            $last_check_dt = new DateTime($record->last_check, $timezone);
     61            if ($now >= $daily_threshold && $last_check_dt < $daily_threshold) {
     62                $records[] = $record;
     63            }
     64        }
     65    }
     66
     67    $to_process = count($records);
     68    rc_sm_pagespeed_log("Record totali: {$total} | Da processare: {$to_process}", $log_file);
     69
     70    if ($to_process === 0) {
     71        rc_sm_pagespeed_log('Nessun record da processare in questo ciclo.', $log_file);
    5072        return;
    5173    }
     
    7395
    7496        // Delay tra URL (non dopo l'ultimo)
    75         if ($index < $total - 1) {
     97        if ($index < $to_process - 1) {
    7698            sleep(5);
    7799        }
     
    79101
    80102    rc_sm_pagespeed_log("=== FINE JOB ===", $log_file);
    81     rc_sm_pagespeed_log("Processati: {$processed}/{$total}", $log_file);
    82     rc_sm_pagespeed_log("Falliti: {$failed}/{$total}", $log_file);
     103    rc_sm_pagespeed_log("Processati: {$processed}/{$to_process}", $log_file);
     104    rc_sm_pagespeed_log("Falliti: {$failed}/{$to_process}", $log_file);
    83105    rc_sm_pagespeed_log("================\n", $log_file);
    84106}
  • rc-site-manager-optimization/trunk/includes/database.php

    r3482178 r3482478  
    1313            id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
    1414            post_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
     15            term_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
    1516            url TEXT NULL,
    1617            action VARCHAR(100) NULL,
     
    364365    );
    365366}
     367
     368
     369include 'database_migration.php';
  • rc-site-manager-optimization/trunk/rc-site-manager-optimization.php

    r3482178 r3482478  
    33 * Plugin Name: RC Site Manager & Optimization
    44 * Description: All-in-one Wordpress manager: control WooCommerce, SEO, caching, media, and multilingual tools from one dashboard.
    5  * Version: 2.4.3
     5 * Version: 2.4.4
    66 * Author: Rocket Comunicazione
    77 * Author URI: https://www.rocketcomunicazione.com
     
    1818
    1919
    20 define('RC_SM_PLUGIN_VERSION', '2.4.3');
     20define('RC_SM_PLUGIN_VERSION', '2.4.4');
    2121
    2222define( 'RC_SM_SITE_URL', home_url() );
  • rc-site-manager-optimization/trunk/readme.txt

    r3482178 r3482478  
    55Tested up to: 6.9
    66Requires PHP: 8.1
    7 Stable tag: 2.4.3
     7Stable tag: 2.4.4
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    160160== Changelog ==
    161161
     162
     163= 2.4.4 - March 14, 2026 =
     164* Minor bug fixes and improvement
    162165
    163166= 2.4.3 - March 13, 2026 =
     
    307310== Upgrade Notice ==
    308311
     312= 2.4.4 - March 14, 2026 =
     313Minor bug fixes.
     314
    309315= 2.4.3 - March 13, 2026 =
    310316Minor bug fixes.
  • rc-site-manager-optimization/trunk/top_url/index.php

    r3482178 r3482478  
    103103                                        $columns = [
    104104                                            'id'        => ['label' => 'ID',                                                             'class' => 'rc_sm_table_column_hide'],
    105                                             'post_id'   => ['label' => 'ID' . ' (post_id)',                                            'class' => 'rc_sm_width_1'],
     105                                            'post_id'   => ['label' => 'ID',                                                            'class' => 'rc_sm_width_1'],
    106106                                            'url'       => ['label' => 'URL',                                                          'class' => 'rc_sm_width_4'],
    107107                                            'type'      => ['label' => __('Type', 'rc-site-manager-optimization'),                     'class' => 'rc_sm_width_1'],
    108                                             'info'      => ['label' => __('Informations', 'rc-site-manager-optimization') . ' (post_id)',     'class' => 'rc_sm_width_2'],
     108                                            'info'      => ['label' => __('Informations', 'rc-site-manager-optimization'),              'class' => 'rc_sm_width_2'],
    109109                                            'rucss'     => ['label' => 'WP-Rocket / ' . __('Used CSS', 'rc-site-manager-optimization'),    'class' => 'rc_sm_width_2'],
    110110                                            'pagespeed' => ['label' => 'Page Speed',                                                    'class' => 'rc_sm_width_2'],
  • rc-site-manager-optimization/trunk/top_url/top_url_function.php

    r3482178 r3482478  
    22
    33if (!defined('ABSPATH')) { exit; }
     4
     5
     6/**
     7 * Resolve any URL to an internal ID.
     8 * Works on any WordPress site regardless of permalink structure.
     9 * Returns array: ['post_id' => int, 'term_id' => int]
     10 */
     11function rc_sm_url_to_id($clean_url) {
     12
     13    // 1. Post, pages, CPT (includes WooCommerce products)
     14    $post_id = url_to_postid($clean_url);
     15    if ($post_id) return ['post_id' => (int) $post_id, 'term_id' => 0];
     16
     17    // 2. All registered taxonomies — try every segment of the path
     18    //    Works regardless of category_base, tag_base, or custom permalink settings
     19    $path     = parse_url($clean_url, PHP_URL_PATH);
     20    $segments = array_filter(explode('/', trim($path, '/')));
     21
     22    $skip_slugs = array_filter([
     23        get_option('category_base'),
     24        get_option('tag_base'),
     25        'category', 'tag',
     26    ]);
     27
     28    foreach (array_reverse($segments) as $slug) {
     29        if (in_array($slug, $skip_slugs, true)) continue;
     30        foreach (get_taxonomies() as $taxonomy) {
     31            $term = get_term_by('slug', $slug, $taxonomy);
     32            if ($term && !is_wp_error($term)) return ['post_id' => 0, 'term_id' => (int) $term->term_id];
     33        }
     34    }
     35
     36    // 3. Not found
     37    return ['post_id' => 0, 'term_id' => 0];
     38}
     39
    440
    541add_action('wp_ajax_rc_sm_top_url', function () {
     
    743    header('Content-Type: application/json');
    844
    9     // Security verification
    1045    if (!rc_sm_security_ajax_verify()) {
    1146        return;
     
    1752    $page    = max(1, rc_sm_security_ajax_get_int('pagination', 1));
    1853
    19     $allowed_orderby = ['url', 'post_id', 'control'];
     54    $allowed_orderby = ['url', 'post_id', 'term_id', 'control'];
    2055    $orderby = in_array($orderby, $allowed_orderby, true) ? $orderby : 'url';
    2156    $order   = in_array($order, ['ASC', 'DESC'], true) ? $order : 'ASC';
     
    2358    $per_page = RC_SM_PAGINATION_ORDER_OFFSET;
    2459    $offset   = ($page - 1) * $per_page;
    25 
    26     $table  = RC_SM_TABLE_CONTROL;
     60    $table    = RC_SM_TABLE_CONTROL;
    2761
    2862    if ($search) {
     
    3064    }
    3165
    32     // Count total results
    3366    if ($search) {
    3467        $count = (int) $wpdb->get_var(
     
    4982    $pages = (int) ceil($count / $per_page);
    5083
    51     // Retrieve paginated results
    5284    if ($search) {
    5385        $results = $wpdb->get_results(
     
    74106    if (!empty($results)) {
    75107        foreach ($results as $row) {
    76             $post_id = absint($row->post_id);
    77             $url     = untrailingslashit($row->url);
    78             $post    = get_post($post_id);
    79             if (!$post) continue;
    80 
    81             $type_label = get_post_type_object($post->post_type)->labels->singular_name ?? $post->post_type;
    82             $status_obj = get_post_status_object($post->post_status);
    83             $status     = $status_obj->label ?? $post->post_status;
    84 
    85             $status_html = $post->post_status === 'publish'
    86                 ? "<span class='rc_sm_bold rc_sm_color_success'>" . esc_html($status) . "</span>"
    87                 : "<span class='rc_sm_bold rc_sm_color_warning'>" . esc_html($status) . "</span>";
    88 
    89             // Retrieve data from WP Rocket table
     108
     109            $post_id = (int) $row->post_id;
     110            $term_id = (int) $row->term_id;
     111            $url      = untrailingslashit($row->url);
     112            $url_view = rc_sm_url_slash($url);
     113
     114            if ($post_id > 0) {
     115                // Post / page / CPT
     116                $post = get_post($post_id);
     117                if (!$post) continue;
     118                $type_label  = get_post_type_object($post->post_type)->labels->singular_name ?? $post->post_type;
     119                $type_slug   = $post->post_type;
     120                $status_obj  = get_post_status_object($post->post_status);
     121                $status      = $status_obj->label ?? $post->post_status;
     122                $status_html = $post->post_status === 'publish'
     123                    ? "<span class='rc_sm_bold rc_sm_color_success'>" . esc_html($status) . "</span>"
     124                    : "<span class='rc_sm_bold rc_sm_color_warning'>" . esc_html($status) . "</span>";
     125                $is_public   = $post->post_status === 'publish';
     126                $id_display  = $post_id;
     127
     128            } elseif ($term_id > 0) {
     129                // Term (category, tag, custom taxonomy)
     130                $term = get_term($term_id);
     131                if (!$term || is_wp_error($term)) continue;
     132                $taxonomy_obj = get_taxonomy($term->taxonomy);
     133                $type_label   = $taxonomy_obj->labels->singular_name ?? $term->taxonomy;
     134                $type_slug    = $term->taxonomy;
     135                $status_html  = "<span class='rc_sm_bold rc_sm_color_success'>" . esc_html__('Published', 'rc-site-manager-optimization') . "</span>";
     136                $is_public    = true;
     137                $id_display   = $term_id;
     138
     139            } else {
     140                // No ID found
     141                $type_label  = '';
     142                $type_slug   = '';
     143                $status_html = '';
     144                $is_public   = true;
     145                $id_display  = 0;
     146            }
     147
    90148            $rucss_table = $wpdb->prefix . 'wpr_rucss_used_css';
    91149            $rucss_rows  = $wpdb->get_results(
     
    96154            );
    97155
    98             $rucss_map = ['0' => '-', '1' => '-'];
     156            $rucss_map = ['0' => '', '1' => ''];
    99157            foreach ($rucss_rows as $r) {
    100158                $rucss_map[$r->is_mobile] = $r->status;
     
    104162                if ($status === 'completed') {
    105163                    return "<span class='rc_sm_bold rc_sm_color_success'>" . esc_html('completed') . "</span>";
    106                 } elseif ($status === '-') {
    107                     return "<span class='rc_sm_bold rc_sm_color_error'>-</span>";
     164                } elseif ($status === '') {
     165                    return '';
    108166                }
    109167                return "<span class='rc_sm_bold rc_sm_color_warning'>" . esc_html($status) . "</span>";
    110168            };
    111169
    112             // Retrieve last PageSpeed data
    113             $ps_html = rc_sm_pagespeed_performance_html($url);
    114 
    115             $url_view = rc_sm_url_slash($url);
     170            $ps_html    = rc_sm_pagespeed_performance_html($url);
     171            $id_display = $id_display > 0 ? esc_html($id_display) : '';
     172
    116173            echo "<tr>";
    117174            echo "<td class='rc_sm_table_column_hide'>" . esc_html($row->id) . "</td>";
    118             echo "<td>" . esc_html($post_id) . "</td>";
    119             echo "<td>" . ($post->post_status === 'publish'
     175            echo "<td>" . $id_display . "</td>";
     176            echo "<td>" . ($is_public
    120177                ? "<a href='" . esc_url($url_view) . "' target='_blank'>" . esc_html($url_view) . "</a>"
    121178                : esc_html($url_view)) . "</td>";
    122             echo "<td>" . esc_html($type_label) . " <code>(" . esc_html($post->post_type) . ")</code></td>";
    123             echo '<td>' . esc_html('ID: ') . esc_html($post_id) . '<br>' . esc_html(__('Status:', 'rc-site-manager-optimization')) . wp_kses_post(' ' . $status_html) . '</td>';
     179            echo "<td>" . ($type_label !== '' ? esc_html($type_label) . " <code>(" . esc_html($type_slug) . ")</code>" : '') . "</td>";
     180            $type_source = $post_id > 0 ? 'post_id' : ($term_id > 0 ? 'term_id' : '');
     181            echo '<td>'
     182                . ($id_display !== '' ? esc_html(__('ID:', 'rc-site-manager-optimization')) . ' ' . $id_display . '<br>' : '')
     183                . ($type_source !== '' ? esc_html(__('Type:', 'rc-site-manager-optimization')) . ' <code>' . esc_html($type_source) . '</code><br>' : '')
     184                . esc_html(__('Status:', 'rc-site-manager-optimization')) . wp_kses_post(' ' . $status_html)
     185                . '</td>';
    124186            echo '<td>' . esc_html('Desktop: ') . wp_kses_post($label($rucss_map[0])) . '<br>' . esc_html('Mobile: ') . wp_kses_post($label($rucss_map[1])) . '</td>';
    125187            echo '<td>' . wp_kses_post($ps_html) . '</td>';
     
    133195        }
    134196    }
    135     $html_rows = ob_get_clean();
     197    $html_rows  = ob_get_clean();
    136198    $pagination = rc_sm_pagination_render($page, $pages);
    137199
     
    153215    global $wpdb;
    154216
    155     // Nonce check
    156217    $nonce = rc_sm_security_ajax_get_param('rc_sm_url_add_nonce');
    157218
     
    160221    }
    161222
    162     // Retrieve and validate URL
    163223    $raw_url = rc_sm_security_ajax_get_param('rc_sm_url_new');
    164     $check = rc_sm_url_validate($raw_url);
     224    $check   = rc_sm_url_validate($raw_url);
    165225
    166226    if (!$check['valid']) {
     
    171231    $table     = RC_SM_TABLE_CONTROL;
    172232
    173     // Check for duplicates
    174233    $exists = $wpdb->get_var(
    175234        $wpdb->prepare(
     
    183242    }
    184243
    185     // Get post_id from URL
    186     $post_id = url_to_postid($clean_url);
    187 
    188     if (!$post_id) {
    189         // Fallback on GUID
    190         $post_id = $wpdb->get_var(
    191             $wpdb->prepare(
    192                 "SELECT ID FROM " . esc_sql($wpdb->posts) . " WHERE guid = %s LIMIT 1",
    193                 $clean_url
    194             )
    195         );
    196     }
    197 
    198     if (!$post_id) {
    199         return '<div class="rc_sm_notice_error">' . esc_html(__('No published content matches this URL.', 'rc-site-manager-optimization')) . '</div>';
    200     }
    201 
    202     // Insert record
     244    $ids = rc_sm_url_to_id($clean_url);
     245
    203246    $inserted = $wpdb->insert(
    204247        $table,
    205248        [
    206             'post_id' => $post_id,
     249            'post_id' => $ids['post_id'],
     250            'term_id' => $ids['term_id'],
    207251            'url'     => esc_url_raw($clean_url),
    208252            'action'  => 'top_url',
    209253        ],
    210         ['%d', '%s', '%s']
     254        ['%d', '%d', '%s', '%s']
    211255    );
    212256
     
    223267    global $wpdb;
    224268
    225     // Security verification
    226269    if (!rc_sm_security_ajax_verify()) {
    227270        return;
     
    236279    $table = RC_SM_TABLE_CONTROL;
    237280
    238     // Recupera URL prima di cancellare
    239281    $url = $wpdb->get_var(
    240282        $wpdb->prepare(
Note: See TracChangeset for help on using the changeset viewer.