Tuesday, 21 April 2015

Question: How to get image details like name,extensions,date ,content from encoded URL?
For example, i am coping an image from Google which is giving me an encoded URL for that image and using php i want to see the detail of that image.


Solution: 

<?php
try this : print_r( get_headers( $url ) );
?>
you will get the result something like this:
Array
(
    [0] => HTTP/1.1 100 OK
    [1] => Access-Control-Allow-Origin: *
    [2] => ETag: "v1"
    [3] => Expires: MON, 11 Apr 2011 09:10:30 GMT
    [4] => Cache-Control: public, max-age=45600, no-transform
    [5] => Content-Disposition: inline;filename="xyz.png"
    [6] => Content-Type: image/jpg
    [7] => Date: Tue, 21 Apr 2013 09:17:30 GMT
    [8] => Server: xyz
    [9] => Content-Length: 12345
    [10] => X-XSS-Protection: 1; mode=block
    [11] => Alternate-Protocol: 80:quic,p=1
)
or else use function
finfo_file() to get the file/image details.
Returns a textual description of the contents of the file_name argument, or FALSE if an error occurred.

Wednesday, 15 April 2015

Question: Passing variable in php script but its not working


exec("python -c 'import smtp; smtp.email({$email_address})'");


Answer : use \" 
exec("python -c 'import smtp; smtp.email(\"$email_address\")'");

Tuesday, 14 April 2015

Once when i was beginner in wordpress, i searched this question on google. 
For beginners in wordpress :

Question: How to add categories by using code/script to wordpress admin category?


Answer: To avoid manual entry of categories or wanted to add category by coding simply use the inbuilt functions, Actually there is a function in wordpress wp_create_category() , even you can see parameters of this function in wordpress manual as the link is
http://codex.wordpress.org/Function_Reference/wp_create_category 

Wednesday, 8 April 2015

Question asked by a colleague : how to get term id of current taxonomy in wordpress :by using this plugin
 get_term_meta($term_id, $key, $single)
However I am unable to get this to work.. I have to manually enter the term_id like so..
 
$term_meta = get_term_meta('12', '', true);

Answer:
try this

$idObj = get_category_by_slug(post_type);  
$id1 = $idObj->term_id; 
If you are using any WordPress inbuilt function, then you need write the objname->subkey.

Question asked by one of my friend : Migrating a small PHP application to Wordpress

Firstly create a template file in theme folder. There you can place your php code. Then create page from admin panel and assign that template and run.
It will be helpful because as you create template , you can use wordpress inbuilt functions also.
Thanks