Skip to content

Instantly share code, notes, and snippets.

@kadavre
kadavre / prevent-multiple-submite.js
Created August 5, 2013 08:22
Prevent Multiple Submit of Your Form
$(document).ready(function() {
$('form').submit(function() {
if(typeof jQuery.data(this, "disabledOnSubmit") == 'undefined') {
jQuery.data(this, "disabledOnSubmit", { submited: true });
$('input[type=submit], input[type=button]', this).each(function() {
$(this).attr("disabled", "disabled");
});
return true;
}
else
@kadavre
kadavre / image.php
Created September 4, 2013 09:48 — forked from bchapuis/image.php
<?php
class ImageHelper extends Helper {
var $helpers = array('Html');
var $cacheDir = 'cache'; // relative to IMAGES_URL path
function resize($path, $dst_w, $dst_h, $htmlAttributes = array(), $return = false) {
$types = array(1 => "gif", "jpeg", "png", "swf", "psd", "wbmp"); // used to determine image type
@kadavre
kadavre / wp_my_plugin.php
Last active December 25, 2015 04:59
Never ever simply hook into 'admin_head' to add your script: not only you will be adding it to every admin pages (the Dashboard, Comments, etc…) but also to every other plugin pages. Seriously, half of the support question I've had with Who Sees Ads were because of WP-ContactForm adding its crappy javascript everywhere it could, including my plu…
$mypage = add_management_page( 'myplugin', 'myplugin', 9, __FILE__, 'myplugin_admin_page' );
add_action( "admin_print_scripts-$mypage", 'myplugin_admin_head' );
function myplugin_admin_head() {
// what your plugin needs in its <head>
}
@kadavre
kadavre / cake_email.php
Last active October 25, 2019 11:03
Send mail with cakephp using gmail.
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'votreidentifiant@gmail.com',
'password' => 'motdepasse',
'transport' => 'Smtp',
'timeout' => 30
);
$email = new CakeEmail('gmail');
@kadavre
kadavre / country_state_jquery.js
Created October 14, 2013 12:19
plugin that display countrie, states and cities on multiple select
var countries = Object();
countries['Africa'] = 'Algeria|Angola|Benin|Botswana|Burkina Faso|Burundi|Cameroon|Cape Verde|Central African Republic|Chad|Comoros|Congo, Dem.|Congo, Rep.|Djibouti|Egypt|Equatorial Guinea|Eritrea|Ethiopia|Gabon|Gambia|Ghana|Guinea|Guinea-Bissau|Kenya|Lesotho|Liberia|Libya|Madagascar|Malawi|Mali|Mauritania|Mauritius|Morocco|Mozambique|Namibia|Niger|Nigeria|Rwanda|Sao Tome/Principe|Senegal|Seychelles|Sierra Leone|Somalia|South Africa|Sudan|Swaziland|Tanzania|Togo|Tunisia|Uganda|Zambia|Zimbabwe';
countries['Antarctica'] = 'Amundsen-Scott';
countries['Asia'] = 'Bangladesh|Bhutan|Brunei|Burma (Myanmar)|Cambodia|China|East Timor|India|Indonesia|Japan|Kazakhstan|Korea (north)|Korea (south)|Laos|Malaysia|Maldives|Mongolia|Nepal|Philippines|Russian Federation|Singapore|Sri Lanka|Taiwan|Thailand|Vietnam';
countries['Australia/Oceania'] = 'Australia|Fiji|Kiribati|Micronesia|Nauru|New Zealand|Palau|Papua New Guinea|Samoa|Tonga|Tuvalu|Vanuatu';
countries['Caribbean'] = 'Anguilla|Antigua/Barbuda
@kadavre
kadavre / wp_meta_description.php
Last active December 28, 2015 00:09
WordPress does not support the use of meta description tags by default. Though metas have lost their significance in SEO, they can still influence the ranking of your blog in the search engines. To make your site search engine friendly, you should open the header.php file of your theme and copy and paste the code below to the space between the o…
<meta name="description" content="
<?php
if ((is_home()) || (is_front_page())){
echo ('Your main description goes here');
}elseif(is_category()){
echo category_description();
}elseif(is_tag()){
echo '-tag archive page for this blog' . single_tag_title();
}elseif(is_month()){
echo 'archive page for this blog' . the_time('F, Y');
@kadavre
kadavre / wp_define_posts.php
Last active December 28, 2015 00:09
Majority of bloggers display posts in more or less them same way on the home pages of their blogs. This is understandable since WordPress does not feature a default option to define how posts should be displayed. Fortunately, you can surmount this problem by using custom fields. To define posts in your home page, you can use either the full post…
<?php
if (have_posts()) :
while (have_posts()) : the_post();
$customField = get_post_custom_values("full");
if (isset($customField[0])) {
//Custom field is set, display a full post
the_title();
the_content();
}else{
// No custom field set, let's display an excerpt
@kadavre
kadavre / wp_googlemap_shortcode.php
Last active December 28, 2015 00:09
Once you copy and paste the above code to your function.php, you will need to copy the short code below into the exact place where you want Google Maps to be displayed. [googlemap width="200" height="200" src="[url]"]
//Google Maps Shortcode
function fn_googleMaps($atts, $content = null) {
extract (shortcode_atts (array (
"width" => '640',
"height" => '480',
"src" => ''
), $atts));
return '<iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'"></iframe>';
}
@kadavre
kadavre / wp_page_categories_dropdown.php
Last active December 28, 2015 00:09
Sometimes, you may want to add a cool drop down menu that will show all existing categories in your WordPress site. Here is a simple way of doing it. Copy and paste the code below into the index.php or sidebar.php file.
<form action="<?php bloginfo('url'); ?>/" method="get">
<?php
$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
?>
<noscript><input type="submit" value="View" /></noscript>
</form>
@kadavre
kadavre / wp_similar_posts.php
Last active December 28, 2015 00:09
It’s also possible to display similar posts in your blog so as to draw the attention of visitors and engage them. I know you will be tempted to use a plugin to display similar posts, but there is no need to overload your WordPress blog with plug ins when you can use tags and custom codes. Here is a powerful code to do display related posts quick…
<?php
//for use in the loop, list 5 post titles related to first tag on
//current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo 'Related Posts';
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),