Archive for category PHP

Showing custom comments saved values to visitors

Hi everyone
It’s been a long time since I wrote something
Due to requests for showing the custom fields in the template I searched a little bit and finally found the easiest solution
So what should you do?

First of all
Go to you template directory (in default template it’s “wp-content/themes/twentyten”)
Open comments.php and search for “wp_list_comments”(Don’t search with quotes :P)
Do you see the “something” in wp_list_comments( array( ‘callback’ => ‘something’ ) );?
That’s the function that will be overwrite the default template for comments
If it’s not there add it and instead of something write the name you like
Now open functions.php
If you haven’t changed anything in comments.php so search for “something”(the name of the function)
Now you you should add this code to this function wherever you want(put it in different place to see where it will appear-at the beginning it will be before author and at the end after the reply link-)

The function

$CComment_fields = array_filter(explode(",", get_option('CComment_fields')));
foreach ($CComment_fields as $CComment_field){
$CComment_field_arr = explode(";CuCo;", get_option($CComment_field));
$CComment_field_desc = $CComment_field_arr[0];
$CComment_field_active = $CComment_field_arr[1];
$Comment_field_value = get_comment_meta(get_comment_ID(), "CuCo_".$CComment_field);
if ($CComment_field_active == 1)
echo $CComment_field_desc.' : '. (($Comment_field_value[0] != '') ? $Comment_field_value[0] : '-');

Do you see this line “echo $CComment_field_desc.’ : ‘. (($Comment_field_value[0] != ”) ? $Comment_field_value[0] : ‘-‘);”?
It’s the part that prints each of custom field and it’s value
Just play with it as you please(add class, id or whatever you want)
For example
echo ‘
<div class=”cc-field”>’ . $CComment_field_desc .</div>
. ‘ : ‘. (($Comment_field_value[0] != ”) ? $Comment_field_value[0] : ‘-‘);
I hope this helps
Thanks for all of the comments about this plugin 🙂


, , ,



In following of the last post…
After finishing protect_content function I thought I can use it in wp too
So I tried to learn how to make a plugin for wordpress
At the beginning it was really hard but after an hour I got used to it And i finished writing a simple plugin in 5 hours(lots of time XD)
Download the plugin HERE
I hope you enjoy it
Have a good day

, , , , , ,


Protect Content Function

Hi everyone
Last night I wrote a function to protect content of my site
For whoever has a site and wants to use my function here is the function
* I used simple_html_dom class in this function, you can download it here Simple html DOM

function protect_images($text, $protect_images = true, $protect_text = true){
$html = str_get_html($text);
$image_original = array();
$image_protected = array();
if ($protect_images)
foreach($html->find('img') as $element){
$src = $element->src;
$width = $element->width;
$width_p = $width + 2;
$height = $element->height;
$height_p = $height + 2;
$element->outertext = '

if ($protect_text)
return '


return $html;

, , , ,

Leave a comment


Hello everyone!

Today I had a little problem with a spammer.

He was requesting a page like 3 o 4 times per second.

And I found about it after one of my tables(stats) got overloaded by data so I contacted my host (The host I’m using is really good and fast and has a really good support, thanks ipage) and they restored my database.

First I emptied stats table and then blocked the spammer’s ip with .htaccess.

Then I thought about preventing spammers accessing my site too fast.

So I wrote this piece of code.

I know It’s really simple but I guess it gives the idea to some newbies like me.

For the table:
`ip` varchar(15) NOT NULL,
`accessTime` int(11) NOT NULL,
`accessPage` varchar(10) NOT NULL

And at the header of you site:


$con = mysql_connect(“localhost”,”user”,”pass”);
if (!$con)
die(‘Could not connect: ‘ . mysql_error());

mysql_select_db(“your_db”, $con);

$interval=3; //these two parameters mean that the a user can access your site maximum 2 times in 3 seconds
$timeLow = time()-$interval;
$timeNow = time();

$accessNum=mysql_query(“SELECT * FROM Ips WHERE accessTime > ‘$timeLow’ AND ip=’$ip'”);
if(mysql_num_rows($accessNum) > 2){
mysql_query(“INSERT INTO Ips (ip,accessTime,accessPage) VALUES (‘$ip’,0,’$accessPage’)”);//I used this to check know who accessed my site too fast(just with searching the table for accessTime=0
die(‘You are accessing this site too fast’);
mysql_query(“INSERT INTO Ips (ip,accessTime,accessPage) VALUES (‘$ip’,’$timeNow’,’$accessPage’)”);

Well you can add more columns to database for more details(like date).

I hope this article be a little help for you:D

, , , , ,

Leave a comment