// ============================================ // أكواد الإصلاح لمشاكل Functions.php // ============================================ // ✅ الإصلاح #1: SQL Injection (سطر 4714) // ❌ الكود الخاطئ: // $c_id = $wpdb->get_results("SELECT meta_value FROM $wpdb->commentmeta WHERE (meta_key = 'phone' AND comment_id = '". $comment_id ."')"); // ✅ الكود الصحيح: function safe_get_comment_phone_meta( $comment_id ) { global $wpdb; return $wpdb->get_results( $wpdb->prepare( "SELECT meta_value FROM $wpdb->commentmeta WHERE meta_key = 'phone' AND comment_id = %d", intval( $comment_id ) )); } // ============================================ // ✅ الإصلاح #2: معالجة $_GET آمنة (سطر 131) // ❌ الكود الخاطئ: // self::$is_rtl = ( self::option( 'rtl' ) || is_rtl() || isset( $_GET['rtl'] ) ); // ✅ الكود الصحيح: public function wp() { self::$preview = is_customize_preview(); // التحقق الآمن من معامل RTL $rtl_param = isset($_GET['rtl']) ? sanitize_key($_GET['rtl']) : ''; self::$is_rtl = ( self::option( 'rtl' ) || is_rtl() || !empty($rtl_param) ); } // ============================================ // ✅ الإصلاح #3: مشكلة Caching المتغيرات الثابتة // ❌ الكود الخاطئ (لا يأخذ في الاعتبار معرف المنشور): // if ( ! self::$meta ) { // self::$meta = apply_filters( 'codevz/page/meta', get_post_meta( $id, 'codevz_page_meta', true ), $id ); // } // ✅ الكود الصحيح: public static function meta( $id = null, $key = null, $default = '' ) { global $post; // معرف المنشور if ( ! $id && isset( $post->ID ) ) { $id = $post->ID; } // إضافة معرف المنشور إلى Cache key $cache_key = 'codevz_meta_' . $id; // استخدام transient بدلاً من متغير ثابت if ( ! isset( self::$meta[ $cache_key ] ) ) { $meta = wp_cache_get( $cache_key, 'codevz' ); if ( false === $meta ) { $meta = apply_filters( 'codevz/page/meta', get_post_meta( $id, 'codevz_page_meta', true ), $id ); wp_cache_set( $cache_key, $meta, 'codevz', 3600 ); // cache لمدة ساعة } self::$meta[ $cache_key ] = $meta; } $meta = self::$meta[ $cache_key ]; if ( $key ) { return empty( $meta[ $key ] ) ? $default : $meta[ $key ]; } else { return ( $id && $meta ) ? $meta : $default; } } // ============================================ // ✅ الإصلاح #4: معالجة آمنة لـ rename() (سطور 239، 259) // ❌ الكود الخاطئ: // rename( $dir . '/woocommerce.php', $dir . '/woocommerce-template.php' ); // ✅ الكود الصحيح: function safe_rename_woo_file( $dir, $old_name, $new_name ) { $old_path = trailingslashit( $dir ) . $old_name; $new_path = trailingslashit( $dir ) . $new_name; if ( ! file_exists( $old_path ) ) { return false; } if ( file_exists( $new_path ) ) { return false; // الملف الجديد موجود بالفعل } if ( ! @rename( $old_path, $new_path ) ) { error_log( 'Failed to rename ' . $old_name . ' to ' . $new_name ); return false; } return true; } // الاستخدام: // if ( is_dir( $dir . '/woocommerce' ) && file_exists( $dir . '/woocommerce.php' ) ) { // safe_rename_woo_file( $dir, 'woocommerce.php', 'woocommerce-template.php' ); // } // ============================================ // ✅ الإصلاح #5: جدولة الأحداث بشكل آمن (سطور 4800-4802) // ❌ الكود الخاطئ (موضوع في كل صفحة): // if ( ! wp_next_scheduled( 'check_iso_certificate_expiry' ) ) { // wp_schedule_event( time(), 'daily', 'check_iso_certificate_expiry' ); // } // ✅ الكود الصحيح: add_action( 'wp_loaded', function() { if ( ! wp_next_scheduled( 'check_iso_certificate_expiry' ) ) { wp_schedule_event( time(), 'daily', 'check_iso_certificate_expiry' ); } }, 20 ); // إضافة deactivation hook لإزالة الجدول عند تعطيل الـ theme: register_theme_deactivation_hook( __FILE__, function() { $timestamp = wp_next_scheduled( 'check_iso_certificate_expiry' ); if ( $timestamp ) { wp_unschedule_event( $timestamp, 'check_iso_certificate_expiry' ); } }); // ============================================ // ✅ الإصلاح #6: رسائل بريد آمنة مع HTML headers // ❌ الكود الخاطئ: // wp_mail( $email, $subject, $message ); // ✅ الكود الصحيح: function send_iso_alert_email( $email1, $email2, $subject, $message ) { $emails = array_filter( [ $email1, $email2 ] ); if ( empty( $emails ) ) { return false; } $headers = array( 'Content-Type: text/html; charset=UTF-8' ); $subject = sanitize_text_field( $subject ); $message = wp_kses_post( $message ); // تنظيف الـ HTML $sent = false; foreach ( $emails as $email ) { $email = sanitize_email( $email ); if ( is_email( $email ) ) { if ( wp_mail( $email, $subject, $message, $headers ) ) { $sent = true; } } } return $sent; } // ============================================ // ✅ الإصلاح #7: AJAX مع Nonce verification // ❌ الكود الخاطئ: // add_action( 'wp_ajax_codevz_ajax_post_views', [ $this, 'post_views' ] ); // add_action( 'wp_ajax_nopriv_codevz_ajax_post_views', [ $this, 'post_views' ] ); // ✅ الكود الصحيح: // في دالة wp_enqueue_scripts: wp_localize_script( 'codevz', 'codevz_ajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'codevz_ajax_nonce' ), )); // في دالة post_views: public function post_views() { check_ajax_referer( 'codevz_ajax_nonce', 'security' ); if ( ! isset( $_POST['post_id'] ) ) { wp_send_json_error( 'Missing post ID' ); } $post_id = intval( $_POST['post_id'] ); // باقي الكود... wp_send_json_success( $data ); } // ============================================ // ✅ الإصلاح #8: معالجة البيانات الفارغة بشكل صحيح // ❌ الكود الخاطئ: // if ( ! $email_1 && ! $email_2 ) continue; // ✅ الكود الصحيح: if ( ! trim($email_1) && ! trim($email_2) ) { continue; // تخطي إذا كانت البيانات فارغة أو whitespace فقط } // ============================================ // ✅ الإصلاح #9: معالجة آمنة للتواريخ // ❌ الكود الخاطئ: // if ($days_diff === $day) { // === قد تفشل مع أنواع بيانات مختلفة // ✅ الكود الصحيح: if ( (int)$days_diff === (int)$day ) { // التحويل الصريح يضمن المقارنة الصحيحة } // ============================================ // ✅ الإصلاح #10: التحقق من وجود ACF // ❌ الكود الخاطئ: // $company_name = get_field('company_name', $cert_id); // ✅ الكود الصحيح: function get_safe_field( $field_name, $post_id ) { if ( function_exists( 'get_field' ) ) { return get_field( $field_name, $post_id ); } else { // fallback للـ post meta إذا لم يكن ACF متوفر return get_post_meta( $post_id, $field_name, true ); } } // ============================================ // ✅ الإصلاح #11: تصحيح Text Domain للترجمة // ❌ الكود الخاطئ: // 'name' => _x( 'تصنيف المجتمع الإفتراضي', 'taxonomy general name' ), // ✅ الكود الصحيح: 'name' => _x( 'تصنيف المجتمع الإفتراضي', 'taxonomy general name', 'codevz' ), 'singular_name' => _x( 'تصنيف المجتمع الإفتراضي', 'taxonomy singular name', 'codevz' ), // ============================================ // ✅ نصيحة إضافية: استخدام error_log آمن function codevz_log( $message, $level = 'error' ) { if ( WP_DEBUG && WP_DEBUG_LOG ) { error_log( '[Codevz-' . strtoupper($level) . '] ' . wp_json_encode( $message ) ); } } // الاستخدام: // codevz_log( 'Something went wrong', 'error' ); // codevz_log( array( 'user_id' => 123, 'action' => 'login' ), 'info' ); 1.0Strategy Missionhttps://www.strategymission.org/en/Eng.Mohammed Alaghahttps://www.strategymission.org/en/author/admin12/What are the importance and benefits of water consumption auditingrich600338<blockquote class="wp-embedded-content" data-secret="eXxKYFaOHB"><a href="https://www.strategymission.org/en/water/">What are the importance and benefits of water consumption auditing</a></blockquote><iframe sandbox="allow-scripts" security="restricted" src="https://www.strategymission.org/en/water/embed/#?secret=eXxKYFaOHB" width="600" height="338" title="“What are the importance and benefits of water consumption auditing” — Strategy Mission" data-secret="eXxKYFaOHB" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe><script type="text/javascript"> /* <![CDATA[ */ /*! This file is auto-generated */ !function(d,l){"use strict";l.querySelector&&d.addEventListener&&"undefined"!=typeof URL&&(d.wp=d.wp||{},d.wp.receiveEmbedMessage||(d.wp.receiveEmbedMessage=function(e){var t=e.data;if((t||t.secret||t.message||t.value)&&!/[^a-zA-Z0-9]/.test(t.secret)){for(var s,r,n,a=l.querySelectorAll('iframe[data-secret="'+t.secret+'"]'),o=l.querySelectorAll('blockquote[data-secret="'+t.secret+'"]'),c=new RegExp("^https?:$","i"),i=0;i<o.length;i++)o[i].style.display="none";for(i=0;i<a.length;i++)s=a[i],e.source===s.contentWindow&&(s.removeAttribute("style"),"height"===t.message?(1e3<(r=parseInt(t.value,10))?r=1e3:~~r<200&&(r=200),s.height=r):"link"===t.message&&(r=new URL(s.getAttribute("src")),n=new URL(t.value),c.test(n.protocol))&&n.host===r.host&&l.activeElement===s&&(d.top.location.href=t.value))}},d.addEventListener("message",d.wp.receiveEmbedMessage,!1),l.addEventListener("DOMContentLoaded",function(){for(var e,t,s=l.querySelectorAll("iframe.wp-embedded-content"),r=0;r<s.length;r++)(t=(e=s[r]).getAttribute("data-secret"))||(t=Math.random().toString(36).substring(2,12),e.src+="#?secret="+t,e.setAttribute("data-secret",t)),e.contentWindow.postMessage({message:"ready",secret:t},"*")},!1)))}(window,document); //# sourceURL=https://www.strategymission.org/wp-includes/js/wp-embed.min.js /* ]]> */ </script> https://www.strategymission.org/wp-content/uploads/2023/09/28.jpg350350