Sunday, July 29, 2012

Uploading a picture in Wordpress to your media gallery using xmlrpc

If you're automatically creating a wordpress post or page from php code, rather than from the wordpress admin panel, sometimes you might need to add a pic from a different website to your upload directory, and then display that pic inside your wordpress page.

In This post, I will show you to how to upload a picture to your wordpress inside your media library and retrieve its URL using xmlrpc library.

The Code:

//make sure to include the correct path to class-IXR.php, depending on your  current Directoryr
include 'wp-includes/class-IXR.php'; 

//Wordpress Username
$username = "myWpUsername";
//Wordpress Password
$password = "myWpPassword";
//make sure you specify the exact path to your xmlrpc.php
$xmlrpc_url = ''; 

$ixrClient = new IXR_Client($xmlrpc_url);

//url or image to add to the media library
$img = "";
$image['name'] = md5($img). '.jpg';
//type of image
$image['type'] = 'image/jpg';
//url or full path of an image
$image['bits'] = new IXR_Base64(file_get_contents($img));
//overwrite if exist
$image['overwrite'] = true;

//Upload the pic
if (!$ixrClient->query('wp.uploadFile', '1', $username, $password, $image))
    //If upload is unsuccessfull, write the error in error log
    error_log('An error occurred - ' . $ixrClient->getErrorCode() . ":" . $ixrClient->getErrorMessage());
     //Get Response
    $clientResponse = $ixrClient->getResponse();
    //echo URL of Image
    echo $clientResponse['url'];  

Any questions? Please leave a comment below.

Saturday, July 28, 2012

What's your favorite Operating System?

What's your favorite Operating System?

Please use the poll to in the right sidebar and vote for your favorite Operating System.


Free and open source operating system, used mostly by computer geeks and on servers.

Mac OS

How can someone not like apple, iphones, ipads, etc?


Friendly user interface, by far the most used operating system and has a huge variety of programs, games and tools.

None of the above?

Please leave a comment and let us know your favorite Operating System!

Friday, July 27, 2012

15 most used linux commands and how to use them

Lately I've been using linux commands a lot, to configure servers and to optimize them. So I decided to write about my 15 most used commands linux, a brief explanations about them, and couple of examples of each.

15 most used linux commands:

1- su and su- command (Switch User or Super User or Set User)

su  stands for super user, switch user or set user. By default su command will promote the current user to a super user, if the super user has a password, they will have to authenticate first, and if authenticated successfully, they will be granted the permission to access the super user, for example:


To switch from a user to another, enter the following:

su etienne

2- cd Command (Change Directory)

cd stands for change directory, to go into a new directory, we use cd as follows:
cd myNewDirectory

To go back one directory, we use cd.., for example:
cd ..

To go back to the home directory, we just write cd

3- Wget Command (World Wide Web and get)

Wget stands for World Wide Web and the word get.

Wget is used to download a file from a http server (or https), and even ftp servers.
Wget can also be used to download an entire directory recursively.

To download a single file with Wget, we use the following command:
wget directUrlForAFile

or we can use Wget with -c option to resume a file that we previously started downloading it:
wget -c directUrlForAFile

More examples about working with Wget can be found in here:

4- Vi and Vim Commands (Text Editor)

Vi is the Unix text editor originally created for Unix operating system, while Vim is also a text editor extended from Vi. Vim is also known as "Vi Improved" and has additional features over Vi, and helps in editing the text easier.

Editing a file with Vi or Vim is easy:
vi myFile.txt
vi /etc/my.cnf

vim myFile.txt
vi /etc/my.cnf

5- Man Command (Manual)

Man stands for manual, and its job is to display the manual of a command, the options for a command and their descriptions. Man is very important in case you forget an option parameter or if you just wish to learn about new commands.
The below example, will display the help of the vi command explained earlier:

man vim

and will display the following:
man vim

6- Whoami Command (Who Am I)

whoami command will display the name of the current logged in user, just type whoami in a command line and your name will appear, for example:

[root@changeme ~]# whoami

7-  Free Command  (Free Command)

The free displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. The shared memory column should be ignored; it is obsolete.
By default, free will show the usage in KB, If you want to check your memory usage in MB, enter the command free -m, in GB free -g , and in Bytes free -b.

free -b
free -m
free -g

More information about "free command" can be found in here:

8- Top Command (Display top CPU processes)

The top command provides a real-time view of the running system or server. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel (tasks running, CPU load, used memory, free memory).


9- Yum Command (Yellowdog Updater Modified Command)

Yum Command can be used to install new packages, update existing packages and remove packages. Yum can also include dependency analysis and obsolete processing based on "repository" metadata.

An example of using yum to install php is as follows:

yum install php

If php is already installed, yum will display the version of the installed packages, and if a new version is available, yum will ask if you would like to update it, and update all the dependency and related packages.

yum install php

10- Ping Command (send ICMP ECHO_REQUEST to network hosts)

 Ping uses the ICMP protocol to send packets and check if a certain address is reachable. For example:

Pinging a domain name:

Pinging an IP version 4

Pinging an IP version 6 (facebook open graph IP in this case)
ping 2a03:2880:10:1f02:face:b00c:0:26

11- Zip and Unzip Commands

Zip is usesd to compress and/or package one or more files. Unzip is used to unpack and uncompress the file(s) that were previously zipped.

Zipping several files in a directory can be achieved by using the recursive -r option:
zip -r

To unzip the file to the current directory:

You might also be interested in reading this post about zipping files or directories:

12- ls Command (Listing Directory Content)

ls lists all the files in the current directory, sorted alphabetically, ls can take some arguments, for example:

or ls -l, which will show a long listing format, and the current permission of each file and directory, alongside their size and last modified date.

ls -l

13- kill Command (Terminating/Killing a process)

The command kill send a TERM signal to a process. All linux processes can have a signal function where in case a kill command is initiated, this process will first access their signal function and execute whatever code is written in it. In case the process does not have a signal function, the kill command will terminate the process immediately, the following example will kill process number 18020:
kill 18020

Sometimes you want to kill a process without letting it call their signal function, this can be done by using the kill 9 command:
kill 9 18020

In the above example, the process will be terminated immediately.

14- Service Command

Service command is used to run the system V init scripts. that is instead of calling the files located in the /etc/init.d/ directory by specifying their full path, you can use the service command. For example to check all the running services, we use the following command:
service --status-all

To start, stop, and restart apache server, we can use the following (Works on CentOS)
service httpd stop
service httpd start
service httpd restart

15- rm Command (Remove file(s) and directories)

rm removes each specified file. By default, it does not remove directories.

To remove a single file, you have to confirm before removing:
rm myfile.txt
rm: remove regular file `myfile.txt'?

To remove a single file, without confirmation, we use the -f (force) option:
rm -f myfile.txt

To recursively remove all files and directories from a specific directory called myDir:;
rm -r myDir

There are many more useful commands in linux that can be used often, however I think that the above list contains the most used commands.

In case I missed an important command, please leave a comment and let me know :)

Thursday, July 26, 2012

How to disable adblock plus for one specific website

Adblock Plus is a firefox (and chrome) add-on or extension that allow users to block some page elements, like advertisements for example, from being displayed on the webpage.

Adblock Plus is very useful to block advertisements, unwanted popups and some tracking java script files.

However sometimes you might want to disable or unblock a website, or part of a website.

To unblock a website, simply click on the ABP icon 

Adblock Plus ABP

Then select "Disable on..." (example, Disable on")

adblock plus disable website 

If you can't see the ABP button, you can do it from tools => Adblock Plus => Disable on

adblock plus disable website 

If you can't see  the "tools", simply click ALT key on your keyboard.

If you want to unblock a part of the website, choose  "Open blockable Items".

adblock plus blockable items 

And you will see in red all the blocked items, such as facebook ads in this example
adblock plus blockable items

To unblock an item, right click the red line and choose disable filter, then reload the page.

adblock plus disable blockable items 

Any questions or comments, please post below :)