From 36ebf79294c1ba4d677e774e4fde52368d326ec9 Mon Sep 17 00:00:00 2001 From: jorge-vitrubio Date: Mon, 18 Jul 2022 16:01:57 +0200 Subject: [PATCH] added hangar plugin with support for svg, category and tags in pages --- assets/css/hangar-wpplugin--styles.css | 0 assets/css/hangar-wpplugin-styles.css | 5 + hangar-wp-plugin.php | 63 ++++++++++ includes/hangar-enable-svg.php | 26 ++++ includes/hangar-plugin-init-textdomain.php | 25 ++++ includes/hangar-stylesheet-admin.php | 26 ++++ includes/hangar-stylesheet-public.php | 26 ++++ includes/hangar-tags-and-pages.php | 109 +++++++++++++++++ includes/hangar-tags-category-shortcode.php | 127 ++++++++++++++++++++ uninstall.php | 23 ++++ 10 files changed, 430 insertions(+) create mode 100644 assets/css/hangar-wpplugin--styles.css create mode 100644 assets/css/hangar-wpplugin-styles.css create mode 100644 hangar-wp-plugin.php create mode 100644 includes/hangar-enable-svg.php create mode 100644 includes/hangar-plugin-init-textdomain.php create mode 100644 includes/hangar-stylesheet-admin.php create mode 100644 includes/hangar-stylesheet-public.php create mode 100644 includes/hangar-tags-and-pages.php create mode 100644 includes/hangar-tags-category-shortcode.php create mode 100644 uninstall.php diff --git a/assets/css/hangar-wpplugin--styles.css b/assets/css/hangar-wpplugin--styles.css new file mode 100644 index 0000000..e69de29 diff --git a/assets/css/hangar-wpplugin-styles.css b/assets/css/hangar-wpplugin-styles.css new file mode 100644 index 0000000..9e73b76 --- /dev/null +++ b/assets/css/hangar-wpplugin-styles.css @@ -0,0 +1,5 @@ +/* hangar wp plugin styles +* +* css styles +* +*/ diff --git a/hangar-wp-plugin.php b/hangar-wp-plugin.php new file mode 100644 index 0000000..bde595d --- /dev/null +++ b/hangar-wp-plugin.php @@ -0,0 +1,63 @@ + + */ + + function hangar_enable_mime_types( $mimes ) { + $mimes['svg'] = 'image/svg+xml'; + return $mimes; + } + add_filter('upload_mimes', 'hangar_enable_mime_types'); diff --git a/includes/hangar-plugin-init-textdomain.php b/includes/hangar-plugin-init-textdomain.php new file mode 100644 index 0000000..9699a4b --- /dev/null +++ b/includes/hangar-plugin-init-textdomain.php @@ -0,0 +1,25 @@ + + */ + +function hangar_init_textdomain() { + load_plugin_textdomain( 'hangar-wpplugin', null, plugin_dir_path( __FILE__ ).'/assets/languages/' ); +} +add_action('plugins_loaded', 'hangar_init_textdomain'); diff --git a/includes/hangar-stylesheet-admin.php b/includes/hangar-stylesheet-admin.php new file mode 100644 index 0000000..0a794ce --- /dev/null +++ b/includes/hangar-stylesheet-admin.php @@ -0,0 +1,26 @@ + + */ + +function hangar_admin_styles() { + add_editor_style( 'assets/css/hangar-wpplugin-admin-styles.css' ); +} +add_action( 'admin_init', 'hangar_admin_styles' ); diff --git a/includes/hangar-stylesheet-public.php b/includes/hangar-stylesheet-public.php new file mode 100644 index 0000000..8e96286 --- /dev/null +++ b/includes/hangar-stylesheet-public.php @@ -0,0 +1,26 @@ + + */ + +function hangar_public_styles() { + add_editor_style( 'assets/css/hangar-wpplugin-styles.css' ); +} +add_action( 'admin_init', 'hangar_public_styles' ); diff --git a/includes/hangar-tags-and-pages.php b/includes/hangar-tags-and-pages.php new file mode 100644 index 0000000..cf08a30 --- /dev/null +++ b/includes/hangar-tags-and-pages.php @@ -0,0 +1,109 @@ + +Original Author URI: https://burobjorn.nl +******************************************************************************/ + +/* Copyright 2012 +Tag Pages is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +Tag Pages is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +/** + * Add the 'post_tag' taxonomy, which is the name of the existing taxonomy + * used for tags to the Post type page. Normally in WordPress Pages cannot + * be tagged, but this let's WordPress treat Pages just like Posts + * and enables the tags metabox so you can add tags to a Page. + * NB: This uses the register_taxonomy_for_object_type() function which is only + * in WordPress 3 and higher! + */ + +// add tag and category support to pages +if( ! function_exists ('hangar_category_tags_support_all') ){ + function hangar_category_tags_support_all() + { + register_taxonomy_for_object_type('post_tag', 'page'); + register_taxonomy_for_object_type('category', 'page'); + } + add_action('init', 'hangar_category_tags_support_all'); +} + +// ensure all pages are included in tag and category queries +if( ! function_exists ('hangar_category_tags_support_query') ){ + function hangar_category_tags_support_query($wp_query) { + if ($wp_query->get('tag')) $wp_query->set('post_type', 'any'); + if ($wp_query->get('category')) $wp_query->set('post_type', 'any'); + } + add_action('pre_get_posts', 'hangar_category_tags_support_query'); +} + +/** + * Display all post_types on the tags archive page. This forces WordPress to + * show tagged Pages together with tagged Posts. Thanks to Page Tagger by + * Ramesh Nair: http://wordpress.org/extend/plugins/page-tagger/ + */ +if( ! function_exists('hangar_tagpages_display_tagged_pages_archive') ){ + function hangar_tagpages_display_tagged_pages_archive(&$query) + { + if ( !is_admin() && $query->is_archive && $query->is_tag ) { + $q = &$query->query_vars; + $q['post_type'] = 'any'; + } + } + add_action('pre_get_posts', 'hangar_tagpages_display_tagged_pages_archive'); +} + + +// show category using shortcode +// https://stackoverflow.com/a/13996873 +if( ! function_exists('hangar_show_categoriced') ){ + function hangar_show_categoriced() + { + add_shortcode('hangar-catlist', function($atts, $content) { + $atts += array('category' => 1); + $posts = get_posts("category={$atts['category']}"); + + foreach ($posts as $post) { + echo $post->post_name . '
'; + } + }); + echo do_shortcode('[hangar-catlist category=5]'); + } +} +if( ! function_exists('hangar_show_tagged') ){ + function hangar_show_tagged() + { + add_shortcode('hangar-taglist', function($atts, $content) { + $atts += array('tag' => 1); + $posts = get_posts("tag={$atts['tag']}"); + + foreach ($posts as $post) { + echo $post->post_name . '
'; + } + }); + echo do_shortcode('[hangar-taglist tag=5]'); + } +} diff --git a/includes/hangar-tags-category-shortcode.php b/includes/hangar-tags-category-shortcode.php new file mode 100644 index 0000000..936c6ae --- /dev/null +++ b/includes/hangar-tags-category-shortcode.php @@ -0,0 +1,127 @@ + 'cat-post', + 'totalposts' => '-1', + 'category' => '', + 'thumbnail' => 'false', + 'thumbnail_height' => '130', + 'thumbnail_width' => '130', + 'date' => 'false', + 'excerpt' => 'true', + 'orderby' => 'post_date', + 'order' => 'desc' + ), $atts)); + + $output = '
'; + global $post; +$tmp_post = $post; + $myposts = get_posts("numberposts=$totalposts&category=$category&orderby=$orderby&order=$order"); + + foreach($myposts as $post) { + setup_postdata($post); + $output .= '
'; + if($thumbnail == 'true') { + $thumb_image = get_post_meta($post->ID, 'thumbnail-url',true); + if(empty($thumb_image)){ + preg_match_all('//i', $post->post_content, $matches); + $thumb_image = $matches [1] [0]; + } + if(empty($thumb_image)){ + $thumb_image =''; + } + + $output .= '
'; + } + $output .= '
'.get_the_title().''; + if ($date == 'true') { + $output .= ''; + } + if ($excerpt == 'true') { + $output .= ''.get_the_excerpt().''; + } + $output .= '
+
+
'; + }; + $output .= '
'; + $post = $tmp_post; + wp_reset_query(); + return $output; +} +add_shortcode('cat', 'cat_func'); + +?> diff --git a/uninstall.php b/uninstall.php new file mode 100644 index 0000000..9c8534c --- /dev/null +++ b/uninstall.php @@ -0,0 +1,23 @@ +query("DROP TABLE IF EXISTS {$wpdb->prefix}mytable"); + +?>