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' ); 


Add Custom link and content on fronted dashboard of buddypress

 





CUSTOM PROFILE TAB

function bp_custom_user_nav_item() {

    global $bp;

 

    $args = array(

            'name' => __('Portfolio', 'buddypress'),

            'slug' => 'portfolio',

            'default_subnav_slug' => 'portfolio',

            'position' => 50,

            'show_for_displayed_user' => false,

            'screen_function' => 'bp_custom_user_nav_item_screen',

            'item_css_id' => 'portfolio'

    );

 

    bp_core_new_nav_item( $args );

}

add_action( 'bp_setup_nav', 'bp_custom_user_nav_item', 99 );


SCREEN CALLBACK FUNCTION

function bp_custom_user_nav_item_screen() {

    add_action( 'bp_template_content', 'bp_custom_screen_content' );

    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );

}



SCREEN CONTENT FUNCTION

function bp_custom_screen_content() {

 

   echo 'the custom content. 

    You can put a post loop here, 

    pass $user_id with bp_displayed_user_id()';

 

}

Friday, 26 March 2021

Custome URL with theme directory

 Custome URL with theme directory


wp

'-> wp-content



function.php

-------------

add_action('init', function() {

$url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/');

$re = '/string-one\/(.*)\/string-two/';

preg_match($re, $url_path, $matches, PREG_OFFSET_CAPTURE, 0);

if ( $matches ) {

$load = locate_template('template.php', true);

if ($load) {

exit(); 

}

}

});


template.php

------------

get_header();

$url_path = trim(parse_url(add_query_arg(array()), PHP_URL_PATH), '/');

$re = '/string-one\/(.*)\/string-two/';

preg_match($re, $url_path, $matches, PREG_OFFSET_CAPTURE, 0);

print_r($mathes);

Thursday, 25 March 2021

 <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/default.min.css">

<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/tomorrow.min.css">

<?php //$temp_data = ["Xa0Q0J5tOP0", "taJ60kskkns", "FG0fTKAqZ5g"] ?>

<style type="text/css">

.av_d_none{display: none;}

input[type=range] { margin-bottom: 30px; }

</style>

<div>

<p><span id="current-time">0:00</span> / <span id="duration">0:00</span> <span id="totalViewPercentage">0%</span></p>

<input type="range" id="progress-bar" value="0">

<br>

<?php foreach ($temp_data as $key => $value): ?>

<div id="video-placeholder_<?= $value ?>" data-id="<?= $value ?>" class="av_d_none"></div>

<?php endforeach ?>

</div>

<?php foreach ($temp_data as $key => $value): ?>

<div id="controls_<?= $value ?>" data-id="<?= $value ?>">

<p><span id="current-time_<?= $value ?>" data-id="<?= $value ?>">0:00</span> / <span id="duration_<?= $value ?>">0:00</span></p>

<input type="range" id="progress-bar_<?= $value ?>" data-id="<?= $value ?>" value="0">

<i id="play_<?= $value ?>" data-id="<?= $value ?>" class="material-icons">play_arrow</i>

<i id="pause_<?= $value ?>" data-id="<?= $value ?>" class="av_d_none material-icons">pause</i>

</div>

<?php endforeach ?>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/highlight.min.js"></script>

<script src="https://www.youtube.com/iframe_api"></script>

<script>

var player = [], time_update_interval = [], player_key = jQuery.parseJSON('<?= json_encode($temp_data) ?>');

function onYouTubeIframeAPIReady() {

for (var i = player_key.length - 1; i >= 0; i--) {

let temp_data2 = player_key[i];

player[player_key[i]] = new YT.Player('video-placeholder_'+player_key[i], {

width: 600,

height: 400,

videoId: player_key[i],

playerVars: {

color: 'white',

},

events: {

onReady: initialize,

onStateChange : function (event) {

if (event.data == 1) {           

$('#play_'+temp_data2).click();

}

}

}

});

}

}



function initialize(){

for (var i = player_key.length - 1; i >= 0; i--) {

updateTimerDisplay(player_key[i]);

updateProgressBar(player_key[i]);

// $('#play_'+player_key[i]).css("display", "block");

$("#video-placeholder_"+player_key[0]).css("display", "block");

}

}

function updateTimerDisplay(player_key){

$('#current-time_'+player_key).text(formatTime( player[player_key].getCurrentTime() ));

$('#duration_'+player_key).text(formatTime( player[player_key].getDuration() ));

}

function updateProgressBar(player_key){

$('#progress-bar_'+player_key).val((player[player_key].getCurrentTime() / player[player_key].getDuration()) * 100);

}

function updateTotalProgressBar() {

player_key = jQuery.parseJSON('<?= json_encode($temp_data) ?>');

var totalCurrentTime = 0;

var totalDuration = 0;

for (var i = player_key.length - 1; i >= 0; i--) {

totalCurrentTime += player[player_key[i]].getCurrentTime();

totalDuration += player[player_key[i]].getDuration();

}

$('#progress-bar').val((totalCurrentTime / totalDuration) * 100);

$('#current-time').text(formatTime( totalCurrentTime ));

$('#duration').text(formatTime( totalDuration ));totalViewPercentage

$('#duration').text(formatTime( totalDuration ));

$('#totalViewPercentage').text(((totalCurrentTime / totalDuration) * 100).toFixed(2) +"%");

}

for (var i = player_key.length - 1; i >= 0; i--) {

$('#progress-bar_'+player_key[i]).on('mouseup touchend', function (e) {

var newTime = player[$(this).attr("data-id")].getDuration() * (e.target.value / 100);

player[$(this).attr("data-id")].seekTo(newTime);

});

$('#play_'+player_key[i]).on('click', function () {

var temp_data3 = '<?= json_encode($temp_data) ?>';

for (var i = player_key.length - 1; i >= 0; i--) {

if(player_key[i] != $(this).attr("data-id")){

$("#video-placeholder_"+player_key[i]).css("display", "none");

$("#pause_"+player_key[i]).click();

}

}

$("#video-placeholder_"+$(this).attr("data-id")).css("display", "block");

player[$(this).attr("data-id")].playVideo();

let temp_data = $(this).attr("data-id");

time_update_interval[$(this).attr("data-id")] = setInterval(function () {

updateTimerDisplay(temp_data);

updateProgressBar(temp_data);

updateTotalProgressBar();

}, 1000);


$("#play_"+$(this).attr("data-id")).css("display", "none");

$("#pause_"+$(this).attr("data-id")).css("display", "block");

});

$('#pause_'+player_key[i]).on('click', function () {

clearInterval(time_update_interval[$(this).attr("data-id")]);

player[$(this).attr("data-id")].pauseVideo();

$("#play_"+$(this).attr("data-id")).css("display", "block");

$("#pause_"+$(this).attr("data-id")).css("display", "none");

});

$('#mute-toggle_'+player_key[i]).on('click', function() {

var mute_toggle = $(this);

if(player[player_key[i]].isMuted()){

player[player_key[i]].unMute();

mute_toggle.text('volume_up');

}

else{

player[player_key[i]].mute();

mute_toggle.text('volume_off');

}

});

$('#volume-input_'+player_key[i]).on('change', function () {

player[player_key[i]].setVolume($(this).val());

});

$('#speed_'+player_key[i]).on('change', function () {

player[player_key[i]].setPlaybackRate($(this).val());

});

$('#quality_'+player_key[i]).on('change', function () {

player[player_key[i]].setPlaybackQuality($(this).val());

});

$('#next_'+player_key[i]).on('click', function () {

player[player_key[i]].nextVideo()

});

$('#prev_'+player_key[i]).on('click', function () {

player[player_key[i]].previousVideo()

});

$('.thumbnail_'+player_key[i]).on('click', function () {

var url = $(this).attr('data-video-id');

player[player_key[i]].cueVideoById(url);

});

}


function formatTime(time){

time = Math.round(time);

var minutes = Math.floor(time / 60),

seconds = time - minutes * 60;

seconds = seconds < 10 ? '0' + seconds : seconds;

return minutes + ":" + seconds;

}

</script>

Wednesday, 24 March 2021

Ts

 





if (!function_exists('extend_admin_search')) {

    add_action('admin_init', 'extend_admin_search');


    /**

     * hook the posts search if we're on the admin page for our type

     */

    function extend_admin_search() {

        global $typenow;


        if ($typenow === 'your_custom_post_type') {

            add_filter('posts_search', 'posts_search_custom_post_type', 10, 2);

        }

    }


    /**

     * add query condition for custom meta

     * @param string $search the search string so far

     * @param WP_Query $query

     * @return string

     */

    function posts_search_custom_post_type($search, $query) {

        global $wpdb;


        if ($query->is_main_query() && !empty($query->query['s'])) {

            $sql    = "

            or exists (

                select * from {$wpdb->postmeta} where post_id={$wpdb->posts}.ID

                and meta_key in ('rg_1job_designation','rg_2job_designation')

                and meta_value like %s

            )

        ";

            $like   = '%' . $wpdb->esc_like($query->query['s']) . '%';

            $search = preg_replace("#\({$wpdb->posts}.post_title LIKE [^)]+\)\K#",

                $wpdb->prepare($sql, $like), $search);

        }


        return $search;

    }

}