commit 3c151eb62bbd9e04dfbf19f0cfa904af61fb8613 Author: Patrick Date: Wed Apr 1 01:57:39 2026 +0200 created plugin and started tag implementation diff --git a/src/admin/admin.php b/src/admin/admin.php new file mode 100644 index 0000000..b4459e3 --- /dev/null +++ b/src/admin/admin.php @@ -0,0 +1,29 @@ +

Theatergruppe Gänserndorf

'; +} + + +add_action('admin_menu', 'TheaterGF\Core\add_admin_menu'); diff --git a/src/media.php b/src/media.php new file mode 100644 index 0000000..3fab685 --- /dev/null +++ b/src/media.php @@ -0,0 +1,205 @@ +parent != 0 ) { + $parts[] = $term->name; + $term = get_term($term->parent, 'ttgf_media_tags'); + } + + if ( $term ) { + $parts[] = $term->name; + } + + return implode('/', array_reverse($parts)); +} + +class MediaManager { + + public function __construct() { + + add_action('init', [ $this, 'register_structure' ]); + + add_filter('attachment_fields_to_edit', [ $this, 'create_edit_media_control' ], 10, 2); + add_action('add_meta_boxes', [ $this, 'create_tag_management_box' ]); + + // Dont know what it does + add_filter( 'update_post_term_count_statuses', function( $statuses, $taxonomy ) { + + if( 'folders' === $taxonomy->name ) { + $statuses[] = 'inherit'; + $statuses = array_unique( $statuses ); + } + return $statuses; + + }, 25, 2 ); + + add_action('restrict_manage_posts', [ $this, 'show_list_filter' ]); + add_filter('pre_get_posts', [ $this, 'apply_list_filter' ]); + } + + public function register_structure() { + register_taxonomy('ttgf_media_tags', 'attachment', [ + 'labels' => [ + 'name' => 'Tags', + 'singular_name' => 'Tag', + 'search_items' => 'Search tags', + 'all_items' => 'All tags', + 'parent_item' => 'Parent tag', + 'edit_item' => 'Edit tags', + 'update_item' => 'Update tags', + 'add_new_item' => 'Add new tag', + 'new_item_name' => 'New tag name', + 'menu_name' => 'Tags', + ], + 'hierarchical' => true, + 'public' => false, + 'show_ui' => false, + 'show_admin_column' => true, + 'rewrite' => false, + 'update_count_callback' => '_update_generic_term_count' + ]); + } + + public function create_tag_management_box() { + add_meta_box( + 'ttgf_media_tags_box', + 'Tags', + [ $this, 'tag_management_meta_box_html' ], + 'attachment', + 'side' + ); + } + + public function tag_management_meta_box_html( $post ) { + $all_terms = get_terms([ + 'taxonomy' => 'ttgf_media_tags', + 'hide_empty' => false, + ]); + $all_tags = build_tag_name($all_terms); + + $terms = get_the_terms($post, 'ttgf_media_tags'); + $tags = build_tag_name($terms); +?> +

Assigned

+ +
+ +
+ +
+ 'ttgf_media_tags', 'hide_empty' => false ]); + + $fields['ttgf_media_tags'] = [ + 'label' => 'Tags', + 'input' => 'html', + 'html' => $this->_build_dropdown("attachments[{$post->ID}][ttgf_media_tags]", + array_map(function ($term) { return [ 'value' => $term->id, 'name' => $term->name ]; }, $terms), + $post->ID) + ]; + + $fields['ttgf_media_hidden'] = [ + 'label' => 'Folder Attributes', + 'input' => 'html', + 'html' => "" + ]; + + return $fields; + } + + public function show_list_filter() { + global $typenow; + + if ( $typenow !== 'attachment' ) { + return; + } + + $selected = isset( $_GET[ 'ttgf_media_folder' ] ) ? $_GET[ 'ttgf_media_folder' ] : false; + wp_dropdown_categories([ + 'show_option_all' => 'All folders', + 'taxonomy' => 'ttgf_media_folder', + 'name' => 'ttgf_media_folder', + 'orderby' => 'name', + 'selected' => $selected, + 'hierarchical' => true, + 'value_field' => 'name', + 'depth' => 3, + 'hide_empty' => true, + ]); + + echo ''; + + + return; + + /*$terms = get_terms([ 'taxonomy' => 'ttgf_media_folder', 'hide_empty' => false ]); + + echo '';*/ + } + + public function apply_list_filter( $query ) { + if ( ! is_admin() || $query->is_main_query() ) { + return; + } + + if (!empty($_GET['media_folder_filter'])) { + $query->set('tax_query', [[ + 'taxonomy' => 'ttgf_media_folder', + 'field' => 'name', + 'terms' => $_GET['ttgf_media_folder'], + ]]); + } + + $show_hidden = isset($_GET['ttgf_media_folder_filter']) && $_GET['ttgf_media_folder_filter'] != "show_hidden"; + $query->set('meta_query', [[ + 'key' => 'ttgf_media_hidden', + 'value' => ( ! $show_hidden), + 'compare' => '!=' + ]]); + } + + private function _build_dropdown( $name, $options, $selected, $empty = true ) { + + $html_options = $empty ? '' : ''; + foreach ( $options as $option ) { + $html_options .= ""; + } + + return ""; + } +} + +new MediaManager(); + diff --git a/theatergf-core.php b/theatergf-core.php new file mode 100644 index 0000000..27f3b32 --- /dev/null +++ b/theatergf-core.php @@ -0,0 +1,27 @@ +