Bagaimana Menambahkan Kolom user_registered di Halaman Authors & Users pada wp-admin WordPress

Suatu hari, saya ingin mengetahui sekaligus mengawasi tanggal pendaftaran pengguna di situs WordPress saya. Atau dengan kata lain, saya perlu mengambil nilai dari field user_registered pada tabel users, lalu menampilkannya ke halaman Authors & Users pada wp-admin dari situs WordPress saya. Saya sudah mencari plugin yang terkait dengan hal ini, tapi saya tidak menemukan satupun. Sebenarnya, saya ingin membuat plugin untuk mengimplementasikannya. Sayangnya, saya masih belum memahami secara detil bagaimana melakukannya, karena saya memang belum pakar di bidang buat-membuat plugin (suatu hari mungkin saya akan bisa membuatnya). Lalu saya memutuskan untuk memodifikasi kode di file utama milik WordPress. Pertama sekali, saya membuka file users.php yang terdapat di dalam sub direktori wp-admin. Setelah menyelidiki selama beberapa menit, saya menemukan kode yang terkait dengan bagaimana cara menampilkan daftar atau senarai pengguna di file lainnya yang bernama template.php, berdasarkan kode atau pemanggilan fungsi user_row dan get_column_headers. File template.php ini terdapat di dalam sub direktori /wp-admin/includes/. Nah, berikut ini modifikasi yang sudah saya buat.

Open your /wp-admin/includes/template.php, lalu temukan kode ini:

899
900
901
902
903
904
905
906
907
		case 'users':
			$_wp_column_headers[$page] = array(
				'cb' => '<input type="checkbox" />',
				'username' => __('Username'),
				'name' => __('Name'),
				'email' => __('E-mail'),
				'role' => __('Role'),
				'posts' => __('Posts')
			);

kemudian timpa kode tersebut dengan kode berikut ini:

899
900
901
902
903
904
905
906
907
908
		case 'users':
			$_wp_column_headers[$page] = array(
				'cb' => '<input type="checkbox" />',
				'username' => __('Username'),
				'name' => __('Name'),
				'email' => __('E-mail'),
				'role' => __('Role'),
				'posts' => __('Posts'),
				'user_registered' => __('Registered Date') // added by Masino Sinaga, January 13, 2010
			);

Cari lagi kode yang ini:

1985
1986
1987
1988
1989
			default:
				$r .= "<td $attributes>";
				$r .= apply_filters('manage_users_custom_column', '', $column_name, $user_object->ID);
				$r .= "</td>";
		}

sebelum baris pertama dari kode tersebut, tambahkan kode berikut ini:

1984
1985
1986
			case 'user_registered':  // added by Masino Sinaga, January 13, 2010
				$r .= "<td $attributes>$user_object->user_registered</td>";
				break;

Itulah semuanya. Sekarang, pergi ke wp-admin dari situs WordPress Anda, lalu buka halaman Authors & Users di bawah menu Users. Seharusnya sekarang Anda sudah melihat sebuah kolom baru di sebelah paling kanan dari daftar atau senarai pengguna yang bernama Registered Date. Saya sudah mencobanya, dan berhasil dengan baik.

Mohon jangan ragu-ragu untuk meninggalkan komentar apabila Anda memiliki suatu ide bagaimana mengimplementasikan modifikasi tersebut di atas dengan menggunakan plugin di WordPress.

Semoga bermanfaat bagi Anda yang membutuhkan.

Diperbaharui pada 5 Oktober 2011: Artikel di atas saya tulis ketika versi WordPress masih di bawah 3.0. Saya menemukan sebuah plugin yang bagus yang dapat melakukan fungsi yang sama di atas. Namanya Recently Registered.

Share

1,840 kali dibacaCetak Artikel Ini Cetak Artikel Ini

Komentar

  1. Luca mengatakan:

    Thanks for the solution.

    Do you think this modification of the core will be interferee with other plugins, or with the wordpress core itself?

  2. Masino Sinaga mengatakan:

    I don’t think so. As long as the other plugins does not have the same purpose with this modification, they will not be interferee with this modification. Let me know if you find the plugin related to this modification.

    Please note that if you upgrade your WordPress to the new version, then you have to apply this modification to the related files as WordPress will overwrite the change you made to the core files. Don’t forget to backup your files before doing that. Thanks.

  3. Roseann mengatakan:

    This worked like a charm. Do you know of any way to enable the sorting of columns?

  4. John Kolbert mengatakan:

    This can all be done with out modifying the core files. WordPress has numerous actions and filters just for this. I’ve done things similar to this on the post/page tables all from a plugin I created for a client. I would hesitate A LOT before editing core files, as you’ll loose them in the upgrades.

  5. Masino Sinaga mengatakan:

    @Roseann

    I will try to find out how to do that. Thanks for the idea.

  6. Masino Sinaga mengatakan:

    @John Kolbert

    I knew about how to add the new column on post/page list. Unfortunately, I still have no idea how to do the similar things for users list page, since the code structure for displaying the users list look like completely different with the code structure for displaying the post/page list. Should you find out the way, please let me know. Thanks.

Utarakan pikiran Anda

*


*