From 72715308a9b695fec588a5562a7c0ca9f3fb1736 Mon Sep 17 00:00:00 2001 From: Matth_eu Date: Sun, 29 Sep 2013 23:49:00 +0100 Subject: [PATCH 1/3] remove loads of unused code... --- custom-meta-boxes.php | 85 ------------------------------------------- 1 file changed, 85 deletions(-) diff --git a/custom-meta-boxes.php b/custom-meta-boxes.php index cb708433..a52e797e 100755 --- a/custom-meta-boxes.php +++ b/custom-meta-boxes.php @@ -148,89 +148,4 @@ function _cmb_field_class_for_type( $type ) { return false; -} - -/** - * Draw the meta boxes in places other than the post edit screen - * - * @return null - */ -function cmb_draw_meta_boxes( $pages, $context = 'normal', $object = null ) { - - cmb_do_meta_boxes( $pages, $context, $object ); - - wp_enqueue_script('post'); - -} - -/** - * Meta-Box template function - * - * @since 2.5.0 - * - * @param string|object $screen Screen identifier - * @param string $context box context - * @param mixed $object gets passed to the box callback function as first parameter - * @return int number of meta_boxes - */ -function cmb_do_meta_boxes( $screen, $context, $object ) { - - global $wp_meta_boxes; - - static $already_sorted = false; - - if ( empty( $screen ) ) - $screen = get_current_screen(); - - elseif ( is_string( $screen ) ) - $screen = convert_to_screen( $screen ); - - $page = $screen->id; - - $hidden = get_hidden_meta_boxes( $screen ); - - $i = 0; - - do { - // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose - - if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) - foreach ( $sorted as $box_context => $ids ) - foreach ( explode(',', $ids ) as $id ) - if ( $id && 'dashboard_browser_nag' !== $id ) - add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); - - $already_sorted = true; - - if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) ) - break; - - foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { - - if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) { - - foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) { - - if ( false == $box || ! $box['title'] ) - continue; - - $i++; - - $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; ?> - -
- - - -
- - Date: Tue, 22 Oct 2013 11:35:16 +0100 Subject: [PATCH 2/3] Revert "remove loads of unused code..." This reverts commit 72715308a9b695fec588a5562a7c0ca9f3fb1736. --- custom-meta-boxes.php | 85 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/custom-meta-boxes.php b/custom-meta-boxes.php index a52e797e..cb708433 100755 --- a/custom-meta-boxes.php +++ b/custom-meta-boxes.php @@ -148,4 +148,89 @@ function _cmb_field_class_for_type( $type ) { return false; +} + +/** + * Draw the meta boxes in places other than the post edit screen + * + * @return null + */ +function cmb_draw_meta_boxes( $pages, $context = 'normal', $object = null ) { + + cmb_do_meta_boxes( $pages, $context, $object ); + + wp_enqueue_script('post'); + +} + +/** + * Meta-Box template function + * + * @since 2.5.0 + * + * @param string|object $screen Screen identifier + * @param string $context box context + * @param mixed $object gets passed to the box callback function as first parameter + * @return int number of meta_boxes + */ +function cmb_do_meta_boxes( $screen, $context, $object ) { + + global $wp_meta_boxes; + + static $already_sorted = false; + + if ( empty( $screen ) ) + $screen = get_current_screen(); + + elseif ( is_string( $screen ) ) + $screen = convert_to_screen( $screen ); + + $page = $screen->id; + + $hidden = get_hidden_meta_boxes( $screen ); + + $i = 0; + + do { + // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose + + if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) + foreach ( $sorted as $box_context => $ids ) + foreach ( explode(',', $ids ) as $id ) + if ( $id && 'dashboard_browser_nag' !== $id ) + add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); + + $already_sorted = true; + + if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) ) + break; + + foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { + + if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) { + + foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) { + + if ( false == $box || ! $box['title'] ) + continue; + + $i++; + + $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; ?> + +
+ + + +
+ + Date: Tue, 22 Oct 2013 11:41:31 +0100 Subject: [PATCH 3/3] move field anywhere code to separate file and document. --- custom-meta-boxes.php | 89 ++--------------------------------------- fields-anywhere.php | 92 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 85 deletions(-) create mode 100644 fields-anywhere.php diff --git a/custom-meta-boxes.php b/custom-meta-boxes.php index cb708433..3459f99e 100755 --- a/custom-meta-boxes.php +++ b/custom-meta-boxes.php @@ -40,6 +40,10 @@ include_once( CMB_PATH . '/classes.fields.php' ); include_once( CMB_PATH . '/class.cmb-meta-box.php' ); + +// Make it possible to add fields in locations other than post edit screen. +include_once( CMB_PATH . '/fields-anywhere.php' ); + // include_once( CMB_PATH . '/example-functions.php' ); /** @@ -148,89 +152,4 @@ function _cmb_field_class_for_type( $type ) { return false; -} - -/** - * Draw the meta boxes in places other than the post edit screen - * - * @return null - */ -function cmb_draw_meta_boxes( $pages, $context = 'normal', $object = null ) { - - cmb_do_meta_boxes( $pages, $context, $object ); - - wp_enqueue_script('post'); - -} - -/** - * Meta-Box template function - * - * @since 2.5.0 - * - * @param string|object $screen Screen identifier - * @param string $context box context - * @param mixed $object gets passed to the box callback function as first parameter - * @return int number of meta_boxes - */ -function cmb_do_meta_boxes( $screen, $context, $object ) { - - global $wp_meta_boxes; - - static $already_sorted = false; - - if ( empty( $screen ) ) - $screen = get_current_screen(); - - elseif ( is_string( $screen ) ) - $screen = convert_to_screen( $screen ); - - $page = $screen->id; - - $hidden = get_hidden_meta_boxes( $screen ); - - $i = 0; - - do { - // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose - - if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) - foreach ( $sorted as $box_context => $ids ) - foreach ( explode(',', $ids ) as $id ) - if ( $id && 'dashboard_browser_nag' !== $id ) - add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); - - $already_sorted = true; - - if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) ) - break; - - foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { - - if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) { - - foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) { - - if ( false == $box || ! $box['title'] ) - continue; - - $i++; - - $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; ?> - -
- - - -
- - id; + + $hidden = get_hidden_meta_boxes( $screen ); + + $i = 0; + + do { + // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose + + if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) + foreach ( $sorted as $box_context => $ids ) + foreach ( explode(',', $ids ) as $id ) + if ( $id && 'dashboard_browser_nag' !== $id ) + add_meta_box( $id, null, null, $screen, $box_context, 'sorted' ); + + $already_sorted = true; + + if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) ) + break; + + foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { + + if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) { + + foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) { + + if ( false == $box || ! $box['title'] ) + continue; + + $i++; + + $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; ?> + +
+ + + +
+ +