Commit 784fbd86 authored by John James Jacoby's avatar John James Jacoby
Browse files

Initial commit.

parents
Pipeline #1028 skipped
<?php
/**
* Plugin Name: WP User Title
* Plugin URI: http://wordpress.org/plugins/wp-user-title/
* Author: John James Jacoby
* Author URI: https://profiles.wordpress.org/johnjamesjacoby/
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Description: Titles for WordPress users, powered by WP User Profiles
* Version: 0.1.0
* Text Domain: wp-user-title
* Domain Path: /assets/lang/
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Output the user title field in the "About" box
*
* @since 0.1.0
*
* @param WP_User $user
*/
function wp_user_title_field( $user = null ) {
?>
<table class="form-table">
<tr class="user-title-wrap">
<th><label for="url"><?php esc_html_e( 'Title', 'wp-user-title' ) ?></label></th>
<td>
<input type="title" name="title" id="title" value="<?php echo esc_attr( $user->title ) ?>" class="regular-text" />
<p class="description"><?php esc_html_e( 'Your role, position, or status. This may be shown publicly.', 'wp-user-title' ); ?></p>
</td>
</tr>
</table>
<?php
}
add_action( 'wp_user_profiles_about_metabox_after', 'wp_user_title_field' );
/**
* Maybe save title field
*
* @since 0.1.0
*
* @param array $meta
* @param WP_User $user
* @param bool $update
*/
function wp_user_title_save( $meta = array() ) {
// Maybe add title
if ( ! empty( $_POST['title'] ) ) {
$meta['title'] = wp_kses( $_POST['title'], array() );
}
// Return meta, maybe with title
return $meta;
}
add_filter( 'insert_user_meta', 'wp_user_title_save', 10, 2 );
/**
* If using WP User Directory, output the user's title towards the top
*
* @since 0.1.0
*/
function wp_user_title_directory_meta() {
// Bail if function is missing
if ( ! function_exists( 'wp_user_directory_displayed_user_field' ) ) {
return;
}
// Bail if no title
if ( ! wp_user_directory_get_displayed_user_field( 'title' ) ) {
return;
}
// Output the title
?><small><?php
wp_user_directory_displayed_user_field( 'title' );
?></small><br><?php
}
add_action( 'wp_user_directory_card_meta', 'wp_user_title_directory_meta', 1 );
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment