wordpress

How to create custom table from plugin in WordPress 3

27 Nov , 2011  

When creating plugin, we need to create a custom table. We will use register hook activation, de-activation and uninstall to handle database creation and removal. Now, we start with database created automatically when plugin installed / activated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/* Register installation into hook */
register_activation_hook(__FILE__, 'your_plugin_install');

/* Install montage SQL into database */
function your_plugin_install() {
    global $wpdb;
    $table_name = $wpdb->prefix.'your-table';

    $sql = "CREATE TABLE IF NOT EXISTS ". $table_name . " (
            id int(11) NOT NULL AUTO_INCREMENT,
            name varchar(255) binary DEFAULT NULL,
            PRIMARY KEY (id)
            ) TYPE=MyISAM AUTO_INCREMENT=1;
    ";

    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    dbDelta($sql);
}

More…

,

wordpress

Showing WordPress 3 query database error

22 Nov , 2011  

When you building plugin or themes, sometimes you need to contact with database ( select, update, insert or delete ). Somehow after executing database, there no result and no changes in database. That mean some problem with your code. You should check it with showing query error in WordPress by :

1
$wpdb->show_errors();

For example :

1
2
$wpdb->show_errors();
$wpdb->insert($wpdb->preffix.'table', $result);

This will show what error occured in inserting data.

Simple and straight-foward! 🙂

,

configuration

Solve Overheat in Ubuntu 11.10 with Jupiter + VGA solution

16 Nov , 2011  

Check this for turn off your VGA and decrease overheat fall into 57 C

After suffering overheat ( 80 Celcius ) about 2 month with Ubuntu Oneiric ( 11.10 ), finally i got my HP 431 so cool and it steady on 66 C. No Overheat anymore. Probably the main cause why this happen is VGA driver which i use ATI and there CPU lock on Maximum mode.

UPDATE: Try upgrade your BIOS. Several people have said they reduce heat by upgrading the BIOS.
http://h20000.www2.hp.com/bizsupport/TechSupport/SoftwareIndex.jsp?lang=en&cc=th&prodNameId=5086746&prodTypeId=321957&prodSeriesId=5086745&swLang=13&taskId=135&swEnvOID=4061#93211

My solution is by installing proprietary ATI Radeon manually and use Jupiter for “cooling down” my laptop. First, we should install ATI Radeon driver by following my previous article :

http://cisight.com/install-amd-radeon-hd-6470m-and-solve-overheat-on-ubuntu-1110-oneiric/

Second, we should install Jupiter on Ubuntu Oneiric by :

1
2
3
sudo add-apt-repository ppa:webupd8team/jupiter
sudo apt-get update
sudo apt-get install jupiter

After Jupiter installed, we should enable it on systray. You will have problem to enable Jupiter on Ubuntu 11.10 that run Unity or Unity 2D. Why this Jupiter not shown on Unity panel ? It’s because we need to whitelist-ed our application into Unity panel.

To make Jupiter show up on Unity, create a file called “whitelist” :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash
SCHEMA="com.canonical.Unity.Panel"
OBJECT="systray-whitelist"
APP="$1"
if [ ! "$(gsettings get $SCHEMA $OBJECT 2>/dev/null || echo FALSE)" = "FALSE" ]; then
  echo "Whitelisting $APP to work around flawed distribution design.."
  OBJARRAY=$(gsettings get $SCHEMA $OBJECT | sed -s -e "s#['##g" -e "s#', '# #g" -e "s#']##g")
  if [[ "${OBJARRAY[@]}" =~ "$APP" ]]; then
    echo "$APP already whitelisted, skipping"
  else
    OBJARRAY=("${OBJARRAY[@]}" $APP)
    OBJARRAY=$(echo ${OBJARRAY[@]} | sed -s -e "s# #', '#g")
    OBJSET="['"$OBJARRAY"']"
    gsettings set $SCHEMA $OBJECT "$OBJSET"
  fi
else
  echo "This is not a Canonical "designed" product."
fi

Note: This script taken from www.fewt.com/2011/03/whitelist-utility-script-to-allow-apps.html.

Execute it by :

1
2
chmod a+x whitelist
./whitelist jupiter

Reboot your Ubuntu to make it works. After the Jupiter menu show up, switch performance mode into “High Performance”.

After this long way, you should have no overheat problem on Ubuntu. 🙂

,

wordpress

How to load Zend Framework in WordPress 3 plugin

12 Nov , 2011  

Loading Zend Framework into WordPress 3 plugin is quite easy. You can download latest ZendFramework on http://framework.zend.com/download/latest . To use Zend Framework with our plugin, extract it on inside plugin folder.

1
2
3
4
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) );

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

,

wordpress

How to load Zend Framework into PHP files

11 Nov , 2011  

Zend Framework provide a lot of interesting libraries. Instead re-invent the wheel, using Zend Framework libraries will boost our development time. You can download latest ZendFramework on http://framework.zend.com/download/latest . To use Zend Framework with our system like individual php files, CMS or Framework, we should configure our path.

This is scheme of folders and extracted Zend Framework:

1
2
3
Project Folder
   |__ Zend
   |__ my.php

More…

,

wordpress

How to create WordPress 3 Custom Plugin for dummies

10 Nov , 2011  

Creating custom plugin in WordPress 3.2 is easy and it will fast if we do on the right way. So, what we need to know as newbie / n00b to build a custom wordpress plugin ? First, you should read : http://codex.wordpress.org/Writing_a_Plugin.

Now you have insight to build a plugin on WordPress. I will guide you to create wordpress plugin that follow WordPress Guidelines. We will create plugin called “writter”.

Create folder on “/wp-content/plugins” called “writter”. Go to folder and create file called “writter.php”

1
2
cd your-wordpress-path/wp-content/plugins/
mkdir writter

Now we ready to create plugins in WordPress 3 :

1. Standar plugin Information
We start create a standar plugin information on writter.php.
More…

,

configuration

Fix host-only adapter Virtualbox can’t dhclient and get ip address

7 Nov , 2011  

I use Ubuntu 11.10 as Host and Ubuntu 11.04 as Guest on Virtualbox 4.1.4. I running VM using Vagrant and Virtualbox (for Desktop version). When i set host-only adapter, i got issue that my network card (eth1) can’t get IP address.

This is weird which i have this work before. Switch on-off on network card doesn’t fix this problem. Also, when i delete “/etc/udev/rules.d/70-persistent-net.rules”, the problem still occured.

After diving for a while, i gota the solution.

1. Configure Host-adapter
Go to File -> Preferences -> Network. If you don’t have vboxnet0, you should create new one. Then, we need to configure this host-only adapter to available for static and dhcp ip. Edit this adapter :
For example, i use 33.33.33.1 as my host IP address.
More…

,

configuration

Fix shared folder Ubuntu Guest & Host Virtualbox permission denied

7 Nov , 2011  

After installing Virtualbox Guest Addition, we can share folder in our OS into guest Virtualbox. First, we go to shared folder and add new folder to share. Don’t forget to check auto-mount. Start your VM ( which mine is Ubuntu Oneiric 11.10 ) and go to /media to see sf_ubuntu / sf_folder.

When you click on folder, you will get permission denied. Why this happen? It because your user in VM not registered yet in vboxsf group. All you need is add your username into vboxsf group

1
sudo usermod -G vboxsf -a <your-username>

Then reboot your VM. Soon as you’re login into VM, you will get full access into shared folder 🙂

,