Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: zamoose/LB-Colorbox
base: 9b8c6d24b5
...
head fork: zamoose/LB-Colorbox
compare: 41b6ab2d74
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
9 include/lbcb-cpt.php
@@ -158,6 +158,15 @@ function lbcb_initialize_cmb_meta_boxes() {
add_action( 'init', 'lbcb_initialize_cmb_meta_boxes', 9999 );
/**
+ * Remove Yoast's WP SEO metaboxes
+ */
+function lbcb_remove_wpseo_mb() {
+ // if ( ! current_user_can( 'edit_others_posts' ) )
+ remove_meta_box( 'wpseo_meta', 'ColorBox', 'normal' );
+}
+add_action( 'add_meta_boxes', 'lbcb_remove_wpseo_mb', 99);
+
+/**
* Insert colorbox into the CPTs.
*/
function lbcb_insert_colorbox( $colorbox = array() ){
View
60 include/lbcb-output.php
@@ -148,4 +148,62 @@ function lbcb_kulers_shortcode( $atts ){
lbcb_kulers_out( $type, $display );
}
-add_shortcode( 'kulers', 'lbcb_kulers_shortcode' );
+add_shortcode( 'kulers', 'lbcb_kulers_shortcode' );
+
+/**
+ * Outputs CSS styles in the header.
+ *
+ * @param array $args
+ */
+
+function lbcb_css( $args ){
+ extract( shortcode_atts(array(
+ "name" => "",
+ "slug" => "",
+ "id" => "",
+ ),
+ $args
+ )
+ );
+
+ $lbcb_args = array(
+ 'order' => 'DESC',
+ 'orderby' => 'date',
+ 'post_type' => 'colorbox',
+ 'post_status' => 'publish'
+ );
+
+ // echo $lbcb_args;
+ // echo $args;
+ // if( !empty($name))
+ // $lbcb_args['post__in'] = $wpdb->get_col( "select ID from $wpdb->posts where post_title LIKE '%" . $name . "%' AND post_status = 'publish'" );
+ // if( !empty($slug) ){
+ // $lbcb_args['post_name'] = $slug;
+ // } elseif( !empty($id) ){
+ // $lbcb_args['p'] = $id;
+ // }
+ //
+ // $lbcb_query = new WP_Query( $lbcb_args );
+ // $lbcb_query->have_posts();
+
+ $colorbox = wp_get_single_post( $id );
+ $cb_meta = get_post_meta( $id );
+
+ echo '<style type="text/css">';
+ for( $i = 1; $i <= 5; $i++ ){
+ echo ".color" . $i . " { \n" .
+ " color: " . $cb_meta['color' . $i][0] . ";\n" .
+ "}\n\n";
+
+ echo ".bgcolor" . $i . " { \n" .
+ " background-color: " . $cb_meta['color' . $i][0] . ";\n" .
+ "}\n\n";
+ }
+ echo '</style>';
+ echo "\n";
+}
+
+function lbcb_css_head() {
+ lbcb_css( array("id" => "1117" ) );
+}
+add_action( 'wp_head', 'lbcb_css_head' );
View
233 include/metaboxes/init.php
@@ -4,8 +4,9 @@
Contributors: Andrew Norcross (@norcross / andrewnorcross.com)
Jared Atchison (@jaredatch / jaredatchison.com)
Bill Erickson (@billerickson / billerickson.net)
+ Justin Sternberg (@jtsternberg / dsgnwrks.pro)
Description: This will create metaboxes with custom fields that will blow your mind.
-Version: 0.9
+Version: 0.9.1
*/
/**
@@ -20,7 +21,7 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -40,7 +41,7 @@
/**
* Validate value of meta fields
- * Define ALL validation methods inside this class and use the names of these
+ * Define ALL validation methods inside this class and use the names of these
* methods in the definition of meta boxes (key 'validate_func' of each field)
*/
class cmb_Meta_Box_Validate {
@@ -57,7 +58,13 @@ function check_text( $text ) {
* This may need to be filtered for local Window installations.
* If resources do not load, please check the wiki for details.
*/
-define( 'CMB_META_BOX_URL', apply_filters( 'cmb_meta_box_url', trailingslashit( str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, dirname( __FILE__ ) ) ) ) );
+if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+ //winblows
+ define( 'CMB_META_BOX_URL', trailingslashit( str_replace( DIRECTORY_SEPARATOR, '/', str_replace( str_replace( '/', DIRECTORY_SEPARATOR, WP_CONTENT_DIR ), WP_CONTENT_URL, dirname(__FILE__) ) ) ) );
+
+} else {
+ define( 'CMB_META_BOX_URL', apply_filters( 'cmb_meta_box_url', trailingslashit( str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, dirname( __FILE__ ) ) ) ) );
+}
/**
* Create meta boxes
@@ -77,8 +84,8 @@ function __construct( $meta_box ) {
break;
}
}
-
- global $pagenow;
+
+ global $pagenow;
if ( $upload && in_array( $pagenow, array( 'page.php', 'page-new.php', 'post.php', 'post-new.php' ) ) ) {
add_action( 'admin_head', array( &$this, 'add_post_enctype' ) );
}
@@ -105,33 +112,33 @@ function add() {
$this->_meta_box['context'] = empty($this->_meta_box['context']) ? 'normal' : $this->_meta_box['context'];
$this->_meta_box['priority'] = empty($this->_meta_box['priority']) ? 'high' : $this->_meta_box['priority'];
$this->_meta_box['show_on'] = empty( $this->_meta_box['show_on'] ) ? array('key' => false, 'value' => false) : $this->_meta_box['show_on'];
-
+
foreach ( $this->_meta_box['pages'] as $page ) {
if( apply_filters( 'cmb_show_on', true, $this->_meta_box ) )
add_meta_box( $this->_meta_box['id'], $this->_meta_box['title'], array(&$this, 'show'), $page, $this->_meta_box['context'], $this->_meta_box['priority']) ;
}
}
-
+
/**
* Show On Filters
* Use the 'cmb_show_on' filter to further refine the conditions under which a metabox is displayed.
* Below you can limit it by ID and page template
*/
-
- // Add for ID
+
+ // Add for ID
function add_for_id( $display, $meta_box ) {
if ( 'id' !== $meta_box['show_on']['key'] )
return $display;
- // If we're showing it based on ID, get the current ID
+ // If we're showing it based on ID, get the current ID
if( isset( $_GET['post'] ) ) $post_id = $_GET['post'];
elseif( isset( $_POST['post_ID'] ) ) $post_id = $_POST['post_ID'];
if( !isset( $post_id ) )
return false;
-
- // If value isn't an array, turn it into one
+
+ // If value isn't an array, turn it into one
$meta_box['show_on']['value'] = !is_array( $meta_box['show_on']['value'] ) ? array( $meta_box['show_on']['value'] ) : $meta_box['show_on']['value'];
-
+
// If current page id is in the included array, display the metabox
if ( in_array( $post_id, $meta_box['show_on']['value'] ) )
@@ -139,21 +146,21 @@ function add_for_id( $display, $meta_box ) {
else
return false;
}
-
+
// Add for Page Template
function add_for_page_template( $display, $meta_box ) {
if( 'page-template' !== $meta_box['show_on']['key'] )
return $display;
-
+
// Get the current ID
if( isset( $_GET['post'] ) ) $post_id = $_GET['post'];
elseif( isset( $_POST['post_ID'] ) ) $post_id = $_POST['post_ID'];
if( !( isset( $post_id ) || is_page() ) ) return false;
-
+
// Get current template
$current_template = get_post_meta( $post_id, '_wp_page_template', true );
-
- // If value isn't an array, turn it into one
+
+ // If value isn't an array, turn it into one
$meta_box['show_on']['value'] = !is_array( $meta_box['show_on']['value'] ) ? array( $meta_box['show_on']['value'] ) : $meta_box['show_on']['value'];
// See if there's a match
@@ -162,7 +169,7 @@ function add_for_page_template( $display, $meta_box ) {
else
return false;
}
-
+
// Show fields
function show() {
@@ -179,21 +186,21 @@ function show() {
if ( !isset( $field['std'] ) ) $field['std'] = '';
if ( 'file' == $field['type'] && !isset( $field['allow'] ) ) $field['allow'] = array( 'url', 'attachment' );
if ( 'file' == $field['type'] && !isset( $field['save_id'] ) ) $field['save_id'] = false;
- if ( 'multicheck' == $field['type'] ) $field['multiple'] = true;
-
+ if ( 'multicheck' == $field['type'] ) $field['multiple'] = true;
+
$meta = get_post_meta( $post->ID, $field['id'], 'multicheck' != $field['type'] /* If multicheck this can be multiple values */ );
echo '<tr>';
-
+
if ( $field['type'] == "title" ) {
echo '<td colspan="2">';
} else {
if( $this->_meta_box['show_names'] == true ) {
echo '<th style="width:18%"><label for="', $field['id'], '">', $field['name'], '</label></th>';
- }
+ }
echo '<td>';
- }
-
+ }
+
switch ( $field['type'] ) {
case 'text':
@@ -218,7 +225,7 @@ function show() {
break;
case 'text_time':
echo '<input class="cmb_timepicker text_time" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" /><span class="cmb_metabox_description">', $field['desc'], '</span>';
- break;
+ break;
case 'text_money':
echo '$ <input class="cmb_text_money" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" /><span class="cmb_metabox_description">', $field['desc'], '</span>';
break;
@@ -239,7 +246,7 @@ function show() {
break;
case 'textarea_code':
echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="10" class="cmb_textarea_code">', '' !== $meta ? $meta : $field['std'], '</textarea>','<p class="cmb_metabox_description">', $field['desc'], '</p>';
- break;
+ break;
case 'select':
if( empty( $meta ) && !empty( $field['std'] ) ) $meta = $field['std'];
echo '<select name="', $field['id'], '" id="', $field['id'], '">';
@@ -281,12 +288,12 @@ function show() {
foreach ( $field['options'] as $value => $name ) {
// Append `[]` to the name to get multiple values
// Use in_array() to check whether the current option should be checked
- echo '<li><input type="checkbox" name="', $field['id'], '[]" id="', $field['id'], $i, '" value="', $value, '"', in_array( $value, $meta ) ? ' checked="checked"' : '', ' /><label for="', $field['id'], $i, '">', $name, '</label></li>';
+ echo '<li><input type="checkbox" name="', $field['id'], '[]" id="', $field['id'], $i, '" value="', $value, '"', in_array( $value, $meta ) ? ' checked="checked"' : '', ' /><label for="', $field['id'], $i, '">', $name, '</label></li>';
$i++;
}
echo '</ul>';
- echo '<span class="cmb_metabox_description">', $field['desc'], '</span>';
- break;
+ echo '<span class="cmb_metabox_description">', $field['desc'], '</span>';
+ break;
case 'title':
echo '<h5 class="cmb_metabox_title">', $field['name'], '</h5>';
echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
@@ -328,12 +335,14 @@ function show() {
$names = wp_get_object_terms( $post->ID, $field['taxonomy'] );
$terms = get_terms( $field['taxonomy'], 'hide_empty=0' );
foreach ($terms as $term) {
- echo '<li><input type="checkbox" name="', $field['id'], '[]" id="', $field['id'], '" value="', $term->name , '"';
+ echo '<li><input type="checkbox" name="', $field['id'], '[]" id="', $field['id'], '" value="', $term->name , '"';
foreach ($names as $name) {
if ( $term->slug == $name->slug ){ echo ' checked="checked" ';};
}
echo' /><label>', $term->name , '</label></li>';
}
+ echo '</ul>';
+ echo '<span class="cmb_metabox_description">', $field['desc'], '</span>';
break;
case 'file_list':
echo '<input class="cmb_upload_file" type="text" size="36" name="', $field['id'], '" value="" />';
@@ -363,10 +372,10 @@ function show() {
$input_type_url="text";
echo '<input class="cmb_upload_file" type="' . $input_type_url . '" size="45" id="', $field['id'], '" name="', $field['id'], '" value="', $meta, '" />';
echo '<input class="cmb_upload_button button" type="button" value="Upload File" />';
- echo '<input class="cmb_upload_file_id" type="hidden" id="', $field['id'], '_id" name="', $field['id'], '_id" value="', get_post_meta( $post->ID, $field['id'] . "_id",true), '" />';
+ echo '<input class="cmb_upload_file_id" type="hidden" id="', $field['id'], '_id" name="', $field['id'], '_id" value="', get_post_meta( $post->ID, $field['id'] . "_id",true), '" />';
echo '<p class="cmb_metabox_description">', $field['desc'], '</p>';
- echo '<div id="', $field['id'], '_status" class="cmb_upload_status">';
- if ( $meta != '' ) {
+ echo '<div id="', $field['id'], '_status" class="cmb_media_status">';
+ if ( $meta != '' ) {
$check_image = preg_match( '/(^.*\.jpg|jpeg|png|gif|ico*)/i', $meta );
if ( $check_image ) {
echo '<div class="img_status">';
@@ -377,16 +386,34 @@ function show() {
$parts = explode( '/', $meta );
for( $i = 0; $i < count( $parts ); ++$i ) {
$title = $parts[$i];
- }
+ }
echo 'File: <strong>', $title, '</strong>&nbsp;&nbsp;&nbsp; (<a href="', $meta, '" target="_blank" rel="external">Download</a> / <a href="#" class="cmb_remove_file_button" rel="', $field['id'], '">Remove</a>)';
- }
+ }
}
- echo '</div>';
+ echo '</div>';
break;
+ case 'oembed':
+ echo '<input class="cmb_oembed" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" />','<p class="cmb_metabox_description">', $field['desc'], '</p>';
+ echo '<p class="cmb-spinner spinner"></p>';
+ echo '<div id="', $field['id'], '_status" class="cmb_media_status ui-helper-clearfix embed_wrap">';
+ if ( $meta != '' ) {
+ $check_embed = $GLOBALS['wp_embed']->run_shortcode( '[embed]'. esc_url( $meta ) .'[/embed]' );
+ if ( $check_embed ) {
+ echo '<div class="embed_status">';
+ echo $check_embed;
+ echo '<a href="#" class="cmb_remove_file_button" rel="', $field['id'], '">Remove Embed</a>';
+ echo '</div>';
+ } else {
+ echo 'URL is not a valid oEmbed URL.';
+ }
+ }
+ echo '</div>';
+ break;
+
default:
do_action('cmb_render_' . $field['type'] , $field, $meta);
}
-
+
echo '</td>','</tr>';
}
echo '</table>';
@@ -415,18 +442,18 @@ function save( $post_id) {
}
foreach ( $this->_meta_box['fields'] as $field ) {
- $name = $field['id'];
+ $name = $field['id'];
if ( ! isset( $field['multiple'] ) )
- $field['multiple'] = ( 'multicheck' == $field['type'] ) ? true : false;
-
+ $field['multiple'] = ( 'multicheck' == $field['type'] ) ? true : false;
+
$old = get_post_meta( $post_id, $name, !$field['multiple'] /* If multicheck this can be multiple values */ );
$new = isset( $_POST[$field['id']] ) ? $_POST[$field['id']] : null;
-
- if ( in_array( $field['type'], array( 'taxonomy_select', 'taxonomy_radio', 'taxonomy_multicheck' ) ) ) {
- $new = wp_set_object_terms( $post_id, $new, $field['taxonomy'] );
+
+ if ( in_array( $field['type'], array( 'taxonomy_select', 'taxonomy_radio', 'taxonomy_multicheck' ) ) ) {
+ $new = wp_set_object_terms( $post_id, $new, $field['taxonomy'] );
}
-
+
if ( ($field['type'] == 'textarea') || ($field['type'] == 'textarea_small') ) {
$new = htmlspecialchars( $new );
}
@@ -434,7 +461,7 @@ function save( $post_id) {
if ( ($field['type'] == 'textarea_code') ) {
$new = htmlspecialchars_decode( $new );
}
-
+
if ( $field['type'] == 'text_date_timestamp' ) {
$new = strtotime( $new );
}
@@ -443,9 +470,9 @@ function save( $post_id) {
$string = $new['date'] . ' ' . $new['time'];
$new = strtotime( $string );
}
-
- $new = apply_filters('cmb_validate_' . $field['type'], $new, $post_id, $field);
-
+
+ $new = apply_filters('cmb_validate_' . $field['type'], $new, $post_id, $field);
+
// validate meta value
if ( isset( $field['validate_func']) ) {
$ok = call_user_func( array( 'cmb_Meta_Box_Validate', $field['validate_func']), $new );
@@ -453,18 +480,18 @@ function save( $post_id) {
continue;
}
} elseif ( $field['multiple'] ) {
- delete_post_meta( $post_id, $name );
+ delete_post_meta( $post_id, $name );
if ( !empty( $new ) ) {
foreach ( $new as $add_new ) {
add_post_meta( $post_id, $name, $add_new, false );
}
- }
+ }
} elseif ( '' !== $new && $new != $old ) {
update_post_meta( $post_id, $name, $new );
} elseif ( '' == $new ) {
delete_post_meta( $post_id, $name );
}
-
+
if ( 'file' == $field['type'] ) {
$name = $field['id'] . "_id";
$old = get_post_meta( $post_id, $name, !$field['multiple'] /* If multicheck this can be multiple values */ );
@@ -479,7 +506,7 @@ function save( $post_id) {
} elseif ( '' == $new && $old ) {
delete_post_meta( $post_id, $name, $old );
}
- }
+ }
}
}
}
@@ -488,12 +515,23 @@ function save( $post_id) {
* Adding scripts and styles
*/
function cmb_scripts( $hook ) {
+ global $wp_version;
if ( $hook == 'post.php' || $hook == 'post-new.php' || $hook == 'page-new.php' || $hook == 'page.php' ) {
+ $cmb_script_array = array( 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'media-upload', 'thickbox' );
+ $cmb_style_array = array( 'thickbox' );
+ if( 3.5 <= $wp_version ){
+ $cmb_script_array[] = 'wp-color-picker';
+ $cmb_style_array[] = 'wp-color-picker';
+ }else{
+ $cmb_script_array[] = 'farbtastic';
+ $cmb_style_array[] = 'farbtastic';
+ }
wp_register_script( 'cmb-timepicker', CMB_META_BOX_URL . 'js/jquery.timePicker.min.js' );
- wp_register_script( 'cmb-scripts', CMB_META_BOX_URL . 'js/cmb.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker', 'media-upload', 'thickbox', 'farbtastic' ) );
+ wp_register_script( 'cmb-scripts', CMB_META_BOX_URL . 'js/cmb.js', $cmb_script_array, '0.9.1' );
+ wp_localize_script( 'cmb-scripts', 'cmb_ajax_data', array( 'ajax_nonce' => wp_create_nonce( 'ajax_nonce' ), 'post_id' => get_the_ID() ) );
wp_enqueue_script( 'cmb-timepicker' );
wp_enqueue_script( 'cmb-scripts' );
- wp_register_style( 'cmb-styles', CMB_META_BOX_URL . 'style.css', array( 'thickbox', 'farbtastic' ) );
+ wp_register_style( 'cmb-styles', CMB_META_BOX_URL . 'style.css', $cmb_style_array );
wp_enqueue_style( 'cmb-styles' );
}
}
@@ -501,42 +539,42 @@ function cmb_scripts( $hook ) {
function cmb_editor_footer_scripts() { ?>
<?php
- if ( isset( $_GET['cmb_force_send'] ) && 'true' == $_GET['cmb_force_send'] ) {
- $label = $_GET['cmb_send_label'];
+ if ( isset( $_GET['cmb_force_send'] ) && 'true' == $_GET['cmb_force_send'] ) {
+ $label = $_GET['cmb_send_label'];
if ( empty( $label ) ) $label="Select File";
- ?>
+ ?>
<script type="text/javascript">
jQuery(function($) {
$('td.savesend input').val('<?php echo $label; ?>');
});
</script>
- <?php
+ <?php
}
}
add_action( 'admin_print_footer_scripts', 'cmb_editor_footer_scripts', 99 );
-// Force 'Insert into Post' button from Media Library
+// Force 'Insert into Post' button from Media Library
add_filter( 'get_media_item_args', 'cmb_force_send' );
function cmb_force_send( $args ) {
-
- // if the Gallery tab is opened from a custom meta box field, add Insert Into Post button
+
+ // if the Gallery tab is opened from a custom meta box field, add Insert Into Post button
if ( isset( $_GET['cmb_force_send'] ) && 'true' == $_GET['cmb_force_send'] )
$args['send'] = true;
-
- // if the From Computer tab is opened AT ALL, add Insert Into Post button after an image is uploaded
+
+ // if the From Computer tab is opened AT ALL, add Insert Into Post button after an image is uploaded
if ( isset( $_POST['attachment_id'] ) && '' != $_POST["attachment_id"] ) {
-
- $args['send'] = true;
- // TO DO: Are there any conditions in which we don't want the Insert Into Post
+ $args['send'] = true;
+
+ // TO DO: Are there any conditions in which we don't want the Insert Into Post
// button added? For example, if a post type supports thumbnails, does not support
// the editor, and does not have any cmb file inputs? If so, here's the first
// bits of code needed to check all that.
// $attachment_ancestors = get_post_ancestors( $_POST["attachment_id"] );
// $attachment_parent_post_type = get_post_type( $attachment_ancestors[0] );
// $post_type_object = get_post_type_object( $attachment_parent_post_type );
- }
-
+ }
+
// change the label of the button on the From Computer tab
if ( isset( $_POST['attachment_id'] ) && '' != $_POST["attachment_id"] ) {
@@ -552,7 +590,7 @@ function cmbGetParameterByNameInline(name) {
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
-
+
jQuery(function($) {
if (cmbGetParameterByNameInline("cmb_force_send")=="true") {
var cmb_send_label = cmbGetParameterByNameInline("cmb_send_label");
@@ -562,8 +600,57 @@ function cmbGetParameterByNameInline(name) {
</script>
';
}
-
+
return $args;
}
-// End. That's it, folks! //
+
+add_action( 'wp_ajax_cmb_oembed_handler', 'cmb_oembed_ajax_results' );
+/**
+ * Handles our oEmbed ajax request
+ */
+function cmb_oembed_ajax_results() {
+
+ // verify our nonce
+ if ( ! ( isset( $_REQUEST['cmb_ajax_nonce'], $_REQUEST['oembed_url'] ) && wp_verify_nonce( $_REQUEST['cmb_ajax_nonce'], 'ajax_nonce' ) ) )
+ die();
+
+ // sanitize our search string
+ $oembed_string = sanitize_text_field( $_REQUEST['oembed_url'] );
+
+ if ( empty( $oembed_string ) ) {
+ $return = '<p class="ui-state-error-text">'. __( 'Please Try Again', 'cmb' ) .'</p>';
+ $found = 'not found';
+ } else {
+
+ global $wp_embed;
+
+ $oembed_url = esc_url( $oembed_string );
+ // Post ID is needed to check for embeds
+ if ( isset( $_REQUEST['post_id'] ) )
+ $GLOBALS['post'] = get_post( $_REQUEST['post_id'] );
+ // ping WordPress for an embed
+ $check_embed = $wp_embed->run_shortcode( '[embed]'. $oembed_url .'[/embed]' );
+ // fallback that WordPress creates when no oEmbed was found
+ $fallback = $wp_embed->maybe_make_link( $oembed_url );
+
+ if ( $check_embed && $check_embed != $fallback ) {
+ // Embed data
+ $return = '<div class="embed_status">'. $check_embed .'<a href="#" class="cmb_remove_file_button" rel="'. $_REQUEST['field_id'] .'">'. __( 'Remove Embed', 'cmb' ) .'</a></div>';
+ // set our response id
+ $found = 'found';
+
+ } else {
+ // error info when no oEmbeds were found
+ $return = '<p class="ui-state-error-text">'.sprintf( __( 'No oEmbed Results Found for %s. View more info at', 'cmb' ), $fallback ) .' <a href="http://codex.wordpress.org/Embeds" target="_blank">codex.wordpress.org/Embeds</a>.</p>';
+ // set our response id
+ $found = 'not found';
+ }
+ }
+
+ // send back our encoded data
+ echo json_encode( array( 'result' => $return, 'id' => $found ) );
+ die();
+}
+
+// End. That's it, folks! //
View
105 include/metaboxes/js/cmb.js
@@ -4,6 +4,7 @@
* @author Andrew Norcross
* @author Jared Atchison
* @author Bill Erickson
+ * @author Justin Sternberg
* @see https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress
*/
@@ -41,20 +42,24 @@ jQuery(document).ready(function ($) {
});
// Wrap date picker in class to narrow the scope of jQuery UI CSS and prevent conflicts
$("#ui-datepicker-div").wrap('<div class="cmb_element" />');
-
+
/**
* Initialize color picker
*/
- $('input:text.cmb_colorpicker').each(function (i) {
- $(this).after('<div id="picker-' + i + '" style="z-index: 1000; background: #EEE; border: 1px solid #CCC; position: absolute; display: block;"></div>');
- $('#picker-' + i).hide().farbtastic($(this));
- })
- .focus(function() {
- $(this).next().show();
- })
- .blur(function() {
- $(this).next().hide();
- });
+ if( typeof jQuery.wp === 'object' && typeof jQuery.wp.wpColorPicker === 'function' ){
+ $('input:text.cmb_colorpicker').wpColorPicker();
+ }else{
+ $('input:text.cmb_colorpicker').each(function (i) {
+ $(this).after('<div id="picker-' + i + '" style="z-index: 1000; background: #EEE; border: 1px solid #CCC; position: absolute; display: block;"></div>');
+ $('#picker-' + i).hide().farbtastic($(this));
+ })
+ .focus(function() {
+ $(this).next().show();
+ })
+ .blur(function() {
+ $(this).next().hide();
+ });
+ }
/**
* File and image upload handling
@@ -116,7 +121,7 @@ jQuery(document).ready(function ($) {
$('#' + formfield).val(itemurl);
$('#' + formfield + '_id').val(itemid);
- $('#' + formfield).siblings('.cmb_upload_status').slideDown().html(uploadStatus);
+ $('#' + formfield).siblings('.cmb_media_status').slideDown().html(uploadStatus);
tb_remove();
} else {
@@ -125,4 +130,80 @@ jQuery(document).ready(function ($) {
formfield = '';
};
+
+ /**
+ * Ajax oEmbed display
+ */
+
+ // ajax on paste
+ $('.cmb_oembed').bind('paste', function (e) {
+ var pasteitem = $(this);
+ // paste event is fired before the value is filled, so wait a bit
+ setTimeout(function () {
+ // fire our ajax function
+ doCMBajax(pasteitem, 'paste');
+ }, 100);
+ }).blur(function () {
+ // when leaving the input
+ setTimeout(function () {
+ // if it's been 2 seconds, hide our spinner
+ $('.postbox table.cmb_metabox .cmb-spinner').hide();
+ }, 2000);
+ });
+
+ // ajax when typing
+ $('.cmb_metabox').on('keyup', '.cmb_oembed', function (event) {
+ // fire our ajax function
+ doCMBajax($(this), event);
+ });
+
+ // function for running our ajax
+ function doCMBajax(obj, e) {
+ // get typed value
+ var oembed_url = obj.val();
+ // only proceed if the field contains more than 6 characters
+ if (oembed_url.length < 6)
+ return;
+
+ // only proceed if the user has pasted, pressed a number, letter, or whitelisted characters
+ if (e === 'paste' || e.which <= 90 && e.which >= 48 || e.which >= 96 && e.which <= 111 || e.which == 8 || e.which == 9 || e.which == 187 || e.which == 190) {
+
+ // get field id
+ var field_id = obj.attr('id');
+ // get our inputs context for pinpointing
+ var context = obj.parents('.cmb_metabox tr td');
+ // show our spinner
+ $('.cmb-spinner', context).show();
+ // clear out previous results
+ $('.embed_wrap', context).html('');
+ // and run our ajax function
+ setTimeout(function () {
+ // if they haven't typed in 500 ms
+ if ($('.cmb_oembed:focus').val() == oembed_url) {
+ $.ajax({
+ type : 'post',
+ dataType : 'json',
+ url : window.ajaxurl,
+ data : {
+ 'action': 'cmb_oembed_handler',
+ 'oembed_url': oembed_url,
+ 'field_id': field_id,
+ 'post_id': window.cmb_ajax_data.post_id,
+ 'cmb_ajax_nonce': window.cmb_ajax_data.ajax_nonce
+ },
+ success: function (response) {
+ // if we have a response id
+ if (typeof response.id !== 'undefined') {
+ // hide our spinner
+ $('.cmb-spinner', context).hide();
+ // and populate our results from ajax response
+ $('.embed_wrap', context).html(response.result);
+ }
+ }
+ });
+ }
+ }, 500);
+ }
+ }
+
});
View
247 include/metaboxes/readme.md
@@ -1,121 +1,126 @@
-# Custom Metaboxes and Fields for WordPress
-
-**Contributors**:
-
-* Andrew Norcross ( [@norcross](http://twitter.com/norcross ) / [andrewnorcross.com](http://andrewnorcross.com/) )
-* Jared Atchison ( [@jaredatch](http://twitter.com/jaredatch ) / [jaredatchison.com](http://jaredatchison.com/) )
-* Bill Erickson ( [@billerickson](http://twitter.com/billerickson ) / [billerickson.net](http://billerickson.net/) )
-
-**Version**: 0.9
-**Requires at least**: 3.3
-**Tested up to**: 3.3
-**License**: GPLv2
-
-## Description
-
-Custom Metaboxes and Fields (CMB for short) will create metaboxes with custom fields that will blow your mind.
-
-##### Links
-* [Github project page](http://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress)
-* [Documentation (GitHub wiki)](http://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki)
-
-##### Field Types:
-* text
-* text small
-* text medium
-* text money
-* date picker
-* date picker (unix timestamp)
-* date time picker combo (unix timestamp)
-* time picker
-* color picker
-* textarea
-* textarea small
-* textarea code
-* select
-* radio
-* radio inline
-* taxonomy radio
-* taxonomy select
-* checkbox
-* multicheck
-* WYSIWYG/TinyMCE
-* Image/file upload
-
-[More on field types (GitHub wiki)](github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Field-Types)
-
-## Installation
-
-This script is easy to install. If you can't figure it out you probably shouldn't be using it.
-
-1. Place `metabox` directory inside of your (activated) theme. E.g. inside `/themes/twentyten/lib/metabox/`.
-2. Include `init.php`.
-3. See `example-functions.php` for further guidance.
-4. Profit.
-
-## Known Issues
-
-* Problem inserting file url inside field for image with caption (issue #50)
-* `CMB_META_BOX_URL` does not define properly in WAMP/XAMP (Windows) (issue #31)
-* Metabox containing WYSIWYG editor cannot be moved (this is a TinyMCE issue)
-
-## To-do
-* Fix known issues (above)
-* clean up code
-* improve inline documentation
-* move timepicker and datepicker jQuery inline
-* support for multiple configurable timepickers/datepickers
-* add ability to save fields in a single custom field
-* add ability to mark fields as required
-* add ability to define `placeholder` text
-* repeatable fields
-* look at possiblity of tabs
-* look at preserving taxonomy hierarchies
-
-## Changelog
-
-### 0.9
-* __Note: This release requires WordPress 3.3+__
-* Cleaned up scripts being queued, props @jaredatch
-* Cleaned up and reorganized jQuery, props @GaryJones
-* Use $pagenow instead of custom $current_page, props @jaredatch
-* Fixed CSS, removed inline styles, now all in style.css, props @jaredatch
-* Fixed multicheck issues (issue #48), props @jaredatch
-* Fixed jQuery UI datepicker CSS conflicting with WordPress UI elements, props @jaredatch
-* Fixed zeros not saving in fields, props @GaryJones
-* Fixed improper labels on radio and multicheck fields, props @jaredatch
-* Fixed fields not rendering properly when in sidebar, props @jaredatch
-* Fixed bug where datepicker triggers extra space after footer in Firefox (issue #14), props @jaredatch
-* Added jQuery UI datepicker packaged with 3.3 core, props @jaredatch
-* Added date time combo picker, props @jaredatch
-* Added color picker, props @jaredatch
-* Added readme.md markdown file, props @jaredatch
-
-### 0.8
-* Added jQuery timepicker, props @norcross
-* Added 'raw' textarea to convert special HTML entities back to characters, props @norcross
-* Added missing examples on example-functions.php, props @norcross
-
-### 0.7
-* Added the new wp_editor() function for the WYSIWYG dialog box, props @jcpry
-* Created 'cmb_show_on' filter to define your own Show On Filters, props @billerickson
-* Added page template show_on filter, props @billerickson
-* Improvements to the 'file' field type, props @randyhoyt
-* Allow for default values on 'radio' and 'radio_inline' field types, props @billerickson
-
-### 0.6.1
-* Enabled the ability to define your own custom field types (issue #28). props @randyhoyt
-
-### 0.6
-* Added the ability to limit metaboxes to certain posts by id. props @billerickson
-
-### 0.5
-* Fixed define to prevent notices. props @destos
-* Added text_date_timestap option. props @andrewyno
-* Fixed WYSIWYG paragraph breaking/spacing bug. props @wpsmith
-* Added taxonomy_radio and taxonomies_select options. props @c3mdigital
-* Fixed script causing the dashboard widgets to not be collapsible.
-* Fixed various spacing and whitespace inconsistencies
-
-### 0.4
-* Think we have a release that is mostly working. We'll say the initial release :)
+# Custom Metaboxes and Fields for WordPress
+
+**Contributors**:
+
+* Andrew Norcross ( [@norcross](http://twitter.com/norcross ) / [andrewnorcross.com](http://andrewnorcross.com/) )
+* Jared Atchison ( [@jaredatch](http://twitter.com/jaredatch ) / [jaredatchison.com](http://jaredatchison.com/) )
+* Bill Erickson ( [@billerickson](http://twitter.com/billerickson ) / [billerickson.net](http://billerickson.net/) )
+* Justin Sternberg ( [@jtsternberg](http://twitter.com/jtsternberg ) / [dsgnwrks.pro](http://dsgnwrks.pro) )
+
+**Version**: 0.9.1
+**Requires at least**: 3.3
+**Tested up to**: 3.5
+**License**: GPLv2
+
+## Description
+
+Custom Metaboxes and Fields (CMB for short) will create metaboxes with custom fields that will blow your mind.
+
+##### Links
+* [Github project page](http://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress)
+* [Documentation (GitHub wiki)](http://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki)
+
+##### Field Types:
+* text
+* text small
+* text medium
+* text money
+* date picker
+* date picker (unix timestamp)
+* date time picker combo (unix timestamp)
+* time picker
+* color picker
+* textarea
+* textarea small
+* textarea code
+* select
+* radio
+* radio inline
+* taxonomy radio
+* taxonomy select
+* checkbox
+* multicheck
+* WYSIWYG/TinyMCE
+* Image/file upload
+* oEmbed
+
+[More on field types (GitHub wiki)](https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Field-Types)
+
+## Installation
+
+This script is easy to install. If you can't figure it out you probably shouldn't be using it.
+
+1. Place `metabox` directory inside of your (activated) theme. E.g. inside `/themes/twentyten/lib/metabox/`.
+2. Include `init.php` (preferably on the 'init' WordPress hook).
+3. See `example-functions.php` for further guidance.
+4. Profit.
+
+## Known Issues
+
+* Problem inserting file url inside field for image with caption (issue #50)
+* `CMB_META_BOX_URL` does not define properly in WAMP/XAMP (Windows) (issue #31)
+* Metabox containing WYSIWYG editor cannot be moved (this is a TinyMCE issue)
+
+## To-do
+* Fix known issues (above)
+* clean up code
+* improve inline documentation
+* move timepicker and datepicker jQuery inline
+* support for multiple configurable timepickers/datepickers
+* add ability to save fields in a single custom field
+* add ability to mark fields as required
+* add ability to define `placeholder` text
+* repeatable fields
+* look at possiblity of tabs
+* look at preserving taxonomy hierarchies
+
+## Changelog
+
+### 0.9.1
+* Added 'oEmbed' field type with ajax display, props @jtsternberg
+
+### 0.9
+* __Note: This release requires WordPress 3.3+__
+* Cleaned up scripts being queued, props @jaredatch
+* Cleaned up and reorganized jQuery, props @GaryJones
+* Use $pagenow instead of custom $current_page, props @jaredatch
+* Fixed CSS, removed inline styles, now all in style.css, props @jaredatch
+* Fixed multicheck issues (issue #48), props @jaredatch
+* Fixed jQuery UI datepicker CSS conflicting with WordPress UI elements, props @jaredatch
+* Fixed zeros not saving in fields, props @GaryJones
+* Fixed improper labels on radio and multicheck fields, props @jaredatch
+* Fixed fields not rendering properly when in sidebar, props @jaredatch
+* Fixed bug where datepicker triggers extra space after footer in Firefox (issue #14), props @jaredatch
+* Added jQuery UI datepicker packaged with 3.3 core, props @jaredatch
+* Added date time combo picker, props @jaredatch
+* Added color picker, props @jaredatch
+* Added readme.md markdown file, props @jaredatch
+
+### 0.8
+* Added jQuery timepicker, props @norcross
+* Added 'raw' textarea to convert special HTML entities back to characters, props @norcross
+* Added missing examples on example-functions.php, props @norcross
+
+### 0.7
+* Added the new wp_editor() function for the WYSIWYG dialog box, props @jcpry
+* Created 'cmb_show_on' filter to define your own Show On Filters, props @billerickson
+* Added page template show_on filter, props @billerickson
+* Improvements to the 'file' field type, props @randyhoyt
+* Allow for default values on 'radio' and 'radio_inline' field types, props @billerickson
+
+### 0.6.1
+* Enabled the ability to define your own custom field types (issue #28). props @randyhoyt
+
+### 0.6
+* Added the ability to limit metaboxes to certain posts by id. props @billerickson
+
+### 0.5
+* Fixed define to prevent notices. props @destos
+* Added text_date_timestap option. props @andrewyno
+* Fixed WYSIWYG paragraph breaking/spacing bug. props @wpsmith
+* Added taxonomy_radio and taxonomies_select options. props @c3mdigital
+* Fixed script causing the dashboard widgets to not be collapsible.
+* Fixed various spacing and whitespace inconsistencies
+
+### 0.4
+* Think we have a release that is mostly working. We'll say the initial release :)
View
15 include/metaboxes/style.css
@@ -27,14 +27,15 @@ table.cmb_metabox .mceLayout {border:1px solid #DFDFDF !important;}
table.cmb_metabox .mceIframeContainer {background:#FFF;}
table.cmb_metabox .meta_mce {width:97%;}
table.cmb_metabox .meta_mce textarea {width:100%;}
-table.cmb_metabox .cmb_upload_status { margin: 10px 0 0 0;}
-table.cmb_metabox .cmb_upload_status .img_status { position: relative; }
-table.cmb_metabox .cmb_upload_status .img_status img { border:1px solid #DFDFDF; background: #FAFAFA; max-width:350px; padding: 5px; -moz-border-radius: 2px; border-radius: 2px;}
-table.cmb_metabox .cmb_upload_status .img_status .cmb_remove_file_button { text-indent: -9999px; background: url(images/ico-delete.png); width: 16px; height: 16px; position: absolute; top: -5px; left: -5px;}
+table.cmb_metabox .cmb_media_status { margin: 10px 0 0 0;}
+table.cmb_metabox .cmb_media_status .img_status, table.cmb_metabox .cmb_media_status .embed_status { position: relative; }
+table.cmb_metabox .cmb_media_status .img_status img, table.cmb_metabox .cmb_media_status .embed_status { border:1px solid #DFDFDF; background: #FAFAFA; max-width:350px; padding: 5px; -moz-border-radius: 2px; border-radius: 2px;}
+table.cmb_metabox .cmb_media_status .embed_status { float: left; max-width:800px;}
+table.cmb_metabox .cmb_media_status .img_status .cmb_remove_file_button, table.cmb_metabox .cmb_media_status .embed_status .cmb_remove_file_button { text-indent: -9999px; background: url(images/ico-delete.png); width: 16px; height: 16px; position: absolute; top: -5px; left: -5px;}
/* Sidebar placement adjustments */
.inner-sidebar table.cmb_metabox input[type=text], table.cmb_metabox textarea { width: 95%; }
-.inner-sidebar table.cmb_metabox .cmb_upload_status .img_status img { width: 90%; }
-
+.inner-sidebar table.cmb_metabox .cmb_media_status .img_status img, .inner-sidebar table.cmb_metabox .cmb_media_status .embed_status img { width: 90%; }
+.postbox table.cmb_metabox .cmb-spinner { float: left; }
/**
* Timepicker
*/
@@ -286,7 +287,7 @@ div.time-picker li.selected { background: #0063CE; color: #fff; }
.cmb_element .ui-datepicker .ui-datepicker-title { margin: 0 2.3em; line-height: 1.8em; text-align: center; }
.cmb_element .ui-datepicker .ui-datepicker-title select { font-size:1em; margin:1px 0; }
.cmb_element .ui-datepicker select.ui-datepicker-month-year {width: 100%;}
- .cmb_element .ui-datepicker select.ui-datepicker-month,
+ .cmb_element .ui-datepicker select.ui-datepicker-month,
.cmb_element .ui-datepicker select.ui-datepicker-year { width: 49%;}
.cmb_element .ui-datepicker table {width: 100%; font-size: .9em; border-collapse: collapse; margin:0 0 .4em; }
.cmb_element .ui-datepicker th { padding: .7em .3em; text-align: center; font-weight: bold; border: 0; }

No commit comments for this range

Something went wrong with that request. Please try again.