مشاكل خصائص ملف القالب – YourColor
السلام عليكم ورحمة الله وبركاته
في هذه التدوينة سنتحدث عن طريقة ادراج الهاكات في ملف خصائص القالب (function.php) لتفادي الكثير من المشاكل وهي طريقة بسيطة لا تحتاج الا بعض التدقيق في الدوال
نفتح ملف خصائص القالب نقوم بادراج هذا الهاك مثالا :
function autoblank($text) { $return = str_replace(´<a href=´, ´<a target="_blank" href=´, $text); $return = str_replace(´<a target="_blank" href="http://example.com´, ´<a href="http://example.com´, $return); $return = str_replace(´<a target="_blank" href="#´, ´<a href="#´, $return); $return = str_replace(´ target="_blank">´, ´>´, $return); return $return; } add_filter(´the_content´, ´autoblank´); add_filter(´comment_text´, ´autoblank´);
هذا الهاك سنقسمه الى قسمين قسم الدالة وقسم اضافة الفلترة
قسم الدالة :
function autoblank($text) { $return = str_replace(´<a href=´, ´<a target="_blank" href=´, $text); $return = str_replace(´<a target="_blank" href="http://example.com´, ´<a href="http://example.com´, $return); $return = str_replace(´<a target="_blank" href="#´, ´<a href="#´, $return); $return = str_replace(´ target="_blank">´, ´>´, $return); return $return; }
قسم اضافة الفلترة :
add_filter(´the_content´, ´autoblank´); add_filter(´comment_text´, ´autoblank´);
لدينا في ملف خصائص القلب الخاص بنا مثلا دالتين بهذا الشكل :
function the_more($more_link_text = ´Read More´, $stripteaser = 0, $more_file = ´´) { $content = get_the_more($more_link_text, $stripteaser, $more_file); echo $content; } function get_the_more($more_link_text = ´Read More´, $stripteaser = 0, $more_file = ´´) { global $id, $post, $more, $single, $withcomments, $page, $pages, $multipage, $numpages; global $preview; global $pagenow; $output = ´´; $content = $pages[$page-1]; if ( preg_match(´/<!--more(.+?)?-->/´, $content, $matches) ) { $content = explode($matches[0], $content, 2); if ( !empty($matches[1]) && !empty($more_link_text) ) $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1]))); } else { $content = array($content); } if ( count($content) > 1 ) { if ( $more ) { $output .= ´<a id="more-´.$id.´"></a>´.$content[1]; } else { $output = balanceTags($output); if ( ! empty($more_link_text) ) $output .= ´ <a href="´. get_permalink() . "" class="more-link">$more_link_text</a>"; } } if ( $preview ) // preview fix for javascript bug with foreign languages $output = preg_replace(´/%u([0-9A-F]{4,4})/e´, "´&#´.base_convert(´\1´,16,10).´;´", $output); return $output; }
لاحظ معي اين ساضع قسم الدالة
function the_more($more_link_text = ´Read More´, $stripteaser = 0, $more_file = ´´) { $content = get_the_more($more_link_text, $stripteaser, $more_file); echo $content; } function autoblank($text) { $return = str_replace(´<a href=´, ´<a target="_blank" href=´, $text); $return = str_replace(´<a target="_blank" href="http://example.com´, ´<a href="http://example.com´, $return); $return = str_replace(´<a target="_blank" href="#´, ´<a href="#´, $return); $return = str_replace(´ target="_blank">´, ´>´, $return); return $return; } function get_the_more($more_link_text = ´Read More´, $stripteaser = 0, $more_file = ´´) { global $id, $post, $more, $single, $withcomments, $page, $pages, $multipage, $numpages; global $preview; global $pagenow; $output = ´´; $content = $pages[$page-1]; if ( preg_match(´/<!--more(.+?)?-->/´, $content, $matches) ) { $content = explode($matches[0], $content, 2); if ( !empty($matches[1]) && !empty($more_link_text) ) $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1]))); } else { $content = array($content); } if ( count($content) > 1 ) { if ( $more ) { $output .= ´<a id="more-´.$id.´"></a>´.$content[1]; } else { $output = balanceTags($output); if ( ! empty($more_link_text) ) $output .= ´ <a href="´. get_permalink() . "" class="more-link">$more_link_text</a>"; } } if ( $preview ) // preview fix for javascript bug with foreign languages $output = preg_replace(´/%u([0-9A-F]{4,4})/e´, "´&#´.base_convert(´\1´,16,10).´;´", $output); return $output; }
تم وضع قسم الدالة بين الداتين في ملف خصائص القالب . بالنسبة لقسم اضافة الفلترة نتوجه اسفل القالب الى ان نجد اي فلترة واضفها اسفلها مباشرة او قبلها مثال :
add_action(´admin_menu´, ´mytheme_add_admin´); ?> add_filter(´the_content´, ´autoblank´); add_filter(´comment_text´, ´autoblank´);
اذا كان هناك اي استفسار يرجى وضع تعليق و الى اللقاء في تدوينة جديدة انشاء الله
والسلام عليكم ورحمة الله وبركاته
يجب عليك تسجيل الدخول لكتابة تعليق.