Пример #1
0
/**
 * Get the activity action
 *
 * @since 0.1.0
 *
 * @param   int    $post
 * @param   array  $meta
 *
 * @return  string
 */
function wp_get_user_activity_ua($post = 0, $meta = array())
{
    // Get the post
    $_post = get_post($post);
    // Get meta if none passed
    if (empty($meta)) {
        $meta = wp_user_activity_get_meta($_post->ID);
    }
    // Get IP address
    $retval = !empty($meta['ua']) ? $meta['ua'] : '—';
    // Filter & return
    return apply_filters('wp_get_user_activity_ua', $retval, $_post, $meta);
}
Пример #2
0
/**
 * Output the activity user metabox
 *
 * Note that this metabox shares a nonce with `wp_user_activity_object_metabox()`
 *
 * @since  0.1.0
*/
function wp_user_activity_user_metabox()
{
    // Get the post
    $post = get_post();
    // Get the metas
    $meta = wp_user_activity_get_meta($post->ID);
    // Query for users
    $users = get_users(array('count_total' => false, 'orderby' => 'display_name'));
    // Start an output buffer
    ob_start();
    ?>

	<table class="form-table rowfat">
		<tr>
			<td>
				<label for="post_author"><?php 
    esc_html_e('User', 'wp-user-activity');
    ?>
</label>
			</td>

			<td>
				<select name="post_author" id="post_author">
					<option value="0"><?php 
    esc_html_e('&mdash; No user &mdash;', 'wp-user-activity');
    ?>
</option>

					<?php 
    foreach ($users as $user) {
        $user->filter = 'display';
        // Prefer first & last name, fallback to display name
        if (!empty($user->first_name) && !empty($user->last_name)) {
            $display_name = "{$user->first_name} {$user->last_name}";
        } else {
            $display_name = $user->display_name;
        }
        ?>

						<option value="<?php 
        echo esc_attr($user->ID);
        ?>
" <?php 
        selected($post->post_author, $user->ID);
        ?>
><?php 
        echo esc_html($display_name);
        ?>
</option>

					<?php 
    }
    ?>

				</select>
			</td>

			<td>
				<label for="wp_user_activity_ip"><?php 
    esc_html_e('IP Address', 'wp-user-activity');
    ?>
</label>
			</td>

			<td>
				<input type="text" class="wp_user_activity_ip" name="wp_user_activity_ip" id="wp_user_activity_ip" value="<?php 
    echo esc_attr($meta['ip']);
    ?>
" /><br>
			</td>
		</tr>

		<tr>
			<td colspan="2">

			</td>

			<td>
				<label for="wp_user_activity_ua"><?php 
    esc_html_e('User Agent', 'wp-user-activity');
    ?>
</label>
			</td>

			<td>
				<textarea class="wp_user_activity_ua" name="wp_user_activity_ua" id="wp_user_activity_ua"><?php 
    echo esc_attr($meta['ua']);
    ?>
</textarea>
			</td>
		</tr>
	</table>

	<?php 
    // End & flush the output buffer
    ob_end_flush();
}
Пример #3
0
/**
 * Output content for each activity item
 *
 * @since 0.1.0
 *
 * @param  string  $column
 * @param  int     $post_id
 */
function wp_user_activity_manage_custom_column_data($column = '', $post_id = 0)
{
    // Get post & metadata
    $post = get_post($post_id);
    $meta = wp_user_activity_get_meta($post_id);
    // Custom column IDs
    switch ($column) {
        // Attempt to output human-readable action
        case 'activity_type':
            echo wp_get_user_activity_type_icon($post, $meta);
            break;
            // User who performed this activity
        // User who performed this activity
        case 'activity_username':
            echo wp_get_user_activity_action($post, $meta);
            break;
            // Session of the user who performed this activity
        // Session of the user who performed this activity
        case 'activity_session':
            echo '<abbr title="' . wp_get_user_activity_ua($post, $meta) . '">' . wp_get_user_activity_ip($post, $meta) . '</abbr>';
            break;
            // Attempt to output helpful connection to object
        // Attempt to output helpful connection to object
        case 'activity_when':
            $when = strtotime($post->post_date);
            $date = get_option('date_format');
            $time = get_option('time_format');
            echo date_i18n($date, $when, true);
            echo '<br>';
            echo date_i18n($time, $when, true);
            break;
    }
}