settings = getShortcodeSettings(); $this->pluginname = $this->settings['block']['blockname']; add_action('admin_head', [$this, 'setMCEConfig']); add_filter('mce_external_plugins', [$this, 'addMCEButtons']); add_shortcode( 'downloads', [ $this, 'shortcodeOutput' ]); add_shortcode( 'download', [ $this, 'shortcodeOutput' ]); } public function shortcodeOutput( $atts ) { error_log('Shortcode: ' . print_r($atts, true)); $atts = shortcode_atts([ 'category' => '', "cat" => '', "tags" => '', "type" => 'category', // category, document "format" => 'liste', // table, liste "htmlpre" => '', "htmlpost" => '', "htmlitempre" => '', "htmlitempost" => '', "search_application" => false, "search_image" => false, "search_video" => false, "search_audio" => false, "search_text" => false, "showsize" => false, "showcreated" => false, "showexcerpt" => false, "showcontent" => false, "errormsg" => '', "orderby" => 'title', "sort" => 'asc' ], $atts, 'downloads'); $output = ''; $sp = ' '; $category = esc_attr($atts['category']); $tags = esc_attr($atts['tags']); $format = esc_attr($atts['format']); $type = esc_attr($atts['type']); $htmlpre = esc_attr($atts['htmlpre']); $htmlpost = esc_attr($atts['htmlpost']); $htmlitempre = esc_attr($atts['htmlitempre']); $htmlitempost = esc_attr($atts['htmlitempost']); $errormsg = esc_attr($atts['errormsg']); $orderby = esc_attr($atts['orderby']); $sort = esc_attr($atts['sort']); $search_application = filter_var($atts['search_application'], FILTER_VALIDATE_BOOLEAN); $search_image = filter_var($atts['search_image'], FILTER_VALIDATE_BOOLEAN); $search_video = filter_var($atts['search_video'], FILTER_VALIDATE_BOOLEAN); $search_audio = filter_var($atts['search_audio'], FILTER_VALIDATE_BOOLEAN); $search_text = filter_var($atts['search_text'], FILTER_VALIDATE_BOOLEAN); $showsize = filter_var($atts['showsize'], FILTER_VALIDATE_BOOLEAN); $showcreated = filter_var($atts['showcreated'], FILTER_VALIDATE_BOOLEAN); $showexcerpt = filter_var($atts['showexcerpt'], FILTER_VALIDATE_BOOLEAN); $showcontent = filter_var($atts['showcontent'], FILTER_VALIDATE_BOOLEAN); $orderby = !empty($orderby) && in_array(strtolower($orderby), array('title', 'date')) ? strtolower($orderby) : 'title'; $sort = !empty($sort) && in_array(strtoupper($sort), array('ASC', 'DESC')) ? strtoupper($sort) : 'ASC'; $type = in_array($type, array('category', 'document')) ? $type : 'category'; $category = get_term_by('slug', $category, 'attachment_' . $type); $atts = array('post_type' => 'attachment', 'post_status' => 'any', 'posts_per_page' => -1, 'orderby' => $orderby, 'order' => $sort, 'tax_query' => array(), 'suppress_filters' => true); if ($category) { $catquery = array( 'taxonomy' => 'attachment_' . $type, 'field' => 'id', // can be slug or id - a CPT-onomy term's ID is the same as its post ID 'terms' => $category->term_id, 'include_children' => false ); $atts['tax_query'][] = $catquery; } if ($tags) { $tagquery = array( 'taxonomy' => 'attachment_tag', 'field' => 'slug', 'terms' => explode(',', $tags), ); $atts['tax_query'][] = $tagquery; } $mimetype = array(); if ($search_application == true) { $mimetype[] = 'application'; } if ($search_video == true) { $mimetype[] = 'video'; } if ($search_image == true) { $mimetype[] = 'image'; } if ($search_audio == true) { $mimetype[] = 'audio'; } if ($search_text == true) { $mimetype[] = 'text'; } if (!empty($mimetype)) { $atts['post_mime_type'] = $mimetype; } else { $atts['post_mime_type'] = "application"; } $files = get_posts($atts); if ($files) { $prehtml = ''; $posthtml = ''; if ($format == 'table') { $prehtml = '
' . $errormsg . '
'; } else { $output .= '' . __('Dowloads: Es konnten keine Dateien gefunden werden.', 'rrze-downloads') . '
'; } } return $output; } public function setMCEConfig(){ $shortcode = ''; foreach($this->settings as $att => $details){ if ($att != 'block'){ $shortcode .= ' ' . $att . '=""'; } } $shortcode = '[' . $this->pluginname . ' ' . $shortcode . ']'; ?>