| @@ -56,9 +56,9 @@ | ||
| 56 | 56 | $attachment_id = media_handle_sideload($file_array, 0); |
| 57 | 57 | |
| 58 | 58 | # Clean up the temp file |
| 59 | 59 | if (file_exists($tmp_file_path)) { |
| 60 | - @unlink($tmp_file_path); # Delete only the temp copy, not the original file | |
| 60 | + @wp_delete_file($tmp_file_path); # Delete only the temp copy, not the original file | |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | if (is_wp_error($attachment_id)) { |
| 64 | 64 | return ''; # Return empty if upload fails |
| @@ -104,18 +104,14 @@ | ||
| 104 | 104 | |
| 105 | 105 | # Check if the post already exists by title |
| 106 | 106 | global $wpdb; |
| 107 | 107 | |
| 108 | - # prepare query | |
| 109 | - $query = $wpdb->prepare( | |
| 108 | + # Get the Data (prepare query inline) | |
| 109 | + $existing_post = $wpdb->get_var($wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- maintenance of the plugin hidden OG post — direct status/content surgery keeps it invisible to WP_Query consumers | |
| 110 | 110 | "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND (post_type = 'post' OR post_type = 'metasync_post_type') LIMIT 1", |
| 111 | 111 | $this->post_title |
| 112 | - ); | |
| 112 | + )); | |
| 113 | 113 | |
| 114 | - | |
| 115 | - # Get the Data | |
| 116 | - $existing_post = $wpdb->get_var($query); | |
| 117 | - | |
| 118 | 114 | $this->get_image_url_Data(); |
| 119 | 115 | if ($existing_post) { |
| 120 | 116 | |
| 121 | 117 | #show post |
| @@ -170,9 +166,9 @@ | ||
| 170 | 166 | } |
| 171 | 167 | |
| 172 | 168 | # Flip to publish via direct DB write — bypasses transition_post_status |
| 173 | 169 | global $wpdb; |
| 174 | - $wpdb->update( | |
| 170 | + $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- maintenance of the plugin hidden OG post — direct status/content surgery keeps it invisible to WP_Query consumers | |
| 175 | 171 | $wpdb->posts, |
| 176 | 172 | ['post_status' => 'publish'], |
| 177 | 173 | ['ID' => $post_id] |
| 178 | 174 | ); |
| @@ -229,9 +225,9 @@ | ||
| 229 | 225 | private function check_and_fix_page_content($post_id) |
| 230 | 226 | { |
| 231 | 227 | # Switch to page type via direct DB write — bypasses transition_post_status |
| 232 | 228 | global $wpdb; |
| 233 | - $wpdb->update( | |
| 229 | + $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- maintenance of the plugin hidden OG post — direct status/content surgery keeps it invisible to WP_Query consumers | |
| 234 | 230 | $wpdb->posts, |
| 235 | 231 | [ |
| 236 | 232 | 'post_type' => 'page', |
| 237 | 233 | 'post_status' => 'publish', |
| @@ -278,9 +274,9 @@ | ||
| 278 | 274 | */ |
| 279 | 275 | private function check_and_fix_post_content($post_id,$post_type='post') |
| 280 | 276 | { |
| 281 | 277 | if (!class_exists('DOMDocument')) { |
| 282 | - error_log('MetaSync: skipping check_and_fix_post_content — DOMDocument (php-dom extension) is not available on this server.'); | |
| 278 | + error_log('MetaSync: skipping check_and_fix_post_content — DOMDocument (php-dom extension) is not available on this server.'); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- genuine failure path, bounded, no secrets | |
| 283 | 279 | return false; |
| 284 | 280 | } |
| 285 | 281 | |
| 286 | 282 | # Get the post title |
| @@ -409,22 +405,27 @@ | ||
| 409 | 405 | * @return array{body: string|false, status: int} |
| 410 | 406 | */ |
| 411 | 407 | protected function fetch_post_html($post_url) |
| 412 | 408 | { |
| 413 | - $ch = curl_init(); | |
| 414 | - curl_setopt($ch, CURLOPT_URL, $post_url); # Set the URL to fetch | |
| 415 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # Return the response as a string | |
| 416 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); # Follow redirects if any | |
| 417 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); # Bound connection establishment | |
| 418 | - curl_setopt($ch, CURLOPT_TIMEOUT, 15); # Bound the complete request | |
| 419 | - curl_setopt($ch, CURLOPT_MAXREDIRS, 5); # Bound redirect chains | |
| 420 | - $html = curl_exec($ch); # Execute the request and store the HTML response | |
| 421 | - $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); # Capture the HTTP status code | |
| 422 | - curl_close($ch); # Close the cURL session | |
| 409 | + $response = wp_remote_get( | |
| 410 | + $post_url, | |
| 411 | + [ | |
| 412 | + 'timeout' => 15, | |
| 413 | + 'redirection' => 5, | |
| 414 | + 'sslverify' => true, | |
| 415 | + ] | |
| 416 | + ); | |
| 423 | 417 | |
| 418 | + if (is_wp_error($response)) { | |
| 419 | + return [ | |
| 420 | + 'body' => false, | |
| 421 | + 'status' => 0, | |
| 422 | + ]; | |
| 423 | + } | |
| 424 | + | |
| 424 | 425 | return [ |
| 425 | - 'body' => $html, | |
| 426 | - 'status' => (int) $http_code, | |
| 426 | + 'body' => wp_remote_retrieve_body($response), | |
| 427 | + 'status' => (int) wp_remote_retrieve_response_code($response), | |
| 427 | 428 | ]; |
| 428 | 429 | } |
| 429 | 430 | |
| 430 | 431 | /** |
| @@ -435,9 +436,9 @@ | ||
| 435 | 436 | global $wpdb; |
| 436 | 437 | |
| 437 | 438 | # Single direct DB write for both type + status — bypasses |
| 438 | 439 | # transition_post_status so auto-share plugins never see this post |
| 439 | - $wpdb->update( | |
| 440 | + $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- maintenance of the plugin hidden OG post — direct status/content surgery keeps it invisible to WP_Query consumers | |
| 440 | 441 | $wpdb->posts, |
| 441 | 442 | [ |
| 442 | 443 | 'post_type' => 'post', |
| 443 | 444 | 'post_status' => 'publish', |
| @@ -454,9 +455,9 @@ | ||
| 454 | 455 | global $wpdb; |
| 455 | 456 | |
| 456 | 457 | # Single direct DB write — bypasses transition_post_status on the |
| 457 | 458 | # publish→draft transition (some plugins hook that direction too) |
| 458 | - $wpdb->update( | |
| 459 | + $wpdb->update( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- maintenance of the plugin hidden OG post — direct status/content surgery keeps it invisible to WP_Query consumers | |
| 459 | 460 | $wpdb->posts, |
| 460 | 461 | [ |
| 461 | 462 | 'post_status' => 'draft', |
| 462 | 463 | 'post_type' => 'metasync_post_type', |