| 1 |
<?php |
| 2 |
/** |
| 3 |
* class-groups-shortcodes.php |
| 4 |
* |
| 5 |
* Copyright (c) "kento" Karim Rahimpur www.itthinx.com |
| 6 |
* |
| 7 |
* This code is released under the GNU General Public License. |
| 8 |
* See COPYRIGHT.txt and LICENSE.txt. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* This header and all notices must be kept intact. |
| 16 |
* |
| 17 |
* @author Karim Rahimpur |
| 18 |
* @package groups |
| 19 |
* @since groups 1.0.0 |
| 20 |
*/ |
| 21 |
class Groups_Shortcodes { |
| 22 |
|
| 23 |
/** |
| 24 |
* Adds shortcodes. |
| 25 |
*/ |
| 26 |
public static function init() { |
| 27 |
// group info |
| 28 |
add_shortcode( 'groups_group_info', array( __CLASS__, 'groups_group_info' ) ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Renders information about a group. |
| 33 |
* Attributes: |
| 34 |
* - "group" : group name or id |
| 35 |
* - "show" : what to show, can be "name", "description", "count" |
| 36 |
* |
| 37 |
* @param array $atts attributes |
| 38 |
* @param string $content content to render |
| 39 |
* @return rendered information |
| 40 |
*/ |
| 41 |
public static function groups_group_info( $atts, $content = null ) { |
| 42 |
global $wpdb; |
| 43 |
$output = ""; |
| 44 |
$options = shortcode_atts( |
| 45 |
array( |
| 46 |
'group' => '', |
| 47 |
'show' => '', |
| 48 |
'format' => '', |
| 49 |
'single' => '1', |
| 50 |
'plural' => '%d' |
| 51 |
), |
| 52 |
$atts |
| 53 |
); |
| 54 |
$group = trim( $options['group'] ); |
| 55 |
$current_group = Groups_Group::read( $group ); |
| 56 |
if ( !$current_group ) { |
| 57 |
$current_group = Groups_Group::read_by_name( $group ); |
| 58 |
} |
| 59 |
if ( $current_group ) { |
| 60 |
switch( $options['show'] ) { |
| 61 |
case 'name' : |
| 62 |
$output .= wp_filter_nohtml_kses( $current_group->name ); |
| 63 |
break; |
| 64 |
case 'description' : |
| 65 |
$output .= wp_filter_nohtml_kses( $current_group->description ); |
| 66 |
break; |
| 67 |
case 'count' : |
| 68 |
$user_group_table = _groups_get_tablename( "user_group" ); |
| 69 |
$count = $wpdb->get_var( $wpdb->prepare( |
| 70 |
"SELECT COUNT(*) FROM $user_group_table WHERE group_id = %d", |
| 71 |
Groups_Utility::id( $current_group->group_id ) |
| 72 |
) ); |
| 73 |
if ( $count === null ) { |
| 74 |
$count = 0; |
| 75 |
} else { |
| 76 |
$count = intval( $count ); |
| 77 |
} |
| 78 |
$output .= _n( $options['single'], sprintf( $options['plural'], $count ), $count, GROUPS_PLUGIN_DOMAIN ); |
| 79 |
break; |
| 80 |
} |
| 81 |
} |
| 82 |
return $output; |
| 83 |
} |
| 84 |
} |
| 85 |
Groups_Shortcodes::init(); |
| 86 |
|