Cara Merubah Hak Akses WordPress User

Image representing MySQL as depicted in CrunchBase

Omje lagi nyari cara gimana merubah hak akses user di blog wordpress. Kebetulan ane baru aja bikinin website buat klien, trus Omje pingin ngatur apa aja yang tampil dan tidak di halaman admin klien. Kebetulan websitenya adalah toko online yang ane bikin pake plugin wp ecommerce.

Sebenernya wordpress sendiri udah ngasih fasilitas utk ngatur hak akses untuk user ini, pengaturannya ada di halaman admin/users. Disitu ada 5 jenis user role capabilities: administrator, author, editor, contributor, & subscriber. Nah, masalahnya Omje ga suka default settingnya, karena ga bisa kita atur sesuka kita capabilities ditiap usernya. Misalnya, conto ekstrimnya, Omje pengen merubah user jenis “Subscriber” bisa memiliki hak akses seperti user “Administrator”, heu3..hayo, gimana coba caranya🙂

Omje udah nyoba berbagai macam plugin, cuman tetep ajah ada yang ga bisa mereka lakukan. Wabilkhusus website toko online dengan wordpress yang dipasangin plugin wp e commerce. Beuuh..itu yang namanya bandel, bener2 bandel abis..bedegong kacida tuh si wp ecommerce. Soalnya, walowpun udah dipasangin plugin utk ngedit user role capabilities, tapi beberapa fitur plugin wp ecommerce teteup ga bisa tersentuh.

Akhirnya, dengan sangat terpaksa dan bercucuran air mata, Omje melakukan jalan kekerasan. Hehe..lebay! Yaitu dengan mengotak atik database SQLnya lewat phpmyadmin. Dan alhamdulillah berhasil, bahkan bisa ngerubah user “Subscriber” berkemampuan “Administrator”, bahkan semua fitur plugin wp ecommerce bisa muncul di user “Subscriber”. Rasain tuh!🙂

Bagaimana caranya? Ni dia caranya, Omje copy paste & ane kasih juga link url sumbernya. Baca sampe tamat yah. Selamat mencoba🙂

——————————————————————————-

First of all, user roles data are stored in the MySQL database table which is named ‘wp_options’ by default. You need to have one of MySQL client software (MyPHPAdmin, MySQLyog, etc.) to connect to your blog MySQL database and go ahead with text of this post further.
This SQL command help you find the record containing information about WordPress user roles:

SELECT * FROM wp_options WHERE option_name="wp_user_roles"

As the result we can see that user roles data is stored in the option_value field as the text string of the special format. To be exact, it is a format which can be used to read from and write to the PHP array.

a:5:{
s:13:"administrator";a:2:{s:4:"name";s:13:"Administrator";s:12:"capabilities";a:54:{s:13:"switch_themes";b:1;s:11:"edit_themes";b:1;s:16:"activate_plugins";b:1;s:12:"edit_plugins";b:1;s:10:"edit_users";b:1;s:10:"edit_files";b:1;s:14:"manage_options";b:1;s:17:"moderate_comments";b:1;s:17:"manage_categories";b:1;s:12:"manage_links";b:1;s:12:"upload_files";b:1;s:6:"import";b:1;s:15:"unfiltered_html";b:1;s:10:"edit_posts";b:1;s:17:"edit_others_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:10:"edit_pages";b:1;s:4:"read";b:1;s:8:"level_10";b:1;s:7:"level_9";b:1;s:7:"level_8";b:1;s:7:"level_7";b:1;s:7:"level_6";b:1;s:7:"level_5";b:1;s:7:"level_4";b:1;s:7:"level_3";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:17:"edit_others_pages";b:1;s:20:"edit_published_pages";b:1;s:13:"publish_pages";b:1;s:12:"delete_pages";b:1;s:19:"delete_others_pages";b:1;s:22:"delete_published_pages";b:1;s:12:"delete_posts";b:1;s:19:"delete_others_posts";b:1;s:22:"delete_published_posts";b:1;s:20:"delete_private_posts";b:1;s:18:"edit_private_posts";b:1;s:18:"read_private_posts";b:1;s:20:"delete_private_pages";b:1;s:18:"edit_private_pages";b:1;s:18:"read_private_pages";b:1;s:12:"delete_users";b:1;s:12:"create_users";b:1;s:17:"unfiltered_upload";b:1;s:14:"edit_dashboard";b:1;s:14:"update_plugins";b:1;s:14:"delete_plugins";b:1;s:15:"install_plugins";b:1;s:13:"update_themes";b:1;s:14:"install_themes";b:1;}}
s:6:"editor";a:2:{s:4:"name";s:6:"Editor";s:12:"capabilities";a:34:{s:17:"moderate_comments";b:1;s:17:"manage_categories";b:1;s:12:"manage_links";b:1;s:12:"upload_files";b:1;s:15:"unfiltered_html";b:1;s:10:"edit_posts";b:1;s:17:"edit_others_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:10:"edit_pages";b:1;s:4:"read";b:1;s:7:"level_7";b:1;s:7:"level_6";b:1;s:7:"level_5";b:1;s:7:"level_4";b:1;s:7:"level_3";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:17:"edit_others_pages";b:1;s:20:"edit_published_pages";b:1;s:13:"publish_pages";b:1;s:12:"delete_pages";b:1;s:19:"delete_others_pages";b:1;s:22:"delete_published_pages";b:1;s:12:"delete_posts";b:1;s:19:"delete_others_posts";b:1;s:22:"delete_published_posts";b:1;s:20:"delete_private_posts";b:1;s:18:"edit_private_posts";b:1;s:18:"read_private_posts";b:1;s:20:"delete_private_pages";b:1;s:18:"edit_private_pages";b:1;s:18:"read_private_pages";b:1;}}
s:6:"author";a:2:{s:4:"name";s:6:"Author";s:12:"capabilities";a:10:{s:12:"upload_files";b:1;s:10:"edit_posts";b:1;s:20:"edit_published_posts";b:1;s:13:"publish_posts";b:1;s:4:"read";b:1;s:7:"level_2";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:12:"delete_posts";b:1;s:22:"delete_published_posts";b:1;}}
s:11:"contributor";a:2:{s:4:"name";s:11:"Contributor";s:12:"capabilities";a:5:{s:10:"edit_posts";b:1;s:4:"read";b:1;s:7:"level_1";b:1;s:7:"level_0";b:1;s:12:"delete_posts";b:1;}}
s:10:"subscriber";a:2:{s:4:"name";s:10:"Subscriber";s:12:"capabilities";a:2:{s:4:"read";b:1;s:7:"level_0";b:1;}}}

Here we see that:

    • a:number:{ is the begin of array and “number” is the number of array elements. For example “a:5:{” at the begin of the string means that roles array consists of 5 element. Remember that WordPress has exactly 5 roles.
    • s:number:"string"; – “s” is the type of string element, number is the quant of chars in the string. E.g. s:6:"author";
    • b:1; – means the Boolean element with value “1″ or “True”

That’s almost all. We can see that capabilities are stored inside roles in the “Name-Boolean value” format. Now we should to find the “unfiltered_html” capability in the “Editor” role, copy the sequence s:15:"unfiltered_html";b:1; from there and paste it into the “Author” role, just after s:12:"upload_files";b:1; capability. To finish the role change we have to increase to 1 the quant of elements in the “Author” role array. By default the “Author” role has 10 capabilities or in this special format a:10:{s:12:"upload_files". To finish the role update we need to change 10 to 11, and finally have this a:11:{s:12:"upload_files" inside the “Author” role.
What is left? Just update MySQL table wp_options to store your changes. Use this SQL command for that:

 UPDATE `wp_options` 
SET option_value='changed value here' WHERE option_id=NN;

Do not forget to replace ‘changed value here’ with modified user roles data from the previous query and ‘NN’ on the wp_options table record Id from the same query.
Warning! Make a backup of wp_options table first. Just after making the fresh backup go ahead with any update SQL command.

Congratulations, we changed WordPress user role without change the line of PHP code.

——————————————————————————-

Nah, itu dia tutorialnya. Dan ini link url sumbernya:

How to change WordPress User Role capabilities | ShinePHP.com.

NOTE:

Omje coba di WordPress 3.3.1, theme Tokoonline dari Tokokoo, dan plugin WP e Commerce 3.8.8.3

4 responses to this post.

  1. Posted by indra on 26/07/2012 at 10:04

    punya theme gratisan gax om ???

    Reply

    • Posted by omje on 26/07/2012 at 10:11

      maksudnya theme wp ecommerce ya sob?
      itu mah banyak di internet, coba tanya ke mang gugel🙂
      ane dapetnya juga dari dia..kebanyakan sih yg ngasih free theme dari Tokokoo, orang2 bandung tuh..ane pernah ketemu sama orang2nya, hebadd lah🙂

      Reply

      • Posted by indra on 30/07/2012 at 09:30

        owhh gitu ye…
        ok siipp…
        ane mau nanya klo user bisa mengedit kaya admin gmna?
        contohnya kaya blogdetik.com😀

      • Posted by omje on 01/05/2013 at 15:52

        nah, kalo yg itu belom ane coba gan🙂
        barangkali yg lain ada yg pnya pngalaman utk dshare?

Balas

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s