From d16c75d1ad776a127454b0cb4172d01d4c750b9d Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Thu, 11 Apr 2019 16:11:03 -0600 Subject: [PATCH] add sidebar and custom directory widget update transient names, add spectrum tax --- acf-json/group_5c814f3b73fd9.json | 24 ++++++- functions.php | 44 +++++++++++- includes/wasmo-directory-widget.php | 72 ++++++++++++++++++++ page.php | 38 +++++++++++ style.css | 24 ++++++- template-parts/content/content-directory.php | 36 +++++++--- template-parts/sidebar/sidebar.php | 24 +++++++ 7 files changed, 248 insertions(+), 14 deletions(-) create mode 100644 includes/wasmo-directory-widget.php create mode 100644 page.php create mode 100644 template-parts/sidebar/sidebar.php diff --git a/acf-json/group_5c814f3b73fd9.json b/acf-json/group_5c814f3b73fd9.json index 1204423..678c7c0 100644 --- a/acf-json/group_5c814f3b73fd9.json +++ b/acf-json/group_5c814f3b73fd9.json @@ -291,6 +291,28 @@ "ajax": 0, "return_format": "value", "placeholder": "" + }, + { + "key": "field_5cadf1eccb472", + "label": "Spectrum", + "name": "spectrum", + "type": "taxonomy", + "instructions": "Where are you on the spectrum? (add \"labels\" as needed)", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "taxonomy": "spectrum", + "field_type": "multi_select", + "allow_null": 0, + "add_term": 1, + "save_terms": 1, + "load_terms": 1, + "return_format": "id", + "multiple": 0 } ], "location": [ @@ -325,5 +347,5 @@ ], "active": 1, "description": "", - "modified": 1553002733 + "modified": 1554903603 } \ No newline at end of file diff --git a/functions.php b/functions.php index 4d58547..0626dcc 100644 --- a/functions.php +++ b/functions.php @@ -1,5 +1,13 @@ 'edit_posts' ) ); + ); register_taxonomy( "question", array( "post" ), $args ); + + /** + * Taxonomy: Spectrum. + */ + + $labels = array( + "name" => __( "Spectrum", "wasmo" ), + "singular_name" => __( "Spectrum", "wasmo" ), + ); + + $args = array( + "label" => __( "Spectrum", "wasmo" ), + "labels" => $labels, + "public" => true, + "publicly_queryable" => true, + "hierarchical" => false, + "show_ui" => true, + "show_in_menu" => true, + "show_in_nav_menus" => true, + "query_var" => true, + "rewrite" => array( 'slug' => 'spectrum', 'with_front' => true, ), + "show_admin_column" => false, + "show_in_rest" => true, + "rest_base" => "spectrum", + "rest_controller_class" => "WP_REST_Terms_Controller", + "show_in_quick_edit" => false, + ); + register_taxonomy( "spectrum", array( "post", "user" ), $args ); } add_action( 'init', 'cptui_register_my_taxes' ); - function wasmo_widgets_init() { register_sidebar( @@ -240,8 +276,10 @@ function wasmo_update_user( $post_id ) { update_user_meta( $user_id, 'last_save', time() ); // clear directory transients - delete_transient( 'directory-private' ); - delete_transient( 'directory-public' ); + delete_transient( 'directory-private-full' ); + delete_transient( 'directory-public-full' ); + delete_transient( 'directory-private-widget' ); + delete_transient( 'directory-public-widget' ); // update question counts if user includes any if( have_rows( 'questions', 'user_' . $user_id ) ){ diff --git a/includes/wasmo-directory-widget.php b/includes/wasmo-directory-widget.php new file mode 100644 index 0000000..8e319db --- /dev/null +++ b/includes/wasmo-directory-widget.php @@ -0,0 +1,72 @@ + esc_html__( 'wasmo Directory Widget', 'text_domain' ), ) // Args + ); + } + + /** + * Front-end display of widget. + * + * @see WP_Widget::widget() + * + * @param array $args Widget arguments. + * @param array $instance Saved values from database. + */ + public function widget( $args, $instance ) { + echo $args['before_widget']; + if ( ! empty( $instance['title'] ) ) { + echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; + } + set_query_var( 'context', 'widget' ); + get_template_part( 'template-parts/content/content', 'directory' ); + echo $args['after_widget']; + } + + /** + * Back-end widget form. + * + * @see WP_Widget::form() + * + * @param array $instance Previously saved values from database. + */ + public function form( $instance ) { + $title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'Directory', 'text_domain' ); + ?> +

+ + +

+ + +
+
+ + + + +
+
+ 'last_save', 'order' => 'DESC', 'fields' => 'all', - ); + ); + // if ( 'widget' === $context ) { + // $args['number'] = 10; + // } $users = get_users( $args ); $the_directory .= '
'; $the_directory .= '
'; - + $counter = 0; // Array of WP_User objects. foreach ( $users as $user ) { $userid = $user->ID; - // only add to directory if user includes themself and has filled out the first two fields // true = public // private = only to a logged in user @@ -39,11 +52,12 @@ if ( false === ( $the_directory = get_transient( $transient_name ) ) ) { get_field( 'tagline', 'user_' . $userid ) && 'true' === get_field( 'in_directory', 'user_' . $userid ) || 'private' === get_field( 'in_directory', 'user_' . $userid ) && is_user_logged_in() ) { - + + $counter++; $userimg = get_field( 'photo', 'user_' . $userid ); $username = esc_html( $user->nickname ); - $the_directory .= ''; + $the_directory .= ''; $the_directory .= ''; if ( $userimg ) { $the_directory .= wp_get_attachment_image( $userimg, 'medium' ); @@ -54,6 +68,12 @@ if ( false === ( $the_directory = get_transient( $transient_name ) ) ) { $the_directory .= '' . $username . ''; $the_directory .= ''; } + + // only include 9 if a widget + if ( 'widget' === $context && + $counter >= 9 ) { + break; + } } $the_directory .= '
'; $the_directory .= '
'; diff --git a/template-parts/sidebar/sidebar.php b/template-parts/sidebar/sidebar.php new file mode 100644 index 0000000..9ee8f3b --- /dev/null +++ b/template-parts/sidebar/sidebar.php @@ -0,0 +1,24 @@ + + + + +