Category: How to

PHP Functions

How to Sort an Array with PHP

Create the function sortArray() public function sortArray(&$array, $subkey=”id”, $sort_ascending=true) { if (count($array)) $temp_array[key($array)] = array_shift($array); foreach($array as $key => $val){ $offset = 0; $found = false; foreach($temp_array as $tmp_key => $tmp_val) { if(!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) { $temp_array = array_merge( (array)array_slice($temp_array,0,$offset), array($key => $val), array_slice($temp_array,$offset) ); $found = true; } $offset++; } if(!$found) $temp_array […]

Read more

How To Get Public IP Address from Command line

  curl http://ipecho.net/plain  

Read more

Speech Recognition With Javascript

  var grammar = ‘#JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghostwhite | gold | goldenrod | gray | green | indigo | ivory | khaki | lavender | lime | […]

Read more

Google Maps V3 Map inside Div instead or Body Tag

Ok instead of this body onLoad=”” to this div id=”map” simply add this below your map load(); This makes it to that the javascript runs at load. Done.

Read more

How to find a User WITHOUT Facebook on Spotify

  To find a particular user.  In the search bar type “spotify:user:replacethiswithusername”  without quotes. Done.

Read more

Install phpmyadmin on nginx

Paste this code inside the server{} code in your etc/nginx/sites-available/example.com file. location /phpmyadmin { root /usr/share/; index index.php index.html index.htm; location ~ ^/phpmyadmin/(.+\.php)$ { try_files $uri =404; root /usr/share/; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/; } } location /phpMyAdmin { rewrite ^/* /phpmyadmin last; } […]

Read more

How to Add Custom Fields to User Profile – WordPress

Super easy way to add custom fields to the user profile on WordPress. This will take you 3 seconds to implement.   function modify_contact_methods($profile_fields) { // Add new fields – this can be as many as you like $profile_fields[‘cool_new_field’] = ‘Twitter Username’; // Remove old fields unset($profile_fields[‘some_existing_field_you_hate’]); return $profile_fields; } add_filter(‘user_contactmethods’, ‘modify_contact_methods’); //And if you […]

Read more

Cron Job to remove all Files older than a Specific Amount of days

In this example I’m using 90 days. But you can use whatever you would like in the place of it. It’s also set to run at the first of every month. 0 0 1 * * find /home/somehomedir/thatfolderyouwanttouse/ -type f -mtime +90 -exec rm {} +  

Read more

Use WordPress Media Uploader in your Custom Plugin

This will make is Basicly what I did was adding this to my plugin: function test_admin_scripts() { wp_enqueue_script(‘media-upload’); wp_enqueue_script(‘thickbox’); wp_enqueue_script(‘jquery’); } function test_admin_styles() { wp_enqueue_style(‘thickbox’); } add_action(‘admin_print_scripts’, ‘test_admin_scripts’); add_action(‘admin_print_styles’, ‘test_admin_styles’); And later this part: <script language=”JavaScript”> jQuery(document).ready(function() { jQuery(‘#upload_image_button’).click(function() { formfield = jQuery(‘#upload_image’).attr(‘name’); tb_show(”, ‘media-upload.php?type=image&TB_iframe=true’); return false; }); window.send_to_editor = function(html) { imgurl = jQuery(‘img’,html).attr(‘src’); […]

Read more

Make Div Appear and Reappear with javascript

Make a div with the same id as the select input and you should be good to go. $(window).load(function() { $(document).ready(function() { $(‘.group’).hide(); $(‘#div1’).fadeIn(‘slow’); $(‘#div1’).change(function() { $(‘.group’).hide(); $(‘#’ + $(this).val()).fadeIn(‘slow’); }) }); });

Read more