Google help on software/programming And Windows Tricks

helponsoftware

Monday, 27 April 2015

Wordpress Media uploader in frontend

<label for="image_url">Photo</label>
<input type="hidden" name="image_url" id="image_url" class="regular-text">
<input type="hidden" name="attachement_id" id="image_id" class="regular-text">
<div id="img_btn"><input type="button" name="upload-btn" id="upload-btn" class="button-secondary" value="Upload Image"></div>
<?php wp_nonce_field( 'my_image_upload', 'my_image_upload_nonce' ); ?>

<script type="text/javascript">
jQuery(document).ready(function($){
$('#upload-btn').click(function(e) {
e.preventDefault();
var image = wp.media({
title: 'Upload Image',
// mutiple: true if you want to upload multiple files at once
multiple: false
}).open()
.on('select', function(e){
// This will return the selected image from the Media Uploader, the result is an object
var uploaded_image = image.state().get('selection').first();
// We convert uploaded_image to a JSON object to make accessing it easier
// Output to the console uploaded_image
//console.log(uploaded_image);
var image_url = uploaded_image.toJSON().url;
var id = uploaded_image.toJSON().id;
// Let's assign the url value to the input field
$('#image_url').val(image_url);
$('#image_id').val(id);
});
});
});

</script>


USE below FUNCTION IN " functions.php"
wp_enqueue_media();

Wordpress login by user Role

add_action('login_form', 'wdm_login_form_role');
function wdm_login_form_role()
{
 ?>
<p><label for="user_role">Role<br>
<select name="role" style="flaot:left;width:100%;margin-bottom:10px;padding: 10px;">
<option value="publishers">Publishers</option>
<option value="advertisers">Advertisers</option>
</select></label>
<p>
 <?php
  }
add_filter('wp_authenticate_user','wdm_validate_login_role',10,2);
function wdm_validate_login_role($user, $password) {

   $ruser= get_user_by('login',$_POST['log']);

  if($ruser){
       if($ruser->roles[0]==$_POST['role']){
          return $user;
                   }
      else{
     return null;
      }
 }
}

Friday, 27 February 2015

Get all chekbox value and set into textbox as an array

<script>
$('input:checkbox').on('change',function () {
      if(this.checked){
       var Val = (this.checked ? $(this).val() : "");
       var oldVal = $('#idoftextbox').val();
      $('#idoftextbox').val(Val+","+oldVal);
  }
else{

     var Val = $(this).val();
     var oldVal = $('#idoftextbox').val();
     data = removeValue(oldVal,Val);
      $('#activity_level').val(data);
}

  });

function removeValue(list, value) {
  list = list.split(',');
  list.splice(list.indexOf(value), 1);
  return list.join(',');
}

</script>

Friday, 6 February 2015

Social Sharing by Url

http://www.facebook.com/sharer.php?u=

http://twitter.com/share?url=

http://www.linkedin.com/shareArticle?mini=true&url=

https://plus.google.com/share?url=

Thursday, 15 January 2015

Open new Tab in I phone and Safari browser

<script>
function openTab(url) {
    // Create link in memory
    var a = window.document.createElement("a");
    a.target = '_blank';
    a.href = url;

    // Dispatch fake click
    var e = window.document.createEvent("MouseEvents");
    e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    a.dispatchEvent(e);
};
</script>

after that you can call  this function to open any url like:

openTab('url');