settings = AA_settings(); $this->tabs = array(); } /** * Set a field id callback handler * * @access public * * @param callback $callback * * @return void */ function setFieldIdCallback( $callback ) { if ( is_callable( $callback ) ) { $this->field_id_callback = $callback; } else { trigger_error( 'Error: callback function is not callable.', E_USER_ERROR ); $this->field_id_callback = null; } } /** * Set a field name callback handler * * @access public * * @param callback $callback * * @return void */ function setFieldNameCallback( $callback ) { if ( is_callable( $callback ) ) { $this->field_name_callback = $callback; } else { trigger_error( 'Error: callback function is not callable.', E_USER_ERROR ); $this->field_name_callback = null; } } /** * Return the field id * * @access protected * * @param string $id * * @return string */ function _getFieldId( $id ) { if ( $this->field_id_callback != null ) { $id = call_user_func( $this->field_id_callback, $id ); } return $id; } /** * Return the field name * * @access protected * * @param string $name * * @return string */ function _getFieldName( $name ) { if ( $this->field_name_callback != null ) { $name = call_user_func( $this->field_name_callback, $name ); } // TODO: remove when core fixed // hack to handle cange in core in WP 4.4 if ( ( strlen( $name ) - 1 ) !== strrpos( $name, ']' ) ) { $name = $name . ']'; } $name = str_replace( ']]', ']', $name ); return $name; } /** * Renders the blog filter select field. * * @param mixed $values the field values * @param string $name the field name * * @return string */ function renderFieldBlogs( $values = array(), $name = 'blogs' ) { $html = ''; if ( $this->settings->blog_selection_allowed() ) { $id = $this->_getFieldId( $name ); $name = $this->_getFieldName( $name ); $html .= '
' . AAFormHelper::choice( $name, Array( - 1 => "All" ) + $this->_getAllBlogs(), $values, array(
'id' => $id,
'multiple' => true,
'label' => '' . __( 'Show users from blogs', 'author-avatars' ) . ':
',
'help' => '
' . __( 'If no blog is selected only users from the current blog are displayed.', 'author-avatars' ) . '',
) ) . '
' . AAFormHelper::input( 'text', $name, $value, $attributes ) . '
'; } /** * Renders the hiddenusers input text field. * * @param string $value the field value * @param string $name the field name * * @return string */ function render_field_white_list_users( $value = '', $name = 'whitelistusers' ) { $attributes = array( 'id' => $this->_getFieldId( $name ), 'label' => '' . __( 'White List of users', 'author-avatars' ) . ':' . AAFormHelper::input( 'text', $name, $value, $attributes ) . '
'; } /** * Renders the set of display options (as it's used in the widget atm) * * @param string $display_values * @param string $name_base * * @return string * @deprecated this is used on the old widget admin should be replaced by the new tab base one... */ function renderDisplayOptions( $display_values = array(), $name_base = 'display' ) { $html = ''; $html .= $this->renderFieldDisplayOptions( $display_values, $name_base ); $html .= $this->renderFieldMaxBioLength( $display_values, $name_base ); $html .= $this->renderFieldUserLink( $display_values, $name_base . '[user_link]' ); $html .= $this->renderFieldOrder( $display_values['order'], $name_base . '[order]' ); $html .= $this->renderFieldSortDirection( $display_values['sort_direction'], $name_base . '[sort_direction]' ); $html .= '' . AAFormHelper::choice( $name, $order_options, $values, $attributes ) . '
'; } /** * Renders the "user_link" dropdown * * @param mixed $values the field values * @param string $name the field name * * @return string */ function renderFieldUserLink( $values = array(), $name = 'user_link' ) { $user_link_options = Array( '' => '-', 'authorpage' => __( 'Author Page', 'author-avatars' ), 'website' => __( 'Website', 'author-avatars' ), 'last_post' => __( 'Users Last Post this blog', 'author-avatars' ), 'last_post_filtered' => __( 'Filtered Last Post', 'author-avatars' ), ); if ( AA_is_bp() ) { $user_link_options['bp_memberpage'] = __( 'BP Member Page', 'author-avatars' ); } if ( class_exists( 'UM_API' ) ) { $user_link_options['um_profile'] = __( 'UM Profile Page', 'author-avatars' ); } if ( AA_is_wpmu() ) { $user_link_options['last_post_all'] = __( 'Users Last Post ALL blogs', 'author-avatars' ); $user_link_options['blog'] = __( 'Blog', 'author-avatars' ); } if ( AA_is_bbpress() ) { $user_link_options['bbpress_memberpage'] = __( 'BBpress Member Page', 'author-avatars' ); } $attributes = array( 'id' => $this->_getFieldId( $name ), 'label' => __( 'Link users to', 'author-avatars' ) . ': ', ); $name = $this->_getFieldName( $name ); return '' . AAFormHelper::choice( $name, $user_link_options, $values, $attributes ) . '
'; } /** * Renders the "order by" dropdown * * @param mixed $values the field values * @param string $name the field name * * @return string */ function renderFieldSortDirection( $values = array(), $name = 'sort_direction' ) { $order_options = Array( 'asc' => __( 'Ascending', 'author-avatars' ), 'desc' => __( 'Descending', 'author-avatars' ) ); $attributes = array( 'id' => $this->_getFieldId( $name ), 'label' => __( 'Sorting direction', 'author-avatars' ) . ': ', ); $name = $this->_getFieldName( $name ); return '' . AAFormHelper::choice( $name, $order_options, $values, $attributes ) . '
'; } /** * Renders the "limit" input field * * @param string $value the field value * @param string $name the field name * * @return string */ function renderFieldLimit( $value = '', $name = 'limit' ) { $attributes = array( 'id' => $this->_getFieldId( $name ), 'label' => __( 'Max. number of avatars shown', 'author-avatars' ) . ': ', 'size' => '5' ); $name = $this->_getFieldName( $name ); return '' . AAFormHelper::input( 'text', $name, $value, $attributes ) . '
'; } /** * Renders the "limit" input field * * @param string $value the field value * @param string $name the field name * * @return string */ function renderPageLimit( $value = '', $name = 'page_size' ) { $attributes = array( 'id' => $this->_getFieldId( $name ), 'label' => __( 'Max. number of avatars per page', 'author-avatars' ) . ': ', 'size' => '5' ); $name = $this->_getFieldName( $name ); return '' . AAFormHelper::input( 'text', $name, $value, $attributes ) . '
'; } /** * Renders the "max bio length" input field * * @param string $value the field value * @param string $name the field name * * @return string */ function renderFieldMaxBioLength( $value = '', $name = 'max_bio_length' ) { $attributes = array( 'id' => $this->_getFieldId( $name ), 'label' => __( 'Trim Bio Length to ', 'author-avatars' ), 'help' => ' characters.', 'size' => '4' ); $name = $this->_getFieldName( $name ); return '' . AAFormHelper::input( 'text', $name, $value, $attributes ) . '
'; } /** * Renders the "min_post_count" input field * * @param string $value the field value * @param string $name the field name * * @return string */ function renderFieldMinPostCount( $value = '', $name = 'min_post_count' ) { $attributes = array( 'id' => $this->_getFieldId( $name ), 'label' => __( 'Required minimum number of posts', 'author-avatars' ) . ': ', 'size' => '5' ); $name = $this->_getFieldName( $name ); return '' . AAFormHelper::input( 'text', $name, $value, $attributes ) . '
'; } /** * Renders the avatar size input field. * * @param string $value the field value * @param string $name the field name * @param bool $preview If set to true (default) the "avatar_size_preview" div is rendered. jQuery UI and "js/widget.admin.js" needs to included in order for this to work. */ function renderFieldAvatarSize( $value = '', $name = 'avatar_size', $preview = true ) { $attributes = array( 'id' => $this->_getFieldId( $name ), 'label' => __( 'Avatar Size', 'author-avatars' ) . ': ', 'help' => 'px', 'class' => 'avatar_size_input', 'size' => '5' ); $name = $this->_getFieldName( $name ); $html = '' . AAFormHelper::input( 'text', $name, $value, $attributes ) . '
'; if ( $preview == true ) { global $user_email; wp_get_current_user(); $html .= '' . AAFormHelper::choice( $name, $type_options, $values, $attributes ) . '
'; } /** * Renders the email/userid input field for the show_avatar wizard * * @param string $value the field value * @param string $name the field name * * @return string */ function renderFieldEmail( $value = '', $name = 'email' ) { $attributes = array( 'id' => $this->_getFieldId( $name ), 'style' => 'width: 95%;', ); $name = $this->_getFieldName( $name ); return AAFormHelper::input( 'text', $name, $value, $attributes ) . ''; } /** * Renders the User pick input field for the show_avatar wizard * * @param string $value the field value * @param string $name the field name * * @return string */ function renderFieldUsers( $values = array(), $name = 'user_id' ) { $attributes = array( 'id' => $this->_getFieldId( $name ), 'label' => '' . __( 'Email address or user id', 'author-avatars' ) . ':' . AAFormHelper::choice( $name, $users, $values, $attributes );
}
/**
* Retrieves all roles, and returns them as an associative array (key -> role name)
*
* @access private
* @return Array of role names.
*/
function _get_all_users( $users = array() ) {
global $wpdb;
$user_data = get_users();
foreach ( $user_data as $key => $user ) {
$users[ "" . $user->ID . "" ] = $user->user_nicename;
}
return $users;
}
/**
* Renders the alignment radio fields for the show_avatar wizard
*
* @param mixed $values the field values
* @param string $name the field name
*
* @return string
*/
function renderFieldAlignment( $values = '', $name = 'alignment' ) {
$alignment_options = array(
'' => __( 'None', 'author-avatars' ),
'left' => __( 'Left', 'author-avatars' ),
'center' => __( 'Center', 'author-avatars' ),
'right' => __( 'Right', 'author-avatars' ),
);
$attributes = array(
'id' => $this->_getFieldId( $name ),
'label' => '' . __( 'Alignment', 'author-avatars' ) . '
',
'expanded' => true,
'inline' => true,
'class' => 'alignment',
);
$name = $this->_getFieldName( $name );
return '
' . AAFormHelper::choice( $name, $alignment_options, $values, $attributes ) . '
'; } /** * Renders an opening tab div * * @param string $title The tab title * @param string $id tab id (optional). Generated from $title if empty. * * @return string */ function renderTabStart( $title, $id = '' ) { if ( empty( $id ) ) { $id = 'tab-' . $title; } $id = AAFormHelper::cleanHtmlId( $id ); if ( isset( $this->tabs[ $id ] ) ) { trigger_error( 'Warning: id "' . $id . '" has already been used as tab identifier.', E_USER_WARNING ); } else { $this->tabs[ $id ] = $title; } return '