#52: Custom CSS PlugIn for Wordpress MU
Beberapa hari yang lalu, atas saran seorang teman, dan bantuan teman yang lain, akhirnya sukses juga meng-install Wordpress MU (multi-users). Rencananya sih dipake untuk ngeblog rame-rame di intranet. Biasa … begitu ada mainan baru, langsung tertarik untuk ngoprek :p). Setelah baca-baca dan berkunjung ke forum, baru tahu kalo ternyata wordpress MU tidak sama persis dengan wordpress (biasa), dalam hal pengaturan Theme. Kalau di wordpress (seperti yang ada disini juga, blogsome), theme bisa dimodifikasi dengan leluasa oleh masing-masing user. Di wordpress MU, theme disediakan di satu direktori, dan digunakan secara bersama-sama oleh semua user. User hanya bisa memilih theme mana yang akan dipakai, tetapi tidak bisa meng-customize-nya lebih jauh.
Some days ago, based on a friend’s suggestion, and a help from another friend, finally our Wordpress MU (multi-users) had been installed. The plan is using that for blogging activities via our intranet. Like another day … if there is a new toy, there is an adrenaline to hack (learn more about) it :p) After googling and reading from forum, just found that wordpress MU is not really identic with wordpress, especially when talking about theme setting feature. Wordpress MU using a “public” theme. Users can only select one of them, but can not customize it.
Nah, berangkat dari situ, akhirnya baca-baca lebih jauh dech mengenai wordpress MU. Karena semuanya ditulis dalam PHP, lebih mudah buat dimengerti. Tujuannya adalah untuk menambahkan fitur Edit Theme seperti yang ada di wordpress biasa. Setelah ketemu, percobaan pertama sukses dilakukan dengan langsung melakukan perubahan coding di beberapa file PHP core-nya wordpress. Tapi kemudian kepikiran mengenai masalah security, karena sebagian besar file template theme ditulis dalam format PHP. Karena semua user wordpress MU pada prinsipnya memiliki level yang sama, maka menyediakan fasilitas untuk mengedit sendiri file PHP bagi user akan menjadi bumerang.
Starting from that, I read more about wordpress MU. The core is written using PHP, make it more easy. My goal is to add a feature like wordpress’ Edit Theme. After knowing how to do it, my first success attempt is by modifying the core code. But then, I think about the security issues, because almost all template files is written in PHP. In principe, all wordpress MU users are having a same level. So, providing a feature to modify the PHP file is very dangerous.
Setelah dipikir-pikir lagi, akhirnya mendhing menggunakan konsep Custom CSS (yang ternyata ada juga di wordpress). Dengan fitur ini, user “hanya” boleh mengedit file CSS (style.css), yang artinya memberi kebebasan ke user untuk mengatur semua parameter CSS bawaan dari theme. Tetap bermanfa’at, terutama untuk memenuhi selera user terhadap format, warna, atau image yang disediakan oleh theme yang sudah dipilih. Dengan fitur ini, mereka bisa mengubahnya sesuka hati mereka.
Thinking and rethinking … and then decide, not to do that, but providing Custom CSS (actually it also used by wordpress). With this feature, users can only modify the CSS (style css), which means giving them a freedom to overwrite the default CSS parameters from the selected theme. Still useful, especially to them who like to change the defaul format, color, or image from their lovely theme. They can do that with this feature.
Browsing lagi di internet, dan akhirnya kepikir tentang plugins. Ternyata fitur ini bisa juga disediakan dengan menggunakan konsep plugins. Perbedaannya adalah, core PHP tidak perlu diubah, sehingga bisa lebih rapi. Setelah baca-baca contoh dari hello.php, akhirnya berhasil-lah bikin plugins pertama untuk wordpress MU. Kalau plugins ini dicopy di folder mu-plugins, maka dia akan dijalankan secara otomatis tanpa perlu ada proses aktifasi dulu. Mantab dech … :p)
Browsing more … and then found about plugins. Fortunately, that feature can also be done by plugins. The main difference is using plugins we do not need to modify the core code. Make it more clean. After looking at the hello.php, finally, my first plugins for wordpress MU is ready. If it is copied to the mu-plugins folder, then it will be called automatically by wordpress MU, no activation process needed. Great … :p)
Tertarik?
Download saja file ini, extract, lalu copy file ccss.php ke folder wp-content/mu-plugins Anda. Dan juga copy file wpmu-custom-css.php ke folder wp-admin.
Interested?
Just download this file, extract, then copy the ccss.php file to your wp-content/mu-plugins folder. And also copy wpmu-custom-css.php file into your wp-admin folder.
Semoga bermanfa’at,
Hope it is usefull,

p.s. I also commented in the wpmu forums…
I tested this and as all other similar solutions, it has one point of failure as far as I can see:
It just assumes the file structure exists already, i.e. in my case I get all these warnings:
Warning: filesize() [function.filesize]: stat failed for /var/www/web5/web/wp-content/blogs.dir/1/files/themes/edu-clean_style.css in /var/www/web5/web/wp-admin/wpmu-custom-css.php on line 57
Custom CSS Files
Warning: opendir(/var/www/web5/web/wp-content/blogs.dir/1/files/themes) [function.opendir]: failed to open dir: No such file or directory in /var/www/web5/web/wp-admin/wpmu-custom-css.php on line 85
* No file found !
Having said that I would like the plugin to create the structure if not found, can we do that? I mean most of my blogs, arecreated, then users start browsing through the backend, without first uploading anything, so …blogs.dir/BLOG_ID/ exists but the rest of the structure doesn’t.
Comment by ovidiu — 12 October 2008 @ 5:53 pm
1. It’s look like your PHP.ini warning is turning ON.
2. OK, I did modify the wpmu-custom-css.php to eliminate that ‘error’ (filesize and opendir).
3. I also modify some algorithm, so only main style file (themefoldername_style.css) is allowed.
Please re-download it, and try again …
Comment by rizapn — 12 October 2008 @ 6:05 pm