Sunday, 18 March 2018

PHP Prevent submit until some time

To prevent submission of form or any script we can use PHP Session to prevent concurrent submission.

if (isset($_POST) && !empty($_POST)) 
{
    if (isset($_SESSION['posttimer']))
    {
        if ( (time() - $_SESSION['posttimer']) <= 2)
        {
            // less then 2 seconds since last post
        }
        else
        {
            // more than 2 seconds since last post
        }
    }
    $_SESSION['posttimer'] = time();
}

SSL-certificate; Green lock not displaying

My best guess would be that your page contains some non-https content.
Add Following meta value to your header. Basically it will force non HTTPS to use HTTPS secure connection url.
If you want to allow the Mixed Content request, then add the below tag into tag.
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
If you want to block then add the below tag into the tag
<meta http-equiv="Content-Security-Policy" content="block-all-mixed-content">

Saturday, 28 October 2017

CORS header 'Access-Control-Allow-Origin' missing

ERROR : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.SOMEURL  (Reason: CORS header 'Access-Control-Allow-Origin' missing).


.
When the code send the request, you shall have a "200 OK" response code in your browser console, which means that the resource is accessed, but it does not grant the right to share that resource. It does this by not allowing "Access-Control-Allow-Origin".


To change that, you have to write this in the .htaccess of the requested domain file (notyourdomain.com):

Add following code to your .HTACCESS file

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

Thursday, 12 October 2017

WooCommerce CHEKCKOUT FIELDS PLAY GROUND

// Billing Fields.
add_filter( 'woocommerce_billing_fields' , 'woocommerce_billing_fields_custom' );
function woocommerce_billing_fields_custom( $fields ) {

$fields['billing_phone']['required'] = false;
$fields['billing_phone']['maxlength'] = 10;
$fields['billing_state']['class'] = array( 'form-row-first' );
$fields['billing_postcode']['maxlength'] = 4;
$fields['billing_postcode']['class'] = array( 'form-row-last' );

//Order Billing fields
$fields['billing_email']['priority'] = 33;
$fields['billing_phone']['priority'] = 37;
$fields['billing_country']['priority'] = 100;

return $fields;

}



// Shipping Fields.

add_filter( 'woocommerce_shipping_fields' , 'woocommerce_shipping_fields_custom' );

function woocommerce_shipping_fields_custom( $fields ) {

$fields['shipping_state']['class'] = array( 'form-row-first' );
$fields['shipping_postcode']['maxlength'] = 4;
$fields['shipping_postcode']['class'] = array( 'form-row-last' );

//Order Shipping fields
$fields['shipping_country']['priority'] = 100;
$fields['shipping_country']['priority'] = 100;

return $fields;
}

// ----------- CHANGE FIELDS PRIORITY EN ------



// ----------- UNSET CHECKOUT FIELDS ST ------
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {

/*
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_email']);
unset($fields['account']['account_username']);
unset($fields['account']['account_password']);
unset($fields['account']['account_password-2']);
*/

unset($fields['billing']['billing_phone']);
unset($fields['shipping']['shipping_phone']);
unset($fields['order']['order_comments']);

unset($fields['billing']['billing_email']);
unset($fields['shipping']['shipping_email']);
unset($fields['billing']['billing_state']);
unset($fields['shipping']['shipping_state']);


return $fields;
}
// ----------- UNSET CHECKOUT FIELDS EN ------

PHP Pinterest RSS Feed PARSING

class XmlToJson {
  public function Parse( $url ) {
    $fileContents = file_get_contents( $url );
    $fileContents = str_replace( array(
      "\n",
      "\r",
      "\t"
    ), '', $fileContents );
    $fileContents = trim( str_replace( '"', "'", $fileContents ) );
    $simpleXml = simplexml_load_string( $fileContents );
    $json = json_encode( $simpleXml );
    return $json;
  }
}

function viral_pinterest() {
  $xml   = new XmlToJson;
  $feed  = json_decode( $xml->Parse( "https://www.pinterest.com/codifyclub/feed.rss/" ) );
  $items = $feed->channel->item;
  foreach( $items as $item ) :
 
   // print_r($item);
   if(is_string($item->title)) echo $item->title;
    echo '<br/>';
   
    echo $item->link;
    echo '<br/>';
 
    $doc = new DOMDocument();
    @$doc->loadHTML($item->description);
    $img_tags = $doc->getElementsByTagName('img');
    foreach ($img_tags as $img_tag) {
       echo $img_path = $img_tag->getAttribute('src');
    }
   

  endforeach;
}

viral_pinterest();

Wednesday, 20 September 2017

jQuery Select dropdown duplicate value remove

$('select').blur(function() {
    var myOpt = [];
    $("select").each(function () {
        myOpt.push($(this).val());
    });
    $("select").each(function () {
        $(this).find("option").prop('hidden', false);
        var sel = $(this);
        $.each(myOpt, function(key, value) {
            if((value != "") && (value != sel.val())) {
                sel.find("option").filter('[value="' + value +'"]').prop('hidden', true);
            }
        });
    });
});

Monday, 18 September 2017

WP WPML Link language

// TO DISPLAY LANGUAGE FLAG
<?php language_selector_flags(); ?>


// CREATE CURRENT PAGE LINK IN ANOTHER LANGUAGE
$url = get_the_permalink();

$wpml_permalink = apply_filters( 'wpml_permalink', $url , 'fr' );


// LANGUAGE CHECK
if(ICL_LANGUAGE_CODE==en){...}


// CUSTOM
<div class="lang-bar">
<?php
$languages = icl_get_languages('skip_missing=0&orderby=code');
if(!empty($languages)){
$count=1;
foreach($languages as $l){

if(!$l['active']) echo '<a href="'.$l['url'].'">';
echo $l['translated_name'];
if($count=='1')echo "&nbsp;<span>|</span>&nbsp;";
if(!$l['active']) echo '</a>';
$count++;
}
}
//echo $_SESSION['design'];
?>
</div>