$item, 'menu_order' => $order++, ) ); } anim8_Meta_Box::ajax_response( __( 'Order saved', 'anim8' ), 'success' ); } /** * Get field HTML * * @param string $html * @param mixed $meta * @param array $field * * @return string */ static function html( $html, $meta, $field ) { $i18n_title = _x( 'Upload images', 'image upload', 'anim8' ); $i18n_more = _x( '+ Add new image', 'image upload', 'anim8' ); $html = wp_nonce_field( "anim8-delete-file_{$field['id']}", "nonce-delete-file_{$field['id']}", false, false ); $html .= wp_nonce_field( "anim8-reorder-images_{$field['id']}", "nonce-reorder-images_{$field['id']}", false, false ); $html .= ""; // Uploaded images if ( ! empty( $meta ) ) $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 ) { $html = ''; return $html; } /** * Get HTML markup for ONE uploaded image * * @param int $image Image ID * @param int $field_id Field ID, used to delete action * * @return string */ static function img_html( $image, $field_id ) { $i18n_delete = _x( 'Delete', 'image upload', 'anim8' ); $i18n_edit = _x( 'Edit', 'image upload', 'anim8' ); $li = '
  • %s | %s
  • '; $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, $field_id, $image, $i18n_delete ); } /** * 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 = anim8_Meta_Box::meta( $meta, $post_id, $saved, $field ); if ( empty( $meta ) ) return array(); $meta = implode( ',' , $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; } } }