PluginProbe
WP Author Slug / 6
WP Author Slug v6
trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.3.0 2 3 4 5 6
wp-author-slug / wp-author-slug.php

wp-author-slug.php in WP Author Slug 6, at wp-author-slug.php

93 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: WP Author Slug
4 * Plugin URI: http://en.wp.obenland.it/wp-author-slug/?utm_source=wordpress&utm_medium=plugin&utm_campaign=wp-author-slug
5 * Description: Rewrites the author url to NOT display the username but the display name
6 * Version: 6
7 * Author: Konstantin Obenland
8 * Author URI: http://en.wp.obenland.it/?utm_source=wordpress&utm_medium=plugin&utm_campaign=wp-author-slug
9 * Text Domain: wp-author-slug
10 * Domain Path: /lang
11 * License: GPLv2
12 *
13 * @package wp-author-slug
14 */
15
16 if ( ! class_exists( 'Obenland_Wp_Plugins_V5' ) ) {
17 require_once 'class-obenland-wp-plugins-v5.php';
18 }
19
20 require_once 'class-obenland-wp-author-slug.php';
21 Obenland_Wp_Author_Slug::get_instance();
22
23 /**
24 * Overwrites the users' nicenames with the users' display name.
25 *
26 * Only runs on activation of plugin.
27 */
28 function wp_author_slug_activation() {
29 $users = get_users(
30 array(
31 'blog_id' => '',
32 'fields' => array( 'ID', 'display_name' ),
33 )
34 );
35
36 $conflicts = array();
37
38 foreach ( $users as $user ) {
39 if ( ! empty( $user->display_name ) ) {
40 $proposed_slug = sanitize_title( $user->display_name );
41
42 // Check for conflicts with existing pages.
43 $existing_page = get_page_by_path( $proposed_slug );
44 if ( $existing_page ) {
45 $conflicts[] = array(
46 'user_id' => $user->ID,
47 'page_id' => $existing_page->ID,
48 );
49 }
50
51 wp_update_user(
52 array(
53 'ID' => $user->ID,
54 'user_nicename' => $proposed_slug,
55 )
56 );
57 }
58 }
59
60 // Store conflicts for admin notices.
61 if ( ! empty( $conflicts ) ) {
62 update_option( 'wp_author_slug_conflicts', $conflicts );
63 }
64 }
65 register_activation_hook( __FILE__, 'wp_author_slug_activation' );
66
67 /**
68 * Restores users' nicenames.
69 *
70 * Only runs on deactivation of plugin.
71 */
72 function wp_author_slug_deactivation() {
73 $users = get_users(
74 array(
75 'blog_id' => '',
76 'fields' => array( 'ID', 'user_login' ),
77 )
78 );
79
80 foreach ( $users as $user ) {
81 wp_update_user(
82 array(
83 'ID' => $user->ID,
84 'user_nicename' => sanitize_title( $user->user_login ),
85 )
86 );
87 }
88
89 // Clean up stored conflicts.
90 delete_option( 'wp_author_slug_conflicts' );
91 }
92 register_deactivation_hook( __FILE__, 'wp_author_slug_deactivation' );
93