Plugin Directory

Changeset 3358399


Ignore:
Timestamp:
09/09/2025 08:13:37 AM (6 months ago)
Author:
aryans
Message:
  • Refined Google Analytics Detection
  • Improved Content Security Policy.
  • Bug fixes.
Location:
site-suggest
Files:
32 added
6 edited

Legend:

Unmodified
Added
Removed
  • site-suggest/trunk/app/ajax-controller.php

    r3350957 r3358399  
    1616        function __construct()
    1717        {
    18             add_action('wp_ajax_stsgt_save_prev_log', array($this, 'save_prev_log'));
    19             add_action('wp_ajax_stsgt_run_audit', array($this, 'run_audit'));
    20             add_action('wp_ajax_stsgt_save_admin_settings', array($this, 'save_admin_settings'));
    21 
    22             add_action('wp_ajax_clear_stsgt_log_all', array($this, 'clear_stsgt_log_all_clbk'));
    23             add_action('wp_ajax_nopriv_clear_stsgt_log_all', array($this, 'clear_stsgt_log_all_clbk'));
    24 
    25             add_action('wp_ajax_remove_stsgt_log_item', array($this, 'remove_stsgt_log_item_clbk'));
    26             add_action('wp_ajax_nopriv_remove_stsgt_log_item', array($this, 'remove_stsgt_log_item_clbk'));
    27 
    28             add_action('wp_ajax_stsgt_delete_revisions', array($this, 'delete_revisions'));
    29             add_action('wp_ajax_nopriv_stsgt_delete_revisions', array($this, 'delete_revisions'));
    30 
    31             add_action('wp_ajax_stsgt_delete_drafts', array($this, 'delete_drafts'));
    32             add_action('wp_ajax_nopriv_stsgt_delete_drafts', array($this, 'delete_drafts'));
    33 
    34             add_action('wp_ajax_stsgt_delete_spam_comments', array($this, 'spam_comments'));
    35             add_action('wp_ajax_nopriv_stsgt_delete_spam_comments', array($this, 'spam_comments'));
    36 
    37             add_action('wp_ajax_stsgt_delete_trash_comments', array($this, 'trash_comments'));
    38             add_action('wp_ajax_nopriv_stsgt_delete_trash_comments', array($this, 'trash_comments'));
    39 
    40             add_action('wp_ajax_stsgt_delete_trash', array($this, 'delete_trash'));
    41             add_action('wp_ajax_nopriv_stsgt_delete_trash', array($this, 'delete_trash'));
    42 
    43             add_action('wp_ajax_stsgt_delete_transients', array($this, 'delete_transients'));
    44             add_action('wp_ajax_nopriv_stsgt_delete_transients', array($this, 'delete_transients'));
    45 
    46             add_action('wp_ajax_stsgt_export_images_csv', array($this, 'stsgt_export_images_csv_callback'));
    47             add_action('wp_ajax_nopriv_stsgt_export_images_csv', array($this, 'stsgt_export_images_csv_callback'));
    48 
    49             add_action('wp_ajax_stsgt_import_images_csv', array($this, 'stsgt_import_images_csv_callback'));
    50             add_action('wp_ajax_nopriv_stsgt_import_images_csv', array($this, 'stsgt_import_images_csv_callback'));
    51 
    52             add_action('wp_ajax_stsgt_run_audit_cron_observer', array($this, 'stsgt_run_audit_cron_observer_callback'));
    53             add_action('wp_ajax_nopriv_stsgt_run_audit_cron_observer', array($this, 'stsgt_run_audit_cron_observer_callback'));
    54             add_action('stsgt_every_min_cron', array($this, 'stsgt_audit_cron_observer'));
    55 
    56             add_action('wp_ajax_stsgt_save_fetched_audit_data', array($this, 'stsgt_save_fetched_audit_data_callback'));
    57             add_action('wp_ajax_nopriv_stsgt_save_fetched_audit_data', array($this, 'stsgt_save_fetched_audit_data_callback'));
    58 
    59             add_action('wp_ajax_stsgt_start_cron_run_audit', array($this, 'stsgt_start_cron_run_audit_callback'));
    60 
    61             add_action('wp_ajax_stsgt_approve_share_tech_data', array($this, 'approve_share_tech_data'));
    62 
    63             add_action('wp_ajax_stsgt_robots_txt_content', array($this, 'stsgt_robots_txt_content_clbk'));
    64 
    65             add_action('wp_ajax_stsgt_clear_404_logs', array($this, 'stsgt_clear_404_logs_callback'));
    66             add_action('wp_ajax_stsgt_update_banner_update', array($this, 'stsgt_update_banner_update_callback'));
    67 
     18            // Ajax Request Handlers
     19            add_action('wp_ajax_stsgt_save_prev_log', [$this, 'save_prev_log']);
     20            add_action('wp_ajax_stsgt_run_audit', [$this, 'run_audit']);
     21            add_action('wp_ajax_stsgt_save_admin_settings', [$this, 'save_admin_settings']);
     22            add_action('wp_ajax_clear_stsgt_log_all', [$this, 'clear_stsgt_log_all_clbk']);
     23            add_action('wp_ajax_remove_stsgt_log_item', [$this, 'remove_stsgt_log_item_clbk']);
     24            add_action('wp_ajax_stsgt_delete_revisions', [$this, 'delete_revisions']);
     25            add_action('wp_ajax_stsgt_delete_drafts', [$this, 'delete_drafts']);
     26            add_action('wp_ajax_stsgt_delete_spam_comments', [$this, 'spam_comments']);
     27            add_action('wp_ajax_stsgt_delete_trash_comments', [$this, 'trash_comments']);
     28            add_action('wp_ajax_stsgt_delete_trash', [$this, 'delete_trash']);
     29            add_action('wp_ajax_stsgt_delete_transients', [$this, 'delete_transients']);
     30            add_action('wp_ajax_stsgt_export_images_csv', [$this, 'stsgt_export_images_csv_callback']);
     31            add_action('wp_ajax_stsgt_import_images_csv', [$this, 'stsgt_import_images_csv_callback']);
     32            add_action('wp_ajax_stsgt_run_audit_cron_observer', [$this, 'stsgt_run_audit_cron_observer_callback']);
     33            add_action('wp_ajax_stsgt_save_fetched_audit_data', [$this, 'stsgt_save_fetched_audit_data_callback']);
     34            add_action('wp_ajax_stsgt_start_cron_run_audit', [$this, 'stsgt_start_cron_run_audit_callback']);
     35            add_action('wp_ajax_stsgt_approve_share_tech_data', [$this, 'approve_share_tech_data']);
     36            add_action('wp_ajax_stsgt_robots_txt_content', [$this, 'stsgt_robots_txt_content_clbk']);
     37            add_action('wp_ajax_stsgt_clear_404_logs', [$this, 'stsgt_clear_404_logs_callback']);
     38            add_action('wp_ajax_stsgt_update_banner_update', [$this, 'stsgt_update_banner_update_callback']);
    6839            add_action('wp_ajax_reset_scanning_process', [$this, 'stsgt_reset_scanning_process']);
    69 
    7040            add_action('wp_ajax_stsgt_cron_checker', [$this, 'stsgt_cron_checker_clbk']);
    71 
    7241            add_action('wp_ajax_stsgt_dismiss_admin_notice', [$this, 'stsgt_dismiss_admin_notice_clbk']);
    73 
    7442            add_action('wp_ajax_stsgt_send_bug_report', [$this, 'report_request']);
    75             add_action('wp_ajax_nopriv_stsgt_send_bug_report', [$this, 'report_request']);
     43
     44            // Cron Handler
     45            add_action('stsgt_every_min_cron', [$this, 'stsgt_audit_cron_observer']);
     46        }
     47
     48        /**
     49         *  Validate User Capabilities
     50         * @return bool
     51         */
     52        private function is_valid_request(){
     53            if (current_user_can('administrator')) {
     54                return true;
     55            }
     56            return false;
     57        }
     58
     59        /**
     60         * Send Invalid Response
     61         * @return void
     62         */
     63        private function invalid_request(){
     64            wp_send_json(['status' => 400, 'message' => 'Invalid Request!']);
    7665        }
    7766
    7867        public function stsgt_dismiss_admin_notice_clbk()
    7968        {
     69            if(!$this->is_valid_request()){
     70                $this->invalid_request();
     71            }
     72
    8073            if (isset($_POST['_']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_'])), 'stsgt_nonce')) {
    8174                update_option('stsgt_cron_scanning_complete', []);
     
    9083        public function stsgt_cron_checker_clbk()
    9184        {
     85            if(!$this->is_valid_request()){
     86                $this->invalid_request();
     87            }
     88
    9289            if (isset($_POST['_']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_'])), 'stsgt_nonce')) {
    9390                $is_cron = get_option('stsgt_real_cron_obsv_started');
     
    121118        public function stsgt_reset_scanning_process()
    122119        {
     120            if(!$this->is_valid_request()){
     121                $this->invalid_request();
     122            }
     123
    123124            $resp = [];
    124125            if (isset($_POST['_']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_'])), 'stsgt_nonce')) {
     
    149150        public function stsgt_update_banner_update_callback()
    150151        {
     152            if(!$this->is_valid_request()){
     153                $this->invalid_request();
     154            }
     155
    151156            $resp = [];
    152157
     
    168173        public function stsgt_clear_404_logs_callback()
    169174        {
     175            if(!$this->is_valid_request()){
     176                $this->invalid_request();
     177            }
     178
    170179            $resp = [];
    171180            if (isset($_POST['_']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_'])), 'stsgt_nonce')) {
     
    198207                ob_start();
    199208                $is_404_page = true;
    200                 $_404_monitor_tab_keys =  ['_404_error_monitor'];
    201                 $new_site_info_data =  [];
     209                $_404_monitor_tab_keys = ['_404_error_monitor'];
     210                $new_site_info_data = [];
    202211                foreach ($_404_monitor_tab_keys as $_404_monitor_tab_item) {
    203212                    $new_site_info_data[$_404_monitor_tab_item] = $prev_opt_data[$_404_monitor_tab_item] ?? '';
     
    216225        private function read_file($path)
    217226        {
    218             if (! function_exists('request_filesystem_credentials')) {
     227            if (!function_exists('request_filesystem_credentials')) {
    219228                require_once ABSPATH . 'wp-admin/includes/file.php';
    220229            }
     
    232241        private function overwrite_file($path, $data)
    233242        {
    234             if (! function_exists('request_filesystem_credentials')) {
     243            if (!function_exists('request_filesystem_credentials')) {
    235244                require_once ABSPATH . 'wp-admin/includes/file.php';
    236245            }
     
    245254        public function stsgt_robots_txt_content_clbk()
    246255        {
     256            if(!$this->is_valid_request()){
     257                $this->invalid_request();
     258            }
     259
    247260            $resp = [];
    248261            if (isset($_POST['_']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_'])), 'stsgt_nonce')) {
     
    270283        public function save_prev_log()
    271284        {
     285            if(!$this->is_valid_request()){
     286                $this->invalid_request();
     287            }
     288
    272289            if (isset($_POST['_']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_'])), 'stsgt_nonce')) {
    273290                $stsgt_site_speed_data = get_option('stsgt_site_speed_data');
     
    292309        public function approve_share_tech_data()
    293310        {
     311            if(!$this->is_valid_request()){
     312                $this->invalid_request();
     313            }
     314
    294315            if (isset($_POST['_']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_'])), 'stsgt_nonce')) {
    295316                $status = isset($_POST['sts']) ? sanitize_text_field(wp_unslash($_POST['sts'])) : 'no';
     
    310331        public function stsgt_start_cron_run_audit_callback()
    311332        {
     333            if(!$this->is_valid_request()){
     334                $this->invalid_request();
     335            }
     336
    312337            if (isset($_POST['_']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_'])), 'stsgt_nonce')) {
    313338                $checklist = isset($_POST['checklist']) ? json_decode(base64_decode(sanitize_text_field(wp_unslash($_POST['checklist']))), true) : [];
     
    349374                require_once ABSPATH . 'wp-admin/includes/file.php';
    350375                $credentials = request_filesystem_credentials('', '', false, false, null);
    351                 if (! WP_Filesystem($credentials)) {
     376                if (!WP_Filesystem($credentials)) {
    352377                    return false;
    353378                }
     
    358383        public function stsgt_save_fetched_audit_data_callback()
    359384        {
     385            if(!$this->is_valid_request()){
     386                $this->invalid_request();
     387            }
     388
    360389            if (wp_verify_nonce(sanitize_text_field(wp_unslash((isset($_POST['nonce']) ? $_POST['nonce'] : ''))), 'stsgt_nonce')) {
    361390                $stsgt_site_speed_data = get_option('stsgt_site_speed_data') ?: [];
     
    569598                            $link = $hom_link . $link;
    570599                        }
    571                        
     600
    572601                        add_filter('http_request_timeout', function ($time, $url) {
    573602                            $time = 60;
     
    592621        public function remove_stsgt_log_item_clbk()
    593622        {
     623            if(!$this->is_valid_request()){
     624                $this->invalid_request();
     625            }
     626
    594627            if (isset($_POST['_']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_'])), 'stsgt_nonce')) {
    595628                $post_id = isset($_POST['post_id']) ? sanitize_text_field(wp_unslash($_POST['post_id'])) : 0;
     
    606639        public function clear_stsgt_log_all_clbk()
    607640        {
     641            if(!$this->is_valid_request()){
     642                $this->invalid_request();
     643            }
     644
    608645            if (isset($_POST['_']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_'])), 'stsgt_nonce')) {
    609646                $res = [];
    610647                $stsgt_args = array(
    611                     'post_type'      => 'stsgt-log',
     648                    'post_type' => 'stsgt-log',
    612649                    'posts_per_page' => -1,
    613                     'post_status'    => 'any',
     650                    'post_status' => 'any',
    614651                );
    615652
     
    730767
    731768
     769        private function get_schema_json($url){
     770            $resp = false;
     771            $url = 'https://validator.schema.org/validate?url=' . urlencode($url);
     772
     773            $response = wp_remote_post( $url, array(
     774                'headers' => array(
     775                    'Content-Length' => '0',
     776                ),
     777                'timeout' => 30, // you can adjust like CURLOPT_TIMEOUT
     778                'redirection' => 10, // like CURLOPT_MAXREDIRS
     779            ) );
     780
     781            if ( is_wp_error( $response ) ) {
     782                $error_message = $response->get_error_message();
     783            } else {
     784                $resp = wp_remote_retrieve_body( $response );
     785            }
     786            return $resp;
     787        }
     788
     789        private function get_schema_warnings($jsonString){
     790            $data = json_decode($jsonString, true);
     791
     792            $results = [
     793                'errors' => [],
     794                'warnings' => []
     795            ];
     796
     797            // Recursive scanner
     798            $scan = function($node) use (&$scan, &$results) {
     799                if (isset($node['errors']) && is_array($node['errors'])) {
     800                    foreach ($node['errors'] as $error) {
     801                        $severity = $error['ownerToSeverity']['SPORE'] ?? '';
     802                        $item = [
     803                            'type' => $error['errorType'] ?? '',
     804                            'args' => $error['args'] ?? [],
     805                            'severity' => $severity,
     806                            'isSevere' => $error['isSevere'] ?? false,
     807                            'begin' => $error['begin'] ?? null,
     808                            'end' => $error['end'] ?? null,
     809                        ];
     810                        if ($severity === 'ERROR') {
     811                            $results['errors'][] = $item;
     812                        } else {
     813                            $results['warnings'][] = $item;
     814                        }
     815                    }
     816                }
     817                if(is_array($node)){
     818                    foreach ($node as $child) {
     819                        if (is_array($child)) {
     820                            $scan($child);
     821                        }
     822                    }
     823                }
     824            };
     825
     826            $scan($data);
     827
     828            return $results;
     829        }
    732830
    733831        /**
     
    736834        public function schema_markup_check($html_content, $post_id)
    737835        {
     836            $warnings = [];
     837            $errors = [];
    738838            $checked_schema_markups = get_option('stsgt_checked_schema_markups', []);
    739839
    740840            $this_post = get_post($post_id);
    741841            $this_post_type = $this_post->post_type;
    742 
    743             preg_match_all('/<script[^>]*type=["\']application\/ld\+json["\'][^>]*>(.*?)<\/script>/is', $html_content, $matches);
    744             $json_ld_blocks = $matches[1];
    745             $json_ld_blocks = isset($json_ld_blocks[0]) ? json_decode($json_ld_blocks[0], true) : [];
    746 
    747             if (!in_array($this_post_type, $checked_schema_markups)) {
    748                 $ld_schemas_arr = $this->check_nested_schmark($json_ld_blocks);
    749                 $ld_schemas = $ld_schemas_arr[0];
    750                 $page_title = $ld_schemas_arr[1];
    751                 $un_ld_schemas = $ld_schemas_arr[2];
    752                 if ($this_post_type != "page") {
    753                     $checked_schema_markups[] = $this_post_type;
    754                 }
    755                 update_option('stsgt_checked_schema_markups', $checked_schema_markups);
    756                 $ld_schemas = array_intersect(array_unique($ld_schemas), $this->recognized_schema_types);
    757                 $final_out = '<strong>Recognized schemas</strong>: ' . implode(', ', $ld_schemas);
    758 
    759                 if (!empty($un_ld_schemas)) {
    760                     $final_out .= '<br><strong>Unrecognized schemas</strong>: ' . implode(', ', $un_ld_schemas);
    761                 }
    762                 return [$page_title => $final_out];
    763             }
    764 
    765             return null;
     842            $this_post_link = get_the_permalink($this_post->ID);
     843
     844            $this_json = $this->get_schema_json($this_post_link);
     845            $this_result = $this->get_schema_warnings($this_json);
     846
     847            $warnings = $this_result['warnings'];
     848            $errors = $this_result['errors'];
     849
     850            $warning_string = '';
     851            $errors_string = '';
     852            if(!empty(($warnings))){
     853                foreach($warnings as $warnings_key => $warnings_value){
     854                    $warning_string .= $warnings_value['type'].' - '.implode(', ', $warnings_value['args']);
     855                }
     856            }
     857            if(!empty(($errors))){
     858                foreach($errors as $errors_key => $errors_value){
     859                    $errors_string .= $errors_value['type'].' - '.implode(', ', $errors_value['args']);
     860                }
     861            }
     862
     863            $this_return = ['<strong>Warnings</strong>:- '.$warning_string.' <br> '.' <strong>Errors</strong>:- '.$errors_string];
     864           
     865            return $this_return;
    766866        }
    767867
     
    866966                        if (!empty($stsgt_site_speed_data) && isset($stsgt_site_speed_data[$key])) {
    867967                            if (is_array($stsgt_site_speed_data[$key])) {
    868                                 $stsgt_site_speed_data[$key] = array_merge($stsgt_site_speed_data[$key], $new_audit_item);
     968                                if(is_array($new_audit_item)){
     969                                    $stsgt_site_speed_data[$key] = array_merge($stsgt_site_speed_data[$key], $new_audit_item);
     970                                }else{
     971                                    $stsgt_site_speed_data[$key] = $new_audit_item;
     972                                }
    869973                            } else {
    870974                                $stsgt_site_speed_data[$key] = $new_audit_item;
     
    892996        public function stsgt_run_audit_cron_observer_callback()
    893997        {
     998            if(!$this->is_valid_request()){
     999                $this->invalid_request();
     1000            }
     1001
    8941002            // sleep(1);
    8951003            if (wp_verify_nonce(sanitize_text_field(wp_unslash((isset($_POST['nonce']) ? $_POST['nonce'] : ''))), 'stsgt_audt_nonce')) {
     
    9741082        public function stsgt_export_images_csv_callback()
    9751083        {
     1084            if(!$this->is_valid_request()){
     1085                $this->invalid_request();
     1086            }
     1087
    9761088            global $wp_filesystem;
    9771089
    9781090            // Initialize WP Filesystem
    979             if (! function_exists('WP_Filesystem')) {
     1091            if (!function_exists('WP_Filesystem')) {
    9801092                require_once ABSPATH . 'wp-admin/includes/file.php';
    9811093            }
     
    9831095
    9841096            $args = array(
    985                 'post_type'      => 'attachment',
    986                 'post_status'    => 'inherit',
     1097                'post_type' => 'attachment',
     1098                'post_status' => 'inherit',
    9871099                'posts_per_page' => -1
    9881100            );
     
    9981110                    $attachment_id = get_the_ID();
    9991111                    $attachment_guid = get_the_guid();
    1000                     $url_separator  = '/wp-content/';
     1112                    $url_separator = '/wp-content/';
    10011113                    $url_prefix = get_site_url();
    10021114                    $attachment_guid_arr = explode($url_separator, $attachment_guid);
     
    10611173        public function stsgt_import_images_csv_callback()
    10621174        {
     1175            if(!$this->is_valid_request()){
     1176                $this->invalid_request();
     1177            }
     1178
    10631179            if (wp_verify_nonce((isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : ''), 'stsgt_nonce')) {
    10641180                global $wp_filesystem;
     
    11081224                            foreach ($csv_data as $csv_data_item) {
    11091225                                $attachment_name = $csv_data_item['URL'];
    1110                                 $url_separator  = '/wp-content/';
     1226                                $url_separator = '/wp-content/';
    11111227                                $attachment_guid_arr = explode($url_separator, $attachment_name);
    11121228                                $attachment_name = isset($attachment_guid_arr[1]) ? $url_separator . $attachment_guid_arr[1] : '';
     
    11611277        public function run_audit()
    11621278        {
     1279            if(!$this->is_valid_request()){
     1280                $this->invalid_request();
     1281            }
     1282
    11631283            if (wp_verify_nonce((isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : ''), 'stsgt_nonce')) {
    11641284                $check_name = isset($_POST['check_name']) ? sanitize_text_field(wp_unslash($_POST['check_name'])) : '';
    11651285                $audit_type = isset($_POST['audit_type']) ? sanitize_text_field(wp_unslash($_POST['audit_type'])) : '';
    11661286
    1167                 $cron_observers = ['HTTP_links_found', 'broken_links_detected_[Beta]', 'Large_image_check', 'H1_tag_check', 'Form_Check[experimental]']; //, 'reCaptcha_enabled'];
     1287                $cron_observers = ['HTTP_links_found', 'broken_links_detected_[Beta]', 'Large_image_check', 'H1_tag_check', 'Form_Check[experimental]', 'schema_markup_check']; //, 'reCaptcha_enabled'];
    11681288                $current_cron_observers = get_option('stsgt_cron_observers', []);
    11691289
     
    12101330                    endswitch;
    12111331
    1212                     $new_site_info_data =  [];
     1332                    $new_site_info_data = [];
    12131333                    foreach ($new_tab_keys as $new_tab_item) {
    12141334                        $new_site_info_data[$new_tab_item] = $wp_site_info[$new_tab_item] ?? '';
     
    12561376        public function save_admin_settings()
    12571377        {
     1378            if(!$this->is_valid_request()){
     1379                $this->invalid_request();
     1380            }
     1381
    12581382            if (wp_verify_nonce((isset($_POST['stsgt_settings_data_nonce']) ? sanitize_text_field(wp_unslash($_POST['stsgt_settings_data_nonce'])) : ''), 'stsgt_settings_field')) {
    12591383                $resp = array('status' => 200, 'message' => esc_html__('Connection working', 'site-suggest'));
     
    12641388
    12651389                $data = array(
    1266                     'stsgt_api_share_diagnostic_data'  => $stsgt_api_share_diagnostic_data,
    1267                     'stsgt_api_delete_plugin_data'     => $stsgt_api_delete_plugin_data,
    1268                     'stsgt_api_disable_safari_zoom'  => $stsgt_api_disable_safari_zoom,
     1390                    'stsgt_api_share_diagnostic_data' => $stsgt_api_share_diagnostic_data,
     1391                    'stsgt_api_delete_plugin_data' => $stsgt_api_delete_plugin_data,
     1392                    'stsgt_api_disable_safari_zoom' => $stsgt_api_disable_safari_zoom,
    12691393                );
    12701394
     
    12801404        public function deleteRevisions()
    12811405        {
     1406            if(!$this->is_valid_request()){
     1407                $this->invalid_request();
     1408            }
     1409
    12821410            $args = [
    1283                 'post_type'      => 'revision',
    1284                 'post_status'    => 'any',
     1411                'post_type' => 'revision',
     1412                'post_status' => 'any',
    12851413                'posts_per_page' => -1, // Get all revisions
    1286                 'fields'         => 'ids', // Only fetch IDs (better performance)
     1414                'fields' => 'ids', // Only fetch IDs (better performance)
    12871415            ];
    12881416
     
    13051433        public function delete_revisions()
    13061434        {
     1435            if(!$this->is_valid_request()){
     1436                $this->invalid_request();
     1437            }
     1438
    13071439            $stsgt_site_speed_data = get_option('stsgt_site_speed_data') ?: [];
    13081440
     
    13231455        public function delete_draft_posts()
    13241456        {
     1457            if(!$this->is_valid_request()){
     1458                $this->invalid_request();
     1459            }
     1460
    13251461            $args = [
    13261462                'post_type' => $post_types = get_post_types([], 'names'),
    1327                 'post_status'    => 'draft',
     1463                'post_status' => 'draft',
    13281464                'posts_per_page' => -1, // Get all draft posts
    1329                 'fields'         => 'ids', // Fetch only post IDs (optimized)
     1465                'fields' => 'ids', // Fetch only post IDs (optimized)
    13301466            ];
    13311467
     
    13491485        public function delete_drafts()
    13501486        {
     1487            if(!$this->is_valid_request()){
     1488                $this->invalid_request();
     1489            }
     1490
    13511491            $stsgt_site_speed_data = get_option('stsgt_site_speed_data') ?: [];
    13521492
     
    13671507        public function delete_spam_comments()
    13681508        {
     1509            if(!$this->is_valid_request()){
     1510                $this->invalid_request();
     1511            }
     1512
    13691513            $spam_comments = get_comments([
    13701514                'status' => 'spam',
     
    14061550        public function delete_trashed_posts()
    14071551        {
     1552            if(!$this->is_valid_request()){
     1553                $this->invalid_request();
     1554            }
     1555
    14081556            $args = [
    14091557                'post_type' => get_post_types(['public' => true], 'names'),
    1410                 'post_status'    => 'trash',
     1558                'post_status' => 'trash',
    14111559                'posts_per_page' => -1, // Get all trashed posts
    1412                 'fields'         => 'ids', // Only get post IDs (better performance)
     1560                'fields' => 'ids', // Only get post IDs (better performance)
    14131561            ];
    14141562
     
    14551603        public function delete_transients()
    14561604        {
     1605            if(!$this->is_valid_request()){
     1606                $this->invalid_request();
     1607            }
    14571608
    14581609            $stsgt_site_speed_data = get_option('stsgt_site_speed_data') ?: [];
     
    15031654        {
    15041655            $trashed_comments = get_comments([
    1505                 'status'  => 'trash',
    1506                 'fields'  => 'ids', // Only get IDs for better performance
     1656                'status' => 'trash',
     1657                'fields' => 'ids', // Only get IDs for better performance
    15071658            ]);
    15081659
     
    15241675        public function trash_comments()
    15251676        {
     1677            if(!$this->is_valid_request()){
     1678                $this->invalid_request();
     1679            }
     1680
    15261681            $stsgt_site_speed_data = get_option('stsgt_site_speed_data') ?: [];
    15271682
     
    15391694            exit();
    15401695        }
    1541        
     1696
    15421697
    15431698        public function report_request()
    15441699        {
     1700            if(!$this->is_valid_request()){
     1701                $this->invalid_request();
     1702            }
     1703           
    15451704            if (isset($_POST['_']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_'])), 'stsgt_nonce')) {
    15461705                $data_for = isset($_POST['data_for']) ? sanitize_text_field(wp_unslash($_POST['data_for'])) : '';
     
    15701729                    ]);
    15711730                }
    1572             }else{
     1731            } else {
    15731732                wp_send_json_error([
    15741733                    'message' => 'Invalid Nonce.',
  • site-suggest/trunk/app/info-controller.php

    r3350957 r3358399  
    509509                return 1024; // 1 GB
    510510            }
    511             return $suggested_limit;
     511            return 256;//$suggested_limit;
    512512        }
    513513
     
    542542            $peak_memory_text = 'Peak Usage - ' . $real_peak_used_memory . 'M';
    543543            $sgst_limit = '';
    544             $sgst_limit = $current_mb . 'M - Suggested memory limit ' . $recommended . 'M.'; // . $peak_memory_text;
     544            $sgst_limit = 'WP_MEMORY_LIMIT ('.$current_mb . 'M) - Suggested memory limit ' . $recommended . 'M.';
     545            $sgst_limit .= '<br>WP_MAX_MEMORY_LIMIT (256M) - Suggested memory limit 512M.';
    545546            return $sgst_limit;
    546547        }
     
    973974        public function schema_markup_check()
    974975        {
     976            return '';
    975977            preg_match_all('/<script[^>]*type=["\']application\/ld\+json["\'][^>]*>(.*?)<\/script>/is', $this->html, $matches);
    976978            $json_ld_blocks = $matches[1];
     
    16991701                    $resp_arr = get_option('stsgt_analytics_data', []);
    17001702                }
    1701                 if ($resp_arr) {
     1703                if (empty($resp_arr)) {
    17021704                    $remote_data = wp_remote_get('https://c.sitesuggest.io/?url=' . get_site_url(), ['timeout' => 60]);
    17031705                    if (!is_wp_error($remote_data)) {
  • site-suggest/trunk/app/main-controller.php

    r3350957 r3358399  
    2222
    2323      // Required static files
     24      add_filter('script_loader_tag', array($this, 'add_sri_attributes'), 10, 3);
    2425      add_action('admin_enqueue_scripts', array($this, 'stsgt_enqueue_scripts'));
    2526      add_action('admin_enqueue_scripts', array($this, 'head_snippet'));
     
    3940      add_action('init', [$this, 'terminate_page_for_www']);
    4041    }
     42
     43    private function get_sri_hash($handle, $src)
     44    {
     45      $cache_key = 'sri_hash_' . md5($src);
     46      $hash = get_transient($cache_key);
     47
     48      if (!$hash) {
     49        $response = wp_remote_get($src);
     50        if (!is_wp_error($response)) {
     51          $body = wp_remote_retrieve_body($response);
     52          if ($body) {
     53            $rawHash = base64_encode(hash('sha384', $body, true));
     54            $hash = 'sha384-' . $rawHash;
     55            set_transient($cache_key, $hash, WEEK_IN_SECONDS); // cache for a week
     56          }
     57        }
     58      }
     59      return $hash;
     60    }
     61
     62    public function add_sri_attributes($html, $handle, $src)
     63    {
     64      if (strpos($handle, 'stsgt-') !== false) {
     65        $hash = $this->get_sri_hash($handle, $src);
     66        $html = str_replace('></script>', ' integrity="' . esc_attr($hash) . '" crossorigin="anonymous"></script>', $html);
     67      }
     68      return $html;
     69    }
     70
    4171
    4272    public function terminate_page_for_www()
  • site-suggest/trunk/readme.txt

    r3350957 r3358399  
    44Tested up to:      6.8
    55Requires PHP:      7.2
    6 Stable tag:        1.2.9
     6Stable tag:        1.3.0
    77License:           GPLv2 or later
    88License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     
    151151== Changelog ==
    152152
     153= 1.3.0 - 2025-09-09 =
     154* Refined Google Analytics Detection
     155* Improved Content Security Policy.
     156* Bug fixes.
     157
     158= 1.2.9 - 2025-09-02 =
     159* Improved Security and Access Control.
     160* Bug fixes.
     161
    153162= 1.2.9 - 2025-08-27 =
    154163* Added report feature (Users can report issues to plugin author).
  • site-suggest/trunk/site-suggest.php

    r3350957 r3358399  
    66 * Author: Blurr Studio
    77 * Author URI: https://blurr.it/
    8  * Version: 1.2.9
     8 * Version: 1.3.0
    99 * License: GPL v2 or later
    1010 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    3636            define('stsgt_URL', plugin_dir_url(__FILE__));
    3737            define('stsgt_SLUG', 'site-suggest');
    38             define('stsgt_VERSION', '1.2.9');
     38            define('stsgt_VERSION', '1.3.0');
    3939        }
    4040
  • site-suggest/trunk/views/admin-parts/admin-site-info.php

    r3350957 r3358399  
    422422                    if (!is_numeric($title)) {
    423423                    ?>
    424                         <div class="title_wrap asd <?php echo esc_html($has_progress); ?>" data_total="<?php echo esc_html($cron_total_progress); ?>" data_current="<?php echo esc_html($cron_progress); ?>" data_item="<?php echo esc_html($title); ?>" style="--stsgt_cron_progress: <?php echo esc_html($cron_progress_perc); ?>%;">
     424                        <div class="title_wrap <?php echo esc_html($has_progress); ?>" data_total="<?php echo esc_html($cron_total_progress); ?>" data_current="<?php echo esc_html($cron_progress); ?>" data_item="<?php echo esc_html($title); ?>" style="--stsgt_cron_progress: <?php echo esc_html($cron_progress_perc); ?>%;">
    425425                            <?php
    426426                            if ($has_progress != '') {
     
    510510        ?>
    511511            <li stsgt_check_name="<?php echo esc_attr($title, 'site-suggest') ?>">
    512                 <div class="title_wrap rweee<?php echo esc_html($has_progress); ?>" data_total="<?php echo esc_html($cron_total_progress); ?>" data_current="<?php echo esc_html($cron_progress); ?>" data_item="<?php echo esc_html($title); ?>" style="--stsgt_cron_progress: <?php echo esc_html($cron_progress_perc); ?>%;">
     512                <div class="title_wrap <?php echo esc_html($has_progress); ?>" data_total="<?php echo esc_html($cron_total_progress); ?>" data_current="<?php echo esc_html($cron_progress); ?>" data_item="<?php echo esc_html($title); ?>" style="--stsgt_cron_progress: <?php echo esc_html($cron_progress_perc); ?>%;">
    513513                    <?php
    514514                    if ($has_progress != '') {
Note: See TracChangeset for help on using the changeset viewer.