Recently the question (How to add add custom functions to a theme) was posed in فى الاونة الاخيرة مسألة (كيفية اضافة وظائف الى العرف اضافة موضوع) التي طرحت في WordPress Support Forum منتدى الدعم WordPress . Personally I faced the same question when re-designing انا شخصيا واجهت نفس السؤال عند إعادة تصميم this site في هذا الموقع . The following is a discussion of the option with the pros and cons. فيما يلى مناقشة للمع الخيار محاسن ومساوئ.

There are two solutions. هناك حلين.
The first is to create a plugin which goes with the theme. الاول هو انشاء البرنامج المساعد الذي يذهب مع هذا الموضوع. However the theme, when invoking functions defined in the plugin should check first for the availability of the function. ولكن هذا الموضوع ، وعندما تحتكم الى الوظائف المحددة في البرنامج المساعد الاول لان تتحقق من مدى توفر هذه الوظيفة. It should also provide a fallback option if the plugin is not available or has not been activated. كما ينبغي ان يوفر احتياطي البرنامج المساعد اذا كان الخيار غير متاح او لم يتم تنشيط.

 if(function_exists('your_function_name')) {     // Invoke your function: your_function_name()... اذا كانت الاجابه ب (function_exists ( 'your_function_name')) (/ / وظيفة الاحتجاج الخاص بك : your_function_name ()... else {     // Execute fallback option } والا (/ / تنفيذ الخيار الاحتياطي) 

The advantages are: مزايا هي :

  • The plugin can be independently managed. فان البرنامج المساعد يمكن ان تدار بشكل مستقل.
  • The plugin can be reused for other purposes. فان البرنامج المساعد ويمكن اعادة استخدامها لاغراض اخرى.

The disadvantages are: مساوئ هي :

  • It requires another additional step for the theme user to remember. وهو يتطلب خطوة اضافية اخرى للموضوع ان نتذكر المستخدم.
  • It slightly complicates development and testing. يعقد طفيف لتطوير واختبار.

The second solution to this problem would be to incorporate the functionaility in a php file (as usual) which resides in the theme directory. الثانية الى حل لهذه المشكلة سيكون لادراج functionaility في ملف بي. اتش. بى (كالعاده) الذي يقيم في موضوع الدليل. This file is included in header.php like: هذا الملف هو مدرج في header.php مثل :
include (’your_php_file.php’); وتشمل ( 'your_php_file.php') ؛

Yes you may also require it for simplicity like: نعم يمكنك أيضا لأنها تتطلب البساطه مثل :
require (’your_php_file.php’); يتطلب ( 'your_php_file.php') ؛

The advantage to this approach is simplicity of usage and deployment by end-users. وميزة هذا النهج هو بساطة الاستعمال والنشر من قبل المستخدمين النهائيين. It also simplifies development. كما يبسط التنمية.

If the user later decides to switch to a different theme and yet wants to retain the functionality, he would have to re-purpose the custom code into a plugin. اذا قام المستخدم في وقت لاحق تقرر ان أنتقل الى موضوع مختلف ، ومع ذلك يريد الابقاء على وظائف ، وقال انه كان لغرض اعادة العادة المدونه الى البرنامج المساعد.

In essence the reusability of the custom functionality determines the ideal location of the custom code. في الجوهر ، واعادة استعمال وظائف من العرف يحدد المكان المثالي للقانون العرف.