Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- CUSTOM ADMIN PANEL IN THEME
- Reference: http://wp.tutsplus.com/tutorials/the-complete-guide-to-the-wordpress-settings-api-part-1/
- Authror: Tom McFarlin (http://wp.tutsplus.com/author/tom/)
- সংজ্ঞা__________________________________________________
- ___FIELDS
- texbox, check box, radio button etc., যা ভ্যালু ডাটাবেজে নিয়ে যাবে
- ___SECTIONS
- ফিল্ডগুলোর লজিক্যাল গ্রুপিং হলো সেকশন; সেকশন এর মেনুকেও correspond করবে
- ___SETTINGS
- সেকশন আর ফিল্ডের একটি সম্মিলনক্ষেত্র
- */
- /* **********************************
- * THEME OPTIONS STARTS
- ********************************** */
- /* আমরা ন্যানোডিযাইন্স-এর জন্য আলাদা একটা অ্যাডমিন বাটন তৈরি করছি
- এজন্য add_menu_page ব্যবহার করছি এবং একটা ফাংশন দিয়ে
- তা ইনিশিয়ালাইজ করছি
- */
- // SEPERATE ADMIN PAGE nanoadmin
- function nano_admin_menu() {
- // syntax: add_menu_page( $page_title*, $menu_title*, $capability*, $menu_slug*, $function*, $icon_url, $position ); - * - required
- add_menu_page(
- 'nano<span style="font-weight: normal;">admin</span>', // page_title : ঐ পাতায় গেলে যে টাইটেলটা দেখা যাবে
- 'nano<span style="font-weight: normal;">admin</span>', // menu_title : মেনুতে যে নামটা দেখা যাবে
- 'manage_options', // capability : যারা এটা দেখতে পাবে
- 'nano_admin', // menu_slug : এই মেনু'র unique ID - slug
- 'nano_admin_callback', // function : callback function - যেখানে পেজটির দৃশ্যমানতার কোড বসানো হবে
- '', // icon_url : যে আইকনটা দেখাতে চাই, তার ঠিকানা
- '61' // position : যে অবস্থানে বা যে সিরিয়ালে দেখা যাবে মেনুটি (60 : Appearance)
- );
- // syntax: add_submenu_page( $parent_slug*, $page_title*, $menu_title*, $capability*, $menu_slug*, $function ); - * - required
- add_submenu_page(
- 'nano_admin', // parent_slug : যে মেনুর অধীনে এই সাবমেনুটি বসবে, তার slug বা ID
- '<strong>price</strong>quotation', // page_title : যে নামটি দেখা যাবে সাব মেনু পেজে
- '<strong>price</strong>quotation', // menu_title : সাবমেনুর নাম হিসেবে যে নামটি দেখা যাবে
- 'manage_options', // capability : যারা এটা দেখতে পাবে
- 'price_quotation', // menu_slug : এই সাব মেনু'র unique ID - slug
- 'price_quotation_callback' // function : callback function - যেখানে পেজটির দৃশ্যমানতার কোড বসানো হবে
- );
- } // nano_admin_menu()
- add_action( 'admin_menu', 'nano_admin_menu' );
- // CALLBACK FUNCTION FOR nanoadmin
- // main menu callback
- function nano_admin_callback() { ?>
- <div class="wrap">
- <h2><strong>nano</strong>admin</h2>
- <p>welcome to <strong>nano</strong>admin panel</p>
- <?php //Make a call to the WordPress function for rendering errors when settings are saved. ?>
- <?php settings_errors(); ?>
- <?php // Create the form that will be used to render our options ?>
- <form method="post" action="options.php">
- <?php settings_fields( 'general' ); ?>
- <?php do_settings_sections( 'general' ); ?>
- <?php submit_button(); ?>
- </form>
- </div> <!-- .wrap -->
- <?php }
- // sub menu callback
- function price_quotation_callback() { ?>
- <div class="wrap">
- <h2><strong>price</strong>quotation</h2>
- <p>when price tag is OFF, get user's price quotation request here in this admin panel area</p>
- </div> <!-- .wrap -->
- <?php }
- /*
- প্রথমেই আমরা একটা সেকশন তৈরি করছি, যেখানে আমাদের কিছু ফিল্ড থাকবে
- সেকশনের ফাংশনটা ইনিশিয়ালাইজ করার জন্য একটা ফাংশন দিয়ে একে ঢাকতে হবে
- তারপর admin_init দিয়ে hook করতে হবে
- */
- function initialize_theme_options() {
- // এই nanodesigns_admin_control_options দিয়ে সেকশনকে কল করা হবে
- if( false == get_option( 'nanodesigns_admin_control_options' ) ) {
- add_option( 'nanodesigns_admin_control_options' );
- } // end if
- // syntax: add_settings_section( $id*, $title*, $callback*, $page* ); - * - required
- add_settings_section(
- 'admin_control_section', // id : খুব গুরুত্বপূর্ণ, এই আইডি দিয়েই পরবর্তিতে ফিল্ডগুলো নির্দেশ করা হবে
- 'admin<span style="font-weight: normal;">control</span>', // name : যে নামে সেকশনটা দেখা যাবে স্ক্রিনে, পাতাটা খুললে
- 'nanodesigns_admin_control', // callback : ফাংশনের নাম, যা ব্যবহার করে এই সেকশনকে কার্যকর করা হবে
- 'general' // page : যে পেজের অধীনে সেকশনটি স্থান পাবে (প্রাথমিকভাবে সেটিংস > জেনারেল পেজে রাখছি)
- );
- // syntax: add_settings_field( $id*, $title*, $callback*, $page*, $section, $args ); - * - required
- add_settings_field (
- 'show_price', // id : খুব গুরুত্বপূর্ণ, এই আইডি ধরেই পরবর্তিতে ফিল্ড থেকে ডাটা ডাটাবেজে ইনপুট নেয়া হবে
- '<img src="' . get_bloginfo( template_directory ) . '/admin/images/price.png"/> Show Price (৳)', // name : যে নামে field-টা দেখা যাবে স্ক্রিনে
- 'show_price_callback', // callback : ফাংশনের নাম, যা ব্যবহার করে এই ফিল্ডকে কার্যকর করা হবে
- 'general', // page : যে পেজে ফিল্ডটা প্রদর্শিত হবে (যদি আলাদা কোনো সেটিংস না করা হয়, তবে বর্তমান পেজেই দেখানো যায়)
- 'admin_control_section', // section : যে সেকশনে দেখাতে চাই ফিল্ডটা
- array (
- 'Activate the "Product Price" into the whole website'
- )
- );
- // REGISTER THE FIELD TO GET INPUT INTO db
- // Finally, we register the fields with WordPress
- // syntax:
- register_setting(
- 'general',
- 'show_price'
- );
- } // end initialize_theme_options()
- add_action( 'admin_init', 'initialize_theme_options' );
- /* --------------------------------------------------------
- SECTION CALLBACK
- -------------------------------------------------------- */
- // 'Theme Options' callback function
- function nanodesigns_admin_control() { ?>
- <p style="color: grey;">control most of the admin features of the whole site just from here</p>
- <?php }
- // 'Show Price' callback function
- function show_price_callback( $args ) {
- $html = '<input type="checkbox" id="show_price" name="show_price" value="1" ' . checked( 1, get_option( 'show_price' ), false ) . '/>';
- $html .= '<label for="show_price"> ' . $args[0] . '</label>';
- echo $html;
- }
- /* **********************************
- * THEME OPTIONS ENDS
- ********************************** */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement