WordPress Directory Constants

WordPress Directory Constants – जब हम WordPress Theme/Plugin Create करते हैं, तब हमें अक्सर WordPress Installation के कुछ Folders व Files को बार-बार Reference करने की जरूरत पडती है। साथ ही WordPress 2.6 के बाद के Versions में हमें ये सुविधा प्राप्त होती है कि हम WordPress के किसी भी Folder को अपने Web Host पर किसी भी Location पर Move कर सकते हैं। इस स्थिति में हम कभी भी Theme/Plugin Create करते समय विभिन्न WordPress Installation Folders के Path को Hard Coded Form में नहीं लिख सकते।

इसलिए WordPress में कुछ PHP Constants को Define किया गया है, जो कि WordPress Installation के /wp-content/ /plugins/ नाम के जरूरी Folders के Paths को Represent करते हैं और हम इन Constants को अपने किसी भी Plugin/Theme में बिना किसी तरह का Configuration किए हुए Directly Use कर सकते हैं, जबकि इन्हें Use करते समय इस बात का कोई प्रभाव नहीं पडता कि WordPress Installation के विभिन्न Folders Web Server पर Actually किस Location पर Exist हैं।

WP_CONTENT_URL        :       Full URL to wp-content
WP_CONTENT_DIR         :       The Server Path to the wp-content directory
WP_PLUGIN_URL           :       Full URL to the plugins directory
WP_PLUGIN_DIR            :       The Server Path to the plugins directory
WP_LANG_DIR                 :       The Server Path to the language directory

चूंकि WordPress में इन Constants को 2.6 Version में Add किया गया था, इसलिए WordPress 2.6 से पहले के Versions में ये Constants Exist नहीं हैं। इसलिए WordPress 2.6 से पहले के Versions में इन Constants की Requirements को पूरा करने के लिए व अपने Plugin को Backward Compatible बनाए रखने के लिए हम अपने Plugin/Theme में निम्नानुसार कुछ Statements लिख सकते हैं:

<?php
// For WordPress < Version 2.6 Compatibility
if ( !defined('WP_CONTENT_URL' ) )
        define('WP_CONTENT_URL', get_option('siteurl' ) .'/wp-content' );

if ( !defined('WP_CONTENT_DIR' ) )
        define('WP_CONTENT_DIR', ABSPATH .'wp-content' );

if ( !defined('WP_PLUGIN_URL' ) )
        define('WP_PLUGIN_URL', WP_CONTENT_URL.'/plugins' );

if ( !defined('WP_PLUGIN_DIR' ) )
        define('WP_PLUGIN_DIR', WP_CONTENT_DIR .'/plugins' );

if ( !defined('WP_LANG_DIR') )
        define('WP_LANG_DIR', WP_CONTENT_DIR .'/languages' );
?>

इस तरह से अपने Plugin/Theme में उपरोक्तानुसार Code लिखकर हम इस बात को निश्चित कर सकते हैं कि भले ही ये Constants WordPress के Current Version में Specified हों चाहे न हों, हमारे Plugin Normal/Theme में इन Constants से सम्बंधित Path Normal तरीके से काम करेगा।

WordPress Internationalization
WordPress get_option - update_option - WP Options API

WordPress in Hindi - BccFalna.comये Article इस वेबसाईट पर Selling हेतु उपलब्‍ध EBook Advance WordPress in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी है, तो निश्चित रूप से ये EBook भी आपके लिए काफी उपयोगी साबित होगी।

Advance WordPress in Hindi | Page: 835 | Format: PDF

BUY NOW GET DEMO REVIEWS