PageRenderTime 54ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/codepress-admin-columns/classes/values/users.php

https://bitbucket.org/antonyravel/cape-resorts
PHP | 159 lines | 87 code | 33 blank | 39 comment | 19 complexity | 5785897ff2ac792d6a7462264bb2f5d4 MD5 | raw file
  1. <?php
  2. /**
  3. * CPAC_Users_Values Class
  4. *
  5. * @since 1.4.4
  6. *
  7. */
  8. class CPAC_Users_Values extends CPAC_Values
  9. {
  10. /**
  11. * Constructor
  12. *
  13. * @since 1.4.4
  14. */
  15. function __construct()
  16. {
  17. parent::__construct();
  18. add_filter( 'manage_users_custom_column', array( $this, 'manage_users_column_value'), 10, 3 );
  19. }
  20. /**
  21. * Manage custom column for Users.
  22. *
  23. * @since 1.1
  24. */
  25. public function manage_users_column_value( $value, $column_name, $user_id )
  26. {
  27. $type = $column_name;
  28. $userdata = get_userdata( $user_id );
  29. if ( ! $userdata )
  30. return false;
  31. // Check for user custom fields: column-meta-[customfieldname]
  32. if ( $this->is_column_meta($type) )
  33. $type = 'column-user-meta';
  34. // Check for post count: column-user_postcount-[posttype]
  35. if ( Codepress_Admin_Columns::get_posttype_by_postcount_column($type) )
  36. $type = 'column-user_postcount';
  37. // Hook
  38. do_action('cpac-manage-users-column', $type, $column_name, $user_id);
  39. $result = '';
  40. switch ($type) :
  41. // user id
  42. case "column-user_id" :
  43. $result = $user_id;
  44. break;
  45. // first name
  46. case "column-nickname" :
  47. $result = $userdata->nickname;
  48. break;
  49. // first name
  50. case "column-first_name" :
  51. $result = $userdata->first_name;
  52. break;
  53. // last name
  54. case "column-last_name" :
  55. $result = $userdata->last_name;
  56. break;
  57. // user url
  58. case "column-user_url" :
  59. $result = $userdata->user_url;
  60. break;
  61. // user registration date
  62. case "column-user_registered" :
  63. $result = $userdata->user_registered;
  64. break;
  65. // user description
  66. case "column-user_description" :
  67. $result = $this->get_shortened_string( get_the_author_meta('user_description', $user_id), $this->excerpt_length );
  68. break;
  69. // user description
  70. case "column-user_postcount" :
  71. $post_type = Codepress_Admin_Columns::get_posttype_by_postcount_column($column_name);
  72. // get post count
  73. $count = Codepress_Admin_Columns::get_post_count( $post_type, $user_id );
  74. // set result
  75. $result = $count > 0 ? "<a href='edit.php?post_type={$post_type}&author={$user_id}'>{$count}</a>" : (string) $count;
  76. break;
  77. // user actions
  78. case "column-actions" :
  79. $result = $this->get_column_value_actions($user_id, 'users');
  80. break;
  81. // user meta data ( custom field )
  82. case "column-user-meta" :
  83. $result = $this->get_column_value_custom_field($user_id, $column_name, 'user');
  84. break;
  85. default :
  86. $result = $value;
  87. endswitch;
  88. // Filter for customizing the result output
  89. apply_filters('cpac-users-column-result', $result, $type, $column_name, $user_id);
  90. return $result;
  91. }
  92. /**
  93. * Get column value of user actions
  94. *
  95. * This part is copied from the Users List Table class
  96. *
  97. * @since 1.4.2
  98. */
  99. private function get_column_value_actions( $id )
  100. {
  101. $actions = array();
  102. $user_object = new WP_User( $id );
  103. $screen = get_current_screen();
  104. if ( 'site-users-network' == $screen->id )
  105. $url = "site-users.php?id={$this->site_id}&amp;";
  106. else
  107. $url = 'users.php?';
  108. if ( get_current_user_id() == $user_object->ID ) {
  109. $edit_link = 'profile.php';
  110. } else {
  111. $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), "user-edit.php?user_id=$user_object->ID" ) );
  112. }
  113. if ( current_user_can( 'edit_user', $user_object->ID ) ) {
  114. $edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";
  115. $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
  116. } else {
  117. $edit = "<strong>$user_object->user_login</strong><br />";
  118. }
  119. if ( !is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) )
  120. $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . "</a>";
  121. if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'remove_user', $user_object->ID ) )
  122. $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url."action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
  123. return implode(' | ', $actions);
  124. }
  125. }
  126. ?>