Skip to content

Commit

Permalink
Issue #3 - Update bw_user to display gravatar, with author-box style
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Mar 4, 2019
1 parent 360181e commit 95dd736
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 20 deletions.
17 changes: 17 additions & 0 deletions includes/oik-user.inc
Expand Up @@ -55,3 +55,20 @@ function oiku_get_gravatar( $parms ) {
return( $gravatar );
}

/**
* Returns the value of the virtual field follow_me
*
* Displays the follow me social links for the given user.
* The parameters to bw_follow_me are passed through the $atts array
*
* @param $parms - post ID of the post being displayed
* @return string
*/
function oiku_get_follow_me( $parms ) {
oik_require( "shortcodes/oik-follow.php");
$atts = oiku_atts();
bw_push();
$follow_me = bw_follow_me( $atts );
bw_pop();
return $follow_me;
}
16 changes: 13 additions & 3 deletions oik-user.php
Expand Up @@ -3,15 +3,15 @@
Plugin Name: oik user
Plugin URI: https://www.oik-plugins.com/oik-plugins/oik-user
Description: oik lazy smart shortcodes by user ID/name
Version: 0.6.1
Version: 0.7.0
Author: bobbingwide
Author URI: https://www.oik-plugins.com/author/bobbingwide
Text Domain: oik-user
Domain Path: /languages/
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Copyright 2013-2017 Bobbing Wide (email : herb@bobbingwide.com )
Copyright 2013-2019 Bobbing Wide (email : herb@bobbingwide.com )
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -214,11 +214,21 @@ function oiku_oik_fields_loaded() {
$field_args = array( "#callback" => "oiku_get_gravatar"
, "#parms" => ""
, "#plugin" => "oik-user"
, "#file" => "includes/oik-user.php"
, "#file" => "includes/oik-user.inc"
, "#form" => false
, "#hint" => "virtual field"
);
bw_register_field( "gravatar", "virtual", "Gravatar", $field_args );

$field_args = array( "#callback" => "oiku_get_follow_me"
, "#parms" => ""
, "#plugin" => "oik-user"
, "#file" => "includes/oik-user.inc"
, "#form" => false
, "#hint" => "virtual field"
);
bw_register_field( "follow_me", "virtual", "Follow me", $field_args );

}

/**
Expand Down
51 changes: 34 additions & 17 deletions shortcodes/oik-user.php
@@ -1,10 +1,10 @@
<?php // (C) Copyright Bobbing Wide 2013-2016
<?php // (C) Copyright Bobbing Wide 2013-2019

/**
* Register the user field if required
*
* Find the most appropriate field name given the field name that the user typed
* determine it's field type ( if not text ) and the suggested label
* determine its field type ( if not text ) and the suggested label
* and register the field if it's necessary.
*
*
Expand Down Expand Up @@ -65,7 +65,7 @@ function oiku_get_field_type( $name ) {
* Note: For backward compatibility, we retain the original labels for the default field names of the bw_user shortcode; name, bio and email.
*
* If you want to use bw_user for an author-box use `[bw_user fields="gravatar,about,bio" class="author-box"]`
* then use CSS to hide the labels and separators for `gravatar` and `bio` , but not for `about` .
* then use CSS to hide the labels and separators for `gravatar` and `bio` , and maybe not for `about` .
*
* @param string $field the field name
* @return string the label/title for the field
Expand Down Expand Up @@ -105,20 +105,28 @@ function oiku_register_field( $name, $type, $label ) {
*/
function oiku_format_fields( $user, $atts ) {
$fields = bw_array_get_from( $atts, "fields,0", "name,bio,email" );
if ( $fields ) {
$field_arr = explode( ",", $fields );
$field_arr = bw_assoc( $field_arr );
//bw_trace2( $field_arr, "field_arr", false );
foreach ( $field_arr as $field ) {
$name = oiku_map_field( $field );
//e( $name );
$user_meta = get_the_author_meta( $name, $user );
//e ( "User meta: $user_meta!" );
$customfields = array( $name => $user_meta );
sdiv( $name );
//bw_backtrace();
bw_format_meta( $customfields );
ediv( $name );
$field_divs = explode( "/", $fields );
if ( count( $field_divs )) {
foreach ( $field_divs as $key => $fields ) {
$field_classes = str_replace( ",", "-", $fields );
sdiv( "bw_user-fields-$key $field_classes");
if ( $fields ) {
$field_arr = explode( ",", $fields );
$field_arr = bw_assoc( $field_arr );
//bw_trace2( $field_arr, "field_arr", false );
foreach ( $field_arr as $field ) {
$name = oiku_map_field( $field );
//e( $name );
$user_meta = get_the_author_meta( $name, $user );
//e ( "User meta: $user_meta!" );
$customfields = array( $name => $user_meta );
sdiv( $name );
//bw_backtrace();
bw_format_meta( $customfields );
ediv( $name );
}
}
ediv();
}
} else {
p( "Invalid fields= parameter for bw_user shortcode" );
Expand All @@ -136,6 +144,7 @@ function oiku_format_fields( $user, $atts ) {
* @return string generated HTML
*/
function oiku_user( $atts=null, $content=null, $tag=null ) {
oiku_atts( $atts );
$id = bw_default_user( false );
$user_id = bw_array_get_dcb( $atts, "user", null );
if ( $user_id ) {
Expand Down Expand Up @@ -464,6 +473,14 @@ function oiku_users( $atts=null, $content=null, $tag=null ) {
return( bw_ret() );
}

function oiku_atts( $atts=null ) {
static $saved_atts = [];
if ( null !== $atts ) {
$saved_atts = $atts;
}
return $saved_atts;
}

/**
* Implement help hook for [bw_users]
*/
Expand Down

0 comments on commit 95dd736

Please sign in to comment.