\n"; // continent } elseif ( $selectcontinent != $continent ) { $structure .= "\n\n"; // continent } if ( isset( $city ) != "") { if ( !empty( $subcity ) != "" ) { $city = $city . "/". $subcity; } $structure .= "\t" . str_replace( "_", " ", $city ). "\n"; //Timezone } else { if ( !empty( $subcity ) != "" ) { $city = $city . "/". $subcity; } $structure .= "\t\n"; //Timezone } $selectcontinent = $continent; } } $structure .= "\n"; return $structure; } if ( !class_exists('customFieldsInterface') ) { class customFieldsInterface { /** * @var string $handle The handle for the box containing the custom fields */ var $handle = ""; /** * @var string $label The label for the box containing the custom fields */ var $label = ""; /** * @var string $desc The description/introduction for the box containing the custom fields */ var $desc = ""; /** * @var string $prefix The prefix for storing custom fields in the postmeta table */ var $prefix = ""; /** * @var array $postTypes An array of public custom post types, plus the standard "post" and "page" - add the custom types you want to include here */ var $postTypes = array(); /** * @var array $customFields Defines the custom fields available */ var $customFields = array(); /** * PHP 4 Compatible Constructor */ function customFieldsInterface( $handle, $label, $desc, $prefix, $postTypes, $customFields ) { $this->__construct( $handle, $label, $desc, $prefix, $postTypes, $customFields ); } /** * PHP 5 Constructor */ function __construct( $handle, $label, $desc, $prefix, $postTypes, $customFields ) { $this->handle = $handle; $this->label = $label; $this->desc = $desc; $this->prefix = $prefix; $this->postTypes = $postTypes ; $this->customFields = $customFields; 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 ) { foreach ( $this->postTypes as $postType ) { remove_meta_box( 'postcustom', $postType, $context ); } } } /** * Create the new Custom Fields meta box */ function createCustomFields() { // Only enqueue scripts if we're dealing with 'timed-content-rule' pages foreach ( $this->postTypes as $a_postType ) { if ( ( isset( $_GET['post_type'] ) && $_GET['post_type'] == $a_postType ) || ( isset( $post_type ) && $post_type == $a_postType ) || ( isset( $_GET['post'] ) && get_post_type( $_GET['post'] ) == $a_postType ) ) { wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_style( 'timed-content-jquery-ui', TIMED_CONTENT_JQUERY_UI_CSS ); wp_enqueue_script( 'jquery-ui-datepicker' ); wp_enqueue_script( 'jquery-ui-spinner' ); wp_register_style( 'timed-content-jquery-ui-timepicker-css', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_CSS ); wp_enqueue_style( 'timed-content-jquery-ui-timepicker-css' ); wp_register_script( 'timed-content-jquery-ui-timepicker-js', TIMED_CONTENT_JQUERY_UI_TIMEPICKER_JS, array('jquery', 'jquery-ui-datepicker'), TIMED_CONTENT_VERSION ); wp_enqueue_script( 'timed-content-jquery-ui-timepicker-js' ); if ( function_exists( 'add_meta_box' ) ) add_meta_box( $this->handle, $this->label, array( &$this, 'displayCustomFields' ), $a_postType, 'normal', 'high' ); } } } /** * Display the new Custom Fields meta box */ function displayCustomFields() { global $post; ?>

desc; ?>

handle, $this->handle . '_wpnonce', false, true ); foreach ( $this->customFields as $customField ) { // Check scope $scope = $customField[ 'scope' ]; $output = false; foreach ( $scope as $scopeItem ) { switch ( $scopeItem ) { default: { if ( $post->post_type == $scopeItem ) $output = true; break; } } if ( $output ) break; } // Check capability if ( !current_user_can( $customField['capability'], $post->ID ) ) $output = false; // Output if allowed if ( $output ) { ?>
ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); echo "" . $customField[ 'title' ] . "
\n"; foreach ( $customField['values'] as $value => $label ) { echo "prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "_" . $value . "\" value=\"" . $value . "\""; if ( $checked_value == $value ) echo " checked=\"checked\""; echo " style=\"width: 30px;\" />
\n"; } break; } case "menu": { // menu echo "
\n"; if ( sizeof ( $customField['values'] ) == 0 ) echo "This menu is empty.\n"; else { $selected_value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); echo "\n"; } break; } case "list": { // list echo "  \n"; if ( sizeof ( $customField['values'] ) == 0 ) echo "This list is empty.\n"; else { $selected_value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); echo "\n"; } break; } case "timezone-list": { // timezone list $selected_value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); echo "  \n"; echo "\n"; break; } case "checkbox": { // Checkbox $checked_value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); echo "  \n"; echo "prefix . $customField['name'] . "\" id=\"" . $this->prefix . $customField['name'] . "\" value=\"yes\""; if ( $checked_value == "yes" ) echo " checked=\"checked\""; echo " style=\"width: 30px;\" />\n"; break; } case "checkbox-list": { // Checkbox list $checked_value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); echo "" . $customField[ 'title' ] . "
\n"; if ( sizeof ( $customField['values'] ) == 0 ) echo "This list is empty.\n"; else { foreach ( $customField['values'] as $value => $label ) { echo "prefix . $customField['name'] . "[]\" id=\"" . $this->prefix . $customField['name'] . "_" . $value . "\" value=\"" . $value . "\""; if ( ( is_array( $checked_value ) ) && ( in_array( $value, $checked_value ) ) ) echo " checked=\"checked\""; echo " style=\"width: 30px;\" />
\n"; } } break; } case "textarea": case "wysiwyg": { // Text area $value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); echo "\n"; echo "\n"; // WYSIWYG if ( $customField[ 'type' ] == "wysiwyg" ) { ?> ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); // Color picker using WP's built-in Iris jQuery plugin ?> prefix . $customField[ 'name' ] . "\">" . $customField[ 'title' ] . "  \n"; echo "prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "\" value=\"" . $value . "\" size=\"7\" maxlength=\"7\" style=\"width: 100px;\" />\n"; break; } case "date": { echo "" . $customField[ 'title' ] . "  \n"; $value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); // Date picker using WP's built-in Datepicker jQuery plugin ?> prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "\" value=\"" . htmlspecialchars( $value ) . "\" style=\"width: 175px;\" />\n"; break; } case "datetime": { echo "" . $customField[ 'title' ] . "
\n"; $value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); foreach ( $value as $k => $v ) $value[$k] = htmlspecialchars( $v ); // Date picker using WP's built-in Datepicker jQuery plugin // Time picker using jQuery UI Timepicker: http://fgelinas.com/code/timepicker ?> prefix . $customField[ 'name' ] . "_date\" style=\"display:inline;\">" . _x( 'Date', 'Date field label', 'timed-content' ) . ":  \n"; echo "prefix . $customField[ 'name' ] . "[date]\" id=\"" . $this->prefix . $customField[ 'name' ] . "_date\" value=\"" . $value['date'] . "\" style=\"width: 175px;\" />\n"; echo "  \n"; echo "prefix . $customField[ 'name' ] . "[time]\" id=\"" . $this->prefix . $customField[ 'name' ] . "_time\" value=\"" . $value['time'] . "\" style=\"width: 125px;\" />\n"; break; } case "number": { (int)$value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); // Number picker using WP's built-in Spinner jQuery plugin ?> prefix . $customField[ 'name' ] . "\" style=\"display:inline;\">" . $customField[ 'title' ] . "  \n"; echo "prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "\" value=\"" . $value . "\" size=\"2\" />\n"; break; } case "hidden": { $value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); // Hidden field echo "prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "\" value=\"" . $value . "\" />\n"; break; } default: { $value = ( "" === get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ? $customField['default'] : get_post_meta( $post->ID, $this->prefix . $customField['name'], true ) ); // Plain text field echo "\n"; echo "prefix . $customField[ 'name' ] . "\" id=\"" . $this->prefix . $customField[ 'name' ] . "\" value=\"" . $value . "\" />\n"; break; } } ?> " . $customField[ 'description' ] . "

\n"; ?>
handle . '_wpnonce' ] ) || !wp_verify_nonce( $_POST[ $this->handle . '_wpnonce' ], $this->handle ) ) return; // Make sure the user can edit this specific post if ( !current_user_can( 'edit_post', $post_id ) ) return; // Make sure this meta box is associated with the right post types if ( ! in_array( $post->post_type, $this->postTypes ) ) return; foreach ( $this->customFields as $customField ) { if ( current_user_can( $customField['capability'], $post_id ) ) { if ( isset( $_POST[ $this->prefix . $customField['name'] ] ) ) { if ( is_array( $_POST[ $this->prefix . $customField['name'] ] ) ) { foreach ( $_POST[ $this->prefix . $customField['name'] ] as $k => $v ) $_POST[ $this->prefix . $customField['name'] ][$k] = trim( $v ); } else $_POST[ $this->prefix . $customField['name'] ] = trim( $_POST[ $this->prefix . $customField['name'] ] ); $value = $_POST[ $this->prefix . $customField['name'] ]; // Auto-paragraphs for any WYSIWYG if ( $customField['type'] == "wysiwyg" ) $value = wpautop( $value ); if ( $customField['type'] == "checkbox" ) $value = "yes"; if ( $customField['type'] == "number" ) $value = intval( $value ); update_post_meta( $post_id, $this->prefix . $customField[ 'name' ], $value ); } else { delete_post_meta( $post_id, $this->prefix . $customField[ 'name' ] ); } } } } } // End Class } // End if class exists statement ?>