Tuesday, January 30, 2018

Avoiding the Not Secure Warning in Chrome

Chrome will have following impact after the version 65:

1. The websites that having Symantec-issued TLS certificates older than June 1, 2016 and that must be replaced
2. Chrome will mark non-secure pages containing password and credit card input fields as Not Secure in the URL bar.

To avoid this you need to install the SSL on the website that contains containing password and credit card input fields. 


For testing:
  1. Please install the updated version of chrome - https://www.google.com/chrome/browser/canary.html
  2. Configure Chrome to show the warning as it will appear in January 2017, open chrome://flags/#mark-non-secure-as and set the Mark non-secure origins as non-secure option to Display a verbose state when password or credit card fields are detected on an HTTP page. Then relaunch your browser.
https://developers.google.com/web/updates/2016/10/avoid-not-secure-warn

Tuesday, January 23, 2018

Wordpress - Set the maximum upload size limit for non-administrators.

/**
 * Set the upload size limit for non-administrators.
 * @param string $size Upload size limit (in bytes).
 * @return int (maybe) Filtered size limit.
 */
function filter_site_upload_size_limit( $size ) {
    // Set the upload size limit to 2 MB for users lacking the 'manage_options' capability.
    if ( ! current_user_can( 'manage_options' ) ) {
        // 2 MB.
        $size = 2 * 1024* 1024;
    }
    return $size;
}
add_filter( 'upload_size_limit', 'filter_site_upload_size_limit', 2 );

Friday, January 19, 2018

WordPress - Briefly unavailable for scheduled maintenance. Check back in a minute.

Briefly unavailable for scheduled maintenance. Check back in a minute.

How to fix it.

When this happens, WordPress generates a .maintenance file in the root directory of the installation. With normal behavior, the update script completes and WordPress auto-removes the .maintenance file. In the case of an interruption of some sort, this file doesn’t get deleted and the message won’t go away.
The answer? Delete it manually.
Here are the steps:
  • Log into your web server via FTP or your web host’s control panel.*
  • Locate the root of your WordPress install (this is where you’ll find folders for wp-content, wp-admin, and wp-includes)
  • Look for a file called .maintenance
  • Delete it

Saturday, January 13, 2018

Wordpress - The requested URL /page/ was not found on this server.

How to fix The requested URL was not found on this server error for the hello/name url?

This error is due to the rewrite module and this is the .htaccess file error, please update the .htaccess file with the following code:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress
For more information, please visit the wordpress codex - https://codex.wordpress.org/htaccess

Saturday, December 30, 2017

Redirect incoming requests to specific URLs in IIS 7


The Rule "aboutus" is redirect a specific page to a another page.

The Rule "legal" is to redirect the all html files from a folder to a specific page.
<system .webserver="">
        <rewrite>
          <rules>
            <rule name="aboutus">
              <match url="^about-us.html$"></match>
              <action type="Redirect" url="/index.html"></action>
            </rule>
            <rule name="Legal">
              <match url="^Legal/(.*).html$"></match>
              <action type="Redirect" url="/index.html"></action>
            </rule>
          </rules>
        </rewrite>
     </system>

Friday, December 29, 2017

wordpress - error "Sorry, you are not allowed to attach files to this post."

please edit the capabilities.php file at location /wp-includes/capabilities.php:

Replace below code:
function current_user_can( $capability ) {
    $current_user = wp_get_current_user();

    if ( empty( $current_user ) )
        return false;

    $args = array_slice( func_get_args(), 1 );
    $args = array_merge( array( $capability ), $args );

    return call_user_func_array( array( $current_user, 'has_cap' ), $args );
}
With
function current_user_can( $capability ) {
    $current_user = wp_get_current_user();

    if ( empty( $current_user ) )
        return false;

    if (is_admin())
        return true;
    $args = array_slice( func_get_args(), 1 );
    $args = array_merge( array( $capability ), $args );

    return call_user_func_array( array( $current_user, 'has_cap' ), $args );
}


Thursday, December 28, 2017

Upload Multiple Files Using FileUpload Control In ASP.NET 4.5 +

ASP.NET 4.5 and upper versions support this feature.

Now, FileUpload  control is built to support HTML 5, therefore it is only supported in browsers supporting HTML5. For other browsers it will work like a normal file upload control in ASP.NET.

A new Attribute introduces with the ASP.NET 4.5 FileUplaod control i.e. AllowMultipleIt takes either true or false.

In order to support multiple file uploads, set AllowMulitple="true" other than false.

<asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />

In addition to this control, some new properties have been included to support code-behind coding.


HasFilesCheck whether FileUpload control has multiple files or not.

PostedFilesBasically used to get all the files from the FileUpload control in the iteration.

Example code to upload files:

   <asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />  
   <asp:Button runat="server" ID="uploadedFile" Text="Upload" OnClick="uploadFile_Click" />  

protected void uploadFile_Click(object sender, EventArgs e) {  
    if (UploadImages.HasFiles) {  
        foreach(HttpPostedFile uploadedFile in UploadImages.PostedFiles) {  
            //code to save files  
        }  
    }  
} 



Saturday, December 23, 2017

Wordpress - Change 'Add to cart' button text

Please add the below code to code the 'Add to cart' button text.

Change in Product Catalogue Page:
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' );
function woo_archive_custom_cart_button_text() {
return __( 'ADD TO CART', 'woocommerce' );
}


Change in Single Product Page:
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 +
function woo_custom_cart_button_text() {
return __( 'ADD TO CART', 'woocommerce' );
}

Limit the number of cart Items in Woocommerce

There is 2 actions to check and to control if you want to limit cart items:

  1. Add to basket - When product  is added to cart
  2. Update Basket - When quantities are updated in cart page
Add a custom function hooked in woocommerce_add_to_cart_validation filter hook in function.php file of your active child theme (or theme), will allow customer to restrict the cart items to 'n' max and to display a custom message when this limit is exceeded:

  1. Checking and validating when products are added to cart:
    • Restrict Total Transaction Items:
      add_filter( 'woocommerce_add_to_cart_validation', 'only_n_items_allowed_add_to_cart', 10, 3 );
      function only_n_items_allowed_add_to_cart( $passed, $product_id, $quantity ) {
      $cart_items_count = WC()->cart->get_cart_contents_count();
      $total_count = $cart_items_count + $quantity;

      if( $cart_items_count >= n || $total_count > n ){
      // Set to false
      $passed = false;
      // Display a message
      wc_add_notice( __( "You can’t have more than n items in cart", "woocommerce" ), "error" );
      }
      return $passed;
      }
    • Restrict Item in a transaction:
      add_filter( 'woocommerce_add_to_cart_validation', 'only_five_items_allowed_add_to_cart', 10, 3 );
      function only_five_items_allowed_add_to_cart( $passed, $product_id, $quantity ) {

      //$cart_items_count = WC()->cart->get_cart_contents_count();

      foreach ( WC()->cart->get_cart() as $cart_item ) {
      if($cart_item['product_id'] == $product_id ){
      $cart_items_count = $cart_item['quantity'];
      break; // stop the loop if product is found
      }
      }

      $total_count = $cart_items_count + $quantity;

      if( $cart_items_count > 3 || $total_count > 3 ){
      // Set to false
      $passed = false;
      // Display a message
      wc_add_notice( __( "You can’t add more than 3 items in cart", "woocommerce" ), "error" );
      }
      return $passed;
      }

  2. Checking and validating when updating cart item quantities when products are added to cart
    • Restrict Total Transaction Items:
      add_filter( 'woocommerce_update_cart_validation', 'only_six_items_allowed_cart_update', 10, 4 );
      function only_six_items_allowed_cart_update( $passed, $cart_item_key, $values, $updated_quantity ) {

      $cart_items_count = WC()->cart->get_cart_contents_count();
      $original_quantity = $values['quantity'];
      $total_count = $cart_items_count - $original_quantity + $updated_quantity;

      if( $cart_items_count > 6 || $total_count > 6 ){
      // Set to false
      $passed = false;
      // Display a message
      wc_add_notice( __( "You can’t have more than 6 items in cart", "woocommerce" ), "error" );
      }
      return $passed;
      }
    • Restrict Item in a transaction:
      add_filter( 'woocommerce_update_cart_validation', 'only_five_items_allowed_cart_update', 10, 4 );
      function only_five_items_allowed_cart_update( $passed, $cart_item_key, $values, $updated_quantity ) {

      $cart_items_count = WC()->cart->get_cart_contents_count();
      $original_quantity = $values['quantity'];
      $total_count = $cart_items_count - $original_quantity + $updated_quantity;

      if( $updated_quantity > 3 ){
      // Set to false
      $passed = false;
      // Display a message
      wc_add_notice( __( "You can’t have more than 3 items in cart", "woocommerce" ), "error" );
      }
      return $passed;
      }

Tuesday, December 19, 2017

Wordpress - How to do a plugin/theme conflict test?

Sometimes when you find an issue on your wordpress site with Plugin, it will be caused by a plugin or theme conflict.
This can range from a simple CSS styling issue to a more complex issue where one Plugin/Theme is stopping another plugin/Theme from functioning properly.

do following Steps to a conflict test:
  1. Deactivate all plugins and switch to default Twenty Fifteen theme (this will ensure site is as close to a clean install as possible).
  2. Check the site to see if issue still exists. If issue goes away after deactivating other plugins and switching theme then this means that either the theme or one of the plugins was conflicting with another plugin. If the issue still exists then it is not a plugin or theme conflict.
  3. If it turns out to be a plugin/theme conflict, then you need to activate the plugins/theme one by one until you find the plugin/theme that causes the issue to come back.
  4. Once you have identified the conflict you can report the conflict to the developers of the plugin/theme and also to us.