"page_setting", "title" => "Layout setting", "description" => "All the following items are optional", "type" => "title", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "layout", "title" => "Page Layout", "description" => "", "type" => "select-layout", "scope" => array( "page" ), "capability" => "manage_options" ), array( "name" => "select_sidebar", "title" => "Sidebar", "description" => "", "type" => "select-sidebar", "scope" => array("page"), "capability" => "manage_options" ), array( "name" => "close", "type" => "optionclose", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "slide_setting", "title" => "Slide settings", "description" => "", "type" => "title", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "slide_setimage", "title" => "", "description" => "You need to upload the slider images from your computer", "type" => "slide-btn", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "home_slide_style", "title" => "Style", "description" => "", "type" => "home-slide-style", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "slide_order_by", "title" => "Order images by", "description" => "", "type" => "slide-order-by", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "slide_order", "title" => "Order", "description" => "", "type" => "slide-order", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "numbers_nivo", "title" => "Nivo Slide - Number of Pictures", "description" => "e.g. '3'", "type" => "wormbox", "scope" => array("page"), "capability" => "manage_options" ), array( "name" => "nivo_effect", "title" => "Nivo Slide Effect", "description" => "", "type" => "nivo-effect", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "nivo_slices", "title" => "Nivo Slide Slices", "description" => "e.g. '3'", "type" => "wormbox", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "nivo_animSpeed", "title" => "Nivo Slide transition speed", "description" => "Default 500 (1000 = 1 second)", "type" => "wormbox", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "close", "type" => "optionclose", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "general_setting", "title" => "General settings", "description" => "", "type" => "title", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "guideif", "title" => "Show Breadcrumbs", "description" => "", "type" => "checkbox", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "slogan", "title" => "Slogan", "description" => "e.g.'Design is about how it works, not just how it looks!'", "type" => "textarea", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "quote", "title" => "Quoted text", "description" => "e.g.'Stay hungry, stay foolish! <p align=right>--Steve Jobs</p>'", "type" => "textarea", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "close", "type" => "optionclose", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "item_setting", "title" => "List settings", "description" => "", "type" => "title", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "home_promotion_cat", "title" => "List - Category", "description" => "Please select the category what you want to show in list", "type" => "select-cat", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "home_promotion_nums", "title" => "List - Number of posts", "description" => "Number of posts in one page", "type" => "wormbox", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "list_order_by", "title" => "Order posts by", "description" => "", "type" => "list-order-by", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "list_order", "title" => "Order", "description" => "", "type" => "list-order", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "pagination", "title" => "Pagination", "description" => "", "type" => "select-pagination", "scope" => array("page"), "capability" => "manage_options" ), array( "name" => "col", "title" => "Columns", "description" => "", "type" => "select-col", "scope" => array("page"), "capability" => "manage_options" ), array( "name" => "close", "type" => "optionclose", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "ad_setting", "title" => "Advertising settings", "description" => "", "type" => "title", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "pagead_top", "title" => "Top of page", "description" => "Please enter the AD code.
e.g.<a href="http://sample.com"><img src="http://sample.com/sample.gif"></a>", "type" => "textareaadtop", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "pagead_middle", "title" => "Middle of page", "description" => "Please enter the AD code.
e.g.<a href="http://sample.com"><img src="http://sample.com/sample.gif"></a>", "type" => "textareaadmiddle", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "pagead_insert", "title" => "Insert List", "description" => "Please enter the AD code.
Note:1. Not support JavaScript code. 2. Need set a height for img label. 3. Not for Filterable template.
e.g.<a href="http://sample.com"><img src="http://sample.com/sample.gif" height="300" ></a>", "type" => "textareaadinsert", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "insert_posi", "title" => "Insert List - Position", "description" => "", "type" => "listad_posi", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "pagead_bottom", "title" => "Bottom of page", "description" => "Please enter the AD code.
e.g.<a href="http://sample.com"><img src="http://sample.com/sample.gif"></a>", "type" => "textareaadbottom", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "close", "type" => "optionclose", "scope" => array( "page"), "capability" => "manage_options" ), array( "name" => "post_setting", "title" => "Post settings", "description" => "", "type" => "title", "scope" => array( "post","gallery"), "capability" => "manage_options" ), array( "name" => "layout", "title" => "Layout", "description" => "", "type" => "select-layout", "scope" => array( "post" ), "capability" => "manage_options" ), array( "name" => "select_sidebar", "title" => "Sidebar", "description" => "", "type" => "select-sidebar", "scope" => array( "post","gallery"), "capability" => "manage_options" ), array( "name" => "layoutinlist", "title" => "Layout in list", "description" => "", "type" => "select-layoutinlist", "scope" => array( "post","gallery" ), "capability" => "manage_options" ), array( "name" => "video_link", "title" => "Video URL", "description" => "Show in list, support Youtube(e.g.'http://www.youtube.com/watch?v=xxxxxxxxx'), Vimeo(e.g.'http://vimeo.com/12345678') and SWF(e.g.'http://www.flashrul.com/flashname.swf')", "type" => "text", "scope" => array( "post","gallery"), "capability" => "manage_options" ), array( "name" => "guideif", "title" => "Show Breadcrumbs", "description" => "", "type" => "checkbox", "scope" => array( "post","gallery"), "capability" => "manage_options" ), array( "name" => "showadif", "title" => "Advertising", "description" => "Not show Advertising in this post.", "type" => "checkboxad", "scope" => array( "post"), "capability" => "manage_options" ), array( "name" => "close", "type" => "optionclose", "scope" => array( "post","gallery"), "capability" => "manage_options" ) ); /** * PHP 4 Compatible Constructor */ function myCustomFields() { $this->__construct(); } /** * PHP 5 Constructor */ function __construct() { add_action( 'admin_menu', array( &$this, 'createCustomFields' ) ); add_action( 'save_post', array( &$this, 'saveCustomFields' ), 1, 2 ); // Comment this line out if you want to keep default custom fields meta box add_action( 'do_meta_boxes', array( &$this, 'removeDefaultCustomFields' ), 10, 3 ); } /** * Remove the default Custom Fields meta box */ function removeDefaultCustomFields( $type, $context, $post ) { foreach ( array( 'normal', 'advanced', 'side' ) as $context ) { remove_meta_box( 'postcustom', 'post', $context ); remove_meta_box( 'postcustom', 'page', $context ); remove_meta_box( 'postcustom', 'gallery', $context ); //Use the line below instead of the line above for WP versions older than 2.9.1 //remove_meta_box( 'pagecustomdiv', 'page', $context ); } } /** * Create the new Custom Fields meta box */ function createCustomFields() { if ( function_exists( 'add_meta_box' ) ) { add_meta_box( 'my-custom-fields', 'Custom Fields', array( &$this, 'displayCustomFields' ), 'page', 'normal', 'high' ); add_meta_box( 'my-custom-fields', 'Custom Fields', array( &$this, 'displayCustomFields' ), 'post', 'normal', 'high' ); add_meta_box( 'my-custom-fields', 'Custom Fields', array( &$this, 'displayCustomFields' ), 'gallery', 'normal', 'high' ); } } /** * Display the new Custom Fields meta box */ function displayCustomFields() { global $post; $all_category_ids = get_all_category_ids(); $no_of_categories = count($all_category_ids); $categories = get_categories("taxonomy=catalog"); $all_page_names = all_names("page"); $all_page_titles = all_titles("page"); $all_page_ids = all_IDs("page"); $no_of_pages = count($all_page_ids); $all_post_names = all_names("post"); $all_post_titles = all_titles("post"); $all_post_ids = all_IDs("post"); $no_of_posts = count($all_post_ids); $all_post_names = all_names("gallery"); $all_post_titles = all_titles("gallery"); $all_post_ids = all_IDs("gallery"); $no_of_posts = count($all_post_ids); ?>
customFields as $customField ) { // Check scope $scope = $customField[ 'scope' ]; $output = false; foreach ( $scope as $scopeItem ) { if ($post->post_type == $scopeItem ){ $output = true; break; } } // Check capability //if ( !current_user_can( $customField['capability'], $post->ID ) ) //$output = false; // Output if allowed if ( $output ) { ?>
' . esc_html($customField[ 'title' ]) . '
'; break; } case "optionclose": { echo '
'; break; } case "checkbox": { // Checkbox echo '

  '; echo 'ID, $this->prefix . $customField['name'], true ) == "yes" ) echo ' checked="checked"'; echo '" style="width: auto;" /> Yes
'; break; } case "checkboxad": { // Checkbox echo '

  '; echo 'ID, $this->prefix . $customField['name'], true ) == "yes" ) echo ' checked="checked"'; echo '" style="width: auto;" /> Not show'; break; } case "textarea": { // Text area echo ''; echo ''; break; } case "textareaadtop": { // Text area echo ''; echo ''; break; } case "textareaadmiddle": { // Text area echo ''; echo ''; break; } case "textareaadbottom": { // Text area echo ''; echo ''; break; } case "textareaadinsert": { // Text area echo ''; echo ''; break; } case "select-cat": { // Drop Down echo ''; echo ' '; ?> '; break; } case "select-page": { // Drop Down echo ''; echo ' '; ?> item'; break; } case "select-sidebar": { // Drop Down echo ''; echo ' '; ?> '; break; } case "nivo-effect": { // Drop Down echo ''; echo ' '; ?> '; break; } case "yes-no": { // Drop Down echo ''; echo 'ID, $this->prefix . $customField[ 'name' ], true ) == 'One Image Layout A') echo 'checked="checked"'; ?> />
'; ?> '; ?> prefix . $customField[ 'name' ]) .'">' . esc_attr($customField[ 'title' ]) . ''; echo ' '; ?> '; break; } case "yes-no": { // Drop Down echo ''; echo ' '; ?> '; break; } case "select-col": { // Drop Down echo ''; echo ''; break; } // upload image case "image": { $std = get_post_meta( $post->ID, $this->prefix . $customField[ 'name' ], true ); if($std != '') { $val = $std; }; echo ''; echo ''; if(get_post_meta( $post->ID, $this->prefix . $customField[ 'name' ], true )) { echo '
'; } break; } case "slide-color-box": { // Plain text field, width is smaller echo ''; echo ''; break; } case "slide-btn": { // Plain text field, width is smaller echo ''; echo ''; break; } default: { // Plain text field echo ''; echo ''; break; } } //switch end ?> ' . esc_attr($customField[ 'description' ]) . '

'; ?> post_type != 'page' && $post->post_type != 'post' && $post->post_type != 'gallery') return; foreach ( $this->customFields as $customField ) { //if ( current_user_can( $customField['capability'], $post_id ) ) { if ( isset( $_POST[ $this->prefix . $customField['name'] ] ) && trim( $_POST[ $this->prefix . $customField['name'] ] ) ) { update_post_meta( $post_id, $this->prefix . $customField[ 'name' ], $_POST[ $this->prefix . $customField['name'] ] ); } if(isset($_FILES[$this->prefix . $customField['name']]) && ($_FILES[$this->prefix . $customField['name']]['size'] > 0)){ //New upload $override['action'] = 'editpost'; $uploaded_file = wp_handle_upload($_FILES[$this->prefix . $customField['name']], $override); $file_name_and_location = $uploaded_file['file']; $file_title_for_media_library = 'your title here'; require_once(ABSPATH . "wp-admin" . '/includes/image.php'); update_post_meta($post->ID, $this->prefix . $customField[ 'name' ], $uploaded_file['url']); } else if(empty($_FILES[$this->prefix . $customField['name']])){ update_post_meta($post->ID, $this->prefix . $customField[ 'name' ],$_POST[ $this->prefix . $customField[ 'name' ]]);; } //} } } } // End Class } // End if class exists statement // Instantiate the class if ( class_exists('myCustomFields') ) { $myCustomFields_var = new myCustomFields(); } ?>