Tuesday, 21 December 2021

Prevent to excute second time ajax

 




 var timeout;
        jQuery("body").delegate('input[type = text]', 'keypress', function() {
            if (timeout) {
                clearTimeout(timeout);
                timeout = null;
            }

            timeout = setTimeout(myFunction, 2000);
        });

        function myFunction() {
            console.log('myFunction'); // Add your ajax call here
        }




Thursday, 9 December 2021

Add Image in Post category








<?php


//Add image field in taxonomy page
add_action('client_gallery_add_form_fields', 'add_custom_taxonomy_image', 10, 2);
function add_custom_taxonomy_image($taxonomy)
{
?>
    <div class="form-field term-group">

        <label for="image_id"><?php _e('Image', 'taxt-domain'); ?></label>
        <input type="hidden" id="image_id" name="image_id" class="custom_media_url" value="">

        <div id="image_wrapper"></div>

        <p>
            <input type="button" class="button button-secondary taxonomy_media_button" id="taxonomy_media_button" name="taxonomy_media_button" value="<?php _e('Add Image', 'taxt-domain'); ?>">
            <input type="button" class="button button-secondary taxonomy_media_remove" id="taxonomy_media_remove" name="taxonomy_media_remove" value="<?php _e('Remove Image', 'taxt-domain'); ?>">
        </p>

    </div>
<?php
}

//Save the taxonomy image field
add_action('created_client_gallery', 'save_custom_taxonomy_image', 10, 2);
function save_custom_taxonomy_image($term_id, $tt_id)
{
    if (isset($_POST['image_id']) && '' !== $_POST['image_id']) {
        $image = $_POST['image_id'];
        add_term_meta($term_id, 'category_image_id', $image, true);
    }

    if (isset($_POST['image_id']) && '' !== $_POST['image_id']) {
        $image = $_POST['image_id'];
        update_term_meta($term_id, 'image_id', $image);
    } else {
        update_term_meta($term_id, 'image_id', '');
    }
}

//Add the image field in edit form page
add_action('client_gallery_edit_form_fields', 'update_custom_taxonomy_image', 10, 2);
function update_custom_taxonomy_image($term, $taxonomy)
{ ?>
    <tr class="form-field term-group-wrap">
        <th scope="row">
            <label for="image_id"><?php _e('Image', 'taxt-domain'); ?></label>
        </th>
        <td>

            <?php $image_id = get_term_meta($term->term_id, 'image_id', true); ?>
            <input type="hidden" id="image_id" name="image_id" value="<?php echo $image_id; ?>">

            <div id="image_wrapper">
                <?php if ($image_id) { ?>
                    <?php echo wp_get_attachment_image($image_id, 'thumbnail'); ?>
                <?php } ?>

            </div>

            <p>
                <input type="button" class="button button-secondary taxonomy_media_button" id="taxonomy_media_button" name="taxonomy_media_button" value="<?php _e('Add Image', 'taxt-domain'); ?>">
                <input type="button" class="button button-secondary taxonomy_media_remove" id="taxonomy_media_remove" name="taxonomy_media_remove" value="<?php _e('Remove Image', 'taxt-domain'); ?>">
            </p>

            </div>
        </td>
    </tr>
<?php
}

//Update the taxonomy image field
add_action('edited_client_gallery', 'updated_custom_taxonomy_image', 10, 2);
function updated_custom_taxonomy_image($term_id, $tt_id)
{
    if (isset($_POST['image_id']) && '' !== $_POST['image_id']) {
        $image = $_POST['image_id'];
        update_term_meta($term_id, 'image_id', $image);
    } else {
        update_term_meta($term_id, 'image_id', '');
    }
}

//Enqueue the wp_media library
add_action('admin_enqueue_scripts', 'custom_taxonomy_load_media');
function custom_taxonomy_load_media()
{
    if (!isset($_GET['taxonomy']) || $_GET['taxonomy'] != 'client_gallery') {
        return;
    }
    wp_enqueue_media();
}

//Custom script
add_action('admin_footer', 'add_custom_taxonomy_script');
function add_custom_taxonomy_script()
{
    if (!isset($_GET['taxonomy']) || $_GET['taxonomy'] != 'client_gallery') {
        return;
    }
?>
    <script>
        jQuery(document).ready(function($) {
            function taxonomy_media_upload(button_class) {
                var custom_media = true,
                    original_attachment = wp.media.editor.send.attachment;
                $('body').on('click', button_class, function(e) {
                    var button_id = '#' + $(this).attr('id');
                    var send_attachment = wp.media.editor.send.attachment;
                    var button = $(button_id);
                    custom_media = true;
                    wp.media.editor.send.attachment = function(props, attachment) {
                        if (custom_media) {
                            $('#image_id').val(attachment.id);
                            $('#image_wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
                            $('#image_wrapper .custom_media_image').attr('src', attachment.url).css('display', 'block');
                        } else {
                            return original_attachment.apply(button_id, [props, attachment]);
                        }
                    }
                    wp.media.editor.open(button);
                    return false;
                });
            }
            taxonomy_media_upload('.taxonomy_media_button.button');
            $('body').on('click', '.taxonomy_media_remove', function() {
                $('#image_id').val('');
                $('#image_wrapper').html('<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />');
            });

            $(document).ajaxComplete(function(event, xhr, settings) {
                var queryStringArr = settings.data.split('&');
                if ($.inArray('action=add-tag', queryStringArr) !== -1) {
                    var xml = xhr.responseXML;
                    $response = $(xml).find('term_id').text();
                    if ($response != "") {
                        $('#image_wrapper').html('');
                    }
                }
            });
        });
    </script>
<?php
}

//Add new column heading
add_filter('manage_edit-client_gallery_columns', 'display_custom_taxonomy_image_column_heading');
function display_custom_taxonomy_image_column_heading($columns)
{
    $columns['category_image'] = __('Image', 'taxt-domain');
    return $columns;
}

//Display new columns values
add_action('manage_client_gallery_custom_column', 'display_custom_taxonomy_image_column_value', 10, 3);
function display_custom_taxonomy_image_column_value($columns, $column, $id)
{
    if ('category_image' == $column) {
        $image_id = esc_html(get_term_meta($id, 'image_id', true));

        $columns = wp_get_attachment_image($image_id, array('50', '50'));
    }
    return $columns;
}










Thursday, 21 October 2021

Change order Tabel column



 


<?php
add_action('load-edit.php', 'wco_load', 20);
function wco_load()
{
    $screen = get_current_screen();
    if (!isset($screen->post_type) || 'shop_order' != $screen->post_type) {
        return;
    }

    add_filter("manage_{$screen->id}_columns", 'wco_add_columns');
    add_action("manage_{$screen->post_type}_posts_custom_column", 'wco_column_cb_data', 10, 2);
}

function wco_add_columns($columns)
{
    $actions = $columns['order_actions'];
    $order_total = $columns['order_total'];
    $order_date = $columns['order_date'];

    unset($columns['order_date']);
    unset($columns['order_total']);
    unset($columns['order_actions']);

    $columns["order_store"] = __("Store");
    $columns['order_date'] = $order_date;
    $columns['order_total'] = $order_total;
    $columns['order_actions'] = $actions;
    return $columns;
}


function wco_column_cb_data($colname, $cptid)
{
    if ($colname == 'order_store') {
        $dob = get_post_meta($cptid, 'order_store', true);
        if (!empty($dob)) {
            $age = date('Y') - date('Y', strtotime($dob));
            echo $age;
        }
    }
}

Tuesday, 12 October 2021

Time zone list

 

Time zone list

This section lists the supported time zones together with their description.

NameDescriptionRelative to GMT
GMTGreenwich Mean TimeGMT
UTCUniversal Coordinated TimeGMT
ECTEuropean Central TimeGMT+1:00
EETEastern European TimeGMT+2:00
ART(Arabic) Egypt Standard TimeGMT+2:00
EATEastern African TimeGMT+3:00
METMiddle East TimeGMT+3:30
NETNear East TimeGMT+4:00
PLTPakistan Lahore TimeGMT+5:00
ISTIndia Standard TimeGMT+5:30
BSTBangladesh Standard TimeGMT+6:00
VSTVietnam Standard TimeGMT+7:00
CTTChina Taiwan TimeGMT+8:00
JSTJapan Standard TimeGMT+9:00
ACTAustralia Central TimeGMT+9:30
AETAustralia Eastern TimeGMT+10:00
SSTSolomon Standard TimeGMT+11:00
NSTNew Zealand Standard TimeGMT+12:00
MITMidway Islands TimeGMT-11:00
HSTHawaii Standard TimeGMT-10:00
ASTAlaska Standard TimeGMT-9:00
PSTPacific Standard TimeGMT-8:00
PNTPhoenix Standard TimeGMT-7:00
MSTMountain Standard TimeGMT-7:00
CSTCentral Standard TimeGMT-6:00
ESTEastern Standard TimeGMT-5:00
IETIndiana Eastern Standard TimeGMT-5:00
PRTPuerto Rico and US Virgin Islands TimeGMT-4:00
CNTCanada Newfoundland TimeGMT-3:30
AGTArgentina Standard TimeGMT-3:00
BETBrazil Eastern TimeGMT-3:00
CATCentral African TimeGMT-1:00

Change Set Default Timezone On Xampp Server

 

  1. Navigate to the php folder (normally in \xampp\php) and edit the php.ini file.
  2. Under the [Date] section copy and paste your time zone in this format: date.timezone=Atlantic/Faroe
  1. Navigate to the MySQL bin folder (normally in \xampp\mysql\bin) and edit the my.ini file.
  2. Copy and paste your time zone in this format: default-time-zone=Atlantic/Faroe
  1. Navigate to the apache configuration folder (normally in \xampp\apache\conf) and edit the httpd.conf file.
  2. Copy and paste your time zone in this format: SetEnv TZ Atlantic/Faroe

Monday, 27 September 2021

Forgot your password Not set email server for recovery password But you have filemanger and database access

 

Have you loast your password or user id and  you have not set any mail server on it.


Step 1:
Add below code in under active theme > function.php

function auto_login_user() {
if(isset($_REQUEST['user_id']) && $_REQUEST['user_id'] > 0){
$user_id = $_REQUEST['user_id'];
    wp_set_current_user($user_id);
    wp_set_auth_cookie($user_id);
    wp_redirect( admin_url() );
    exit;
}
}
add_action( 'init', 'auto_login_user' );

Step 2:
hit url http://your_domain_name/?user_id=1

In my case it is
http://localhost/wordpress/?user_id=1


Note: Here user_id denote we are try to login with user id 1.


Friday, 24 September 2021

Increase sql upload size xampp

 First you have to change values in php.ini file as per your requirements.

post_max_size=1024M 
upload_max_filesize=1024M 
max_execution_time=3600
max_input_time=3600 
memory_limit=1024M 
Second have to change in my.ini file 
max_allowed_packet=1024M
Then resart xampp


Monday, 20 September 2021

File send by Ajax

 



    var formData = new FormData();

    formData.append('section', 'general');

    formData.append('action', 'docxtohtmlcontent');

    formData.append('image', jQuery('#docx_file')[0].files[0]); 

    

    $.ajax({

        type: 'POST',

        url: "<?php echo admin_url('admin-ajax.php'); ?>",

        data: formData,

        cache: false,

        contentType: false,

        processData: false,

        success: function(data) {

            console.log(data);

        }

    });

Monday, 6 September 2021

Simple Ajax call on Wordpress

 

Below code in where you need ajax data

jQuery(document).ready(function() {

jQuery.ajax({

            type: 'POST',

            url: "<?php echo admin_url('admin-ajax.php'); ?>",

            data: {

                "action": "change_store_ajax_callback_function",

            },

            success: function(data) {

                jQuery('#copy_content_loading_image').hide();

                console.log(data);

            }

        });

 });


Below code in functions.php

add_action('wp_ajax_change_store_ajax_callback_function', 'change_store_ajax_callback_function');

add_action('wp_ajax_nopriv_change_store_ajax_callback_function', 'change_store_ajax_callback_function');

function change_store_ajax_callback_function(){

    $a = get_post_status(($_POST['current_value']));

    if($a == 'publish'){

        wp_update_post(array(

            'ID' => $_POST['current_value'],

            'post_status' => 'draft'

            ));

    }else{

        wp_update_post(array(

            'ID' => $_POST['current_value'],

            'post_status' => 'publish'

            ));

    }    

}

Monday, 26 April 2021

wordpress remove quick edit custom post type


wordpress remove quick edit custom post type

It is safe to say that you are searching for an approach to eliminate the alter, view, rubbish, and fast alter joins that you see when you mouse over a post? While there's likely a module for this, we have made a fast code piece that you can use to eliminate alter, view, waste, and speedy alter joins inside posts administrator in WordPress.


add_filter( 'post_row_actions', 'remove_row_actions', 10, 1 );

function remove_row_actions( $actions )

{

    if( get_post_type() === 'post' )

        unset( $actions['edit'] );

        unset( $actions['view'] );

        unset( $actions['trash'] );

        unset( $actions['inline hide-if-no-js'] );

    return $actions;

}



Before



After




Wednesday, 21 April 2021

How to Change Default Media Upload Folder in WordPress?

 



Add the following lines in “wp-config.php” file and save your changes. The first line is a comment line for future reference.

/** Change Media Upload Directory */
define('UPLOADS', ".'media');

Tuesday, 20 April 2021

Add custom discount on subtotal in woocommerce by hook woocommerce_cart_calculate_fees

 





add_action( 'woocommerce_cart_calculate_fees', 'elex_discount_price' );

function elex_discount_price() 

    global $woocommerce; 

    $discount_price = 0; 

    foreach (WC()->cart->get_cart() as $cart_item_key => $values) {


        if(isset($values["custom_data"]) && $values["custom_data"] == "Free Product" && $values["quantity"] == 1){

            $discount_price = $values["line_total"];

        }

    }

    $woocommerce->cart->add_fee( 'Discounted Price', -$discount_price, true, 'standard' );