$item, 'menu_order' => $order++, ) ); } RW_Meta_Box::ajax_response( __( 'Order saved', 'rwmb' ), 'success' ); } /** * Get field HTML * * @param string $html * @param mixed $meta * @param array $field * * @return string */ static function html( $html, $meta, $field ) { $i18n_title = apply_filters( 'rwmb_image_upload_string', _x( 'Upload Images', 'image upload', 'rwmb' ), $field ); $i18n_more = apply_filters( 'rwmb_image_add_string', _x( '+ Add new image', 'image upload', 'rwmb' ), $field ); // Uploaded images $html .= self::get_uploaded_images( $meta, $field ); // Show form upload $html .= sprintf( '

%s

%s
', $i18n_title, $field['id'], $i18n_more ); return $html; } /** * Get HTML markup for uploaded images * * @param array $images * @param array $field * * @return string */ static function get_uploaded_images( $images, $field ) { $reorder_nonce = wp_create_nonce( "rwmb-reorder-images_{$field['id']}" ); $delete_nonce = wp_create_nonce( "rwmb-delete-file_{$field['id']}" ); $classes = array('rwmb-images', 'rwmb-uploaded'); if ( count( $images ) <= 0 ) $classes[] = 'hidden'; $ul = ''; return $html; } /** * Get HTML markup for ONE uploaded image * * @param int $image Image ID * * @return string */ static function img_html( $image ) { $i18n_delete = apply_filters( 'rwmb_image_delete_string', _x( 'Delete', 'image upload', 'rwmb' ) ); $i18n_edit = apply_filters( 'rwmb_image_edit_string', _x( 'Edit', 'image upload', 'rwmb' ) ); $li = '
  • %s | x
  • '; $src = wp_get_attachment_image_src( $image, 'thumbnail' ); $src = $src[0]; $link = get_edit_post_link( $image ); return sprintf( $li, $image, $src, $i18n_edit, $link, $i18n_edit, $i18n_delete, $image ); } /** * Standard meta retrieval * * @param mixed $meta * @param int $post_id * @param array $field * @param bool $saved * * @return mixed */ static function meta( $meta, $post_id, $saved, $field ) { global $wpdb; $meta = RW_Meta_Box::meta( $meta, $post_id, $saved, $field ); if ( empty( $meta ) ) return array(); $meta = implode( ',' , (array) $meta ); // Re-arrange images with 'menu_order' $meta = $wpdb->get_col( " SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND ID in ({$meta}) ORDER BY menu_order ASC " ); return (array) $meta; } } }