diff --git a/classes/PodsMeta.php b/classes/PodsMeta.php index eb4586ca90..f1be92c185 100644 --- a/classes/PodsMeta.php +++ b/classes/PodsMeta.php @@ -304,11 +304,28 @@ public function core () { if ( function_exists( 'pll_current_language' ) ) add_action( 'init', array( $this, 'cache_pods' ), 101 ); + // Priority 20 because PodsInit has priority 15 + add_action( 'admin_enqueue_scripts', array( $this, 'assets' ), 20 ); + add_action( 'wp_enqueue_scripts', array( $this, 'assets' ), 20 ); + do_action( 'pods_meta_init' ); return $this; } + /** + * Add styles and scripts globally or conditionally + * @since 2.6.8 + */ + public function assets() { + + // Add Pods form styles to the Media Library + if ( is_admin() && get_current_screen()->base == 'upload' ) { + wp_enqueue_style( 'pods-form' ); + //wp_enqueue_script( 'pods' ); + } + } + public static function enqueue () { foreach ( self::$queue as $type => $objects ) { foreach ( $objects as $pod_name => $pod ) { @@ -1301,6 +1318,46 @@ public function meta_media ( $form_fields, $post ) { } } + /** + * Add hierarchical taxonomies as checkboxes + * Based on Enhanced Media Library + */ + if ( function_exists( 'wp_terms_checklist' ) ) { + foreach ( $form_fields as $field => $args ) { + if ( ! empty( $args[ 'hierarchical' ] ) && ( ! isset( $form_fields[ $field ][ 'input' ] ) || $form_fields[ $field ][ 'input' ] != 'html' ) ) { + + ob_start(); + + wp_terms_checklist( $post->ID, array( 'taxonomy' => $field, 'checked_ontop' => false ) ); + + $content = ob_get_contents(); + + if ( $content ) { + $html = ''; + } else { + $html = ''; + } + + ob_end_clean(); + + /** + * Ensure data is send and saved. + * Default array structures not working in update + * @todo file bug at WP trac? + */ + $counter = 0; + while( false !== strpos( $html, '['.$field.'][]' ) ) { + $html = preg_replace( '/\['.$field.'\]\[\]/', '['.$field.']['.($counter++).']', $html, 1 ); + } + + unset( $form_fields[ $field ][ 'value' ] ); + + $form_fields[ $field ][ 'input' ] = 'html'; + $form_fields[ $field ][ 'html' ] = $html; + } + } + } + $form_fields = apply_filters( 'pods_meta_' . __FUNCTION__, $form_fields ); return $form_fields; @@ -1414,6 +1471,24 @@ public function save_media_ajax () { if ( empty( $_REQUEST[ 'attachments' ][ $id ] ) ) $_REQUEST[ 'attachments' ][ $id ][ '_fix_wp' ] = 1; + + /** + * Update taxonomies when changed to checkboxes in the attachment modal + * @since 2.6.8 + */ + if ( ! empty( $_POST['tax_input'] ) ) { + foreach ( $_POST['tax_input'] as $tax => $terms ) { + /** + * Validate for an array + * Otherwise we didn't change this functionality since this is a string by default in WP core + */ + if ( is_taxonomy_hierarchical( $tax ) && is_array( $terms ) ) { + $tax = sanitize_title( $tax ); + $terms = array_map( 'intval', $terms ); + wp_set_post_terms( $id, $terms, $tax ); + } + } + } } /** diff --git a/ui/css/pods-form.css b/ui/css/pods-form.css index a88aa4ccfb..5892406e94 100644 --- a/ui/css/pods-form.css +++ b/ui/css/pods-form.css @@ -311,3 +311,23 @@ input.pods-form-ui-field-type-color { clear: both; display: block; } + +/** + * Modal fields + */ +.media-modal .compat-item .pods-term-list { + margin: 0; + padding: 3px; + background: #fff; + border: 1px solid #dfdfdf; +} +.media-modal .compat-item .pods-term-list input { + vertical-align: text-bottom; + margin: 3px 3px 0; +} +.media-modal .compat-item .pods-term-list > li:last-child { + margin-bottom: 3px; +} +.media-modal .compat-item .pods-term-list ul.children { + margin: 6px 0 0 18px; +} \ No newline at end of file